From a68334a87501c04ea2d62dc9d788aa43651f5ffc Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 12 Jan 2020 16:20:57 +0300 Subject: [PATCH] resolve: Say "import" when reporting private imports --- src/librustc_resolve/diagnostics.rs | 3 +++ src/test/ui/extern/extern-crate-visibility.rs | 4 ++-- src/test/ui/extern/extern-crate-visibility.stderr | 12 ++++++------ src/test/ui/import.stderr | 6 +++--- src/test/ui/imports/issue-55884-2.rs | 2 +- src/test/ui/imports/issue-55884-2.stderr | 6 +++--- src/test/ui/imports/reexports.stderr | 12 ++++++------ src/test/ui/privacy/privacy2.stderr | 6 +++--- src/test/ui/proc-macro/disappearing-resolution.rs | 2 +- .../ui/proc-macro/disappearing-resolution.stderr | 6 +++--- src/test/ui/shadowed/shadowed-use-visibility.rs | 4 ++-- src/test/ui/shadowed/shadowed-use-visibility.stderr | 12 ++++++------ 12 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 20c8f78b1cf0e..a433ae8ed676a 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -921,6 +921,9 @@ impl<'a> Resolver<'a> { if is_constructor { descr += " constructor"; } + if binding.is_import() { + descr += " import"; + } let mut err = struct_span_err!(session, ident.span, E0603, "{} `{}` is private", descr, ident); diff --git a/src/test/ui/extern/extern-crate-visibility.rs b/src/test/ui/extern/extern-crate-visibility.rs index e0a5cd5e98f4b..cda1227cc8e92 100644 --- a/src/test/ui/extern/extern-crate-visibility.rs +++ b/src/test/ui/extern/extern-crate-visibility.rs @@ -3,10 +3,10 @@ mod foo { } // Check that private crates can be used from outside their modules, albeit with warnings -use foo::core::cell; //~ ERROR crate `core` is private +use foo::core::cell; //~ ERROR crate import `core` is private fn f() { - foo::core::cell::Cell::new(0); //~ ERROR crate `core` is private + foo::core::cell::Cell::new(0); //~ ERROR crate import `core` is private use foo::*; mod core {} // Check that private crates are not glob imported diff --git a/src/test/ui/extern/extern-crate-visibility.stderr b/src/test/ui/extern/extern-crate-visibility.stderr index 6d38b4d8d66d6..d0c073d67a4ee 100644 --- a/src/test/ui/extern/extern-crate-visibility.stderr +++ b/src/test/ui/extern/extern-crate-visibility.stderr @@ -1,22 +1,22 @@ -error[E0603]: crate `core` is private +error[E0603]: crate import `core` is private --> $DIR/extern-crate-visibility.rs:6:10 | LL | use foo::core::cell; - | ^^^^ this crate is private + | ^^^^ this crate import is private | -note: the crate `core` is defined here +note: the crate import `core` is defined here --> $DIR/extern-crate-visibility.rs:2:5 | LL | extern crate core; | ^^^^^^^^^^^^^^^^^^ -error[E0603]: crate `core` is private +error[E0603]: crate import `core` is private --> $DIR/extern-crate-visibility.rs:9:10 | LL | foo::core::cell::Cell::new(0); - | ^^^^ this crate is private + | ^^^^ this crate import is private | -note: the crate `core` is defined here +note: the crate import `core` is defined here --> $DIR/extern-crate-visibility.rs:2:5 | LL | extern crate core; diff --git a/src/test/ui/import.stderr b/src/test/ui/import.stderr index c66a4fa7151dc..5219ffacd15c0 100644 --- a/src/test/ui/import.stderr +++ b/src/test/ui/import.stderr @@ -13,13 +13,13 @@ error[E0432]: unresolved import `foo` LL | use foo; | ^^^ no `foo` in the root -error[E0603]: unresolved item `foo` is private +error[E0603]: unresolved item import `foo` is private --> $DIR/import.rs:15:10 | LL | zed::foo(); - | ^^^ this unresolved item is private + | ^^^ this unresolved item import is private | -note: the unresolved item `foo` is defined here +note: the unresolved item import `foo` is defined here --> $DIR/import.rs:10:9 | LL | use foo; diff --git a/src/test/ui/imports/issue-55884-2.rs b/src/test/ui/imports/issue-55884-2.rs index 1b4f652c9fc2f..75bb4206f97d6 100644 --- a/src/test/ui/imports/issue-55884-2.rs +++ b/src/test/ui/imports/issue-55884-2.rs @@ -9,6 +9,6 @@ mod parser { use ParseOptions; } -pub use parser::ParseOptions; //~ ERROR struct `ParseOptions` is private +pub use parser::ParseOptions; //~ ERROR struct import `ParseOptions` is private fn main() {} diff --git a/src/test/ui/imports/issue-55884-2.stderr b/src/test/ui/imports/issue-55884-2.stderr index 9e77283cd5946..f16d2adb3656e 100644 --- a/src/test/ui/imports/issue-55884-2.stderr +++ b/src/test/ui/imports/issue-55884-2.stderr @@ -1,10 +1,10 @@ -error[E0603]: struct `ParseOptions` is private +error[E0603]: struct import `ParseOptions` is private --> $DIR/issue-55884-2.rs:12:17 | LL | pub use parser::ParseOptions; - | ^^^^^^^^^^^^ this struct is private + | ^^^^^^^^^^^^ this struct import is private | -note: the struct `ParseOptions` is defined here +note: the struct import `ParseOptions` is defined here --> $DIR/issue-55884-2.rs:9:9 | LL | use ParseOptions; diff --git a/src/test/ui/imports/reexports.stderr b/src/test/ui/imports/reexports.stderr index 67c12e0c8d3ca..b173884080f80 100644 --- a/src/test/ui/imports/reexports.stderr +++ b/src/test/ui/imports/reexports.stderr @@ -10,25 +10,25 @@ note: consider marking `foo` as `pub` in the imported module LL | pub use super::foo; | ^^^^^^^^^^ -error[E0603]: module `foo` is private +error[E0603]: module import `foo` is private --> $DIR/reexports.rs:33:15 | LL | use b::a::foo::S; - | ^^^ this module is private + | ^^^ this module import is private | -note: the module `foo` is defined here +note: the module import `foo` is defined here --> $DIR/reexports.rs:21:17 | LL | pub use super::foo; // This is OK since the value `foo` is visible enough. | ^^^^^^^^^^ -error[E0603]: module `foo` is private +error[E0603]: module import `foo` is private --> $DIR/reexports.rs:34:15 | LL | use b::b::foo::S as T; - | ^^^ this module is private + | ^^^ this module import is private | -note: the module `foo` is defined here +note: the module import `foo` is defined here --> $DIR/reexports.rs:26:17 | LL | pub use super::*; // This is also OK since the value `foo` is visible enough. diff --git a/src/test/ui/privacy/privacy2.stderr b/src/test/ui/privacy/privacy2.stderr index d9f003ddae7ac..719dc27ccf4d6 100644 --- a/src/test/ui/privacy/privacy2.stderr +++ b/src/test/ui/privacy/privacy2.stderr @@ -4,13 +4,13 @@ error[E0432]: unresolved import `bar::foo` LL | use bar::foo; | ^^^^^^^^ no `foo` in `bar` -error[E0603]: function `foo` is private +error[E0603]: function import `foo` is private --> $DIR/privacy2.rs:23:20 | LL | use bar::glob::foo; - | ^^^ this function is private + | ^^^ this function import is private | -note: the function `foo` is defined here +note: the function import `foo` is defined here --> $DIR/privacy2.rs:10:13 | LL | use foo; diff --git a/src/test/ui/proc-macro/disappearing-resolution.rs b/src/test/ui/proc-macro/disappearing-resolution.rs index a01b8f302cae3..50f04b1eae150 100644 --- a/src/test/ui/proc-macro/disappearing-resolution.rs +++ b/src/test/ui/proc-macro/disappearing-resolution.rs @@ -8,7 +8,7 @@ extern crate test_macros; mod m { use test_macros::Empty; } -use m::Empty; //~ ERROR derive macro `Empty` is private +use m::Empty; //~ ERROR derive macro import `Empty` is private // To resolve `empty_helper` we need to resolve `Empty`. // During initial resolution `use m::Empty` introduces no entries, so we proceed to `macro_use`, diff --git a/src/test/ui/proc-macro/disappearing-resolution.stderr b/src/test/ui/proc-macro/disappearing-resolution.stderr index d81ab5ebf9bc6..3beaedf61d73a 100644 --- a/src/test/ui/proc-macro/disappearing-resolution.stderr +++ b/src/test/ui/proc-macro/disappearing-resolution.stderr @@ -4,13 +4,13 @@ error: cannot find attribute `empty_helper` in this scope LL | #[empty_helper] | ^^^^^^^^^^^^ -error[E0603]: derive macro `Empty` is private +error[E0603]: derive macro import `Empty` is private --> $DIR/disappearing-resolution.rs:11:8 | LL | use m::Empty; - | ^^^^^ this derive macro is private + | ^^^^^ this derive macro import is private | -note: the derive macro `Empty` is defined here +note: the derive macro import `Empty` is defined here --> $DIR/disappearing-resolution.rs:9:9 | LL | use test_macros::Empty; diff --git a/src/test/ui/shadowed/shadowed-use-visibility.rs b/src/test/ui/shadowed/shadowed-use-visibility.rs index 8185e82ee830e..6b801972f4179 100644 --- a/src/test/ui/shadowed/shadowed-use-visibility.rs +++ b/src/test/ui/shadowed/shadowed-use-visibility.rs @@ -6,11 +6,11 @@ mod foo { } mod bar { - use foo::bar::f as g; //~ ERROR module `bar` is private + use foo::bar::f as g; //~ ERROR module import `bar` is private use foo as f; pub use foo::*; } -use bar::f::f; //~ ERROR module `f` is private +use bar::f::f; //~ ERROR module import `f` is private fn main() {} diff --git a/src/test/ui/shadowed/shadowed-use-visibility.stderr b/src/test/ui/shadowed/shadowed-use-visibility.stderr index 77bf2abe34555..cd8ec13794c6f 100644 --- a/src/test/ui/shadowed/shadowed-use-visibility.stderr +++ b/src/test/ui/shadowed/shadowed-use-visibility.stderr @@ -1,22 +1,22 @@ -error[E0603]: module `bar` is private +error[E0603]: module import `bar` is private --> $DIR/shadowed-use-visibility.rs:9:14 | LL | use foo::bar::f as g; - | ^^^ this module is private + | ^^^ this module import is private | -note: the module `bar` is defined here +note: the module import `bar` is defined here --> $DIR/shadowed-use-visibility.rs:4:9 | LL | use foo as bar; | ^^^^^^^^^^ -error[E0603]: module `f` is private +error[E0603]: module import `f` is private --> $DIR/shadowed-use-visibility.rs:15:10 | LL | use bar::f::f; - | ^ this module is private + | ^ this module import is private | -note: the module `f` is defined here +note: the module import `f` is defined here --> $DIR/shadowed-use-visibility.rs:11:9 | LL | use foo as f;