Skip to content

Commit 01703e3

Browse files
committed
parse array lengths without mgca shenanigans
1 parent 23a44d3 commit 01703e3

11 files changed

Lines changed: 21 additions & 243 deletions

File tree

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,16 +1622,8 @@ impl<'a> Parser<'a> {
16221622
let first_expr = self.parse_expr()?;
16231623
if self.eat(exp!(Semi)) {
16241624
// Repeating array syntax: `[ 0; 512 ]`
1625-
let count = if self.eat_keyword(exp!(Const)) {
1626-
// While we could just disambiguate `Direct` from `AnonConst` by
1627-
// treating all const block exprs as `AnonConst`, that would
1628-
// complicate the DefCollector and likely all other visitors.
1629-
// So we strip the const blockiness and just store it as a block
1630-
// in the AST with the extra disambiguator on the AnonConst
1631-
self.parse_mgca_const_block(false)?
1632-
} else {
1633-
self.parse_expr_anon_const(|this, expr| this.mgca_direct_lit_hack(expr))?
1634-
};
1625+
let count =
1626+
self.parse_expr_anon_const(|this, expr| this.mgca_direct_lit_hack(expr))?;
16351627
self.expect(close)?;
16361628
ExprKind::Repeat(first_expr, count)
16371629
} else if self.eat(exp!(Comma)) {

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,8 @@ impl<'a> Parser<'a> {
658658
};
659659

660660
let ty = if self.eat(exp!(Semi)) {
661-
let mut length = if self.eat_keyword(exp!(Const)) {
662-
// While we could just disambiguate `Direct` from `AnonConst` by
663-
// treating all const block exprs as `AnonConst`, that would
664-
// complicate the DefCollector and likely all other visitors.
665-
// So we strip the const blockiness and just store it as a block
666-
// in the AST with the extra disambiguator on the AnonConst
667-
self.parse_mgca_const_block(false)?
668-
} else {
669-
self.parse_expr_anon_const(|this, expr| this.mgca_direct_lit_hack(expr))?
670-
};
661+
let mut length =
662+
self.parse_expr_anon_const(|this, expr| this.mgca_direct_lit_hack(expr))?;
671663

672664
if let Err(e) = self.expect(exp!(CloseBracket)) {
673665
// Try to recover from `X<Y, ...>` when `X::<Y, ...>` works
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn foo() {
2+
let a = [(); const { let x = 1; x }];
3+
}
4+
5+
fn foo() {
6+
let x = [(); const { 1 }];
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn foo() {
2+
let a = [(); const {
3+
let x = 1;
4+
x
5+
}];
6+
}
7+
8+
fn foo() {
9+
let x = [(); const { 1 }];
10+
}

tests/ui/const-generics/mgca/explicit_anon_consts.rs

Lines changed: 0 additions & 73 deletions
This file was deleted.

tests/ui/const-generics/mgca/explicit_anon_consts.stderr

Lines changed: 0 additions & 80 deletions
This file was deleted.

tests/ui/const-generics/mgca/selftyalias-containing-param.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/ui/const-generics/mgca/selftyalias-containing-param.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/ui/const-generics/mgca/selftyparam.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/ui/const-generics/mgca/selftyparam.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)