Change:
I wrote code that looked like this while not having my brain turned on 100%. Due to said brain not functioning, it took me a while to understand what rustc was trying to tell me with the message pointing to the pattern with the text . sure looked like a unit variant to me! What rustc was trying to tell me was that the definition of the variant was a struct variant ("found struct variant") and my pattern wasn't matching the definition ("this pattern you specified looks like it's trying to match a variant that is not a unit struct, unit variant or constant"). The change I needed to make was adding to my pattern, because I was trying to distinguish different variants from each other, not use pieces within the variants. Suggesting seems like a decent starting point to me, but there could definitely be cases I'm not considering here and I'm totally open to hearing that No response No response <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
WEIRD this PR looks like it implements what I wish rustc did: but the test files in that PR say they're for and I'm getting
Aha ok this test shows that for tuple variants, rustc will suggest adding : and that test also shows that rustc isn't suggesting anything for struct variants!
Aha and it looks like adding struct fields was more complex so that's why it wasn't done?
claim

Discussion:
use fn_ctxt::FnCtxt; use rustc_data_structures::unord::UnordSet; use rustc_errors::codes::*; <del> use rustc_errors::{struct_span_code_err, Applicability, ErrorGuaranteed}; </del> <ins> use rustc_errors::{pluralize, struct_span_code_err, Applicability, ErrorGuaranteed}; </ins> use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::Visitor;

err.multipart_suggestion_verbose(descr, suggestion, Applicability::MaybeIncorrect); err } <ins> Res::Def(DefKind::Variant, _) if expr.is_none() => { err.span_label(span, format!("not a {expected}")); let fields = &tcx.expect_variant_res(res).fields.raw; let span = qpath.span().shrink_to_hi().to(span.shrink_to_hi()); let (msg, sugg) = if fields.is_empty() { ("use the struct variant pattern syntax".to_string(), " {}".to_string()) } else { let msg = format!( "the struct variant's field{s} {are} being ignored", s = pluralize!(fields.len()), are = pluralize!("is", fields.len()) ); let fields = fields .iter() .map(|field| format!("{}: _", field.name.to_ident_string())) .collect::<Vec<_>>() .join(", "); let sugg = format!(" {{ {} }}", fields); (msg, sugg) }; err.span_suggestion_verbose( qpath.span().shrink_to_hi().to(span.shrink_to_hi()), msg, sugg, Applicability::HasPlaceholders, ); err } </ins> _ => err.with_span_label(span, format!("not a {expected}")), } .emit()

| LL |         E::Empty3 => () |         ^^^^^^^^^ not a unit struct, unit variant or constant <ins> | help: use the struct variant pattern syntax | LL |         E::Empty3 {} => () |                   ++ </ins> error[E0533]: expected unit struct, unit variant or constant, found struct variant `XE::XEmpty3` --> $DIR/empty-struct-braces-pat-1.rs:31:9 | LL |         XE::XEmpty3 => () |         ^^^^^^^^^^^ not a unit struct, unit variant or constant <ins> | help: use the struct variant pattern syntax | LL |         XE::XEmpty3 {} => () |                     ++ </ins> error: aborting due to 2 previous errors

| LL |         E::Empty3() => () |         ^^^^^^^^^^^ not a tuple struct or tuple variant <ins> | help: use the struct variant pattern syntax | LL |         E::Empty3 {} => () |                   ~~ </ins> error[E0164]: expected tuple struct or tuple variant, found struct variant `XE::XEmpty3` --> $DIR/empty-struct-braces-pat-3.rs:21:9 | LL |         XE::XEmpty3() => () |         ^^^^^^^^^^^^^ not a tuple struct or tuple variant <ins> | help: use the struct variant pattern syntax | LL |         XE::XEmpty3 {} => () |                     ~~ </ins> error[E0164]: expected tuple struct or tuple variant, found struct variant `E::Empty3` --> $DIR/empty-struct-braces-pat-3.rs:25:9 | LL |         E::Empty3(..) => () |         ^^^^^^^^^^^^^ not a tuple struct or tuple variant <ins> | help: use the struct variant pattern syntax | LL |         E::Empty3 {} => () |                   ~~ </ins> error[E0164]: expected tuple struct or tuple variant, found struct variant `XE::XEmpty3` --> $DIR/empty-struct-braces-pat-3.rs:29:9 | LL |         XE::XEmpty3(..) => () |         ^^^^^^^^^^^^^^^ not a tuple struct or tuple variant <ins> | help: use the struct variant pattern syntax | LL |         XE::XEmpty3 {} => () |                     ~~ </ins> error: aborting due to 4 previous errors

| LL |         MyEnum::Struct => "", |         ^^^^^^^^^^^^^^ not a unit struct, unit variant or constant <ins> | help: the struct variant's field is being ignored | LL |         MyEnum::Struct { s: _ } => "", |                        ++++++++ </ins> error: aborting due to 2 previous errors

| LL |         Enum::Foo(a, b) => {} |         ^^^^^^^^^^^^^^^ not a tuple struct or tuple variant <ins> | help: the struct variant's fields are being ignored | LL |         Enum::Foo { a: _, b: _ } => {} |                   ~~~~~~~~~~~~~~ </ins> error[E0769]: tuple variant `Enum::Bar` written as struct variant --> $DIR/recover-from-bad-variant.rs:12:9

| LL |         FarmAnimal::Chicken(_) => "cluck, cluck!".to_string(), |         ^^^^^^^^^^^^^^^^^^^^^^ not a tuple struct or tuple variant <ins> | help: the struct variant's field is being ignored | LL |         FarmAnimal::Chicken { num_eggs: _ } => "cluck, cluck!".to_string(), |                             ~~~~~~~~~~~~~~~ </ins> error: aborting due to 2 previous errors

| LL |     let Alias::Braced = panic!(); |         ^^^^^^^^^^^^^ not a unit struct, unit variant or constant <ins> | help: use the struct variant pattern syntax | LL |     let Alias::Braced {} = panic!(); |                       ++ </ins> error[E0164]: expected tuple struct or tuple variant, found struct variant `Alias::Braced` --> $DIR/incorrect-variant-form-through-alias-caught.rs:12:9 | LL |     let Alias::Braced(..) = panic!(); |         ^^^^^^^^^^^^^^^^^ not a tuple struct or tuple variant <ins> | help: use the struct variant pattern syntax | LL |     let Alias::Braced {} = panic!(); |                       ~~ </ins> error[E0618]: expected function, found enum variant `Alias::Unit` --> $DIR/incorrect-variant-form-through-alias-caught.rs:15:5