@@ -1465,16 +1465,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14651465 }
14661466 }
14671467
1468- /// Resolves `typ` by a single level if `typ` is a type variable .
1468+ /// Try to resolve `ty` to a structural type, normalizing aliases .
14691469 ///
1470- /// When the new solver is enabled, this will also attempt to normalize
1471- /// the type if it's a projection (note that it will not deeply normalize
1472- /// projections within the type, just the outermost layer of the type).
1473- ///
1474- /// If no resolution is possible, then an error is reported.
1475- /// Numeric inference variables may be left unresolved.
1476- pub fn structurally_resolve_type ( & self , sp : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1477- let mut ty = self . resolve_vars_with_obligations ( ty) ;
1470+ /// In case there is still ambiguity, the returned type may be an inference
1471+ /// variable. This is different from `structurally_resolve_type` which errors
1472+ /// in this case.
1473+ pub fn try_structurally_resolve_type ( & self , sp : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1474+ let ty = self . resolve_vars_with_obligations ( ty) ;
14781475
14791476 if self . next_trait_solver ( )
14801477 && let ty:: Alias ( ty:: Projection , _) = ty. kind ( )
@@ -1483,15 +1480,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14831480 . at ( & self . misc ( sp) , self . param_env )
14841481 . structurally_normalize ( ty, & mut * * self . fulfillment_cx . borrow_mut ( ) )
14851482 {
1486- Ok ( normalized_ty) => {
1487- ty = normalized_ty;
1488- } ,
1483+ Ok ( normalized_ty) => normalized_ty,
14891484 Err ( errors) => {
14901485 let guar = self . err_ctxt ( ) . report_fulfillment_errors ( & errors) ;
14911486 return self . tcx . ty_error ( guar) ;
14921487 }
14931488 }
1494- }
1489+ } else {
1490+ ty
1491+ }
1492+ }
1493+
1494+ /// Resolves `ty` by a single level if `ty` is a type variable.
1495+ ///
1496+ /// When the new solver is enabled, this will also attempt to normalize
1497+ /// the type if it's a projection (note that it will not deeply normalize
1498+ /// projections within the type, just the outermost layer of the type).
1499+ ///
1500+ /// If no resolution is possible, then an error is reported.
1501+ /// Numeric inference variables may be left unresolved.
1502+ pub fn structurally_resolve_type ( & self , sp : Span , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1503+ let ty = self . try_structurally_resolve_type ( sp, ty) ;
14951504
14961505 if !ty. is_ty_var ( ) {
14971506 ty
0 commit comments