Skip to content

Commit

Permalink
Rollup merge of rust-lang#36128 - gavinb:error_msgs_p2, r=jonathandtu…
Browse files Browse the repository at this point in the history
…rner

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
  • Loading branch information
Jonathan Turner authored Sep 6, 2016
2 parents a4a9f04 + cd56d47 commit f03886e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
24 changes: 16 additions & 8 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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
}
Expand All @@ -77,15 +81,17 @@ 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
}
}
"simd" => {
conflicting_reprs += 1;
if target != Target::Struct {
"attribute should be applied to struct"
("attribute should be applied to struct",
"a struct")
} else {
continue
}
Expand All @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/E0516.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

fn main() {
let x: typeof(92) = 92; //~ ERROR E0516
//~| reserved keyword
}
4 changes: 4 additions & 0 deletions src/test/compile-fail/E0517.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/E0518.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}

Expand Down

0 comments on commit f03886e

Please sign in to comment.