Skip to content

Commit

Permalink
Rollup merge of rust-lang#36330 - aclarry:e0560-update, r=jonathandtu…
Browse files Browse the repository at this point in the history
…rner

Updated E0560 to new error format

Added a small bit of code to add a label for E0560.

Also renamed src/test/compile-fail/E560.rs file to E0560.rs (not sure why it was named E560).
Updated all test cases which check this error.

Closes rust-lang#36199
  • Loading branch information
Jonathan Turner authored Sep 21, 2016
2 parents 53f9730 + 23efc54 commit aa22135
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 13 deletions.
13 changes: 12 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3094,7 +3094,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if let Some(field_name) = Self::suggest_field_name(variant,
&field.name,
skip_fields.collect()) {
err.span_label(field.name.span,&format!("did you mean `{}`?",field_name));
err.span_label(field.name.span,
&format!("field does not exist - did you mean `{}`?", field_name));
} else {
match ty.sty {
ty::TyAdt(adt, ..) if adt.is_enum() => {
err.span_label(field.name.span, &format!("`{}::{}` does not have this field",
ty, variant.name.as_str()));
}
_ => {
err.span_label(field.name.span, &format!("`{}` does not have this field", ty));
}
}
};
err.emit();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/E0559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ enum Field {
fn main() {
let s = Field::Fool { joke: 0 };
//~^ ERROR E0559
//~| NOTE did you mean `x`?
//~| NOTE field does not exist - did you mean `x`?
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ struct Simba {
}

fn main() {
let s = Simba { mother: 1, father: 0 }; //~ ERROR E0560
let s = Simba { mother: 1, father: 0 };
//~^ ERROR E0560
//~| NOTE `Simba` does not have this field
}
1 change: 1 addition & 0 deletions src/test/compile-fail/issue-19922.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ enum Homura {
fn main() {
let homura = Homura::Akemi { kaname: () };
//~^ ERROR variant `Homura::Akemi` has no field named `kaname`
//~| NOTE field does not exist - did you mean `madoka`?
}
8 changes: 6 additions & 2 deletions src/test/compile-fail/numeric-fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
struct S(u8, u16);

fn main() {
let s = S{0b1: 10, 0: 11}; //~ ERROR struct `S` has no field named `0b1`
let s = S{0b1: 10, 0: 11};
//~^ ERROR struct `S` has no field named `0b1`
//~| NOTE field does not exist - did you mean `1`?
match s {
S{0: a, 0x1: b, ..} => {} //~ ERROR does not have a field named `0x1`
S{0: a, 0x1: b, ..} => {}
//~^ ERROR does not have a field named `0x1`
//~| NOTE struct `S::{{constructor}}` does not have field `0x1`
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/struct-fields-hints-no-dupe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
foo : 5,
bar : 42,
//~^ ERROR struct `A` has no field named `bar`
//~| NOTE did you mean `barr`?
//~| NOTE field does not exist - did you mean `barr`?
car : 9,
};
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/struct-fields-hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ fn main() {
foo : 5,
bar : 42,
//~^ ERROR struct `A` has no field named `bar`
//~| NOTE did you mean `car`?
//~| NOTE field does not exist - did you mean `car`?
};
}
4 changes: 3 additions & 1 deletion src/test/compile-fail/struct-fields-too-many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct BuildData {
fn main() {
let foo = BuildData {
foo: 0,
bar: 0 //~ ERROR struct `BuildData` has no field named `bar`
bar: 0
//~^ ERROR struct `BuildData` has no field named `bar`
//~| NOTE `BuildData` does not have this field
};
}
8 changes: 4 additions & 4 deletions src/test/compile-fail/suggest-private-fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ fn main () {
let k = B {
aa: 20,
//~^ ERROR struct `xc::B` has no field named `aa`
//~| NOTE did you mean `a`?
//~| NOTE field does not exist - did you mean `a`?
bb: 20,
//~^ ERROR struct `xc::B` has no field named `bb`
//~| NOTE did you mean `a`?
//~| NOTE field does not exist - did you mean `a`?
};
// local crate struct
let l = A {
aa: 20,
//~^ ERROR struct `A` has no field named `aa`
//~| NOTE did you mean `a`?
//~| NOTE field does not exist - did you mean `a`?
bb: 20,
//~^ ERROR struct `A` has no field named `bb`
//~| NOTE did you mean `b`?
//~| NOTE field does not exist - did you mean `b`?
};
}
2 changes: 2 additions & 0 deletions src/test/compile-fail/union/union-fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn main() {
let u = U { a: 0, b: 1 }; //~ ERROR union expressions should have exactly one field
let u = U { a: 0, b: 1, c: 2 }; //~ ERROR union expressions should have exactly one field
//~^ ERROR union `U` has no field named `c`
//~| NOTE `U` does not have this field
let u = U { ..u }; //~ ERROR union expressions should have exactly one field
//~^ ERROR functional record update syntax requires a struct

Expand All @@ -29,6 +30,7 @@ fn main() {
let U { a, b } = u; //~ ERROR union patterns should have exactly one field
let U { a, b, c } = u; //~ ERROR union patterns should have exactly one field
//~^ ERROR union `U` does not have a field named `c`
//~| NOTE union `U` does not have field `c`
let U { .. } = u; //~ ERROR union patterns should have exactly one field
//~^ ERROR `..` cannot be used in union patterns
let U { a, .. } = u; //~ ERROR `..` cannot be used in union patterns
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/union/union-suggest-field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl U {
fn main() {
let u = U { principle: 0 };
//~^ ERROR union `U` has no field named `principle`
//~| NOTE did you mean `principal`?
//~| NOTE field does not exist - did you mean `principal`?
let w = u.principial; //~ ERROR attempted access of field `principial` on type `U`
//~^ HELP did you mean `principal`?

Expand Down

0 comments on commit aa22135

Please sign in to comment.