mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
fix ICE on stable related to attrs on macros
This commit is contained in:
@@ -265,7 +265,7 @@ fn emit_err<'sess>(
|
||||
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 @@ pub(crate) fn emit_err_or_delay(&self, diag: Diag<'_>) -> ErrorGuaranteed {
|
||||
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 @@ fn parse_unsuffixed_meta_item_lit(&mut self) -> PResult<'sess, MetaItemLit> {
|
||||
|
||||
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 @@ fn new<'sess>(
|
||||
) {
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user