@@ -1465,16 +1465,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1465
1465
}
1466
1466
}
1467
1467
1468
- /// Resolves `typ` by a single level if `typ` is a type variable .
1468
+ /// Try to resolve `ty` to a structural type, normalizing aliases .
1469
1469
///
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) ;
1478
1475
1479
1476
if self . next_trait_solver ( )
1480
1477
&& let ty:: Alias ( ty:: Projection , _) = ty. kind ( )
@@ -1483,15 +1480,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1483
1480
. at ( & self . misc ( sp) , self . param_env )
1484
1481
. structurally_normalize ( ty, & mut * * self . fulfillment_cx . borrow_mut ( ) )
1485
1482
{
1486
- Ok ( normalized_ty) => {
1487
- ty = normalized_ty;
1488
- } ,
1483
+ Ok ( normalized_ty) => normalized_ty,
1489
1484
Err ( errors) => {
1490
1485
let guar = self . err_ctxt ( ) . report_fulfillment_errors ( & errors) ;
1491
1486
return self . tcx . ty_error ( guar) ;
1492
1487
}
1493
1488
}
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) ;
1495
1504
1496
1505
if !ty. is_ty_var ( ) {
1497
1506
ty
0 commit comments