@@ -2,9 +2,7 @@ use super::combine::{CombineFields, RelationDir};
22use super :: SubregionOrigin ;
33
44use crate :: infer:: combine:: ConstEquateRelation ;
5- use crate :: infer:: { TypeVariableOrigin , TypeVariableOriginKind } ;
65use crate :: traits:: Obligation ;
7- use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
86use rustc_middle:: ty:: relate:: { Cause , Relate , RelateResult , TypeRelation } ;
97use rustc_middle:: ty:: visit:: TypeVisitable ;
108use rustc_middle:: ty:: TyVar ;
@@ -130,39 +128,18 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
130128 ( & ty:: Opaque ( did, ..) , _) | ( _, & ty:: Opaque ( did, ..) )
131129 if self . fields . define_opaque_types && did. is_local ( ) =>
132130 {
133- let mut generalize = |ty, ty_is_expected| {
134- let var = infcx. next_ty_var_id_in_universe (
135- TypeVariableOrigin {
136- kind : TypeVariableOriginKind :: MiscVariable ,
137- span : self . fields . trace . cause . span ,
138- } ,
139- ty:: UniverseIndex :: ROOT ,
140- ) ;
141- self . fields . instantiate ( ty, RelationDir :: SubtypeOf , var, ty_is_expected) ?;
142- Ok ( infcx. tcx . mk_ty_var ( var) )
143- } ;
144- let ( a, b) = if self . a_is_expected { ( a, b) } else { ( b, a) } ;
145- let ( ga, gb) = match ( a. kind ( ) , b. kind ( ) ) {
146- ( & ty:: Opaque ( ..) , _) => ( a, generalize ( b, true ) ?) ,
147- ( _, & ty:: Opaque ( ..) ) => ( generalize ( a, false ) ?, b) ,
148- _ => unreachable ! ( ) ,
149- } ;
150131 self . fields . obligations . extend (
151132 infcx
152- . handle_opaque_type ( ga, gb, true , & self . fields . trace . cause , self . param_env ( ) )
153- // Don't leak any generalized type variables out of this
154- // subtyping relation in the case of a type error.
155- . map_err ( |err| {
156- let ( ga, gb) = self . fields . infcx . resolve_vars_if_possible ( ( ga, gb) ) ;
157- if let TypeError :: Sorts ( sorts) = err && sorts. expected == ga && sorts. found == gb {
158- TypeError :: Sorts ( ExpectedFound { expected : a, found : b } )
159- } else {
160- err
161- }
162- } ) ?
133+ . handle_opaque_type (
134+ a,
135+ b,
136+ self . a_is_expected ,
137+ & self . fields . trace . cause ,
138+ self . param_env ( ) ,
139+ ) ?
163140 . obligations ,
164141 ) ;
165- Ok ( ga )
142+ Ok ( a )
166143 }
167144 // Optimization of GeneratorWitness relation since we know that all
168145 // free regions are replaced with bound regions during construction.
0 commit comments