Change:
Pretty straightforward. The idea is to plug logic into a template. This seems like something that should/could work. Playground link: <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
"smaller": Error:
claim
release-assignment is not structural match so this should not compile. We probably shouldn't ICE here though :laughing: cc
It shouldn't be, but it currently is. To fix it you need to change , .

Discussion:
} if let Some(non_sm_ty) = structural { <del> let adt_def = match non_sm_ty { traits::NonStructuralMatchTy::Adt(adt_def) => adt_def, </del> <ins> let msg = match non_sm_ty { traits::NonStructuralMatchTy::Adt(adt_def) => { let path = self.tcx().def_path_str(adt_def.did); format!( "to use a constant of type `{}` in a pattern,  `{}` must be annotated with `#[derive(PartialEq, Eq)]`", path, path, ) } traits::NonStructuralMatchTy::Dynamic => { format!("trait objects cannot be used in patterns") } </ins> traits::NonStructuralMatchTy::Param => { bug!("use of constant whose type is a parameter inside a pattern") } }; <del> let path = self.tcx().def_path_str(adt_def.did); let make_msg = || -> String { format!( "to use a constant of type `{}` in a pattern,  `{}` must be annotated with `#[derive(PartialEq, Eq)]`", path, path, ) }; </del> // double-check there even *is* a semantic `PartialEq` to dispatch to. //

if !ty_is_partial_eq { // span_fatal avoids ICE from resolution of non-existent method (rare case). <del> self.tcx().sess.span_fatal(self.span, &make_msg()); </del> <ins> self.tcx().sess.span_fatal(self.span, &msg); </ins> } else if mir_structural_match_violation { self.tcx().struct_span_lint_hir( lint::builtin::INDIRECT_STRUCTURAL_MATCH, self.id, self.span, <del> |lint| lint.build(&make_msg()).emit(), </del> <ins> |lint| lint.build(&msg).emit(), </ins> ); } else { debug!(

pub enum NonStructuralMatchTy<'tcx> { Adt(&'tcx AdtDef), Param, <ins> Dynamic, </ins> } /// This method traverses the structure of `ty`, trying to find an

self.found = Some(NonStructuralMatchTy::Param); return true; // Stop visiting. } <ins> ty::Dynamic(..) => { self.found = Some(NonStructuralMatchTy::Dynamic); return true; // Stop visiting. } </ins> ty::RawPtr(..) => { // structural-match ignores substructure of // `*const _`/`*mut _`, so skip `super_visit_with`.

<ins> #![feature(const_generics)] //~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash trait A {} struct B; impl A for B {} fn test<const T: &'static dyn A>() { //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]` to be used unimplemented!() } fn main() { test::<{ &B }>(); } </ins>

<ins> warning: the feature `const_generics` is incomplete and may cause the compiler to crash --> $DIR/issue-63322-forbid-dyn.rs:1:12 | LL | #![feature(const_generics)] |            ^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default error[E0741]: `&'static (dyn A + 'static)` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter --> $DIR/issue-63322-forbid-dyn.rs:8:18 | LL | fn test<const T: &'static dyn A>() { |                  ^^^^^^^^^^^^^^ `&'static (dyn A + 'static)` doesn't derive both `PartialEq` and `Eq` error: aborting due to previous error; 1 warning emitted For more information about this error, try `rustc --explain E0741`. </ins>

<ins> const F: &'static dyn Send = &7u32; fn main() { let a: &dyn Send = &7u32; match a { F => panic!(), //~^ ERROR trait objects cannot be used in patterns _ => {} } } </ins>

<ins> error: trait objects cannot be used in patterns --> $DIR/issue-70972-dyn-trait.rs:6:9 | LL |         F => panic!(), |         ^ error: aborting due to previous error </ins>