Rollup merge of #36128 - gavinb:error_msgs_p2, r=jonathandturner

Update Error format for E0516, E0517, E0518

- E0518 Update error format #36111
- E0517 Update error format #36109
- E0516 Update error format #36108
- Part of #35233

r? @jonathandturner
This commit is contained in:
Jonathan Turner 2016-09-06 09:38:02 -07:00 committed by GitHub
commit 4f74f837b6
5 changed files with 28 additions and 10 deletions

View File

@ -42,7 +42,9 @@ struct CheckAttrVisitor<'a> {
impl<'a> CheckAttrVisitor<'a> {
fn check_inline(&self, attr: &ast::Attribute, target: Target) {
if target != Target::Fn {
span_err!(self.sess, attr.span, E0518, "attribute should be applied to function");
struct_span_err!(self.sess, attr.span, E0518, "attribute should be applied to function")
.span_label(attr.span, &format!("requires a function"))
.emit();
}
}
@ -56,18 +58,20 @@ impl<'a> CheckAttrVisitor<'a> {
let mut conflicting_reprs = 0;
for word in words {
let name = match word.name() {
Some(word) => word,
None => continue,
};
let message = match &*name {
let (message, label) = match &*name {
"C" => {
conflicting_reprs += 1;
if target != Target::Struct &&
target != Target::Union &&
target != Target::Enum {
"attribute should be applied to struct, enum or union"
("attribute should be applied to struct, enum or union",
"a struct, enum or union")
} else {
continue
}
@ -77,7 +81,8 @@ impl<'a> CheckAttrVisitor<'a> {
// can be used to modify another repr hint
if target != Target::Struct &&
target != Target::Union {
"attribute should be applied to struct or union"
("attribute should be applied to struct or union",
"a struct or union")
} else {
continue
}
@ -85,7 +90,8 @@ impl<'a> CheckAttrVisitor<'a> {
"simd" => {
conflicting_reprs += 1;
if target != Target::Struct {
"attribute should be applied to struct"
("attribute should be applied to struct",
"a struct")
} else {
continue
}
@ -95,15 +101,17 @@ impl<'a> CheckAttrVisitor<'a> {
"isize" | "usize" => {
conflicting_reprs += 1;
if target != Target::Enum {
"attribute should be applied to enum"
("attribute should be applied to enum",
"an enum")
} else {
continue
}
}
_ => continue,
};
span_err!(self.sess, attr.span, E0517, "{}", message);
struct_span_err!(self.sess, attr.span, E0517, "{}", message)
.span_label(attr.span, &format!("requires {}", label))
.emit();
}
if conflicting_reprs > 1 {
span_warn!(self.sess, attr.span, E0566,

View File

@ -1769,8 +1769,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
}
}
hir::TyTypeof(ref _e) => {
span_err!(tcx.sess, ast_ty.span, E0516,
"`typeof` is a reserved keyword but unimplemented");
struct_span_err!(tcx.sess, ast_ty.span, E0516,
"`typeof` is a reserved keyword but unimplemented")
.span_label(ast_ty.span, &format!("reserved keyword"))
.emit();
tcx.types.err
}
hir::TyInfer => {

View File

@ -10,4 +10,5 @@
fn main() {
let x: typeof(92) = 92; //~ ERROR E0516
//~| reserved keyword
}

View File

@ -9,15 +9,19 @@
// except according to those terms.
#[repr(C)] //~ ERROR E0517
//~| requires a struct, enum or union
type Foo = u8;
#[repr(packed)] //~ ERROR E0517
//~| requires a struct
enum Foo2 {Bar, Baz}
#[repr(u8)] //~ ERROR E0517
//~| requires an enum
struct Foo3 {bar: bool, baz: bool}
#[repr(C)] //~ ERROR E0517
//~| requires a struct, enum or union
impl Foo3 {
}

View File

@ -9,9 +9,11 @@
// except according to those terms.
#[inline(always)] //~ ERROR E0518
//~| requires a function
struct Foo;
#[inline(never)] //~ ERROR E0518
//~| requires a function
impl Foo {
}