about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2022-11-08 20:40:53 +0100
committerGitHub <noreply@github.com>2022-11-08 20:40:53 +0100
commite3c98a88bfa4cb798707f65298307d93e3f1cc9c (patch)
treee8dcc97f1ec2ad0976d5fbfa88834bf7b694c231 /compiler/rustc_parse/src/parser
parented38562d76c4bfc9d702e2a9ae3ef872d3fa1747 (diff)
parent268ea3528d85c44126aa01a22b9c00f0951f21f0 (diff)
downloadrust-e3c98a88bfa4cb798707f65298307d93e3f1cc9c.tar.gz
rust-e3c98a88bfa4cb798707f65298307d93e3f1cc9c.zip
Rollup merge of #104147 - WaffleLapkin:don't-compare-ptr-addresses-in-parser-, r=compiler-errors
Remove an address comparison from the parser

Originally this check was added in #68985, as suggested by https://github.com/rust-lang/rust/pull/68985/commits/940f65782cc5df7fecad27b38cc25b6d1eeaf2e8#r376850175. I don't think that this address check is a robust way of making parser more robust.

This code is also extensively tested by [`ui/parser/issues/issue-35813-postfix-after-cast.rs`](https://github.com/rust-lang/rust/blob/57d3c58ed6e0faf89a62411f96c000ffc9fd3937/src/test/ui/parser/issues/issue-35813-postfix-after-cast.rs).

_Replaces #103700_

r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs9
1 files changed, 2 insertions, 7 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 4a1162b9599..d784fef2bed 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -833,16 +833,11 @@ impl<'a> Parser<'a> {
                 ("cast", None)
             };
 
-        // Save the memory location of expr before parsing any following postfix operators.
-        // This will be compared with the memory location of the output expression.
-        // If they different we can assume we parsed another expression because the existing expression is not reallocated.
-        let addr_before = &*cast_expr as *const _ as usize;
         let with_postfix = self.parse_dot_or_call_expr_with_(cast_expr, span)?;
-        let changed = addr_before != &*with_postfix as *const _ as usize;
 
         // Check if an illegal postfix operator has been added after the cast.
-        // If the resulting expression is not a cast, or has a different memory location, it is an illegal postfix operator.
-        if !matches!(with_postfix.kind, ExprKind::Cast(_, _) | ExprKind::Type(_, _)) || changed {
+        // If the resulting expression is not a cast, it is an illegal postfix operator.
+        if !matches!(with_postfix.kind, ExprKind::Cast(_, _) | ExprKind::Type(_, _)) {
             let msg = format!(
                 "{cast_kind} cannot be followed by {}",
                 match with_postfix.kind {