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

Const generic in macros_rules unable to be found in function scope #60746

Closed
memoryruins opened this issue May 11, 2019 · 2 comments · Fixed by #63083
Closed

Const generic in macros_rules unable to be found in function scope #60746

memoryruins opened this issue May 11, 2019 · 2 comments · Fixed by #63083
Labels
A-const-generics Area: const generics (parameters and arguments) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@memoryruins
Copy link
Contributor

nightly 2019-05-10 d595b113584f8f446957

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=8ed8182c5ced88e5436ba074014283c1

#![feature(const_generics)]

macro_rules! compile {
    ($t:ty; $e:expr) => {{
        fn compiletime<const N: $t>() -> $t {
            N
        }
        compiletime::<{ $e }>()
    }};
}

const fn square(x: usize) -> usize {
    x * x
}

fn main() {
    let mut x = compile! { usize;
        square(4) + square(5)
    };

    x += 1;
    println!("{}", x);
}

Produces the error:

error[E0425]: cannot find value `N` in this scope
  --> src/main.rs:6:13
   |
6  |               N
   |               ^ not found in this scope
...
17 |       let mut x = compile! { usize;
   |  _________________-
18 | |         square(4) + square(5)
19 | |     };
   | |_____- in this macro invocation

Without the macro:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=3bc031a4b607a3128a5ce1f53564c181

42
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 11, 2019
@varkor
Copy link
Member

varkor commented May 11, 2019

I think this is probably due to #58307.

@varkor varkor removed their assignment May 30, 2019
@varkor
Copy link
Member

varkor commented May 30, 2019

cc @petrochenkov

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-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) 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