New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl_trait_in_params
now supports impls and traits
#11550
impl_trait_in_params
now supports impls and traits
#11550
Conversation
r? @dswij (rustbot has picked a reviewer for you, use r? to override) |
Thanks! I recommend adding a test for trait implementations -- I believe this lint should not warn for trait implementations because traits may be defined in the upstream crate, and the user who implements them may be unable to change them. |
tests/ui/impl_trait_in_params.rs
Outdated
// Trying with imported traits | ||
impl ToString for S { | ||
fn to_string(&self) -> String { | ||
String::from("a") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lint warns for impl trait in parameters, so I think we also need to test for a case where parameters include impl trait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh what a brain melt. I really didn't notice that 🐱
f5860aa
to
8eccfc2
Compare
struct S; | ||
impl S { | ||
pub fn h(_: impl Trait) {} //~ ERROR: `impl Trait` used as a function parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lint is for public APIs, so I think it would be preferable to warn only of cases where both the type and the associated function are pub
.
I just noticed the failing CI, I'll get to work on it right now 🐈 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for this!
@blyxyas can you squash some commits? And then you can r=me |
@@ -0,0 +1,41 @@ | |||
error: trait `Trait` is more private than the item `Public::t` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error seems unrelated to what we want to test here. I guess you have to make Trait
trait public.
2c15981
to
689c46f
Compare
689c46f
to
7755737
Compare
Wow I really fucked up the Git history for a couple minutes (like, adding 21 commits, 2K lines changed that aren't mine). |
@bors r=dswij |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
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 supportsimpl
blocks and functions in traits