diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-11-21 20:07:32 +0100 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-11-21 20:13:40 +0100 |
| commit | 21a870515b18e5b2b90435d0f1a6d3089b5217ae (patch) | |
| tree | 4e2c8766f7f64f8a122f38338db2614f1f909a63 /compiler/rustc_parse/src | |
| parent | 0ff861096449f47956521b40e5e4e88caa7fe27c (diff) | |
| download | rust-21a870515b18e5b2b90435d0f1a6d3089b5217ae.tar.gz rust-21a870515b18e5b2b90435d0f1a6d3089b5217ae.zip | |
Fix `clippy::needless_borrow` in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/lexer/mod.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/lexer/tokentrees.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/validate_attr.rs | 2 |
7 files changed, 20 insertions, 20 deletions
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index f2eed5c9be5..6e0765f74fe 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -75,7 +75,7 @@ pub(crate) fn parse_token_trees<'a>( let mut buffer = Vec::with_capacity(1); for unmatched in unmatched_delims { - if let Some(err) = make_unclosed_delims_error(unmatched, &sess) { + if let Some(err) = make_unclosed_delims_error(unmatched, sess) { err.buffer(&mut buffer); } } @@ -362,7 +362,7 @@ impl<'a> StringReader<'a> { if contains_text_flow_control_chars(content) { let span = self.mk_sp(start, self.pos); self.sess.buffer_lint_with_diagnostic( - &TEXT_DIRECTION_CODEPOINT_IN_COMMENT, + TEXT_DIRECTION_CODEPOINT_IN_COMMENT, span, ast::CRATE_NODE_ID, "unicode codepoint changing visible direction of text present in comment", @@ -683,7 +683,7 @@ impl<'a> StringReader<'a> { } else { // Before Rust 2021, only emit a lint for migration. self.sess.buffer_lint_with_diagnostic( - &RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX, + RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX, prefix_span, ast::CRATE_NODE_ID, format!("prefix `{prefix}` is unknown"), diff --git a/compiler/rustc_parse/src/lexer/tokentrees.rs b/compiler/rustc_parse/src/lexer/tokentrees.rs index db795ce9f72..e646f5dfd85 100644 --- a/compiler/rustc_parse/src/lexer/tokentrees.rs +++ b/compiler/rustc_parse/src/lexer/tokentrees.rs @@ -97,7 +97,7 @@ impl<'a> TokenTreesReader<'a> { report_suspicious_mismatch_block( &mut err, &self.diag_info, - &self.string_reader.sess.source_map(), + self.string_reader.sess.source_map(), *delim, ) } @@ -164,7 +164,7 @@ impl<'a> TokenTreesReader<'a> { unclosed_delimiter = Some(sp); }; for (brace, brace_span) in &self.diag_info.open_braces { - if same_indentation_level(&sm, self.token.span, *brace_span) + if same_indentation_level(sm, self.token.span, *brace_span) && brace == &close_delim { // high likelihood of these two corresponding @@ -271,7 +271,7 @@ impl<'a> TokenTreesReader<'a> { report_suspicious_mismatch_block( &mut err, &self.diag_info, - &self.string_reader.sess.source_map(), + self.string_reader.sess.source_map(), delim, ); err.span_label(self.token.span, "unexpected closing delimiter"); diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 57bc865a0ee..ecb840f067e 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1281,11 +1281,11 @@ impl<'a> Parser<'a> { (BinOpKind::Ge, AssocOp::GreaterEqual | AssocOp::Greater) => { let expr_to_str = |e: &Expr| { self.span_to_snippet(e.span) - .unwrap_or_else(|_| pprust::expr_to_string(&e)) + .unwrap_or_else(|_| pprust::expr_to_string(e)) }; err.chaining_sugg = Some(ComparisonOperatorsCannotBeChainedSugg::SplitComparison { span: inner_op.span.shrink_to_hi(), - middle_term: expr_to_str(&r1), + middle_term: expr_to_str(r1), }); false // Keep the current parse behavior, where the AST is `(x < y) < z`. } @@ -1506,7 +1506,7 @@ impl<'a> Parser<'a> { pub(super) fn maybe_report_ambiguous_plus(&mut self, impl_dyn_multi: bool, ty: &Ty) { if impl_dyn_multi { - self.sess.emit_err(AmbiguousPlus { sum_ty: pprust::ty_to_string(&ty), span: ty.span }); + self.sess.emit_err(AmbiguousPlus { sum_ty: pprust::ty_to_string(ty), span: ty.span }); } } @@ -1939,7 +1939,7 @@ impl<'a> Parser<'a> { self.sess.emit_err(IncorrectAwait { span, sugg_span: (span, applicability), - expr: self.span_to_snippet(expr.span).unwrap_or_else(|_| pprust::expr_to_string(&expr)), + expr: self.span_to_snippet(expr.span).unwrap_or_else(|_| pprust::expr_to_string(expr)), question_mark: if is_question { "?" } else { "" }, }); diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index d8e99d34016..79567eb3898 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1060,7 +1060,7 @@ impl<'a> Parser<'a> { match &*components { // 1e2 [IdentLike(i)] => { - DestructuredFloat::Single(Symbol::intern(&i), span) + DestructuredFloat::Single(Symbol::intern(i), span) } // 1. [IdentLike(i), Punct('.')] => { @@ -1072,7 +1072,7 @@ impl<'a> Parser<'a> { } else { (span, span) }; - let symbol = Symbol::intern(&i); + let symbol = Symbol::intern(i); DestructuredFloat::TrailingDot(symbol, ident_span, dot_span) } // 1.2 | 1.2e3 @@ -1088,8 +1088,8 @@ impl<'a> Parser<'a> { } else { (span, span, span) }; - let symbol1 = Symbol::intern(&i1); - let symbol2 = Symbol::intern(&i2); + let symbol1 = Symbol::intern(i1); + let symbol2 = Symbol::intern(i2); DestructuredFloat::MiddleDot(symbol1, ident1_span, dot_span, symbol2, ident2_span) } // 1e+ | 1e- (recovered) @@ -2052,7 +2052,7 @@ impl<'a> Parser<'a> { Err(err) => { let span = token.uninterpolated_span(); self.bump(); - report_lit_error(&self.sess, err, lit, span); + report_lit_error(self.sess, err, lit, span); // Pack possible quotes and prefixes from the original literal into // the error literal's symbol so they can be pretty-printed faithfully. let suffixless_lit = token::Lit::new(lit.kind, lit.symbol, None); @@ -3207,7 +3207,7 @@ impl<'a> Parser<'a> { if let Some((ident, _)) = self.token.ident() && !self.token.is_reserved_ident() && self.look_ahead(1, |t| { - AssocOp::from_token(&t).is_some() + AssocOp::from_token(t).is_some() || matches!(t.kind, token::OpenDelim(_)) || t.kind == token::Dot }) diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index d124ea571ab..23886b1208b 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2271,7 +2271,7 @@ impl<'a> Parser<'a> { } else { &[token::Semi, token::OpenDelim(Delimiter::Brace)] }; - if let Err(mut err) = self.expected_one_of_not_found(&[], &expected) { + if let Err(mut err) = self.expected_one_of_not_found(&[], expected) { if self.token.kind == token::CloseDelim(Delimiter::Brace) { // The enclosing `mod`, `trait` or `impl` is being closed, so keep the `fn` in // the AST for typechecking. diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 5cec3f5762d..15491cac56a 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -541,7 +541,7 @@ impl<'a> Parser<'a> { } self.sess - .emit_err(AmbiguousRangePattern { span: pat.span, pat: pprust::pat_to_string(&pat) }); + .emit_err(AmbiguousRangePattern { span: pat.span, pat: pprust::pat_to_string(pat) }); } /// Parse `&pat` / `&mut pat`. @@ -641,7 +641,7 @@ impl<'a> Parser<'a> { self.sess.emit_err(if changed_any_binding { InvalidMutInPattern::NestedIdent { span: lo.to(pat.span), - pat: pprust::pat_to_string(&pat), + pat: pprust::pat_to_string(pat), } } else { InvalidMutInPattern::NonIdent { span: lo.until(pat.span) } diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs index e6c46fc2528..cbe75b3dab6 100644 --- a/compiler/rustc_parse/src/validate_attr.rs +++ b/compiler/rustc_parse/src/validate_attr.rs @@ -188,7 +188,7 @@ fn emit_malformed_attribute( } suggestions.sort(); if should_warn(name) { - sess.buffer_lint(&ILL_FORMED_ATTRIBUTE_INPUT, span, ast::CRATE_NODE_ID, msg); + sess.buffer_lint(ILL_FORMED_ATTRIBUTE_INPUT, span, ast::CRATE_NODE_ID, msg); } else { sess.span_diagnostic .struct_span_err(span, error_msg) |
