Skip to content

Commit 610615b

Browse files
authored
Merge pull request #1153 from oli-obk/too_many_extern_fn_args
extern fns often need to adhere to a specific api -> don't suggest api changes
2 parents ac5abcf + 331afc3 commit 610615b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clippy_lints/src/functions.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc::ty;
44
use rustc::lint::*;
55
use std::collections::HashSet;
66
use syntax::ast;
7+
use syntax::abi::Abi;
78
use syntax::codemap::Span;
89
use utils::{span_lint, type_is_unsafe_function};
910

@@ -85,15 +86,23 @@ impl LateLintPass for Functions {
8586

8687
// don't warn for implementations, it's not their fault
8788
if !is_impl {
88-
self.check_arg_number(cx, decl, span);
89+
// don't lint extern functions decls, it's not their fault either
90+
match kind {
91+
hir::intravisit::FnKind::Method(_, &hir::MethodSig { abi: Abi::Rust, .. }, _, _) |
92+
hir::intravisit::FnKind::ItemFn(_, _, _, _, Abi::Rust, _, _) => self.check_arg_number(cx, decl, span),
93+
_ => {},
94+
}
8995
}
9096

9197
self.check_raw_ptr(cx, unsafety, decl, block, nodeid);
9298
}
9399

94100
fn check_trait_item(&mut self, cx: &LateContext, item: &hir::TraitItem) {
95101
if let hir::MethodTraitItem(ref sig, ref block) = item.node {
96-
self.check_arg_number(cx, &sig.decl, item.span);
102+
// don't lint extern functions decls, it's not their fault
103+
if sig.abi == Abi::Rust {
104+
self.check_arg_number(cx, &sig.decl, item.span);
105+
}
97106

98107
if let Some(ref block) = *block {
99108
self.check_raw_ptr(cx, sig.unsafety, &sig.decl, block, item.id);

tests/compile-fail/functions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _
1212
//~^ ERROR: this function has too many arguments (8/7)
1313
}
1414

15+
// don't lint extern fns
16+
extern fn extern_fn(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
17+
1518
pub trait Foo {
1619
fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool);
1720
fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ());

0 commit comments

Comments
 (0)