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

inline format!() args #114019

Closed
Closed
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 compiler/rustc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn set_windows_exe_options() {
let mut manifest = env::current_dir().unwrap();
manifest.push(WINDOWS_MANIFEST_FILE);

println!("cargo:rerun-if-changed={}", WINDOWS_MANIFEST_FILE);
println!("cargo:rerun-if-changed={WINDOWS_MANIFEST_FILE}");
// Embed the Windows application manifest file.
println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFEST:EMBED");
println!("cargo:rustc-link-arg-bin=rustc-main=/MANIFESTINPUT:{}", manifest.to_str().unwrap());
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ pub trait LayoutCalculator {
}
_ => assert!(
start == Bound::Unbounded && end == Bound::Unbounded,
"nonscalar layout for layout_scalar_valid_range type: {:#?}",
st,
"nonscalar layout for layout_scalar_valid_range type: {st:#?}",
),
}

Expand Down Expand Up @@ -463,7 +462,7 @@ pub trait LayoutCalculator {
min = 0;
max = 0;
}
assert!(min <= max, "discriminant range is {}...{}", min, max);
assert!(min <= max, "discriminant range is {min}...{max}");
let (min_ity, signed) = discr_range_of_repr(min, max); //Integer::repr_discr(tcx, ty, &repr, min, max);

let mut align = dl.aggregate_align;
Expand Down Expand Up @@ -537,8 +536,7 @@ pub trait LayoutCalculator {
// space necessary to represent would have to be discarded (or layout is wrong
// on thinking it needs 16 bits)
panic!(
"layout decided on a larger discriminant type ({:?}) than typeck ({:?})",
min_ity, typeck_ity
"layout decided on a larger discriminant type ({min_ity:?}) than typeck ({typeck_ity:?})"
);
// However, it is fine to make discr type however large (as an optimisation)
// after this point – we’ll just truncate the value we load in codegen.
Expand Down
17 changes: 6 additions & 11 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl TargetDataLayout {
16 => 1 << 15,
32 => 1 << 31,
64 => 1 << 47,
bits => panic!("obj_size_bound: unknown pointer bit size {}", bits),
bits => panic!("obj_size_bound: unknown pointer bit size {bits}"),
}
}

Expand All @@ -342,7 +342,7 @@ impl TargetDataLayout {
16 => I16,
32 => I32,
64 => I64,
bits => panic!("ptr_sized_integer: unknown pointer bit size {}", bits),
bits => panic!("ptr_sized_integer: unknown pointer bit size {bits}"),
}
}

