Skip to content
Draft
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
1 change: 0 additions & 1 deletion src/tools/clippy/clippy_lints/src/disallowed_macros.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use clippy_config::Conf;
use clippy_config::types::{DisallowedPath, create_disallowed_map};
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
28 changes: 13 additions & 15 deletions src/tools/miri/cargo-miri/src/arg.rs
Copy link
Member

@RalfJung RalfJung May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't reformat files you're not even changing in this PR. All of the Miri and Clippy changes should be undone.

Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ impl<'s, I: Iterator<Item = Cow<'s, str>>> Iterator for ArgSplitFlagValue<'_, I>
}
// These branches cannot be merged if we want to avoid the allocation in the `Borrowed` branch.
match &arg {
Cow::Borrowed(arg) =>
Cow::Borrowed(arg) => {
if let Some(suffix) = arg.strip_prefix(self.name) {
// Strip leading `name`.
if suffix.is_empty() {
@@ -55,8 +55,9 @@ impl<'s, I: Iterator<Item = Cow<'s, str>>> Iterator for ArgSplitFlagValue<'_, I>
// This argument is `name=value`; get the value.
return Some(Ok(Cow::Borrowed(suffix)));
}
},
Cow::Owned(arg) =>
}
}
Cow::Owned(arg) => {
if let Some(suffix) = arg.strip_prefix(self.name) {
// Strip leading `name`.
if suffix.is_empty() {
@@ -67,7 +68,8 @@ impl<'s, I: Iterator<Item = Cow<'s, str>>> Iterator for ArgSplitFlagValue<'_, I>
// here as a `String` cannot be subsliced (what would the lifetime be?).
return Some(Ok(Cow::Owned(suffix.to_owned())));
}
},
}
}
}
Some(Err(arg))
}
@@ -78,11 +80,9 @@ impl<'a, I: Iterator<Item = String> + 'a> ArgSplitFlagValue<'a, I> {
args: I,
name: &'a str,
) -> impl Iterator<Item = Result<String, String>> + 'a {
ArgSplitFlagValue::new(args.map(Cow::Owned), name).map(|x| {
match x {
Ok(s) => Ok(s.into_owned()),
Err(s) => Err(s.into_owned()),
}
ArgSplitFlagValue::new(args.map(Cow::Owned), name).map(|x| match x {
Ok(s) => Ok(s.into_owned()),
Err(s) => Err(s.into_owned()),
})
}
}
@@ -92,12 +92,10 @@ impl<'x: 'a, 'a, I: Iterator<Item = &'x str> + 'a> ArgSplitFlagValue<'a, I> {
args: I,
name: &'a str,
) -> impl Iterator<Item = Result<&'x str, &'x str>> + 'a {
ArgSplitFlagValue::new(args.map(Cow::Borrowed), name).map(|x| {
match x {
Ok(Cow::Borrowed(s)) => Ok(s),
Err(Cow::Borrowed(s)) => Err(s),
_ => panic!("iterator converted borrowed to owned"),
}
ArgSplitFlagValue::new(args.map(Cow::Borrowed), name).map(|x| match x {
Ok(Cow::Borrowed(s)) => Ok(s),
Err(Cow::Borrowed(s)) => Err(s),
_ => panic!("iterator converted borrowed to owned"),
})
}
}
7 changes: 3 additions & 4 deletions src/tools/miri/cargo-miri/src/phases.rs
Original file line number Diff line number Diff line change
@@ -85,10 +85,9 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
"setup" => MiriCommand::Setup,
"test" | "t" | "run" | "r" | "nextest" => MiriCommand::Forward(subcommand),
"clean" => MiriCommand::Clean,
_ =>
show_error!(
"`cargo miri` supports the following subcommands: `run`, `test`, `nextest`, `clean`, and `setup`."
),
_ => show_error!(
"`cargo miri` supports the following subcommands: `run`, `test`, `nextest`, `clean`, and `setup`."
),
};
let verbose = num_arg_flag("-v");
let quiet = has_arg_flag("-q") || has_arg_flag("--quiet");
9 changes: 6 additions & 3 deletions src/tools/miri/cargo-miri/src/setup.rs
Original file line number Diff line number Diff line change
@@ -75,10 +75,12 @@ pub fn setup(
None =>
// No-std heuristic taken from rust/src/bootstrap/config.rs
// (https://github.com/rust-lang/rust/blob/25b5af1b3a0b9e2c0c57b223b2d0e3e203869b2c/src/bootstrap/config.rs#L549-L555).
{
target.contains("-none")
|| target.contains("nvptx")
|| target.contains("switch")
|| target.contains("-uefi"),
|| target.contains("-uefi")
}
Some(val) => val != "0",
};
let sysroot_config = if no_std {
@@ -170,13 +172,14 @@ pub fn setup(
.when_build_required(notify)
.build_from_source(&rust_src);
match status {
Ok(SysrootStatus::AlreadyCached) =>
Ok(SysrootStatus::AlreadyCached) => {
if !quiet && show_setup {
eprintln!(
"A sysroot for Miri is already available in `{}`.",
sysroot_dir.display()
);
},
}
}
Ok(SysrootStatus::SysrootBuilt) => {
// Print what `notify` prepared.
eprint!("{after_build_output}");
12 changes: 6 additions & 6 deletions src/tools/miri/src/bin/miri.rs
Original file line number Diff line number Diff line change
@@ -555,12 +555,12 @@ fn main() {
"abort" => miri::IsolatedOp::Reject(miri::RejectOpWith::Abort),
"hide" => miri::IsolatedOp::Reject(miri::RejectOpWith::NoWarning),
"warn" => miri::IsolatedOp::Reject(miri::RejectOpWith::Warning),
"warn-nobacktrace" =>
miri::IsolatedOp::Reject(miri::RejectOpWith::WarningWithoutBacktrace),
_ =>
show_error!(
"-Zmiri-isolation-error must be `abort`, `hide`, `warn`, or `warn-nobacktrace`"
),
"warn-nobacktrace" => {
miri::IsolatedOp::Reject(miri::RejectOpWith::WarningWithoutBacktrace)
}
_ => show_error!(
"-Zmiri-isolation-error must be `abort`, `hide`, `warn`, or `warn-nobacktrace`"
),
};
} else if arg == "-Zmiri-ignore-leaks" {
miri_config.ignore_leaks = true;
74 changes: 38 additions & 36 deletions src/tools/miri/src/borrow_tracker/mod.rs
Original file line number Diff line number Diff line change
@@ -253,14 +253,12 @@ impl GlobalStateInner {
machine: &MiriMachine<'_>,
) -> AllocState {
match self.borrow_tracker_method {
BorrowTrackerMethod::StackedBorrows =>
AllocState::StackedBorrows(Box::new(RefCell::new(Stacks::new_allocation(
id, alloc_size, self, kind, machine,
)))),
BorrowTrackerMethod::TreeBorrows =>
AllocState::TreeBorrows(Box::new(RefCell::new(Tree::new_allocation(
id, alloc_size, self, kind, machine,
)))),
BorrowTrackerMethod::StackedBorrows => AllocState::StackedBorrows(Box::new(
RefCell::new(Stacks::new_allocation(id, alloc_size, self, kind, machine)),
)),
BorrowTrackerMethod::TreeBorrows => AllocState::TreeBorrows(Box::new(RefCell::new(
Tree::new_allocation(id, alloc_size, self, kind, machine),
))),
}
}
}
@@ -324,8 +322,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.tcx.tcx.dcx().warn("Stacked Borrows does not support named pointers; `miri_pointer_name` is a no-op");
interp_ok(())
}
BorrowTrackerMethod::TreeBorrows =>
this.tb_give_pointer_debug_name(ptr, nth_parent, name),
BorrowTrackerMethod::TreeBorrows => {
this.tb_give_pointer_debug_name(ptr, nth_parent, name)
}
}
}

