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

Add utils helper for filtering out type/lifetime parameters on generics #3787

Open
Manishearth opened this issue Feb 19, 2019 · 4 comments
Open
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@Manishearth
Copy link
Member

See https://github.com/rust-lang/rust-clippy/pull/3786/files , we have a lot of code that does something like params.args.iter().filter_map(|arg| match arg { GenericArg::Lifetime(lt) => Some(lt), _ => None }

We should probably have a helper function that returns an iterator for these, placed in utils. Probably something like:

fn types_of_generics(generics: &Generics) -> impl Iterator<Type> {...}
fn lifetimes_of_generics(generics: &Generics) -> impl Iterator<Lifetime> {...}
@Manishearth Manishearth added good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Feb 19, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Feb 19, 2019

lol you read my mind. I was gonna add this to rustc directly, because they probably have the same problems. I think we can add this directly on the Generics type as a method. There's precedent for the Substs<'tcx> type.

@Manishearth
Copy link
Member Author

IIRC this used to exist on Generics anyway, but got removed at some point. I recall doing a rustup where we added a bunch of these matches. But sure, adding this to rustc would be great, I'm sure it has a similar pattern.

@flip1995
Copy link
Member

I'm in favor of implementing such a function in rustc:

// FIXME(flip1995): messy, improve if there is a better option
// in the compiler
let types: Vec<_> = params
.args
.iter()
.filter_map(|arg| match arg {
hir::GenericArg::Type(ty) => Some(ty),
_ => None,
})
.collect();

Git blame me: #2871

I'll open a PR in rustc in the next few days for these iterators.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

No branches or pull requests

4 participants