Add suggestion for bad block fragment error
This commit is contained in:
parent
04075b3202
commit
2cc7782cfd
@ -353,6 +353,7 @@ parse_int_literal_too_large = integer literal is too large
|
|||||||
|
|
||||||
parse_invalid_block_macro_segment = cannot use a `block` macro fragment here
|
parse_invalid_block_macro_segment = cannot use a `block` macro fragment here
|
||||||
.label = the `block` fragment is within this context
|
.label = the `block` fragment is within this context
|
||||||
|
.suggestion = wrap this in another block
|
||||||
|
|
||||||
parse_invalid_char_in_escape = {parse_invalid_char_in_escape_msg}: `{$ch}`
|
parse_invalid_char_in_escape = {parse_invalid_char_in_escape_msg}: `{$ch}`
|
||||||
.label = {parse_invalid_char_in_escape_msg}
|
.label = {parse_invalid_char_in_escape_msg}
|
||||||
|
@ -333,6 +333,17 @@ pub(crate) struct InvalidBlockMacroSegment {
|
|||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[label]
|
#[label]
|
||||||
pub context: Span,
|
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)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -2186,6 +2186,10 @@ impl<'a> Parser<'a> {
|
|||||||
self.sess.emit_err(errors::InvalidBlockMacroSegment {
|
self.sess.emit_err(errors::InvalidBlockMacroSegment {
|
||||||
span: self.token.span,
|
span: self.token.span,
|
||||||
context: lo.to(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(),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ LL | m!({});
|
|||||||
| ------ in this macro invocation
|
| ------ in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: wrap this in another block
|
||||||
|
|
|
||||||
|
LL | 'lab: { $b };
|
||||||
|
| + +
|
||||||
|
|
||||||
error: cannot use a `block` macro fragment here
|
error: cannot use a `block` macro fragment here
|
||||||
--> $DIR/bad-interpolated-block.rs:6:16
|
--> $DIR/bad-interpolated-block.rs:6:16
|
||||||
@ -23,6 +27,10 @@ LL | m!({});
|
|||||||
| ------ in this macro invocation
|
| ------ in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: wrap this in another block
|
||||||
|
|
|
||||||
|
LL | unsafe { $b };
|
||||||
|
| + +
|
||||||
|
|
||||||
error: cannot use a `block` macro fragment here
|
error: cannot use a `block` macro fragment here
|
||||||
--> $DIR/bad-interpolated-block.rs:7:23
|
--> $DIR/bad-interpolated-block.rs:7:23
|
||||||
@ -34,6 +42,10 @@ LL | m!({});
|
|||||||
| ------ in this macro invocation
|
| ------ in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: wrap this in another block
|
||||||
|
|
|
||||||
|
LL | |x: u8| -> () { $b };
|
||||||
|
| + +
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
@ -77,6 +77,10 @@ LL | m!({});
|
|||||||
| ------ in this macro invocation
|
| ------ in this macro invocation
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: wrap this in another block
|
||||||
|
|
|
||||||
|
LL | 'l5 { $b };
|
||||||
|
| + +
|
||||||
|
|
||||||
error: labeled expression must be followed by `:`
|
error: labeled expression must be followed by `:`
|
||||||
--> $DIR/labeled-no-colon-expr.rs:14:8
|
--> $DIR/labeled-no-colon-expr.rs:14:8
|
||||||
|
Loading…
x
Reference in New Issue
Block a user