From 47747cd4120e260a144242aadd7732e11d133fe4 Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Mon, 7 Jun 2021 13:59:01 +0200 Subject: Apply some clippy suggestions --- crates/hir_def/src/body/lower.rs | 7 +++---- crates/hir_def/src/body/tests.rs | 9 +++------ crates/hir_def/src/generics.rs | 5 ++--- crates/hir_def/src/item_scope.rs | 6 ++---- crates/hir_def/src/item_tree/pretty.rs | 6 +++--- crates/hir_def/src/nameres.rs | 5 +---- crates/hir_def/src/nameres/path_resolution.rs | 2 +- crates/hir_def/src/path.rs | 2 +- crates/hir_def/src/resolver.rs | 12 ++++++------ 9 files changed, 22 insertions(+), 32 deletions(-) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index bed4c4994..f6e6cdbe2 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -690,9 +690,7 @@ impl ExprCollector<'_> { } } ast::Stmt::Item(item) => { - if self.check_cfg(&item).is_none() { - return; - } + self.check_cfg(&item); } } } @@ -717,7 +715,8 @@ impl ExprCollector<'_> { block.statements().for_each(|s| self.collect_stmt(s)); block.tail_expr().and_then(|e| { let expr = self.maybe_collect_expr(e)?; - Some(self.statements_in_scope.push(Statement::Expr { expr, has_semi: false })) + self.statements_in_scope.push(Statement::Expr { expr, has_semi: false }); + Some(()) }); let mut tail = None; diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs index 27d837d47..673a75386 100644 --- a/crates/hir_def/src/body/tests.rs +++ b/crates/hir_def/src/body/tests.rs @@ -15,12 +15,9 @@ fn lower(ra_fixture: &str) -> Arc { let mut fn_def = None; 'outer: for (_, module) in def_map.modules() { for decl in module.scope.declarations() { - match decl { - ModuleDefId::FunctionId(it) => { - fn_def = Some(it); - break 'outer; - } - _ => {} + if let ModuleDefId::FunctionId(it) = decl { + fn_def = Some(it); + break 'outer; } } } diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs index 0f04b2bae..096ac7968 100644 --- a/crates/hir_def/src/generics.rs +++ b/crates/hir_def/src/generics.rs @@ -104,7 +104,7 @@ impl GenericParams { ) -> Interned { let _p = profile::span("generic_params_query"); - let generics = match def { + match def { GenericDefId::FunctionId(id) => { let id = id.lookup(db).id; let tree = id.item_tree(db); @@ -150,8 +150,7 @@ impl GenericParams { GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => { Interned::new(GenericParams::default()) } - }; - generics + } } fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile) { diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs index 08407ebfa..567ae5660 100644 --- a/crates/hir_def/src/item_scope.rs +++ b/crates/hir_def/src/item_scope.rs @@ -241,10 +241,8 @@ impl ItemScope { check_changed!(changed, (self / def).values, glob_imports[lookup], def_import_type); check_changed!(changed, (self / def).macros, glob_imports[lookup], def_import_type); - if def.is_none() { - if self.unresolved.insert(lookup.1) { - changed = true; - } + if def.is_none() && self.unresolved.insert(lookup.1) { + changed = true; } changed diff --git a/crates/hir_def/src/item_tree/pretty.rs b/crates/hir_def/src/item_tree/pretty.rs index e63bc8232..8b12e5a67 100644 --- a/crates/hir_def/src/item_tree/pretty.rs +++ b/crates/hir_def/src/item_tree/pretty.rs @@ -30,16 +30,16 @@ pub(super) fn print_item_tree(tree: &ItemTree) -> String { macro_rules! w { ($dst:expr, $($arg:tt)*) => { - drop(write!($dst, $($arg)*)) + { let _ = write!($dst, $($arg)*); } }; } macro_rules! wln { ($dst:expr) => { - drop(writeln!($dst)) + { let _ = writeln!($dst); } }; ($dst:expr, $($arg:tt)*) => { - drop(writeln!($dst, $($arg)*)) + { let _ = writeln!($dst, $($arg)*); } }; } diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index ebfcc26c4..9e6aa9607 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs @@ -367,10 +367,7 @@ impl DefMap { pub fn containing_module(&self, local_mod: LocalModuleId) -> Option { match &self[local_mod].parent { Some(parent) => Some(self.module_id(*parent)), - None => match &self.block { - Some(block) => Some(block.parent), - None => None, - }, + None => self.block.as_ref().map(|block| block.parent), } } diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index 629bc7952..229f57d77 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs @@ -55,7 +55,7 @@ impl ResolvePathResult { segment_index: Option, krate: Option, ) -> ResolvePathResult { - ResolvePathResult { resolved_def, reached_fixedpoint, segment_index, krate } + ResolvePathResult { resolved_def, segment_index, reached_fixedpoint, krate } } } diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index 4cdb5913d..667092cd2 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs @@ -209,7 +209,7 @@ impl Path { pub fn is_self_type(&self) -> bool { self.type_anchor.is_none() - && self.generic_args == &[None] + && self.generic_args == [None] && self.mod_path.as_ident() == Some(&name!(Self)) } } diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index 49c573087..a11439c3b 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs @@ -388,9 +388,9 @@ impl Resolver { self.module_scope().map(|t| t.0.krate()) } - pub fn where_predicates_in_scope<'a>( - &'a self, - ) -> impl Iterator + 'a { + pub fn where_predicates_in_scope( + &self, + ) -> impl Iterator { self.scopes .iter() .rev() @@ -464,16 +464,16 @@ impl Scope { &Scope::GenericParams { ref params, def: parent } => { for (local_id, param) in params.types.iter() { if let Some(ref name) = param.name { - let id = TypeParamId { local_id, parent }; + let id = TypeParamId { parent, local_id }; f(name.clone(), ScopeDef::GenericParam(id.into())) } } for (local_id, param) in params.consts.iter() { - let id = ConstParamId { local_id, parent }; + let id = ConstParamId { parent, local_id }; f(param.name.clone(), ScopeDef::GenericParam(id.into())) } for (local_id, param) in params.lifetimes.iter() { - let id = LifetimeParamId { local_id, parent }; + let id = LifetimeParamId { parent, local_id }; f(param.name.clone(), ScopeDef::GenericParam(id.into())) } } -- cgit v1.2.3