- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
macro_rules! co_vec_default {
    () => {
        1
    }
}
struct V<const U: usize>
where
    [(); U]:;
trait Tr {}
impl Tr for V<{co_vec_default!()}> {}Playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=058b224b06eefb23132dda5fad6f2950
The above generates a warning:
Compiling playground v0.0.1 (/playground)
warning: unnecessary braces around const expression
  --> src/lib.rs:16:15
   |
16 | impl Tr for V<{co_vec_default!()}> {}
   |               ^                 ^
   |
   = note: `#[warn(unused_braces)]` on by default
help: remove these braces
That above warning is either
- false positive, or
- directing a developer to an unimplemented rustcfunctionality or error, because without the braces it produces a (confusing) error. The same example code adjusted:
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
macro_rules! co_vec_default {
    () => {
        1
    }
}
struct V<const U: usize>
where
    [(); U]:;
trait Tr {}
impl Tr for V<co_vec_default!()> {}Limited playground (I don't see a way to pass -Z macro-backtrace to the playground):
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=8b334f459ac48f56639de94f116a7705
The current output (with nightly invoked with RUSTFLAGS="-Z macro-backtrace" cargo build) is:
Compiling co_vec_macro v0.1.0 (/tmp/co_vec_macro)
error: expected type, found `1`
  --> src/lib.rs:6:9
   |
4  | / macro_rules! co_vec_default {
5  | |     () => {
6  | |         1
   | |         ^ expected type
7  | |     }
8  | | }
   | |_- in this expansion of `co_vec_default!`
...
16 |   impl Tr for V<co_vec_default!()> {}
   |                 -----------------
   |                 |
   |                 this macro call doesn't expand to a type
   |                 in this macro invocation
error[E0747]: type provided when a constant was expected
  --> src/lib.rs:16:15
   |
16 | impl Tr for V<co_vec_default!()> {}
   |               ^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0747`.
Thank you in advance for any progress.
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.