Emit warning for ignored #[inline] on foreign function prototypes

This commit is contained in:
varkor 2019-10-11 02:35:49 +01:00
parent 94c4dd9902
commit 66d7ef077a
3 changed files with 29 additions and 0 deletions

View file

@ -40,6 +40,9 @@ pub(crate) enum Target {
AssocConst,
Method { body: bool },
AssocTy,
ForeignFn,
ForeignStatic,
ForeignTy,
}
impl Display for Target {
@ -67,6 +70,9 @@ impl Display for Target {
Target::AssocConst => "associated const",
Target::Method { .. } => "method",
Target::AssocTy => "associated type",
Target::ForeignFn => "foreign function",
Target::ForeignStatic => "foreign static item",
Target::ForeignTy => "foreign type",
})
}
}
@ -105,6 +111,12 @@ impl Target {
TraitItemKind::Type(..) => Target::AssocTy,
}
}
fn from_foreign_item(foreign_item: &hir::ForeignItem) -> Target {
match foreign_item.kind {
hir::ForeignItemKind::Fn(..) => Target::ForeignFn,
hir::ForeignItemKind::Static(..) => Target::ForeignStatic,
hir::ForeignItemKind::Type => Target::ForeignTy,
}
}
}
@ -427,6 +439,12 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
intravisit::walk_trait_item(self, trait_item)
}
fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem) {
let target = Target::from_foreign_item(f_item);
self.check_attributes(f_item.hir_id, &f_item.attrs, &f_item.span, target, None);
intravisit::walk_foreign_item(self, f_item)
}
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt) {
self.check_stmt_attributes(stmt);
intravisit::walk_stmt(self, stmt)

View file

@ -5,4 +5,9 @@ trait Trait {
fn foo();
}
extern {
#[inline] //~ ERROR `#[inline]` is ignored on function prototypes
fn foo();
}
fn main() {}

View file

@ -10,5 +10,11 @@ note: lint level defined here
LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
error: `#[inline]` is ignored on function prototypes
--> $DIR/warn-unused-inline-on-fn-prototypes.rs:4:5
|
LL | #[inline]
| ^^^^^^^^^
error: aborting due to 2 previous errors