Skip to content
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

'Cannot find value in this scope' on macro expansion with generic over const impl block inside. #61574

Closed
L117 opened this issue Jun 6, 2019 · 1 comment · Fixed by #63083
Labels
A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name resolution C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@L117
Copy link
Contributor

L117 commented Jun 6, 2019

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>.

Playground permalink

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).

@L117 L117 changed the title 'Cannot find value in this scope' on macro expansion with generic over const impl block inside.. 'Cannot find value in this scope' on macro expansion with generic over const impl block inside. Jun 6, 2019
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name resolution C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 6, 2019
@c410-f3r
Copy link
Contributor

Minimal code:

macro_rules! some_macro {
    ($struct_name:ident) => {
        struct $struct_name<const N: usize>([usize; N]);
    }
}
some_macro!(Foo);

Centril added a commit to Centril/rust that referenced this issue Jul 29, 2019
…petrochenkov

Make generic parameters always use modern hygiene

* E0263 (lifetime parameter declared twice in the same scope) now compares modernized identifiers.
* Const parameters are now resolved with modern hygiene.

Closes rust-lang#58307
Closes rust-lang#60746
Closes rust-lang#61574
Closes rust-lang#62433
Centril added a commit to Centril/rust that referenced this issue Jul 30, 2019
…petrochenkov

Make generic parameters always use modern hygiene

* E0263 (lifetime parameter declared twice in the same scope) now compares modernized identifiers.
* Const parameters are now resolved with modern hygiene.

Closes rust-lang#58307
Closes rust-lang#60746
Closes rust-lang#61574
Closes rust-lang#62433
Centril added a commit to Centril/rust that referenced this issue Jul 30, 2019
…petrochenkov

Make generic parameters always use modern hygiene

* E0263 (lifetime parameter declared twice in the same scope) now compares modernized identifiers.
* Const parameters are now resolved with modern hygiene.

Closes rust-lang#58307
Closes rust-lang#60746
Closes rust-lang#61574
Closes rust-lang#62433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-resolve Area: Name resolution C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants