diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-08-01 18:43:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-01 18:43:41 +0200 |
| commit | 29cd3103a162c1bf80a6123aaa77fc2d3e392150 (patch) | |
| tree | 90cb44fdcd80612350ee6a299ccf0a303c8c15cb /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 8671b0bfbd905c69773657d8f87eb08ccf01056d (diff) | |
| parent | e157954cce4497738a728f8c295c71b229d35a66 (diff) | |
| download | rust-29cd3103a162c1bf80a6123aaa77fc2d3e392150.tar.gz rust-29cd3103a162c1bf80a6123aaa77fc2d3e392150.zip | |
Rollup merge of #128496 - clubby789:box-syntax-multipart, r=compiler-errors
Fix removed `box_syntax` diagnostic if source isn't available Fix #128442
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 10 |
1 files changed, 6 insertions, 4 deletions
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))) } |
