@@ -111,23 +111,21 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
111
111
}
112
112
113
113
if let Some ( non_sm_ty) = structural {
114
- let adt_def = match non_sm_ty {
115
- traits:: NonStructuralMatchTy :: Adt ( adt_def) => adt_def,
116
- traits:: NonStructuralMatchTy :: Param => {
117
- bug ! ( "use of constant whose type is a parameter inside a pattern" )
114
+ let msg = match non_sm_ty {
115
+ traits:: NonStructuralMatchTy :: Adt ( adt_def) => {
116
+ let path = self . tcx ( ) . def_path_str ( adt_def. did ) ;
117
+ format ! (
118
+ "to use a constant of type `{}` in a pattern, \
119
+ `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
120
+ path, path,
121
+ )
118
122
}
119
123
traits:: NonStructuralMatchTy :: Dynamic => {
120
- bug ! ( "use of a trait object inside a pattern" )
124
+ format ! ( "trait objects cannot be used in patterns" )
125
+ }
126
+ traits:: NonStructuralMatchTy :: Param => {
127
+ bug ! ( "use of constant whose type is a parameter inside a pattern" )
121
128
}
122
- } ;
123
- let path = self . tcx ( ) . def_path_str ( adt_def. did ) ;
124
-
125
- let make_msg = || -> String {
126
- format ! (
127
- "to use a constant of type `{}` in a pattern, \
128
- `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
129
- path, path,
130
- )
131
129
} ;
132
130
133
131
// double-check there even *is* a semantic `PartialEq` to dispatch to.
@@ -158,13 +156,13 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
158
156
159
157
if !ty_is_partial_eq {
160
158
// span_fatal avoids ICE from resolution of non-existent method (rare case).
161
- self . tcx ( ) . sess . span_fatal ( self . span , & make_msg ( ) ) ;
159
+ self . tcx ( ) . sess . span_fatal ( self . span , & msg ) ;
162
160
} else if mir_structural_match_violation {
163
161
self . tcx ( ) . struct_span_lint_hir (
164
162
lint:: builtin:: INDIRECT_STRUCTURAL_MATCH ,
165
163
self . id ,
166
164
self . span ,
167
- |lint| lint. build ( & make_msg ( ) ) . emit ( ) ,
165
+ |lint| lint. build ( & msg ) . emit ( ) ,
168
166
) ;
169
167
} else {
170
168
debug ! (
0 commit comments