@@ -85,33 +85,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8585 } )
8686 }
8787
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
8989 /// version (resolve_vars_if_possible), this version will
9090 /// also select obligations if it seems useful, in an effort
9191 /// to get more type information.
9292 // FIXME(-Znext-solver): A lot of the calls to this method should
9393 // probably be `try_structurally_resolve_type` or `structurally_resolve_type` instead.
9494 #[ 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 {
9699 // No Infer()? Nothing needs doing.
97- if !ty . has_non_region_infer ( ) {
100+ if !t . has_non_region_infer ( ) {
98101 debug ! ( "no inference var, nothing needs doing" ) ;
99- return ty ;
102+ return t ;
100103 }
101104
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 ;
107110 }
108111
109112 // If not, try resolving pending obligations as much as
110113 // possible. This can help substantially when there are
111114 // indirect dependencies that don't seem worth tracking
112115 // precisely.
113116 self . select_obligations_where_possible ( |_| { } ) ;
114- self . resolve_vars_if_possible ( ty )
117+ self . resolve_vars_if_possible ( t )
115118 }
116119
117120 pub ( crate ) fn record_deferred_call_resolution (
@@ -1454,7 +1457,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14541457 sp : Span ,
14551458 ct : ty:: Const < ' tcx > ,
14561459 ) -> 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 ) ;
14581461
14591462 if self . next_trait_solver ( )
14601463 && let ty:: ConstKind :: Unevaluated ( ..) = ct. kind ( )
@@ -1510,6 +1513,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15101513 }
15111514 }
15121515
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+
15131542 pub ( crate ) fn with_breakable_ctxt < F : FnOnce ( ) -> R , R > (
15141543 & self ,
15151544 id : HirId ,
0 commit comments