Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --<!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details
Regression in nightly-2023-08-05 Regression in cc
This is probably because it recovers from it and gives the field no name. We should probably give it the macro's name instead I believe this is the offending line:
An alternative approach would be to directly throw an error instead of allowing the parser to continue, imo.
label -needs-triage

Discussion:
attrs: AttrVec, ) -> PResult<'a, FieldDef> { let name = self.parse_field_ident(adt_ty, lo)?; <del> // Parse the macro invocation and recover </del> if self.token.kind == token::Not { if let Err(mut err) = self.unexpected::<FieldDef>() { <del> err.subdiagnostic(MacroExpandsToAdtField { adt_ty }).emit(); self.bump(); self.parse_delim_args()?; return Ok(FieldDef { span: DUMMY_SP, ident: None, vis, id: DUMMY_NODE_ID, ty: self.mk_ty(DUMMY_SP, TyKind::Err), attrs, is_placeholder: false, }); </del> <ins> // Encounter the macro invocation err.subdiagnostic(MacroExpandsToAdtField { adt_ty }); return Err(err); </ins> } } self.expect_field_ty_separator()?;

// compile-flags: --crate-type=lib <ins> // https://github.com/rust-lang/rust/issues/113766 </ins> macro_rules! field { ($name:ident:$type:ty) => { $name:$type

} struct Struct { <ins> //~^ NOTE while parsing this struct </ins> field!(bar:u128), //~^ NOTE macros cannot expand to struct fields //~| ERROR unexpected token: `!` //~| NOTE unexpected token after this a: u32, b: u32, <del> field!(recovers:()), //~ NOTE macros cannot expand to struct fields //~^ ERROR unexpected token: `!` //~^^ NOTE unexpected token after this </del> <ins> field!(recovers:()), </ins> } enum EnumVariant {

//~^ NOTE macros cannot expand to enum variants //~| ERROR unexpected token: `!` //~| NOTE unexpected token after this <del> Data { </del> <ins> Data { //~ NOTE while parsing this struct </ins> field!(x:u32), //~^ NOTE macros cannot expand to struct fields //~| ERROR unexpected token: `!`

} enum EnumVariantField { <del> Named { </del> <ins> Named { //~ NOTE while parsing this struct </ins> field!(oopsies:()), //~^ NOTE macros cannot expand to struct fields //~| ERROR unexpected token: `!` //~| unexpected token after this field!(oopsies2:()), <del> //~^ NOTE macros cannot expand to struct fields //~| ERROR unexpected token: `!` //~| unexpected token after this </del> }, } union Union { <ins> //~^ NOTE while parsing this union </ins> A: u32, field!(oopsies:()), //~^ NOTE macros cannot expand to union fields //~| ERROR unexpected token: `!` <del> //~| unexpected token after this </del> <ins> //~| NOTE unexpected token after this </ins> B: u32, field!(recovers:()), <del> //~^ NOTE macros cannot expand to union fields </del> <ins> } // https://github.com/rust-lang/rust/issues/114636 #[derive(Debug)] pub struct Lazy { //~^ NOTE while parsing this struct unreachable!() //~^ NOTE macros cannot expand to struct fields </ins> //~| ERROR unexpected token: `!` <del> //~| unexpected token after this </del> <ins> //~| NOTE unexpected token after this </ins> } <ins> fn main() {} </ins>

error: unexpected token: `!` <del> --> $DIR/macro-expand-to-field.rs:16:10 </del> <ins> --> $DIR/macro-expand-to-field.rs:19:10 </ins> | <ins> LL | struct Struct { |        ------ while parsing this struct LL | </ins> LL |     field!(bar:u128), |          ^ unexpected token after this | = note: macros cannot expand to struct fields error: unexpected token: `!` <del> --> $DIR/macro-expand-to-field.rs:22:10 | LL |     field!(recovers:()), |          ^ unexpected token after this | = note: macros cannot expand to struct fields error: unexpected token: `!` --> $DIR/macro-expand-to-field.rs:28:12 </del> <ins> --> $DIR/macro-expand-to-field.rs:29:12 </ins> | LL |     variant!(whoops), |            ^ unexpected token after this

= note: macros cannot expand to enum variants error: unexpected token: `!` <del> --> $DIR/macro-expand-to-field.rs:34:12 </del> <ins> --> $DIR/macro-expand-to-field.rs:35:12 </ins> | LL |     variant!(recovers), |            ^ unexpected token after this

= note: macros cannot expand to enum variants error: unexpected token: `!` <del> --> $DIR/macro-expand-to-field.rs:39:14 </del> <ins> --> $DIR/macro-expand-to-field.rs:40:14 </ins> | <ins> LL |     Data { |     ---- while parsing this struct </ins> LL |         field!(x:u32), |              ^ unexpected token after this | = note: macros cannot expand to struct fields error: unexpected token: `!` <del> --> $DIR/macro-expand-to-field.rs:48:14 </del> <ins> --> $DIR/macro-expand-to-field.rs:49:14 </ins> | <ins> LL |     Named { |     ----- while parsing this struct </ins> LL |         field!(oopsies:()), |              ^ unexpected token after this | = note: macros cannot expand to struct fields error: unexpected token: `!` <del> --> $DIR/macro-expand-to-field.rs:52:14 | LL |         field!(oopsies2:()), |              ^ unexpected token after this | = note: macros cannot expand to struct fields error: unexpected token: `!` --> $DIR/macro-expand-to-field.rs:61:10 </del> <ins> --> $DIR/macro-expand-to-field.rs:60:10 </ins> | <ins> LL | union Union { |       ----- while parsing this union ... </ins> LL |     field!(oopsies:()), |          ^ unexpected token after this | = note: macros cannot expand to union fields error: unexpected token: `!` <del> --> $DIR/macro-expand-to-field.rs:66:10 </del> <ins> --> $DIR/macro-expand-to-field.rs:73:16 </ins> | <del> LL |     field!(recovers:()), |          ^ unexpected token after this </del> <ins> LL | pub struct Lazy { |            ---- while parsing this struct LL | LL |     unreachable!() |                ^ unexpected token after this </ins> | <del> = note: macros cannot expand to union fields </del> <ins> = note: macros cannot expand to struct fields </ins> <del> error: aborting due to 9 previous errors </del> <ins> error: aborting due to 7 previous errors </ins>