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 use const params from macros as const args without braces #79127

Closed
lcnr opened this issue Nov 17, 2020 · 0 comments · Fixed by #79164
Closed

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

lcnr opened this issue Nov 17, 2020 · 0 comments · Fixed by #79164
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate.

Comments

@lcnr
Copy link
Contributor

lcnr commented Nov 17, 2020

#![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.

@lcnr lcnr added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. F-min_const_generics E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Nov 17, 2020
@lcnr lcnr changed the title cannot use const params from macros without braces cannot use const args from macros without braces Nov 17, 2020
@lcnr lcnr changed the title cannot use const args from macros without braces cannot use const params from macros as const args without braces Nov 17, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
…t-arguments, r=petrochenkov

Permit standalone generic parameters as const generic arguments in macros

Fixes rust-lang#79127.

r? `@petrochenkov`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
…t-arguments, r=petrochenkov

Permit standalone generic parameters as const generic arguments in macros

Fixes rust-lang#79127.

r? ``@petrochenkov``
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 19, 2020
…t-arguments, r=petrochenkov

Permit standalone generic parameters as const generic arguments in macros

Fixes rust-lang#79127.

r? ```@petrochenkov```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant