Skip to content

Commit acdbd06

Browse files
committed
resolve: More precise spans for privacy errors
1 parent b45b4da commit acdbd06

Some content is hidden

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

45 files changed

+276
-281
lines changed

src/librustc_resolve/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ enum NameBindingKind<'a> {
12071207
}
12081208
}
12091209

1210-
struct PrivacyError<'a>(Span, Name, &'a NameBinding<'a>);
1210+
struct PrivacyError<'a>(Span, Ident, &'a NameBinding<'a>);
12111211

12121212
struct UseError<'a> {
12131213
err: DiagnosticBuilder<'a>,
@@ -4743,9 +4743,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47434743
}
47444744
}
47454745

4746-
for &PrivacyError(span, name, binding) in &self.privacy_errors {
4747-
if !reported_spans.insert(span) { continue }
4748-
span_err!(self.session, span, E0603, "{} `{}` is private", binding.descr(), name);
4746+
for &PrivacyError(dedup_span, ident, binding) in &self.privacy_errors {
4747+
if reported_spans.insert(dedup_span) {
4748+
span_err!(self.session, ident.span, E0603, "{} `{}` is private",
4749+
binding.descr(), ident.name);
4750+
}
47494751
}
47504752
}
47514753

src/librustc_resolve/resolve_imports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
275275
return Ok(self.dummy_binding);
276276
}
277277
if !self.is_accessible(binding.vis) {
278-
self.privacy_errors.push(PrivacyError(path_span, ident.name, binding));
278+
self.privacy_errors.push(PrivacyError(path_span, ident, binding));
279279
}
280280
}
281281

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: constant `PRIVATE` is private
2-
--> $DIR/E0603.rs:16:5
2+
--> $DIR/E0603.rs:16:17
33
|
44
LL | SomeModule::PRIVATE; //~ ERROR E0603
5-
| ^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^
66

77
error: aborting due to previous error
88

src/test/ui/error-festival.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | y = 2;
55
| ^ did you mean `x`?
66

77
error[E0603]: constant `FOO` is private
8-
--> $DIR/error-festival.rs:32:5
8+
--> $DIR/error-festival.rs:32:10
99
|
1010
LL | foo::FOO;
11-
| ^^^^^^^^
11+
| ^^^
1212

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

src/test/ui/export-import.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: function `unexported` is private
2-
--> $DIR/export-import.rs:11:5
2+
--> $DIR/export-import.rs:11:8
33
|
44
LL | use m::unexported;
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^^^^^
66

77
error: aborting due to previous error
88

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: enum `y` is private
2-
--> $DIR/export-tag-variant.rs:17:21
2+
--> $DIR/export-tag-variant.rs:17:26
33
|
44
LL | fn main() { let z = foo::y::y1; } //~ ERROR: enum `y` is private
5-
| ^^^^^^^^^^
5+
| ^
66

77
error: aborting due to previous error
88

src/test/ui/export.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ LL | fn z(y: isize) { log(debug, y); }
2323
| ^^^^^ not found in this scope
2424

2525
error[E0603]: function `z` is private
26-
--> $DIR/export.rs:20:13
26+
--> $DIR/export.rs:20:18
2727
|
2828
LL | fn main() { foo::z(10); } //~ ERROR function `z` is private
29-
| ^^^^^^
29+
| ^
3030

3131
error: aborting due to 5 previous errors
3232

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0603]: extern crate `core` is private
2-
--> $DIR/extern-crate-visibility.rs:16:5
2+
--> $DIR/extern-crate-visibility.rs:16:10
33
|
44
LL | use foo::core::cell; //~ ERROR extern crate `core` is private
5-
| ^^^^^^^^^^^^^^^
5+
| ^^^^
66

77
error[E0603]: extern crate `core` is private
8-
--> $DIR/extern-crate-visibility.rs:19:5
8+
--> $DIR/extern-crate-visibility.rs:19:10
99
|
1010
LL | foo::core::cell::Cell::new(0); //~ ERROR extern crate `core` is private
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^
1212

1313
error: aborting due to 2 previous errors
1414

src/test/ui/hygiene/privacy.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: function `f` is private
2-
--> $DIR/privacy.rs:26:9
2+
--> $DIR/privacy.rs:26:14
33
|
44
LL | foo::f() //~ ERROR `f` is private
5-
| ^^^^^^
5+
| ^
66

77
error: aborting due to previous error
88

