Skip to content

Able to use the turbofish syntax with impl trait for methods #50950

Closed

Description

@Thinkofname

In some cases it seems like you are able to use the turbofish syntax with impl Trait

use std::any::Any;
pub struct EventHandler {
}

impl EventHandler
{
    pub fn handle_event<T: Any>(&mut self, _efunc: impl FnMut(T)) {}
}

struct TestEvent(i32);

fn main() {
    let mut evt = EventHandler {};
    evt.handle_event::<TestEvent, fn(TestEvent)>(|_evt| {
    });
}

playground: http://play.rust-lang.org/?gist=62b8c9d317dd6f149354555ca42d45b3&version=stable&mode=debug

This should fail with error[E0632]: cannot provide explicit type parameters when `impl Trait` is used in argument position.

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    C-bugCategory: This is a bug.
    on May 21, 2018
  2. kennytm commented on May 21, 2018

    @kennytm
    Member

    Note that the <T: Any> is irrelevant. E0632 seems to be ignoring functions in an impl methods.

    struct X;
    impl X {
        fn g(&self, _: impl Send) {}
    }
    fn main() {
        X.g::<u64>(0);
    }

    Edit: Calling with fully-qualified syntax X::g::<u64>(&X, 0) will trigger E0632.

  3. petrochenkov commented on May 21, 2018

    @petrochenkov
    Contributor

    E0632 seems to be ignoring functions in an impl methods.

    This is great.
    Now it remains to make it ignore non-methods.

  4. Restioson commented on May 21, 2018

    @Restioson

    Yeah, this is a plus, actually.

  5. scottmcm commented on May 22, 2018

    @scottmcm
    Member

    Hmm, is this one of the things that would be covered by rust-lang/rfcs#2405?

  6. changed the title [-]Able to use the turbofish syntax with impl trait in some cases[/-] [+]Able to use the turbofish syntax with impl trait for methods[/+] on May 24, 2018
  7. self-assigned this
    on May 24, 2018
  8. nikomatsakis commented on May 25, 2018

    @nikomatsakis
    Contributor

    @scottmcm

    Hmm, is this one of the things that would be covered by rust-lang/rfcs#2405?

    certainly =)

  9. added a commit that references this issue on May 25, 2018
    9823cb9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions