rustc_parse: revert conversion of "non-item in item list" diagnostic

#[derive(Subdiagnostic)] does not allow multiple subdiagnostics on one
variant, as in NonItemInItemListSub::Other.
This commit is contained in:
Xiretza 2022-12-13 18:57:41 +01:00
parent 7631b12e3e
commit a476683c84
2 changed files with 25 additions and 50 deletions

View File

@ -1446,38 +1446,6 @@ pub(crate) struct ExpectedTraitInTraitImplFoundType {
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_non_item_in_item_list)]
pub(crate) struct NonItemInItemList {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub sub: NonItemInItemListSub,
#[suggestion(suggestion_remove_semicolon, code = "", applicability = "maybe-incorrect")]
pub remove_semicolon: Option<Span>,
}
#[derive(Subdiagnostic)]
pub(crate) enum NonItemInItemListSub {
#[suggestion(
suggestion_use_const_not_let,
code = "const",
applicability = "machine-applicable"
)]
Let {
#[primary_span]
span: Span,
},
Other {
#[label(label_list_start)]
list_start: Span,
#[label(label_non_item)]
non_item: Span,
#[label(label_list_end)]
list_end: Span,
},
}
#[derive(Diagnostic)]
#[diag(parse_bounds_not_allowed_on_trait_aliases)]
pub(crate) struct BoundsNotAllowedOnTraitAliases {

View File

@ -4,9 +4,9 @@
DefaultNotFollowedByItem, DocCommentDoesNotDocumentAnything, EnumStructMutuallyExclusive,
ExpectedTraitInTraitImplFoundType, ExternCrateNameWithDashes, ExternCrateNameWithDashesSugg,
ExternItemCannotBeConst, MissingConstType, MissingForInTraitImpl,
MissingKeywordForItemDefinition, MissingTraitInTraitImpl, NonItemInItemList,
NonItemInItemListSub, SelfArgumentPointer, TraitAliasCannotBeAuto, TraitAliasCannotBeUnsafe,
UnexpectedTokenAfterStructName, UseEmptyBlockNotSemi, VisibilityNotFollowedByItem,
MissingKeywordForItemDefinition, MissingTraitInTraitImpl, SelfArgumentPointer,
TraitAliasCannotBeAuto, TraitAliasCannotBeUnsafe, UnexpectedTokenAfterStructName,
UseEmptyBlockNotSemi, VisibilityNotFollowedByItem,
};
use super::diagnostics::{dummy_arg, ConsumeClosingDelim};
@ -703,22 +703,29 @@ fn parse_item_list<T>(
let non_item_span = self.token.span;
let is_let = self.token.is_keyword(kw::Let);
let mut err = self.struct_span_err(non_item_span, "non-item in item list");
self.consume_block(Delimiter::Brace, ConsumeClosingDelim::Yes);
self.sess.emit_err(NonItemInItemList {
span: non_item_span,
sub: if is_let {
NonItemInItemListSub::Let { span: non_item_span }
} else {
NonItemInItemListSub::Other {
list_start: open_brace_span,
non_item: non_item_span,
list_end: self.prev_token.span,
}
},
remove_semicolon: is_unnecessary_semicolon.then_some(semicolon_span),
});
if is_let {
err.span_suggestion(
non_item_span,
"consider using `const` instead of `let` for associated const",
"const",
Applicability::MachineApplicable,
);
} else {
err.span_label(open_brace_span, "item list starts here")
.span_label(non_item_span, "non-item starts here")
.span_label(self.prev_token.span, "item list ends here");
}
if is_unnecessary_semicolon {
err.span_suggestion(
semicolon_span,
"consider removing this semicolon",
"",
Applicability::MaybeIncorrect,
);
}
err.emit();
break;
}
Ok(Some(item)) => items.extend(item),