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

Rollup of 9 pull requests #64427

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5287885
use randSecure and randABytes
bpangWR Sep 10, 2019
83e7976
Merge pull request #20 from Wind-River/rand
BaoshanPang Sep 11, 2019
5e8bf87
Merge pull request #21 from rust-lang/master
BaoshanPang Sep 11, 2019
b731e11
declare EnvKey before use to fix build error
bpangWR Sep 11, 2019
a8c5f90
Fix inconsistent link formatting.
tomasz-rozanski Sep 11, 2019
223600a
Guarantee vec.clear/truncate is O(1) for trivial types
kornelski Sep 11, 2019
08fa803
Merge pull request #22 from Wind-River/master_002
BaoshanPang Sep 12, 2019
612c394
Trim rustc-workspace-hack
mati865 Sep 11, 2019
baf97b7
Add long error explanation for E0493
GuillaumeGomez Sep 11, 2019
0ad141c
update tests
GuillaumeGomez Sep 12, 2019
34d71f1
Ban non-extern rust intrinsics
Mark-Simulacrum Sep 12, 2019
a47a5c3
typo fix
Sep 9, 2019
69112a2
Add self to .mailmap
ollie27 Sep 13, 2019
3f920e5
Rollup merge of #64372 - Wind-River:master, r=alexcrichton
Centril Sep 13, 2019
51ea8e6
Rollup merge of #64375 - kornelski:vecdrop, r=rkruppe
Centril Sep 13, 2019
1059ddd
Rollup merge of #64377 - GuillaumeGomez:E0493, r=estebank
Centril Sep 13, 2019
f4ec1f0
Rollup merge of #64378 - Rosto75:master, r=jonas-schievink
Centril Sep 13, 2019
1fb1b93
Rollup merge of #64384 - mati865:tools_hack, r=alexcrichton
Centril Sep 13, 2019
12ee41c
Rollup merge of #64393 - Wind-River:master_002_envKey, r=alexcrichton
Centril Sep 13, 2019
0bba7ad
Rollup merge of #64406 - Mark-Simulacrum:error-unknown-intrinsic, r=C…
Centril Sep 13, 2019
6143b15
Rollup merge of #64423 - ollie27:mailmap, r=Mark-Simulacrum
Centril Sep 13, 2019
bdc6271
Rollup merge of #64425 - guanqun:typo-fix, r=matthewjasper
Centril Sep 13, 2019
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
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Neil Pankey <[email protected]> <[email protected]>
Nick Platt <[email protected]>
Nicole Mazzuca <[email protected]>
Nif Ward <[email protected]>
Oliver Middleton <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Expand Down
4 changes: 0 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3256,13 +3256,9 @@ version = "1.0.0"
dependencies = [
"byteorder",
"crossbeam-utils 0.6.5",
"parking_lot 0.7.1",
"rand 0.6.1",
"scopeguard 0.3.3",
"serde",
"serde_json",
"smallvec",
"syn 0.15.35",
"winapi 0.3.6",
]

Expand Down
30 changes: 17 additions & 13 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,21 +685,25 @@ impl<T> Vec<T> {
/// [`drain`]: #method.drain
#[stable(feature = "rust1", since = "1.0.0")]
pub fn truncate(&mut self, len: usize) {
let current_len = self.len;
unsafe {
let mut ptr = self.as_mut_ptr().add(self.len);
// Set the final length at the end, keeping in mind that
// dropping an element might panic. Works around a missed
// optimization, as seen in the following issue:
// https://github.com/rust-lang/rust/issues/51802
let mut local_len = SetLenOnDrop::new(&mut self.len);
if mem::needs_drop::<T>() {
let current_len = self.len;
unsafe {
let mut ptr = self.as_mut_ptr().add(self.len);
// Set the final length at the end, keeping in mind that
// dropping an element might panic. Works around a missed
// optimization, as seen in the following issue:
// https://github.com/rust-lang/rust/issues/51802
let mut local_len = SetLenOnDrop::new(&mut self.len);

// drop any extra elements
for _ in len..current_len {
local_len.decrement_len(1);
ptr = ptr.offset(-1);
ptr::drop_in_place(ptr);
// drop any extra elements
for _ in len..current_len {
local_len.decrement_len(1);
ptr = ptr.offset(-1);
ptr::drop_in_place(ptr);
}
}
} else if len <= self.len {
self.len = len;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub enum ParamName {
Fresh(usize),

/// Indicates an illegal name was given and an error has been
/// repored (so we should squelch other derived errors). Occurs
/// reported (so we should squelch other derived errors). Occurs
/// when, e.g., `'_` is used in the wrong place.
Error,
}
Expand Down
46 changes: 45 additions & 1 deletion src/librustc_mir/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,51 @@ Remember this solution is unsafe! You will have to ensure that accesses to the
cell are synchronized.
"##,

E0493: r##"
A type with a `Drop` implementation was deconstructed when trying to initialize
a static item.

Erroneous code example:

```compile_fail,E0493
enum DropType {
A,
}

impl Drop for DropType {
fn drop(&mut self) {}
}

struct Foo {
field1: DropType,
}

static FOO: Foo = Foo { ..Foo { field1: DropType::A } }; // error!
```

The problem here is that if the given type or one of its fields implements the
`Drop` trait, this `Drop` implementation cannot be called during the static
type initialization which might cause a memory leak. To prevent this issue,
you need to instantiate all the static type's fields by hand.

```
enum DropType {
A,
}

impl Drop for DropType {
fn drop(&mut self) {}
}

struct Foo {
field1: DropType,
}

static FOO: Foo = Foo { field1: DropType::A }; // We initialize all fields
// by hand.
```
"##,

E0499: r##"
A variable was borrowed as mutable more than once. Erroneous code example:

Expand Down Expand Up @@ -2391,7 +2436,6 @@ There are some known bugs that trigger this message.
// E0299, // mismatched types between arms
// E0471, // constant evaluation error (in pattern)
// E0385, // {} in an aliasable location
E0493, // destructors cannot be evaluated at compile-time
E0521, // borrowed data escapes outside of closure
E0524, // two closures require unique access to `..` at the same time
E0526, // shuffle indices are not constant
Expand Down
20 changes: 19 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,8 @@ fn check_fn<'a, 'tcx>(

let span = body.value.span;

fn_maybe_err(fcx.tcx, span, fn_sig.abi);

if body.generator_kind.is_some() && can_be_generator.is_some() {
let yield_ty = fcx.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeInference,
Expand Down Expand Up @@ -1439,6 +1441,14 @@ fn check_opaque_for_cycles<'tcx>(
}
}

// Forbid defining intrinsics in Rust code,
// as they must always be defined by the compiler.
fn fn_maybe_err(tcx: TyCtxt<'_>, sp: Span, abi: Abi) {
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = abi {
tcx.sess.span_err(sp, "intrinsic must be in `extern \"rust-intrinsic\" { ... }` block");
}
}

pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item) {
debug!(
"check_item_type(it.hir_id={}, it.name={})",
Expand Down Expand Up @@ -1475,9 +1485,17 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item) {
check_on_unimplemented(tcx, trait_def_id, it);
}
}
hir::ItemKind::Trait(..) => {
hir::ItemKind::Trait(_, _, _, _, ref items) => {
let def_id = tcx.hir().local_def_id(it.hir_id);
check_on_unimplemented(tcx, def_id, it);

for item in items.iter() {
let item = tcx.hir().trait_item(item.id);
if let hir::TraitItemKind::Method(sig, _) = &item.node {
let abi = sig.header.abi;
fn_maybe_err(tcx, item.ident.span, abi);
}
}
}
hir::ItemKind::Struct(..) => {
check_struct(tcx, it.hir_id, it.span);
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ pub struct StdinLock<'a> {
///
/// Each handle returned is a reference to a shared global buffer whose access
/// is synchronized via a mutex. If you need more explicit control over
/// locking, see the [`lock() method`][lock].
/// locking, see the [`Stdin::lock`] method.
///
/// [lock]: struct.Stdin.html#method.lock
/// [`Stdin::lock`]: struct.Stdin.html#method.lock
///
/// ### Note: Windows Portability Consideration
/// When operating in a console, the Windows implementation of this stream does not support
Expand Down Expand Up @@ -425,9 +425,9 @@ pub struct StdoutLock<'a> {
///
/// Each handle returned is a reference to a shared global buffer whose access
/// is synchronized via a mutex. If you need more explicit control over
/// locking, see the [Stdout::lock] method.
/// locking, see the [`Stdout::lock`] method.
///
/// [Stdout::lock]: struct.Stdout.html#method.lock
/// [`Stdout::lock`]: struct.Stdout.html#method.lock
///
/// ### Note: Windows Portability Consideration
/// When operating in a console, the Windows implementation of this stream does not support
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/vxworks/process/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub use self::process_common::{Command, ExitStatus, ExitCode, Stdio, StdioPipes};
pub use self::process_inner::Process;
pub use crate::ffi::OsString as EnvKey;

mod process_common;
#[path = "process_vxworks.rs"]
Expand Down
2 changes: 0 additions & 2 deletions src/libstd/sys/vxworks/process/process_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use crate::collections::BTreeMap;

use libc::{c_int, gid_t, uid_t, c_char, EXIT_SUCCESS, EXIT_FAILURE};

pub use crate::ffi::OsString as EnvKey;

////////////////////////////////////////////////////////////////////////////////
// Command
////////////////////////////////////////////////////////////////////////////////
Expand Down
21 changes: 14 additions & 7 deletions src/libstd/sys/vxworks/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ pub fn hashmap_random_keys() -> (u64, u64) {
mod imp {
use libc;
use crate::io;

extern "C" {
fn randBytes (randBuf: *mut libc::c_uchar,
numOfBytes: libc::c_int) -> libc::c_int;
}
use core::sync::atomic::{AtomicBool, Ordering::Relaxed};

pub fn fill_bytes(v: &mut [u8]) {
static RNG_INIT: AtomicBool = AtomicBool::new(false);
while !RNG_INIT.load(Relaxed) {
let ret = unsafe { libc::randSecure() };
if ret < 0 {
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
} else if ret > 0 {
RNG_INIT.store(true, Relaxed);
break;
}
unsafe { libc::usleep(10) };
}
let ret = unsafe {
randBytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
libc::randABytes(v.as_mut_ptr() as *mut libc::c_uchar, v.len() as libc::c_int)
};
if ret == -1 {
if ret < 0 {
panic!("couldn't generate random bytes: {}", io::Error::last_os_error());
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/test/incremental/hashes/function_interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


#![allow(warnings)]
#![feature(intrinsics)]
#![feature(linkage)]
#![feature(rustc_attrs)]
#![crate_type = "rlib"]
Expand Down Expand Up @@ -99,15 +98,15 @@ pub fn make_extern() {}
pub extern "C" fn make_extern() {}


// Extern C Extern Rust-Intrinsic ----------------------------------------------
// Extern C Extern stdcall ----------------------------------------------

#[cfg(cfail1)]
pub extern "C" fn make_intrinsic() {}
pub extern "C" fn make_stdcall() {}

#[cfg(not(cfail1))]
#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, typeck_tables_of, fn_sig")]
#[rustc_clean(cfg = "cfail3")]
pub extern "rust-intrinsic" fn make_intrinsic() {}
pub extern "stdcall" fn make_stdcall() {}


// Type Parameter --------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions src/test/incremental/hashes/trait_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#![feature(rustc_attrs)]
#![crate_type="rlib"]
#![feature(associated_type_defaults)]
#![feature(intrinsics)]


// Change trait visibility
Expand Down Expand Up @@ -318,7 +317,7 @@ trait TraitAddExternModifier {



// Change extern "C" to extern "rust-intrinsic"
// Change extern "C" to extern "stdcall"
#[cfg(cfail1)]
trait TraitChangeExternCToRustIntrinsic {
extern "C" fn method();
Expand All @@ -330,7 +329,7 @@ trait TraitChangeExternCToRustIntrinsic {
trait TraitChangeExternCToRustIntrinsic {
#[rustc_dirty(label="Hir", cfg="cfail2")]
#[rustc_clean(label="Hir", cfg="cfail3")]
extern "rust-intrinsic" fn method();
extern "stdcall" fn method();
}


Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/check-static-values-constraints.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ LL | let y = { static x: Box<isize> = box 3; x };

error: aborting due to 17 previous errors

Some errors have detailed explanations: E0010, E0015, E0019, E0507.
Some errors have detailed explanations: E0010, E0015, E0019, E0493, E0507.
For more information about an error, try `rustc --explain E0010`.
1 change: 1 addition & 0 deletions src/test/ui/consts/const-eval/const_let.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ LL | const Z2: () = { let mut x; x = None; x = Some(FakeNeedsDrop); };

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0493`.
4 changes: 2 additions & 2 deletions src/test/ui/consts/min_const_fn/min_const_fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,5 @@ LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo }

error: aborting due to 36 previous errors

Some errors have detailed explanations: E0515, E0723.
For more information about an error, try `rustc --explain E0515`.
Some errors have detailed explanations: E0493, E0515, E0723.
For more information about an error, try `rustc --explain E0493`.
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ LL | const X: Vec<u32> = Vec::new();

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0493`.
10 changes: 8 additions & 2 deletions src/test/ui/feature-gates/feature-gate-abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

// Functions
extern "rust-intrinsic" fn f1() {} //~ ERROR intrinsics are subject to change
//~^ ERROR intrinsic must be in
extern "platform-intrinsic" fn f2() {} //~ ERROR platform intrinsics are experimental
//~^ ERROR intrinsic must be in
extern "vectorcall" fn f3() {} //~ ERROR vectorcall is experimental and subject to change
extern "rust-call" fn f4() {} //~ ERROR rust-call ABI is subject to change
extern "msp430-interrupt" fn f5() {} //~ ERROR msp430-interrupt ABI is experimental
Expand All @@ -22,7 +24,9 @@ extern "amdgpu-kernel" fn f9() {} //~ ERROR amdgpu-kernel ABI is experimental an
// Methods in trait definition
trait Tr {
extern "rust-intrinsic" fn m1(); //~ ERROR intrinsics are subject to change
//~^ ERROR intrinsic must be in
extern "platform-intrinsic" fn m2(); //~ ERROR platform intrinsics are experimental
//~^ ERROR intrinsic must be in
extern "vectorcall" fn m3(); //~ ERROR vectorcall is experimental and subject to change
extern "rust-call" fn m4(); //~ ERROR rust-call ABI is subject to change
extern "msp430-interrupt" fn m5(); //~ ERROR msp430-interrupt ABI is experimental
Expand All @@ -31,8 +35,6 @@ trait Tr {
extern "thiscall" fn m8(); //~ ERROR thiscall is experimental and subject to change
extern "amdgpu-kernel" fn m9(); //~ ERROR amdgpu-kernel ABI is experimental and subject to change

extern "rust-intrinsic" fn dm1() {} //~ ERROR intrinsics are subject to change
extern "platform-intrinsic" fn dm2() {} //~ ERROR platform intrinsics are experimental
extern "vectorcall" fn dm3() {} //~ ERROR vectorcall is experimental and subject to change
extern "rust-call" fn dm4() {} //~ ERROR rust-call ABI is subject to change
extern "msp430-interrupt" fn dm5() {} //~ ERROR msp430-interrupt ABI is experimental
Expand All @@ -47,7 +49,9 @@ struct S;
// Methods in trait impl
impl Tr for S {
extern "rust-intrinsic" fn m1() {} //~ ERROR intrinsics are subject to change
//~^ ERROR intrinsic must be in
extern "platform-intrinsic" fn m2() {} //~ ERROR platform intrinsics are experimental
//~^ ERROR intrinsic must be in
extern "vectorcall" fn m3() {} //~ ERROR vectorcall is experimental and subject to change
extern "rust-call" fn m4() {} //~ ERROR rust-call ABI is subject to change
extern "msp430-interrupt" fn m5() {} //~ ERROR msp430-interrupt ABI is experimental
Expand All @@ -60,7 +64,9 @@ impl Tr for S {
// Methods in inherent impl
impl S {
extern "rust-intrinsic" fn im1() {} //~ ERROR intrinsics are subject to change
//~^ ERROR intrinsic must be in
extern "platform-intrinsic" fn im2() {} //~ ERROR platform intrinsics are experimental
//~^ ERROR intrinsic must be in
extern "vectorcall" fn im3() {} //~ ERROR vectorcall is experimental and subject to change
extern "rust-call" fn im4() {} //~ ERROR rust-call ABI is subject to change
extern "msp430-interrupt" fn im5() {} //~ ERROR msp430-interrupt ABI is experimental
Expand Down
Loading