diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/utils.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide/src/hover.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide/src/references.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_db/src/defs.rs | 22 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/diagnostics.rs | 2 |
8 files changed, 22 insertions, 23 deletions
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index 54d5678d1..0de6fdf3f 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs | |||
@@ -257,7 +257,7 @@ pub use prelude::*; | |||
257 | .find(|dep| &dep.name.to_string() == std_crate)? | 257 | .find(|dep| &dep.name.to_string() == std_crate)? |
258 | .krate; | 258 | .krate; |
259 | 259 | ||
260 | let mut module = std_crate.root_module(db)?; | 260 | let mut module = std_crate.root_module(db); |
261 | for segment in path { | 261 | for segment in path { |
262 | module = module.children(db).find_map(|child| { | 262 | module = module.children(db).find_map(|child| { |
263 | let name = child.name(db)?; | 263 | let name = child.name(db)?; |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 27cdabea0..44456e49e 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -83,9 +83,9 @@ impl Crate { | |||
83 | .collect() | 83 | .collect() |
84 | } | 84 | } |
85 | 85 | ||
86 | pub fn root_module(self, db: &dyn HirDatabase) -> Option<Module> { | 86 | pub fn root_module(self, db: &dyn HirDatabase) -> Module { |
87 | let module_id = db.crate_def_map(self.id).root; | 87 | let module_id = db.crate_def_map(self.id).root; |
88 | Some(Module::new(self, module_id)) | 88 | Module::new(self, module_id) |
89 | } | 89 | } |
90 | 90 | ||
91 | pub fn root_file(self, db: &dyn HirDatabase) -> FileId { | 91 | pub fn root_file(self, db: &dyn HirDatabase) -> FileId { |
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index b44b6fe22..45389fd23 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -40,7 +40,7 @@ pub(crate) fn goto_definition( | |||
40 | reference_definition(&sema, &name_ref).to_vec() | 40 | reference_definition(&sema, &name_ref).to_vec() |
41 | }, | 41 | }, |
42 | ast::Name(name) => { | 42 | ast::Name(name) => { |
43 | let def = classify_name(&sema, &name)?.definition(sema.db)?; | 43 | let def = classify_name(&sema, &name)?.definition(sema.db); |
44 | let nav = def.try_to_nav(sema.db)?; | 44 | let nav = def.try_to_nav(sema.db)?; |
45 | vec![nav] | 45 | vec![nav] |
46 | }, | 46 | }, |
@@ -82,7 +82,8 @@ pub(crate) fn reference_definition( | |||
82 | name_ref: &ast::NameRef, | 82 | name_ref: &ast::NameRef, |
83 | ) -> ReferenceResult { | 83 | ) -> ReferenceResult { |
84 | let name_kind = classify_name_ref(sema, name_ref); | 84 | let name_kind = classify_name_ref(sema, name_ref); |
85 | if let Some(def) = name_kind.and_then(|def| def.definition(sema.db)) { | 85 | if let Some(def) = name_kind { |
86 | let def = def.definition(sema.db); | ||
86 | return match def.try_to_nav(sema.db) { | 87 | return match def.try_to_nav(sema.db) { |
87 | Some(nav) => ReferenceResult::Exact(nav), | 88 | Some(nav) => ReferenceResult::Exact(nav), |
88 | None => ReferenceResult::Approximate(Vec::new()), | 89 | None => ReferenceResult::Approximate(Vec::new()), |
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index a632ea6a2..f6e493817 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs | |||
@@ -85,8 +85,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
85 | let node = token.parent(); | 85 | let node = token.parent(); |
86 | let definition = match_ast! { | 86 | let definition = match_ast! { |
87 | match node { | 87 | match node { |
88 | ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).and_then(|d| d.definition(sema.db)), | 88 | ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)), |
89 | ast::Name(name) => classify_name(&sema, &name).and_then(|d| d.definition(sema.db)), | 89 | ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition(sema.db)), |
90 | _ => None, | 90 | _ => None, |
91 | } | 91 | } |
92 | }; | 92 | }; |
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 9dd228b9c..453985de3 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs | |||
@@ -130,13 +130,13 @@ fn find_name( | |||
130 | opt_name: Option<ast::Name>, | 130 | opt_name: Option<ast::Name>, |
131 | ) -> Option<RangeInfo<Definition>> { | 131 | ) -> Option<RangeInfo<Definition>> { |
132 | if let Some(name) = opt_name { | 132 | if let Some(name) = opt_name { |
133 | let def = classify_name(sema, &name)?.definition(sema.db)?; | 133 | let def = classify_name(sema, &name)?.definition(sema.db); |
134 | let range = name.syntax().text_range(); | 134 | let range = name.syntax().text_range(); |
135 | return Some(RangeInfo::new(range, def)); | 135 | return Some(RangeInfo::new(range, def)); |
136 | } | 136 | } |
137 | let name_ref = | 137 | let name_ref = |
138 | sema.find_node_at_offset_with_descend::<ast::NameRef>(&syntax, position.offset)?; | 138 | sema.find_node_at_offset_with_descend::<ast::NameRef>(&syntax, position.offset)?; |
139 | let def = classify_name_ref(sema, &name_ref)?.definition(sema.db)?; | 139 | let def = classify_name_ref(sema, &name_ref)?.definition(sema.db); |
140 | let range = name_ref.syntax().text_range(); | 140 | let range = name_ref.syntax().text_range(); |
141 | Some(RangeInfo::new(range, def)) | 141 | Some(RangeInfo::new(range, def)) |
142 | } | 142 | } |
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index e2a4f2983..9bb95277d 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs | |||
@@ -93,19 +93,19 @@ pub enum NameClass { | |||
93 | impl NameClass { | 93 | impl NameClass { |
94 | pub fn into_definition(self, db: &dyn HirDatabase) -> Option<Definition> { | 94 | pub fn into_definition(self, db: &dyn HirDatabase) -> Option<Definition> { |
95 | Some(match self { | 95 | Some(match self { |
96 | NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db)?.into()), | 96 | NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), |
97 | NameClass::Definition(it) => it, | 97 | NameClass::Definition(it) => it, |
98 | NameClass::ConstReference(_) => return None, | 98 | NameClass::ConstReference(_) => return None, |
99 | NameClass::FieldShorthand { local, field: _ } => Definition::Local(local), | 99 | NameClass::FieldShorthand { local, field: _ } => Definition::Local(local), |
100 | }) | 100 | }) |
101 | } | 101 | } |
102 | 102 | ||
103 | pub fn definition(self, db: &dyn HirDatabase) -> Option<Definition> { | 103 | pub fn definition(self, db: &dyn HirDatabase) -> Definition { |
104 | Some(match self { | 104 | match self { |
105 | NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db)?.into()), | 105 | NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), |
106 | NameClass::Definition(it) | NameClass::ConstReference(it) => it, | 106 | NameClass::Definition(it) | NameClass::ConstReference(it) => it, |
107 | NameClass::FieldShorthand { local: _, field } => field, | 107 | NameClass::FieldShorthand { local: _, field } => field, |
108 | }) | 108 | } |
109 | } | 109 | } |
110 | } | 110 | } |
111 | 111 | ||
@@ -148,7 +148,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option | |||
148 | }) | 148 | }) |
149 | .and_then(|name_ref| classify_name_ref(sema, &name_ref))?; | 149 | .and_then(|name_ref| classify_name_ref(sema, &name_ref))?; |
150 | 150 | ||
151 | Some(NameClass::Definition(name_ref_class.definition(sema.db)?)) | 151 | Some(NameClass::Definition(name_ref_class.definition(sema.db))) |
152 | } else { | 152 | } else { |
153 | let extern_crate = it.syntax().parent().and_then(ast::ExternCrate::cast)?; | 153 | let extern_crate = it.syntax().parent().and_then(ast::ExternCrate::cast)?; |
154 | let resolved = sema.resolve_extern_crate(&extern_crate)?; | 154 | let resolved = sema.resolve_extern_crate(&extern_crate)?; |
@@ -234,14 +234,12 @@ pub enum NameRefClass { | |||
234 | } | 234 | } |
235 | 235 | ||
236 | impl NameRefClass { | 236 | impl NameRefClass { |
237 | pub fn definition(self, db: &dyn HirDatabase) -> Option<Definition> { | 237 | pub fn definition(self, db: &dyn HirDatabase) -> Definition { |
238 | Some(match self { | 238 | match self { |
239 | NameRefClass::ExternCrate(krate) => { | 239 | NameRefClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), |
240 | Definition::ModuleDef(krate.root_module(db)?.into()) | ||
241 | } | ||
242 | NameRefClass::Definition(def) => def, | 240 | NameRefClass::Definition(def) => def, |
243 | NameRefClass::FieldShorthand { local, field: _ } => Definition::Local(local), | 241 | NameRefClass::FieldShorthand { local, field: _ } => Definition::Local(local), |
244 | }) | 242 | } |
245 | } | 243 | } |
246 | } | 244 | } |
247 | 245 | ||
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 721d41a58..0d386841e 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -72,7 +72,7 @@ impl AnalysisStatsCmd { | |||
72 | shuffle(&mut rng, &mut krates); | 72 | shuffle(&mut rng, &mut krates); |
73 | } | 73 | } |
74 | for krate in krates { | 74 | for krate in krates { |
75 | let module = krate.root_module(db).expect("crate without root module"); | 75 | let module = krate.root_module(db); |
76 | let file_id = module.definition_source(db).file_id; | 76 | let file_id = module.definition_source(db).file_id; |
77 | let file_id = file_id.original_file(db); | 77 | let file_id = file_id.original_file(db); |
78 | let source_root = db.file_source_root(file_id); | 78 | let source_root = db.file_source_root(file_id); |
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs index 4ac8c8772..f17fc5dfe 100644 --- a/crates/rust-analyzer/src/cli/diagnostics.rs +++ b/crates/rust-analyzer/src/cli/diagnostics.rs | |||
@@ -28,7 +28,7 @@ pub fn diagnostics( | |||
28 | let mut work = Vec::new(); | 28 | let mut work = Vec::new(); |
29 | let krates = Crate::all(db); | 29 | let krates = Crate::all(db); |
30 | for krate in krates { | 30 | for krate in krates { |
31 | let module = krate.root_module(db).expect("crate without root module"); | 31 | let module = krate.root_module(db); |
32 | let file_id = module.definition_source(db).file_id; | 32 | let file_id = module.definition_source(db).file_id; |
33 | let file_id = file_id.original_file(db); | 33 | let file_id = file_id.original_file(db); |
34 | let source_root = db.file_source_root(file_id); | 34 | let source_root = db.file_source_root(file_id); |