This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +57
-2
lines changed
compiler/rustc_middle/src/ty Expand file tree Collapse file tree 4 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -309,7 +309,10 @@ impl Visibility {
309309 } else if restricted_id == tcx. parent_module_from_def_id ( def_id) . to_local_def_id ( ) {
310310 "pub(self)" . to_string ( )
311311 } else {
312- format ! ( "pub({})" , tcx. item_name( restricted_id. to_def_id( ) ) )
312+ format ! (
313+ "pub(in crate{})" ,
314+ tcx. def_path( restricted_id. to_def_id( ) ) . to_string_no_crate_verbose( )
315+ )
313316 }
314317 }
315318 ty:: Visibility :: Public => "pub" . to_string ( ) ,
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ warning: glob import doesn't reexport anything with visibility `pub` because no
6262LL | 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 |
6868LL | pub use super::*;
Original file line number Diff line number Diff line change 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 ( ) { }
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments