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

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

Closed
Thinkofname opened this Issue May 21, 2018 · 5 comments

Comments

Projects
None yet
7 participants
@Thinkofname
Copy link

Thinkofname commented May 21, 2018

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.

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented May 21, 2018

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.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented May 21, 2018

E0632 seems to be ignoring functions in an impl methods.

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

@Restioson

This comment has been minimized.

Copy link

Restioson commented May 21, 2018

Yeah, this is a plus, actually.

@oli-obk oli-obk added the I-nominated label May 21, 2018

@scottmcm

This comment has been minimized.

Copy link
Member

scottmcm commented May 22, 2018

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

@nikomatsakis nikomatsakis added P-high and removed I-nominated labels May 24, 2018

@nikomatsakis nikomatsakis 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 May 24, 2018

@nikomatsakis nikomatsakis self-assigned this May 24, 2018

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 25, 2018

@scottmcm

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

certainly =)

bors added a commit that referenced this issue May 25, 2018

Auto merge of #51051 - nikomatsakis:turbofish-impl-trait-method, r=eddyb
prohibit turbofish in `impl Trait` methods

Fix #50950

@bors bors closed this in #51051 May 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment