Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 96cc9c9

Browse files
committed
Inline and remove Parser::parse_and_disallow_postfix_after_cast.
It has a single call site. Removing it removes the need for an `ExprKind` check. The commit also clarifies the relevant comment.
1 parent d247489 commit 96cc9c9

File tree

1 file changed

+4
-13
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+4
-13
lines changed

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -785,19 +785,10 @@ impl<'a> Parser<'a> {
785785
}
786786
};
787787

788-
self.parse_and_disallow_postfix_after_cast(cast_expr)
789-
}
790-
791-
/// Parses a postfix operators such as `.`, `?`, or index (`[]`) after a cast,
792-
/// then emits an error and returns the newly parsed tree.
793-
/// The resulting parse tree for `&x as T[0]` has a precedence of `((&x) as T)[0]`.
794-
fn parse_and_disallow_postfix_after_cast(
795-
&mut self,
796-
cast_expr: P<Expr>,
797-
) -> PResult<'a, P<Expr>> {
798-
if let ExprKind::Type(_, _) = cast_expr.kind {
799-
panic!("ExprKind::Type must not be parsed");
800-
}
788+
// Try to parse a postfix operator such as `.`, `?`, or index (`[]`)
789+
// after a cast. If one is present, emit an error then return a valid
790+
// parse tree; For something like `&x as T[0]` will be as if it was
791+
// written `((&x) as T)[0]`.
801792

802793
let span = cast_expr.span;
803794

0 commit comments

Comments
 (0)