Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Error format for E0516, E0517, E0518 #36128

Merged
merged 3 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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