Skip to content

Tracking issue for explicit_generic_args_with_impl_trait #83701

Closed

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

Activity

  1. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    on Mar 31, 2021
  2. added
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    T-langRelevant to the language team
    and removed
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Mar 31, 2021
  3. alexxbb commented on Jun 8, 2021

    @alexxbb

    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:

    impl Parameter {
        pub fn set<T: ParmType>(&self, value: impl AsRef<[<T as ParmType>::Type]>) -> Result<()> {
            T::set(self.node, &self.info, value)
        }
    }
    
    // 
    let parm: Parameter;
    parm.set::<i32>([1,2,3]);
  4. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    and removed
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    on Aug 2, 2021
  5. changed the title [-]Allow callers of `impl Trait` functions to specify explicit generic arguments.[/-] [+]Tracking issue for `explicit_generic_args_with_impl_trait`[/+] on Aug 2, 2021
  6. added a commit that references this issue on Aug 2, 2021
  7. jhpratt commented on Sep 2, 2021

    @jhpratt
    Member

    With the only unresolved question listed being diagnostics, is there anything holding up stabilization? Other than a stabilization report of course.

  8. nbdd0121 commented on Sep 2, 2021

    @nbdd0121
    Member

    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.

  9. jhpratt commented on Sep 2, 2021

    @jhpratt
    Member

    FCP was a given. Time-wise makes sense, though.

  10. XAMPPRocky commented on Sep 2, 2021

    @XAMPPRocky
    ContributorAuthor

    @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. 🙂

  11. 52 remaining items

  12. joshtriplett commented on Jul 20, 2022

    @joshtriplett
    Member

    This will stabilize in 1.63, closing.

  13. Xiretza commented on Jul 20, 2022

    @Xiretza
    Contributor

    Can someone link #96868 in the issue description?

  14. added a commit that references this issue on Sep 16, 2022
  15. added a commit that references this issue on Oct 5, 2022
  16. added a commit that references this issue on Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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 teamdisposition-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