2023-01-09 17:18:24 -06:00
|
|
|
#![allow(unused)]
|
2023-01-13 05:17:30 -06:00
|
|
|
#![warn(clippy::impl_trait_in_params)]
|
2023-09-21 15:37:32 -05:00
|
|
|
|
2023-07-27 06:40:22 -05:00
|
|
|
//@no-rustfix
|
2023-01-09 17:18:24 -06:00
|
|
|
pub trait Trait {}
|
2023-01-13 05:54:51 -06:00
|
|
|
pub trait AnotherTrait<T> {}
|
2023-01-09 17:18:24 -06:00
|
|
|
|
|
|
|
// Should warn
|
|
|
|
pub fn a(_: impl Trait) {}
|
2023-09-21 15:37:32 -05:00
|
|
|
//~^ ERROR: `impl Trait` used as a function parameter
|
2023-01-09 17:18:24 -06:00
|
|
|
pub fn c<C: Trait>(_: C, _: impl Trait) {}
|
2023-09-21 15:37:32 -05:00
|
|
|
//~^ ERROR: `impl Trait` used as a function parameter
|
2023-01-09 17:18:24 -06:00
|
|
|
|
|
|
|
// Shouldn't warn
|
|
|
|
|
|
|
|
pub fn b<B: Trait>(_: B) {}
|
2023-01-13 05:54:51 -06:00
|
|
|
fn e<T: AnotherTrait<u32>>(_: T) {}
|
2023-09-21 15:37:32 -05:00
|
|
|
fn d(_: impl AnotherTrait<u32>) {}
|
|
|
|
|
|
|
|
//------ IMPLS
|
|
|
|
|
2023-09-23 13:36:06 -05:00
|
|
|
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
|
2023-09-21 15:37:32 -05:00
|
|
|
fn t(_: impl Trait);
|
|
|
|
fn tt<T: Trait>(_: T) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S;
|
|
|
|
impl S {
|
|
|
|
pub fn h(_: impl Trait) {} //~ ERROR: `impl Trait` used as a function parameter
|
|
|
|
fn i(_: impl Trait) {}
|
|
|
|
pub fn j<J: Trait>(_: J) {}
|
|
|
|
pub fn k<K: AnotherTrait<u32>>(_: K, _: impl AnotherTrait<u32>) {} //~ ERROR: `impl Trait` used as a function parameter
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trying with traits
|
2023-09-23 13:36:06 -05:00
|
|
|
impl Public for S {
|
2023-09-21 15:37:32 -05:00
|
|
|
fn t(_: impl Trait) {}
|
|
|
|
}
|
2023-01-09 17:18:24 -06:00
|
|
|
|
|
|
|
fn main() {}
|