diff options
| author | Michael Goulet <michael@errs.io> | 2023-06-23 19:18:18 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-06-23 19:18:20 +0000 |
| commit | 2cc7782cfd85a2c4dc2fa566fae4d4e356976471 (patch) | |
| tree | ff4b7e9b097aed21ee8bdc70bf425821b2bb5c05 /compiler/rustc_parse/src | |
| parent | 04075b32021932e3e8f6ab55d519b3b3494b6ef9 (diff) | |
| download | rust-2cc7782cfd85a2c4dc2fa566fae4d4e356976471.tar.gz rust-2cc7782cfd85a2c4dc2fa566fae4d4e356976471.zip | |
Add suggestion for bad block fragment error
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 84494eab855..96e1c0e3c6d 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -333,6 +333,17 @@ pub(crate) struct InvalidBlockMacroSegment { pub span: Span, #[label] pub context: Span, + #[subdiagnostic] + pub wrap: WrapInExplicitBlock, +} + +#[derive(Subdiagnostic)] +#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")] +pub(crate) struct WrapInExplicitBlock { + #[suggestion_part(code = "{{ ")] + pub 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 88c6cc1ae70..1b3d4e301a9 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2186,6 +2186,10 @@ impl<'a> Parser<'a> { self.sess.emit_err(errors::InvalidBlockMacroSegment { span: self.token.span, context: lo.to(self.token.span), + wrap: errors::WrapInExplicitBlock { + lo: self.token.span.shrink_to_lo(), + hi: self.token.span.shrink_to_hi(), + }, }); } |
