extern fns often need to adhere to a specific api -> don't suggest api-changes

This commit is contained in:
Oliver Schneider 2016-08-08 17:21:47 +02:00
parent ac5abcf593
commit 331afc3246
No known key found for this signature in database
GPG Key ID: 56D6EEA0FC67AC46
2 changed files with 14 additions and 2 deletions

View File

@ -4,6 +4,7 @@ use rustc::ty;
use rustc::lint::*;
use std::collections::HashSet;
use syntax::ast;
use syntax::abi::Abi;
use syntax::codemap::Span;
use utils::{span_lint, type_is_unsafe_function};
@ -85,7 +86,12 @@ impl LateLintPass for Functions {
// don't warn for implementations, it's not their fault
if !is_impl {
self.check_arg_number(cx, decl, span);
// don't lint extern functions decls, it's not their fault either
match kind {
hir::intravisit::FnKind::Method(_, &hir::MethodSig { abi: Abi::Rust, .. }, _, _) |
hir::intravisit::FnKind::ItemFn(_, _, _, _, Abi::Rust, _, _) => self.check_arg_number(cx, decl, span),
_ => {},
}
}
self.check_raw_ptr(cx, unsafety, decl, block, nodeid);
@ -93,7 +99,10 @@ impl LateLintPass for Functions {
fn check_trait_item(&mut self, cx: &LateContext, item: &hir::TraitItem) {
if let hir::MethodTraitItem(ref sig, ref block) = item.node {
self.check_arg_number(cx, &sig.decl, item.span);
// don't lint extern functions decls, it's not their fault
if sig.abi == Abi::Rust {
self.check_arg_number(cx, &sig.decl, item.span);
}
if let Some(ref block) = *block {
self.check_raw_ptr(cx, sig.unsafety, &sig.decl, block, item.id);

View File

@ -12,6 +12,9 @@ fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _
//~^ ERROR: this function has too many arguments (8/7)
}
// don't lint extern fns
extern fn extern_fn(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
pub trait Foo {
fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool);
fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ());