88use std:: iter;
99
1010use chalk_ir:: { BoundVar , Mutability , TyKind , TyVariableKind , cast:: Cast } ;
11- use hir_def:: {
12- hir:: ExprId ,
13- lang_item:: LangItem ,
14- } ;
11+ use hir_def:: { hir:: ExprId , lang_item:: LangItem } ;
1512use rustc_type_ir:: solve:: Certainty ;
1613use stdx:: always;
1714use triomphe:: Arc ;
1815
1916use crate :: {
20- autoderef:: { Autoderef , AutoderefKind } , db:: HirDatabase , infer:: {
17+ Canonical , FnAbi , FnPointer , FnSig , Goal , InEnvironment , Interner , Lifetime , Substitution ,
18+ TraitEnvironment , Ty , TyBuilder , TyExt ,
19+ autoderef:: { Autoderef , AutoderefKind } ,
20+ db:: HirDatabase ,
21+ infer:: {
2122 Adjust , Adjustment , AutoBorrow , InferOk , InferenceContext , OverloadedDeref , PointerCast ,
2223 TypeError , TypeMismatch ,
23- } , utils:: ClosureSubst , Canonical , FnAbi , FnPointer , FnSig , Goal , InEnvironment , Interner , Lifetime , Substitution , TraitEnvironment , Ty , TyBuilder , TyExt
24+ } ,
25+ utils:: ClosureSubst ,
2426} ;
2527
2628use super :: unify:: InferenceTable ;
@@ -37,11 +39,7 @@ fn simple(kind: Adjust) -> impl FnOnce(Ty) -> Vec<Adjustment> {
3739}
3840
3941/// This always returns `Ok(...)`.
40- fn success (
41- adj : Vec < Adjustment > ,
42- target : Ty ,
43- goals : Vec < InEnvironment < Goal > > ,
44- ) -> CoerceResult {
42+ fn success ( adj : Vec < Adjustment > , target : Ty , goals : Vec < InEnvironment < Goal > > ) -> CoerceResult {
4543 Ok ( InferOk { goals, value : ( adj, target) } )
4644}
4745
@@ -285,8 +283,8 @@ impl InferenceTable<'_> {
285283 to_ty : & Ty ,
286284 coerce_never : CoerceNever ,
287285 ) -> Result < ( Vec < Adjustment > , Ty ) , TypeError > {
288- let from_ty = self . resolve_ty_shallow ( from_ty) ;
289- let to_ty = self . resolve_ty_shallow ( to_ty) ;
286+ let from_ty = self . structurally_resolve_type ( from_ty) ;
287+ let to_ty = self . structurally_resolve_type ( to_ty) ;
290288 match self . coerce_inner ( from_ty, & to_ty, coerce_never) {
291289 Ok ( InferOk { value : ( adjustments, ty) , goals } ) => {
292290 self . register_infer_ok ( InferOk { value : ( ) , goals } ) ;
@@ -302,7 +300,7 @@ impl InferenceTable<'_> {
302300 fn coerce_inner ( & mut self , from_ty : Ty , to_ty : & Ty , coerce_never : CoerceNever ) -> CoerceResult {
303301 if from_ty. is_never ( ) {
304302 if let TyKind :: InferenceVar ( tv, TyVariableKind :: General ) = to_ty. kind ( Interner ) {
305- self . set_diverging ( * tv, TyVariableKind :: General , true ) ;
303+ self . set_diverging ( * tv, TyVariableKind :: General ) ;
306304 }
307305 if coerce_never == CoerceNever :: Yes {
308306 // Subtle: If we are coercing from `!` to `?T`, where `?T` is an unbound
@@ -707,12 +705,9 @@ impl InferenceTable<'_> {
707705
708706 let goal: Goal = coerce_unsized_tref. cast ( Interner ) ;
709707
710- self . commit_if_ok ( |table| {
711- match table. solve_obligation ( goal) {
712- Ok ( Certainty :: Yes ) => Ok ( ( ) ) ,
713- Ok ( Certainty :: Maybe ( _) ) => Ok ( ( ) ) ,
714- Err ( _) => Err ( TypeError ) ,
715- }
708+ self . commit_if_ok ( |table| match table. solve_obligation ( goal) {
709+ Ok ( Certainty :: Yes ) => Ok ( ( ) ) ,
710+ _ => Err ( TypeError ) ,
716711 } ) ?;
717712
718713 let unsize =
0 commit comments