src/test/ui/import.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ LL | use foo; //~ ERROR unresolved import `foo` [E0432]
1111
| ^^^ no `foo` in the root
1212

1313
error[E0603]: unresolved item `foo` is private
14-
--> $DIR/import.rs:23:5
14+
--> $DIR/import.rs:23:10
1515
|
1616
LL | zed::foo(); //~ ERROR `foo` is private
17-
| ^^^^^^^^
17+
| ^^^
1818

1919
error: aborting due to 3 previous errors
2020

src/test/ui/imports/reexports.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ LL | pub use super::*; //~ ERROR must import something with the glob's v
1717
| ^^^^^^^^
1818

1919
error[E0603]: module `foo` is private
20-
--> $DIR/reexports.rs:38:9
20+
--> $DIR/reexports.rs:38:15
2121
|
2222
LL | use b::a::foo::S; //~ ERROR `foo`
23-
| ^^^^^^^^^^^^
23+
| ^^^
2424

2525
error[E0603]: module `foo` is private
26-
--> $DIR/reexports.rs:39:9
26+
--> $DIR/reexports.rs:39:15
2727
|
2828
LL | use b::b::foo::S as T; //~ ERROR `foo`
29-
| ^^^^^^^^^^^^^^^^^
29+
| ^^^
3030

3131
error: aborting due to 4 previous errors
3232

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: struct `S` is private
2-
--> $DIR/issue-10545.rs:17:11
2+
--> $DIR/issue-10545.rs:17:14
33
|
44
LL | fn foo(_: a::S) { //~ ERROR: struct `S` is private
5-
| ^^^^
5+
| ^
66

77
error: aborting due to previous error
88

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: trait `Foo` is private
2-
--> $DIR/issue-11593.rs:17:6
2+
--> $DIR/issue-11593.rs:17:24
33
|
44
LL | impl private_trait_xc::Foo for Bar {}
5-
| ^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^
66

77
error: aborting due to previous error
88

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0603]: enum `Foo` is private
2-
--> $DIR/issue-11680.rs:16:14
2+
--> $DIR/issue-11680.rs:16:21
33
|
44
LL | let _b = other::Foo::Bar(1);
5-
| ^^^^^^^^^^^^^^^
5+
| ^^^
66

77
error[E0603]: enum `Foo` is private
8-
--> $DIR/issue-11680.rs:19:14
8+
--> $DIR/issue-11680.rs:19:27
99
|
1010
LL | let _b = other::test::Foo::Bar(1);
11-
| ^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^
1212

1313
error: aborting due to 2 previous errors
1414

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: unit struct `C` is private
2-
--> $DIR/issue-13407.rs:16:5
2+
--> $DIR/issue-13407.rs:16:8
33
|
44
LL | A::C = 1;
5-
| ^^^^
5+
| ^
66

77
error[E0308]: mismatched types
88
--> $DIR/issue-13407.rs:16:12

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0603]: struct `Foo` is private
2-
--> $DIR/issue-13641.rs:19:5
2+
--> $DIR/issue-13641.rs:19:8
33
|
44
LL | a::Foo::new();
5-
| ^^^^^^^^^^^
5+
| ^^^
66

77
error[E0603]: enum `Bar` is private
8-
--> $DIR/issue-13641.rs:21:5
8+
--> $DIR/issue-13641.rs:21:8
99
|
1010
LL | a::Bar::new();
11-
| ^^^^^^^^^^^
11+
| ^^^
1212

1313
error: aborting due to 2 previous errors
1414

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: function `bar` is private
2-
--> $DIR/issue-16725.rs:16:14
2+
--> $DIR/issue-16725.rs:16:19
33
|
44
LL | unsafe { foo::bar(); }
5-
| ^^^^^^^^
5+
| ^^^
66

77
error: aborting due to previous error
88

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: constant `B` is private
2-
--> $DIR/issue-17718-const-privacy.rs:15:5
2+
--> $DIR/issue-17718-const-privacy.rs:15:8
33
|
44
LL | use a::B; //~ ERROR: constant `B` is private
5-
| ^^^^
5+
| ^
66

77
error[E0603]: constant `BAR` is private
88
--> $DIR/issue-17718-const-privacy.rs:18:5

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: module `n` is private
2-
--> $DIR/issue-28388-2.rs:17:5
2+
--> $DIR/issue-28388-2.rs:17:8
33
|
44
LL | use m::n::{};
5-
| ^^^^^^^^
5+
| ^
66

