Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ dependencies = [

[[package]]
name = "annotate-snippets"
version = "0.12.15"
version = "0.12.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92570a3f9c98e7e84df84b71d0965ac99b1871fcd75a3773a3bd1bad13f64cf7"
checksum = "f211a51805bc641f3ad5b7664c77d2547af685cc33b4cd8d31964027a46f13f1"
dependencies = [
"anstyle",
"memchr",
Expand Down Expand Up @@ -3958,7 +3958,7 @@ dependencies = [
name = "rustc_errors"
version = "0.0.0"
dependencies = [
"annotate-snippets 0.12.15",
"annotate-snippets 0.12.16",
"anstream",
"anstyle",
"derive_setters",
Expand Down
33 changes: 26 additions & 7 deletions compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use thin_vec::ThinVec;

use crate::ShouldEmit;
use crate::session_diagnostics::{
InvalidMetaItem, InvalidMetaItemQuoteIdentSugg, InvalidMetaItemRemoveNegSugg, MetaBadDelim,
MetaBadDelimSugg, SuffixedLiteralInAttribute,
ExpectedComma, InvalidMetaItem, InvalidMetaItemQuoteIdentSugg, InvalidMetaItemRemoveNegSugg,
MetaBadDelim, MetaBadDelimSugg, SuffixedLiteralInAttribute,
};

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -704,6 +704,29 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
self.parser.dcx().create_err(err)
}

fn should_continue_parsing_meta_items(&mut self) -> Result<bool, Diag<'sess>> {
if self.parser.eat(exp!(Comma)) {
return Ok(true);
} else if self.parser.token == token::Eof {
return Ok(false);
}

let mut snapshot = self.parser.create_snapshot_for_diagnostic();
if matches!(self.should_emit, ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed }) {
let span = self.parser.prev_token.span.shrink_to_hi();
self.should_emit = ShouldEmit::Nothing;
match self.parse_meta_item_inner() {
Ok(_) => {
return Err(self.parser.dcx().create_err(ExpectedComma { span }));
}
Err(e) => {
e.cancel();
}
}
}
snapshot.unexpected_any()
}

fn parse(
tokens: TokenStream,
psess: &'sess ParseSess,
Expand All @@ -724,15 +747,11 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
while this.parser.token != token::Eof {
sub_parsers.push(this.parse_meta_item_inner()?);

if !this.parser.eat(exp!(Comma)) {
if !this.should_continue_parsing_meta_items()? {
break;
}
}

if parser.token != token::Eof {
parser.unexpected()?;
}

Ok(MetaItemListParser { sub_parsers, span })
}
}
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_attr_parsing/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,3 +1032,16 @@ pub(crate) struct SanitizeInvalidStatic {
pub span: Span,
pub field: &'static str,
}

#[derive(Diagnostic)]
#[diag("attribute items not separated with `,`")]
pub(crate) struct ExpectedComma {
#[primary_span]
#[suggestion(
"try adding `,` here",
code = ",",
applicability = "maybe-incorrect",
style = "short"
)]
pub span: Span,
}
2 changes: 1 addition & 1 deletion compiler/rustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024"

[dependencies]
# tidy-alphabetical-start
annotate-snippets = { version = "0.12.15", features = ["simd"] }
annotate-snippets = { version = "0.12.16", features = ["simd"] }
anstream = "0.6.20"
anstyle = "1.0.13"
derive_setters = "0.1.6"
Expand Down
Loading
Loading