1 use clippy_utils
::{diagnostics::span_lint_and_then, is_in_test_function}
;
3 use rustc_hir
::{intravisit::FnKind, Body, HirId}
;
4 use rustc_lint
::LateContext
;
7 use super::IMPL_TRAIT_IN_PARAMS
;
9 pub(super) fn check_fn
<'tcx
>(cx
: &LateContext
<'_
>, kind
: &'tcx FnKind
<'_
>, body
: &'tcx Body
<'_
>, hir_id
: HirId
) {
10 if cx
.tcx
.visibility(cx
.tcx
.hir().body_owner_def_id(body
.id())).is_public() && !is_in_test_function(cx
.tcx
, hir_id
)
12 if let FnKind
::ItemFn(ident
, generics
, _
) = kind
{
13 for param
in generics
.params
{
14 if param
.is_impl_trait() {
15 // No generics with nested generics, and no generics like FnMut(x)
20 "'`impl Trait` used as a function parameter'",
22 if let Some(gen_span
) = generics
.span_for_param_suggestion() {
23 diag
.span_suggestion_with_style(
25 "add a type paremeter",
26 format
!(", {{ /* Generic name */ }}: {}", ¶m
.name
.ident().as_str()[5..]),
27 rustc_errors
::Applicability
::HasPlaceholders
,
28 rustc_errors
::SuggestionStyle
::ShowAlways
,
31 diag
.span_suggestion_with_style(
33 body
.params
[0].span
.lo() - rustc_span
::BytePos(1),
38 "add a type paremeter",
39 format
!("<{{ /* Generic name */ }}: {}>", ¶m
.name
.ident().as_str()[5..]),
40 rustc_errors
::Applicability
::HasPlaceholders
,
41 rustc_errors
::SuggestionStyle
::ShowAlways
,