77
error: aborting due to previous error
88

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | pub fn default() -> A { //~ ERROR unnecessary visibility qualifier
55
| ^^^ `pub` not permitted here because it's implied
66

77
error[E0603]: struct `A` is private
8-
--> $DIR/issue-29161.rs:23:5
8+
--> $DIR/issue-29161.rs:23:8
99
|
1010
LL | a::A::default();
11-
| ^^^^^^^^^^^^^
11+
| ^
1212

1313
error: aborting due to 2 previous errors
1414

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | let a = std::sys::imp::process::process_common::StdioPipes { ..panic!()
55
| ^^^ Could not find `imp` in `sys`
66

77
error[E0603]: module `sys` is private
8-
--> $DIR/issue-38857.rs:12:13
8+
--> $DIR/issue-38857.rs:12:18
99
|
1010
LL | let a = std::sys::imp::process::process_common::StdioPipes { ..panic!() };
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^
1212

1313
error: aborting due to 2 previous errors
1414

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: function `fly` is private
2-
--> $DIR/issue-3993.rs:11:5
2+
--> $DIR/issue-3993.rs:11:10
33
|
44
LL | use zoo::fly; //~ ERROR: function `fly` is private
5-
| ^^^^^^^^
5+
| ^^^
66

77
error: aborting due to previous error
88

src/test/ui/macros/macro-local-data-key-priv.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: constant `baz` is private
2-
--> $DIR/macro-local-data-key-priv.rs:18:5
2+
--> $DIR/macro-local-data-key-priv.rs:18:10
33
|
44
LL | bar::baz.with(|_| ());
5-
| ^^^^^^^^
5+
| ^^^
66

77
error: aborting due to previous error
88

src/test/ui/privacy/privacy-in-paths.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error[E0603]: module `bar` is private
2-
--> $DIR/privacy-in-paths.rs:34:9
2+
--> $DIR/privacy-in-paths.rs:34:16
33
|
44
LL | ::foo::bar::baz::f(); //~ERROR module `bar` is private
5-
| ^^^^^^^^^^^^^^^^^^
5+
| ^^^
66

77
error[E0603]: module `bar` is private
8-
--> $DIR/privacy-in-paths.rs:35:9
8+
--> $DIR/privacy-in-paths.rs:35:16
99
|
1010
LL | ::foo::bar::S::f(); //~ERROR module `bar` is private
11-
| ^^^^^^^^^^^^^^^^
11+
| ^^^
1212

1313
error[E0603]: trait `T` is private
14-
--> $DIR/privacy-in-paths.rs:36:9
14+
--> $DIR/privacy-in-paths.rs:36:23
1515
|
1616
LL | <() as ::foo::T>::Assoc::f(); //~ERROR trait `T` is private
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
| ^
1818

1919
error: aborting due to 3 previous errors
2020

src/test/ui/privacy/privacy-ns2.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ LL | use foo3::Bar;
5555
|
5656

5757
error[E0603]: trait `Bar` is private
58-
--> $DIR/privacy-ns2.rs:70:9
58+
--> $DIR/privacy-ns2.rs:70:15
5959
|
6060
LL | use foo3::Bar; //~ ERROR `Bar` is private
61-
| ^^^^^^^^^
61+
| ^^^
6262

6363
error[E0603]: trait `Bar` is private
64-
--> $DIR/privacy-ns2.rs:74:9
64+
--> $DIR/privacy-ns2.rs:74:15
6565
|
6666
LL | use foo3::Bar; //~ ERROR `Bar` is private
67-
| ^^^^^^^^^
67+
| ^^^
6868

6969
error[E0603]: trait `Bar` is private
7070
--> $DIR/privacy-ns2.rs:81:16

src/test/ui/privacy/privacy-ufcs.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0603]: trait `Bar` is private
2-
--> $DIR/privacy-ufcs.rs:22:5
2+
--> $DIR/privacy-ufcs.rs:22:20
33
|
44
LL | <i32 as ::foo::Bar>::baz(); //~ERROR trait `Bar` is private
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^
66

77
error: aborting due to previous error
88

src/test/ui/privacy/privacy1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ mod foo {
127127
fn test2() {
128128
use bar::baz::{foo, bar};
129129
//~^ ERROR: module `baz` is private
130-
//~| ERROR: module `baz` is private
131130

132131
foo();
133132
bar();

0 commit comments

Comments
 (0)