Skip to content

Commit d54745a

Browse files
committed
fix: Fix item tree lowering pub(self) to pub()
1 parent 2d879e0 commit d54745a

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed

crates/hir-def/src/item_tree/tests.rs

+12
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,15 @@ struct S<#[cfg(never)] T>;
370370
"#]],
371371
)
372372
}
373+
374+
#[test]
375+
fn pub_self() {
376+
check(
377+
r#"
378+
pub(self) struct S;
379+
"#,
380+
expect![[r#"
381+
pub(self) struct S;
382+
"#]],
383+
)
384+
}

crates/hir-def/src/nameres/path_resolution.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,11 @@ impl DefMap {
9393
if remaining.is_some() {
9494
return None;
9595
}
96-
let types = result.take_types();
97-
98-
match (types, path.kind) {
99-
(Some(ModuleDefId::ModuleId(m)), _) => Visibility::Module(m),
100-
// resolve_path doesn't find any values for a plan pathkind of a private function
101-
(None, PathKind::Plain | PathKind::Crate) => {
102-
Visibility::Module(self.module_id(original_module))
103-
}
104-
(_, _) => {
96+
let types = result.take_types()?;
97+
match types {
98+
ModuleDefId::ModuleId(m) => Visibility::Module(m),
99+
// error: visibility needs to refer to module
100+
_ => {
105101
return None;
106102
}
107103
}

crates/hir-def/src/visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl RawVisibility {
7373
RawVisibility::Module(path)
7474
}
7575
ast::VisibilityKind::PubSelf => {
76-
let path = ModPath::from_kind(PathKind::Plain);
76+
let path = ModPath::from_kind(PathKind::Super(0));
7777
RawVisibility::Module(path)
7878
}
7979
ast::VisibilityKind::Pub => RawVisibility::Public,

crates/ide-completion/src/completions/expr.rs

+9-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Completion of names from the current scope in expression position.
22
3-
use hir::{HasVisibility, Module, ScopeDef};
3+
use hir::ScopeDef;
44
use syntax::ast;
55

66
use crate::{
@@ -9,23 +9,6 @@ use crate::{
99
CompletionContext, Completions,
1010
};
1111

12-
fn scope_def_applicable(
13-
def: ScopeDef,
14-
ctx: &CompletionContext<'_>,
15-
module: Option<&Module>,
16-
) -> bool {
17-
match (def, module) {
18-
(ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) | ScopeDef::Label(_), _) => {
19-
false
20-
}
21-
(ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac)), _) => mac.is_fn_like(ctx.db),
22-
(ScopeDef::ModuleDef(hir::ModuleDef::Function(f)), Some(m)) => {
23-
f.is_visible_from(ctx.db, *m)
24-
}
25-
_ => true,
26-
}
27-
}
28-
2912
pub(crate) fn complete_expr_path(
3013
acc: &mut Completions,
3114
ctx: &CompletionContext<'_>,
@@ -54,6 +37,12 @@ pub(crate) fn complete_expr_path(
5437
let wants_mut_token =
5538
ref_expr_parent.as_ref().map(|it| it.mut_token().is_none()).unwrap_or(false);
5639

40+
let scope_def_applicable = |def| match def {
41+
ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) | ScopeDef::Label(_) => false,
42+
ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac)) => mac.is_fn_like(ctx.db),
43+
_ => true,
44+
};
45+
5746
let add_assoc_item = |acc: &mut Completions, item| match item {
5847
hir::AssocItem::Function(func) => acc.add_function(ctx, path_ctx, func, None),
5948
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
@@ -98,7 +87,7 @@ pub(crate) fn complete_expr_path(
9887
hir::PathResolution::Def(hir::ModuleDef::Module(module)) => {
9988
let module_scope = module.scope(ctx.db, Some(ctx.module));
10089
for (name, def) in module_scope {
101-
if scope_def_applicable(def, ctx, Some(module)) {
90+
if scope_def_applicable(def) {
10291
acc.add_path_resolution(
10392
ctx,
10493
path_ctx,
@@ -244,7 +233,7 @@ pub(crate) fn complete_expr_path(
244233
[..] => acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases),
245234
}
246235
}
247-
_ if scope_def_applicable(def, ctx, None) => {
236+
_ if scope_def_applicable(def) => {
248237
acc.add_path_resolution(ctx, path_ctx, name, def, doc_aliases)
249238
}
250239
_ => (),

crates/ide-completion/src/tests/special.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ fn completes_only_public() {
12921292
r#"
12931293
//- /e.rs
12941294
pub(self) fn i_should_be_hidden() {}
1295-
pub(in crate::krate) fn i_should_also_be_hidden() {}
1295+
pub(in crate::e) fn i_should_also_be_hidden() {}
12961296
pub fn i_am_public () {}
12971297
12981298
//- /lib.rs crate:krate

0 commit comments

Comments
 (0)