internal: remove one more needless extern crate
This commit is contained in:
parent
dbf11b16da
commit
bbb053532e
@ -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,
|
||||
}
|
||||
};
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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(<))
|
||||
|
@ -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())
|
||||
|
@ -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(),
|
||||
),
|
||||
|
||||
_ => {
|
||||
|
@ -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<Definition> {
|
||||
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)
|
||||
|
@ -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"))?;
|
||||
|
@ -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 {
|
||||
|
@ -39,5 +39,5 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
|
||||
</style>
|
||||
<pre><code><span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module library">std</span><span class="semicolon">;</span>
|
||||
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module library">alloc</span> <span class="keyword">as</span> <span class="module">abc</span><span class="semicolon">;</span>
|
||||
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module library">alloc</span> <span class="keyword">as</span> <span class="module declaration library">abc</span><span class="semicolon">;</span>
|
||||
</code></pre>
|
@ -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<Name> {
|
||||
/// 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<Definition> {
|
||||
pub fn defined(self) -> Option<Definition> {
|
||||
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> {
|
||||
}
|
||||
|
||||
/// `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<RootDatabase>, name: &ast::Name) -> Option<Name
|
||||
Some(NameClass::Definition(name_ref_class.referenced()))
|
||||
} else {
|
||||
let extern_crate = it.syntax().parent().and_then(ast::ExternCrate::cast)?;
|
||||
let resolved = sema.resolve_extern_crate(&extern_crate)?;
|
||||
Some(NameClass::ExternCrate(resolved))
|
||||
let krate = sema.resolve_extern_crate(&extern_crate)?;
|
||||
let root_module = krate.root_module(sema.db);
|
||||
Some(NameClass::Definition(Definition::ModuleDef(root_module.into())))
|
||||
}
|
||||
},
|
||||
ast::IdentPat(it) => {
|
||||
|
@ -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 {
|
||||
|
@ -29,7 +29,7 @@ pub(crate) fn incorrect_case(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCas
|
||||
fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCase) -> Option<Vec<Assist>> {
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user