Rollup merge of #96027 - matthiaskrgr:clippy_rec, r=fee1-dead

remove function parameters only used in recursion
This commit is contained in:
Dylan DPC 2022-04-15 20:50:48 +02:00 committed by GitHub
commit 937b0a04cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 30 deletions

View File

@ -77,7 +77,6 @@ use crate::mbe::{KleeneOp, TokenTree};
use rustc_ast::token::{self, DocComment, Nonterminal, NonterminalKind, Token}; use rustc_ast::token::{self, DocComment, Nonterminal, NonterminalKind, Token};
use rustc_parse::parser::{NtOrTt, Parser}; use rustc_parse::parser::{NtOrTt, Parser};
use rustc_session::parse::ParseSess;
use rustc_span::symbol::MacroRulesNormalizedIdent; use rustc_span::symbol::MacroRulesNormalizedIdent;
use rustc_span::Span; use rustc_span::Span;
@ -128,9 +127,8 @@ pub(super) enum MatcherLoc {
Eof, Eof,
} }
pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<MatcherLoc> { pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec<MatcherLoc> {
fn inner( fn inner(
sess: &ParseSess,
tts: &[TokenTree], tts: &[TokenTree],
locs: &mut Vec<MatcherLoc>, locs: &mut Vec<MatcherLoc>,
next_metavar: &mut usize, next_metavar: &mut usize,
@ -147,7 +145,7 @@ pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<Match
locs.push(MatcherLoc::Delimited); locs.push(MatcherLoc::Delimited);
locs.push(MatcherLoc::Token { token: open_token }); locs.push(MatcherLoc::Token { token: open_token });
inner(sess, &delimited.tts, locs, next_metavar, seq_depth); inner(&delimited.tts, locs, next_metavar, seq_depth);
locs.push(MatcherLoc::Token { token: close_token }); locs.push(MatcherLoc::Token { token: close_token });
} }
TokenTree::Sequence(_, seq) => { TokenTree::Sequence(_, seq) => {
@ -162,7 +160,7 @@ pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<Match
let op = seq.kleene.op; let op = seq.kleene.op;
let idx_first = locs.len(); let idx_first = locs.len();
let idx_seq = idx_first - 1; let idx_seq = idx_first - 1;
inner(sess, &seq.tts, locs, next_metavar, seq_depth + 1); inner(&seq.tts, locs, next_metavar, seq_depth + 1);
if let Some(separator) = &seq.separator { if let Some(separator) = &seq.separator {
locs.push(MatcherLoc::SequenceSep { separator: separator.clone() }); locs.push(MatcherLoc::SequenceSep { separator: separator.clone() });
@ -197,7 +195,7 @@ pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<Match
let mut locs = vec![]; let mut locs = vec![];
let mut next_metavar = 0; let mut next_metavar = 0;
inner(sess, matcher, &mut locs, &mut next_metavar, /* seq_depth */ 0); inner(matcher, &mut locs, &mut next_metavar, /* seq_depth */ 0);
// A final entry is needed for eof. // A final entry is needed for eof.
locs.push(MatcherLoc::Eof); locs.push(MatcherLoc::Eof);

View File

@ -435,7 +435,7 @@ pub fn compile_declarative_macro(
), ),
]; ];
// Convert it into `MatcherLoc` form. // Convert it into `MatcherLoc` form.
let argument_gram = mbe::macro_parser::compute_locs(&sess.parse_sess, &argument_gram); let argument_gram = mbe::macro_parser::compute_locs(&argument_gram);
let parser = Parser::new(&sess.parse_sess, body, true, rustc_parse::MACRO_ARGUMENTS); let parser = Parser::new(&sess.parse_sess, body, true, rustc_parse::MACRO_ARGUMENTS);
let mut tt_parser = let mut tt_parser =
@ -478,7 +478,7 @@ pub fn compile_declarative_macro(
) )
.pop() .pop()
.unwrap(); .unwrap();
valid &= check_lhs_nt_follows(&sess.parse_sess, features, &def, &tt); valid &= check_lhs_nt_follows(&sess.parse_sess, &def, &tt);
return tt; return tt;
} }
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs") sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs")
@ -540,7 +540,7 @@ pub fn compile_declarative_macro(
// Ignore the delimiters around the matcher. // Ignore the delimiters around the matcher.
match lhs { match lhs {
mbe::TokenTree::Delimited(_, delimited) => { mbe::TokenTree::Delimited(_, delimited) => {
mbe::macro_parser::compute_locs(&sess.parse_sess, &delimited.tts) mbe::macro_parser::compute_locs(&delimited.tts)
} }
_ => sess.parse_sess.span_diagnostic.span_bug(def.span, "malformed macro lhs"), _ => sess.parse_sess.span_diagnostic.span_bug(def.span, "malformed macro lhs"),
} }
@ -563,16 +563,11 @@ pub fn compile_declarative_macro(
})) }))
} }
fn check_lhs_nt_follows( fn check_lhs_nt_follows(sess: &ParseSess, def: &ast::Item, lhs: &mbe::TokenTree) -> bool {
sess: &ParseSess,
features: &Features,
def: &ast::Item,
lhs: &mbe::TokenTree,
) -> bool {
// lhs is going to be like TokenTree::Delimited(...), where the // lhs is going to be like TokenTree::Delimited(...), where the
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens. // entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
if let mbe::TokenTree::Delimited(_, delimited) = lhs { if let mbe::TokenTree::Delimited(_, delimited) = lhs {
check_matcher(sess, features, def, &delimited.tts) check_matcher(sess, def, &delimited.tts)
} else { } else {
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters"; let msg = "invalid macro matcher; matchers must be contained in balanced delimiters";
sess.span_diagnostic.span_err(lhs.span(), msg); sess.span_diagnostic.span_err(lhs.span(), msg);
@ -632,16 +627,11 @@ fn check_rhs(sess: &ParseSess, rhs: &mbe::TokenTree) -> bool {
false false
} }
fn check_matcher( fn check_matcher(sess: &ParseSess, def: &ast::Item, matcher: &[mbe::TokenTree]) -> bool {
sess: &ParseSess,
features: &Features,
def: &ast::Item,
matcher: &[mbe::TokenTree],
) -> bool {
let first_sets = FirstSets::new(matcher); let first_sets = FirstSets::new(matcher);
let empty_suffix = TokenSet::empty(); let empty_suffix = TokenSet::empty();
let err = sess.span_diagnostic.err_count(); let err = sess.span_diagnostic.err_count();
check_matcher_core(sess, features, def, &first_sets, matcher, &empty_suffix); check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix);
err == sess.span_diagnostic.err_count() err == sess.span_diagnostic.err_count()
} }
@ -955,7 +945,6 @@ impl<'tt> TokenSet<'tt> {
// see `FirstSets::new`. // see `FirstSets::new`.
fn check_matcher_core<'tt>( fn check_matcher_core<'tt>(
sess: &ParseSess, sess: &ParseSess,
features: &Features,
def: &ast::Item, def: &ast::Item,
first_sets: &FirstSets<'tt>, first_sets: &FirstSets<'tt>,
matcher: &'tt [mbe::TokenTree], matcher: &'tt [mbe::TokenTree],
@ -1008,7 +997,7 @@ fn check_matcher_core<'tt>(
token::CloseDelim(d.delim), token::CloseDelim(d.delim),
span.close, span.close,
)); ));
check_matcher_core(sess, features, def, first_sets, &d.tts, &my_suffix); check_matcher_core(sess, def, first_sets, &d.tts, &my_suffix);
// don't track non NT tokens // don't track non NT tokens
last.replace_with_irrelevant(); last.replace_with_irrelevant();
@ -1040,8 +1029,7 @@ fn check_matcher_core<'tt>(
// At this point, `suffix_first` is built, and // At this point, `suffix_first` is built, and
// `my_suffix` is some TokenSet that we can use // `my_suffix` is some TokenSet that we can use
// for checking the interior of `seq_rep`. // for checking the interior of `seq_rep`.
let next = let next = check_matcher_core(sess, def, first_sets, &seq_rep.tts, my_suffix);
check_matcher_core(sess, features, def, first_sets, &seq_rep.tts, my_suffix);
if next.maybe_empty { if next.maybe_empty {
last.add_all(&next); last.add_all(&next);
} else { } else {

View File

@ -158,7 +158,6 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
#[allow(dead_code)] // FIXME(81658): should be used + lint reinstated after #83171 relands. #[allow(dead_code)] // FIXME(81658): should be used + lint reinstated after #83171 relands.
fn check_for_self_assign(&mut self, assign: &'tcx hir::Expr<'tcx>) { fn check_for_self_assign(&mut self, assign: &'tcx hir::Expr<'tcx>) {
fn check_for_self_assign_helper<'tcx>( fn check_for_self_assign_helper<'tcx>(
tcx: TyCtxt<'tcx>,
typeck_results: &'tcx ty::TypeckResults<'tcx>, typeck_results: &'tcx ty::TypeckResults<'tcx>,
lhs: &'tcx hir::Expr<'tcx>, lhs: &'tcx hir::Expr<'tcx>,
rhs: &'tcx hir::Expr<'tcx>, rhs: &'tcx hir::Expr<'tcx>,
@ -177,7 +176,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
} }
(hir::ExprKind::Field(lhs_l, ident_l), hir::ExprKind::Field(lhs_r, ident_r)) => { (hir::ExprKind::Field(lhs_l, ident_l), hir::ExprKind::Field(lhs_r, ident_r)) => {
if ident_l == ident_r { if ident_l == ident_r {
return check_for_self_assign_helper(tcx, typeck_results, lhs_l, lhs_r); return check_for_self_assign_helper(typeck_results, lhs_l, lhs_r);
} }
return false; return false;
} }
@ -188,7 +187,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
} }
if let hir::ExprKind::Assign(lhs, rhs, _) = assign.kind { if let hir::ExprKind::Assign(lhs, rhs, _) = assign.kind {
if check_for_self_assign_helper(self.tcx, self.typeck_results(), lhs, rhs) if check_for_self_assign_helper(self.typeck_results(), lhs, rhs)
&& !assign.span.from_expansion() && !assign.span.from_expansion()
{ {
let is_field_assign = matches!(lhs.kind, hir::ExprKind::Field(..)); let is_field_assign = matches!(lhs.kind, hir::ExprKind::Field(..));