aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorClemens Wasser <[email protected]>2021-06-07 12:59:01 +0100
committerClemens Wasser <[email protected]>2021-06-21 15:40:21 +0100
commit47747cd4120e260a144242aadd7732e11d133fe4 (patch)
treeba767d7da808c050e313446ac4cb90d810d0f4de /crates/hir_def
parent4402f2b280f58896ed0696f4243d88a58fd970ca (diff)
Apply some clippy suggestions
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/body/lower.rs7
-rw-r--r--crates/hir_def/src/body/tests.rs9
-rw-r--r--crates/hir_def/src/generics.rs5
-rw-r--r--crates/hir_def/src/item_scope.rs6
-rw-r--r--crates/hir_def/src/item_tree/pretty.rs6
-rw-r--r--crates/hir_def/src/nameres.rs5
-rw-r--r--crates/hir_def/src/nameres/path_resolution.rs2
-rw-r--r--crates/hir_def/src/path.rs2
-rw-r--r--crates/hir_def/src/resolver.rs12
9 files changed, 22 insertions, 32 deletions
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<'_> {
690 } 690 }
691 } 691 }
692 ast::Stmt::Item(item) => { 692 ast::Stmt::Item(item) => {
693 if self.check_cfg(&item).is_none() { 693 self.check_cfg(&item);
694 return;
695 }
696 } 694 }
697 } 695 }
698 } 696 }
@@ -717,7 +715,8 @@ impl ExprCollector<'_> {
717 block.statements().for_each(|s| self.collect_stmt(s)); 715 block.statements().for_each(|s| self.collect_stmt(s));
718 block.tail_expr().and_then(|e| { 716 block.tail_expr().and_then(|e| {
719 let expr = self.maybe_collect_expr(e)?; 717 let expr = self.maybe_collect_expr(e)?;
720 Some(self.statements_in_scope.push(Statement::Expr { expr, has_semi: false })) 718 self.statements_in_scope.push(Statement::Expr { expr, has_semi: false });
719 Some(())
721 }); 720 });
722 721
723 let mut tail = None; 722 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<Body> {
15 let mut fn_def = None; 15 let mut fn_def = None;
16 'outer: for (_, module) in def_map.modules() { 16 'outer: for (_, module) in def_map.modules() {
17 for decl in module.scope.declarations() { 17 for decl in module.scope.declarations() {
18 match decl { 18 if let ModuleDefId::FunctionId(it) = decl {
19 ModuleDefId::FunctionId(it) => { 19 fn_def = Some(it);
20 fn_def = Some(it); 20 break 'outer;
21 break 'outer;
22 }
23 _ => {}
24 } 21 }
25 } 22 }
26 } 23 }
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 {
104 ) -> Interned<GenericParams> { 104 ) -> Interned<GenericParams> {
105 let _p = profile::span("generic_params_query"); 105 let _p = profile::span("generic_params_query");
106 106
107 let generics = match def { 107 match def {
108 GenericDefId::FunctionId(id) => { 108 GenericDefId::FunctionId(id) => {
109 let id = id.lookup(db).id; 109 let id = id.lookup(db).id;
110 let tree = id.item_tree(db); 110 let tree = id.item_tree(db);
@@ -150,8 +150,7 @@ impl GenericParams {
150 GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => { 150 GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => {
151 Interned::new(GenericParams::default()) 151 Interned::new(GenericParams::default())
152 } 152 }
153 }; 153 }
154 generics
155 } 154 }
156 155
157 fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) { 156 fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) {
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 {
241 check_changed!(changed, (self / def).values, glob_imports[lookup], def_import_type); 241 check_changed!(changed, (self / def).values, glob_imports[lookup], def_import_type);
242 check_changed!(changed, (self / def).macros, glob_imports[lookup], def_import_type); 242 check_changed!(changed, (self / def).macros, glob_imports[lookup], def_import_type);
243 243
244 if def.is_none() { 244 if def.is_none() && self.unresolved.insert(lookup.1) {
245 if self.unresolved.insert(lookup.1) { 245 changed = true;
246 changed = true;
247 }
248 } 246 }
249 247
250 changed 248 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 {
30 30
31macro_rules! w { 31macro_rules! w {
32 ($dst:expr, $($arg:tt)*) => { 32 ($dst:expr, $($arg:tt)*) => {
33 drop(write!($dst, $($arg)*)) 33 { let _ = write!($dst, $($arg)*); }
34 }; 34 };
35} 35}
36 36
37macro_rules! wln { 37macro_rules! wln {
38 ($dst:expr) => { 38 ($dst:expr) => {
39 drop(writeln!($dst)) 39 { let _ = writeln!($dst); }
40 }; 40 };
41 ($dst:expr, $($arg:tt)*) => { 41 ($dst:expr, $($arg:tt)*) => {
42 drop(writeln!($dst, $($arg)*)) 42 { let _ = writeln!($dst, $($arg)*); }
43 }; 43 };
44} 44}
45 45
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 {
367 pub fn containing_module(&self, local_mod: LocalModuleId) -> Option<ModuleId> { 367 pub fn containing_module(&self, local_mod: LocalModuleId) -> Option<ModuleId> {
368 match &self[local_mod].parent { 368 match &self[local_mod].parent {
369 Some(parent) => Some(self.module_id(*parent)), 369 Some(parent) => Some(self.module_id(*parent)),
370 None => match &self.block { 370 None => self.block.as_ref().map(|block| block.parent),
371 Some(block) => Some(block.parent),
372 None => None,
373 },
374 } 371 }
375 } 372 }
376 373
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 {
55 segment_index: Option<usize>, 55 segment_index: Option<usize>,
56 krate: Option<CrateId>, 56 krate: Option<CrateId>,
57 ) -> ResolvePathResult { 57 ) -> ResolvePathResult {
58 ResolvePathResult { resolved_def, reached_fixedpoint, segment_index, krate } 58 ResolvePathResult { resolved_def, segment_index, reached_fixedpoint, krate }
59 } 59 }
60} 60}
61 61
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 {
209 209
210 pub fn is_self_type(&self) -> bool { 210 pub fn is_self_type(&self) -> bool {
211 self.type_anchor.is_none() 211 self.type_anchor.is_none()
212 && self.generic_args == &[None] 212 && self.generic_args == [None]
213 && self.mod_path.as_ident() == Some(&name!(Self)) 213 && self.mod_path.as_ident() == Some(&name!(Self))
214 } 214 }
215} 215}
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 {
388 self.module_scope().map(|t| t.0.krate()) 388 self.module_scope().map(|t| t.0.krate())
389 } 389 }
390 390
391 pub fn where_predicates_in_scope<'a>( 391 pub fn where_predicates_in_scope(
392 &'a self, 392 &self,
393 ) -> impl Iterator<Item = &'a crate::generics::WherePredicate> + 'a { 393 ) -> impl Iterator<Item = &crate::generics::WherePredicate> {
394 self.scopes 394 self.scopes
395 .iter() 395 .iter()
396 .rev() 396 .rev()
@@ -464,16 +464,16 @@ impl Scope {
464 &Scope::GenericParams { ref params, def: parent } => { 464 &Scope::GenericParams { ref params, def: parent } => {
465 for (local_id, param) in params.types.iter() { 465 for (local_id, param) in params.types.iter() {
466 if let Some(ref name) = param.name { 466 if let Some(ref name) = param.name {
467 let id = TypeParamId { local_id, parent }; 467 let id = TypeParamId { parent, local_id };
468 f(name.clone(), ScopeDef::GenericParam(id.into())) 468 f(name.clone(), ScopeDef::GenericParam(id.into()))
469 } 469 }
470 } 470 }
471 for (local_id, param) in params.consts.iter() { 471 for (local_id, param) in params.consts.iter() {
472 let id = ConstParamId { local_id, parent }; 472 let id = ConstParamId { parent, local_id };
473 f(param.name.clone(), ScopeDef::GenericParam(id.into())) 473 f(param.name.clone(), ScopeDef::GenericParam(id.into()))
474 } 474 }
475 for (local_id, param) in params.lifetimes.iter() { 475 for (local_id, param) in params.lifetimes.iter() {
476 let id = LifetimeParamId { local_id, parent }; 476 let id = LifetimeParamId { parent, local_id };
477 f(param.name.clone(), ScopeDef::GenericParam(id.into())) 477 f(param.name.clone(), ScopeDef::GenericParam(id.into()))
478 } 478 }
479 } 479 }