fix: check visibility of each segment in path resolution
This commit is contained in:
parent
599142c34a
commit
dea49d0826
3 changed files with 41 additions and 0 deletions
|
@ -212,6 +212,7 @@ impl Import {
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
struct ImportDirective {
|
struct ImportDirective {
|
||||||
|
/// The module this import directive is in.
|
||||||
module_id: LocalModuleId,
|
module_id: LocalModuleId,
|
||||||
import: Import,
|
import: Import,
|
||||||
status: PartialResolvedImport,
|
status: PartialResolvedImport,
|
||||||
|
@ -963,8 +964,10 @@ impl DefCollector<'_> {
|
||||||
|
|
||||||
fn update(
|
fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
// The module for which `resolutions` have been resolve
|
||||||
module_id: LocalModuleId,
|
module_id: LocalModuleId,
|
||||||
resolutions: &[(Option<Name>, PerNs)],
|
resolutions: &[(Option<Name>, PerNs)],
|
||||||
|
// Visibility this import will have
|
||||||
vis: Visibility,
|
vis: Visibility,
|
||||||
import_type: ImportType,
|
import_type: ImportType,
|
||||||
) {
|
) {
|
||||||
|
@ -974,6 +977,7 @@ impl DefCollector<'_> {
|
||||||
|
|
||||||
fn update_recursive(
|
fn update_recursive(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
// The module for which `resolutions` have been resolve
|
||||||
module_id: LocalModuleId,
|
module_id: LocalModuleId,
|
||||||
resolutions: &[(Option<Name>, PerNs)],
|
resolutions: &[(Option<Name>, PerNs)],
|
||||||
// All resolutions are imported with this visibility; the visibilities in
|
// All resolutions are imported with this visibility; the visibilities in
|
||||||
|
|
|
@ -73,7 +73,10 @@ impl DefMap {
|
||||||
pub(crate) fn resolve_visibility(
|
pub(crate) fn resolve_visibility(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
|
// module to import to
|
||||||
original_module: LocalModuleId,
|
original_module: LocalModuleId,
|
||||||
|
// pub(path)
|
||||||
|
// ^^^^ this
|
||||||
visibility: &RawVisibility,
|
visibility: &RawVisibility,
|
||||||
) -> Option<Visibility> {
|
) -> Option<Visibility> {
|
||||||
let mut vis = match visibility {
|
let mut vis = match visibility {
|
||||||
|
@ -115,6 +118,7 @@ impl DefMap {
|
||||||
&self,
|
&self,
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
mode: ResolveMode,
|
mode: ResolveMode,
|
||||||
|
// module to import to
|
||||||
mut original_module: LocalModuleId,
|
mut original_module: LocalModuleId,
|
||||||
path: &ModPath,
|
path: &ModPath,
|
||||||
shadow: BuiltinShadowMode,
|
shadow: BuiltinShadowMode,
|
||||||
|
@ -361,6 +365,9 @@ impl DefMap {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
curr_per_ns = curr_per_ns
|
||||||
|
.filter_visibility(|vis| vis.is_visible_from_def_map(db, self, original_module));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolvePathResult::with(curr_per_ns, ReachedFixedPoint::Yes, None, Some(self.krate))
|
ResolvePathResult::with(curr_per_ns, ReachedFixedPoint::Yes, None, Some(self.krate))
|
||||||
|
|
|
@ -336,3 +336,33 @@ mod d {
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn glob_name_collision_check_visibility() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
mod event {
|
||||||
|
mod serenity {
|
||||||
|
pub fn Event() {}
|
||||||
|
}
|
||||||
|
use serenity::*;
|
||||||
|
|
||||||
|
pub struct Event {}
|
||||||
|
}
|
||||||
|
|
||||||
|
use event::Event;
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
crate
|
||||||
|
Event: t
|
||||||
|
event: t
|
||||||
|
|
||||||
|
crate::event
|
||||||
|
Event: t v
|
||||||
|
serenity: t
|
||||||
|
|
||||||
|
crate::event::serenity
|
||||||
|
Event: v
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue