Merge #10440
10440: Fix Clippy warnings and replace some `if let`s with `match` r=Veykril a=arzg I decided to try fixing a bunch of Clippy warnings. I am aware of this project’s opinion of Clippy (I have read both [rust-lang/clippy#5537](https://github.com/rust-lang/rust-clippy/issues/5537) and [rust-analyzer/rowan#57 (comment)](https://github.com/rust-analyzer/rowan/pull/57#discussion_r415676159)), so I totally understand if part of or the entirety of this PR is rejected. In particular, I can see how the semicolons and `if let` vs `match` commits provide comparatively little benefit when compared to the ensuing churn. I tried to separate each kind of change into its own commit to make it easier to discard certain changes. I also only applied Clippy suggestions where I thought they provided a definite improvement to the code (apart from semicolons, which is IMO more of a formatting/consistency question than a linting question). In the end I accumulated a list of 28 Clippy lints I ignored entirely. Sidenote: I should really have asked about this on Zulip before going through all 1,555 `if let`s in the codebase to decide which ones definitely look better as `match` :P Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
This commit is contained in:
@@ -67,11 +67,11 @@ pub(crate) mod entry_points {
|
||||
}
|
||||
|
||||
pub(crate) fn stmt(p: &mut Parser) {
|
||||
expressions::stmt(p, expressions::StmtWithSemi::No, true)
|
||||
expressions::stmt(p, expressions::StmtWithSemi::No, true);
|
||||
}
|
||||
|
||||
pub(crate) fn stmt_optional_semi(p: &mut Parser) {
|
||||
expressions::stmt(p, expressions::StmtWithSemi::Optional, false)
|
||||
expressions::stmt(p, expressions::StmtWithSemi::Optional, false);
|
||||
}
|
||||
|
||||
pub(crate) fn visibility(p: &mut Parser) {
|
||||
@@ -84,7 +84,7 @@ pub(crate) mod entry_points {
|
||||
}
|
||||
|
||||
pub(crate) fn item(p: &mut Parser) {
|
||||
items::item_or_macro(p, true)
|
||||
items::item_or_macro(p, true);
|
||||
}
|
||||
|
||||
pub(crate) fn macro_items(p: &mut Parser) {
|
||||
@@ -109,7 +109,7 @@ pub(crate) mod entry_points {
|
||||
}
|
||||
|
||||
pub(crate) fn attr(p: &mut Parser) {
|
||||
attributes::outer_attrs(p)
|
||||
attributes::outer_attrs(p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,8 +128,7 @@ pub(crate) fn reparser(
|
||||
EXTERN_ITEM_LIST => items::extern_item_list,
|
||||
TOKEN_TREE if first_child? == T!['{'] => items::token_tree,
|
||||
ASSOC_ITEM_LIST => match parent? {
|
||||
IMPL => items::assoc_item_list,
|
||||
TRAIT => items::assoc_item_list,
|
||||
IMPL | TRAIT => items::assoc_item_list,
|
||||
_ => return None,
|
||||
},
|
||||
ITEM_LIST => items::item_list,
|
||||
@@ -246,7 +245,7 @@ fn name_r(p: &mut Parser, recovery: TokenSet) {
|
||||
}
|
||||
|
||||
fn name(p: &mut Parser) {
|
||||
name_r(p, TokenSet::EMPTY)
|
||||
name_r(p, TokenSet::EMPTY);
|
||||
}
|
||||
|
||||
fn name_ref(p: &mut Parser) {
|
||||
|
||||
@@ -2,13 +2,13 @@ use super::*;
|
||||
|
||||
pub(super) fn inner_attrs(p: &mut Parser) {
|
||||
while p.at(T![#]) && p.nth(1) == T![!] {
|
||||
attr(p, true)
|
||||
attr(p, true);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn outer_attrs(p: &mut Parser) {
|
||||
while p.at(T![#]) {
|
||||
attr(p, false)
|
||||
attr(p, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ pub(super) fn expr_block_contents(p: &mut Parser) {
|
||||
continue;
|
||||
}
|
||||
|
||||
stmt(p, StmtWithSemi::Yes, false)
|
||||
stmt(p, StmtWithSemi::Yes, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)>
|
||||
_ => {
|
||||
// test full_range_expr
|
||||
// fn foo() { xs[..]; }
|
||||
for &op in [T![..=], T![..]].iter() {
|
||||
for op in [T![..=], T![..]] {
|
||||
if p.at(op) {
|
||||
m = p.start();
|
||||
p.bump(op);
|
||||
@@ -468,12 +468,12 @@ fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
||||
let m = lhs.precede(p);
|
||||
p.bump(T![.]);
|
||||
if p.at(IDENT) || p.at(INT_NUMBER) {
|
||||
name_ref_or_index(p)
|
||||
name_ref_or_index(p);
|
||||
} else if p.at(FLOAT_NUMBER) {
|
||||
// FIXME: How to recover and instead parse INT + T![.]?
|
||||
p.bump_any();
|
||||
} else {
|
||||
p.error("expected field name or number")
|
||||
p.error("expected field name or number");
|
||||
}
|
||||
m.complete(p, FIELD_EXPR)
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ fn match_expr(p: &mut Parser) -> CompletedMarker {
|
||||
if p.at(T!['{']) {
|
||||
match_arm_list(p);
|
||||
} else {
|
||||
p.error("expected `{`")
|
||||
p.error("expected `{`");
|
||||
}
|
||||
m.complete(p, MATCH_EXPR)
|
||||
}
|
||||
@@ -602,7 +602,7 @@ fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
|
||||
if p.at(T!['{']) {
|
||||
stmt_list(p);
|
||||
} else {
|
||||
p.error("expected a block")
|
||||
p.error("expected a block");
|
||||
}
|
||||
m.complete(p, BLOCK_EXPR)
|
||||
}
|
||||
@@ -639,7 +639,7 @@ fn meta_var_expr(p: &mut Parser) -> CompletedMarker {
|
||||
}
|
||||
_ => {
|
||||
while !p.at(R_DOLLAR) {
|
||||
p.bump_any()
|
||||
p.bump_any();
|
||||
}
|
||||
p.bump(R_DOLLAR);
|
||||
m.complete(p, ERROR)
|
||||
|
||||
@@ -34,7 +34,7 @@ fn generic_param(p: &mut Parser) {
|
||||
T![const] => const_param(p, m),
|
||||
_ => {
|
||||
m.abandon(p);
|
||||
p.err_and_bump("expected type parameter")
|
||||
p.err_and_bump("expected type parameter");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ fn type_param(p: &mut Parser, m: Marker) {
|
||||
// test type_param_default
|
||||
// struct S<T = i32>;
|
||||
p.bump(T![=]);
|
||||
types::type_(p)
|
||||
types::type_(p);
|
||||
}
|
||||
m.complete(p, TYPE_PARAM);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use super::*;
|
||||
pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
|
||||
attributes::inner_attrs(p);
|
||||
while !p.at(EOF) && !(p.at(T!['}']) && stop_on_r_curly) {
|
||||
item_or_macro(p, stop_on_r_curly)
|
||||
item_or_macro(p, stop_on_r_curly);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ pub(super) fn opt_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
|
||||
p.bump_remap(T![default]);
|
||||
p.bump(T![async]);
|
||||
if is_unsafe {
|
||||
p.bump(T![unsafe])
|
||||
p.bump(T![unsafe]);
|
||||
}
|
||||
has_mods = true;
|
||||
}
|
||||
@@ -404,7 +404,7 @@ fn fn_(p: &mut Parser, m: Marker) {
|
||||
// trait T { fn foo(); }
|
||||
p.bump(T![;]);
|
||||
} else {
|
||||
expressions::block_expr(p)
|
||||
expressions::block_expr(p);
|
||||
}
|
||||
m.complete(p, FN);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ pub(super) fn enum_(p: &mut Parser, m: Marker) {
|
||||
if p.at(T!['{']) {
|
||||
variant_list(p);
|
||||
} else {
|
||||
p.error("expected `{`")
|
||||
p.error("expected `{`");
|
||||
}
|
||||
m.complete(p, ENUM);
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ use super::*;
|
||||
// const C: u32 = 92;
|
||||
pub(super) fn konst(p: &mut Parser, m: Marker) {
|
||||
p.bump(T![const]);
|
||||
const_or_static(p, m, true)
|
||||
const_or_static(p, m, true);
|
||||
}
|
||||
|
||||
pub(super) fn static_(p: &mut Parser, m: Marker) {
|
||||
p.bump(T![static]);
|
||||
const_or_static(p, m, false)
|
||||
const_or_static(p, m, false);
|
||||
}
|
||||
|
||||
fn const_or_static(p: &mut Parser, m: Marker, is_const: bool) {
|
||||
@@ -27,7 +27,7 @@ fn const_or_static(p: &mut Parser, m: Marker, is_const: bool) {
|
||||
if p.at(T![:]) {
|
||||
types::ascription(p);
|
||||
} else {
|
||||
p.error("missing type for `const` or `static`")
|
||||
p.error("missing type for `const` or `static`");
|
||||
}
|
||||
if p.eat(T![=]) {
|
||||
expressions::expr(p);
|
||||
|
||||
@@ -6,21 +6,21 @@ use super::*;
|
||||
// fn c(x: i32, ) {}
|
||||
// fn d(x: i32, y: ()) {}
|
||||
pub(super) fn param_list_fn_def(p: &mut Parser) {
|
||||
list_(p, Flavor::FnDef)
|
||||
list_(p, Flavor::FnDef);
|
||||
}
|
||||
|
||||
// test param_list_opt_patterns
|
||||
// fn foo<F: FnMut(&mut Foo<'a>)>(){}
|
||||
pub(super) fn param_list_fn_trait(p: &mut Parser) {
|
||||
list_(p, Flavor::FnTrait)
|
||||
list_(p, Flavor::FnTrait);
|
||||
}
|
||||
|
||||
pub(super) fn param_list_fn_ptr(p: &mut Parser) {
|
||||
list_(p, Flavor::FnPointer)
|
||||
list_(p, Flavor::FnPointer);
|
||||
}
|
||||
|
||||
pub(super) fn param_list_closure(p: &mut Parser) {
|
||||
list_(p, Flavor::Closure)
|
||||
list_(p, Flavor::Closure);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -104,13 +104,13 @@ fn param(p: &mut Parser, m: Marker, flavor: Flavor) -> Variadic {
|
||||
Flavor::FnDef => {
|
||||
patterns::pattern(p);
|
||||
if variadic_param(p) {
|
||||
res = Variadic(true)
|
||||
res = Variadic(true);
|
||||
} else if p.at(T![:]) {
|
||||
types::ascription(p)
|
||||
types::ascription(p);
|
||||
} else {
|
||||
// test_err missing_fn_param_type
|
||||
// fn f(x y: i32, z, t: i32) {}
|
||||
p.error("missing type for function parameter")
|
||||
p.error("missing type for function parameter");
|
||||
}
|
||||
}
|
||||
// test value_parameters_no_patterns
|
||||
@@ -128,11 +128,11 @@ fn param(p: &mut Parser, m: Marker, flavor: Flavor) -> Variadic {
|
||||
if (p.at(IDENT) || p.at(UNDERSCORE)) && p.nth(1) == T![:] && !p.nth_at(1, T![::]) {
|
||||
patterns::pattern_single(p);
|
||||
if variadic_param(p) {
|
||||
res = Variadic(true)
|
||||
res = Variadic(true);
|
||||
} else if p.at(T![:]) {
|
||||
types::ascription(p)
|
||||
types::ascription(p);
|
||||
} else {
|
||||
p.error("missing type for function parameter")
|
||||
p.error("missing type for function parameter");
|
||||
}
|
||||
} else {
|
||||
types::type_(p);
|
||||
|
||||
@@ -16,15 +16,15 @@ pub(super) fn is_use_path_start(p: &Parser) -> bool {
|
||||
}
|
||||
|
||||
pub(super) fn use_path(p: &mut Parser) {
|
||||
path(p, Mode::Use)
|
||||
path(p, Mode::Use);
|
||||
}
|
||||
|
||||
pub(crate) fn type_path(p: &mut Parser) {
|
||||
path(p, Mode::Type)
|
||||
path(p, Mode::Type);
|
||||
}
|
||||
|
||||
pub(super) fn expr_path(p: &mut Parser) {
|
||||
path(p, Mode::Expr)
|
||||
path(p, Mode::Expr);
|
||||
}
|
||||
|
||||
pub(crate) fn type_path_for_qualifier(p: &mut Parser, qual: CompletedMarker) -> CompletedMarker {
|
||||
@@ -117,7 +117,7 @@ fn opt_path_type_args(p: &mut Parser, mode: Mode) {
|
||||
params::param_list_fn_trait(p);
|
||||
opt_ret_type(p);
|
||||
} else {
|
||||
generic_args::opt_generic_arg_list(p, false)
|
||||
generic_args::opt_generic_arg_list(p, false);
|
||||
}
|
||||
}
|
||||
Mode::Expr => generic_args::opt_generic_arg_list(p, true),
|
||||
|
||||
@@ -19,7 +19,7 @@ pub(crate) fn pattern(p: &mut Parser) {
|
||||
|
||||
/// Parses a pattern list separated by pipes `|`.
|
||||
pub(super) fn pattern_top(p: &mut Parser) {
|
||||
pattern_top_r(p, PAT_RECOVERY_SET)
|
||||
pattern_top_r(p, PAT_RECOVERY_SET);
|
||||
}
|
||||
|
||||
pub(crate) fn pattern_single(p: &mut Parser) {
|
||||
@@ -78,7 +78,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) {
|
||||
|
||||
// FIXME: support half_open_range_patterns (`..=2`),
|
||||
// exclusive_range_pattern (`..5`) with missing lhs
|
||||
for &range_op in [T![...], T![..=], T![..]].iter() {
|
||||
for range_op in [T![...], T![..=], T![..]] {
|
||||
if p.at(range_op) {
|
||||
let m = lhs.precede(p);
|
||||
p.bump(range_op);
|
||||
|
||||
@@ -57,7 +57,7 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
|
||||
pub(super) fn ascription(p: &mut Parser) {
|
||||
assert!(p.at(T![:]));
|
||||
p.bump(T![:]);
|
||||
type_(p)
|
||||
type_(p);
|
||||
}
|
||||
|
||||
fn paren_or_tuple_type(p: &mut Parser) {
|
||||
@@ -204,7 +204,7 @@ fn fn_ptr_type(p: &mut Parser) {
|
||||
if p.at(T!['(']) {
|
||||
params::param_list_fn_ptr(p);
|
||||
} else {
|
||||
p.error("expected parameters")
|
||||
p.error("expected parameters");
|
||||
}
|
||||
// test fn_pointer_type_with_ret
|
||||
// type F = fn() -> ();
|
||||
@@ -274,7 +274,7 @@ fn dyn_trait_type(p: &mut Parser) {
|
||||
// type C = self::Foo;
|
||||
// type D = super::Foo;
|
||||
pub(super) fn path_type(p: &mut Parser) {
|
||||
path_type_(p, true)
|
||||
path_type_(p, true);
|
||||
}
|
||||
|
||||
// test macro_call_type
|
||||
|
||||
@@ -177,7 +177,7 @@ impl<'t> Parser<'t> {
|
||||
if kind == EOF {
|
||||
return;
|
||||
}
|
||||
self.do_bump(kind, 1)
|
||||
self.do_bump(kind, 1);
|
||||
}
|
||||
|
||||
/// Advances the parser by one token, remapping its kind.
|
||||
@@ -200,7 +200,7 @@ impl<'t> Parser<'t> {
|
||||
/// does.
|
||||
pub(crate) fn error<T: Into<String>>(&mut self, message: T) {
|
||||
let msg = ParseError(Box::new(message.into()));
|
||||
self.push_event(Event::Error { msg })
|
||||
self.push_event(Event::Error { msg });
|
||||
}
|
||||
|
||||
/// Consume the next token if it is `kind` or emit an error
|
||||
@@ -258,7 +258,7 @@ impl<'t> Parser<'t> {
|
||||
}
|
||||
|
||||
fn push_event(&mut self, event: Event) {
|
||||
self.events.push(event)
|
||||
self.events.push(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ impl TokenSet {
|
||||
let mut i = 0;
|
||||
while i < kinds.len() {
|
||||
res |= mask(kinds[i]);
|
||||
i += 1
|
||||
i += 1;
|
||||
}
|
||||
TokenSet(res)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user