Fix even more clippy warnings
This commit is contained in:
parent
bfecb18771
commit
57c6ed0c07
53 changed files with 276 additions and 520 deletions
|
@ -344,10 +344,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
|||
|
||||
fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
|
||||
// If any statements are items, we need to create an anonymous module
|
||||
block.stmts.iter().any(|statement| match statement.kind {
|
||||
StmtKind::Item(_) | StmtKind::MacCall(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
block
|
||||
.stmts
|
||||
.iter()
|
||||
.any(|statement| matches!(statement.kind, StmtKind::Item(_) | StmtKind::MacCall(_)))
|
||||
}
|
||||
|
||||
// Add an import to the current module.
|
||||
|
|
|
@ -922,15 +922,10 @@ impl<'a> Resolver<'a> {
|
|||
);
|
||||
self.add_typo_suggestion(err, suggestion, ident.span);
|
||||
|
||||
let import_suggestions = self.lookup_import_candidates(
|
||||
ident,
|
||||
Namespace::MacroNS,
|
||||
parent_scope,
|
||||
|res| match res {
|
||||
Res::Def(DefKind::Macro(MacroKind::Bang), _) => true,
|
||||
_ => false,
|
||||
},
|
||||
);
|
||||
let import_suggestions =
|
||||
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, |res| {
|
||||
matches!(res, Res::Def(DefKind::Macro(MacroKind::Bang), _))
|
||||
});
|
||||
show_candidates(err, None, &import_suggestions, false, true);
|
||||
|
||||
if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
|
||||
|
@ -1010,11 +1005,8 @@ impl<'a> Resolver<'a> {
|
|||
fn binding_description(&self, b: &NameBinding<'_>, ident: Ident, from_prelude: bool) -> String {
|
||||
let res = b.res();
|
||||
if b.span.is_dummy() {
|
||||
let add_built_in = match b.res() {
|
||||
// These already contain the "built-in" prefix or look bad with it.
|
||||
Res::NonMacroAttr(..) | Res::PrimTy(..) | Res::ToolMod => false,
|
||||
_ => true,
|
||||
};
|
||||
let add_built_in =
|
||||
!matches!(b.res(), Res::NonMacroAttr(..) | Res::PrimTy(..) | Res::ToolMod);
|
||||
let (built_in, from) = if from_prelude {
|
||||
("", " from prelude")
|
||||
} else if b.is_extern_crate()
|
||||
|
@ -1610,10 +1602,7 @@ fn find_span_immediately_after_crate_name(
|
|||
if *c == ':' {
|
||||
num_colons += 1;
|
||||
}
|
||||
match c {
|
||||
':' if num_colons == 2 => false,
|
||||
_ => true,
|
||||
}
|
||||
!matches!(c, ':' if num_colons == 2)
|
||||
});
|
||||
// Find everything after the second colon.. `foo::{baz, makro};`
|
||||
let from_second_colon = use_span.with_lo(until_second_colon.hi() + BytePos(1));
|
||||
|
|
|
@ -114,10 +114,7 @@ crate struct Import<'a> {
|
|||
|
||||
impl<'a> Import<'a> {
|
||||
pub fn is_glob(&self) -> bool {
|
||||
match self.kind {
|
||||
ImportKind::Glob { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, ImportKind::Glob { .. })
|
||||
}
|
||||
|
||||
pub fn is_nested(&self) -> bool {
|
||||
|
@ -898,12 +895,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
|||
let msg = "inconsistent resolution for an import";
|
||||
self.r.session.span_err(import.span, msg);
|
||||
}
|
||||
} else {
|
||||
if self.r.privacy_errors.is_empty() {
|
||||
let msg = "cannot determine resolution for the import";
|
||||
let msg_note = "import resolution is stuck, try simplifying other imports";
|
||||
self.r.session.struct_span_err(import.span, msg).note(msg_note).emit();
|
||||
}
|
||||
} else if self.r.privacy_errors.is_empty() {
|
||||
let msg = "cannot determine resolution for the import";
|
||||
let msg_note = "import resolution is stuck, try simplifying other imports";
|
||||
self.r.session.struct_span_err(import.span, msg).note(msg_note).emit();
|
||||
}
|
||||
|
||||
module
|
||||
|
@ -1044,19 +1039,14 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
|||
if res != initial_res && this.ambiguity_errors.is_empty() {
|
||||
span_bug!(import.span, "inconsistent resolution for an import");
|
||||
}
|
||||
} else {
|
||||
if res != Res::Err
|
||||
&& this.ambiguity_errors.is_empty()
|
||||
&& this.privacy_errors.is_empty()
|
||||
{
|
||||
let msg = "cannot determine resolution for the import";
|
||||
let msg_note =
|
||||
"import resolution is stuck, try simplifying other imports";
|
||||
this.session
|
||||
.struct_span_err(import.span, msg)
|
||||
.note(msg_note)
|
||||
.emit();
|
||||
}
|
||||
} else if res != Res::Err
|
||||
&& this.ambiguity_errors.is_empty()
|
||||
&& this.privacy_errors.is_empty()
|
||||
{
|
||||
let msg = "cannot determine resolution for the import";
|
||||
let msg_note =
|
||||
"import resolution is stuck, try simplifying other imports";
|
||||
this.session.struct_span_err(import.span, msg).note(msg_note).emit();
|
||||
}
|
||||
}
|
||||
Err(..) => {
|
||||
|
|
|
@ -257,16 +257,12 @@ impl<'a> PathSource<'a> {
|
|||
}
|
||||
|
||||
fn is_call(self) -> bool {
|
||||
match self {
|
||||
PathSource::Expr(Some(&Expr { kind: ExprKind::Call(..), .. })) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, PathSource::Expr(Some(&Expr { kind: ExprKind::Call(..), .. })))
|
||||
}
|
||||
|
||||
crate fn is_expected(self, res: Res) -> bool {
|
||||
match self {
|
||||
PathSource::Type => match res {
|
||||
Res::Def(
|
||||
PathSource::Type => matches!(res, Res::Def(
|
||||
DefKind::Struct
|
||||
| DefKind::Union
|
||||
| DefKind::Enum
|
||||
|
@ -280,19 +276,12 @@ impl<'a> PathSource<'a> {
|
|||
_,
|
||||
)
|
||||
| Res::PrimTy(..)
|
||||
| Res::SelfTy(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Trait(AliasPossibility::No) => match res {
|
||||
Res::Def(DefKind::Trait, _) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Trait(AliasPossibility::Maybe) => match res {
|
||||
Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Expr(..) => match res {
|
||||
Res::Def(
|
||||
| Res::SelfTy(..)),
|
||||
PathSource::Trait(AliasPossibility::No) => matches!(res, Res::Def(DefKind::Trait, _)),
|
||||
PathSource::Trait(AliasPossibility::Maybe) => {
|
||||
matches!(res, Res::Def(DefKind::Trait | DefKind::TraitAlias, _))
|
||||
}
|
||||
PathSource::Expr(..) => matches!(res, Res::Def(
|
||||
DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)
|
||||
| DefKind::Const
|
||||
| DefKind::Static
|
||||
|
@ -303,23 +292,16 @@ impl<'a> PathSource<'a> {
|
|||
_,
|
||||
)
|
||||
| Res::Local(..)
|
||||
| Res::SelfCtor(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Pat => match res {
|
||||
Res::Def(
|
||||
| Res::SelfCtor(..)),
|
||||
PathSource::Pat => matches!(res, Res::Def(
|
||||
DefKind::Ctor(_, CtorKind::Const) | DefKind::Const | DefKind::AssocConst,
|
||||
_,
|
||||
)
|
||||
| Res::SelfCtor(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::TupleStruct(..) => match res {
|
||||
Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::SelfCtor(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
PathSource::Struct => match res {
|
||||
Res::Def(
|
||||
| Res::SelfCtor(..)),
|
||||
PathSource::TupleStruct(..) => {
|
||||
matches!(res, Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::SelfCtor(..))
|
||||
}
|
||||
PathSource::Struct => matches!(res, Res::Def(
|
||||
DefKind::Struct
|
||||
| DefKind::Union
|
||||
| DefKind::Variant
|
||||
|
@ -327,9 +309,7 @@ impl<'a> PathSource<'a> {
|
|||
| DefKind::AssocTy,
|
||||
_,
|
||||
)
|
||||
| Res::SelfTy(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
| Res::SelfTy(..)),
|
||||
PathSource::TraitItem(ns) => match res {
|
||||
Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) if ns == ValueNS => true,
|
||||
Res::Def(DefKind::AssocTy, _) if ns == TypeNS => true,
|
||||
|
@ -1450,10 +1430,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
|||
}
|
||||
|
||||
fn is_base_res_local(&self, nid: NodeId) -> bool {
|
||||
match self.r.partial_res_map.get(&nid).map(|res| res.base_res()) {
|
||||
Some(Res::Local(..)) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.r.partial_res_map.get(&nid).map(|res| res.base_res()), Some(Res::Local(..)))
|
||||
}
|
||||
|
||||
/// Checks that all of the arms in an or-pattern have exactly the
|
||||
|
|
|
@ -702,10 +702,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
|||
_ => break,
|
||||
}
|
||||
}
|
||||
let followed_by_brace = match sm.span_to_snippet(sp) {
|
||||
Ok(ref snippet) if snippet == "{" => true,
|
||||
_ => false,
|
||||
};
|
||||
let followed_by_brace = matches!(sm.span_to_snippet(sp), Ok(ref snippet) if snippet == "{");
|
||||
// In case this could be a struct literal that needs to be surrounded
|
||||
// by parentheses, find the appropriate span.
|
||||
let mut i = 0;
|
||||
|
@ -1788,12 +1785,11 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
|
|||
}
|
||||
msg = "consider introducing a named lifetime parameter".to_string();
|
||||
should_break = true;
|
||||
if let Some(param) = generics.params.iter().find(|p| match p.kind {
|
||||
hir::GenericParamKind::Type {
|
||||
if let Some(param) = generics.params.iter().find(|p| {
|
||||
!matches!(p.kind, hir::GenericParamKind::Type {
|
||||
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
|
||||
..
|
||||
} => false,
|
||||
_ => true,
|
||||
})
|
||||
}) {
|
||||
(param.span.shrink_to_lo(), "'a, ".to_string())
|
||||
} else {
|
||||
|
|
|
@ -351,10 +351,7 @@ fn krate(tcx: TyCtxt<'_>) -> NamedRegionMap {
|
|||
/// We have to account for this when computing the index of the other generic parameters.
|
||||
/// This function returns whether there is such an implicit parameter defined on the given item.
|
||||
fn sub_items_have_self_param(node: &hir::ItemKind<'_>) -> bool {
|
||||
match *node {
|
||||
hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*node, hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..))
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
|
@ -417,10 +414,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
|
||||
// Impls permit `'_` to be used and it is equivalent to "some fresh lifetime name".
|
||||
// This is not true for other kinds of items.x
|
||||
let track_lifetime_uses = match item.kind {
|
||||
hir::ItemKind::Impl { .. } => true,
|
||||
_ => false,
|
||||
};
|
||||
let track_lifetime_uses = matches!(item.kind, hir::ItemKind::Impl { .. });
|
||||
// These kinds of items have only early-bound lifetime parameters.
|
||||
let mut index = if sub_items_have_self_param(&item.kind) {
|
||||
1 // Self comes before lifetimes
|
||||
|
@ -970,10 +964,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
|
||||
let trait_ref_hack = take(&mut self.trait_ref_hack);
|
||||
if !trait_ref_hack
|
||||
|| trait_ref.bound_generic_params.iter().any(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => true,
|
||||
_ => false,
|
||||
})
|
||||
|| trait_ref
|
||||
.bound_generic_params
|
||||
.iter()
|
||||
.any(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
|
||||
{
|
||||
if trait_ref_hack {
|
||||
struct_span_err!(
|
||||
|
@ -1384,18 +1378,16 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
}
|
||||
if in_band {
|
||||
Some(param.span)
|
||||
} else if generics.params.len() == 1 {
|
||||
// if sole lifetime, remove the entire `<>` brackets
|
||||
Some(generics.span)
|
||||
} else {
|
||||
if generics.params.len() == 1 {
|
||||
// if sole lifetime, remove the entire `<>` brackets
|
||||
Some(generics.span)
|
||||
// if removing within `<>` brackets, we also want to
|
||||
// delete a leading or trailing comma as appropriate
|
||||
if i >= generics.params.len() - 1 {
|
||||
Some(generics.params[i - 1].span.shrink_to_hi().to(param.span))
|
||||
} else {
|
||||
// if removing within `<>` brackets, we also want to
|
||||
// delete a leading or trailing comma as appropriate
|
||||
if i >= generics.params.len() - 1 {
|
||||
Some(generics.params[i - 1].span.shrink_to_hi().to(param.span))
|
||||
} else {
|
||||
Some(param.span.to(generics.params[i + 1].span.shrink_to_lo()))
|
||||
}
|
||||
Some(param.span.to(generics.params[i + 1].span.shrink_to_lo()))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -2047,10 +2039,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
//
|
||||
// This is intended to leave room for us to implement the
|
||||
// correct behavior in the future.
|
||||
let has_lifetime_parameter = generic_args.args.iter().any(|arg| match arg {
|
||||
GenericArg::Lifetime(_) => true,
|
||||
_ => false,
|
||||
});
|
||||
let has_lifetime_parameter =
|
||||
generic_args.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)));
|
||||
|
||||
// Resolve lifetimes found in the type `XX` from `Item = XX` bindings.
|
||||
for b in generic_args.bindings {
|
||||
|
|
|
@ -313,17 +313,17 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
|
|||
ItemKind::ExternCrate(_) => {}
|
||||
// but place them before the first other item
|
||||
_ => {
|
||||
if self.span.map_or(true, |span| item.span < span) {
|
||||
if !item.span.from_expansion() {
|
||||
// don't insert between attributes and an item
|
||||
if item.attrs.is_empty() {
|
||||
self.span = Some(item.span.shrink_to_lo());
|
||||
} else {
|
||||
// find the first attribute on the item
|
||||
for attr in &item.attrs {
|
||||
if self.span.map_or(true, |span| attr.span < span) {
|
||||
self.span = Some(attr.span.shrink_to_lo());
|
||||
}
|
||||
if self.span.map_or(true, |span| item.span < span)
|
||||
&& !item.span.from_expansion()
|
||||
{
|
||||
// don't insert between attributes and an item
|
||||
if item.attrs.is_empty() {
|
||||
self.span = Some(item.span.shrink_to_lo());
|
||||
} else {
|
||||
// find the first attribute on the item
|
||||
for attr in &item.attrs {
|
||||
if self.span.map_or(true, |span| attr.span < span) {
|
||||
self.span = Some(attr.span.shrink_to_lo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -558,17 +558,11 @@ impl<'a> ModuleData<'a> {
|
|||
|
||||
// `self` resolves to the first module ancestor that `is_normal`.
|
||||
fn is_normal(&self) -> bool {
|
||||
match self.kind {
|
||||
ModuleKind::Def(DefKind::Mod, _, _) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, ModuleKind::Def(DefKind::Mod, _, _))
|
||||
}
|
||||
|
||||
fn is_trait(&self) -> bool {
|
||||
match self.kind {
|
||||
ModuleKind::Def(DefKind::Trait, _, _) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, ModuleKind::Def(DefKind::Trait, _, _))
|
||||
}
|
||||
|
||||
fn nearest_item_scope(&'a self) -> Module<'a> {
|
||||
|
@ -628,10 +622,7 @@ enum NameBindingKind<'a> {
|
|||
impl<'a> NameBindingKind<'a> {
|
||||
/// Is this a name binding of a import?
|
||||
fn is_import(&self) -> bool {
|
||||
match *self {
|
||||
NameBindingKind::Import { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*self, NameBindingKind::Import { .. })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -750,13 +741,10 @@ impl<'a> NameBinding<'a> {
|
|||
}
|
||||
|
||||
fn is_variant(&self) -> bool {
|
||||
match self.kind {
|
||||
NameBindingKind::Res(
|
||||
matches!(self.kind, NameBindingKind::Res(
|
||||
Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Variant, ..), _),
|
||||
_,
|
||||
) => true,
|
||||
_ => false,
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
fn is_extern_crate(&self) -> bool {
|
||||
|
@ -774,10 +762,7 @@ impl<'a> NameBinding<'a> {
|
|||
}
|
||||
|
||||
fn is_import(&self) -> bool {
|
||||
match self.kind {
|
||||
NameBindingKind::Import { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, NameBindingKind::Import { .. })
|
||||
}
|
||||
|
||||
fn is_glob_import(&self) -> bool {
|
||||
|
@ -788,17 +773,14 @@ impl<'a> NameBinding<'a> {
|
|||
}
|
||||
|
||||
fn is_importable(&self) -> bool {
|
||||
match self.res() {
|
||||
Res::Def(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, _) => false,
|
||||
_ => true,
|
||||
}
|
||||
!matches!(
|
||||
self.res(),
|
||||
Res::Def(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, _)
|
||||
)
|
||||
}
|
||||
|
||||
fn is_macro_def(&self) -> bool {
|
||||
match self.kind {
|
||||
NameBindingKind::Res(Res::Def(DefKind::Macro(..), _), _) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.kind, NameBindingKind::Res(Res::Def(DefKind::Macro(..), _), _))
|
||||
}
|
||||
|
||||
fn macro_kind(&self) -> Option<MacroKind> {
|
||||
|
@ -1380,7 +1362,7 @@ impl<'a> Resolver<'a> {
|
|||
let maybe_unused_extern_crates = self.maybe_unused_extern_crates;
|
||||
let glob_map = self.glob_map;
|
||||
ResolverOutputs {
|
||||
definitions: definitions,
|
||||
definitions,
|
||||
cstore: Box::new(self.crate_loader.into_cstore()),
|
||||
visibilities,
|
||||
extern_crate_map,
|
||||
|
@ -1992,11 +1974,12 @@ impl<'a> Resolver<'a> {
|
|||
// The macro is a proc macro derive
|
||||
if let Some(def_id) = module.expansion.expn_data().macro_def_id {
|
||||
if let Some(ext) = self.get_macro_by_def_id(def_id) {
|
||||
if !ext.is_builtin && ext.macro_kind() == MacroKind::Derive {
|
||||
if parent.expansion.outer_expn_is_descendant_of(span.ctxt()) {
|
||||
*poisoned = Some(node_id);
|
||||
return module.parent;
|
||||
}
|
||||
if !ext.is_builtin
|
||||
&& ext.macro_kind() == MacroKind::Derive
|
||||
&& parent.expansion.outer_expn_is_descendant_of(span.ctxt())
|
||||
{
|
||||
*poisoned = Some(node_id);
|
||||
return module.parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2390,10 +2373,7 @@ impl<'a> Resolver<'a> {
|
|||
_ => None,
|
||||
};
|
||||
let (label, suggestion) = if module_res == self.graph_root.res() {
|
||||
let is_mod = |res| match res {
|
||||
Res::Def(DefKind::Mod, _) => true,
|
||||
_ => false,
|
||||
};
|
||||
let is_mod = |res| matches!(res, Res::Def(DefKind::Mod, _));
|
||||
// Don't look up import candidates if this is a speculative resolve
|
||||
let mut candidates = if record_used {
|
||||
self.lookup_import_candidates(ident, TypeNS, parent_scope, is_mod)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue