Skip to content

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

Closed
@memoryruins

Description

@memoryruins

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

Activity

added
A-const-genericsArea: const generics (parameters and arguments)
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
C-bugCategory: This is a bug.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on May 11, 2019
varkor

varkor commented on May 11, 2019

@varkor
Member

I think this is probably due to #58307.

removed their assignment
on May 30, 2019
varkor

varkor commented on May 30, 2019

@varkor
Member
added 3 commits that reference this issue on Jul 29, 2019

Rollup merge of rust-lang#63083 - matthewjasper:parameter-hygiene, r=…

16a733b

Rollup merge of rust-lang#63083 - matthewjasper:parameter-hygiene, r=…

cbce93c

Rollup merge of rust-lang#63083 - matthewjasper:parameter-hygiene, r=…

652f13d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jonas-schievink@varkor@memoryruins

      Issue actions

        Const generic in macros_rules unable to be found in function scope · Issue #60746 · rust-lang/rust