mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-04 12:44:40 +00:00
Update error format for E0062
This commit is contained in:
parent
e804a3cf25
commit
0214ec248b
@ -3063,6 +3063,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
remaining_fields.insert(field.name, field);
|
||||
}
|
||||
|
||||
let mut seen_fields = FnvHashMap();
|
||||
|
||||
let mut error_happened = false;
|
||||
|
||||
// Typecheck each field.
|
||||
@ -3071,13 +3073,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
if let Some(v_field) = remaining_fields.remove(&field.name.node) {
|
||||
expected_field_type = self.field_ty(field.span, v_field, substs);
|
||||
|
||||
seen_fields.insert(field.name.node, field.span);
|
||||
} else {
|
||||
error_happened = true;
|
||||
expected_field_type = tcx.types.err;
|
||||
if let Some(_) = variant.find_field_named(field.name.node) {
|
||||
span_err!(self.tcx.sess, field.name.span, E0062,
|
||||
"field `{}` specified more than once",
|
||||
field.name.node);
|
||||
let mut err = struct_span_err!(self.tcx.sess,
|
||||
field.name.span,
|
||||
E0062,
|
||||
"field `{}` specified more than once",
|
||||
field.name.node);
|
||||
|
||||
err.span_label(field.name.span, &format!("used more than once"));
|
||||
|
||||
if let Some(prev_span) = seen_fields.get(&field.name.node) {
|
||||
err.span_label(*prev_span, &format!("first use of `{}`", field.name.node));
|
||||
}
|
||||
|
||||
err.emit();
|
||||
} else {
|
||||
self.report_unknown_field(adt_ty, variant, field, ast_fields);
|
||||
}
|
||||
|
@ -14,7 +14,9 @@ struct Foo {
|
||||
|
||||
fn main() {
|
||||
let x = Foo {
|
||||
x: 0, //~ NOTE first use of `x`
|
||||
x: 0,
|
||||
x: 0, //~ ERROR E0062
|
||||
//~^ ERROR E0062
|
||||
//~| NOTE used more than once
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user