Skip to content

Commit ea65ab6

Browse files
authored
Auto merge of #36761 - jonathandturner:E0425_E0446_E0449, r=nrc
Update E0425, E0446, E0449 This addresses #35343, #35923, and #35924. Part of #35233 Specifically, this adds labels to these error messages following the suggestions in the attached bugs. r? @nrc
2 parents 8467e8d + c0f29fd commit ea65ab6

18 files changed

+107
-35
lines changed

src/librustc_passes/ast_validation.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ impl<'a> AstValidator<'a> {
5353
span,
5454
E0449,
5555
"unnecessary visibility qualifier");
56+
if vis == &Visibility::Public {
57+
err.span_label(span, &format!("`pub` not needed here"));
58+
}
5659
if let Some(note) = note {
57-
err.span_note(span, note);
60+
err.note(note);
5861
}
5962
err.emit();
6063
}

src/librustc_privacy/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,10 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
972972
if !vis.is_at_least(self.required_visibility, &self.tcx.map) {
973973
if self.tcx.sess.features.borrow().pub_restricted ||
974974
self.old_error_set.contains(&ty.id) {
975-
span_err!(self.tcx.sess, ty.span, E0446,
975+
let mut err = struct_span_err!(self.tcx.sess, ty.span, E0446,
976976
"private type in public interface");
977+
err.span_label(ty.span, &format!("can't leak private type"));
978+
err.emit();
977979
} else {
978980
self.tcx.sess.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
979981
node_id,

src/librustc_resolve/lib.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,14 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
366366
let mut err = struct_span_err!(resolver.session,
367367
span,
368368
E0425,
369-
"unresolved name `{}`{}",
370-
path,
371-
msg);
369+
"unresolved name `{}`",
370+
path);
371+
if msg != "" {
372+
err.span_label(span, &msg);
373+
} else {
374+
err.span_label(span, &format!("unresolved name"));
375+
}
376+
372377
match context {
373378
UnresolvedNameContext::Other => {
374379
if msg.is_empty() && is_static_method && is_field {
@@ -2941,7 +2946,7 @@ impl<'a> Resolver<'a> {
29412946
let mut context = UnresolvedNameContext::Other;
29422947
let mut def = Def::Err;
29432948
if !msg.is_empty() {
2944-
msg = format!(". Did you mean {}?", msg);
2949+
msg = format!("did you mean {}?", msg);
29452950
} else {
29462951
// we display a help message if this is a module
29472952
let name_path = path.segments.iter()

src/test/compile-fail/E0033.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ trait SomeTrait {
1515
fn main() {
1616
let trait_obj: &SomeTrait = SomeTrait;
1717
//~^ ERROR E0425
18+
//~| NOTE unresolved name
1819
//~| ERROR E0038
1920
//~| method `foo` has no receiver
2021
//~| NOTE the trait `SomeTrait` cannot be made into an object

src/test/compile-fail/E0446.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod Foo {
1212
struct Bar(u32);
1313

1414
pub fn bar() -> Bar { //~ ERROR E0446
15+
//~| NOTE can't leak private type
1516
Bar(0)
1617
}
1718
}

src/test/compile-fail/E0449.rs

+4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ trait Foo {
1515
}
1616

1717
pub impl Bar {} //~ ERROR E0449
18+
//~| NOTE `pub` not needed here
19+
//~| NOTE place qualifiers on individual impl items instead
1820

1921
pub impl Foo for Bar { //~ ERROR E0449
22+
//~| NOTE `pub` not needed here
2023
pub fn foo() {} //~ ERROR E0449
24+
//~| NOTE `pub` not needed here
2125
}
2226

2327
fn main() {

src/test/compile-fail/bad-expr-path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: unresolved name `m1::arguments`. Did you mean `arguments`?
11+
// error-pattern: unresolved name `m1::arguments`
1212

1313
mod m1 {}
1414

src/test/compile-fail/bad-expr-path2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: unresolved name `m1::arguments`. Did you mean `arguments`?
11+
// error-pattern: unresolved name `m1::arguments`
1212

1313
mod m1 {
1414
pub mod arguments {}

src/test/compile-fail/issue-14254.rs

+43-19
Original file line numberDiff line numberDiff line change
@@ -27,87 +27,111 @@ impl BarTy {
2727
impl Foo for *const BarTy {
2828
fn bar(&self) {
2929
baz();
30-
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
30+
//~^ ERROR: unresolved name `baz`
31+
//~| NOTE did you mean to call `self.baz`?
3132
a;
3233
//~^ ERROR: unresolved name `a`
34+
//~| NOTE unresolved name
3335
}
3436
}
3537

3638
impl<'a> Foo for &'a BarTy {
3739
fn bar(&self) {
3840
baz();
39-
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
41+
//~^ ERROR: unresolved name `baz`
42+
//~| NOTE did you mean to call `self.baz`?
4043
x;
41-
//~^ ERROR: unresolved name `x`. Did you mean `self.x`?
44+
//~^ ERROR: unresolved name `x`
45+
//~| NOTE did you mean `self.x`?
4246
y;
43-
//~^ ERROR: unresolved name `y`. Did you mean `self.y`?
47+
//~^ ERROR: unresolved name `y`
48+
//~| NOTE did you mean `self.y`?
4449
a;
4550
//~^ ERROR: unresolved name `a`
51+
//~| NOTE unresolved name
4652
bah;
47-
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
53+
//~^ ERROR: unresolved name `bah`
54+
//~| NOTE did you mean to call `Foo::bah`?
4855
b;
4956
//~^ ERROR: unresolved name `b`
57+
//~| NOTE unresolved name
5058
}
5159
}
5260

5361
impl<'a> Foo for &'a mut BarTy {
5462
fn bar(&self) {
5563
baz();
56-
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
64+
//~^ ERROR: unresolved name `baz`
65+
//~| NOTE did you mean to call `self.baz`?
5766
x;
58-
//~^ ERROR: unresolved name `x`. Did you mean `self.x`?
67+
//~^ ERROR: unresolved name `x`
68+
//~| NOTE did you mean `self.x`?
5969
y;
60-
//~^ ERROR: unresolved name `y`. Did you mean `self.y`?
70+
//~^ ERROR: unresolved name `y`
71+
//~| NOTE did you mean `self.y`?
6172
a;
6273
//~^ ERROR: unresolved name `a`
74+
//~| NOTE unresolved name
6375
bah;
64-
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
76+
//~^ ERROR: unresolved name `bah`
77+
//~| NOTE did you mean to call `Foo::bah`?
6578
b;
6679
//~^ ERROR: unresolved name `b`
80+
//~| NOTE unresolved name
6781
}
6882
}
6983

7084
impl Foo for Box<BarTy> {
7185
fn bar(&self) {
7286
baz();
73-
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
87+
//~^ ERROR: unresolved name `baz`
88+
//~| NOTE did you mean to call `self.baz`?
7489
bah;
75-
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
90+
//~^ ERROR: unresolved name `bah`
91+
//~| NOTE did you mean to call `Foo::bah`?
7692
}
7793
}
7894

7995
impl Foo for *const isize {
8096
fn bar(&self) {
8197
baz();
82-
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
98+
//~^ ERROR: unresolved name `baz`
99+
//~| NOTE did you mean to call `self.baz`?
83100
bah;
84-
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
101+
//~^ ERROR: unresolved name `bah`
102+
//~| NOTE did you mean to call `Foo::bah`?
85103
}
86104
}
87105

88106
impl<'a> Foo for &'a isize {
89107
fn bar(&self) {
90108
baz();
91-
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
109+
//~^ ERROR: unresolved name `baz`
110+
//~| NOTE did you mean to call `self.baz`?
92111
bah;
93-
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
112+
//~^ ERROR: unresolved name `bah`
113+
//~| NOTE did you mean to call `Foo::bah`?
94114
}
95115
}
96116

97117
impl<'a> Foo for &'a mut isize {
98118
fn bar(&self) {
99119
baz();
100-
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
120+
//~^ ERROR: unresolved name `baz`
121+
//~| NOTE did you mean to call `self.baz`?
101122
bah;
102-
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
123+
//~^ ERROR: unresolved name `bah`
124+
//~| NOTE did you mean to call `Foo::bah`?
103125
}
104126
}
105127

106128
impl Foo for Box<isize> {
107129
fn bar(&self) {
108130
baz();
109-
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
131+
//~^ ERROR: unresolved name `baz`
132+
//~| NOTE did you mean to call `self.baz`?
110133
bah;
111-
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
134+
//~^ ERROR: unresolved name `bah`
135+
//~| NOTE did you mean to call `Foo::bah`?
112136
}
113137
}

src/test/compile-fail/issue-2356.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ impl MaybeDog {
2626
// If this provides a suggestion, it's a bug as MaybeDog doesn't impl Groom
2727
shave();
2828
//~^ ERROR: unresolved name `shave`
29+
//~| NOTE unresolved name
2930
}
3031
}
3132

3233
impl Groom for cat {
3334
fn shave(other: usize) {
3435
whiskers -= other;
3536
//~^ ERROR: unresolved name `whiskers`
37+
//~| NOTE unresolved name
3638
//~| HELP this is an associated function
3739
shave(4);
38-
//~^ ERROR: unresolved name `shave`. Did you mean to call `Groom::shave`?
40+
//~^ ERROR: unresolved name `shave`
41+
//~| NOTE did you mean to call `Groom::shave`?
3942
purr();
4043
//~^ ERROR: unresolved name `purr`
44+
//~| NOTE unresolved name
4145
}
4246
}
4347

@@ -47,12 +51,16 @@ impl cat {
4751
fn purr_louder() {
4852
static_method();
4953
//~^ ERROR: unresolved name `static_method`
54+
//~| NOTE unresolved name
5055
purr();
5156
//~^ ERROR: unresolved name `purr`
57+
//~| NOTE unresolved name
5258
purr();
5359
//~^ ERROR: unresolved name `purr`
60+
//~| NOTE unresolved name
5461
purr();
5562
//~^ ERROR: unresolved name `purr`
63+
//~| NOTE unresolved name
5664
}
5765
}
5866

@@ -69,27 +77,33 @@ impl cat {
6977
fn purr(&self) {
7078
grow_older();
7179
//~^ ERROR: unresolved name `grow_older`
80+
//~| NOTE unresolved name
7281
shave();
7382
//~^ ERROR: unresolved name `shave`
83+
//~| NOTE unresolved name
7484
}
7585

7686
fn burn_whiskers(&mut self) {
7787
whiskers = 0;
78-
//~^ ERROR: unresolved name `whiskers`. Did you mean `self.whiskers`?
88+
//~^ ERROR: unresolved name `whiskers`
89+
//~| NOTE did you mean `self.whiskers`?
7990
}
8091

8192
pub fn grow_older(other:usize) {
8293
whiskers = 4;
8394
//~^ ERROR: unresolved name `whiskers`
95+
//~| NOTE unresolved name
8496
//~| HELP this is an associated function
8597
purr_louder();
8698
//~^ ERROR: unresolved name `purr_louder`
99+
//~| NOTE unresolved name
87100
}
88101
}
89102

90103
fn main() {
91104
self += 1;
92105
//~^ ERROR: unresolved name `self`
106+
//~| NOTE unresolved name
93107
//~| HELP: module `self`
94108
// it's a bug if this suggests a missing `self` as we're not in a method
95109
}

src/test/compile-fail/resolve-hint-macro.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
assert(true); //~ERROR unresolved name `assert`. Did you mean the macro `assert!`?
12+
assert(true);
13+
//~^ ERROR unresolved name `assert`
14+
//~| NOTE did you mean the macro `assert!`?
1315
}

src/test/compile-fail/token-error-correct-2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
fn main() {
1414
if foo { //~ NOTE: unclosed delimiter
1515
//~^ ERROR: unresolved name `foo`
16+
//~| NOTE unresolved name
1617
) //~ ERROR: incorrect close delimiter: `)`
1718
}

src/test/compile-fail/token-error-correct-3.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub mod raw {
1919
callback: F)
2020
-> io::Result<bool> {
2121
if !is_directory(path.as_ref()) { //~ ERROR: unresolved name `is_directory`
22+
//~| NOTE unresolved name
2223
callback(path.as_ref(); //~ NOTE: unclosed delimiter
2324
//~^ ERROR: expected one of
2425
fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types

src/test/compile-fail/token-error-correct.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ fn main() {
1717
//~^^^ ERROR: unresolved name `bar`
1818
//~^^^^ ERROR: unresolved name `foo`
1919
//~^^^^^ ERROR: expected one of `)`, `,`, `.`, `<`, `?`
20+
//~| NOTE unresolved name
21+
//~| NOTE unresolved name
2022
} //~ ERROR: incorrect close delimiter: `}`
2123
//~^ ERROR: incorrect close delimiter: `}`
2224
//~^^ ERROR: expected expression, found `)`

src/test/ui/codemap_tests/tab.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0425]: unresolved name `bar`
22
--> $DIR/tab.rs:14:2
33
|
44
14 | \tbar;
5-
| \t^^^
5+
| \t^^^ unresolved name
66

77
error: aborting due to previous error
88

src/test/ui/macros/macro-backtrace-nested.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0425]: unresolved name `fake`
22
--> $DIR/macro-backtrace-nested.rs:15:12
33
|
44
15 | () => (fake)
5-
| ^^^^
5+
| ^^^^ unresolved name
66
...
77
27 | 1 + call_nested_expr!();
88
| ------------------- in this macro invocation
@@ -11,7 +11,7 @@ error[E0425]: unresolved name `fake`
1111
--> $DIR/macro-backtrace-nested.rs:15:12
1212
|
1313
15 | () => (fake)
14-
| ^^^^
14+
| ^^^^ unresolved name
1515
...
1616
28 | call_nested_expr_sum!();
1717
| ------------------------ in this macro invocation

src/test/compile-fail/typo-suggestion.rs renamed to src/test/ui/span/typo-suggestion.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ fn main() {
1313

1414
// `foo` shouldn't be suggested, it is too dissimilar from `bar`.
1515
println!("Hello {}", bar);
16-
//~^ ERROR: unresolved name `bar`
1716

1817
// But this is close enough.
1918
println!("Hello {}", fob);
20-
//~^ ERROR: unresolved name `fob`. Did you mean `foo`?
2119
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0425]: unresolved name `bar`
2+
--> $DIR/typo-suggestion.rs:15:26
3+
|
4+
15 | println!("Hello {}", bar);
5+
| ^^^ unresolved name
6+
7+
error[E0425]: unresolved name `fob`
8+
--> $DIR/typo-suggestion.rs:18:26
9+
|
10+
18 | println!("Hello {}", fob);
11+
| ^^^ did you mean `foo`?
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)