Don't recover &raw EXPR as a missing comma#157079
Conversation
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
|
r? @jieyouxu rustbot has assigned @jieyouxu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
(Focusing on debuginfo/compiletest/rustfmt reviews this weekend) |
| if self.prev_token.is_keyword(kw::Raw) | ||
| && self.expected_token_types.contains(TokenType::KwMut) | ||
| && self.expected_token_types.contains(TokenType::KwConst) | ||
| && self.token.can_begin_expr() => |
There was a problem hiding this comment.
You'd want to factor out this check into separate method like is_addr_of_missing_const_mut(&self) -> bool, or came up with better naming
There was a problem hiding this comment.
I had it in mind initially but needed validation like this.
given it'll be a parser/diagnostics method, name like is_expected_raw_ref_mut(&self) -> bool reads nicer with surrounding methods e.g the existing label_expected_raw_ref(&mut self, err: &mut Diag<'_>)
There was a problem hiding this comment.
Can we also add a multi arguments test, like takes_raw_ptr(&raw x, x)
|
hm, why this loop was introduced? |
it's basically to preserve the argument count for multi arguments |
|
how was the multi arguments diagnostics looked like without this last commit with loop is that was buggy or something, need this understand what this is fixing |
it was buggy in the sense that it failed the multi args test |
|
i need to think more about this, so review might take some time |
|
ok, here is what i think. let's add this helper fn recover_raw_ref_call_args(&mut self, guar: ErrorGuaranteed) -> ThinVec<Box<Expr>> {
let err_span = self.prev_token.span.to(self.token.span);
let mut args = thin_vec![self.mk_expr_err(err_span, guar)];
while self.token != token::Eof && self.token != token::CloseParen {
if self.eat(exp!(Comma)) {
if self.token != token::Eof && self.token != token::CloseParen {
args.push(self.mk_expr_err(self.prev_token.span.shrink_to_hi(), guar));
}
} else {
self.parse_token_tree();
}
}
let _ = self.eat(exp!(CloseParen));
args
}and then call site's become this Err(err) if self.is_expected_raw_ref_mut() => {
let guar = err.emit();
let args = self.recover_raw_ref_call_args(guar);
return self.mk_expr(lo.to(self.prev_token.span), self.mk_call(fun, args));
}can you try and verify it's work as intended |
Yes, it was part of my initial thought but I couldn’t think of its usefulness outside this issue? |
|
its just keep code clean i guess |
|
@bors r+ rollup |
…=Kivooeo Don't recover `&raw EXPR` as a missing comma The parser already has a targeted suggestion for `&raw EXPR`, added in rust-lang#139392, telling the user that `&raw` must be followed by `const` or `mut`. In comma-separated expression lists, the generic missing-comma recovery would then treat the expression after `raw` as the next list element. That produced follow-up diagnostics like: - `help: missing ','` - `cannot find value raw in this scope` - an arity error for calls such as `takes_raw_ptr(&raw x)` This PR avoids that comma recovery when we are already in the `&raw` missing-`const`/`mut` diagnostic path. For function calls, it preserves the call expression with a single error argument, so useful later diagnostics such as `cannot find function f` are still emitted. Fixes rust-lang#157015.
…uwer Rollup of 23 pull requests Successful merges: - #144220 (Add powerpc64-unknown-linux-gnuelfv2 target) - #153238 (debuginfo: slices are DW_TAG_array_type's) - #157112 (Update aarch64-unknown-freebsd target description) - #157322 (test pre-stabilization items on CI) - #157348 (Don't track cwd for `-Zremap-cwd-prefix` in incremental compilation) - #157490 (Add field-wise CoerceShared reborrow tests) - #157655 (Make Share::share final and improve docs) - #157672 (Region inference: Simplify initialisation of region values) - #157680 (Require `#[pin_v2]` for explicit pin-projection patterns) - #157688 (Create experimental test job `aarch64-apple-macos-26` for evaluating `macos-26` runner images) - #157796 (rustdoc: Some more lazy formatting) - #157818 (miri subtree update) - #157069 (Test that you can't implement Unpin for a compiler-generated future using TAIT) - #157079 (Don't recover `&raw EXPR` as a missing comma) - #157202 (add #[rustc_no_writable] to slice::get_unchecked_mut) - #157622 (Disable retagging for variadic arguments in const-eval) - #157684 (-Zassumptions-on-binders: insert empty assumptions when entering binders in the solver) - #157695 (Extend capabilities of `TypeFoldable_Generic`) - #157766 (interpret: avoid computing layout of sized raw pointee) - #157785 (fuchsia: Support AddressSanitizer on riscv64gc-unknown-fuchsia) - #157795 (revert 157013) - #157798 (Prevent approving PRs that wait for Crater or formal decisions) - #157803 (Rename `errors.rs` file to `diagnostics.rs` (7/N)) Failed merges: - #157752 (Rename `errors.rs` file to `diagnostics.rs` (6/N))
…uwer Rollup of 23 pull requests Successful merges: - rust-lang/rust#144220 (Add powerpc64-unknown-linux-gnuelfv2 target) - rust-lang/rust#153238 (debuginfo: slices are DW_TAG_array_type's) - rust-lang/rust#157112 (Update aarch64-unknown-freebsd target description) - rust-lang/rust#157322 (test pre-stabilization items on CI) - rust-lang/rust#157348 (Don't track cwd for `-Zremap-cwd-prefix` in incremental compilation) - rust-lang/rust#157490 (Add field-wise CoerceShared reborrow tests) - rust-lang/rust#157655 (Make Share::share final and improve docs) - rust-lang/rust#157672 (Region inference: Simplify initialisation of region values) - rust-lang/rust#157680 (Require `#[pin_v2]` for explicit pin-projection patterns) - rust-lang/rust#157688 (Create experimental test job `aarch64-apple-macos-26` for evaluating `macos-26` runner images) - rust-lang/rust#157796 (rustdoc: Some more lazy formatting) - rust-lang/rust#157818 (miri subtree update) - rust-lang/rust#157069 (Test that you can't implement Unpin for a compiler-generated future using TAIT) - rust-lang/rust#157079 (Don't recover `&raw EXPR` as a missing comma) - rust-lang/rust#157202 (add #[rustc_no_writable] to slice::get_unchecked_mut) - rust-lang/rust#157622 (Disable retagging for variadic arguments in const-eval) - rust-lang/rust#157684 (-Zassumptions-on-binders: insert empty assumptions when entering binders in the solver) - rust-lang/rust#157695 (Extend capabilities of `TypeFoldable_Generic`) - rust-lang/rust#157766 (interpret: avoid computing layout of sized raw pointee) - rust-lang/rust#157785 (fuchsia: Support AddressSanitizer on riscv64gc-unknown-fuchsia) - rust-lang/rust#157795 (revert 157013) - rust-lang/rust#157798 (Prevent approving PRs that wait for Crater or formal decisions) - rust-lang/rust#157803 (Rename `errors.rs` file to `diagnostics.rs` (7/N)) Failed merges: - rust-lang/rust#157752 (Rename `errors.rs` file to `diagnostics.rs` (6/N))
The parser already has a targeted suggestion for
&raw EXPR, added in #139392, telling the user that&rawmust be followed byconstormut.In comma-separated expression lists, the generic missing-comma recovery would then treat the expression after
rawas the next list element. That produced follow-up diagnostics like:help: missing ','cannot find value raw in this scopetakes_raw_ptr(&raw x)This PR avoids that comma recovery when we are already in the
&rawmissing-const/mutdiagnostic path. For function calls, it preserves the call expression with a single error argument, so useful later diagnostics such ascannot find function fare still emitted.Fixes #157015.