Skip to content

Commit 23efc54

Browse files
committed
Update E0560 to include label
1 parent af67f0b commit 23efc54

11 files changed

+35
-13
lines changed

src/librustc_typeck/check/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -3094,7 +3094,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30943094
if let Some(field_name) = Self::suggest_field_name(variant,
30953095
&field.name,
30963096
skip_fields.collect()) {
3097-
err.span_label(field.name.span,&format!("did you mean `{}`?",field_name));
3097+
err.span_label(field.name.span,
3098+
&format!("field does not exist - did you mean `{}`?", field_name));
3099+
} else {
3100+
match ty.sty {
3101+
ty::TyAdt(adt, ..) if adt.is_enum() => {
3102+
err.span_label(field.name.span, &format!("`{}::{}` does not have this field",
3103+
ty, variant.name.as_str()));
3104+
}
3105+
_ => {
3106+
err.span_label(field.name.span, &format!("`{}` does not have this field", ty));
3107+
}
3108+
}
30983109
};
30993110
err.emit();
31003111
}

src/test/compile-fail/E0559.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ enum Field {
1515
fn main() {
1616
let s = Field::Fool { joke: 0 };
1717
//~^ ERROR E0559
18-
//~| NOTE did you mean `x`?
18+
//~| NOTE field does not exist - did you mean `x`?
1919
}

src/test/compile-fail/E0560.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ struct Simba {
1313
}
1414

1515
fn main() {
16-
let s = Simba { mother: 1, father: 0 }; //~ ERROR E0560
16+
let s = Simba { mother: 1, father: 0 };
17+
//~^ ERROR E0560
18+
//~| NOTE `Simba` does not have this field
1719
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ enum Homura {
1515
fn main() {
1616
let homura = Homura::Akemi { kaname: () };
1717
//~^ ERROR variant `Homura::Akemi` has no field named `kaname`
18+
//~| NOTE field does not exist - did you mean `madoka`?
1819
}

src/test/compile-fail/numeric-fields.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
struct S(u8, u16);
1414

1515
fn main() {
16-
let s = S{0b1: 10, 0: 11}; //~ ERROR struct `S` has no field named `0b1`
16+
let s = S{0b1: 10, 0: 11};
17+
//~^ ERROR struct `S` has no field named `0b1`
18+
//~| NOTE field does not exist - did you mean `1`?
1719
match s {
18-
S{0: a, 0x1: b, ..} => {} //~ ERROR does not have a field named `0x1`
20+
S{0: a, 0x1: b, ..} => {}
21+
//~^ ERROR does not have a field named `0x1`
22+
//~| NOTE struct `S::{{constructor}}` does not have field `0x1`
1923
}
2024
}

src/test/compile-fail/struct-fields-hints-no-dupe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
foo : 5,
2020
bar : 42,
2121
//~^ ERROR struct `A` has no field named `bar`
22-
//~| NOTE did you mean `barr`?
22+
//~| NOTE field does not exist - did you mean `barr`?
2323
car : 9,
2424
};
2525
}

src/test/compile-fail/struct-fields-hints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ fn main() {
1919
foo : 5,
2020
bar : 42,
2121
//~^ ERROR struct `A` has no field named `bar`
22-
//~| NOTE did you mean `car`?
22+
//~| NOTE field does not exist - did you mean `car`?
2323
};
2424
}

src/test/compile-fail/struct-fields-too-many.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ struct BuildData {
1515
fn main() {
1616
let foo = BuildData {
1717
foo: 0,
18-
bar: 0 //~ ERROR struct `BuildData` has no field named `bar`
18+
bar: 0
19+
//~^ ERROR struct `BuildData` has no field named `bar`
20+
//~| NOTE `BuildData` does not have this field
1921
};
2022
}

src/test/compile-fail/suggest-private-fields.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ fn main () {
2424
let k = B {
2525
aa: 20,
2626
//~^ ERROR struct `xc::B` has no field named `aa`
27-
//~| NOTE did you mean `a`?
27+
//~| NOTE field does not exist - did you mean `a`?
2828
bb: 20,
2929
//~^ ERROR struct `xc::B` has no field named `bb`
30-
//~| NOTE did you mean `a`?
30+
//~| NOTE field does not exist - did you mean `a`?
3131
};
3232
// local crate struct
3333
let l = A {
3434
aa: 20,
3535
//~^ ERROR struct `A` has no field named `aa`
36-
//~| NOTE did you mean `a`?
36+
//~| NOTE field does not exist - did you mean `a`?
3737
bb: 20,
3838
//~^ ERROR struct `A` has no field named `bb`
39-
//~| NOTE did you mean `b`?
39+
//~| NOTE field does not exist - did you mean `b`?
4040
};
4141
}

src/test/compile-fail/union/union-fields.rs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fn main() {
2121
let u = U { a: 0, b: 1 }; //~ ERROR union expressions should have exactly one field
2222
let u = U { a: 0, b: 1, c: 2 }; //~ ERROR union expressions should have exactly one field
2323
//~^ ERROR union `U` has no field named `c`
24+
//~| NOTE `U` does not have this field
2425
let u = U { ..u }; //~ ERROR union expressions should have exactly one field
2526
//~^ ERROR functional record update syntax requires a struct
2627

@@ -29,6 +30,7 @@ fn main() {
2930
let U { a, b } = u; //~ ERROR union patterns should have exactly one field
3031
let U { a, b, c } = u; //~ ERROR union patterns should have exactly one field
3132
//~^ ERROR union `U` does not have a field named `c`
33+
//~| NOTE union `U` does not have field `c`
3234
let U { .. } = u; //~ ERROR union patterns should have exactly one field
3335
//~^ ERROR `..` cannot be used in union patterns
3436
let U { a, .. } = u; //~ ERROR `..` cannot be used in union patterns

src/test/compile-fail/union/union-suggest-field.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl U {
2121
fn main() {
2222
let u = U { principle: 0 };
2323
//~^ ERROR union `U` has no field named `principle`
24-
//~| NOTE did you mean `principal`?
24+
//~| NOTE field does not exist - did you mean `principal`?
2525
let w = u.principial; //~ ERROR attempted access of field `principial` on type `U`
2626
//~^ HELP did you mean `principal`?
2727

0 commit comments

Comments
 (0)