Skip to content

Commit d53ea97

Browse files
committed
E0516 Update error format #36108
- fixes #36108 - part of #35233
1 parent 2dbf600 commit d53ea97

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/librustc/hir/check_attr.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,21 @@ impl<'a> CheckAttrVisitor<'a> {
5656

5757
let mut conflicting_reprs = 0;
5858
for word in words {
59+
5960
let name = match word.name() {
6061
Some(word) => word,
6162
None => continue,
6263
};
6364

64-
let message = match &*name {
65+
let word: &str = &word.name();
66+
let (message, label) = match word {
6567
"C" => {
6668
conflicting_reprs += 1;
6769
if target != Target::Struct &&
6870
target != Target::Union &&
6971
target != Target::Enum {
70-
"attribute should be applied to struct, enum or union"
72+
("attribute should be applied to struct, enum or union",
73+
"a struct, enum or union")
7174
} else {
7275
continue
7376
}
@@ -85,7 +88,8 @@ impl<'a> CheckAttrVisitor<'a> {
8588
"simd" => {
8689
conflicting_reprs += 1;
8790
if target != Target::Struct {
88-
"attribute should be applied to struct"
91+
("attribute should be applied to struct",
92+
"a struct")
8993
} else {
9094
continue
9195
}
@@ -95,15 +99,17 @@ impl<'a> CheckAttrVisitor<'a> {
9599
"isize" | "usize" => {
96100
conflicting_reprs += 1;
97101
if target != Target::Enum {
98-
"attribute should be applied to enum"
102+
("attribute should be applied to enum",
103+
"an enum")
99104
} else {
100105
continue
101106
}
102107
}
103108
_ => continue,
104109
};
105-
106-
span_err!(self.sess, attr.span, E0517, "{}", message);
110+
struct_span_err!(self.sess, attr.span, E0517, "{}", message)
111+
.span_label(attr.span, &format!("requires {}", label))
112+
.emit();
107113
}
108114
if conflicting_reprs > 1 {
109115
span_warn!(self.sess, attr.span, E0566,

src/librustc_typeck/astconv.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
17691769
}
17701770
}
17711771
hir::TyTypeof(ref _e) => {
1772-
span_err!(tcx.sess, ast_ty.span, E0516,
1773-
"`typeof` is a reserved keyword but unimplemented");
1772+
struct_span_err!(tcx.sess, ast_ty.span, E0516,
1773+
"`typeof` is a reserved keyword but unimplemented")
1774+
.span_label(ast_ty.span, &format!("reserved keyword"))
1775+
.emit();
1776+
17741777
tcx.types.err
17751778
}
17761779
hir::TyInfer => {

src/test/compile-fail/E0516.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010

1111
fn main() {
1212
let x: typeof(92) = 92; //~ ERROR E0516
13+
//~| reserved keyword
1314
}

0 commit comments

Comments
 (0)