Skip to content

Commit e18c200

Browse files
committed
reviews
1 parent 0cee95e commit e18c200

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,17 +2413,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24132413
fn lower_anon_const_to_const_arg_direct(&mut self, anon: &AnonConst) -> hir::ConstArg<'hir> {
24142414
let tcx = self.tcx;
24152415

2416+
// We cannot change parsing depending on feature gates available,
2417+
// we can only require feature gates to be active as a delayed check.
2418+
// Thus we just parse anon consts generally and make the real decision
2419+
// making in ast lowering.
2420+
// FIXME(min_generic_const_args): revisit once stable
24162421
if tcx.features().min_generic_const_args() {
2417-
match anon.mgca_disambiguation {
2422+
return match anon.mgca_disambiguation {
24182423
MgcaDisambiguation::AnonConst => {
24192424
let lowered_anon = self.lower_anon_const_to_anon_const(anon);
2420-
return ConstArg {
2425+
ConstArg {
24212426
hir_id: self.next_id(),
24222427
kind: hir::ConstArgKind::Anon(lowered_anon),
2423-
};
2428+
}
24242429
}
24252430
MgcaDisambiguation::Direct => {
2426-
return self.lower_expr_to_const_arg_direct(&anon.value);
2431+
self.lower_expr_to_const_arg_direct(&anon.value)
24272432
}
24282433
}
24292434
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,11 @@ impl<'a> Parser<'a> {
16211621
let count = if self.token.is_keyword(kw::Const)
16221622
&& self.look_ahead(1, |t| *t == token::OpenBrace)
16231623
{
1624+
// While we could just disambiguate `Direct` from `AnonConst` by
1625+
// treating all const block exprs as `AnonConst`, that would
1626+
// complicate the DefCollector and likely all other visitors.
1627+
// So we strip the const blockiness and just store it as a block
1628+
// in the AST with the extra disambiguator on the AnonConst
16241629
self.parse_expr_anon_const(MgcaDisambiguation::AnonConst)?
16251630
} else {
16261631
self.parse_expr_anon_const(MgcaDisambiguation::Direct)?

compiler/rustc_parse/src/parser/path.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,11 @@ impl<'a> Parser<'a> {
874874
let value = self.parse_expr_block(None, self.token.span, BlockCheckMode::Default)?;
875875
(value, MgcaDisambiguation::Direct)
876876
} else if self.token.is_keyword(kw::Const) {
877+
// While we could just disambiguate `Direct` from `AnonConst` by
878+
// treating all const block exprs as `AnonConst`, that would
879+
// complicate the DefCollector and likely all other visitors.
880+
// So we strip the const blockiness and just store it as a block
881+
// in the AST with the extra disambiguator on the AnonConst
877882
let value = self.parse_mgca_const_block(true)?;
878883
(value.value, MgcaDisambiguation::AnonConst)
879884
} else {

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,11 @@ impl<'a> Parser<'a> {
661661
let mut length = if self.token.is_keyword(kw::Const)
662662
&& self.look_ahead(1, |t| *t == token::OpenBrace)
663663
{
664+
// While we could just disambiguate `Direct` from `AnonConst` by
665+
// treating all const block exprs as `AnonConst`, that would
666+
// complicate the DefCollector and likely all other visitors.
667+
// So we strip the const blockiness and just store it as a block
668+
// in the AST with the extra disambiguator on the AnonConst
664669
self.parse_mgca_const_block(false)?
665670
} else {
666671
self.parse_expr_anon_const(MgcaDisambiguation::Direct)?

0 commit comments

Comments
 (0)