@@ -101,23 +101,21 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
101
101
cv. ty, structural
102
102
) ;
103
103
if let Some ( non_sm_ty) = structural {
104
- let adt_def = match non_sm_ty {
105
- traits:: NonStructuralMatchTy :: Adt ( adt_def) => adt_def,
106
- traits:: NonStructuralMatchTy :: Param => {
107
- bug ! ( "use of constant whose type is a parameter inside a pattern" )
104
+ let msg = match non_sm_ty {
105
+ traits:: NonStructuralMatchTy :: Adt ( adt_def) => {
106
+ let path = self . tcx ( ) . def_path_str ( adt_def. did ) ;
107
+ format ! (
108
+ "to use a constant of type `{}` in a pattern, \
109
+ `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
110
+ path, path,
111
+ )
108
112
}
109
113
traits:: NonStructuralMatchTy :: Dynamic => {
110
- bug ! ( "use of a trait object inside a pattern" )
114
+ format ! ( "trait objects cannot be used in patterns" )
115
+ }
116
+ traits:: NonStructuralMatchTy :: Param => {
117
+ bug ! ( "use of constant whose type is a parameter inside a pattern" )
111
118
}
112
- } ;
113
- let path = self . tcx ( ) . def_path_str ( adt_def. did ) ;
114
-
115
- let make_msg = || -> String {
116
- format ! (
117
- "to use a constant of type `{}` in a pattern, \
118
- `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
119
- path, path,
120
- )
121
119
} ;
122
120
123
121
// double-check there even *is* a semantic `PartialEq` to dispatch to.
@@ -148,13 +146,13 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
148
146
149
147
if !ty_is_partial_eq {
150
148
// span_fatal avoids ICE from resolution of non-existent method (rare case).
151
- self . tcx ( ) . sess . span_fatal ( self . span , & make_msg ( ) ) ;
149
+ self . tcx ( ) . sess . span_fatal ( self . span , & msg ) ;
152
150
} else {
153
151
self . tcx ( ) . struct_span_lint_hir (
154
152
lint:: builtin:: INDIRECT_STRUCTURAL_MATCH ,
155
153
self . id ,
156
154
self . span ,
157
- |lint| lint. build ( & make_msg ( ) ) . emit ( ) ,
155
+ |lint| lint. build ( & msg ) . emit ( ) ,
158
156
) ;
159
157
}
160
158
}
0 commit comments