Skip to content

Commit 4f74f83

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#36128 - gavinb:error_msgs_p2, r=jonathandturner
Update Error format for E0516, E0517, E0518 - E0518 Update error format rust-lang#36111 - E0517 Update error format rust-lang#36109 - E0516 Update error format rust-lang#36108 - Part of rust-lang#35233 r? @jonathandturner
2 parents 613f350 + cd56d47 commit 4f74f83

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

src/librustc/hir/check_attr.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ struct CheckAttrVisitor<'a> {
4242
impl<'a> CheckAttrVisitor<'a> {
4343
fn check_inline(&self, attr: &ast::Attribute, target: Target) {
4444
if target != Target::Fn {
45-
span_err!(self.sess, attr.span, E0518, "attribute should be applied to function");
45+
struct_span_err!(self.sess, attr.span, E0518, "attribute should be applied to function")
46+
.span_label(attr.span, &format!("requires a function"))
47+
.emit();
4648
}
4749
}
4850

@@ -56,18 +58,20 @@ impl<'a> CheckAttrVisitor<'a> {
5658

5759
let mut conflicting_reprs = 0;
5860
for word in words {
61+
5962
let name = match word.name() {
6063
Some(word) => word,
6164
None => continue,
6265
};
6366

64-
let message = match &*name {
67+
let (message, label) = match &*name {
6568
"C" => {
6669
conflicting_reprs += 1;
6770
if target != Target::Struct &&
6871
target != Target::Union &&
6972
target != Target::Enum {
70-
"attribute should be applied to struct, enum or union"
73+
("attribute should be applied to struct, enum or union",
74+
"a struct, enum or union")
7175
} else {
7276
continue
7377
}
@@ -77,15 +81,17 @@ impl<'a> CheckAttrVisitor<'a> {
7781
// can be used to modify another repr hint
7882
if target != Target::Struct &&
7983
target != Target::Union {
80-
"attribute should be applied to struct or union"
84+
("attribute should be applied to struct or union",
85+
"a struct or union")
8186
} else {
8287
continue
8388
}
8489
}
8590
"simd" => {
8691
conflicting_reprs += 1;
8792
if target != Target::Struct {
88-
"attribute should be applied to struct"
93+
("attribute should be applied to struct",
94+
"a struct")
8995
} else {
9096
continue
9197
}
@@ -95,15 +101,17 @@ impl<'a> CheckAttrVisitor<'a> {
95101
"isize" | "usize" => {
96102
conflicting_reprs += 1;
97103
if target != Target::Enum {
98-
"attribute should be applied to enum"
104+
("attribute should be applied to enum",
105+
"an enum")
99106
} else {
100107
continue
101108
}
102109
}
103110
_ => continue,
104111
};
105-
106-
span_err!(self.sess, attr.span, E0517, "{}", message);
112+
struct_span_err!(self.sess, attr.span, E0517, "{}", message)
113+
.span_label(attr.span, &format!("requires {}", label))
114+
.emit();
107115
}
108116
if conflicting_reprs > 1 {
109117
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
}

src/test/compile-fail/E0517.rs

+4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@
99
// except according to those terms.
1010

1111
#[repr(C)] //~ ERROR E0517
12+
//~| requires a struct, enum or union
1213
type Foo = u8;
1314

1415
#[repr(packed)] //~ ERROR E0517
16+
//~| requires a struct
1517
enum Foo2 {Bar, Baz}
1618

1719
#[repr(u8)] //~ ERROR E0517
20+
//~| requires an enum
1821
struct Foo3 {bar: bool, baz: bool}
1922

2023
#[repr(C)] //~ ERROR E0517
24+
//~| requires a struct, enum or union
2125
impl Foo3 {
2226
}
2327

src/test/compile-fail/E0518.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
// except according to those terms.
1010

1111
#[inline(always)] //~ ERROR E0518
12+
//~| requires a function
1213
struct Foo;
1314

1415
#[inline(never)] //~ ERROR E0518
16+
//~| requires a function
1517
impl Foo {
1618
}
1719

0 commit comments

Comments
 (0)