fix #137589
This commit is contained in:
parent
ad27045c31
commit
4bf66c57fa
8 changed files with 87 additions and 6 deletions
|
@ -333,7 +333,10 @@ impl<'sess> AttributeParser<'sess> {
|
|||
{
|
||||
lit
|
||||
} else {
|
||||
let guar = self.dcx().has_errors().unwrap();
|
||||
let guar = self.dcx().span_delayed_bug(
|
||||
args.span().unwrap_or(DUMMY_SP),
|
||||
"expr in place where literal is expected (builtin attr parsing)",
|
||||
);
|
||||
ast::MetaItemLit {
|
||||
symbol: kw::Empty,
|
||||
suffix: None,
|
||||
|
|
|
@ -13,7 +13,7 @@ use rustc_ast_pretty::pprust;
|
|||
use rustc_errors::DiagCtxtHandle;
|
||||
use rustc_hir::{self as hir, AttrPath};
|
||||
use rustc_span::symbol::{Ident, kw};
|
||||
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol};
|
||||
use rustc_span::{ErrorGuaranteed, Span, Symbol};
|
||||
|
||||
pub struct SegmentIterator<'a> {
|
||||
offset: usize,
|
||||
|
@ -127,7 +127,7 @@ impl<'a> ArgParser<'a> {
|
|||
}
|
||||
AttrArgs::Eq { eq_span, expr } => Self::NameValue(NameValueParser {
|
||||
eq_span: *eq_span,
|
||||
value: expr_to_lit(dcx, &expr),
|
||||
value: expr_to_lit(dcx, &expr, *eq_span),
|
||||
value_span: expr.span,
|
||||
}),
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ impl NameValueParser {
|
|||
}
|
||||
}
|
||||
|
||||
fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr) -> MetaItemLit {
|
||||
fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr, span: Span) -> MetaItemLit {
|
||||
// In valid code the value always ends up as a single literal. Otherwise, a dummy
|
||||
// literal suffices because the error is handled elsewhere.
|
||||
if let ExprKind::Lit(token_lit) = expr.kind
|
||||
|
@ -356,8 +356,11 @@ fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr) -> MetaItemLit {
|
|||
{
|
||||
lit
|
||||
} else {
|
||||
let guar = dcx.has_errors().unwrap();
|
||||
MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span: DUMMY_SP }
|
||||
let guar = dcx.span_delayed_bug(
|
||||
span,
|
||||
"expr in place where literal is expected (builtin attr parsing)",
|
||||
);
|
||||
MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
7
tests/ui/attributes/crate-type-macro-empty.rs
Normal file
7
tests/ui/attributes/crate-type-macro-empty.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
// Tests for the issue in #137589
|
||||
#[crate_type = foo!()]
|
||||
//~^ ERROR cannot find macro `foo` in this scope
|
||||
|
||||
macro_rules! foo {} //~ ERROR unexpected end of macro invocation
|
||||
|
||||
fn main() {}
|
20
tests/ui/attributes/crate-type-macro-empty.stderr
Normal file
20
tests/ui/attributes/crate-type-macro-empty.stderr
Normal file
|
@ -0,0 +1,20 @@
|
|||
error: unexpected end of macro invocation
|
||||
--> $DIR/crate-type-macro-empty.rs:5:1
|
||||
|
|
||||
LL | macro_rules! foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
|
||||
|
||||
error: cannot find macro `foo` in this scope
|
||||
--> $DIR/crate-type-macro-empty.rs:2:16
|
||||
|
|
||||
LL | #[crate_type = foo!()]
|
||||
| ^^^ consider moving the definition of `foo` before this call
|
||||
|
|
||||
note: a macro with the same name exists, but it appears later
|
||||
--> $DIR/crate-type-macro-empty.rs:5:14
|
||||
|
|
||||
LL | macro_rules! foo {}
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
9
tests/ui/attributes/crate-type-macro-not-crate.rs
Normal file
9
tests/ui/attributes/crate-type-macro-not-crate.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
// Tests for the issue in #137589
|
||||
|
||||
|
||||
macro_rules! foo {
|
||||
($x:expr) => {"rlib"}
|
||||
}
|
||||
|
||||
#[crate_type = foo!()] //~ ERROR unexpected end of macro invocation
|
||||
fn main() {}
|
17
tests/ui/attributes/crate-type-macro-not-crate.stderr
Normal file
17
tests/ui/attributes/crate-type-macro-not-crate.stderr
Normal file
|
@ -0,0 +1,17 @@
|
|||
error: unexpected end of macro invocation
|
||||
--> $DIR/crate-type-macro-not-crate.rs:8:16
|
||||
|
|
||||
LL | macro_rules! foo {
|
||||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | #[crate_type = foo!()]
|
||||
| ^^^^^^ missing tokens in macro arguments
|
||||
|
|
||||
note: while trying to match meta-variable `$x:expr`
|
||||
--> $DIR/crate-type-macro-not-crate.rs:5:6
|
||||
|
|
||||
LL | ($x:expr) => {"rlib"}
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
8
tests/ui/attributes/crate-type-macro-not-found.rs
Normal file
8
tests/ui/attributes/crate-type-macro-not-found.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Tests for the issue in #137589
|
||||
#[crate_type = foo!()] //~ ERROR cannot find macro `foo` in this scope
|
||||
|
||||
macro_rules! foo {
|
||||
($x:expr) => {"rlib"}
|
||||
}
|
||||
|
||||
fn main() {}
|
14
tests/ui/attributes/crate-type-macro-not-found.stderr
Normal file
14
tests/ui/attributes/crate-type-macro-not-found.stderr
Normal file
|
@ -0,0 +1,14 @@
|
|||
error: cannot find macro `foo` in this scope
|
||||
--> $DIR/crate-type-macro-not-found.rs:2:16
|
||||
|
|
||||
LL | #[crate_type = foo!()]
|
||||
| ^^^ consider moving the definition of `foo` before this call
|
||||
|
|
||||
note: a macro with the same name exists, but it appears later
|
||||
--> $DIR/crate-type-macro-not-found.rs:4:14
|
||||
|
|
||||
LL | macro_rules! foo {
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue