Skip to content

Commit

Permalink
Auto merge of #105890 - Nilstrieb:inline-fmt-part-1, r=jackh726
Browse files Browse the repository at this point in the history
Fix `uninlined_format_args` in compiler crates with the diagnostic migration completed

Convert all the crates that have had their diagnostic migration completed (except save_analysis because that will be deleted soon and apfloat because of the licensing problem).

Some of them have been reviewed by myself and they were all correct (though I still recommend going over all of them again for review).
  • Loading branch information
bors committed Jan 6, 2023
2 parents b85f57d + fd7a159 commit 0853d96
Show file tree
Hide file tree
Showing 91 changed files with 287 additions and 329 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2170,10 +2170,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 @@ -2185,7 +2185,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 @@ -310,7 +310,7 @@ impl Attribute {
AttrKind::Normal(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 @@ -125,27 +125,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 @@ -756,7 +756,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
3 changes: 1 addition & 2 deletions compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ impl AttrTokenStream {

assert!(
found,
"Failed to find trailing delimited group in: {:?}",
target_tokens
"Failed to find trailing delimited group in: {target_tokens:?}"
);
}
let mut flat: SmallVec<[_; 1]> = SmallVec::new();
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/util/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl fmt::Display for LitKind {
match *self {
LitKind::Byte(b) => {
let b: String = ascii::escape_default(b).map(Into::<char>::into).collect();
write!(f, "b'{}'", b)?;
write!(f, "b'{b}'")?;
}
LitKind::Char(ch) => write!(f, "'{}'", escape_char_symbol(ch))?,
LitKind::Str(sym, StrStyle::Cooked) => write!(f, "\"{}\"", escape_string_symbol(sym))?,
Expand All @@ -192,15 +192,15 @@ impl fmt::Display for LitKind {
)?;
}
LitKind::Int(n, ty) => {
write!(f, "{}", n)?;
write!(f, "{n}")?;
match ty {
ast::LitIntType::Unsigned(ty) => write!(f, "{}", ty.name())?,
ast::LitIntType::Signed(ty) => write!(f, "{}", ty.name())?,
ast::LitIntType::Unsuffixed => {}
}
}
LitKind::Float(symbol, ty) => {
write!(f, "{}", symbol)?;
write!(f, "{symbol}")?;
match ty {
ast::LitFloatType::Suffixed(ty) => write!(f, "{}", ty.name())?,
ast::LitFloatType::Unsuffixed => {}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
Err(supported_abis) => {
let mut abis = format!("`{}`", supported_abis[0]);
for m in &supported_abis[1..] {
let _ = write!(abis, ", `{}`", m);
let _ = write!(abis, ", `{m}`");
}
self.tcx.sess.emit_err(InvalidAbiClobberAbi {
abi_span: *abi_span,
Expand Down Expand Up @@ -262,7 +262,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let sub = if !valid_modifiers.is_empty() {
let mut mods = format!("`{}`", valid_modifiers[0]);
for m in &valid_modifiers[1..] {
let _ = write!(mods, ", `{}`", m);
let _ = write!(mods, ", `{m}`");
}
InvalidAsmTemplateModifierRegClassSub::SupportModifier {
class_name: class.name(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
_ => {
// Replace the ident for bindings that aren't simple.
let name = format!("__arg{}", index);
let name = format!("__arg{index}");
let ident = Ident::from_str(&name);

(ident, false)
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl std::fmt::Display for ImplTraitPosition {
ImplTraitPosition::ImplReturn => "`impl` method return",
};

write!(f, "{}", name)
write!(f, "{name}")
}
}

Expand Down Expand Up @@ -503,7 +503,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

fn orig_local_def_id(&self, node: NodeId) -> LocalDefId {
self.orig_opt_local_def_id(node)
.unwrap_or_else(|| panic!("no entry for node id: `{:?}`", node))
.unwrap_or_else(|| panic!("no entry for node id: `{node:?}`"))
}

/// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name
Expand All @@ -524,7 +524,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

fn local_def_id(&self, node: NodeId) -> LocalDefId {
self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{:?}`", node))
self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`"))
}

/// Get the previously recorded `to` local def id given the `from` local def id, obtained using
Expand Down Expand Up @@ -2197,7 +2197,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_trait_ref(&mut self, p: &TraitRef, itctx: &ImplTraitContext) -> hir::TraitRef<'hir> {
let path = match self.lower_qpath(p.ref_id, &None, &p.path, ParamMode::Explicit, itctx) {
hir::QPath::Resolved(None, path) => path,
qpath => panic!("lower_trait_ref: unexpected QPath `{:?}`", qpath),
qpath => panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
};
hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id) }
}
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ 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)
}
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)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ impl<'a> State<'a> {
ast::VisibilityKind::Restricted { path, 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_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ fn try_gate_cfg(name: Symbol, span: Span, sess: &ParseSess, features: Option<&Fe
fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &ParseSess, features: &Features) {
let (cfg, feature, has_feature) = gated_cfg;
if !has_feature(features) && !cfg_span.allows_unstable(*feature) {
let explain = format!("`cfg({})` is experimental and subject to change", cfg);
let explain = format!("`cfg({cfg})` is experimental and subject to change");
feature_err(sess, *feature, cfg_span, &explain).emit();
}
}
Expand Down Expand Up @@ -975,7 +975,7 @@ pub fn find_repr_attrs(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
}

pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
assert!(attr.has_name(sym::repr), "expected `#[repr(..)]`, found: {:?}", attr);
assert!(attr.has_name(sym::repr), "expected `#[repr(..)]`, found: {attr:?}");
use ReprAttr::*;
let mut acc = Vec::new();
let diagnostic = &sess.parse_sess.span_diagnostic;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) struct UnknownMetaItem<'a> {
// Manual implementation to be able to format `expected` items correctly.
impl<'a> IntoDiagnostic<'a> for UnknownMetaItem<'_> {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
let expected = self.expected.iter().map(|name| format!("`{}`", name)).collect::<Vec<_>>();
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
let mut diag = handler.struct_span_err_with_code(
self.span,
fluent::attr_unknown_meta_item,
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
14 changes: 6 additions & 8 deletions compiler/rustc_data_structures/src/graph/scc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,9 @@ where
.map(G::Node::new)
.map(|node| match this.start_walk_from(node) {
WalkReturn::Complete { scc_index } => scc_index,
WalkReturn::Cycle { min_depth } => panic!(
"`start_walk_node({:?})` returned cycle with depth {:?}",
node, min_depth
),
WalkReturn::Cycle { min_depth } => {
panic!("`start_walk_node({node:?})` returned cycle with depth {min_depth:?}")
}
})
.collect();

Expand Down Expand Up @@ -272,8 +271,7 @@ where
NodeState::NotVisited => return None,

NodeState::InCycleWith { parent } => panic!(
"`find_state` returned `InCycleWith({:?})`, which ought to be impossible",
parent
"`find_state` returned `InCycleWith({parent:?})`, which ought to be impossible"
),
})
}
Expand Down Expand Up @@ -369,7 +367,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 @@ -394,7 +392,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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<O: ForestObligation> ObligationForest<O> {

let counter = COUNTER.fetch_add(1, Ordering::AcqRel);

let file_path = dir.as_ref().join(format!("{:010}_{}.gv", counter, description));
let file_path = dir.as_ref().join(format!("{counter:010}_{description}.gv"));

let mut gv_file = BufWriter::new(File::create(file_path).unwrap());

Expand All @@ -47,7 +47,7 @@ impl<'a, O: ForestObligation + 'a> dot::Labeller<'a> for &'a ObligationForest<O>
}

fn node_id(&self, index: &Self::Node) -> dot::Id<'_> {
dot::Id::new(format!("obligation_{}", index)).unwrap()
dot::Id::new(format!("obligation_{index}")).unwrap()
}

fn node_label(&self, index: &Self::Node) -> dot::LabelText<'_> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl SelfProfiler {
// length can behave as a source of entropy for heap addresses, when
// ASLR is disabled and the heap is otherwise determinic.
let pid: u32 = process::id();
let filename = format!("{}-{:07}.rustc_profile", crate_name, pid);
let filename = format!("{crate_name}-{pid:07}.rustc_profile");
let path = output_directory.join(&filename);
let profiler =
Profiler::with_counter(&path, measureme::counters::Counter::by_name(counter_name)?)?;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_data_structures/src/small_c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl SmallCStr {
SmallVec::from_vec(data)
};
if let Err(e) = ffi::CStr::from_bytes_with_nul(&data) {
panic!("The string \"{}\" cannot be converted into a CStr: {}", s, e);
panic!("The string \"{s}\" cannot be converted into a CStr: {e}");
}
SmallCStr { data }
}
Expand All @@ -39,7 +39,7 @@ impl SmallCStr {
pub fn new_with_nul(s: &str) -> SmallCStr {
let b = s.as_bytes();
if let Err(e) = ffi::CStr::from_bytes_with_nul(b) {
panic!("The string \"{}\" cannot be converted into a CStr: {}", s, e);
panic!("The string \"{s}\" cannot be converted into a CStr: {e}");
}
SmallCStr { data: SmallVec::from_slice(s.as_bytes()) }
}
Expand Down Expand Up @@ -74,7 +74,7 @@ impl<'a> FromIterator<&'a str> for SmallCStr {
iter.into_iter().flat_map(|s| s.as_bytes()).copied().collect::<SmallVec<_>>();
data.push(0);
if let Err(e) = ffi::CStr::from_bytes_with_nul(&data) {
panic!("The iterator {:?} cannot be converted into a CStr: {}", data, e);
panic!("The iterator {data:?} cannot be converted into a CStr: {e}");
}
Self { data }
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_data_structures/src/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ where
// This should return just one element, otherwise it's a bug
assert!(
filter.next().is_none(),
"Collection {:#?} should have just one matching element",
self
"Collection {self:#?} should have just one matching element"
);
Some(value)
}
Expand Down
Loading

0 comments on commit 0853d96

Please sign in to comment.