-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
impl_trait_in_params
now supports impls and traits
- Loading branch information
Showing
7 changed files
with
158 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
avoid-breaking-exported-api = true |
10 changes: 10 additions & 0 deletions
10
tests/ui-toml/impl_trait_in_params/true/impl_trait_in_params.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//! 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,41 @@ | ||
#![allow(unused)] | ||
#![warn(clippy::impl_trait_in_params)] | ||
|
||
//@no-rustfix | ||
pub trait Trait {} | ||
pub trait AnotherTrait<T> {} | ||
|
||
// Should warn | ||
pub fn a(_: impl Trait) {} | ||
//~^ ERROR: '`impl Trait` used as a function parameter' | ||
//~| NOTE: `-D clippy::impl-trait-in-params` implied by `-D warnings` | ||
//~^ ERROR: `impl Trait` used as a function parameter | ||
pub fn c<C: Trait>(_: C, _: impl Trait) {} | ||
//~^ ERROR: '`impl Trait` used as a function parameter' | ||
fn d(_: impl AnotherTrait<u32>) {} | ||
//~^ ERROR: `impl Trait` used as a function parameter | ||
|
||
// Shouldn't warn | ||
|
||
pub fn b<B: Trait>(_: B) {} | ||
fn e<T: AnotherTrait<u32>>(_: T) {} | ||
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 | ||
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 | ||
impl T for S { | ||
fn t(_: impl Trait) {} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters