Skip to content

Commit 265b10f

Browse files
committed
Correct warning message in restricted visibility
1 parent d2eadb7 commit 265b10f

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

compiler/rustc_middle/src/ty/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ impl Visibility {
297297
} else if restricted_id == tcx.parent_module_from_def_id(def_id).to_local_def_id() {
298298
"pub(self)".to_string()
299299
} else {
300-
format!("pub({})", tcx.item_name(restricted_id.to_def_id()))
300+
format!(
301+
"pub(in crate{})",
302+
tcx.def_path(restricted_id.to_def_id()).to_string_no_crate_verbose()
303+
)
301304
}
302305
}
303306
ty::Visibility::Public => "pub".to_string(),

tests/ui/imports/reexports.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ warning: glob import doesn't reexport anything with visibility `pub` because no
6262
LL | pub use super::*;
6363
| ^^^^^^^^
6464
|
65-
note: the most public imported item is `pub(a)`
65+
note: the most public imported item is `pub(in crate::a)`
6666
--> $DIR/reexports.rs:11:17
6767
|
6868
LL | pub use super::*;
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ check-pass
2+
3+
#![allow(dead_code)]
4+
5+
mod outer {
6+
pub mod inner {
7+
pub(in crate::outer) struct Foo;
8+
pub fn bar() -> Foo {
9+
//~^ WARNING type `Foo` is more private than the item `outer::inner::bar` [private_interfaces]
10+
Foo
11+
}
12+
}
13+
14+
pub mod nested {
15+
pub mod inner {
16+
pub(in crate::outer::nested) struct NestedFoo;
17+
pub fn bar() -> NestedFoo {
18+
//~^ WARNING type `NestedFoo` is more private than the item `nested::inner::bar` [private_interfaces]
19+
NestedFoo
20+
}
21+
}
22+
}
23+
}
24+
25+
fn main() {}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
warning: type `Foo` is more private than the item `outer::inner::bar`
2+
--> $DIR/pub-restricted-warning.rs:8:9
3+
|
4+
LL | pub fn bar() -> Foo {
5+
| ^^^^^^^^^^^^^^^^^^^ function `outer::inner::bar` is reachable at visibility `pub(crate)`
6+
|
7+
note: but type `Foo` is only usable at visibility `pub(in crate::outer)`
8+
--> $DIR/pub-restricted-warning.rs:7:9
9+
|
10+
LL | pub(in crate::outer) struct Foo;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: `#[warn(private_interfaces)]` on by default
13+
14+
warning: type `NestedFoo` is more private than the item `nested::inner::bar`
15+
--> $DIR/pub-restricted-warning.rs:17:13
16+
|
17+
LL | pub fn bar() -> NestedFoo {
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ function `nested::inner::bar` is reachable at visibility `pub(crate)`
19+
|
20+
note: but type `NestedFoo` is only usable at visibility `pub(in crate::outer::nested)`
21+
--> $DIR/pub-restricted-warning.rs:16:13
22+
|
23+
LL | pub(in crate::outer::nested) struct NestedFoo;
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
26+
warning: 2 warnings emitted
27+

0 commit comments

Comments
 (0)