@@ -424,16 +423,16 @@ impl AllocState {
machine: &MiriMachine<'tcx>,
) -> InterpResult<'tcx> {
match self {
AllocState::StackedBorrows(sb) =>
sb.borrow_mut().before_memory_read(alloc_id, prov_extra, range, machine),
AllocState::TreeBorrows(tb) =>
tb.borrow_mut().before_memory_access(
AccessKind::Read,
alloc_id,
prov_extra,
range,
machine,
),
AllocState::StackedBorrows(sb) => {
sb.borrow_mut().before_memory_read(alloc_id, prov_extra, range, machine)
}
AllocState::TreeBorrows(tb) => tb.borrow_mut().before_memory_access(
AccessKind::Read,
alloc_id,
prov_extra,
range,
machine,
),
}
}

@@ -445,16 +444,16 @@ impl AllocState {
machine: &MiriMachine<'tcx>,
) -> InterpResult<'tcx> {
match self {
AllocState::StackedBorrows(sb) =>
sb.get_mut().before_memory_write(alloc_id, prov_extra, range, machine),
AllocState::TreeBorrows(tb) =>
tb.get_mut().before_memory_access(
AccessKind::Write,
alloc_id,
prov_extra,
range,
machine,
),
AllocState::StackedBorrows(sb) => {
sb.get_mut().before_memory_write(alloc_id, prov_extra, range, machine)
}
AllocState::TreeBorrows(tb) => tb.get_mut().before_memory_access(
AccessKind::Write,
alloc_id,
prov_extra,
range,
machine,
),
}
}

@@ -466,10 +465,12 @@ impl AllocState {
machine: &MiriMachine<'tcx>,
) -> InterpResult<'tcx> {
match self {
AllocState::StackedBorrows(sb) =>
sb.get_mut().before_memory_deallocation(alloc_id, prov_extra, size, machine),
AllocState::TreeBorrows(tb) =>
tb.get_mut().before_memory_deallocation(alloc_id, prov_extra, size, machine),
AllocState::StackedBorrows(sb) => {
sb.get_mut().before_memory_deallocation(alloc_id, prov_extra, size, machine)
}
AllocState::TreeBorrows(tb) => {
tb.get_mut().before_memory_deallocation(alloc_id, prov_extra, size, machine)
}
}
}

@@ -490,8 +491,9 @@ impl AllocState {
) -> InterpResult<'tcx> {
match self {
AllocState::StackedBorrows(_sb) => interp_ok(()),
AllocState::TreeBorrows(tb) =>
tb.borrow_mut().release_protector(machine, global, tag, alloc_id),
AllocState::TreeBorrows(tb) => {
tb.borrow_mut().release_protector(machine, global, tag, alloc_id)
}
}
}
}
38 changes: 21 additions & 17 deletions src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -96,8 +96,9 @@ impl fmt::Display for InvalidationCause {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
InvalidationCause::Access(kind) => write!(f, "{kind}"),
InvalidationCause::Retag(perm, info) =>
write!(f, "{perm:?} {retag}", retag = info.summary()),
InvalidationCause::Retag(perm, info) => {
write!(f, "{perm:?} {retag}", retag = info.summary())
}
}
}
}
@@ -250,7 +251,7 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
None => {
last_creation.retag.permission = Some(perm);
}
Some(previous) =>
Some(previous) => {
if previous != perm {
// 'Split up' the creation event.
let previous_range = last_creation.retag.range;
@@ -259,7 +260,8 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
new_event.retag.range = alloc_range(self.offset, previous_range.end());
new_event.retag.permission = Some(perm);
self.history.creations.push(new_event);
},
}
}
}
}

