Skip to content

Commit 2b27c62

Browse files
committed
Allow true and false in const generic arguments
1 parent 2be25e9 commit 2b27c62

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/libsyntax/parse/parser.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -5250,9 +5250,13 @@ impl<'a> Parser<'a> {
52505250
// FIXME(const_generics): to distinguish between idents for types and consts,
52515251
// we should introduce a GenericArg::Ident in the AST and distinguish when
52525252
// lowering to the HIR. For now, idents for const args are not permitted.
5253-
return Err(
5254-
self.fatal("identifiers may currently not be used for const generics")
5255-
);
5253+
if self.token.is_keyword(kw::True) || self.token.is_keyword(kw::False) {
5254+
self.parse_literal_maybe_minus()?
5255+
} else {
5256+
return Err(
5257+
self.fatal("identifiers may currently not be used for const generics")
5258+
);
5259+
}
52565260
} else {
52575261
self.parse_literal_maybe_minus()?
52585262
};

src/test/ui/const-generics/condition-in-trait-const-arg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ trait IsZeroTrait<const IS_ZERO: bool>{}
77

88
impl IsZeroTrait<{0u8 == 0u8}> for () {}
99

10+
impl IsZeroTrait<true> for ((),) {}
11+
1012
fn main() {}

0 commit comments

Comments
 (0)