From d53ea97bfc149da4cdd0fb1fd1beab08295ae45d Mon Sep 17 00:00:00 2001 From: Gavin Baker Date: Tue, 30 Aug 2016 11:04:55 +1000 Subject: [PATCH 1/3] E0516 Update error format #36108 - fixes #36108 - part of #35233 --- src/librustc/hir/check_attr.rs | 18 ++++++++++++------ src/librustc_typeck/astconv.rs | 7 +++++-- src/test/compile-fail/E0516.rs | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index a2d4239388ace..6997b5d770226 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -56,18 +56,21 @@ 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 word: &str = &word.name(); + let (message, label) = match word { "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 } @@ -85,7 +88,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 +99,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 5925d222b4466..334b7a5063a3a 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 a5f609de8497e..be2b89c5f396e 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 } From 8bcd6a33bebb8177781ae07ea1fc0d4a9a679627 Mon Sep 17 00:00:00 2001 From: Gavin Baker Date: Tue, 30 Aug 2016 11:30:46 +1000 Subject: [PATCH 2/3] E0517 Update error format #36109 - Fixes #36109 - Part of #35233 --- src/librustc/hir/check_attr.rs | 6 +++--- src/test/compile-fail/E0517.rs | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 6997b5d770226..a3ab5f949e7d3 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -62,8 +62,7 @@ impl<'a> CheckAttrVisitor<'a> { None => continue, }; - let word: &str = &word.name(); - let (message, label) = match word { + let (message, label) = match &*name { "C" => { conflicting_reprs += 1; if target != Target::Struct && @@ -80,7 +79,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 } diff --git a/src/test/compile-fail/E0517.rs b/src/test/compile-fail/E0517.rs index be06e809915b5..b79cb2c44af39 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 { } From cd56d47da3a2c2ed2eb2a1e4e54ca471c2c9172a Mon Sep 17 00:00:00 2001 From: Gavin Baker Date: Tue, 30 Aug 2016 11:44:25 +1000 Subject: [PATCH 3/3] E0518 Update error format #36111 - Fixes #36111 - Part of #35233 --- src/librustc/hir/check_attr.rs | 4 +++- src/test/compile-fail/E0518.rs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index a3ab5f949e7d3..8ba52cdb64f5f 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(); } } diff --git a/src/test/compile-fail/E0518.rs b/src/test/compile-fail/E0518.rs index 8518bb4a6be3f..f9494e0bcb531 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 { }