migrate maybe_consume_incorrect_semicolon
diagnostic
This commit is contained in:
parent
bd4d1cd7a2
commit
29ed9a56e3
2 changed files with 23 additions and 9 deletions
|
@ -18,3 +18,8 @@ parser-expect-path = expected a path
|
||||||
parser-maybe-recover-from-bad-qpath-stage-2 =
|
parser-maybe-recover-from-bad-qpath-stage-2 =
|
||||||
missing angle brackets in associated item path
|
missing angle brackets in associated item path
|
||||||
.suggestion = try: `{$ty}`
|
.suggestion = try: `{$ty}`
|
||||||
|
|
||||||
|
parser-incorrect-semicolon =
|
||||||
|
expected item, found `;`
|
||||||
|
.suggestion = remove this semicolon
|
||||||
|
.help = {$name} declarations are not followed by a semicolon
|
||||||
|
|
|
@ -295,6 +295,17 @@ struct BadQPathStage2 {
|
||||||
ty: String,
|
ty: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(slug = "parser-incorrect-semicolon")]
|
||||||
|
struct IncorrectSemicolon<'a> {
|
||||||
|
#[primary_span]
|
||||||
|
#[suggestion(applicability = "machine-applicable")]
|
||||||
|
span: Span,
|
||||||
|
#[help]
|
||||||
|
opt_help: Option<()>,
|
||||||
|
name: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
// SnapshotParser is used to create a snapshot of the parser
|
// SnapshotParser is used to create a snapshot of the parser
|
||||||
// without causing duplicate errors being emitted when the `Parser`
|
// without causing duplicate errors being emitted when the `Parser`
|
||||||
// is dropped.
|
// is dropped.
|
||||||
|
@ -1490,13 +1501,10 @@ impl<'a> Parser<'a> {
|
||||||
pub fn maybe_consume_incorrect_semicolon(&mut self, items: &[P<Item>]) -> bool {
|
pub fn maybe_consume_incorrect_semicolon(&mut self, items: &[P<Item>]) -> bool {
|
||||||
if self.token.kind == TokenKind::Semi {
|
if self.token.kind == TokenKind::Semi {
|
||||||
self.bump();
|
self.bump();
|
||||||
let mut err = self.struct_span_err(self.prev_token.span, "expected item, found `;`");
|
|
||||||
err.span_suggestion_short(
|
let mut err =
|
||||||
self.prev_token.span,
|
IncorrectSemicolon { span: self.prev_token.span, opt_help: None, name: "" };
|
||||||
"remove this semicolon",
|
|
||||||
String::new(),
|
|
||||||
Applicability::MachineApplicable,
|
|
||||||
);
|
|
||||||
if !items.is_empty() {
|
if !items.is_empty() {
|
||||||
let previous_item = &items[items.len() - 1];
|
let previous_item = &items[items.len() - 1];
|
||||||
let previous_item_kind_name = match previous_item.kind {
|
let previous_item_kind_name = match previous_item.kind {
|
||||||
|
@ -1509,10 +1517,11 @@ impl<'a> Parser<'a> {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
if let Some(name) = previous_item_kind_name {
|
if let Some(name) = previous_item_kind_name {
|
||||||
err.help(&format!("{name} declarations are not followed by a semicolon"));
|
err.opt_help = Some(());
|
||||||
|
err.name = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err.emit();
|
self.sess.emit_err(err);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue