-
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.
Auto merge of #11550 - blyxyas:fix-impl_trait_in_params-for_assocfn, …
…r=dswij `impl_trait_in_params` now supports impls and traits Before this PR, the lint `impl_trait_in_params`. This PR gives the lint support for functions in impls and traits. (Also, some pretty heavy refactor) fixes #11548 changelog:[`impl_trait_in_params`] now supports `impl` blocks and functions in traits
- Loading branch information
Showing
8 changed files
with
190 additions
and
45 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 = false |
16 changes: 16 additions & 0 deletions
16
tests/ui-toml/impl_trait_in_params/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,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); | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/ui-toml/impl_trait_in_params/impl_trait_in_params.stderr
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,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 | ||
|
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,47 @@ | ||
#![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 | ||
|
||
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) {} | ||
} | ||
|
||
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 Public 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