diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index f199d599d58..1c0380943ea 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -113,7 +113,7 @@ pub(crate) fn external_docs( let definition = match_ast! { match node { ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced())?, - ast::Name(name) => NameClass::classify(&sema, &name).map(|d| d.referenced_or_defined(sema.db))?, + ast::Name(name) => NameClass::classify(&sema, &name).map(|d| d.referenced_or_defined())?, _ => return None, } }; diff --git a/crates/ide/src/goto_declaration.rs b/crates/ide/src/goto_declaration.rs index a9557ea5eff..4f6b5e61868 100644 --- a/crates/ide/src/goto_declaration.rs +++ b/crates/ide/src/goto_declaration.rs @@ -28,7 +28,7 @@ pub(crate) fn goto_declaration( name_kind.referenced() }, ast::Name(name) => { - NameClass::classify(&sema, &name)?.referenced_or_defined(sema.db) + NameClass::classify(&sema, &name)?.referenced_or_defined() }, _ => return None, } diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index d0f7d8de89d..d1ad6db2fdd 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -60,12 +60,12 @@ pub(crate) fn goto_definition( reference_definition(&sema, Either::Right(&name_ref)) }, ast::Name(name) => { - let def = NameClass::classify(&sema, &name)?.referenced_or_defined(sema.db); + let def = NameClass::classify(&sema, &name)?.referenced_or_defined(); try_find_trait_item_definition(sema.db, &def) .or_else(|| def.try_to_nav(sema.db)) }, ast::Lifetime(lt) => if let Some(name_class) = NameClass::classify_lifetime(&sema, <) { - let def = name_class.referenced_or_defined(sema.db); + let def = name_class.referenced_or_defined(); def.try_to_nav(sema.db) } else { reference_definition(&sema, Either::Left(<)) diff --git a/crates/ide/src/goto_implementation.rs b/crates/ide/src/goto_implementation.rs index c1f37e9ed02..636642cfe70 100644 --- a/crates/ide/src/goto_implementation.rs +++ b/crates/ide/src/goto_implementation.rs @@ -29,7 +29,7 @@ pub(crate) fn goto_implementation( let node = sema.find_node_at_offset_with_descend(&syntax, position.offset)?; let def = match &node { ast::NameLike::Name(name) => { - NameClass::classify(&sema, name).map(|class| class.referenced_or_defined(sema.db)) + NameClass::classify(&sema, name).map(|class| class.referenced_or_defined()) } ast::NameLike::NameRef(name_ref) => { NameRefClass::classify(&sema, name_ref).map(|class| class.referenced()) diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 2cce43b41a9..743aa183f78 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -98,14 +98,14 @@ pub(crate) fn hover( // field pattern shorthands to their definition ast::Name(name) => NameClass::classify(&sema, &name).and_then(|class| match class { NameClass::ConstReference(def) => Some(def), - def => def.defined(db), + def => def.defined(), }), ast::NameRef(name_ref) => { NameRefClass::classify(&sema, &name_ref).map(|d| d.referenced()) }, ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime).map_or_else( || NameRefClass::classify_lifetime(&sema, &lifetime).map(|d| d.referenced()), - |d| d.defined(db), + |d| d.defined(), ), _ => { diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 9d0b5f8f06e..fbe79741b39 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -58,7 +58,7 @@ pub(crate) fn find_all_refs( let (def, is_literal_search) = if let Some(name) = get_name_of_item_declaration(&syntax, position) { - (NameClass::classify(sema, &name)?.referenced_or_defined(sema.db), true) + (NameClass::classify(sema, &name)?.referenced_or_defined(), true) } else { (find_def(sema, &syntax, position.offset)?, false) }; @@ -117,14 +117,12 @@ pub(crate) fn find_def( ) -> Option { let def = match sema.find_node_at_offset_with_descend(syntax, offset)? { ast::NameLike::NameRef(name_ref) => NameRefClass::classify(sema, &name_ref)?.referenced(), - ast::NameLike::Name(name) => { - NameClass::classify(sema, &name)?.referenced_or_defined(sema.db) - } + ast::NameLike::Name(name) => NameClass::classify(sema, &name)?.referenced_or_defined(), ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, &lifetime) .map(|class| class.referenced()) .or_else(|| { NameClass::classify_lifetime(sema, &lifetime) - .map(|class| class.referenced_or_defined(sema.db)) + .map(|class| class.referenced_or_defined()) })?, }; Some(def) diff --git a/crates/ide/src/rename.rs b/crates/ide/src/rename.rs index a1a03e775ea..9047d0fb32d 100644 --- a/crates/ide/src/rename.rs +++ b/crates/ide/src/rename.rs @@ -108,7 +108,7 @@ fn find_definition( bail!("Renaming aliases is currently unsupported") } ast::NameLike::Name(name) => { - NameClass::classify(sema, &name).map(|class| class.referenced_or_defined(sema.db)) + NameClass::classify(sema, &name).map(|class| class.referenced_or_defined()) } ast::NameLike::NameRef(name_ref) => { if let Some(def) = @@ -126,8 +126,7 @@ fn find_definition( ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, &lifetime) .map(|class| class.referenced()) .or_else(|| { - NameClass::classify_lifetime(sema, &lifetime) - .map(|it| it.referenced_or_defined(sema.db)) + NameClass::classify_lifetime(sema, &lifetime).map(|it| it.referenced_or_defined()) }), } .ok_or_else(|| format_err!("No references found at position"))?; diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index ab48e5ad289..e16fe644d5f 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -46,7 +46,6 @@ pub(super) fn element( }; match name_kind { - Some(NameClass::ExternCrate(_)) => SymbolKind::Module.into(), Some(NameClass::Definition(def)) => { let mut h = highlight_def(db, krate, def) | HlMod::Definition; if let Definition::ModuleDef(hir::ModuleDef::Trait(trait_)) = &def { diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html index 957fe2f8656..76d80886d11 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html @@ -39,5 +39,5 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
extern crate std;
-extern crate alloc as abc;
+extern crate alloc as abc;
 
\ No newline at end of file diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index 7e480bd34cb..eeae0553498 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs @@ -6,8 +6,8 @@ // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06). use hir::{ - db::HirDatabase, Crate, Field, GenericParam, HasVisibility, Impl, Label, Local, MacroDef, - Module, ModuleDef, Name, PathResolution, Semantics, Visibility, + Field, GenericParam, HasVisibility, Impl, Label, Local, MacroDef, Module, ModuleDef, Name, + PathResolution, Semantics, Visibility, }; use syntax::{ ast::{self, AstNode, PathSegmentKind}, @@ -108,7 +108,6 @@ pub fn name(&self, db: &RootDatabase) -> Option { /// A model special case is `None` constant in pattern. #[derive(Debug)] pub enum NameClass { - ExternCrate(Crate), Definition(Definition), /// `None` in `if let None = Some(82) {}`. /// Syntactically, it is a name, but semantically it is a reference. @@ -124,9 +123,8 @@ pub enum NameClass { impl NameClass { /// `Definition` defined by this name. - pub fn defined(self, db: &dyn HirDatabase) -> Option { + pub fn defined(self) -> Option { let res = match self { - NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), NameClass::Definition(it) => it, NameClass::ConstReference(_) => return None, NameClass::PatFieldShorthand { local_def, field_ref: _ } => { @@ -137,9 +135,8 @@ pub fn defined(self, db: &dyn HirDatabase) -> Option { } /// `Definition` referenced or defined by this name. - pub fn referenced_or_defined(self, db: &dyn HirDatabase) -> Definition { + pub fn referenced_or_defined(self) -> Definition { match self { - NameClass::ExternCrate(krate) => Definition::ModuleDef(krate.root_module(db).into()), NameClass::Definition(it) | NameClass::ConstReference(it) => it, NameClass::PatFieldShorthand { local_def: _, field_ref } => field_ref, } @@ -189,8 +186,9 @@ pub fn classify(sema: &Semantics, name: &ast::Name) -> Option { diff --git a/crates/ide_db/src/items_locator.rs b/crates/ide_db/src/items_locator.rs index ef796b6f776..39aa47fc903 100644 --- a/crates/ide_db/src/items_locator.rs +++ b/crates/ide_db/src/items_locator.rs @@ -142,7 +142,7 @@ fn get_name_definition( candidate_node }; let name = ast::Name::cast(candidate_name_node)?; - NameClass::classify(sema, &name)?.defined(sema.db) + NameClass::classify(sema, &name)?.defined() } fn is_assoc_item(item: ItemInNs, db: &RootDatabase) -> bool { diff --git a/crates/ide_diagnostics/src/handlers/incorrect_case.rs b/crates/ide_diagnostics/src/handlers/incorrect_case.rs index 68f25f28425..e2bbabd53c8 100644 --- a/crates/ide_diagnostics/src/handlers/incorrect_case.rs +++ b/crates/ide_diagnostics/src/handlers/incorrect_case.rs @@ -29,7 +29,7 @@ pub(crate) fn incorrect_case(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCas fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCase) -> Option> { let root = ctx.sema.db.parse_or_expand(d.file)?; let name_node = d.ident.to_node(&root); - let def = NameClass::classify(&ctx.sema, &name_node)?.defined(ctx.sema.db)?; + let def = NameClass::classify(&ctx.sema, &name_node)?.defined()?; let name_node = InFile::new(d.file, name_node.syntax()); let frange = name_node.original_file_range(ctx.sema.db);