Closed
Description
When calling an associated function on a struct, type macros behave very strange and produce weird error messages.
Example on playground
struct S<T>(PhantomData<T>);
impl<T> S<T> {
fn associated_function() {}
}
macro_rules! TypeMacro {
($x:ty) => { S<$x> };
}
fn main() {
// compare the error mesages:
// error: expected one of `.`, `;`, `?`, or an operator, found `::`
let _ = TypeMacro!(u8)::associated_function();
// error: chained comparison operators require parentheses
let _ = S<u8>::associated_function();
// conclusion:
// TypeMacro!(u8) is not the same S<u8>
// this works
let _ = <S<u8>>::associated_function();
let _ = S::<u8>::associated_function();
let _ = <TypeMacro!(u8)>::associated_function();
}
Naturally, one would expect that TypeMacro!(u8)
is the same as S<u8>
because it is defined that way.
The result is the same on all rust versions currently in playground