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

Apply clippy::uninlined_format_args fixes #102804

Closed
wants to merge 1 commit into from
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
4 changes: 2 additions & 2 deletions compiler/rustc_apfloat/src/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,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)?;
write!(f, "{exp:+03}")?;
}

return Ok(());
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_apfloat/tests/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,9 @@ fn to_string() {
let to_string = |d: f64, precision: usize, width: usize| {
let x = Double::from_f64(d);
if precision == 0 {
format!("{:1$}", x, width)
format!("{x:width$}")
} else {
format!("{:2$.1$}", x, precision, width)
format!("{x:width$.precision$}")
}
};
assert_eq!("10", to_string(10.0, 6, 3));
Expand All @@ -985,9 +985,9 @@ fn to_string() {
let to_string = |d: f64, precision: usize, width: usize| {
let x = Double::from_f64(d);
if precision == 0 {
format!("{:#1$}", x, width)
format!("{x:#width$}")
} else {
format!("{:#2$.1$}", x, precision, width)
format!("{x:#width$.precision$}")
}
};
assert_eq!("10", to_string(10.0, 6, 3));
Expand Down
28 changes: 14 additions & 14 deletions compiler/rustc_apfloat/tests/ppc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ fn ppc_double_double_add_special() {
let a2 = DoubleDouble::from_bits(op2);
a1 = a1.add_r(a2, round).value;

assert_eq!(expected, a1.category(), "{:#x} + {:#x}", op1, op2);
assert_eq!(expected, a1.category(), "{op1:#x} + {op2:#x}");
}
{
let a1 = DoubleDouble::from_bits(op1);
let mut a2 = DoubleDouble::from_bits(op2);
a2 = a2.add_r(a1, round).value;

assert_eq!(expected, a2.category(), "{:#x} + {:#x}", op2, op1);
assert_eq!(expected, a2.category(), "{op2:#x} + {op1:#x}");
}
}
}
Expand Down Expand Up @@ -141,14 +141,14 @@ fn ppc_double_double_add() {
let a2 = DoubleDouble::from_bits(op2);
a1 = a1.add_r(a2, round).value;

assert_eq!(expected, a1.to_bits(), "{:#x} + {:#x}", op1, op2);
assert_eq!(expected, a1.to_bits(), "{op1:#x} + {op2:#x}");
}
{
let a1 = DoubleDouble::from_bits(op1);
let mut a2 = DoubleDouble::from_bits(op2);
a2 = a2.add_r(a1, round).value;

assert_eq!(expected, a2.to_bits(), "{:#x} + {:#x}", op2, op1);
assert_eq!(expected, a2.to_bits(), "{op2:#x} + {op1:#x}");
}
}
}
Expand Down Expand Up @@ -177,7 +177,7 @@ fn ppc_double_double_subtract() {
let a2 = DoubleDouble::from_bits(op2);
a1 = a1.sub_r(a2, round).value;

assert_eq!(expected, a1.to_bits(), "{:#x} - {:#x}", op1, op2);
assert_eq!(expected, a1.to_bits(), "{op1:#x} - {op2:#x}");
}
}

Expand Down Expand Up @@ -210,14 +210,14 @@ fn ppc_double_double_multiply_special() {
let a2 = DoubleDouble::from_bits(op2);
a1 = a1.mul_r(a2, round).value;

assert_eq!(expected, a1.category(), "{:#x} * {:#x}", op1, op2);
assert_eq!(expected, a1.category(), "{op1:#x} * {op2:#x}");
}
{
let a1 = DoubleDouble::from_bits(op1);
let mut a2 = DoubleDouble::from_bits(op2);
a2 = a2.mul_r(a1, round).value;

assert_eq!(expected, a2.category(), "{:#x} * {:#x}", op2, op1);
assert_eq!(expected, a2.category(), "{op2:#x} * {op1:#x}");
}
}
}
Expand Down Expand Up @@ -296,14 +296,14 @@ fn ppc_double_double_multiply() {
let a2 = DoubleDouble::from_bits(op2);
a1 = a1.mul_r(a2, round).value;

assert_eq!(expected, a1.to_bits(), "{:#x} * {:#x}", op1, op2);
assert_eq!(expected, a1.to_bits(), "{op1:#x} * {op2:#x}");
}
{
let a1 = DoubleDouble::from_bits(op1);
let mut a2 = DoubleDouble::from_bits(op2);
a2 = a2.mul_r(a1, round).value;

assert_eq!(expected, a2.to_bits(), "{:#x} * {:#x}", op2, op1);
assert_eq!(expected, a2.to_bits(), "{op2:#x} * {op1:#x}");
}
}
}
Expand All @@ -327,7 +327,7 @@ fn ppc_double_double_divide() {
let a2 = DoubleDouble::from_bits(op2);
a1 = a1.div_r(a2, round).value;

assert_eq!(expected, a1.to_bits(), "{:#x} / {:#x}", op1, op2);
assert_eq!(expected, a1.to_bits(), "{op1:#x} / {op2:#x}");
}
}

Expand All @@ -353,7 +353,7 @@ fn ppc_double_double_remainder() {
let a2 = DoubleDouble::from_bits(op2);
let result = a1.ieee_rem(a2).value;

assert_eq!(expected, result.to_bits(), "ieee_rem({:#x}, {:#x})", op1, op2);
assert_eq!(expected, result.to_bits(), "ieee_rem({op1:#x}, {op2:#x})");
}
}

Expand Down Expand Up @@ -381,7 +381,7 @@ fn ppc_double_double_mod() {
let a2 = DoubleDouble::from_bits(op2);
let r = (a1 % a2).value;

assert_eq!(expected, r.to_bits(), "fmod({:#x}, {:#x})", op1, op2);
assert_eq!(expected, r.to_bits(), "fmod({op1:#x}, {op2:#x})");
}
}

Expand Down Expand Up @@ -429,7 +429,7 @@ fn ppc_double_double_compare() {
for (op1, op2, expected) in data {
let a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
assert_eq!(expected, a1.partial_cmp(&a2), "compare({:#x}, {:#x})", op1, op2,);
assert_eq!(expected, a1.partial_cmp(&a2), "compare({op1:#x}, {op2:#x})",);
}
}

Expand All @@ -451,7 +451,7 @@ fn ppc_double_double_bitwise_eq() {
for (op1, op2, expected) in data {
let a1 = DoubleDouble::from_bits(op1);
let a2 = DoubleDouble::from_bits(op2);
assert_eq!(expected, a1.bitwise_eq(a2), "{:#x} = {:#x}", op1, op2);
assert_eq!(expected, a1.bitwise_eq(a2), "{op1:#x} = {op2:#x}");
}
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct Lifetime {

impl fmt::Debug for Lifetime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "lifetime({}: {})", self.id, self)
write!(f, "lifetime({}: {self})", self.id)
}
}

