mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 17:07:26 +00:00
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)]
|
||||
struct ImportDirective {
|
||||
/// The module this import directive is in.
|
||||
module_id: LocalModuleId,
|
||||
import: Import,
|
||||
status: PartialResolvedImport,
|
||||
|
@ -963,8 +964,10 @@ impl DefCollector<'_> {
|
|||
|
||||
fn update(
|
||||
&mut self,
|
||||
// The module for which `resolutions` have been resolve
|
||||
module_id: LocalModuleId,
|
||||
resolutions: &[(Option<Name>, PerNs)],
|
||||
// Visibility this import will have
|
||||
vis: Visibility,
|
||||
import_type: ImportType,
|
||||
) {
|
||||
|
@ -974,6 +977,7 @@ impl DefCollector<'_> {
|
|||
|
||||
fn update_recursive(
|
||||
&mut self,
|
||||
// The module for which `resolutions` have been resolve
|
||||
module_id: LocalModuleId,
|
||||
resolutions: &[(Option<Name>, PerNs)],
|
||||
// All resolutions are imported with this visibility; the visibilities in
|
||||
|
|
|
@ -73,7 +73,10 @@ impl DefMap {
|
|||
pub(crate) fn resolve_visibility(
|
||||
&self,
|
||||
db: &dyn DefDatabase,
|
||||
// module to import to
|
||||
original_module: LocalModuleId,
|
||||
// pub(path)
|
||||
// ^^^^ this
|
||||
visibility: &RawVisibility,
|
||||
) -> Option<Visibility> {
|
||||
let mut vis = match visibility {
|
||||
|
@ -115,6 +118,7 @@ impl DefMap {
|
|||
&self,
|
||||
db: &dyn DefDatabase,
|
||||
mode: ResolveMode,
|
||||
// module to import to
|
||||
mut original_module: LocalModuleId,
|
||||
path: &ModPath,
|
||||
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))
|
||||
|
|
|
@ -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…
Reference in a new issue