fix ICE on stable related to attrs on macros
This commit is contained in:
parent
59ceb02d65
commit
48a4e2d2dd
7 changed files with 58 additions and 30 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
//@ check-pass
|
||||
#[deprecated = concat !()]
|
||||
macro_rules! a {
|
||||
() => {};
|
||||
}
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#![deny(unused)]
|
||||
|
||||
#[crate_name = concat !()]
|
||||
//~^ ERROR crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]
|
||||
macro_rules! a {
|
||||
//~^ ERROR unused macro definition
|
||||
() => {};
|
||||
}
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
error: unused macro definition: `a`
|
||||
--> $DIR/concat-in-crate-name-issue-137687.rs:5:14
|
||||
|
|
||||
LL | macro_rules! a {
|
||||
| ^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/concat-in-crate-name-issue-137687.rs:1:9
|
||||
|
|
||||
LL | #![deny(unused)]
|
||||
| ^^^^^^
|
||||
= note: `#[deny(unused_macros)]` implied by `#[deny(unused)]`
|
||||
|
||||
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
|
||||
--> $DIR/concat-in-crate-name-issue-137687.rs:3:1
|
||||
|
|
||||
LL | #[crate_name = concat !()]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[deny(unused_attributes)]` implied by `#[deny(unused)]`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -5,5 +5,6 @@ fn main() {
|
|||
const {
|
||||
#![path = foo!()]
|
||||
//~^ ERROR: cannot find macro `foo` in this scope
|
||||
//~| ERROR: attribute value must be a literal
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,5 +4,11 @@ error: cannot find macro `foo` in this scope
|
|||
LL | #![path = foo!()]
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error: attribute value must be a literal
|
||||
--> $DIR/path-attr-in-const-block.rs:6:19
|
||||
|
|
||||
LL | #![path = foo!()]
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue