Repository navigation
Tracking issue for explicit_generic_args_with_impl_trait #83701
Description
This is a tracking issue for the explicit_generic_args_with_impl_trait feature gate.
There has not been an RFC for this.
Steps
- Implement (Implement a
explicit_generic_args_with_impl_traitfeature gate #86176) - Adjust documentation (Add a note to the turbofish section about impl Trait reference#1212) (see instructions on rustc-dev-guide)
- Stabilization PR (Stabilize explicit_generic_args_with_impl_trait #96868) (see instructions on rustc-dev-guide)
Unresolved Questions
We should add a bit extra info when there are extra generic args andimpl Trait(see Implement aexplicit_generic_args_with_impl_traitfeature gate #86176 (comment))
Implementation history
- Initital implementation in Implement a
explicit_generic_args_with_impl_traitfeature gate #86176
Background
Currently you cannot specify explicit generic arguments if a function uses impl Trait anywhere its arguments. This is pretty annoying because it heavily restricts what kind of code you can write with functions that use impl Trait compared to what is possible with explicit generics.
This difference between impl Trait and explicit is in my opinion very unintuitive, it feels like you should be able to use them together. It is even mentioned as something in the original tracking issue for impl Trait (#44721) that this would be desirable behaviour, but that there was a decision to hold off for the time being. That issue has been closed for long time, and there hasn't been any follow up as far as I can tell. So I'm opening up a new issue to discuss the feature and hopefully track adding it to the rust compiler.
Examples
#![feature(explicit_generic_args_with_impl_trait)]
fn find_from<I>(iter: impl IntoIterator<Item=impl Into<I>>, is_match: impl Fn(&I) -> bool) -> Option<I> {
for i in iter {
let i = i.into();
if (is_match)(&i) {
return Some(i)
}
}
None
}
fn main () {
matches!(find_from::<u32>(vec![2u8, 3, 4, 5,], |&x| x == 5), Some(5u32));
}
Activity
alexxbb commentedon Jun 8, 2021
It's unfortunate that it's not possible, I just hit this issue and it stops me from having a nice API. Here's my use case:
[-]Allow callers of `impl Trait` functions to specify explicit generic arguments.[/-][+]Tracking issue for `explicit_generic_args_with_impl_trait`[/+]Rollup merge of rust-lang#86176 - nbdd0121:explicit-generic-args, r=j…
jhpratt commentedon Sep 2, 2021
With the only unresolved question listed being diagnostics, is there anything holding up stabilization? Other than a stabilization report of course.
nbdd0121 commentedon Sep 2, 2021
It's still too recent. I only implemented this in June (and merged in August), and I doubt it has been widely used or tested in the ecosystem. This also needs a lang team FCP or RFC.
jhpratt commentedon Sep 2, 2021
FCP was a given. Time-wise makes sense, though.
XAMPPRocky commentedon Sep 2, 2021
@nbdd0121 Thanks for implementing this! I've updated the example to use the new feature so there's now at least one use in the wild. 🙂
52 remaining items
joshtriplett commentedon Jul 20, 2022
This will stabilize in 1.63, closing.
Xiretza commentedon Jul 20, 2022
Can someone link #96868 in the issue description?
Remove an outdated workaround for `impl Trait` (#5659)
Remove an outdated workaround for `impl Trait` (#5659)
change impl FnOnce() to generic type + trait bound (paritytech#11534)
Check Rust version in cargo
Check Rust version in cargo
Check Rust version in cargo
Remove an outdated workaround for `impl Trait` (bevyengine#5659)
Feature/add pallet ibc (#79)
Remove an outdated workaround for `impl Trait` (bevyengine#5659)
Remove an outdated workaround for `impl Trait` (bevyengine#5659)
change impl FnOnce() to generic type + trait bound (paritytech#11534)
Bump MSRV to 1.63.0