Skip to content

Commit 163780e

Browse files
committed
Solves #3222 by checking the BareFnTy Abi type
1 parent eb2cfe6 commit 163780e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clippy_lints/src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::borrow::Cow;
1616
use crate::syntax::ast::{FloatTy, IntTy, UintTy};
1717
use crate::syntax::source_map::Span;
1818
use crate::syntax::errors::DiagnosticBuilder;
19+
use crate::rustc_target::spec::abi::Abi;
1920
use crate::utils::{comparisons, differing_macro_contexts, higher, in_constant, in_macro, last_path_segment, match_def_path, match_path,
2021
match_type, multispan_sugg, opt_def_id, same_tys, snippet, snippet_opt, span_help_and_lint, span_lint,
2122
span_lint_and_sugg, span_lint_and_then, clip, unsext, sext, int_bits};
@@ -1224,7 +1225,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
12241225
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Tup(..) | TyKind::Array(..) => (10 * self.nest, 1),
12251226

12261227
// function types bring a lot of overhead
1227-
TyKind::BareFn(..) => (50 * self.nest, 1),
1228+
TyKind::BareFn(ref bare) if bare.abi == Abi::Rust => (50 * self.nest, 1),
12281229

12291230
TyKind::TraitObject(ref param_bounds, _) => {
12301231
let has_lifetime_parameters = param_bounds

tests/ui/complex_types.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,22 @@ fn test3() {
4040
let _y: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![];
4141
}
4242

43+
#[repr(C)]
44+
struct D {
45+
// should not warn, since we don't have control over the signature (#3222)
46+
test4: extern "C" fn(
47+
itself: &D,
48+
a: usize,
49+
b: usize,
50+
c: usize,
51+
d: usize,
52+
e: usize,
53+
f: usize,
54+
g: usize,
55+
h: usize,
56+
i: usize,
57+
),
58+
}
59+
4360
fn main() {
4461
}

0 commit comments

Comments
 (0)