Expand Down Expand Up @@ -399,7 +399,7 @@ impl FromStr for Endian {
match s {
"little" => Ok(Self::Little),
"big" => Ok(Self::Big),
_ => Err(format!(r#"unknown endian: "{}""#, s)),
_ => Err(format!(r#"unknown endian: "{s}""#)),
}
}
}
Expand Down Expand Up @@ -456,7 +456,7 @@ impl Size {
pub fn bits(self) -> u64 {
#[cold]
fn overflow(bytes: u64) -> ! {
panic!("Size::bits: {} bytes in bits doesn't fit in u64", bytes)
panic!("Size::bits: {bytes} bytes in bits doesn't fit in u64")
}

self.bytes().checked_mul(8).unwrap_or_else(|| overflow(self.bytes()))
Expand Down Expand Up @@ -1179,12 +1179,7 @@ impl FieldsShape {
unreachable!("FieldsShape::offset: `Primitive`s have no fields")
}
FieldsShape::Union(count) => {
assert!(
i < count.get(),
"tried to access field {} of union with {} fields",
i,
count
);
assert!(i < count.get(), "tried to access field {i} of union with {count} fields");
Size::ZERO
}
FieldsShape::Array { stride, count } => {
Expand Down Expand Up @@ -1294,7 +1289,7 @@ impl Abi {
Primitive::Int(_, signed) => signed,
_ => false,
},
_ => panic!("`is_signed` on non-scalar ABI {:?}", self),
_ => panic!("`is_signed` on non-scalar ABI {self:?}"),
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_apfloat/src/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ impl<S: Semantics> fmt::Display for IeeeFloat<S> {

// Exponent always at least two digits if we do not truncate zeros.
if truncate_zero {
write!(f, "{:+}", exp)?;
write!(f, "{exp:+}")?;
} else {
write!(f, "{:+03}", exp)?;
Comment on lines -573 to -575
Copy link
Member

Choose a reason for hiding this comment

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

I think apfloat changes need to be reverted?

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if that is still the case, cc @eddyb

Copy link
Contributor

Choose a reason for hiding this comment

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

but it does make sense to leave this out of this PR, because it at least requires a submodule? update

write!(f, "{exp:+03}")?;
}

return Ok(());
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ fn validate_generic_param_order(
GenericParamKind::Type { .. } => (ParamKindOrd::TypeOrConst, ident.to_string()),
GenericParamKind::Const { ty, .. } => {
let ty = pprust::ty_to_string(ty);
(ParamKindOrd::TypeOrConst, format!("const {}: {}", ident, ty))
(ParamKindOrd::TypeOrConst, format!("const {ident}: {ty}"))
}
};
param_idents.push((kind, ord_kind, bounds, idx, ident));
Expand Down Expand Up @@ -1463,15 +1463,12 @@ fn deny_equality_constraints(
let Some(arg) = args.args.last() else {
continue;
};
(
format!(", {} = {}", assoc, ty),
arg.span().shrink_to_hi(),
)
(format!(", {assoc} = {ty}"), arg.span().shrink_to_hi())
}
_ => continue,
},
None => (
format!("<{} = {}>", assoc, ty),
format!("<{assoc} = {ty}>"),
trait_segment.span().shrink_to_hi(),
),
};
Expand Down
46 changes: 20 additions & 26 deletions compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
desc,
);

err.span_label(borrow_span, format!("{} is borrowed here", borrow_desc));
err.span_label(span, format!("use of borrowed {}", borrow_desc));
err.span_label(borrow_span, format!("{borrow_desc} is borrowed here"));
err.span_label(span, format!("use of borrowed {borrow_desc}"));
err
}

Expand All @@ -51,8 +51,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_opt_via: &str,
old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let via =
|msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {})", msg) };
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
let mut err = struct_span_err!(
self,
new_loan_span,
Expand Down Expand Up @@ -143,9 +142,9 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
);
err.span_label(
new_loan_span,
format!("{} construction occurs here{}", container_name, opt_via),
format!("{container_name} construction occurs here{opt_via}"),
);
err.span_label(old_loan_span, format!("borrow occurs here{}", old_opt_via));
err.span_label(old_loan_span, format!("borrow occurs here{old_opt_via}"));
if let Some(previous_end_span) = previous_end_span {
err.span_label(previous_end_span, "borrow ends here");
}
Expand Down Expand Up @@ -173,13 +172,10 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
opt_via,
kind_new,
);
err.span_label(
new_loan_span,
format!("{}borrow occurs here{}", second_borrow_desc, opt_via),
);
err.span_label(new_loan_span, format!("{second_borrow_desc}borrow occurs here{opt_via}"));
err.span_label(
old_loan_span,
format!("{} construction occurs here{}", container_name, old_opt_via),
format!("{container_name} construction occurs here{old_opt_via}"),
);
if let Some(previous_end_span) = previous_end_span {
err.span_label(previous_end_span, "borrow from closure ends here");
Expand All @@ -199,8 +195,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
msg_old: &str,
old_load_end_span: Option<Span>,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
let via =
|msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {})", msg) };
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
let mut err = struct_span_err!(
self,
span,
Expand All @@ -216,22 +211,21 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {

if msg_new == "" {
// If `msg_new` is empty, then this isn't a borrow of a union field.
err.span_label(span, format!("{} borrow occurs here", kind_new));
err.span_label(old_span, format!("{} borrow occurs here", kind_old));
err.span_label(span, format!("{kind_new} borrow occurs here"));
err.span_label(old_span, format!("{kind_old} borrow occurs here"));
} else {
// If `msg_new` isn't empty, then this a borrow of a union field.
err.span_label(
span,
format!(
"{} borrow of {} -- which overlaps with {} -- occurs here",
kind_new, msg_new, msg_old,
"{kind_new} borrow of {msg_new} -- which overlaps with {msg_old} -- occurs here",
),
);
err.span_label(old_span, format!("{} borrow occurs here{}", kind_old, via(msg_old)));
}

if let Some(old_load_end_span) = old_load_end_span {
err.span_label(old_load_end_span, format!("{} borrow ends here", kind_old));
err.span_label(old_load_end_span, format!("{kind_old} borrow ends here"));
}
err
}
Expand All @@ -250,8 +244,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
desc,
);

err.span_label(borrow_span, format!("{} is borrowed here", desc));
err.span_label(span, format!("{} is assigned to here but it was already borrowed", desc));
err.span_label(borrow_span, format!("{desc} is borrowed here"));
err.span_label(span, format!("{desc} is assigned to here but it was already borrowed"));
err
}

Expand Down Expand Up @@ -330,7 +324,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
optional_adverb_for_moved: &str,
moved_path: Option<String>,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let moved_path = moved_path.map(|mp| format!(": `{}`", mp)).unwrap_or_default();
let moved_path = moved_path.map(|mp| format!(": `{mp}`")).unwrap_or_default();

struct_span_err!(
self,
Expand Down Expand Up @@ -369,8 +363,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
immutable_place,
immutable_section,
);
err.span_label(mutate_span, format!("cannot {}", action));
err.span_label(immutable_span, format!("value is immutable in {}", immutable_section));
err.span_label(mutate_span, format!("cannot {action}"));
err.span_label(immutable_span, format!("value is immutable in {immutable_section}"));
err
}

Expand Down Expand Up @@ -428,7 +422,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {

err.span_label(
span,
format!("{}s a {} data owned by the current function", return_kind, reference_desc),
format!("{return_kind}s a {reference_desc} data owned by the current function"),
);

err
Expand All @@ -449,8 +443,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
"{closure_kind} may outlive the current {scope}, but it borrows {borrowed_path}, \
which is owned by the current {scope}",
);
err.span_label(capture_span, format!("{} is borrowed here", borrowed_path))
.span_label(closure_span, format!("may outlive borrowed value {}", borrowed_path));
err.span_label(capture_span, format!("{borrowed_path} is borrowed here"))
.span_label(closure_span, format!("may outlive borrowed value {borrowed_path}"));
err
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
return;
}
let index = self.borrow_set.get_index_of(&location).unwrap_or_else(|| {
panic!("could not find BorrowIndex for location {:?}", location);
panic!("could not find BorrowIndex for location {location:?}");
});

trans.gen(index);
Expand Down
Loading