Skip to content

Check for known but incorrect attributes #49291

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

Merged
merged 3 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 2 additions & 12 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
self.emit_repr_error(
attr.span,
stmt.span,
&format!("attribute should not be applied to statements"),
&format!("attribute should not be applied a statement"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "to".

&format!("not a struct, enum or union"),
);
}
Expand All @@ -259,16 +259,6 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
}

fn check_expr_attributes(&self, expr: &hir::Expr) {
use hir::Expr_::*;
match expr.node {
// Assignments, Calls and Structs were handled by Items and Statements
ExprCall(..) |
ExprAssign(..) |
ExprMethodCall(..) |
ExprStruct(..) => return,
_ => (),
}

for attr in expr.attrs.iter() {
if attr.check_name("inline") {
self.check_inline(attr, &expr.span, Target::Expression);
Expand All @@ -278,7 +268,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
attr.span,
expr.span,
&format!("attribute should not be applied to an expression"),
&format!("not a struct, enum or union"),
&format!("not defining a struct, enum or union"),
);
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/test/compile-fail/issue-43988.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ fn main() {

#[repr(nothing)]
let _x = 0;
//~^^ ERROR attribute should not be applied to statements

//~^^ ERROR attribute should not be applied a statement

#[repr(something_not_real)]
loop {
Expand All @@ -32,5 +31,12 @@ fn main() {

#[repr]
let _y = "123";
//~^^ ERROR attribute should not be applied to statements
//~^^ ERROR attribute should not be applied a statement


fn foo() {}

#[inline(ABC)]
foo();
//~^^ ERROR attribute should be applied to function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the tests are for statements, could you add a test for an expression too?
Something like let x = #[repr] y;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this example. I needed to add a feature in the tests to get it to actually run.

Otherwise error[E0658]: attributes on non-item statements and expressions are experimental. (see issue #15701) stopped all of the tests early.

}