mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
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 by940f65782c (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`](57d3c58ed6/src/test/ui/parser/issues/issue-35813-postfix-after-cast.rs
). _Replaces #103700_ r? `@compiler-errors`
This commit is contained in:
commit
e3c98a88bf
@ -833,16 +833,11 @@ impl<'a> Parser<'a> {
|
|||||||
("cast", None)
|
("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 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.
|
// 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 the resulting expression is not a cast, it is an illegal postfix operator.
|
||||||
if !matches!(with_postfix.kind, ExprKind::Cast(_, _) | ExprKind::Type(_, _)) || changed {
|
if !matches!(with_postfix.kind, ExprKind::Cast(_, _) | ExprKind::Type(_, _)) {
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"{cast_kind} cannot be followed by {}",
|
"{cast_kind} cannot be followed by {}",
|
||||||
match with_postfix.kind {
|
match with_postfix.kind {
|
||||||
|
Loading…
Reference in New Issue
Block a user