@@ -85,33 +85,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
85
85
} )
86
86
}
87
87
88
- /// Resolves type and const variables in `ty ` if possible. Unlike the infcx
88
+ /// Resolves type and const variables in `t ` if possible. Unlike the infcx
89
89
/// version (resolve_vars_if_possible), this version will
90
90
/// also select obligations if it seems useful, in an effort
91
91
/// to get more type information.
92
92
// FIXME(-Znext-solver): A lot of the calls to this method should
93
93
// probably be `try_structurally_resolve_type` or `structurally_resolve_type` instead.
94
94
#[ instrument( skip( self ) , level = "debug" , ret) ]
95
- pub ( crate ) fn resolve_vars_with_obligations ( & self , mut ty : Ty < ' tcx > ) -> Ty < ' tcx > {
95
+ pub ( crate ) fn resolve_vars_with_obligations < T : TypeFoldable < TyCtxt < ' tcx > > > (
96
+ & self ,
97
+ mut t : T ,
98
+ ) -> T {
96
99
// No Infer()? Nothing needs doing.
97
- if !ty . has_non_region_infer ( ) {
100
+ if !t . has_non_region_infer ( ) {
98
101
debug ! ( "no inference var, nothing needs doing" ) ;
99
- return ty ;
102
+ return t ;
100
103
}
101
104
102
- // If `ty ` is a type variable, see whether we already know what it is.
103
- ty = self . resolve_vars_if_possible ( ty ) ;
104
- if !ty . has_non_region_infer ( ) {
105
- debug ! ( ?ty ) ;
106
- return ty ;
105
+ // If `t ` is a type variable, see whether we already know what it is.
106
+ t = self . resolve_vars_if_possible ( t ) ;
107
+ if !t . has_non_region_infer ( ) {
108
+ debug ! ( ?t ) ;
109
+ return t ;
107
110
}
108
111
109
112
// If not, try resolving pending obligations as much as
110
113
// possible. This can help substantially when there are
111
114
// indirect dependencies that don't seem worth tracking
112
115
// precisely.
113
116
self . select_obligations_where_possible ( |_| { } ) ;
114
- self . resolve_vars_if_possible ( ty )
117
+ self . resolve_vars_if_possible ( t )
115
118
}
116
119
117
120
pub ( crate ) fn record_deferred_call_resolution (
@@ -1454,7 +1457,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1454
1457
sp : Span ,
1455
1458
ct : ty:: Const < ' tcx > ,
1456
1459
) -> ty:: Const < ' tcx > {
1457
- // FIXME(min_const_generic_exprs): We could process obligations here if `ct` is a var.
1460
+ let ct = self . resolve_vars_with_obligations ( ct ) ;
1458
1461
1459
1462
if self . next_trait_solver ( )
1460
1463
&& let ty:: ConstKind :: Unevaluated ( ..) = ct. kind ( )
@@ -1510,6 +1513,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1510
1513
}
1511
1514
}
1512
1515
1516
+ pub ( crate ) fn structurally_resolve_const (
1517
+ & self ,
1518
+ sp : Span ,
1519
+ ct : ty:: Const < ' tcx > ,
1520
+ ) -> ty:: Const < ' tcx > {
1521
+ let ct = self . try_structurally_resolve_const ( sp, ct) ;
1522
+
1523
+ if !ct. is_ct_infer ( ) {
1524
+ ct
1525
+ } else {
1526
+ let e = self . tainted_by_errors ( ) . unwrap_or_else ( || {
1527
+ self . err_ctxt ( )
1528
+ . emit_inference_failure_err (
1529
+ self . body_id ,
1530
+ sp,
1531
+ ct. into ( ) ,
1532
+ TypeAnnotationNeeded :: E0282 ,
1533
+ true ,
1534
+ )
1535
+ . emit ( )
1536
+ } ) ;
1537
+ // FIXME: Infer `?ct = {const error}`?
1538
+ ty:: Const :: new_error ( self . tcx , e)
1539
+ }
1540
+ }
1541
+
1513
1542
pub ( crate ) fn with_breakable_ctxt < F : FnOnce ( ) -> R , R > (
1514
1543
& self ,
1515
1544
id : HirId ,
0 commit comments