Skip to content

Commit 11f3da8

Browse files
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
2 parents 7b11a3c + 0214ec2 commit 11f3da8

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/librustc_typeck/check/mod.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -3069,6 +3069,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30693069
remaining_fields.insert(field.name, field);
30703070
}
30713071

3072+
let mut seen_fields = FnvHashMap();
3073+
30723074
let mut error_happened = false;
30733075

30743076
// Typecheck each field.
@@ -3077,13 +3079,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30773079

30783080
if let Some(v_field) = remaining_fields.remove(&field.name.node) {
30793081
expected_field_type = self.field_ty(field.span, v_field, substs);
3082+
3083+
seen_fields.insert(field.name.node, field.span);
30803084
} else {
30813085
error_happened = true;
30823086
expected_field_type = tcx.types.err;
30833087
if let Some(_) = variant.find_field_named(field.name.node) {
3084-
span_err!(self.tcx.sess, field.name.span, E0062,
3085-
"field `{}` specified more than once",
3086-
field.name.node);
3088+
let mut err = struct_span_err!(self.tcx.sess,
3089+
field.name.span,
3090+
E0062,
3091+
"field `{}` specified more than once",
3092+
field.name.node);
3093+
3094+
err.span_label(field.name.span, &format!("used more than once"));
3095+
3096+
if let Some(prev_span) = seen_fields.get(&field.name.node) {
3097+
err.span_label(*prev_span, &format!("first use of `{}`", field.name.node));
3098+
}
3099+
3100+
err.emit();
30873101
} else {
30883102
self.report_unknown_field(adt_ty, variant, field, ast_fields);
30893103
}

src/test/compile-fail/E0062.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ struct Foo {
1414

1515
fn main() {
1616
let x = Foo {
17+
x: 0, //~ NOTE first use of `x`
1718
x: 0,
18-
x: 0, //~ ERROR E0062
19+
//~^ ERROR E0062
20+
//~| NOTE used more than once
1921
};
2022
}

0 commit comments

Comments
 (0)