Skip to content

Commit 4d596e8

Browse files
committed
resolve: Point at the private item definitions in privacy errors
1 parent daff425 commit 4d596e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1034
-154
lines changed

src/librustc_resolve/diagnostics.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -917,15 +917,21 @@ impl<'a> Resolver<'a> {
917917
let PrivacyError { ident, binding, .. } = *privacy_error;
918918
let session = &self.session;
919919
let mk_struct_span_error = |is_constructor| {
920-
struct_span_err!(
921-
session,
922-
ident.span,
923-
E0603,
924-
"{}{} `{}` is private",
925-
binding.res().descr(),
926-
if is_constructor { " constructor" } else { "" },
927-
ident.name,
928-
)
920+
let mut descr = binding.res().descr().to_string();
921+
if is_constructor {
922+
descr += " constructor";
923+
}
924+
925+
let mut err =
926+
struct_span_err!(session, ident.span, E0603, "{} `{}` is private", descr, ident);
927+
928+
err.span_label(ident.span, &format!("this {} is private", descr));
929+
err.span_note(
930+
session.source_map().def_span(binding.span),
931+
&format!("the {} `{}` is defined here", descr, ident),
932+
);
933+
934+
err
929935
};
930936

931937
let mut err = if let NameBindingKind::Res(

src/test/ui/error-codes/E0603.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error[E0603]: constant `PRIVATE` is private
22
--> $DIR/E0603.rs:6:17
33
|
44
LL | SomeModule::PRIVATE;
5-
| ^^^^^^^
5+
| ^^^^^^^ this constant is private
6+
|
7+
note: the constant `PRIVATE` is defined here
8+
--> $DIR/E0603.rs:2:5
9+
|
10+
LL | const PRIVATE: u32 = 0x_a_bad_1dea_u32;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
612

713
error: aborting due to previous error
814

src/test/ui/error-festival.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ error[E0603]: constant `FOO` is private
88
--> $DIR/error-festival.rs:22:10
99
|
1010
LL | foo::FOO;
11-
| ^^^
11+
| ^^^ this constant is private
12+
|
13+
note: the constant `FOO` is defined here
14+
--> $DIR/error-festival.rs:7:5
15+
|
16+
LL | const FOO: u32 = 0;
17+
| ^^^^^^^^^^^^^^^^^^^
1218

1319
error[E0368]: binary assignment operation `+=` cannot be applied to type `&str`
1420
--> $DIR/error-festival.rs:12:5

src/test/ui/export-import.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error[E0603]: function `unexported` is private
22
--> $DIR/export-import.rs:1:8
33
|
44
LL | use m::unexported;
5-
| ^^^^^^^^^^
5+
| ^^^^^^^^^^ this function is private
6+
|
7+
note: the function `unexported` is defined here
8+
--> $DIR/export-import.rs:7:5
9+
|
10+
LL | fn unexported() { }
11+
| ^^^^^^^^^^^^^^^
612

713
error: aborting due to previous error
814

src/test/ui/export-tag-variant.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error[E0603]: enum `Y` is private
22
--> $DIR/export-tag-variant.rs:7:26
33
|
44
LL | fn main() { let z = foo::Y::Y1; }
5-
| ^
5+
| ^ this enum is private
6+
|
7+
note: the enum `Y` is defined here
8+
--> $DIR/export-tag-variant.rs:4:5
9+
|
10+
LL | enum Y { Y1 }
11+
| ^^^^^^
612

713
error: aborting due to previous error
814

src/test/ui/export.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ error[E0603]: function `z` is private
2626
--> $DIR/export.rs:10:18
2727
|
2828
LL | fn main() { foo::z(10); }
29-
| ^
29+
| ^ this function is private
30+
|
31+
note: the function `z` is defined here
32+
--> $DIR/export.rs:5:5
33+
|
34+
LL | fn z(y: isize) { log(debug, y); }
35+
| ^^^^^^^^^^^^^^
3036

3137
error: aborting due to 5 previous errors
3238

src/test/ui/extern/extern-crate-visibility.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@ error[E0603]: crate `core` is private
22
--> $DIR/extern-crate-visibility.rs:6:10
33
|
44
LL | use foo::core::cell;
5-
| ^^^^
5+
| ^^^^ this crate is private
6+
|
7+
note: the crate `core` is defined here
8+
--> $DIR/extern-crate-visibility.rs:2:5
9+
|
10+
LL | extern crate core;
11+
| ^^^^^^^^^^^^^^^^^^
612

713
error[E0603]: crate `core` is private
814
--> $DIR/extern-crate-visibility.rs:9:10
915
|
1016
LL | foo::core::cell::Cell::new(0);
11-
| ^^^^
17+
| ^^^^ this crate is private
18+
|
19+
note: the crate `core` is defined here
20+
--> $DIR/extern-crate-visibility.rs:2:5
21+
|
22+
LL | extern crate core;
23+
| ^^^^^^^^^^^^^^^^^^
1224

1325
error: aborting due to 2 previous errors
1426

src/test/ui/hygiene/privacy.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error[E0603]: function `f` is private
22
--> $DIR/privacy.rs:16:14
33
|
44
LL | foo::f()
5-
| ^
5+
| ^ this function is private
6+
|
7+
note: the function `f` is defined here
8+
--> $DIR/privacy.rs:4:5
9+
|
10+
LL | fn f() {}
11+
| ^^^^^^
612

713
error: aborting due to previous error
814

src/test/ui/import.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ error[E0603]: unresolved item `foo` is private
1717
--> $DIR/import.rs:15:10
1818
|
1919
LL | zed::foo();
20-
| ^^^
20+
| ^^^ this unresolved item is private
21+
|
22+
note: the unresolved item `foo` is defined here
23+
--> $DIR/import.rs:10:9
24+
|
25+
LL | use foo;
26+
| ^^^
2127

2228
error: aborting due to 3 previous errors
2329

src/test/ui/imports/issue-55884-2.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error[E0603]: struct `ParseOptions` is private
22
--> $DIR/issue-55884-2.rs:12:17
33
|
44
LL | pub use parser::ParseOptions;
5-
| ^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^ this struct is private
6+
|
7+
note: the struct `ParseOptions` is defined here
8+
--> $DIR/issue-55884-2.rs:9:9
9+
|
10+
LL | use ParseOptions;
11+
| ^^^^^^^^^^^^
612

713
error: aborting due to previous error
814

src/test/ui/imports/reexports.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,25 @@ error[E0603]: module `foo` is private
1414
--> $DIR/reexports.rs:33:15
1515
|
1616
LL | use b::a::foo::S;
17-
| ^^^
17+
| ^^^ this module is private
18+
|
19+
note: the module `foo` is defined here
20+
--> $DIR/reexports.rs:21:17
21+
|
22+
LL | pub use super::foo; // This is OK since the value `foo` is visible enough.
23+
| ^^^^^^^^^^
1824

1925
error[E0603]: module `foo` is private
2026
--> $DIR/reexports.rs:34:15
2127
|
2228
LL | use b::b::foo::S as T;
23-
| ^^^
29+
| ^^^ this module is private
30+
|
31+
note: the module `foo` is defined here
32+
--> $DIR/reexports.rs:26:17
33+
|
34+
LL | pub use super::*; // This is also OK since the value `foo` is visible enough.
35+
| ^^^^^^^^
2436

2537
warning: glob import doesn't reexport anything because no candidate is public enough
2638
--> $DIR/reexports.rs:9:17

src/test/ui/imports/unresolved-imports-used.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ error[E0603]: function `quz` is private
3838
--> $DIR/unresolved-imports-used.rs:9:10
3939
|
4040
LL | use qux::quz;
41-
| ^^^
41+
| ^^^ this function is private
42+
|
43+
note: the function `quz` is defined here
44+
--> $DIR/unresolved-imports-used.rs:5:4
45+
|
46+
LL | fn quz() {}
47+
| ^^^^^^^^
4248

4349
error: unused import: `qux::quy`
4450
--> $DIR/unresolved-imports-used.rs:16:5

src/test/ui/issues/issue-10545.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error[E0603]: struct `S` is private
22
--> $DIR/issue-10545.rs:6:14
33
|
44
LL | fn foo(_: a::S) {
5-
| ^
5+
| ^ this struct is private
6+
|
7+
note: the struct `S` is defined here
8+
--> $DIR/issue-10545.rs:2:5
9+
|
10+
LL | struct S;
11+
| ^^^^^^^^^
612

713
error: aborting due to previous error
814

src/test/ui/issues/issue-11593.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error[E0603]: trait `Foo` is private
22
--> $DIR/issue-11593.rs:7:24
33
|
44
LL | impl private_trait_xc::Foo for Bar {}
5-
| ^^^
5+
| ^^^ this trait is private
6+
|
7+
note: the trait `Foo` is defined here
8+
--> $DIR/auxiliary/private-trait-xc.rs:1:1
9+
|
10+
LL | trait Foo {}
11+
| ^^^^^^^^^
612

713
error: aborting due to previous error
814

src/test/ui/issues/issue-11680.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@ error[E0603]: enum `Foo` is private
22
--> $DIR/issue-11680.rs:6:21
33
|
44
LL | let _b = other::Foo::Bar(1);
5-
| ^^^
5+
| ^^^ this enum is private
6+
|
7+
note: the enum `Foo` is defined here
8+
--> $DIR/auxiliary/issue-11680.rs:1:1
9+
|
10+
LL | enum Foo {
11+
| ^^^^^^^^
612

713
error[E0603]: enum `Foo` is private
814
--> $DIR/issue-11680.rs:9:27
915
|
1016
LL | let _b = other::test::Foo::Bar(1);
11-
| ^^^
17+
| ^^^ this enum is private
18+
|
19+
note: the enum `Foo` is defined here
20+
--> $DIR/auxiliary/issue-11680.rs:6:5
21+
|
22+
LL | enum Foo {
23+
| ^^^^^^^^
1224

1325
error: aborting due to 2 previous errors
1426

src/test/ui/issues/issue-13407.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error[E0603]: unit struct `C` is private
22
--> $DIR/issue-13407.rs:6:8
33
|
44
LL | A::C = 1;
5-
| ^
5+
| ^ this unit struct is private
6+
|
7+
note: the unit struct `C` is defined here
8+
--> $DIR/issue-13407.rs:2:5
9+
|
10+
LL | struct C;
11+
| ^^^^^^^^^
612

713
error[E0308]: mismatched types
814
--> $DIR/issue-13407.rs:6:12

src/test/ui/issues/issue-13641.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@ error[E0603]: struct `Foo` is private
22
--> $DIR/issue-13641.rs:9:8
33
|
44
LL | a::Foo::new();
5-
| ^^^
5+
| ^^^ this struct is private
6+
|
7+
note: the struct `Foo` is defined here
8+
--> $DIR/issue-13641.rs:2:5
9+
|
10+
LL | struct Foo;
11+
| ^^^^^^^^^^^
612

713
error[E0603]: enum `Bar` is private
814
--> $DIR/issue-13641.rs:11:8
915
|
1016
LL | a::Bar::new();
11-
| ^^^
17+
| ^^^ this enum is private
18+
|
19+
note: the enum `Bar` is defined here
20+
--> $DIR/issue-13641.rs:4:5
21+
|
22+
LL | enum Bar {}
23+
| ^^^^^^^^
1224

1325
error: aborting due to 2 previous errors
1426

src/test/ui/issues/issue-16725.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error[E0603]: function `bar` is private
22
--> $DIR/issue-16725.rs:6:19
33
|
44
LL | unsafe { foo::bar(); }
5-
| ^^^
5+
| ^^^ this function is private
6+
|
7+
note: the function `bar` is defined here
8+
--> $DIR/auxiliary/issue-16725.rs:2:5
9+
|
10+
LL | fn bar();
11+
| ^^^^^^^^^
612

713
error: aborting due to previous error
814

src/test/ui/issues/issue-17718-const-privacy.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@ error[E0603]: constant `B` is private
22
--> $DIR/issue-17718-const-privacy.rs:5:8
33
|
44
LL | use a::B;
5-
| ^
5+
| ^ this constant is private
6+
|
7+
note: the constant `B` is defined here
8+
--> $DIR/issue-17718-const-privacy.rs:13:5
9+
|
10+
LL | const B: usize = 3;
11+
| ^^^^^^^^^^^^^^^^^^^
612

713
error[E0603]: constant `BAR` is private
814
--> $DIR/issue-17718-const-privacy.rs:8:5
915
|
1016
LL | BAR,
11-
| ^^^
17+
| ^^^ this constant is private
18+
|
19+
note: the constant `BAR` is defined here
20+
--> $DIR/auxiliary/issue-17718-const-privacy.rs:4:1
21+
|
22+
LL | const BAR: usize = 3;
23+
| ^^^^^^^^^^^^^^^^^^^^^
1224

1325
error: aborting due to 2 previous errors
1426

src/test/ui/issues/issue-28388-2.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ error[E0603]: module `n` is private
22
--> $DIR/issue-28388-2.rs:7:8
33
|
44
LL | use m::n::{};
5-
| ^
5+
| ^ this module is private
6+
|
7+
note: the module `n` is defined here
8+
--> $DIR/issue-28388-2.rs:4:5
9+
|
10+
LL | mod n {}
11+
| ^^^^^
612

713
error: aborting due to previous error
814

src/test/ui/issues/issue-29161.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ error[E0603]: struct `A` is private
88
--> $DIR/issue-29161.rs:13:8
99
|
1010
LL | a::A::default();
11-
| ^
11+
| ^ this struct is private
12+
|
13+
note: the struct `A` is defined here
14+
--> $DIR/issue-29161.rs:2:5
15+
|
16+
LL | struct A;
17+
| ^^^^^^^^^
1218

1319
error: aborting due to 2 previous errors
1420

0 commit comments

Comments
 (0)