diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 7b479067ecd..2f1d377585d 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1754,12 +1754,7 @@ impl<'a> Parser<'a> { ident: None, vis, id: DUMMY_NODE_ID, - ty: P(Ty { - id: DUMMY_NODE_ID, - kind: TyKind::Err, - span: DUMMY_SP, - tokens: None, - }), + ty: self.mk_ty(DUMMY_SP, TyKind::Err), attrs, is_placeholder: false, }); diff --git a/tests/ui/parser/macro/macro-expand-to-field.rs b/tests/ui/parser/macro/macro-expand-to-field.rs index fd1d408e726..155872f7a5d 100644 --- a/tests/ui/parser/macro/macro-expand-to-field.rs +++ b/tests/ui/parser/macro/macro-expand-to-field.rs @@ -1,4 +1,4 @@ -#![no_main] +// compile-flags: --crate-type=lib macro_rules! field { ($name:ident:$type:ty) => { @@ -13,9 +13,10 @@ macro_rules! variant { } struct Struct { - field!(bar:u128), //~ NOTE macros cannot expand to struct fields - //~^ ERROR unexpected token: `!` - //~^^ NOTE unexpected token after this + field!(bar:u128), + //~^ NOTE macros cannot expand to struct fields + //~| ERROR unexpected token: `!` + //~| NOTE unexpected token after this a: u32, b: u32, field!(recovers:()), //~ NOTE macros cannot expand to struct fields @@ -24,34 +25,46 @@ struct Struct { } enum EnumVariant { - variant!(whoops), //~ NOTE macros cannot expand to enum variants - //~^ ERROR unexpected token: `!` - //~^^ NOTE unexpected token after this + variant!(whoops), + //~^ NOTE macros cannot expand to enum variants + //~| ERROR unexpected token: `!` + //~| NOTE unexpected token after this U32, F64, - variant!(recovers), //~ NOTE macros cannot expand to enum variants - //~^ ERROR unexpected token: `!` - //~^^ NOTE unexpected token after this + variant!(recovers), + //~^ NOTE macros cannot expand to enum variants + //~| ERROR unexpected token: `!` + //~| NOTE unexpected token after this + Data { + field!(x:u32), + //~^ NOTE macros cannot expand to struct fields + //~| ERROR unexpected token: `!` + //~| NOTE unexpected token after this + } } enum EnumVariantField { Named { - field!(oopsies:()), //~ NOTE macros cannot expand to struct fields - //~^ ERROR unexpected token: `!` - //~^^ unexpected token after this - field!(oopsies2:()), //~ NOTE macros cannot expand to struct fields - //~^ ERROR unexpected token: `!` - //~^^ unexpected token after this + field!(oopsies:()), + //~^ NOTE macros cannot expand to struct fields + //~| ERROR unexpected token: `!` + //~| unexpected token after this + field!(oopsies2:()), + //~^ NOTE macros cannot expand to struct fields + //~| ERROR unexpected token: `!` + //~| unexpected token after this }, } union Union { A: u32, - field!(oopsies:()), //~ NOTE macros cannot expand to union fields - //~^ ERROR unexpected token: `!` - //~^^ unexpected token after this + field!(oopsies:()), + //~^ NOTE macros cannot expand to union fields + //~| ERROR unexpected token: `!` + //~| unexpected token after this B: u32, - field!(recovers:()), //~ NOTE macros cannot expand to union fields - //~^ ERROR unexpected token: `!` - //~^^ unexpected token after this + field!(recovers:()), + //~^ NOTE macros cannot expand to union fields + //~| ERROR unexpected token: `!` + //~| unexpected token after this } diff --git a/tests/ui/parser/macro/macro-expand-to-field.stderr b/tests/ui/parser/macro/macro-expand-to-field.stderr index 108b68b481f..adcd032f5c0 100644 --- a/tests/ui/parser/macro/macro-expand-to-field.stderr +++ b/tests/ui/parser/macro/macro-expand-to-field.stderr @@ -7,7 +7,7 @@ LL | field!(bar:u128), = note: macros cannot expand to struct fields error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:21:10 + --> $DIR/macro-expand-to-field.rs:22:10 | LL | field!(recovers:()), | ^ unexpected token after this @@ -15,7 +15,7 @@ LL | field!(recovers:()), = note: macros cannot expand to struct fields error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:27:12 + --> $DIR/macro-expand-to-field.rs:28:12 | LL | variant!(whoops), | ^ unexpected token after this @@ -23,7 +23,7 @@ LL | variant!(whoops), = note: macros cannot expand to enum variants error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:32:12 + --> $DIR/macro-expand-to-field.rs:34:12 | LL | variant!(recovers), | ^ unexpected token after this @@ -33,13 +33,21 @@ LL | variant!(recovers), error: unexpected token: `!` --> $DIR/macro-expand-to-field.rs:39:14 | +LL | field!(x:u32), + | ^ unexpected token after this + | + = note: macros cannot expand to struct fields + +error: unexpected token: `!` + --> $DIR/macro-expand-to-field.rs:48:14 + | LL | field!(oopsies:()), | ^ unexpected token after this | = note: macros cannot expand to struct fields error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:42:14 + --> $DIR/macro-expand-to-field.rs:52:14 | LL | field!(oopsies2:()), | ^ unexpected token after this @@ -47,7 +55,7 @@ LL | field!(oopsies2:()), = note: macros cannot expand to struct fields error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:50:10 + --> $DIR/macro-expand-to-field.rs:61:10 | LL | field!(oopsies:()), | ^ unexpected token after this @@ -55,12 +63,12 @@ LL | field!(oopsies:()), = note: macros cannot expand to union fields error: unexpected token: `!` - --> $DIR/macro-expand-to-field.rs:54:10 + --> $DIR/macro-expand-to-field.rs:66:10 | LL | field!(recovers:()), | ^ unexpected token after this | = note: macros cannot expand to union fields -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors diff --git a/tests/ui/parser/macro/macro-expand-to-match-arm.rs b/tests/ui/parser/macro/macro-expand-to-match-arm.rs index c176e8bbd9d..39d1d065ed9 100644 --- a/tests/ui/parser/macro/macro-expand-to-match-arm.rs +++ b/tests/ui/parser/macro/macro-expand-to-match-arm.rs @@ -8,8 +8,9 @@ fn main() { let x = Some(1); match x { Some(1) => {}, - arm!(None => {}), //~ NOTE macros cannot expand to match arms - //~^ ERROR unexpected `,` in pattern + arm!(None => {}), + //~^ NOTE macros cannot expand to match arms + //~| ERROR unexpected `,` in pattern // doesn't recover Some(2) => {}, _ => {},