Skip to content

Commit

Permalink
Auto merge of rust-lang#114250 - matthiaskrgr:rollup-0r0dhrr, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#110056 (Fix the example in document for WaitTimeoutResult::timed_out)
 - rust-lang#112655 (Mark `map_or` as `#[must_use]`)
 - rust-lang#114018 (Make `--error-format human-annotate-rs` handle multiple files)
 - rust-lang#114068 (inline format!() args up to and including rustc_middle (2))
 - rust-lang#114223 (Documentation: Fix Stilted Language in Vec->Indexing)
 - rust-lang#114227 (Add tidy check for stray rustfix files)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 30, 2023
2 parents 483ef5f + b9f17f1 commit 89acdae
Show file tree
Hide file tree
Showing 101 changed files with 439 additions and 466 deletions.
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
19 changes: 7 additions & 12 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,17 +1179,12 @@ 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 } => {
let i = u64::try_from(i).unwrap();
assert!(i < count, "tried to access field {} of array with {} fields", i, count);
assert!(i < count, "tried to access field {i} of array with {count} fields");
stride * i
}
FieldsShape::Arbitrary { ref offsets, .. } => offsets[FieldIdx::from_usize(i)],
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
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
16 changes: 7 additions & 9 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
|| named_pos.contains_key(&idx)
|| args.reg_args.contains(idx)
{
let msg = format!("invalid reference to argument at index {}", idx);
let msg = format!("invalid reference to argument at index {idx}");
let mut err = ecx.struct_span_err(span, msg);
err.span_label(span, "from here");

Expand All @@ -588,9 +588,9 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
""
};
let msg = match positional_args {
0 => format!("no {}arguments were given", positional),
1 => format!("there is 1 {}argument", positional),
x => format!("there are {} {}arguments", x, positional),
0 => format!("no {positional}arguments were given"),
1 => format!("there is 1 {positional}argument"),
x => format!("there are {x} {positional}arguments"),
};
err.note(msg);

Expand Down Expand Up @@ -624,7 +624,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
match args.named_args.get(&Symbol::intern(name)) {
Some(&idx) => Some(idx),
None => {
let msg = format!("there is no argument named `{}`", name);
let msg = format!("there is no argument named `{name}`");
let span = arg.position_span;
ecx.struct_span_err(
template_span
Expand Down Expand Up @@ -697,8 +697,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
err.span_label(sp, msg);
err.help(format!(
"if this argument is intentionally unused, \
consider using it in an asm comment: `\"/*{} */\"`",
help_str
consider using it in an asm comment: `\"/*{help_str} */\"`"
));
err.emit();
}
Expand All @@ -712,8 +711,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
}
err.help(format!(
"if these arguments are intentionally unused, \
consider using them in an asm comment: `\"/*{} */\"`",
help_str
consider using them in an asm comment: `\"/*{help_str} */\"`"
));
err.emit();
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_builtin_macros/src/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn cs_clone_simple(
}
_ => cx.span_bug(
trait_span,
format!("unexpected substructure in simple `derive({})`", name),
format!("unexpected substructure in simple `derive({name})`"),
),
}
}
Expand Down Expand Up @@ -178,10 +178,10 @@ fn cs_clone(
vdata = &variant.data;
}
EnumTag(..) | AllFieldlessEnum(..) => {
cx.span_bug(trait_span, format!("enum tags in `derive({})`", name,))
cx.span_bug(trait_span, format!("enum tags in `derive({name})`",))
}
StaticEnum(..) | StaticStruct(..) => {
cx.span_bug(trait_span, format!("associated function in `derive({})`", name))
cx.span_bug(trait_span, format!("associated function in `derive({name})`"))
}
}

