Skip to content

Tracking issue for explicit_generic_args_with_impl_trait #83701

Closed
@XAMPPRocky

Description

@XAMPPRocky

This is a tracking issue for the explicit_generic_args_with_impl_trait feature gate.
There has not been an RFC for this.

Steps

Unresolved Questions

Implementation history


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));
}

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions