Skip to content

Commit

Permalink
fix unclear_local_imports in Miri
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 28, 2024
1 parent 16d58ab commit bbfdd06
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 59 deletions.
6 changes: 3 additions & 3 deletions src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub(super) struct TbError<'node> {
impl TbError<'_> {
/// Produce a UB error.
pub fn build<'tcx>(self) -> InterpError<'tcx> {
use TransitionError::*;
use self::TransitionError::*;
let cause = self.access_cause;
let accessed = self.accessed_info;
let conflicting = self.conflicting_info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ macro_rules! precondition {
}
};
}
#[cfg_attr(not(bootstrap), allow(unclear_local_imports))]
pub(crate) use precondition;

// Trivial impls of `Exhaustive` for the standard types with 0, 1 and 2 elements respectively.
Expand Down
4 changes: 2 additions & 2 deletions src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,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;

Expand Down
10 changes: 5 additions & 5 deletions src/tools/miri/src/borrow_tracker/tree_borrows/perms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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
Expand Down Expand Up @@ -483,14 +483,14 @@ mod propagation_optimization_checks {

impl Exhaustive for AccessKind {
fn exhaustive() -> Box<dyn Iterator<Item = Self>> {
use AccessKind::*;
use self::AccessKind::*;
Box::new(vec![Read, Write].into_iter())
}
}

impl Exhaustive for AccessRelatedness {
fn exhaustive() -> Box<dyn Iterator<Item = Self>> {
use AccessRelatedness::*;
use self::AccessRelatedness::*;
Box::new(vec![This, StrictChildAccess, AncestorAccess, DistantAccess].into_iter())
}
}
Expand All @@ -499,7 +499,7 @@ mod propagation_optimization_checks {
// For any kind of access, if we do it twice the second should be a no-op.
// Even if the protector has disappeared.
fn all_transitions_idempotent() {
use transition::*;
use self::transition::*;
for old in PermissionPriv::exhaustive() {
for (old_protected, new_protected) in <(bool, bool)>::exhaustive() {
// Protector can't appear out of nowhere: either the permission was
Expand All @@ -525,7 +525,7 @@ mod propagation_optimization_checks {
#[test]
#[rustfmt::skip]
fn foreign_read_is_noop_after_foreign_write() {
use transition::*;
use self::transition::*;
let old_access = AccessKind::Write;
let new_access = AccessKind::Read;
for old in PermissionPriv::exhaustive() {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/borrow_tracker/tree_borrows/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ impl AccessRelatedness {
/// for the child node. This function assumes that we propagate away from the initial
/// access.
pub fn for_child(self) -> Self {
use AccessRelatedness::*;
use self::AccessRelatedness::*;
match self {
AncestorAccess | This => AncestorAccess,
StrictChildAccess | DistantAccess => DistantAccess,
Expand Down
6 changes: 3 additions & 3 deletions src/tools/miri/src/borrow_tracker/tree_borrows/tree/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod spurious_read {

impl Exhaustive for PtrSelector {
fn exhaustive() -> Box<dyn Iterator<Item = Self>> {
use PtrSelector::*;
use self::PtrSelector::*;
Box::new(vec![X, Y, Other].into_iter())
}
}
Expand All @@ -152,7 +152,7 @@ mod spurious_read {

impl Exhaustive for RelPosXY {
fn exhaustive() -> Box<dyn Iterator<Item = Self>> {
use RelPosXY::*;
use self::RelPosXY::*;
Box::new(vec![MutuallyForeign, XChildY].into_iter())
}
}
Expand All @@ -178,7 +178,7 @@ mod spurious_read {
/// or an `AncestorAccess` relative to `y`, but it doesn't really matter
/// because `DistantAccess.is_foreign() == AncestorAccess.is_foreign()`).
fn rel_pair(self, xy_rel: RelPosXY) -> (AccessRelatedness, AccessRelatedness) {
use AccessRelatedness::*;
use self::AccessRelatedness::*;
match xy_rel {
RelPosXY::MutuallyForeign =>
match self {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/concurrency/data_race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ trait EvalContextPrivExt<'tcx>: MiriInterpCxExt<'tcx> {
place: &MPlaceTy<'tcx, Provenance>,
atomic: AtomicRwOrd,
) -> InterpResult<'tcx> {
use AtomicRwOrd::*;
use self::AtomicRwOrd::*;
let acquire = matches!(atomic, Acquire | AcqRel | SeqCst);
let release = matches!(atomic, Release | AcqRel | SeqCst);
let this = self.eval_context_mut();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/concurrency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 3 additions & 3 deletions src/tools/miri/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct RacingOp {

impl fmt::Display for TerminationInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use TerminationInfo::*;
use self::TerminationInfo::*;
match self {
Exit { code, .. } => write!(f, "the evaluated program completed with exit code {code}"),
Abort(msg) => write!(f, "{msg}"),
Expand Down Expand Up @@ -212,7 +212,7 @@ pub fn report_error<'tcx>(

let (title, helps) = if let MachineStop(info) = e.kind() {
let info = info.downcast_ref::<TerminationInfo>().expect("invalid MachineStop payload");
use TerminationInfo::*;
use self::TerminationInfo::*;
let title = match info {
Exit { code, leak_check } => return Some((*code, *leak_check)),
Abort(_) => Some("abnormal termination"),
Expand Down Expand Up @@ -579,7 +579,7 @@ pub fn report_msg<'tcx>(

impl<'tcx> MiriMachine<'tcx> {
pub fn emit_diagnostic(&self, e: NonHaltingDiagnostic) {
use NonHaltingDiagnostic::*;
use self::NonHaltingDiagnostic::*;

let stacktrace = Frame::generate_stacktrace_from_stack(self.threads.active_thread_stack());
let (stacktrace, _was_pruned) = prune_stacktrace(stacktrace, self);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'tcx> MainThreadState<'tcx> {
&mut self,
this: &mut MiriInterpCx<'tcx>,
) -> InterpResult<'tcx, Poll<()>> {
use MainThreadState::*;
use self::MainThreadState::*;
match self {
Running => {
*self = TlsDtors(Default::default());
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/intrinsics/atomic.rs
Original file line number Diff line number Diff line change
@@ -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`,
Expand Down
6 changes: 3 additions & 3 deletions src/tools/miri/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use rustc_span::{sym, Symbol};
use rustc_target::abi::Size;

use crate::*;
use atomic::EvalContextExt as _;
use helpers::{check_arg_count, ToHost, ToSoft};
use simd::EvalContextExt as _;
use self::atomic::EvalContextExt as _;
use self::helpers::{check_arg_count, ToHost, ToSoft};
use self::simd::EvalContextExt as _;

impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
clippy::cast_lossless,
clippy::cast_possible_truncation,
)]
#![cfg_attr(not(bootstrap), warn(unclear_local_imports))]
// Needed for rustdoc from bootstrap (with `-Znormalize-docs`).
#![recursion_limit = "256"]

Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_target::{
use super::alloc::{check_alloc_request, 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)]
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod panic;
pub mod time;
pub mod tls;

pub use unix::{DirTable, FdTable};
pub use self::unix::{DirTable, FdTable};

/// What needs to be done after emulating an item (a shim or an intrinsic) is done.
pub enum EmulateItemResult {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_target::spec::abi::Abi;
use rustc_target::spec::PanicStrategy;

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)]
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl<'tcx> TlsDtorsState<'tcx> {
&mut self,
this: &mut MiriInterpCx<'tcx>,
) -> InterpResult<'tcx, Poll<()>> {
use TlsDtorsStatePriv::*;
use self::TlsDtorsStatePriv::*;
let new_state = 'new_state: {
match &mut self.0 {
Init => {
Expand Down
10 changes: 5 additions & 5 deletions src/tools/miri/src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,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 {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_target::abi::Size;
use crate::shims::os_str::bytes_to_os_str;
use crate::shims::unix::*;
use crate::*;
use shims::time::system_time_to_duration;
use self::shims::time::system_time_to_duration;

use self::fd::FileDescriptor;

Expand Down
8 changes: 4 additions & 4 deletions src/tools/miri/src/shims/unix/linux/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 10 additions & 10 deletions src/tools/miri/src/shims/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ mod linux;
mod macos;
mod solarish;

pub use env::UnixEnvVars;
pub use fd::{FdTable, FileDescription};
pub use fs::DirTable;
pub use self::env::UnixEnvVars;
pub use self::fd::{FdTable, FileDescription};
pub use self::fs::DirTable;
// 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 socket::EvalContextExt as _;
pub use sync::EvalContextExt as _;
pub use thread::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::socket::EvalContextExt as _;
pub use self::sync::EvalContextExt as _;
pub use self::thread::EvalContextExt as _;

// Make up some constants.
const UID: u32 = 1000;
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/windows/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/windows/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/tools/miri/src/shims/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/windows/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {}

Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/shims/x86/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bbfdd06

Please sign in to comment.