diff options
| author | bors <bors@rust-lang.org> | 2024-08-01 16:50:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-01 16:50:50 +0000 |
| commit | a886938671e1fde9d7271dce8ca3d6938bae9d2e (patch) | |
| tree | acd309c85635179915664607087a6fe48ebcfb76 /compiler/rustc_parse/src | |
| parent | e60ebb2f2c1facba87e7971798f3cbdfd309cd23 (diff) | |
| parent | e6b6d04b06b0f0d5ccf68b44d42aa534ee654d5d (diff) | |
| download | rust-a886938671e1fde9d7271dce8ca3d6938bae9d2e.tar.gz rust-a886938671e1fde9d7271dce8ca3d6938bae9d2e.zip | |
Auto merge of #128504 - matthiaskrgr:rollup-pawylnk, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #127490 (Add target page for riscv64gc-unknown-linux-gnu) - #128433 (fix(hermit): `deny(unsafe_op_in_unsafe_fn)`) - #128482 (interpret: on a signed deref check, mention the right pointer in the error) - #128496 (Fix removed `box_syntax` diagnostic if source isn't available) - #128497 (fix dropck documentation for `[T;0]` special-case) - #128499 (chore: refactor backtrace formatting) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 23 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 10 |
2 files changed, 22 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 99f2f26b8cb..0d4512be480 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -2725,15 +2725,24 @@ impl HelpUseLatestEdition { #[derive(Diagnostic)] #[diag(parse_box_syntax_removed)] -pub struct BoxSyntaxRemoved<'a> { +pub struct BoxSyntaxRemoved { #[primary_span] - #[suggestion( - code = "Box::new({code})", - applicability = "machine-applicable", - style = "verbose" - )] pub span: Span, - pub code: &'a str, + #[subdiagnostic] + pub sugg: AddBoxNew, +} + +#[derive(Subdiagnostic)] +#[multipart_suggestion( + parse_box_syntax_removed_suggestion, + applicability = "machine-applicable", + style = "verbose" +)] +pub struct AddBoxNew { + #[suggestion_part(code = "Box::new(")] + pub box_kw_and_lo: Span, + #[suggestion_part(code = ")")] + pub hi: Span, } #[derive(Diagnostic)] diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index a4d9d97045d..1b053c39e64 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -618,10 +618,12 @@ impl<'a> Parser<'a> { /// Parse `box expr` - this syntax has been removed, but we still parse this /// for now to provide a more useful error fn parse_expr_box(&mut self, box_kw: Span) -> PResult<'a, (Span, ExprKind)> { - let (span, _) = self.parse_expr_prefix_common(box_kw)?; - let inner_span = span.with_lo(box_kw.hi()); - let code = self.psess.source_map().span_to_snippet(inner_span).unwrap(); - let guar = self.dcx().emit_err(errors::BoxSyntaxRemoved { span: span, code: code.trim() }); + let (span, expr) = self.parse_expr_prefix_common(box_kw)?; + // Make a multipart suggestion instead of `span_to_snippet` in case source isn't available + let box_kw_and_lo = box_kw.until(self.interpolated_or_expr_span(&expr)); + let hi = span.shrink_to_hi(); + let sugg = errors::AddBoxNew { box_kw_and_lo, hi }; + let guar = self.dcx().emit_err(errors::BoxSyntaxRemoved { span, sugg }); Ok((span, ExprKind::Err(guar))) } |
