Fix tests, only lint for public tests
This commit is contained in:
parent
5ed338dff9
commit
775573768e
@ -6,7 +6,7 @@
|
||||
use rustc_hir::{Body, GenericParam, Generics, HirId, ImplItem, ImplItemKind, TraitItem, TraitItemKind};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{BytePos, Span};
|
||||
|
||||
use super::IMPL_TRAIT_IN_PARAMS;
|
||||
|
||||
@ -89,12 +89,16 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) {
|
||||
pub(super) fn check_trait_item(cx: &LateContext<'_>, trait_item: &TraitItem<'_>, avoid_breaking_exported_api: bool) {
|
||||
if_chain! {
|
||||
if !avoid_breaking_exported_api;
|
||||
if let TraitItemKind::Fn(sig, _) = trait_item.kind;
|
||||
if let TraitItemKind::Fn(_, _) = trait_item.kind;
|
||||
if let hir::Node::Item(item) = cx.tcx.hir().get_parent(trait_item.hir_id());
|
||||
// ^^ (Will always be a trait)
|
||||
if !item.vis_span.is_empty(); // Is public
|
||||
if !is_in_test_function(cx.tcx, trait_item.hir_id());
|
||||
then {
|
||||
for param in trait_item.generics.params {
|
||||
if param.is_impl_trait() {
|
||||
report(cx, param, &trait_item.ident, trait_item.generics, sig.decl.inputs[0].span);
|
||||
let sp = trait_item.ident.span.with_hi(trait_item.ident.span.hi() + BytePos(1));
|
||||
report(cx, param, &trait_item.ident, trait_item.generics, sp.shrink_to_hi());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
tests/ui-toml/impl_trait_in_params/clippy.toml
Normal file
1
tests/ui-toml/impl_trait_in_params/clippy.toml
Normal file
@ -0,0 +1 @@
|
||||
avoid-breaking-exported-api = false
|
16
tests/ui-toml/impl_trait_in_params/impl_trait_in_params.rs
Normal file
16
tests/ui-toml/impl_trait_in_params/impl_trait_in_params.rs
Normal file
@ -0,0 +1,16 @@
|
||||
//! As avoid-breaking-exported-api is `false`, nothing here should lint
|
||||
#![warn(clippy::impl_trait_in_params)]
|
||||
#![no_main]
|
||||
//@no-rustfix
|
||||
|
||||
pub trait Trait {}
|
||||
|
||||
trait Private {
|
||||
fn t(_: impl Trait);
|
||||
fn tt<T: Trait>(_: T);
|
||||
}
|
||||
|
||||
pub trait Public {
|
||||
fn t(_: impl Trait); //~ ERROR: `impl Trait` used as a function parameter
|
||||
fn tt<T: Trait>(_: T);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
error: `impl Trait` used as a function parameter
|
||||
--> $DIR/impl_trait_in_params.rs:14:13
|
||||
|
|
||||
LL | fn t(_: impl Trait);
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::impl-trait-in-params` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::impl_trait_in_params)]`
|
||||
help: add a type parameter
|
||||
|
|
||||
LL | fn t<{ /* Generic name */ }: Trait>(_: impl Trait);
|
||||
| +++++++++++++++++++++++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -1 +0,0 @@
|
||||
avoid-breaking-exported-api = true
|
@ -1,10 +0,0 @@
|
||||
//! As avoid-breaking-exported-api is `true`, nothing here should lint
|
||||
#![warn(clippy::impl_trait_in_params)]
|
||||
#![no_main]
|
||||
|
||||
trait Trait {}
|
||||
|
||||
trait T {
|
||||
fn t(_: impl Trait);
|
||||
fn tt<T: Trait>(_: T);
|
||||
}
|
@ -19,8 +19,14 @@ fn d(_: impl AnotherTrait<u32>) {}
|
||||
|
||||
//------ IMPLS
|
||||
|
||||
trait T {
|
||||
// See test in ui-toml for a case where avoid-breaking-exported-api is set to true
|
||||
pub trait Public {
|
||||
// See test in ui-toml for a case where avoid-breaking-exported-api is set to false
|
||||
fn t(_: impl Trait);
|
||||
fn tt<T: Trait>(_: T) {}
|
||||
}
|
||||
|
||||
trait Private {
|
||||
// This shouldn't lint
|
||||
fn t(_: impl Trait);
|
||||
fn tt<T: Trait>(_: T) {}
|
||||
}
|
||||
@ -34,7 +40,7 @@ pub fn k<K: AnotherTrait<u32>>(_: K, _: impl AnotherTrait<u32>) {} //~ ERROR: `i
|
||||
}
|
||||
|
||||
// Trying with traits
|
||||
impl T for S {
|
||||
impl Public for S {
|
||||
fn t(_: impl Trait) {}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ LL | pub fn c<C: Trait, { /* Generic name */ }: Trait>(_: C, _: impl Trait) {}
|
||||
| +++++++++++++++++++++++++++++++
|
||||
|
||||
error: `impl Trait` used as a function parameter
|
||||
--> $DIR/impl_trait_in_params.rs:30:17
|
||||
--> $DIR/impl_trait_in_params.rs:36:17
|
||||
|
|
||||
LL | pub fn h(_: impl Trait) {}
|
||||
| ^^^^^^^^^^
|
||||
@ -34,7 +34,7 @@ LL | pub fn h<{ /* Generic name */ }: Trait>(_: impl Trait) {}
|
||||
| +++++++++++++++++++++++++++++++
|
||||
|
||||
error: `impl Trait` used as a function parameter
|
||||
--> $DIR/impl_trait_in_params.rs:33:45
|
||||
--> $DIR/impl_trait_in_params.rs:39:45
|
||||
|
|
||||
LL | pub fn k<K: AnotherTrait<u32>>(_: K, _: impl AnotherTrait<u32>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
Loading…
Reference in New Issue
Block a user