@@ -281,8 +283,9 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
}
(*range, InvalidationCause::Retag(permission.unwrap(), *info))
}
Operation::Access(AccessOp { kind, range, .. }) =>
(*range, InvalidationCause::Access(*kind)),
Operation::Access(AccessOp { kind, range, .. }) => {
(*range, InvalidationCause::Access(*kind))
}
Operation::Dealloc(_) => {
// This can be reached, but never be relevant later since the entire allocation is
// gone now.
@@ -434,17 +437,17 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
ProtectorKind::StrongProtector => "strongly protected",
};
match self.operation {
Operation::Dealloc(_) =>
err_sb_ub(format!("deallocating while item {item:?} is {protected}",), vec![], None),
Operation::Dealloc(_) => {
err_sb_ub(format!("deallocating while item {item:?} is {protected}",), vec![], None)
}
Operation::Retag(RetagOp { orig_tag: tag, .. })
| Operation::Access(AccessOp { tag, .. }) =>
err_sb_ub(
format!(
"not granting access to tag {tag:?} because that would remove {item:?} which is {protected}",
),
vec![],
tag.and_then(|tag| self.get_logs_relevant_to(tag, Some(item.tag()))),
| Operation::Access(AccessOp { tag, .. }) => err_sb_ub(
format!(
"not granting access to tag {tag:?} because that would remove {item:?} which is {protected}",
),
vec![],
tag.and_then(|tag| self.get_logs_relevant_to(tag, Some(item.tag()))),
),
}
}

@@ -472,8 +475,9 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
}
let cause = match self.operation {
Operation::Dealloc(_) => format!(" due to deallocation"),
Operation::Access(AccessOp { kind, tag, .. }) =>
format!(" due to {kind:?} access for {tag:?}"),
Operation::Access(AccessOp { kind, tag, .. }) => {
format!(" due to {kind:?} access for {tag:?}")
}
Operation::Retag(RetagOp { orig_tag, permission, new_tag, .. }) => {
let permission = permission
.expect("start_grant should set the current permission before popping a tag");
5 changes: 3 additions & 2 deletions src/tools/miri/src/borrow_tracker/stacked_borrows/stack.rs
Original file line number Diff line number Diff line change
@@ -64,8 +64,9 @@ impl Stack {
Permission::Disabled => left.perm() == Permission::SharedReadWrite,
// Unique and SharedReadOnly can terminate a SharedReadWrite block, so only remove
// them if they are both unreachable and not directly after a SharedReadWrite.
Permission::Unique | Permission::SharedReadOnly =>
left.perm() == Permission::SharedReadWrite || tags.contains(&this.tag()),
Permission::Unique | Permission::SharedReadOnly => {
left.perm() == Permission::SharedReadWrite || tags.contains(&this.tag())
}
};

if should_keep {
8 changes: 3 additions & 5 deletions src/tools/miri/src/borrow_tracker/tree_borrows/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -526,11 +526,9 @@ impl DisplayFmt {
/// Print extra text if the tag has a protector.
fn print_protector(&self, protector: Option<&ProtectorKind>) -> &'static str {
protector
.map(|p| {
match *p {
ProtectorKind::WeakProtector => " Weakly protected",
ProtectorKind::StrongProtector => " Strongly protected",
}
.map(|p| match *p {
ProtectorKind::WeakProtector => " Weakly protected",
ProtectorKind::StrongProtector => " Strongly protected",
})
.unwrap_or("")
}
13 changes: 7 additions & 6 deletions src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs
Original file line number Diff line number Diff line change
@@ -336,10 +336,10 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// - if the pointer is not reborrowed (raw pointer) or if `zero_size` is set
// then we override the size to do a zero-length reborrow.
let reborrow_size = match new_perm {
NewPermission { zero_size: false, .. } =>
this.size_and_align_of_mplace(place)?
.map(|(size, _)| size)
.unwrap_or(place.layout.size),
NewPermission { zero_size: false, .. } => this
.size_and_align_of_mplace(place)?
.map(|(size, _)| size)
.unwrap_or(place.layout.size),
_ => Size::from_bytes(0),
};
trace!("Creating new permission: {:?} with size {:?}", new_perm, reborrow_size);
@@ -385,8 +385,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
) -> InterpResult<'tcx, ImmTy<'tcx>> {
let this = self.eval_context_mut();
let new_perm = match val.layout.ty.kind() {
&ty::Ref(_, pointee, mutability) =>
NewPermission::from_ref_ty(pointee, mutability, kind, this),
&ty::Ref(_, pointee, mutability) => {
NewPermission::from_ref_ty(pointee, mutability, kind, this)
}
_ => None,
};
if let Some(new_perm) = new_perm {
Loading