Rust: Able to use the turbofish syntax with impl trait for methods

Created on 21 May 2018  路  5Comments  路  Source: rust-lang/rust

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.

A-impl-trait C-bug P-high T-compiler

Most helpful comment

E0632 seems to be ignoring functions in an impl methods.

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

All 5 comments

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.

E0632 seems to be ignoring functions in an impl methods.

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

Yeah, this is a plus, actually.

Hmm, is this one of the things that would be covered by https://github.com/rust-lang/rfcs/pull/2405?

@scottmcm

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

certainly =)

Was this page helpful?
0 / 5 - 0 ratings