Rollup merge of #35328 - trixnz:update-error-62, r=jonathandturner

Update error format for E0062

Fixes #35217 as part of #35233

There seems to be an issue with the old format ignoring the labels which results in the incorrect line being rendered in the old format. I spoke with @jonathandturner about this and it seems to be a bug. Pertinent information [here](https://gist.github.com/trixnz/ad11e68687529e164427df8f8eb63116).

r? @jonathandturner
This commit is contained in:
Guillaume Gomez 2016-08-05 16:12:59 +02:00 committed by GitHub
commit 8b9700898b
2 changed files with 20 additions and 4 deletions

View file

@ -3069,6 +3069,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.
@ -3077,13 +3079,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);
}

View file

@ -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
};
}