What is wrong with my expectations?
macro_rules! dup
{
( $T : ty ) =>
{
$T, $T,
};
}
fn main()
{
let got : ( dup!( i32 ) ) = ( 1, 1 );
// let got : ( i32, i32, ) = ( 1, 1 );
let exp : ( i32, i32 ) = ( 1, 1 );
assert_eq!( got, exp );
}
Error:
error: macro expansion ignores token `,` and any following
--> src/main.rs:5:7
|
5 | $T, $T,
| ^
...
12 | let got : ( dup!( i32 ) ) = ( 1, 1 );
| ----------- caused by the macro expansion here
|
= note: the usage of `dup!` is likely invalid in type context
warning: unnecessary parentheses around type
--> src/main.rs:12:13
|
12 | let got : ( dup!( i32 ) ) = ( 1, 1 );
| ^^^^^^^^^^^^^^^ help: remove these parentheses
|
= note: `#[warn(unused_parens)]` on by default
error[E0308]: mismatched types
--> src/main.rs:12:31
|
12 | let got : ( dup!( i32 ) ) = ( 1, 1 );
| --- ^^^^^^^^ expected `i32`, found tuple
| |
| expected due to this
|
= note: expected type `i32`
found tuple `({integer}, {integer})`
error[E0308]: mismatched types
--> src/main.rs:15:3
|
15 | assert_eq!( got, exp );
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found tuple
|
= note: expected type `i32`
found tuple `(i32, i32)`
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)