diff --git a/src/borrow_tracker/stacked_borrows/mod.rs b/src/borrow_tracker/stacked_borrows/mod.rs index e7d7cc28ee..f792e75ad0 100644 --- a/src/borrow_tracker/stacked_borrows/mod.rs +++ b/src/borrow_tracker/stacked_borrows/mod.rs @@ -22,9 +22,9 @@ use crate::borrow_tracker::{ use crate::concurrency::data_race::{NaReadType, NaWriteType}; use crate::*; -use diagnostics::{RetagCause, RetagInfo}; -pub use item::{Item, Permission}; -pub use stack::Stack; +use self::diagnostics::{RetagCause, RetagInfo}; +pub use self::item::{Item, Permission}; +pub use self::stack::Stack; pub type AllocState = Stacks; diff --git a/src/borrow_tracker/tree_borrows/mod.rs b/src/borrow_tracker/tree_borrows/mod.rs index 89b8ff1af8..2afe02dc2c 100644 --- a/src/borrow_tracker/tree_borrows/mod.rs +++ b/src/borrow_tracker/tree_borrows/mod.rs @@ -19,8 +19,8 @@ mod unimap; #[cfg(test)] mod exhaustive; -use perms::Permission; -pub use tree::Tree; +use self::perms::Permission; +pub use self::tree::Tree; pub type AllocState = Tree; diff --git a/src/borrow_tracker/tree_borrows/perms.rs b/src/borrow_tracker/tree_borrows/perms.rs index dfb9b8637f..28f9dec7bb 100644 --- a/src/borrow_tracker/tree_borrows/perms.rs +++ b/src/borrow_tracker/tree_borrows/perms.rs @@ -47,7 +47,7 @@ enum PermissionPriv { /// rejects: all child accesses (UB). Disabled, } -use PermissionPriv::*; +use self::PermissionPriv::*; impl PartialOrd for PermissionPriv { /// PermissionPriv is ordered by the reflexive transitive closure of diff --git a/src/concurrency/mod.rs b/src/concurrency/mod.rs index 17789fe9f8..c5082b4e40 100644 --- a/src/concurrency/mod.rs +++ b/src/concurrency/mod.rs @@ -7,4 +7,4 @@ pub mod thread; mod vector_clock; pub mod weak_memory; -pub use vector_clock::VClock; +pub use self::vector_clock::VClock; diff --git a/src/intrinsics/atomic.rs b/src/intrinsics/atomic.rs index d76f622e84..6365e0efd5 100644 --- a/src/intrinsics/atomic.rs +++ b/src/intrinsics/atomic.rs @@ -1,7 +1,7 @@ use rustc_middle::{mir, mir::BinOp, ty}; use crate::*; -use helpers::check_arg_count; +use self::helpers::check_arg_count; pub enum AtomicOp { /// The `bool` indicates whether the result of the operation should be negated (`UnOp::Not`, diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 3eeb11dbbb..b8352b575a 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -13,9 +13,9 @@ use rustc_span::{Symbol, sym}; use rustc_target::abi::Size; use crate::*; -use atomic::EvalContextExt as _; -use helpers::{ToHost, ToSoft, check_arg_count}; -use simd::EvalContextExt as _; +use self::atomic::EvalContextExt as _; +use self::helpers::{ToHost, ToSoft, check_arg_count}; +use self::simd::EvalContextExt as _; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { diff --git a/src/lib.rs b/src/lib.rs index b39f88dd1c..6e015813e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,6 +51,8 @@ clippy::cast_lossless, clippy::cast_possible_truncation, )] +#![cfg_attr(not(bootstrap), feature(unqualified_local_imports))] +#![cfg_attr(not(bootstrap), warn(unqualified_local_imports))] // Needed for rustdoc from bootstrap (with `-Znormalize-docs`). #![recursion_limit = "256"] diff --git a/src/shims/env.rs b/src/shims/env.rs index 6586ea8e48..279df042de 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -3,7 +3,7 @@ use std::ffi::{OsStr, OsString}; use rustc_data_structures::fx::FxHashMap; use crate::*; -use shims::{unix::UnixEnvVars, windows::WindowsEnvVars}; +use self::shims::{unix::UnixEnvVars, windows::WindowsEnvVars}; #[derive(Default)] pub enum EnvVars<'tcx> { diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 67dc147617..11cb9740e3 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -15,7 +15,7 @@ use rustc_target::{ use super::alloc::EvalContextExt as _; use super::backtrace::EvalContextExt as _; use crate::*; -use helpers::{ToHost, ToSoft}; +use self::helpers::{ToHost, ToSoft}; /// Type of dynamic symbols (for `dlsym` et al) #[derive(Debug, Copy, Clone)] diff --git a/src/shims/mod.rs b/src/shims/mod.rs index 618cf8cf20..a689ac2b37 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -17,7 +17,7 @@ pub mod panic; pub mod time; pub mod tls; -pub use unix::{DirTable, EpollInterestTable, FdTable}; +pub use self::unix::{DirTable, EpollInterestTable, FdTable}; /// What needs to be done after emulating an item (a shim or an intrinsic) is done. pub enum EmulateItemResult { diff --git a/src/shims/panic.rs b/src/shims/panic.rs index 44f942cb4c..52c4394591 100644 --- a/src/shims/panic.rs +++ b/src/shims/panic.rs @@ -17,7 +17,7 @@ use rustc_target::spec::PanicStrategy; use rustc_target::spec::abi::Abi; use crate::*; -use helpers::check_arg_count; +use self::helpers::check_arg_count; /// Holds all of the relevant data for when unwinding hits a `try` frame. #[derive(Debug)] diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index 57dae05025..c06ce57e61 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -11,11 +11,11 @@ use crate::shims::alloc::EvalContextExt as _; use crate::shims::unix::*; use crate::*; -use shims::unix::android::foreign_items as android; -use shims::unix::freebsd::foreign_items as freebsd; -use shims::unix::linux::foreign_items as linux; -use shims::unix::macos::foreign_items as macos; -use shims::unix::solarish::foreign_items as solarish; +use self::shims::unix::android::foreign_items as android; +use self::shims::unix::freebsd::foreign_items as freebsd; +use self::shims::unix::linux::foreign_items as linux; +use self::shims::unix::macos::foreign_items as macos; +use self::shims::unix::solarish::foreign_items as solarish; pub fn is_dyn_sym(name: &str, target_os: &str) -> bool { match name { diff --git a/src/shims/unix/fs.rs b/src/shims/unix/fs.rs index 1f7e1b3bd7..c90839138c 100644 --- a/src/shims/unix/fs.rs +++ b/src/shims/unix/fs.rs @@ -15,7 +15,7 @@ use crate::shims::os_str::bytes_to_os_str; use crate::shims::unix::fd::FileDescriptionRef; use crate::shims::unix::*; use crate::*; -use shims::time::system_time_to_duration; +use self::shims::time::system_time_to_duration; use self::fd::FlockOp; diff --git a/src/shims/unix/linux/foreign_items.rs b/src/shims/unix/linux/foreign_items.rs index d64f13f63d..6418280d03 100644 --- a/src/shims/unix/linux/foreign_items.rs +++ b/src/shims/unix/linux/foreign_items.rs @@ -5,10 +5,10 @@ use crate::machine::SIGRTMAX; use crate::machine::SIGRTMIN; use crate::shims::unix::*; use crate::*; -use shims::unix::linux::epoll::EvalContextExt as _; -use shims::unix::linux::eventfd::EvalContextExt as _; -use shims::unix::linux::mem::EvalContextExt as _; -use shims::unix::linux::sync::futex; +use self::shims::unix::linux::epoll::EvalContextExt as _; +use self::shims::unix::linux::eventfd::EvalContextExt as _; +use self::shims::unix::linux::mem::EvalContextExt as _; +use self::shims::unix::linux::sync::futex; pub fn is_dyn_sym(name: &str) -> bool { matches!(name, "statx") diff --git a/src/shims/unix/macos/foreign_items.rs b/src/shims/unix/macos/foreign_items.rs index 47b887dec9..95a4175205 100644 --- a/src/shims/unix/macos/foreign_items.rs +++ b/src/shims/unix/macos/foreign_items.rs @@ -78,6 +78,16 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.write_pointer(environ, dest)?; } + // Random data generation + "CCRandomGenerateBytes" => { + let [bytes, count] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let bytes = this.read_pointer(bytes)?; + let count = this.read_target_usize(count)?; + let success = this.eval_libc_i32("kCCSuccess"); + this.gen_random(bytes, count)?; + this.write_int(success, dest)?; + } + // Time related shims "mach_absolute_time" => { let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; diff --git a/src/shims/unix/mod.rs b/src/shims/unix/mod.rs index 7da6d7b02a..a95b4d3d30 100644 --- a/src/shims/unix/mod.rs +++ b/src/shims/unix/mod.rs @@ -14,18 +14,18 @@ mod linux; mod macos; mod solarish; -pub use env::UnixEnvVars; -pub use fd::{FdTable, FileDescription}; -pub use fs::DirTable; -pub use linux::epoll::EpollInterestTable; +pub use self::env::UnixEnvVars; +pub use self::fd::{FdTable, FileDescription}; +pub use self::fs::DirTable; +pub use self::linux::epoll::EpollInterestTable; // All the Unix-specific extension traits -pub use env::EvalContextExt as _; -pub use fd::EvalContextExt as _; -pub use fs::EvalContextExt as _; -pub use mem::EvalContextExt as _; -pub use sync::EvalContextExt as _; -pub use thread::EvalContextExt as _; -pub use unnamed_socket::EvalContextExt as _; +pub use self::env::EvalContextExt as _; +pub use self::fd::EvalContextExt as _; +pub use self::fs::EvalContextExt as _; +pub use self::mem::EvalContextExt as _; +pub use self::sync::EvalContextExt as _; +pub use self::thread::EvalContextExt as _; +pub use self::unnamed_socket::EvalContextExt as _; // Make up some constants. const UID: u32 = 1000; diff --git a/src/shims/windows/env.rs b/src/shims/windows/env.rs index 495df18a6e..178b0a1a46 100644 --- a/src/shims/windows/env.rs +++ b/src/shims/windows/env.rs @@ -5,7 +5,7 @@ use std::io::ErrorKind; use rustc_data_structures::fx::FxHashMap; use crate::*; -use helpers::windows_check_buffer_size; +use self::helpers::windows_check_buffer_size; #[derive(Default)] pub struct WindowsEnvVars { diff --git a/src/shims/windows/foreign_items.rs b/src/shims/windows/foreign_items.rs index f840ba1616..f385ed4ac1 100644 --- a/src/shims/windows/foreign_items.rs +++ b/src/shims/windows/foreign_items.rs @@ -11,7 +11,7 @@ use rustc_target::spec::abi::Abi; use crate::shims::os_str::bytes_to_os_str; use crate::shims::windows::*; use crate::*; -use shims::windows::handle::{Handle, PseudoHandle}; +use self::shims::windows::handle::{Handle, PseudoHandle}; pub fn is_dyn_sym(name: &str) -> bool { // std does dynamic detection for these symbols diff --git a/src/shims/windows/mod.rs b/src/shims/windows/mod.rs index 65f682b9da..537c724e52 100644 --- a/src/shims/windows/mod.rs +++ b/src/shims/windows/mod.rs @@ -5,9 +5,9 @@ mod handle; mod sync; mod thread; -pub use env::WindowsEnvVars; +pub use self::env::WindowsEnvVars; // All the Windows-specific extension traits -pub use env::EvalContextExt as _; -pub use handle::EvalContextExt as _; -pub use sync::EvalContextExt as _; -pub use thread::EvalContextExt as _; +pub use self::env::EvalContextExt as _; +pub use self::handle::EvalContextExt as _; +pub use self::sync::EvalContextExt as _; +pub use self::thread::EvalContextExt as _; diff --git a/src/shims/windows/thread.rs b/src/shims/windows/thread.rs index f3ddf6072a..9f93fc5f08 100644 --- a/src/shims/windows/thread.rs +++ b/src/shims/windows/thread.rs @@ -2,7 +2,7 @@ use rustc_middle::ty::layout::LayoutOf; use rustc_target::spec::abi::Abi; use crate::*; -use shims::windows::handle::{EvalContextExt as _, Handle, PseudoHandle}; +use self::shims::windows::handle::{EvalContextExt as _, Handle, PseudoHandle}; impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} diff --git a/src/shims/x86/mod.rs b/src/shims/x86/mod.rs index 7c7a0935c4..9139156fd0 100644 --- a/src/shims/x86/mod.rs +++ b/src/shims/x86/mod.rs @@ -9,7 +9,7 @@ use rustc_target::abi::Size; use rustc_target::spec::abi::Abi; use crate::*; -use helpers::bool_to_simd_element; +use self::helpers::bool_to_simd_element; mod aesni; mod avx; diff --git a/tests/fail/dyn-call-trait-mismatch.rs b/tests/fail/dyn-call-trait-mismatch.rs index 982d57b737..7ac619e09a 100644 --- a/tests/fail/dyn-call-trait-mismatch.rs +++ b/tests/fail/dyn-call-trait-mismatch.rs @@ -16,5 +16,5 @@ impl T1 for i32 { fn main() { let r = Box::new(0) as Box; let r2: Box = unsafe { std::mem::transmute(r) }; - r2.method2(); //~ERROR: using vtable for trait `T1` but trait `T2` was expected + r2.method2(); //~ERROR: using vtable for `T1` but `T2` was expected } diff --git a/tests/fail/dyn-call-trait-mismatch.stderr b/tests/fail/dyn-call-trait-mismatch.stderr index 3680a84fac..37d102c871 100644 --- a/tests/fail/dyn-call-trait-mismatch.stderr +++ b/tests/fail/dyn-call-trait-mismatch.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: using vtable for trait `T1` but trait `T2` was expected +error: Undefined Behavior: using vtable for `T1` but `T2` was expected --> tests/fail/dyn-call-trait-mismatch.rs:LL:CC | LL | r2.method2(); - | ^^^^^^^^^^^^ using vtable for trait `T1` but trait `T2` was expected + | ^^^^^^^^^^^^ using vtable for `T1` but `T2` was expected | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/fail/dyn-upcast-trait-mismatch.rs b/tests/fail/dyn-upcast-trait-mismatch.rs index 85d7582d11..f450e7e652 100644 --- a/tests/fail/dyn-upcast-trait-mismatch.rs +++ b/tests/fail/dyn-upcast-trait-mismatch.rs @@ -63,6 +63,6 @@ fn main() { let baz: &dyn Baz = &1; let baz_fake: *const dyn Bar = std::mem::transmute(baz); let _err = baz_fake as *const dyn Foo; - //~^ERROR: using vtable for trait `Baz` but trait `Bar` was expected + //~^ERROR: using vtable for `Baz` but `Bar` was expected } } diff --git a/tests/fail/dyn-upcast-trait-mismatch.stderr b/tests/fail/dyn-upcast-trait-mismatch.stderr index 2129fe66e9..d0fd0e6fcc 100644 --- a/tests/fail/dyn-upcast-trait-mismatch.stderr +++ b/tests/fail/dyn-upcast-trait-mismatch.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: using vtable for trait `Baz` but trait `Bar` was expected +error: Undefined Behavior: using vtable for `Baz` but `Bar` was expected --> tests/fail/dyn-upcast-trait-mismatch.rs:LL:CC | LL | let _err = baz_fake as *const dyn Foo; - | ^^^^^^^^ using vtable for trait `Baz` but trait `Bar` was expected + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ using vtable for `Baz` but `Bar` was expected | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/fail/validity/wrong-dyn-trait-assoc-type.rs b/tests/fail/validity/wrong-dyn-trait-assoc-type.rs new file mode 100644 index 0000000000..1478abedee --- /dev/null +++ b/tests/fail/validity/wrong-dyn-trait-assoc-type.rs @@ -0,0 +1,18 @@ +trait Trait { + type Assoc; + fn foo(&self) -> Self::Assoc; +} + +impl Trait for T { + type Assoc = T; + fn foo(&self) -> T { *self } +} + +fn main() { + let v: Box> = Box::new(2); + let v: Box> = unsafe { std::mem::transmute(v) }; //~ERROR: wrong trait + + if v.foo() { + println!("huh"); + } +} diff --git a/tests/fail/validity/wrong-dyn-trait-assoc-type.stderr b/tests/fail/validity/wrong-dyn-trait-assoc-type.stderr new file mode 100644 index 0000000000..44939a5a83 --- /dev/null +++ b/tests/fail/validity/wrong-dyn-trait-assoc-type.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: constructing invalid value: wrong trait in wide pointer vtable: expected `Trait`, but encountered `Trait` + --> tests/fail/validity/wrong-dyn-trait-assoc-type.rs:LL:CC + | +LL | let v: Box> = unsafe { std::mem::transmute(v) }; + | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: wrong trait in wide pointer vtable: expected `Trait`, but encountered `Trait` + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at tests/fail/validity/wrong-dyn-trait-assoc-type.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error + diff --git a/tests/fail/validity/wrong-dyn-trait.stderr b/tests/fail/validity/wrong-dyn-trait.stderr index 4be3fb52bd..45c882bebd 100644 --- a/tests/fail/validity/wrong-dyn-trait.stderr +++ b/tests/fail/validity/wrong-dyn-trait.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: constructing invalid value: wrong trait in wide pointer vtable: expected `std::fmt::Debug`, but encountered `` +error: Undefined Behavior: constructing invalid value: wrong trait in wide pointer vtable: expected `std::fmt::Debug`, but encountered `std::marker::Send` --> tests/fail/validity/wrong-dyn-trait.rs:LL:CC | LL | let _y: *const dyn fmt::Debug = unsafe { mem::transmute(x) }; - | ^^^^^^^^^^^^^^^^^ constructing invalid value: wrong trait in wide pointer vtable: expected `std::fmt::Debug`, but encountered `` + | ^^^^^^^^^^^^^^^^^ constructing invalid value: wrong trait in wide pointer vtable: expected `std::fmt::Debug`, but encountered `std::marker::Send` | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs b/tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs new file mode 100644 index 0000000000..afcc02bc83 --- /dev/null +++ b/tests/pass-dep/libc/ccrandomgeneratebytes_apple.rs @@ -0,0 +1,7 @@ +//@only-target: apple # This directly tests apple-only functions + +fn main() { + let mut bytes = [0u8; 24]; + let ret = unsafe { libc::CCRandomGenerateBytes(bytes.as_mut_ptr().cast(), bytes.len()) }; + assert_eq!(ret, libc::kCCSuccess); +}