diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2023-11-19 17:46:44 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2023-12-04 22:26:08 +0000 |
| commit | beaf31581a1ade80bbd934e87ae3fa9b2b4c88a4 (patch) | |
| tree | 873154c68fe4c833f5970bfdcb8a831f669c34d0 /tests | |
| parent | 0e2dac8375950a12812ec65868e42b43ed214ef9 (diff) | |
| download | rust-beaf31581a1ade80bbd934e87ae3fa9b2b4c88a4.tar.gz rust-beaf31581a1ade80bbd934e87ae3fa9b2b4c88a4.zip | |
Structured `use` suggestion on privacy error
When encoutering a privacy error on an item through a re-export that is accessible in an alternative path, provide a structured suggestion with that path. ``` error[E0603]: module import `mem` is private --> $DIR/private-std-reexport-suggest-public.rs:4:14 | LL | use foo::mem; | ^^^ private module import | note: the module import `mem` is defined here... --> $DIR/private-std-reexport-suggest-public.rs:8:9 | LL | use std::mem; | ^^^^^^^^ note: ...and refers to the module `mem` which is defined here --> $SRC_DIR/std/src/lib.rs:LL:COL | = note: you could import this help: import `mem` through the re-export | LL | use std::mem; | ~~~~~~~~ ``` Fix #42909.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/imports/issue-55884-2.stderr | 10 | ||||
| -rw-r--r-- | tests/ui/imports/private-std-reexport-suggest-public.fixed | 9 | ||||
| -rw-r--r-- | tests/ui/imports/private-std-reexport-suggest-public.rs | 9 | ||||
| -rw-r--r-- | tests/ui/imports/private-std-reexport-suggest-public.stderr | 23 | ||||
| -rw-r--r-- | tests/ui/privacy/privacy2.stderr | 2 | ||||
| -rw-r--r-- | tests/ui/proc-macro/disappearing-resolution.stderr | 6 |
6 files changed, 54 insertions, 5 deletions
diff --git a/tests/ui/imports/issue-55884-2.stderr b/tests/ui/imports/issue-55884-2.stderr index a409265525b..8a9d5f2a6d8 100644 --- a/tests/ui/imports/issue-55884-2.stderr +++ b/tests/ui/imports/issue-55884-2.stderr @@ -13,17 +13,21 @@ note: ...and refers to the struct import `ParseOptions` which is defined here... --> $DIR/issue-55884-2.rs:13:9 | LL | pub use parser::ParseOptions; - | ^^^^^^^^^^^^^^^^^^^^ consider importing it directly + | ^^^^^^^^^^^^^^^^^^^^ you could import this re-export note: ...and refers to the struct import `ParseOptions` which is defined here... --> $DIR/issue-55884-2.rs:6:13 | LL | pub use options::*; - | ^^^^^^^^^^ consider importing it directly + | ^^^^^^^^^^ you could import this re-export note: ...and refers to the struct `ParseOptions` which is defined here --> $DIR/issue-55884-2.rs:2:5 | LL | pub struct ParseOptions {} - | ^^^^^^^^^^^^^^^^^^^^^^^ consider importing it directly + | ^^^^^^^^^^^^^^^^^^^^^^^ you could import this directly +help: import `ParseOptions` through the re-export + | +LL | pub use parser::ParseOptions; + | ~~~~~~~~~~~~~~~~~~~~ error: aborting due to 1 previous error diff --git a/tests/ui/imports/private-std-reexport-suggest-public.fixed b/tests/ui/imports/private-std-reexport-suggest-public.fixed new file mode 100644 index 00000000000..b6fd22f5d3f --- /dev/null +++ b/tests/ui/imports/private-std-reexport-suggest-public.fixed @@ -0,0 +1,9 @@ +// run-rustfix +#![allow(unused_imports)] +fn main() { + use std::mem; //~ ERROR module import `mem` is private +} + +pub mod foo { + use std::mem; +} diff --git a/tests/ui/imports/private-std-reexport-suggest-public.rs b/tests/ui/imports/private-std-reexport-suggest-public.rs new file mode 100644 index 00000000000..1247055af60 --- /dev/null +++ b/tests/ui/imports/private-std-reexport-suggest-public.rs @@ -0,0 +1,9 @@ +// run-rustfix +#![allow(unused_imports)] +fn main() { + use foo::mem; //~ ERROR module import `mem` is private +} + +pub mod foo { + use std::mem; +} diff --git a/tests/ui/imports/private-std-reexport-suggest-public.stderr b/tests/ui/imports/private-std-reexport-suggest-public.stderr new file mode 100644 index 00000000000..222553235aa --- /dev/null +++ b/tests/ui/imports/private-std-reexport-suggest-public.stderr @@ -0,0 +1,23 @@ +error[E0603]: module import `mem` is private + --> $DIR/private-std-reexport-suggest-public.rs:4:14 + | +LL | use foo::mem; + | ^^^ private module import + | +note: the module import `mem` is defined here... + --> $DIR/private-std-reexport-suggest-public.rs:8:9 + | +LL | use std::mem; + | ^^^^^^^^ +note: ...and refers to the module `mem` which is defined here + --> $SRC_DIR/std/src/lib.rs:LL:COL + | + = note: you could import this directly +help: import `mem` through the re-export + | +LL | use std::mem; + | ~~~~~~~~ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/privacy/privacy2.stderr b/tests/ui/privacy/privacy2.stderr index e7135d3fd8a..46bb9823dbf 100644 --- a/tests/ui/privacy/privacy2.stderr +++ b/tests/ui/privacy/privacy2.stderr @@ -19,7 +19,7 @@ note: ...and refers to the function `foo` which is defined here --> $DIR/privacy2.rs:16:1 | LL | pub fn foo() {} - | ^^^^^^^^^^^^ consider importing it directly + | ^^^^^^^^^^^^ you could import this directly error: requires `sized` lang_item diff --git a/tests/ui/proc-macro/disappearing-resolution.stderr b/tests/ui/proc-macro/disappearing-resolution.stderr index 5b969549a11..e6d0868687e 100644 --- a/tests/ui/proc-macro/disappearing-resolution.stderr +++ b/tests/ui/proc-macro/disappearing-resolution.stderr @@ -19,7 +19,11 @@ note: ...and refers to the derive macro `Empty` which is defined here --> $DIR/auxiliary/test-macros.rs:25:1 | LL | pub fn empty_derive(_: TokenStream) -> TokenStream { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ consider importing it directly + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ you could import this directly +help: import `Empty` directly + | +LL | use test_macros::Empty; + | ~~~~~~~~~~~~~~~~~~ error: aborting due to 2 previous errors |
