Skip to content

cannot use const params from macros as const args without braces #79127

Closed
@lcnr

Description

@lcnr
#![feature(min_const_generics)]
struct Foo<const M: usize>;
macro_rules! baz {
    ( $x:expr) => {
        Foo<$x> //[full]~ ERROR constant expression depends
    }
}
fn test<const N: usize>() {
    let _: baz!(N);
}

fails with

error: expressions must be enclosed in braces to be used as const generic arguments
 --> src/lib.rs:9:17
  |
9 |     let _: baz!(N);
  |                 ^
  |
help: enclose the `const` expression in braces
  |
9 |     let _: baz!({ N });
  |  

This should be allowed. See the discussion in https://github.com/rust-lang/rust/pull/78916/files#r520390092 for more details.
As fixing this should allow strictly more code to compile, this won't require a breaking change. I do not consider this to be blocking stabilization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions