Change:
<!-- Thank you for filing a bug report! Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. If you cannot produce a minimal reproduction case (something that would work in isolation), please provide the steps or even link to a repository that causes the problematic output to occur. -- The current output is: Ideally the output should look like: I'd like it to say "try to use a unit variant like "FarmAnimal::Cow" instead". For example, here's what happens if you use Tuple syntax instead of Struct syntax: So I'd like the new diagnostic to look something like: <!-- If the problem is not self-explanatory, please provide a rationale for the change. --<!-- If dramatically different output is caused by small changes, consider also adding them here. 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. The output might also be different depending on the Edition. --<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
This is an example Ferrous Systems uses in our trainings, and some of our participants have tripped over this lack of suggestion here. The compiler DOES provide diagnostics when you use a struct syntax instead of a tuple syntax.
Alternatively the help could suggest a more direct: "Remove the parenthesis here".
claim
I just wanted to mention , and I wanted to thank you personally for implementing this diagnostics improvement so quickly! Let me know if you have a blog or twitter you'd like us to link to (rather than your GH profile).
Hello, linking to my GH profile is fine. I did not know I would contribute to such an interesting learning experience. Anyway thank you for mentioning me in your blog post .

Discussion:
_ => false, }; <ins> let find_span = |source: &PathSource<'_>, err: &mut DiagnosticBuilder<'_>| { match source { PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. })) | PathSource::TupleStruct(span, _) => { // We want the main underline to cover the suggested code as well for // cleaner output. err.set_span(*span); *span } _ => span, } }; </ins> let mut bad_struct_syntax_suggestion = |def_id: DefId| { let (followed_by_brace, closing_brace) = self.followed_by_brace(span);

} } PathSource::Expr(_) | PathSource::TupleStruct(..) | PathSource::Pat => { <del> let span = match &source { PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. })) | PathSource::TupleStruct(span, _) => { // We want the main underline to cover the suggested code as well for // cleaner output. err.set_span(*span); *span } _ => span, }; </del> <ins> let span = find_span(&source, err); </ins> if let Some(span) = self.def_span(def_id) { err.span_label(span, &format!("`{}` defined here", path_str)); }

) if ns == ValueNS => { bad_struct_syntax_suggestion(def_id); } <ins> (Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id), _) if ns == ValueNS => { match source { PathSource::Expr(_) | PathSource::TupleStruct(..) | PathSource::Pat => { let span = find_span(&source, err); if let Some(span) = self.def_span(def_id) { err.span_label(span, &format!("`{}` defined here", path_str)); } err.span_suggestion( span, &format!("use this syntax instead"), format!("{path_str}"), Applicability::MaybeIncorrect, ); } _ => return false, } } </ins> (Res::Def(DefKind::Ctor(_, CtorKind::Fn), def_id), _) if ns == ValueNS => { if let Some(span) = self.def_span(def_id) { err.span_label(span, &format!("`{}` defined here", path_str));

error[E0532]: expected tuple struct or tuple variant, found unit struct `Empty2` --> $DIR/empty-struct-unit-pat.rs:21:9 | <ins> LL | struct Empty2; | -------------- `Empty2` defined here ... </ins> LL |         Empty2() => () <del> |         ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6` </del> <ins> |         ^^^^^^^^ </ins> | ::: $DIR/auxiliary/empty-struct.rs:3:1 | LL | pub struct XEmpty6(); | --------------------- similarly named tuple struct `XEmpty6` defined here <ins> | help: use this syntax instead | LL |         Empty2 => () |         ^^^^^^ help: a tuple struct with a similar name exists | LL |         XEmpty6() => () |         ^^^^^^^ </ins> error[E0532]: expected tuple struct or tuple variant, found unit struct `XEmpty2` --> $DIR/empty-struct-unit-pat.rs:24:9 | LL |         XEmpty2() => () <del> |         ^^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6` </del> <ins> |         ^^^^^^^^^ </ins> | <del> ::: $DIR/auxiliary/empty-struct.rs:3:1 </del> <ins> ::: $DIR/auxiliary/empty-struct.rs:2:1 </ins> | <ins> LL | pub struct XEmpty2; | ------------------- `XEmpty2` defined here </ins> LL | pub struct XEmpty6(); | --------------------- similarly named tuple struct `XEmpty6` defined here <ins> | help: use this syntax instead | LL |         XEmpty2 => () |         ^^^^^^^ help: a tuple struct with a similar name exists | LL |         XEmpty6() => () |         ^^^^^^^ </ins> error[E0532]: expected tuple struct or tuple variant, found unit struct `Empty2` --> $DIR/empty-struct-unit-pat.rs:28:9 | <ins> LL | struct Empty2; | -------------- `Empty2` defined here ... </ins> LL |         Empty2(..) => () <del> |         ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6` </del> <ins> |         ^^^^^^^^^^ </ins> | ::: $DIR/auxiliary/empty-struct.rs:3:1 | LL | pub struct XEmpty6(); | --------------------- similarly named tuple struct `XEmpty6` defined here <ins> | help: use this syntax instead | LL |         Empty2 => () |         ^^^^^^ help: a tuple struct with a similar name exists | LL |         XEmpty6(..) => () |         ^^^^^^^ </ins> error[E0532]: expected tuple struct or tuple variant, found unit struct `XEmpty2` --> $DIR/empty-struct-unit-pat.rs:32:9 | LL |         XEmpty2(..) => () <del> |         ^^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6` </del> <ins> |         ^^^^^^^^^^^ </ins> | <del> ::: $DIR/auxiliary/empty-struct.rs:3:1 </del> <ins> ::: $DIR/auxiliary/empty-struct.rs:2:1 </ins> | <ins> LL | pub struct XEmpty2; | ------------------- `XEmpty2` defined here </ins> LL | pub struct XEmpty6(); | --------------------- similarly named tuple struct `XEmpty6` defined here <ins> | help: use this syntax instead | LL |         XEmpty2 => () |         ^^^^^^^ help: a tuple struct with a similar name exists | LL |         XEmpty6(..) => () |         ^^^^^^^ </ins> error[E0532]: expected tuple struct or tuple variant, found unit variant `E::Empty4` --> $DIR/empty-struct-unit-pat.rs:37:9 | <ins> LL |     Empty4 |     ------ `E::Empty4` defined here ... </ins> LL |         E::Empty4() => () <del> |         ^^^^^^^^^ not a tuple struct or tuple variant </del> <ins> |         ^^^^^^^^^^^ help: use this syntax instead: `E::Empty4` </ins> error[E0532]: expected tuple struct or tuple variant, found unit variant `XE::XEmpty4` --> $DIR/empty-struct-unit-pat.rs:41:9 | LL |         XE::XEmpty4() => (), <del> |         ^^^^------- |             | |             help: a tuple variant with a similar name exists: `XEmpty5` </del> <ins> |         ^^^^^^^^^^^^^ </ins> | <del> ::: $DIR/auxiliary/empty-struct.rs:8:5 </del> <ins> ::: $DIR/auxiliary/empty-struct.rs:7:5 </ins> | <ins> LL |     XEmpty4, |     ------- `XE::XEmpty4` defined here </ins> LL |     XEmpty5(), |     --------- similarly named tuple variant `XEmpty5` defined here <ins> | help: use this syntax instead | LL |         XE::XEmpty4 => (), |         ^^^^^^^^^^^ help: a tuple variant with a similar name exists | LL |         XE::XEmpty5() => (), |             ^^^^^^^ </ins> error[E0532]: expected tuple struct or tuple variant, found unit variant `E::Empty4` --> $DIR/empty-struct-unit-pat.rs:46:9 | <ins> LL |     Empty4 |     ------ `E::Empty4` defined here ... </ins> LL |         E::Empty4(..) => () <del> |         ^^^^^^^^^ not a tuple struct or tuple variant </del> <ins> |         ^^^^^^^^^^^^^ help: use this syntax instead: `E::Empty4` </ins> error[E0532]: expected tuple struct or tuple variant, found unit variant `XE::XEmpty4` --> $DIR/empty-struct-unit-pat.rs:50:9 | LL |         XE::XEmpty4(..) => (), <del> |         ^^^^------- |             | |             help: a tuple variant with a similar name exists: `XEmpty5` </del> <ins> |         ^^^^^^^^^^^^^^^ </ins> | <del> ::: $DIR/auxiliary/empty-struct.rs:8:5 </del> <ins> ::: $DIR/auxiliary/empty-struct.rs:7:5 </ins> | <ins> LL |     XEmpty4, |     ------- `XE::XEmpty4` defined here </ins> LL |     XEmpty5(), |     --------- similarly named tuple variant `XEmpty5` defined here <ins> | help: use this syntax instead | LL |         XE::XEmpty4 => (), |         ^^^^^^^^^^^ help: a tuple variant with a similar name exists | LL |         XE::XEmpty5(..) => (), |             ^^^^^^^ </ins> error: aborting due to 8 previous errors

error[E0532]: expected tuple struct or tuple variant, found unit struct `S` --> $DIR/issue-32004.rs:16:9 | <ins> LL | struct S; | --------- `S` defined here ... </ins> LL |         S(()) => {} <del> |         ^ not a tuple struct or tuple variant </del> <ins> |         ^^^^^ help: use this syntax instead: `S` </ins> error: aborting due to 2 previous errors

error[E0532]: expected tuple struct or tuple variant, found unit variant `E::A` --> $DIR/issue-pr29383.rs:9:14 | <ins> LL |     A, |     - `E::A` defined here ... </ins> LL |         Some(E::A(..)) => {} <del> |              ^^^^ not a tuple struct or tuple variant </del> <ins> |              ^^^^^^^^ help: use this syntax instead: `E::A` </ins> error[E0532]: expected tuple struct or tuple variant, found unit variant `E::B` --> $DIR/issue-pr29383.rs:11:14 | <ins> LL |     B, |     - `E::B` defined here ... </ins> LL |         Some(E::B(..)) => {} <del> |              ^^^^ not a tuple struct or tuple variant </del> <ins> |              ^^^^^^^^ help: use this syntax instead: `E::B` </ins> error: aborting due to 2 previous errors

error[E0532]: expected tuple struct or tuple variant, found unit variant `Color::NoColor` --> $DIR/match-pattern-field-mismatch-2.rs:12:11 | <ins> LL |         NoColor, |         ------- `Color::NoColor` defined here ... </ins> LL |           Color::NoColor(_) => { } <del> |           ^^^^^^^^^^^^^^ not a tuple struct or tuple variant </del> <ins> |           ^^^^^^^^^^^^^^^^^ help: use this syntax instead: `Color::NoColor` </ins> error: aborting due to previous error

| LL |     B(isize, isize), |     --------------- similarly named tuple variant `B` defined here <ins> LL |     C(isize, isize, isize), LL |     D |     - `A::D` defined here </ins> ... LL |         A::D(_) => (), <del> |         ^^^- |            | |            help: a tuple variant with a similar name exists: `B` </del> <ins> |         ^^^^^^^ | help: use this syntax instead | LL |         A::D => (), |         ^^^^ help: a tuple variant with a similar name exists | LL |         A::B(_) => (), |            ^ </ins> error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields --> $DIR/pattern-error-continue.rs:17:9

<ins> // test for suggestion on fieldless enum variant #[derive(PartialEq, Debug)] enum FarmAnimal { Worm, Cow, Bull, Chicken { num_eggs: usize }, Dog (String), } fn what_does_the_animal_say(animal: &FarmAnimal) { let noise = match animal { FarmAnimal::Cow(_) => "moo".to_string(), //~^ ERROR expected tuple struct or tuple variant, found unit variant `FarmAnimal::Cow` FarmAnimal::Chicken(_) => "cluck, cluck!".to_string(), //~^ ERROR expected tuple struct or tuple variant, found struct variant `FarmAnimal::Chicken` FarmAnimal::Dog{..} => "woof!".to_string(), _ => todo!() }; println!("{:?} says: {:?}", animal, noise); } fn main() {} </ins>

<ins> error[E0532]: expected tuple struct or tuple variant, found unit variant `FarmAnimal::Cow` --> $DIR/issue-84700.rs:15:9 | LL |     Cow, |     --- `FarmAnimal::Cow` defined here ... LL |         FarmAnimal::Cow(_) => "moo".to_string(), |         ^^^^^^^^^^^^^^^^^^ help: use this syntax instead: `FarmAnimal::Cow` error[E0532]: expected tuple struct or tuple variant, found struct variant `FarmAnimal::Chicken` --> $DIR/issue-84700.rs:17:9 | LL |     Chicken { num_eggs: usize }, |     --------------------------- `FarmAnimal::Chicken` defined here ... LL |         FarmAnimal::Chicken(_) => "cluck, cluck!".to_string(), |         ^^^^^^^^^^^^^^^^^^^^^^ help: use struct pattern syntax instead: `FarmAnimal::Chicken { num_eggs }` error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0532`. </ins>