diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index 70cf2f2a4598..24b29b468ad5 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -524,7 +524,11 @@ impl<'a> State<'a> { self.maybe_print_comment(field.span.lo()); self.print_outer_attributes(&field.attrs); self.print_visibility(&field.vis); - self.print_ident(field.ident.unwrap()); + if let Some(ident) = field.ident { + self.print_ident(ident); + } else { + self.word("_"); + } self.word_nbsp(":"); self.print_type(&field.ty); self.word(","); diff --git a/tests/crashes/140333.rs b/tests/crashes/140333.rs deleted file mode 100644 index cec1100e6ada..000000000000 --- a/tests/crashes/140333.rs +++ /dev/null @@ -1,9 +0,0 @@ -//@ known-bug: #140333 -fn a() -> impl b< - [c; { - struct d { - #[a] - bar: e, - } - }], ->; diff --git a/tests/ui/structs/struct-field-ident-issue-140333.rs b/tests/ui/structs/struct-field-ident-issue-140333.rs new file mode 100644 index 000000000000..f1e062afd502 --- /dev/null +++ b/tests/ui/structs/struct-field-ident-issue-140333.rs @@ -0,0 +1,12 @@ +fn a() -> impl b< //~ ERROR cannot find trait `b` in this scope + [c; { //~ ERROR cannot find type `c` in this scope + struct D { + #[a] //~ ERROR annot find attribute `a` in this scope + bar: e, //~ ERROR cannot find type `e` in this scope + } + }], +> { + todo!("need to implement") +} + +fn main() {} diff --git a/tests/ui/structs/struct-field-ident-issue-140333.stderr b/tests/ui/structs/struct-field-ident-issue-140333.stderr new file mode 100644 index 000000000000..5d7195590d43 --- /dev/null +++ b/tests/ui/structs/struct-field-ident-issue-140333.stderr @@ -0,0 +1,40 @@ +error: cannot find attribute `a` in this scope + --> $DIR/struct-field-ident-issue-140333.rs:4:15 + | +LL | #[a] + | ^ + | + = note: `a` is in scope, but it is a function, not an attribute + +error[E0405]: cannot find trait `b` in this scope + --> $DIR/struct-field-ident-issue-140333.rs:1:16 + | +LL | fn a() -> impl b< + | ^ not found in this scope + +error[E0412]: cannot find type `c` in this scope + --> $DIR/struct-field-ident-issue-140333.rs:2:6 + | +LL | [c; { + | ^ not found in this scope + | +help: you might be missing a type parameter + | +LL | fn a() -> impl b< + | +++ + +error[E0412]: cannot find type `e` in this scope + --> $DIR/struct-field-ident-issue-140333.rs:5:18 + | +LL | bar: e, + | ^ not found in this scope + | +help: you might be missing a type parameter + | +LL | struct D { + | +++ + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0405, E0412. +For more information about an error, try `rustc --explain E0405`.