mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
minor: address review comments
This commit is contained in:
parent
7ec8434674
commit
60e7c1de83
@ -346,6 +346,22 @@ impl ModuleDef {
|
||||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for ModuleDef {
|
||||
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
|
||||
match *self {
|
||||
ModuleDef::Module(it) => it.visibility(db),
|
||||
ModuleDef::Function(it) => it.visibility(db),
|
||||
ModuleDef::Adt(it) => it.visibility(db),
|
||||
ModuleDef::Const(it) => it.visibility(db),
|
||||
ModuleDef::Static(it) => it.visibility(db),
|
||||
ModuleDef::Trait(it) => it.visibility(db),
|
||||
ModuleDef::TypeAlias(it) => it.visibility(db),
|
||||
ModuleDef::Variant(it) => it.visibility(db),
|
||||
ModuleDef::BuiltinType(_) => Visibility::Public,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Module {
|
||||
/// Name of this module.
|
||||
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
|
||||
|
@ -809,22 +809,22 @@ fn baz(bar: Bar) {}
|
||||
",
|
||||
);
|
||||
|
||||
// check_assist_not_applicable(
|
||||
// expand_glob_import,
|
||||
// r"
|
||||
// mod foo {
|
||||
// mod bar {
|
||||
// pub mod baz {
|
||||
// pub struct Baz;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
check_assist_not_applicable(
|
||||
expand_glob_import,
|
||||
r"
|
||||
mod foo {
|
||||
mod bar {
|
||||
pub mod baz {
|
||||
pub struct Baz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// use foo::bar::baz::*$0;
|
||||
use foo::bar::baz::*$0;
|
||||
|
||||
// fn qux(baz: Baz) {}
|
||||
// ",
|
||||
// );
|
||||
fn qux(baz: Baz) {}
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -46,18 +46,7 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> O
|
||||
let current_module = ctx.sema.scope(path.syntax()).module()?;
|
||||
let target_module = def.module(ctx.db())?;
|
||||
|
||||
let vis = match def {
|
||||
hir::ModuleDef::Module(it) => it.visibility(ctx.db()),
|
||||
hir::ModuleDef::Function(it) => it.visibility(ctx.db()),
|
||||
hir::ModuleDef::Adt(it) => it.visibility(ctx.db()),
|
||||
hir::ModuleDef::Variant(it) => it.visibility(ctx.db()),
|
||||
hir::ModuleDef::Const(it) => it.visibility(ctx.db()),
|
||||
hir::ModuleDef::Static(it) => it.visibility(ctx.db()),
|
||||
hir::ModuleDef::Trait(it) => it.visibility(ctx.db()),
|
||||
hir::ModuleDef::TypeAlias(it) => it.visibility(ctx.db()),
|
||||
hir::ModuleDef::BuiltinType(_) => return None,
|
||||
};
|
||||
if vis.is_visible_from(ctx.db(), current_module.into()) {
|
||||
if def.visibility(ctx.db()).is_visible_from(ctx.db(), current_module.into()) {
|
||||
return None;
|
||||
};
|
||||
|
||||
|
@ -44,17 +44,7 @@ impl Definition {
|
||||
pub fn visibility(&self, db: &RootDatabase) -> Option<Visibility> {
|
||||
match self {
|
||||
Definition::Field(sf) => Some(sf.visibility(db)),
|
||||
Definition::ModuleDef(def) => match def {
|
||||
ModuleDef::Module(it) => Some(it.visibility(db)),
|
||||
ModuleDef::Function(it) => Some(it.visibility(db)),
|
||||
ModuleDef::Adt(it) => Some(it.visibility(db)),
|
||||
ModuleDef::Const(it) => Some(it.visibility(db)),
|
||||
ModuleDef::Static(it) => Some(it.visibility(db)),
|
||||
ModuleDef::Trait(it) => Some(it.visibility(db)),
|
||||
ModuleDef::TypeAlias(it) => Some(it.visibility(db)),
|
||||
ModuleDef::Variant(it) => Some(it.visibility(db)),
|
||||
ModuleDef::BuiltinType(_) => None,
|
||||
},
|
||||
Definition::ModuleDef(def) => Some(def.visibility(db)),
|
||||
Definition::Macro(_)
|
||||
| Definition::SelfType(_)
|
||||
| Definition::Local(_)
|
||||
|
Loading…
Reference in New Issue
Block a user