Expand All @@ -193,7 +193,7 @@ fn cs_clone(
let Some(ident) = field.name else {
cx.span_bug(
trait_span,
format!("unnamed field in normal struct in `derive({})`", name,),
format!("unnamed field in normal struct in `derive({name})`",),
);
};
let call = subcall(cx, field);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ where
let fields = fields
.iter()
.enumerate()
.map(|(i, &span)| getarg(cx, span, Symbol::intern(&format!("_field{}", i)), i))
.map(|(i, &span)| getarg(cx, span, Symbol::intern(&format!("_field{i}")), i))
.collect();

cx.expr_call(trait_span, path_expr, fields)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/encodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn encodable_substructure(
for (i, &FieldInfo { name, ref self_expr, span, .. }) in fields.iter().enumerate() {
let name = match name {
Some(id) => id.name,
None => Symbol::intern(&format!("_field{}", i)),
None => Symbol::intern(&format!("_field{i}")),
};
let self_ref = cx.expr_addr_of(span, self_expr.clone());
let enc =
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ impl<'a> MethodDef<'a> {
.iter()
.enumerate()
.skip(1)
.map(|(arg_count, _selflike_arg)| format!("__arg{}", arg_count)),
.map(|(arg_count, _selflike_arg)| format!("__arg{arg_count}")),
)
.collect::<Vec<String>>();

Expand All @@ -1181,7 +1181,7 @@ impl<'a> MethodDef<'a> {
let get_tag_pieces = |cx: &ExtCtxt<'_>| {
let tag_idents: Vec<_> = prefixes
.iter()
.map(|name| Ident::from_str_and_span(&format!("{}_tag", name), span))
.map(|name| Ident::from_str_and_span(&format!("{name}_tag"), span))
.collect();

let mut tag_exprs: Vec<_> = tag_idents
Expand Down Expand Up @@ -1521,7 +1521,7 @@ impl<'a> TraitDef<'a> {
}

fn mk_pattern_ident(&self, prefix: &str, i: usize) -> Ident {
Ident::from_str_and_span(&format!("{}_{}", prefix, i), self.span)
Ident::from_str_and_span(&format!("{prefix}_{i}"), self.span)
}

fn create_struct_pattern_fields(
Expand Down Expand Up @@ -1602,8 +1602,7 @@ impl<'a> TraitDef<'a> {
sp,
ast::CRATE_NODE_ID,
format!(
"{} slice in a packed struct that derives a built-in trait",
ty
"{ty} slice in a packed struct that derives a built-in trait"
),
rustc_lint_defs::BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive
);
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn make_format_args(
err.span_suggestion(
unexpanded_fmt_span.shrink_to_lo(),
"you might be missing a string literal to format with",
format!("\"{}\", ", sugg_fmt),
format!("\"{sugg_fmt}\", "),
Applicability::MaybeIncorrect,
);
}
Expand Down Expand Up @@ -668,7 +668,7 @@ fn report_invalid_references(
let num_args_desc = match args.explicit_args().len() {
0 => "no arguments were given".to_string(),
1 => "there is 1 argument".to_string(),
n => format!("there are {} arguments", n),
n => format!("there are {n} arguments"),
};

let mut e;
Expand Down Expand Up @@ -780,7 +780,7 @@ fn report_invalid_references(
if num_placeholders == 1 {
"is 1 argument".to_string()
} else {
format!("are {} arguments", num_placeholders)
format!("are {num_placeholders} arguments")
},
),
);
Expand Down Expand Up @@ -811,7 +811,7 @@ fn report_invalid_references(
};
e = ecx.struct_span_err(
span,
format!("invalid reference to positional {} ({})", arg_list, num_args_desc),
format!("invalid reference to positional {arg_list} ({num_args_desc})"),
);
e.note("positional arguments are zero-based");
}
Expand Down
17 changes: 7 additions & 10 deletions compiler/rustc_builtin_macros/src/format_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ pub(crate) mod printf {
'-' => c_left = true,
'+' => c_plus = true,
_ => {
return Err(Some(format!(
"the flag `{}` is unknown or unsupported",
c
)));
return Err(Some(format!("the flag `{c}` is unknown or unsupported")));
}
}
}
Expand Down Expand Up @@ -268,21 +265,21 @@ pub(crate) mod printf {
impl Num {
fn from_str(s: &str, arg: Option<&str>) -> Self {
if let Some(arg) = arg {
Num::Arg(arg.parse().unwrap_or_else(|_| panic!("invalid format arg `{:?}`", arg)))
Num::Arg(arg.parse().unwrap_or_else(|_| panic!("invalid format arg `{arg:?}`")))
} else if s == "*" {
Num::Next
} else {
Num::Num(s.parse().unwrap_or_else(|_| panic!("invalid format num `{:?}`", s)))
Num::Num(s.parse().unwrap_or_else(|_| panic!("invalid format num `{s:?}`")))
}
}

fn translate(&self, s: &mut String) -> std::fmt::Result {
use std::fmt::Write;
match *self {
Num::Num(n) => write!(s, "{}", n),
Num::Num(n) => write!(s, "{n}"),
Num::Arg(n) => {
let n = n.checked_sub(1).ok_or(std::fmt::Error)?;
write!(s, "{}$", n)
write!(s, "{n}$")
}
Num::Next => write!(s, "*"),
}
Expand Down Expand Up @@ -626,8 +623,8 @@ pub mod shell {
impl Substitution<'_> {
pub fn as_str(&self) -> String {
match self {
Substitution::Ordinal(n, _) => format!("${}", n),
Substitution::Name(n, _) => format!("${}", n),
Substitution::Ordinal(n, _) => format!("${n}"),
Substitution::Name(n, _) => format!("${n}"),
Substitution::Escape(_) => "$$".into(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/global_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl AllocFnFactory<'_, '_> {
let mut abi_args = ThinVec::new();
let mut i = 0;
let mut mk = || {
let name = Ident::from_str_and_span(&format!("arg{}", i), self.span);
let name = Ident::from_str_and_span(&format!("arg{i}"), self.span);
i += 1;
name
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_builtin_macros/src/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
== prev_item.path.segments[0].ident.name
{
format!(
"only one `#[{}]` attribute is allowed on any given function",
path_str,
"only one `#[{path_str}]` attribute is allowed on any given function",
)
} else {
format!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub fn expand_include<'cx>(
Ok(None) => {
if self.p.token != token::Eof {
let token = pprust::token_to_string(&self.p.token);
let msg = format!("expected item, found `{}`", token);
let msg = format!("expected item, found `{token}`");
self.p.struct_span_err(self.p.token.span, msg).emit();
}

Expand Down
Loading

0 comments on commit 89acdae

Please sign in to comment.