Skip to content

Commit 66d7ef0

Browse files
committed
Emit warning for ignored #[inline] on foreign function prototypes
1 parent 94c4dd9 commit 66d7ef0

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/librustc/hir/check_attr.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ pub(crate) enum Target {
4040
AssocConst,
4141
Method { body: bool },
4242
AssocTy,
43+
ForeignFn,
44+
ForeignStatic,
45+
ForeignTy,
4346
}
4447

4548
impl Display for Target {
@@ -67,6 +70,9 @@ impl Display for Target {
6770
Target::AssocConst => "associated const",
6871
Target::Method { .. } => "method",
6972
Target::AssocTy => "associated type",
73+
Target::ForeignFn => "foreign function",
74+
Target::ForeignStatic => "foreign static item",
75+
Target::ForeignTy => "foreign type",
7076
})
7177
}
7278
}
@@ -105,6 +111,12 @@ impl Target {
105111
TraitItemKind::Type(..) => Target::AssocTy,
106112
}
107113
}
114+
115+
fn from_foreign_item(foreign_item: &hir::ForeignItem) -> Target {
116+
match foreign_item.kind {
117+
hir::ForeignItemKind::Fn(..) => Target::ForeignFn,
118+
hir::ForeignItemKind::Static(..) => Target::ForeignStatic,
119+
hir::ForeignItemKind::Type => Target::ForeignTy,
108120
}
109121
}
110122
}
@@ -427,6 +439,12 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
427439
intravisit::walk_trait_item(self, trait_item)
428440
}
429441

442+
fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem) {
443+
let target = Target::from_foreign_item(f_item);
444+
self.check_attributes(f_item.hir_id, &f_item.attrs, &f_item.span, target, None);
445+
intravisit::walk_foreign_item(self, f_item)
446+
}
447+
430448
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt) {
431449
self.check_stmt_attributes(stmt);
432450
intravisit::walk_stmt(self, stmt)

src/test/ui/lint/warn-unused-inline-on-fn-prototypes.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ trait Trait {
55
fn foo();
66
}
77

8+
extern {
9+
#[inline] //~ ERROR `#[inline]` is ignored on function prototypes
10+
fn foo();
11+
}
12+
813
fn main() {}

src/test/ui/lint/warn-unused-inline-on-fn-prototypes.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ note: lint level defined here
1010
LL | #![deny(unused_attributes)]
1111
| ^^^^^^^^^^^^^^^^^
1212

13+
error: `#[inline]` is ignored on function prototypes
14+
--> $DIR/warn-unused-inline-on-fn-prototypes.rs:4:5
15+
|
16+
LL | #[inline]
17+
| ^^^^^^^^^
18+
1319
error: aborting due to 2 previous errors
1420

0 commit comments

Comments
 (0)