Expand Down Expand Up @@ -2120,10 +2120,10 @@ impl fmt::Display for InlineAsmTemplatePiece {
Ok(())
}
Self::Placeholder { operand_idx, modifier: Some(modifier), .. } => {
write!(f, "{{{}:{}}}", operand_idx, modifier)
write!(f, "{{{operand_idx}:{modifier}}}")
}
Self::Placeholder { operand_idx, modifier: None, .. } => {
write!(f, "{{{}}}", operand_idx)
write!(f, "{{{operand_idx}}}")
}
}
}
Expand All @@ -2135,7 +2135,7 @@ impl InlineAsmTemplatePiece {
use fmt::Write;
let mut out = String::new();
for p in s.iter() {
let _ = write!(out, "{}", p);
let _ = write!(out, "{p}");
}
out
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/ast_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ impl HasTokens for Attribute {
match &self.kind {
AttrKind::Normal(normal) => normal.tokens.as_ref(),
kind @ AttrKind::DocComment(..) => {
panic!("Called tokens on doc comment attr {:?}", kind)
panic!("Called tokens on doc comment attr {kind:?}")
}
}
}
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
Some(match &mut self.kind {
AttrKind::Normal(normal) => &mut normal.tokens,
kind @ AttrKind::DocComment(..) => {
panic!("Called tokens_mut on doc comment attr {:?}", kind)
panic!("Called tokens_mut on doc comment attr {kind:?}")
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl Attribute {
AttrKind::Normal(ref normal) => normal
.tokens
.as_ref()
.unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self))
.unwrap_or_else(|| panic!("attribute is missing tokens: {self:?}"))
.to_attr_token_stream()
.to_tokenstream(),
AttrKind::DocComment(comment_kind, data) => TokenStream::new(vec![TokenTree::Token(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/expand/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub enum AllocatorKind {
impl AllocatorKind {
pub fn fn_name(&self, base: Symbol) -> String {
match *self {
AllocatorKind::Global => format!("__rg_{}", base),
AllocatorKind::Default => format!("__rdl_{}", base),
AllocatorKind::Global => format!("__rg_{base}"),
AllocatorKind::Default => format!("__rdl_{base}"),
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,27 @@ impl fmt::Display for Lit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Lit { kind, symbol, suffix } = *self;
match kind {
Byte => write!(f, "b'{}'", symbol)?,
Char => write!(f, "'{}'", symbol)?,
Str => write!(f, "\"{}\"", symbol)?,
Byte => write!(f, "b'{symbol}'")?,
Char => write!(f, "'{symbol}'")?,
Str => write!(f, "\"{symbol}\"")?,
StrRaw(n) => write!(
f,
"r{delim}\"{string}\"{delim}",
delim = "#".repeat(n as usize),
string = symbol
)?,
ByteStr => write!(f, "b\"{}\"", symbol)?,
ByteStr => write!(f, "b\"{symbol}\"")?,
ByteStrRaw(n) => write!(
f,
"br{delim}\"{string}\"{delim}",
delim = "#".repeat(n as usize),
string = symbol
)?,
Integer | Float | Bool | Err => write!(f, "{}", symbol)?,
Integer | Float | Bool | Err => write!(f, "{symbol}")?,
}

if let Some(suffix) = suffix {
write!(f, "{}", suffix)?;
write!(f, "{suffix}")?;
}

Ok(())
Expand Down Expand Up @@ -706,7 +706,7 @@ impl Token {
_ => return None,
},
SingleQuote => match joint.kind {
Ident(name, false) => Lifetime(Symbol::intern(&format!("'{}", name))),
Ident(name, false) => Lifetime(Symbol::intern(&format!("'{name}"))),
_ => return None,
},

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ impl TokenStream {

pub fn from_ast(node: &(impl HasAttrs + HasSpan + HasTokens + fmt::Debug)) -> TokenStream {
let Some(tokens) = node.tokens() else {
panic!("missing tokens for node at {:?}: {:?}", node.span(), node);
panic!("missing tokens for node at {:?}: {node:?}", node.span());
};
let attrs = node.attrs();
let attr_stream = if attrs.is_empty() {
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,25 @@ fn doc_comment_to_string(
data: Symbol,
) -> String {
match (comment_kind, attr_style) {
(CommentKind::Line, ast::AttrStyle::Outer) => format!("///{}", data),
(CommentKind::Line, ast::AttrStyle::Inner) => format!("//!{}", data),
(CommentKind::Block, ast::AttrStyle::Outer) => format!("/**{}*/", data),
(CommentKind::Block, ast::AttrStyle::Inner) => format!("/*!{}*/", data),
(CommentKind::Line, ast::AttrStyle::Outer) => format!("///{data}"),
(CommentKind::Line, ast::AttrStyle::Inner) => format!("//!{data}"),
(CommentKind::Block, ast::AttrStyle::Outer) => format!("/**{data}*/"),
(CommentKind::Block, ast::AttrStyle::Inner) => format!("/*!{data}*/"),
}
}

pub fn literal_to_string(lit: token::Lit) -> String {
let token::Lit { kind, symbol, suffix } = lit;
let mut out = match kind {
token::Byte => format!("b'{}'", symbol),
token::Char => format!("'{}'", symbol),
token::Str => format!("\"{}\"", symbol),
token::Byte => format!("b'{symbol}'"),
token::Char => format!("'{symbol}'"),
token::Str => format!("\"{symbol}\""),
token::StrRaw(n) => {
format!("r{delim}\"{string}\"{delim}", delim = "#".repeat(n as usize), string = symbol)
format!("r{delim}\"{symbol}\"{delim}", delim = "#".repeat(n as usize))
}
token::ByteStr => format!("b\"{}\"", symbol),
token::ByteStr => format!("b\"{symbol}\""),
token::ByteStrRaw(n) => {
format!("br{delim}\"{string}\"{delim}", delim = "#".repeat(n as usize), string = symbol)
format!("br{delim}\"{symbol}\"{delim}", delim = "#".repeat(n as usize))
}
token::Integer | token::Float | token::Bool | token::Err => symbol.to_string(),
};
Expand Down Expand Up @@ -381,7 +381,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
let st = match style {
ast::StrStyle::Cooked => format!("\"{}\"", st.escape_debug()),
ast::StrStyle::Raw(n) => {
format!("r{delim}\"{string}\"{delim}", delim = "#".repeat(n as usize), string = st)
format!("r{delim}\"{st}\"{delim}", delim = "#".repeat(n as usize))
}
};
self.word(st)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_ast::ModKind;
use rustc_span::symbol::Ident;

fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String {
format!("{}{}", State::to_string(|s| s.print_visibility(vis)), s)
format!("{}{s}", State::to_string(|s| s.print_visibility(vis)))
}

impl<'a> State<'a> {
Expand Down Expand Up @@ -417,9 +417,9 @@ impl<'a> State<'a> {
ast::VisibilityKind::Restricted { ref path, id: _, shorthand } => {
let path = Self::to_string(|s| s.print_path(path, false, 0));
if shorthand && (path == "crate" || path == "self" || path == "super") {
self.word_nbsp(format!("pub({})", path))
self.word_nbsp(format!("pub({path})"))
} else {
self.word_nbsp(format!("pub(in {})", path))
self.word_nbsp(format!("pub(in {path})"))
}
}
ast::VisibilityKind::Inherited => {}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/graph/dominators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ impl<Node: Idx> Dominators<Node> {
}

pub fn immediate_dominator(&self, node: Node) -> Node {
assert!(self.is_reachable(node), "node {:?} is not reachable", node);
assert!(self.is_reachable(node), "node {node:?} is not reachable");
self.immediate_dominators[node].unwrap()
}

pub fn dominators(&self, node: Node) -> Iter<'_, Node> {
assert!(self.is_reachable(node), "node {:?} is not reachable", node);
assert!(self.is_reachable(node), "node {node:?} is not reachable");
Iter { dominators: self, node: Some(node) }
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/graph/iterate/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ fn dfs_debug() {
let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3), (3, 0)]);
let mut dfs = DepthFirstSearch::new(&graph).with_start_node(0);
dfs.complete_search();
assert_eq!(format!("{{0, 1, 2, 3}}"), format!("{:?}", dfs));
assert_eq!(format!("{{0, 1, 2, 3}}"), format!("{dfs:?}"));
}
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/graph/scc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ where
previous_node = previous;
}
// Only InCycleWith nodes were added to the reverse linked list.
other => panic!("Invalid previous link while compressing cycle: {:?}", other),
other => panic!("Invalid previous link while compressing cycle: {other:?}"),
}

debug!("find_state: parent_state = {:?}", node_state);
Expand All @@ -395,7 +395,7 @@ where
// NotVisited can not be part of a cycle since it should
// have instead gotten explored.
NodeState::NotVisited | NodeState::InCycleWith { .. } => {
panic!("invalid parent state: {:?}", node_state)
panic!("invalid parent state: {node_state:?}")
}
}
}
Expand Down
Loading