@@ -279,8 +279,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
279
279
/// fall back to subtyping (`unify_and`).
280
280
fn coerce_from_inference_variable ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> CoerceResult < ' tcx > {
281
281
debug ! ( "coerce_from_inference_variable(a={:?}, b={:?})" , a, b) ;
282
- assert ! ( a. is_ty_var( ) && self . shallow_resolve( a) == a) ;
283
- assert ! ( self . shallow_resolve( b) == b) ;
282
+ debug_assert ! ( a. is_ty_var( ) && self . shallow_resolve( a) == a) ;
283
+ debug_assert ! ( self . shallow_resolve( b) == b) ;
284
284
285
285
if b. is_ty_var ( ) {
286
286
// Two unresolved type variables: create a `Coerce` predicate.
@@ -324,6 +324,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
324
324
mutbl_b : hir:: Mutability ,
325
325
) -> CoerceResult < ' tcx > {
326
326
debug ! ( "coerce_borrowed_pointer(a={:?}, b={:?})" , a, b) ;
327
+ debug_assert ! ( self . shallow_resolve( a) == a) ;
328
+ debug_assert ! ( self . shallow_resolve( b) == b) ;
327
329
328
330
// If we have a parameter of type `&M T_a` and the value
329
331
// provided is `expr`, we will be adding an implicit borrow,
@@ -515,10 +517,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
515
517
///
516
518
/// [unsized coercion](https://doc.rust-lang.org/reference/type-coercions.html#unsized-coercions)
517
519
#[ instrument( skip( self ) , level = "debug" ) ]
518
- fn coerce_unsized ( & self , mut source : Ty < ' tcx > , mut target : Ty < ' tcx > ) -> CoerceResult < ' tcx > {
519
- source = self . shallow_resolve ( source) ;
520
- target = self . shallow_resolve ( target) ;
520
+ fn coerce_unsized ( & self , source : Ty < ' tcx > , target : Ty < ' tcx > ) -> CoerceResult < ' tcx > {
521
521
debug ! ( ?source, ?target) ;
522
+ debug_assert ! ( self . shallow_resolve( source) == source) ;
523
+ debug_assert ! ( self . shallow_resolve( target) == target) ;
522
524
523
525
// We don't apply any coercions incase either the source or target
524
526
// aren't sufficiently well known but tend to instead just equate
@@ -801,6 +803,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
801
803
/// - `Pin<Box<T>>` as `Pin<&mut T>`
802
804
#[ instrument( skip( self ) , level = "trace" ) ]
803
805
fn coerce_pin_ref ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> CoerceResult < ' tcx > {
806
+ debug_assert ! ( self . shallow_resolve( a) == a) ;
807
+ debug_assert ! ( self . shallow_resolve( b) == b) ;
808
+
804
809
// We need to make sure the two types are compatible for coercion.
805
810
// Then we will build a ReborrowPin adjustment and return that as an InferOk.
806
811
@@ -849,6 +854,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
849
854
b : Ty < ' tcx > ,
850
855
adjustment : Option < Adjust > ,
851
856
) -> CoerceResult < ' tcx > {
857
+ debug_assert ! ( self . shallow_resolve( b) == b) ;
858
+
852
859
self . commit_if_ok ( |snapshot| {
853
860
let outer_universe = self . infcx . universe ( ) ;
854
861
@@ -889,24 +896,19 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
889
896
fn_ty_a : ty:: PolyFnSig < ' tcx > ,
890
897
b : Ty < ' tcx > ,
891
898
) -> CoerceResult < ' tcx > {
892
- //! Attempts to coerce from the type of a Rust function item
893
- //! into a closure or a `proc`.
894
- //!
895
-
896
- let b = self . shallow_resolve ( b) ;
897
899
debug ! ( ?fn_ty_a, ?b, "coerce_from_fn_pointer" ) ;
900
+ debug_assert ! ( self . shallow_resolve( b) == b) ;
898
901
899
902
self . coerce_from_safe_fn ( fn_ty_a, b, None )
900
903
}
901
904
902
905
fn coerce_from_fn_item ( & self , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> CoerceResult < ' tcx > {
903
- //! Attempts to coerce from the type of a Rust function item
904
- //! into a closure or a `proc`.
906
+ debug ! ( "coerce_from_fn_item(a={:?}, b={:?})" , a, b) ;
907
+ debug_assert ! ( self . shallow_resolve( a) == a) ;
908
+ debug_assert ! ( self . shallow_resolve( b) == b) ;
905
909
906
- let b = self . shallow_resolve ( b) ;
907
910
let InferOk { value : b, mut obligations } =
908
911
self . at ( & self . cause , self . param_env ) . normalize ( b) ;
909
- debug ! ( "coerce_from_fn_item(a={:?}, b={:?})" , a, b) ;
910
912
911
913
match b. kind ( ) {
912
914
ty:: FnPtr ( _, b_hdr) => {
@@ -956,18 +958,17 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
956
958
}
957
959
}
958
960
961
+ /// Attempts to coerce from the type of a non-capturing closure
962
+ /// into a function pointer.
959
963
fn coerce_closure_to_fn (
960
964
& self ,
961
965
a : Ty < ' tcx > ,
962
966
closure_def_id_a : DefId ,
963
967
args_a : GenericArgsRef < ' tcx > ,
964
968
b : Ty < ' tcx > ,
965
969
) -> CoerceResult < ' tcx > {
966
- //! Attempts to coerce from the type of a non-capturing closure
967
- //! into a function pointer.
968
- //!
969
-
970
- let b = self . shallow_resolve ( b) ;
970
+ debug_assert ! ( self . shallow_resolve( a) == a) ;
971
+ debug_assert ! ( self . shallow_resolve( b) == b) ;
971
972
972
973
match b. kind ( ) {
973
974
// At this point we haven't done capture analysis, which means
@@ -1011,6 +1012,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
1011
1012
mutbl_b : hir:: Mutability ,
1012
1013
) -> CoerceResult < ' tcx > {
1013
1014
debug ! ( "coerce_raw_ptr(a={:?}, b={:?})" , a, b) ;
1015
+ debug_assert ! ( self . shallow_resolve( a) == a) ;
1016
+ debug_assert ! ( self . shallow_resolve( b) == b) ;
1014
1017
1015
1018
let ( is_ref, mt_a) = match * a. kind ( ) {
1016
1019
ty:: Ref ( _, ty, mutbl) => ( true , ty:: TypeAndMut { ty, mutbl } ) ,
0 commit comments