diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 7fd891395fa0..427eee1a3c46 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -898,7 +898,7 @@ pub fn default(kind: SyntaxExtensionKind, edition: Edition) -> SyntaxExtension { fn get_collapse_debuginfo(sess: &Session, attrs: &[hir::Attribute], ext: bool) -> bool { let flag = sess.opts.cg.collapse_macro_debuginfo; let attr = if let Some(info) = find_attr!(attrs, CollapseDebugInfo(info) => info) { - info.clone() + *info } else if find_attr!(attrs, RustcBuiltinMacro { .. }) { CollapseMacroDebuginfo::Yes } else { diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index 71566407767c..9f40afa1861c 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -285,7 +285,7 @@ pub(crate) fn expand_cfg_attr(&self, cfg_attr: &Attribute, recursive: bool) -> V let Some((cfg_predicate, expanded_attrs)) = rustc_attr_parsing::parse_cfg_attr( cfg_attr, - &self.sess, + self.sess, self.features, self.lint_node_id, ) else { @@ -422,7 +422,7 @@ pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) { && !attr.span.allows_unstable(sym::stmt_expr_attributes) { let mut err = feature_err( - &self.sess, + self.sess, sym::stmt_expr_attributes, attr.span, msg!("attributes on expressions are experimental"), diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 9f5a01452fdc..abdfe146c85a 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1050,7 +1050,7 @@ fn gate_proc_macro_attr_item(&self, span: Span, item: &Annotatable) { return; } feature_err( - &self.cx.sess, + self.cx.sess, sym::proc_macro_hygiene, span, format!("custom attributes cannot be applied to {kind}"), @@ -1085,7 +1085,7 @@ fn visit_item(&mut self, item: &'ast ast::Item) { } if !self.cx.ecfg.features.proc_macro_hygiene() { - annotatable.visit_with(&mut GateProcMacroInput { sess: &self.cx.sess }); + annotatable.visit_with(&mut GateProcMacroInput { sess: self.cx.sess }); } } @@ -1474,7 +1474,7 @@ fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec) { } } let mut idents = Vec::new(); - collect_use_tree_leaves(&ut, &mut idents); + collect_use_tree_leaves(ut, &mut idents); idents } else { self.kind.ident().into_iter().collect() @@ -1482,7 +1482,7 @@ fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec) { } fn as_target(&self) -> Target { - Target::from_ast_item(&*self) + Target::from_ast_item(self) } } diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index fd2e4e3ec39f..3de94d9830a7 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs @@ -323,9 +323,7 @@ pub(super) fn emit_frag_parse_err( } else if bindings_name.contains(&name) { e.span_label( parser.token.span, - format!( - "there is an macro metavariable with this name in another macro matcher" - ), + "there is an macro metavariable with this name in another macro matcher", ); } else if let Some(matched_name) = rustc_span::edit_distance::find_best_match_for_name(&bindings_name[..], name, None) @@ -343,7 +341,7 @@ pub(super) fn emit_frag_parse_err( .collect::>() .join(", "); - e.span_label(parser.token.span, format!("macro metavariable not found")); + e.span_label(parser.token.span, "macro metavariable not found"); if !matched_rule_bindings_names.is_empty() { e.note(format!("available metavariable names are: {msg}")); } diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 9c327c26849e..b8325e3ce775 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -199,8 +199,8 @@ fn inner( let idx_seq = idx_first - 1; inner(&seq.tts, locs, next_metavar, seq_depth + 1); - if let Some(separator) = &seq.separator { - locs.push(MatcherLoc::SequenceSep { separator: separator.clone() }); + if let Some(separator) = seq.separator { + locs.push(MatcherLoc::SequenceSep { separator }); locs.push(MatcherLoc::SequenceKleeneOpAfterSep { idx_first }); } else { locs.push(MatcherLoc::SequenceKleeneOpNoSep { op, idx_first }); diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index eb874a27cece..a698db543759 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -214,7 +214,7 @@ fn parse_tree<'a>( // during parsing. let mut next = outer_iter.next(); let mut iter_storage; - let mut iter: &mut TokenStreamIter<'_> = match next { + let iter: &mut TokenStreamIter<'_> = match next { Some(tokenstream::TokenTree::Delimited(.., delim, tts)) if delim.skip() => { iter_storage = tts.iter(); next = iter_storage.next(); @@ -284,7 +284,7 @@ fn parse_tree<'a>( let sequence = parse(tts, part, sess, node_id, features, edition); // Get the Kleene operator and optional separator let (separator, kleene) = - parse_sep_and_kleene_op(&mut iter, delim_span.entire(), sess); + parse_sep_and_kleene_op(iter, delim_span.entire(), sess); // Count the number of captured "names" (i.e., named metavars) let num_captures = if part.is_pattern() { count_metavar_decls(&sequence) } else { 0 }; diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index dcf2cd1fa36a..7152ffcd9f30 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -396,7 +396,7 @@ fn transcribe_sequence<'tx, 'itp>( // The first time we encounter the sequence we push it to the stack. It // then gets reused (see the beginning of the loop) until we are done // repeating. - tscx.stack.push(Frame::new_sequence(seq_rep, seq.separator.clone(), seq.kleene.op)); + tscx.stack.push(Frame::new_sequence(seq_rep, seq.separator, seq.kleene.op)); } } } @@ -629,7 +629,7 @@ fn metavar_expr_concat<'tx>( ) -> PResult<'tx, TokenTree> { let dcx = tscx.psess.dcx(); let mut concatenated = String::new(); - for element in elements.into_iter() { + for element in elements { let symbol = match element { MetaVarExprConcatElem::Ident(elem) => elem.name, MetaVarExprConcatElem::Literal(elem) => *elem, @@ -747,7 +747,7 @@ fn maybe_use_metavar_location( TokenTree::Token(Token { kind, span }, spacing) => { let span = metavar_span.with_ctxt(span.ctxt()); with_metavar_spans(|mspans| mspans.insert(span, metavar_span)); - TokenTree::Token(Token { kind: kind.clone(), span }, *spacing) + TokenTree::Token(Token { kind: *kind, span }, *spacing) } TokenTree::Delimited(dspan, dspacing, delimiter, tts) => { let open = metavar_span.with_ctxt(dspan.open.ctxt()); diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs index 79ab3cab22ce..a5799d64d1ea 100644 --- a/compiler/rustc_expand/src/module.rs +++ b/compiler/rustc_expand/src/module.rs @@ -75,7 +75,7 @@ pub(crate) fn parse_external_mod( Some(span), )); let (inner_attrs, items, inner_span) = - parser.parse_mod(exp!(Eof)).map_err(|err| ModError::ParserError(err))?; + parser.parse_mod(exp!(Eof)).map_err(ModError::ParserError)?; attrs.extend(inner_attrs); (items, inner_span, mp.file_path) }; diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index 5b2482f5c1db..9aa8684677a9 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -232,7 +232,7 @@ fn enter(ecx: &mut ExtCtxt<'_>, client: DeriveClient, f: F) -> R { // We need erasure to get rid of the lifetime let ctx = Self { expansion_ctx: ecx as *mut _ as *mut (), client }; - DERIVE_EXPAND_CTX.set(&ctx, || f()) + DERIVE_EXPAND_CTX.set(&ctx, f) } /// Accesses the thread local value of the derive expansion context. diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 037afbb9f550..cb7d62ce191e 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -110,9 +110,8 @@ fn from_internal(stream: TokenStream) -> Self { // Estimate the capacity as `stream.len()` rounded up to the next power // of two to limit the number of required reallocations. let mut trees = Vec::with_capacity(stream.len().next_power_of_two()); - let mut iter = stream.iter(); - while let Some(tree) = iter.next() { + for tree in stream.iter() { let (Token { kind, span }, joint) = match tree.clone() { tokenstream::TokenTree::Delimited(span, _, mut delim, mut stream) => { // In `mk_delimited` we avoid nesting invisible delimited diff --git a/compiler/rustc_expand/src/stats.rs b/compiler/rustc_expand/src/stats.rs index 00f1c11044e0..0d60141f274e 100644 --- a/compiler/rustc_expand/src/stats.rs +++ b/compiler/rustc_expand/src/stats.rs @@ -152,7 +152,7 @@ pub(crate) fn update_macro_stats( } // The recorded size is the difference between the input and the output. - let entry = ecx.macro_stats.entry((name, macro_kind)).or_insert(MacroStat::default()); + let entry = ecx.macro_stats.entry((name, macro_kind)).or_default(); entry.uses += 1; entry.lines += num_lines; entry.bytes += num_bytes;