Skip to content
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

Lint to ban impl Trait in parameters #10030

Closed
SUPERCILEX opened this issue Dec 4, 2022 · 4 comments · Fixed by #10197
Closed

Lint to ban impl Trait in parameters #10030

SUPERCILEX opened this issue Dec 4, 2022 · 4 comments · Fixed by #10197
Assignees
Labels
A-lint Area: New lints

Comments

@SUPERCILEX
Copy link

SUPERCILEX commented Dec 4, 2022

Advantage

You can't use the turbofish with parameter impls which makes it strictly less powerful as far as I can tell. This lint should only apply to public items.

Name: impl_trait_in_param_of_pub_fn.

Category

style (or potentially pedantic)

Example

fn foo(t: impl Trait) {}

Could be written as:

fn foo<T: Trait>(t: T) {}
@SUPERCILEX SUPERCILEX added the A-lint Area: New lints label Dec 4, 2022
@blyxyas
Copy link
Member

blyxyas commented Jan 6, 2023

@rustbot claim

@blyxyas
Copy link
Member

blyxyas commented Jan 6, 2023

Just to be clear, when you refer to you can't use the turbofish with parameter impl, can you put an example?

@SUPERCILEX
Copy link
Author

Sure:

trait A {}

impl A for u32 {}
impl A for u64 {}

fn foo_impl(_a: impl A) {}
fn foo_turbo<AA: A>(_a: AA) {}

fn do_stuff() {
    // foo_impl(0); // Doesn't compile
    // foo_impl::<u32>(0); // Doesn't compile
    foo_impl(0 as u32);
    foo_turbo(0 as u32);
    foo_turbo::<u32>(0);
}

It gets more annoying when people use Option<impl Something> because then when you want to pass in None you have to say None::<Blah> which looks weird IMO. I guess those are both turbofish, so to be more precise I mean turbofish in the function generic position.

@SUPERCILEX
Copy link
Author

Woohoo, thanks!

PS: 5ef3cc8#r101419032

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants