diff options
| author | Jana Dönszelmann <jana@donsz.nl> | 2025-08-23 19:42:14 +0200 |
|---|---|---|
| committer | Jana Dönszelmann <jana@donsz.nl> | 2025-08-24 09:20:57 +0200 |
| commit | 48a4e2d2dde8d68e1d00d3eac07b2c6155f3239d (patch) | |
| tree | 21e4c65b03513947890bc1bd38947a7c0ba75f68 /compiler/rustc_attr_parsing/src | |
| parent | 59ceb02d65f13a20d29422f4d923ecde429d4c0c (diff) | |
| download | rust-48a4e2d2dde8d68e1d00d3eac07b2c6155f3239d.tar.gz rust-48a4e2d2dde8d68e1d00d3eac07b2c6155f3239d.zip | |
fix ICE on stable related to attrs on macros
Diffstat (limited to 'compiler/rustc_attr_parsing/src')
| -rw-r--r-- | compiler/rustc_attr_parsing/src/context.rs | 21 | ||||
| -rw-r--r-- | compiler/rustc_attr_parsing/src/parser.rs | 20 |
2 files changed, 12 insertions, 29 deletions
diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 128ecd67d2a..d4b9cfe00ad 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -265,7 +265,7 @@ impl Stage for Early { sess: &'sess Session, diag: impl for<'x> Diagnostic<'x>, ) -> ErrorGuaranteed { - self.should_emit().emit_err_or_delay(sess.dcx().create_err(diag)) + self.should_emit().emit_err(sess.dcx().create_err(diag)) } fn should_emit(&self) -> ShouldEmit { @@ -667,7 +667,7 @@ pub enum ShouldEmit { } impl ShouldEmit { - pub(crate) fn emit_err_or_delay(&self, diag: Diag<'_>) -> ErrorGuaranteed { + pub(crate) fn emit_err(&self, diag: Diag<'_>) -> ErrorGuaranteed { match self { ShouldEmit::EarlyFatal if diag.level() == Level::DelayedBug => diag.emit(), ShouldEmit::EarlyFatal => diag.upgrade_to_fatal().emit(), @@ -675,21 +675,4 @@ impl ShouldEmit { ShouldEmit::Nothing => diag.delay_as_bug(), } } - - pub(crate) fn maybe_emit_err(&self, diag: Diag<'_>) { - match self { - ShouldEmit::EarlyFatal if diag.level() == Level::DelayedBug => { - diag.emit(); - } - ShouldEmit::EarlyFatal => { - diag.upgrade_to_fatal().emit(); - } - ShouldEmit::ErrorsAndLints => { - diag.emit(); - } - ShouldEmit::Nothing => { - diag.cancel(); - } - } - } } diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs index 3ba188938c6..6d3cf684296 100644 --- a/compiler/rustc_attr_parsing/src/parser.rs +++ b/compiler/rustc_attr_parsing/src/parser.rs @@ -328,14 +328,14 @@ fn expr_to_lit( match res { Ok(lit) => { if token_lit.suffix.is_some() { - should_emit.emit_err_or_delay( + should_emit.emit_err( psess.dcx().create_err(SuffixedLiteralInAttribute { span: lit.span }), ); None } else { if !lit.kind.is_unsuffixed() { // Emit error and continue, we can still parse the attribute as if the suffix isn't there - should_emit.maybe_emit_err( + should_emit.emit_err( psess.dcx().create_err(SuffixedLiteralInAttribute { span: lit.span }), ); } @@ -355,6 +355,10 @@ fn expr_to_lit( } } } else { + if matches!(should_emit, ShouldEmit::Nothing) { + return None; + } + // Example cases: // - `#[foo = 1+1]`: results in `ast::ExprKind::BinOp`. // - `#[foo = include_str!("nonexistent-file.rs")]`: @@ -362,12 +366,8 @@ fn expr_to_lit( // the error because an earlier error will have already // been reported. let msg = "attribute value must be a literal"; - let mut err = psess.dcx().struct_span_err(span, msg); - if let ExprKind::Err(_) = expr.kind { - err.downgrade_to_delayed_bug(); - } - - should_emit.emit_err_or_delay(err); + let err = psess.dcx().struct_span_err(span, msg); + should_emit.emit_err(err); None } } @@ -400,7 +400,7 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> { if !lit.kind.is_unsuffixed() { // Emit error and continue, we can still parse the attribute as if the suffix isn't there - self.should_emit.maybe_emit_err( + self.should_emit.emit_err( self.parser.dcx().create_err(SuffixedLiteralInAttribute { span: lit.span }), ); } @@ -542,7 +542,7 @@ impl<'a> MetaItemListParser<'a> { ) { Ok(s) => Some(s), Err(e) => { - should_emit.emit_err_or_delay(e); + should_emit.emit_err(e); None } } |
