Skip to content

Commit e70b1ba

Browse files
authored
Rollup merge of rust-lang#35285 - razielgn:updated-e0071-to-new-format, r=jonathandturner
Updated E0071 to new format. Bonus: the span underlines only the name of the thing that's not a struct rather than the whole expression. Part of rust-lang#35233. Fixes rust-lang#35220. r? @jonathandturner
2 parents 361d9b4 + 7c58b26 commit e70b1ba

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,9 +3147,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
31473147
};
31483148
if variant.is_none() || variant.unwrap().kind == ty::VariantKind::Tuple {
31493149
// Reject tuple structs for now, braced and unit structs are allowed.
3150-
span_err!(self.tcx.sess, span, E0071,
3151-
"`{}` does not name a struct or a struct variant",
3152-
pprust::path_to_string(path));
3150+
struct_span_err!(self.tcx.sess, path.span, E0071,
3151+
"`{}` does not name a struct or a struct variant",
3152+
pprust::path_to_string(path))
3153+
.span_label(path.span, &format!("not a struct"))
3154+
.emit();
3155+
31533156
return None;
31543157
}
31553158

src/test/compile-fail/E0071.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
enum Foo { FirstValue(i32) }
1212

1313
fn main() {
14-
let u = Foo::FirstValue { value: 0 }; //~ ERROR E0071
15-
let t = u32 { value: 4 }; //~ ERROR E0071
14+
let u = Foo::FirstValue { value: 0 };
15+
//~^ ERROR `Foo::FirstValue` does not name a struct or a struct variant [E0071]
16+
//~| NOTE not a struct
17+
18+
let t = u32 { value: 4 };
19+
//~^ ERROR `u32` does not name a struct or a struct variant [E0071]
20+
//~| NOTE not a struct
1621
}

src/test/compile-fail/trait-as-struct-constructor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ trait TraitNotAStruct {}
1313
fn main() {
1414
TraitNotAStruct{ value: 0 };
1515
//~^ ERROR: `TraitNotAStruct` does not name a struct or a struct variant [E0071]
16+
//~| NOTE not a struct
1617
}

0 commit comments

Comments
 (0)