Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of PRs to Beta #25004

Merged
merged 8 commits into from
Apr 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ fn import_codemap(local_codemap: &codemap::CodeMap,
.into_inner()
.map_in_place(|mbc|
codemap::MultiByteChar {
pos: mbc.pos + start_pos,
pos: mbc.pos - start_pos,
bytes: mbc.bytes
});

Expand Down
54 changes: 54 additions & 0 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2107,3 +2107,57 @@ impl LintPass for UnstableFeatures {
}
}
}

/// Lints for attempts to impl Drop on types that have `#[repr(C)]`
/// attribute (see issue #24585).
#[derive(Copy, Clone)]
pub struct DropWithReprExtern;

declare_lint! {
DROP_WITH_REPR_EXTERN,
Warn,
"use of #[repr(C)] on a type that implements Drop"
}

impl LintPass for DropWithReprExtern {
fn get_lints(&self) -> LintArray {
lint_array!(DROP_WITH_REPR_EXTERN)
}
fn check_crate(&mut self, ctx: &Context, _: &ast::Crate) {
for dtor_did in ctx.tcx.destructors.borrow().iter() {
let (drop_impl_did, dtor_self_type) =
if dtor_did.krate == ast::LOCAL_CRATE {
let impl_did = ctx.tcx.map.get_parent_did(dtor_did.node);
let ty = ty::lookup_item_type(ctx.tcx, impl_did).ty;
(impl_did, ty)
} else {
continue;
};

match dtor_self_type.sty {
ty::ty_enum(self_type_did, _) |
ty::ty_struct(self_type_did, _) |
ty::ty_closure(self_type_did, _) => {
let hints = ty::lookup_repr_hints(ctx.tcx, self_type_did);
if hints.iter().any(|attr| *attr == attr::ReprExtern) &&
ty::ty_dtor(ctx.tcx, self_type_did).has_drop_flag() {
let drop_impl_span = ctx.tcx.map.def_id_span(drop_impl_did,
codemap::DUMMY_SP);
let self_defn_span = ctx.tcx.map.def_id_span(self_type_did,
codemap::DUMMY_SP);
ctx.span_lint(DROP_WITH_REPR_EXTERN,
drop_impl_span,
"implementing Drop adds hidden state to types, \
possibly conflicting with `#[repr(C)]`");
// FIXME #19668: could be span_lint_note instead of manual guard.
if ctx.current_level(DROP_WITH_REPR_EXTERN) != Level::Allow {
ctx.sess().span_note(self_defn_span,
"the `#[repr(C)]` attribute is attached here");
}
}
}
_ => {}
}
}
}
}
1 change: 1 addition & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UnconditionalRecursion,
InvalidNoMangleItems,
PluginAsLibrary,
DropWithReprExtern,
);

add_builtin_with_new!(sess,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/dropck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'tcx>(
ty::Predicate::Trait(ty::Binder(ref t_pred)) => {
let def_id = t_pred.trait_ref.def_id;
match rcx.tcx().lang_items.to_builtin_kind(def_id) {
// Issue 24895: deliberately do not include `BoundCopy` here.
Some(ty::BoundSend) |
Some(ty::BoundSized) |
Some(ty::BoundCopy) |
Some(ty::BoundSync) => false,
_ => true,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub fn all_traits<'a>(ccx: &'a CrateCtxt) -> AllTraits<'a> {
}

pub struct AllTraits<'a> {
borrow: cell::Ref<'a Option<AllTraitsVec>>,
borrow: cell::Ref<'a, Option<AllTraitsVec>>,
idx: usize
}

Expand Down
8 changes: 7 additions & 1 deletion src/libstd/sys/windows/fs2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct OpenOptions {
share_mode: Option<libc::DWORD>,
creation_disposition: Option<libc::DWORD>,
flags_and_attributes: Option<libc::DWORD>,
security_attributes: usize, // *mut T doesn't have a Default impl
}

#[derive(Clone, PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -134,6 +135,9 @@ impl OpenOptions {
pub fn share_mode(&mut self, val: i32) {
self.share_mode = Some(val as libc::DWORD);
}
pub fn security_attributes(&mut self, attrs: libc::LPSECURITY_ATTRIBUTES) {
self.security_attributes = attrs as usize;
}

fn get_desired_access(&self) -> libc::DWORD {
self.desired_access.unwrap_or({
Expand Down Expand Up @@ -185,7 +189,7 @@ impl File {
libc::CreateFileW(path.as_ptr(),
opts.get_desired_access(),
opts.get_share_mode(),
ptr::null_mut(),
opts.security_attributes as *mut _,
opts.get_creation_disposition(),
opts.get_flags_and_attributes(),
ptr::null_mut())
Expand Down Expand Up @@ -262,6 +266,8 @@ impl File {
}

pub fn handle(&self) -> &Handle { &self.handle }

pub fn into_handle(self) -> Handle { self.handle }
}

impl FromInner<libc::HANDLE> for File {
Expand Down
13 changes: 13 additions & 0 deletions src/libstd/sys/windows/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use prelude::v1::*;

use io::ErrorKind;
use io;
use libc::funcs::extra::kernel32::{GetCurrentProcess, DuplicateHandle};
use libc::{self, HANDLE};
use mem;
use ptr;
Expand Down Expand Up @@ -65,6 +66,18 @@ impl Handle {
}));
Ok(amt as usize)
}

pub fn duplicate(&self, access: libc::DWORD, inherit: bool,
options: libc::DWORD) -> io::Result<Handle> {
let mut ret = 0 as libc::HANDLE;
try!(cvt(unsafe {
let cur_proc = GetCurrentProcess();
DuplicateHandle(cur_proc, self.0, cur_proc, &mut ret,
access, inherit as libc::BOOL,
options)
}));
Ok(Handle::new(ret))
}
}

impl Drop for Handle {
Expand Down
Loading