Closed
Description
I kinda hoped that snippet below will be compiled:
#![feature(const_generics)]
use std::ops::Add;
struct VectorLike<T, const SIZE: usize>([T; {SIZE}]);
macro_rules! impl_operator_overload {
($trait_ident:ident, $method_ident:ident) => {
impl<T, const SIZE: usize> $trait_ident for VectorLike<T, {SIZE}>
where
T: $trait_ident,
{
type Output = VectorLike<T, {SIZE}>;
fn $method_ident(self, _: VectorLike<T, {SIZE}>) -> VectorLike<T, {SIZE}> {
unimplemented!()
}
}
}
}
impl_operator_overload!(Add, add);
Instead I got a bunch of errors like
error[E0425]: cannot find value `SIZE` in this scope
for SIZE
in every occurrence of {SIZE}
inside macro body, and one
the const parameter `SIZE` is not constrained by the impl trait, self type, or predicates
for SIZE
in impl<T, const SIZE: usize>
.
Unlike snippet with "const variable" above, this one with "const value" compiles without any
issues:
#![feature(const_generics)]
use std::ops::Add;
struct VectorLike<T, const SIZE: usize>([T; {SIZE}]);
macro_rules! impl_operator_overload {
($trait_ident:ident, $method_ident:ident) => {
impl<T> $trait_ident for VectorLike<T, 3>
where
T: $trait_ident,
{
type Output = VectorLike<T, 3>;
fn $method_ident(self, _: VectorLike<T, 3>) -> VectorLike<T, 3> {
unimplemented!()
}
}
}
}
impl_operator_overload!(Add, add);
This issue seems to be related to #58307.
Rustc version: 1.37.0-nightly (2019-06-04 5d8f59f4b1473217c2de)
.