Skip to content

Commit 7e5bca7

Browse files
committed
fix fallout and some span bugs
1 parent e46c459 commit 7e5bca7

23 files changed

+221
-107
lines changed

src/librustc_resolve/lib.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,15 +2168,15 @@ impl<'a> Resolver<'a> {
21682168
match candidate {
21692169
AssocSuggestion::Field => {
21702170
err.guess(span, "did you intend to access a struct field?",
2171-
format!("self.{}`?", path_str));
2171+
format!("self.{}", path_str));
21722172
if !self_is_available {
21732173
err.span_label(span, &format!("`self` value is only available in \
21742174
methods with `self` parameter"));
21752175
}
21762176
}
21772177
AssocSuggestion::MethodWithSelf if self_is_available => {
21782178
err.guess(span, "did you intend to call a method of the same name?",
2179-
format!("self.{}()", path_str));
2179+
format!("self.{}", path_str));
21802180
}
21812181
AssocSuggestion::MethodWithSelf | AssocSuggestion::AssocItem => {
21822182
err.guess(span, "did you mean an associated item of the same name?",
@@ -2192,7 +2192,7 @@ impl<'a> Resolver<'a> {
21922192
match (def, source) {
21932193
(Def::Macro(..), _) => {
21942194
err.guess(span, "did you intend to invoke a macro of the same name?",
2195-
format!("{}!(...)", path_str));
2195+
format!("{}!", path_str));
21962196
return err;
21972197
}
21982198
(Def::TyAlias(..), PathSource::Trait) => {
@@ -2201,15 +2201,23 @@ impl<'a> Resolver<'a> {
22012201
}
22022202
(Def::Mod(..), PathSource::Expr(Some(parent))) => match *parent {
22032203
ExprKind::Field(_, ident) => {
2204+
let span = Span {
2205+
hi: ident.span.hi,
2206+
.. span
2207+
};
22042208
err.guess(span,
22052209
"did you mean",
22062210
format!("{}::{}", path_str, ident.node));
22072211
return err;
22082212
}
22092213
ExprKind::MethodCall(ident, ..) => {
2214+
let span = Span {
2215+
hi: ident.span.hi,
2216+
.. span
2217+
};
22102218
err.guess(span,
22112219
"did you mean",
2212-
format!("{}::{}(...)", path_str, ident.node));
2220+
format!("{}::{}", path_str, ident.node));
22132221
return err;
22142222
}
22152223
_ => {}
@@ -2221,11 +2229,13 @@ impl<'a> Resolver<'a> {
22212229
if is_expected(ctor_def) && !this.is_accessible(ctor_vis) {
22222230
err.span_label(span, &format!("constructor is not visible \
22232231
here due to private fields"));
2232+
return err;
22242233
}
22252234
}
22262235
}
2227-
err.guess(span, "did you mean",
2228-
format!("{} {{ /* fields */ }}", path_str));
2236+
err.span_label(span,
2237+
&format!("did you mean `{} {{ /* fields */ }}`?",
2238+
path_str));
22292239
return err;
22302240
}
22312241
_ => {}

src/test/compile-fail/E0423.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ fn main () {
1212
struct Foo { a: bool };
1313

1414
let f = Foo(); //~ ERROR E0423
15-
//~^ GUESS Foo { /* fields */ }
1615
}

src/test/compile-fail/empty-struct-braces-expr.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,12 @@ enum E {
2323

2424
fn main() {
2525
let e1 = Empty1; //~ ERROR expected value, found struct `Empty1`
26-
//~^ GUESS Empty1 { /* fields */ }
2726
let e1 = Empty1(); //~ ERROR expected function, found struct `Empty1`
28-
//~^ GUESS Empty1 { /* fields */ }
2927
let e3 = E::Empty3; //~ ERROR expected value, found struct variant `E::Empty3`
30-
//~^ GUESS E::Empty3 { /* fields */ }
3128
let e3 = E::Empty3(); //~ ERROR expected function, found struct variant `E::Empty3`
32-
//~^ GUESS E::Empty3 { /* fields */ }
3329

3430
let xe1 = XEmpty1; //~ ERROR expected value, found struct `XEmpty1`
35-
//~^ GUESS Empty1 { /* fields */ }
3631
let xe1 = XEmpty1(); //~ ERROR expected function, found struct `XEmpty1`
37-
//~^ GUESS Empty1 { /* fields */ }
3832
let xe3 = XE::Empty3; //~ ERROR no associated item named `Empty3` found for type
3933
let xe3 = XE::Empty3(); //~ ERROR no associated item named `Empty3` found for type
4034
}

src/test/compile-fail/empty-struct-braces-pat-1.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ fn main() {
3333
match e3 {
3434
E::Empty3 => ()
3535
//~^ ERROR expected unit struct/variant or constant, found struct variant `E::Empty3`
36-
//~| GUESS E::Empty3 { /* fields */ }
3736
}
3837
match xe1 {
3938
XEmpty1 => () // Not an error, `XEmpty1` is interpreted as a new binding
4039
}
4140
match xe3 {
4241
XE::XEmpty3 => ()
4342
//~^ ERROR expected unit struct/variant or constant, found struct variant `XE::XEmpty3`
44-
//~| GUESS XE::XEmpty3 { /* fields */ }
4543
}
4644
}

src/test/compile-fail/empty-struct-braces-pat-2.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@ fn main() {
2323

2424
match e1 {
2525
Empty1() => () //~ ERROR expected tuple struct/variant, found struct `Empty1`
26-
//~^ GUESS Empty1 { /* fields */ }
2726
}
2827
match xe1 {
2928
XEmpty1() => () //~ ERROR expected tuple struct/variant, found struct `XEmpty1`
30-
//~^ GUESS XEmpty1 { /* fields */ }
3129
}
3230
match e1 {
3331
Empty1(..) => () //~ ERROR expected tuple struct/variant, found struct `Empty1`
34-
//~^ GUESS Empty1 { /* fields */ }
3532
}
3633
match xe1 {
3734
XEmpty1(..) => () //~ ERROR expected tuple struct/variant, found struct `XEmpty1`
38-
//~^ GUESS XEmpty1 { /* fields */ }
3935
}
4036
}

src/test/compile-fail/empty-struct-braces-pat-3.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,17 @@ fn main() {
2626
match e3 {
2727
E::Empty3() => ()
2828
//~^ ERROR expected tuple struct/variant, found struct variant `E::Empty3`
29-
//~| GUESS E::Empty3 { /* fields */ }
3029
}
3130
match xe3 {
3231
XE::XEmpty3() => ()
3332
//~^ ERROR expected tuple struct/variant, found struct variant `XE::XEmpty3`
34-
//~| GUESS XE::XEmpty3 { /* fields */ }
3533
}
3634
match e3 {
3735
E::Empty3(..) => ()
3836
//~^ ERROR expected tuple struct/variant, found struct variant `E::Empty3`
39-
//~| GUESS E::Empty3 { /* fields */ }
4037
}
4138
match xe3 {
4239
XE::XEmpty3(..) => ()
4340
//~^ ERROR expected tuple struct/variant, found struct variant `XE::XEmpty3
44-
//~| GUESS XE::XEmpty3 { /* fields */ }
4541
}
4642
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ fn main() {
1919
match f {
2020
FooB(a, b) => println!("{} {}", a, b),
2121
//~^ ERROR expected tuple struct/variant, found struct variant `FooB`
22-
//~| GUESS FooB { /* fields */ }
2322
}
2423
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
fn main() {
1212
let Box(a) = loop { };
1313
//~^ ERROR expected tuple struct/variant, found struct `Box`
14-
//~| ERROR expected tuple struct/variant, found struct `Box`
1514

1615
// (The below is a trick to allow compiler to infer a type for
1716
// variable `a` without attempting to ascribe a type to the

src/test/compile-fail/namespace-mix.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ mod m2 {
4242
fn f12() {
4343
check(m1::S{}); //~ ERROR c::Item
4444
check(m1::S); //~ ERROR expected value, found type alias `m1::S`
45-
//~^ GUESS m1::S { /* fields */ }
4645
check(m2::S{}); //~ ERROR c::S
4746
check(m2::S); //~ ERROR c::Item
4847
}
4948
fn xf12() {
5049
check(xm1::S{}); //~ ERROR c::Item
5150
check(xm1::S); //~ ERROR expected value, found type alias `xm1::S`
52-
//~^ GUESS xm1::S { /* fields */ }
5351
check(xm2::S{}); //~ ERROR c::S
5452
check(xm2::S); //~ ERROR c::Item
5553
}
@@ -110,14 +108,12 @@ mod m8 {
110108
fn f78() {
111109
check(m7::V{}); //~ ERROR c::Item
112110
check(m7::V); //~ ERROR expected value, found struct variant `m7::V`
113-
//~^ GUESS m7::V { /* fields */ }
114111
check(m8::V{}); //~ ERROR c::E
115112
check(m8::V); //~ ERROR c::Item
116113
}
117114
fn xf78() {
118115
check(xm7::V{}); //~ ERROR c::Item
119116
check(xm7::V); //~ ERROR expected value, found struct variant `xm7::V`
120-
//~^ GUESS xm7::V { /* fields */ }
121117
check(xm8::V{}); //~ ERROR c::E
122118
check(xm8::V); //~ ERROR c::Item
123119
}

src/test/compile-fail/ufcs-partially-resolved.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ fn main() {
6666
let _: <u8 as Dr>::Z; //~ ERROR expected associated type, found method `Dr::Z`
6767
//~^ GUESS Dr::X
6868
<u8 as Dr>::X; //~ ERROR expected method or associated constant, found associated type `Dr::X`
69-
//~^ GUESS Dr::X { /* fields */ }
7069
let _: <u8 as Dr>::Z::N; //~ ERROR expected associated type, found method `Dr::Z`
7170
//~^ GUESS Dr::X
7271
<u8 as Dr>::X::N; //~ ERROR no associated item named `N` found for type `<u8 as Dr>::X`

src/test/compile-fail/xcrate-unit-struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ extern crate xcrate_unit_struct;
1818
fn main() {
1919
let _ = xcrate_unit_struct::StructWithFields;
2020
//~^ ERROR expected value, found struct `xcrate_unit_struct::StructWithFields`
21-
//~| GUESS xcrate_unit_struct::StructWithFields { /* fields */ }
2221
let _ = xcrate_unit_struct::Struct;
2322
}

src/test/ui/did_you_mean/issue-36798.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ error: no field `baz` on type `Foo`
22
--> $DIR/issue-36798.rs:17:7
33
|
44
17 | f.baz;
5-
| ^^^ did you mean `bar`?
5+
| ^^^
6+
|
7+
help: did you mean
8+
| f.bar;
69

710
error: aborting due to previous error
811

src/test/ui/mismatched_types/cast-rfc0401.stderr

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,8 @@ error: casting `&{float}` as `f32` is invalid
230230
81 | vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>();
231231
| ^^^^^^^^ cannot cast `&{float}` as `f32`
232232
|
233-
help: did you mean `*s`?
234-
--> $DIR/cast-rfc0401.rs:81:30
235-
|
236-
81 | vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>();
237-
| ^
233+
help: did you mean
234+
| vec![0.0].iter().map(|s| *s as f32).collect::<Vec<f32>>();
238235

239236
error: aborting due to 34 previous errors
240237

0 commit comments

Comments
 (0)