@@ -11,6 +11,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
11
11
use rustc_hir:: lang_items:: LangItem ;
12
12
use rustc_infer:: infer:: BoundRegionConversionTime :: HigherRankedType ;
13
13
use rustc_infer:: infer:: { DefineOpaqueTypes , InferOk } ;
14
+ use rustc_middle:: traits:: select:: MetadataCastKind ;
14
15
use rustc_middle:: traits:: { BuiltinImplSource , SignatureMismatchData } ;
15
16
use rustc_middle:: ty:: {
16
17
self , GenericArgs , GenericArgsRef , GenericParamDefKind , ToPolyTraitRef , ToPredicate ,
@@ -51,22 +52,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
51
52
ImplSource :: Builtin ( BuiltinImplSource :: Misc , data)
52
53
}
53
54
54
- MetadataCastCandidate { require_eq } => {
55
- let data = if require_eq {
56
- let source = obligation. self_ty ( ) . skip_binder ( ) ;
57
- let target = obligation. predicate . skip_binder ( ) . trait_ref . args . type_at ( 1 ) ;
58
-
59
- let InferOk { obligations, .. } = self
60
- . infcx
61
- . at ( & obligation. cause , obligation. param_env )
62
- . sub ( DefineOpaqueTypes :: No , source, target)
63
- . map_err ( |_| Unimplemented ) ?;
64
-
65
- obligations
66
- } else {
67
- Vec :: new ( )
68
- } ;
69
-
55
+ MetadataCastCandidate ( kind) => {
56
+ let data = self . confirm_metadata_cast_candidate ( obligation, kind) ?;
70
57
ImplSource :: Builtin ( BuiltinImplSource :: Misc , data)
71
58
}
72
59
@@ -291,6 +278,37 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
291
278
obligations
292
279
}
293
280
281
+ fn confirm_metadata_cast_candidate (
282
+ & mut self ,
283
+ obligation : & PolyTraitObligation < ' tcx > ,
284
+ kind : MetadataCastKind < ' tcx > ,
285
+ ) -> Result < Vec < PredicateObligation < ' tcx > > , SelectionError < ' tcx > > {
286
+ match kind {
287
+ MetadataCastKind :: Unconditional => Ok ( Vec :: new ( ) ) ,
288
+ MetadataCastKind :: Subtype => {
289
+ let source = obligation. self_ty ( ) . skip_binder ( ) ;
290
+ let target = obligation. predicate . skip_binder ( ) . trait_ref . args . type_at ( 1 ) ;
291
+
292
+ let InferOk { obligations, .. } = self
293
+ . infcx
294
+ . at ( & obligation. cause , obligation. param_env )
295
+ . sub ( DefineOpaqueTypes :: No , source, target)
296
+ . map_err ( |_| Unimplemented ) ?;
297
+
298
+ Ok ( obligations)
299
+ }
300
+ MetadataCastKind :: Dyn ( source, target) => {
301
+ let InferOk { obligations, .. } = self
302
+ . infcx
303
+ . at ( & obligation. cause , obligation. param_env )
304
+ . eq ( DefineOpaqueTypes :: No , source, target)
305
+ . map_err ( |_| Unimplemented ) ?;
306
+
307
+ Ok ( obligations)
308
+ }
309
+ }
310
+ }
311
+
294
312
#[ instrument( level = "debug" , skip( self ) ) ]
295
313
fn confirm_transmutability_candidate (
296
314
& mut self ,
0 commit comments