Skip to content

Commit

Permalink
resolve: Point at the private item definitions in privacy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 12, 2020
1 parent daff425 commit 4d596e8
Show file tree
Hide file tree
Showing 49 changed files with 1,034 additions and 154 deletions.
24 changes: 15 additions & 9 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,15 +917,21 @@ impl<'a> Resolver<'a> {
let PrivacyError { ident, binding, .. } = *privacy_error;
let session = &self.session;
let mk_struct_span_error = |is_constructor| {
struct_span_err!(
session,
ident.span,
E0603,
"{}{} `{}` is private",
binding.res().descr(),
if is_constructor { " constructor" } else { "" },
ident.name,
)
let mut descr = binding.res().descr().to_string();
if is_constructor {
descr += " constructor";
}

let mut err =
struct_span_err!(session, ident.span, E0603, "{} `{}` is private", descr, ident);

err.span_label(ident.span, &format!("this {} is private", descr));
err.span_note(
session.source_map().def_span(binding.span),
&format!("the {} `{}` is defined here", descr, ident),
);

err
};

let mut err = if let NameBindingKind::Res(
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/error-codes/E0603.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ error[E0603]: constant `PRIVATE` is private
--> $DIR/E0603.rs:6:17
|
LL | SomeModule::PRIVATE;
| ^^^^^^^
| ^^^^^^^ this constant is private
|
note: the constant `PRIVATE` is defined here
--> $DIR/E0603.rs:2:5
|
LL | const PRIVATE: u32 = 0x_a_bad_1dea_u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/error-festival.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ error[E0603]: constant `FOO` is private
--> $DIR/error-festival.rs:22:10
|
LL | foo::FOO;
| ^^^
| ^^^ this constant is private
|
note: the constant `FOO` is defined here
--> $DIR/error-festival.rs:7:5
|
LL | const FOO: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^

error[E0368]: binary assignment operation `+=` cannot be applied to type `&str`
--> $DIR/error-festival.rs:12:5
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/export-import.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ error[E0603]: function `unexported` is private
--> $DIR/export-import.rs:1:8
|
LL | use m::unexported;
| ^^^^^^^^^^
| ^^^^^^^^^^ this function is private
|
note: the function `unexported` is defined here
--> $DIR/export-import.rs:7:5
|
LL | fn unexported() { }
| ^^^^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/export-tag-variant.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ error[E0603]: enum `Y` is private
--> $DIR/export-tag-variant.rs:7:26
|
LL | fn main() { let z = foo::Y::Y1; }
| ^
| ^ this enum is private
|
note: the enum `Y` is defined here
--> $DIR/export-tag-variant.rs:4:5
|
LL | enum Y { Y1 }
| ^^^^^^

error: aborting due to previous error

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/export.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ error[E0603]: function `z` is private
--> $DIR/export.rs:10:18
|
LL | fn main() { foo::z(10); }
| ^
| ^ this function is private
|
note: the function `z` is defined here
--> $DIR/export.rs:5:5
|
LL | fn z(y: isize) { log(debug, y); }
| ^^^^^^^^^^^^^^

error: aborting due to 5 previous errors

Expand Down
16 changes: 14 additions & 2 deletions src/test/ui/extern/extern-crate-visibility.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ error[E0603]: crate `core` is private
--> $DIR/extern-crate-visibility.rs:6:10
|
LL | use foo::core::cell;
| ^^^^
| ^^^^ this crate is private
|
note: the crate `core` is defined here
--> $DIR/extern-crate-visibility.rs:2:5
|
LL | extern crate core;
| ^^^^^^^^^^^^^^^^^^

error[E0603]: crate `core` is private
--> $DIR/extern-crate-visibility.rs:9:10
|
LL | foo::core::cell::Cell::new(0);
| ^^^^
| ^^^^ this crate is private
|
note: the crate `core` is defined here
--> $DIR/extern-crate-visibility.rs:2:5
|
LL | extern crate core;
| ^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/hygiene/privacy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ error[E0603]: function `f` is private
--> $DIR/privacy.rs:16:14
|
LL | foo::f()
| ^
| ^ this function is private
|
note: the function `f` is defined here
--> $DIR/privacy.rs:4:5
|
LL | fn f() {}
| ^^^^^^

error: aborting due to previous error

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/import.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ error[E0603]: unresolved item `foo` is private
--> $DIR/import.rs:15:10
|
LL | zed::foo();
| ^^^
| ^^^ this unresolved item is private
|
note: the unresolved item `foo` is defined here
--> $DIR/import.rs:10:9
|
LL | use foo;
| ^^^

error: aborting due to 3 previous errors

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/imports/issue-55884-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ error[E0603]: struct `ParseOptions` is private
--> $DIR/issue-55884-2.rs:12:17
|
LL | pub use parser::ParseOptions;
| ^^^^^^^^^^^^
| ^^^^^^^^^^^^ this struct is private
|
note: the struct `ParseOptions` is defined here
--> $DIR/issue-55884-2.rs:9:9
|
LL | use ParseOptions;
| ^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
16 changes: 14 additions & 2 deletions src/test/ui/imports/reexports.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ error[E0603]: module `foo` is private
--> $DIR/reexports.rs:33:15
|
LL | use b::a::foo::S;
| ^^^
| ^^^ this module is private
|
note: the module `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
--> $DIR/reexports.rs:34:15
|
LL | use b::b::foo::S as T;
| ^^^
| ^^^ this module is private
|
note: the module `foo` is defined here
--> $DIR/reexports.rs:26:17
|
LL | pub use super::*; // This is also OK since the value `foo` is visible enough.
| ^^^^^^^^

warning: glob import doesn't reexport anything because no candidate is public enough
--> $DIR/reexports.rs:9:17
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/imports/unresolved-imports-used.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ error[E0603]: function `quz` is private
--> $DIR/unresolved-imports-used.rs:9:10
|
LL | use qux::quz;
| ^^^
| ^^^ this function is private
|
note: the function `quz` is defined here
--> $DIR/unresolved-imports-used.rs:5:4
|
LL | fn quz() {}
| ^^^^^^^^

error: unused import: `qux::quy`
--> $DIR/unresolved-imports-used.rs:16:5
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/issues/issue-10545.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ error[E0603]: struct `S` is private
--> $DIR/issue-10545.rs:6:14
|
LL | fn foo(_: a::S) {
| ^
| ^ this struct is private
|
note: the struct `S` is defined here
--> $DIR/issue-10545.rs:2:5
|
LL | struct S;
| ^^^^^^^^^

error: aborting due to previous error

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/issues/issue-11593.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ error[E0603]: trait `Foo` is private
--> $DIR/issue-11593.rs:7:24
|
LL | impl private_trait_xc::Foo for Bar {}
| ^^^
| ^^^ this trait is private
|
note: the trait `Foo` is defined here
--> $DIR/auxiliary/private-trait-xc.rs:1:1
|
LL | trait Foo {}
| ^^^^^^^^^

error: aborting due to previous error

Expand Down
16 changes: 14 additions & 2 deletions src/test/ui/issues/issue-11680.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ error[E0603]: enum `Foo` is private
--> $DIR/issue-11680.rs:6:21
|
LL | let _b = other::Foo::Bar(1);
| ^^^
| ^^^ this enum is private
|
note: the enum `Foo` is defined here
--> $DIR/auxiliary/issue-11680.rs:1:1
|
LL | enum Foo {
| ^^^^^^^^

error[E0603]: enum `Foo` is private
--> $DIR/issue-11680.rs:9:27
|
LL | let _b = other::test::Foo::Bar(1);
| ^^^
| ^^^ this enum is private
|
note: the enum `Foo` is defined here
--> $DIR/auxiliary/issue-11680.rs:6:5
|
LL | enum Foo {
| ^^^^^^^^

error: aborting due to 2 previous errors

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/issues/issue-13407.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ error[E0603]: unit struct `C` is private
--> $DIR/issue-13407.rs:6:8
|
LL | A::C = 1;
| ^
| ^ this unit struct is private
|
note: the unit struct `C` is defined here
--> $DIR/issue-13407.rs:2:5
|
LL | struct C;
| ^^^^^^^^^

error[E0308]: mismatched types
--> $DIR/issue-13407.rs:6:12
Expand Down
16 changes: 14 additions & 2 deletions src/test/ui/issues/issue-13641.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ error[E0603]: struct `Foo` is private
--> $DIR/issue-13641.rs:9:8
|
LL | a::Foo::new();
| ^^^
| ^^^ this struct is private
|
note: the struct `Foo` is defined here
--> $DIR/issue-13641.rs:2:5
|
LL | struct Foo;
| ^^^^^^^^^^^

error[E0603]: enum `Bar` is private
--> $DIR/issue-13641.rs:11:8
|
LL | a::Bar::new();
| ^^^
| ^^^ this enum is private
|
note: the enum `Bar` is defined here
--> $DIR/issue-13641.rs:4:5
|
LL | enum Bar {}
| ^^^^^^^^

error: aborting due to 2 previous errors

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/issues/issue-16725.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ error[E0603]: function `bar` is private
--> $DIR/issue-16725.rs:6:19
|
LL | unsafe { foo::bar(); }
| ^^^
| ^^^ this function is private
|
note: the function `bar` is defined here
--> $DIR/auxiliary/issue-16725.rs:2:5
|
LL | fn bar();
| ^^^^^^^^^

error: aborting due to previous error

Expand Down
16 changes: 14 additions & 2 deletions src/test/ui/issues/issue-17718-const-privacy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ error[E0603]: constant `B` is private
--> $DIR/issue-17718-const-privacy.rs:5:8
|
LL | use a::B;
| ^
| ^ this constant is private
|
note: the constant `B` is defined here
--> $DIR/issue-17718-const-privacy.rs:13:5
|
LL | const B: usize = 3;
| ^^^^^^^^^^^^^^^^^^^

error[E0603]: constant `BAR` is private
--> $DIR/issue-17718-const-privacy.rs:8:5
|
LL | BAR,
| ^^^
| ^^^ this constant is private
|
note: the constant `BAR` is defined here
--> $DIR/auxiliary/issue-17718-const-privacy.rs:4:1
|
LL | const BAR: usize = 3;
| ^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/issues/issue-28388-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ error[E0603]: module `n` is private
--> $DIR/issue-28388-2.rs:7:8
|
LL | use m::n::{};
| ^
| ^ this module is private
|
note: the module `n` is defined here
--> $DIR/issue-28388-2.rs:4:5
|
LL | mod n {}
| ^^^^^

error: aborting due to previous error

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/issues/issue-29161.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ error[E0603]: struct `A` is private
--> $DIR/issue-29161.rs:13:8
|
LL | a::A::default();
| ^
| ^ this struct is private
|
note: the struct `A` is defined here
--> $DIR/issue-29161.rs:2:5
|
LL | struct A;
| ^^^^^^^^^

error: aborting due to 2 previous errors

Expand Down
Loading

0 comments on commit 4d596e8

Please sign in to comment.