Skip to content

Commit 09e8ad5

Browse files
committed
Merge pull request #25004 from alexcrichton/beta-backport
Backport of PRs to Beta
2 parents 4d4a5c8 + 76a9a6f commit 09e8ad5

26 files changed

+878
-182
lines changed

src/librustc/metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ fn import_codemap(local_codemap: &codemap::CodeMap,
664664
.into_inner()
665665
.map_in_place(|mbc|
666666
codemap::MultiByteChar {
667-
pos: mbc.pos + start_pos,
667+
pos: mbc.pos - start_pos,
668668
bytes: mbc.bytes
669669
});
670670

src/librustc_lint/builtin.rs

+54
Original file line numberDiff line numberDiff line change
@@ -2107,3 +2107,57 @@ impl LintPass for UnstableFeatures {
21072107
}
21082108
}
21092109
}
2110+
2111+
/// Lints for attempts to impl Drop on types that have `#[repr(C)]`
2112+
/// attribute (see issue #24585).
2113+
#[derive(Copy, Clone)]
2114+
pub struct DropWithReprExtern;
2115+
2116+
declare_lint! {
2117+
DROP_WITH_REPR_EXTERN,
2118+
Warn,
2119+
"use of #[repr(C)] on a type that implements Drop"
2120+
}
2121+
2122+
impl LintPass for DropWithReprExtern {
2123+
fn get_lints(&self) -> LintArray {
2124+
lint_array!(DROP_WITH_REPR_EXTERN)
2125+
}
2126+
fn check_crate(&mut self, ctx: &Context, _: &ast::Crate) {
2127+
for dtor_did in ctx.tcx.destructors.borrow().iter() {
2128+
let (drop_impl_did, dtor_self_type) =
2129+
if dtor_did.krate == ast::LOCAL_CRATE {
2130+
let impl_did = ctx.tcx.map.get_parent_did(dtor_did.node);
2131+
let ty = ty::lookup_item_type(ctx.tcx, impl_did).ty;
2132+
(impl_did, ty)
2133+
} else {
2134+
continue;
2135+
};
2136+
2137+
match dtor_self_type.sty {
2138+
ty::ty_enum(self_type_did, _) |
2139+
ty::ty_struct(self_type_did, _) |
2140+
ty::ty_closure(self_type_did, _) => {
2141+
let hints = ty::lookup_repr_hints(ctx.tcx, self_type_did);
2142+
if hints.iter().any(|attr| *attr == attr::ReprExtern) &&
2143+
ty::ty_dtor(ctx.tcx, self_type_did).has_drop_flag() {
2144+
let drop_impl_span = ctx.tcx.map.def_id_span(drop_impl_did,
2145+
codemap::DUMMY_SP);
2146+
let self_defn_span = ctx.tcx.map.def_id_span(self_type_did,
2147+
codemap::DUMMY_SP);
2148+
ctx.span_lint(DROP_WITH_REPR_EXTERN,
2149+
drop_impl_span,
2150+
"implementing Drop adds hidden state to types, \
2151+
possibly conflicting with `#[repr(C)]`");
2152+
// FIXME #19668: could be span_lint_note instead of manual guard.
2153+
if ctx.current_level(DROP_WITH_REPR_EXTERN) != Level::Allow {
2154+
ctx.sess().span_note(self_defn_span,
2155+
"the `#[repr(C)]` attribute is attached here");
2156+
}
2157+
}
2158+
}
2159+
_ => {}
2160+
}
2161+
}
2162+
}
2163+
}

src/librustc_lint/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
109109
UnconditionalRecursion,
110110
InvalidNoMangleItems,
111111
PluginAsLibrary,
112+
DropWithReprExtern,
112113
);
113114

114115
add_builtin_with_new!(sess,

src/librustc_typeck/check/dropck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'tcx>(
464464
ty::Predicate::Trait(ty::Binder(ref t_pred)) => {
465465
let def_id = t_pred.trait_ref.def_id;
466466
match rcx.tcx().lang_items.to_builtin_kind(def_id) {
467+
// Issue 24895: deliberately do not include `BoundCopy` here.
467468
Some(ty::BoundSend) |
468469
Some(ty::BoundSized) |
469-
Some(ty::BoundCopy) |
470470
Some(ty::BoundSync) => false,
471471
_ => true,
472472
}

src/librustc_typeck/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
364364
}
365365

366366
pub struct AllTraits<'a> {
367-
borrow: cell::Ref<'a Option<AllTraitsVec>>,
367+
borrow: cell::Ref<'a, Option<AllTraitsVec>>,
368368
idx: usize
369369
}
370370

src/libstd/sys/windows/fs2.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub struct OpenOptions {
5555
share_mode: Option<libc::DWORD>,
5656
creation_disposition: Option<libc::DWORD>,
5757
flags_and_attributes: Option<libc::DWORD>,
58+
security_attributes: usize, // *mut T doesn't have a Default impl
5859
}
5960

6061
#[derive(Clone, PartialEq, Eq, Debug)]
@@ -134,6 +135,9 @@ impl OpenOptions {
134135
pub fn share_mode(&mut self, val: i32) {
135136
self.share_mode = Some(val as libc::DWORD);
136137
}
138+
pub fn security_attributes(&mut self, attrs: libc::LPSECURITY_ATTRIBUTES) {
139+
self.security_attributes = attrs as usize;
140+
}
137141

138142
fn get_desired_access(&self) -> libc::DWORD {
139143
self.desired_access.unwrap_or({
@@ -185,7 +189,7 @@ impl File {
185189
libc::CreateFileW(path.as_ptr(),
186190
opts.get_desired_access(),
187191
opts.get_share_mode(),
188-
ptr::null_mut(),
192+
opts.security_attributes as *mut _,
189193
opts.get_creation_disposition(),
190194
opts.get_flags_and_attributes(),
191195
ptr::null_mut())
@@ -262,6 +266,8 @@ impl File {
262266
}
263267

264268
pub fn handle(&self) -> &Handle { &self.handle }
269+
270+
pub fn into_handle(self) -> Handle { self.handle }
265271
}
266272

267273
impl FromInner<libc::HANDLE> for File {

src/libstd/sys/windows/handle.rs

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use prelude::v1::*;
1212

1313
use io::ErrorKind;
1414
use io;
15+
use libc::funcs::extra::kernel32::{GetCurrentProcess, DuplicateHandle};
1516
use libc::{self, HANDLE};
1617
use mem;
1718
use ptr;
@@ -65,6 +66,18 @@ impl Handle {
6566
}));
6667
Ok(amt as usize)
6768
}
69+
70+
pub fn duplicate(&self, access: libc::DWORD, inherit: bool,
71+
options: libc::DWORD) -> io::Result<Handle> {
72+
let mut ret = 0 as libc::HANDLE;
73+
try!(cvt(unsafe {
74+
let cur_proc = GetCurrentProcess();
75+
DuplicateHandle(cur_proc, self.0, cur_proc, &mut ret,
76+
access, inherit as libc::BOOL,
77+
options)
78+
}));
79+
Ok(Handle::new(ret))
80+
}
6881
}
6982

7083
impl Drop for Handle {

0 commit comments

Comments
 (0)