diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index a2d4239388a..8ba52cdb64f 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -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, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 5925d222b44..334b7a5063a 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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 => { diff --git a/src/test/compile-fail/E0516.rs b/src/test/compile-fail/E0516.rs index a5f609de849..be2b89c5f39 100644 --- a/src/test/compile-fail/E0516.rs +++ b/src/test/compile-fail/E0516.rs @@ -10,4 +10,5 @@ fn main() { let x: typeof(92) = 92; //~ ERROR E0516 + //~| reserved keyword } diff --git a/src/test/compile-fail/E0517.rs b/src/test/compile-fail/E0517.rs index be06e809915..b79cb2c44af 100644 --- a/src/test/compile-fail/E0517.rs +++ b/src/test/compile-fail/E0517.rs @@ -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 { } diff --git a/src/test/compile-fail/E0518.rs b/src/test/compile-fail/E0518.rs index 8518bb4a6be..f9494e0bcb5 100644 --- a/src/test/compile-fail/E0518.rs +++ b/src/test/compile-fail/E0518.rs @@ -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 { }