1
+ use std:: assert_matches:: debug_assert_matches;
2
+
1
3
use rustc_hir:: def:: DefKind ;
2
4
use rustc_hir:: def_id:: DefId ;
3
5
use rustc_session:: lint;
@@ -18,14 +20,18 @@ impl<'tcx> TyCtxt<'tcx> {
18
20
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.
19
21
#[ instrument( skip( self ) , level = "debug" ) ]
20
22
pub fn const_eval_poly ( self , def_id : DefId ) -> EvalToConstValueResult < ' tcx > {
23
+ debug_assert_matches ! (
24
+ self . def_kind( def_id) ,
25
+ DefKind :: Const | DefKind :: AnonConst | DefKind :: InlineConst
26
+ ) ;
21
27
// In some situations def_id will have generic parameters within scope, but they aren't allowed
22
28
// to be used. So we can't use `Instance::mono`, instead we feed unresolved generic parameters
23
29
// into `const_eval` which will return `ErrorHandled::TooGeneric` if any of them are
24
30
// encountered.
25
31
let args = GenericArgs :: identity_for_item ( self , def_id) ;
26
- let instance = ty:: Instance :: new ( def_id, args) ;
27
- let cid = GlobalId { instance, promoted : None } ;
28
32
let typing_env = ty:: TypingEnv :: post_analysis ( self , def_id) ;
33
+ let instance = ty:: Instance :: expect_resolve ( self , typing_env, def_id, args, DUMMY_SP ) ;
34
+ let cid = GlobalId { instance, promoted : None } ;
29
35
self . const_eval_global_id ( typing_env, cid, DUMMY_SP )
30
36
}
31
37
@@ -34,14 +40,18 @@ impl<'tcx> TyCtxt<'tcx> {
34
40
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.
35
41
#[ instrument( skip( self ) , level = "debug" ) ]
36
42
pub fn const_eval_poly_to_alloc ( self , def_id : DefId ) -> EvalToAllocationRawResult < ' tcx > {
43
+ debug_assert_matches ! (
44
+ self . def_kind( def_id) ,
45
+ DefKind :: Const | DefKind :: AnonConst | DefKind :: InlineConst
46
+ ) ;
37
47
// In some situations def_id will have generic parameters within scope, but they aren't allowed
38
48
// to be used. So we can't use `Instance::mono`, instead we feed unresolved generic parameters
39
49
// into `const_eval` which will return `ErrorHandled::TooGeneric` if any of them are
40
50
// encountered.
41
51
let args = GenericArgs :: identity_for_item ( self , def_id) ;
42
- let instance = ty:: Instance :: new ( def_id, args) ;
43
- let cid = GlobalId { instance, promoted : None } ;
44
52
let typing_env = ty:: TypingEnv :: post_analysis ( self , def_id) ;
53
+ let instance = ty:: Instance :: expect_resolve ( self , typing_env, def_id, args, DUMMY_SP ) ;
54
+ let cid = GlobalId { instance, promoted : None } ;
45
55
let inputs = self . erase_regions ( typing_env. as_query_input ( cid) ) ;
46
56
self . eval_to_allocation_raw ( inputs)
47
57
}
@@ -203,14 +213,24 @@ impl<'tcx> TyCtxtEnsureOk<'tcx> {
203
213
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.
204
214
#[ instrument( skip( self ) , level = "debug" ) ]
205
215
pub fn const_eval_poly ( self , def_id : DefId ) {
216
+ debug_assert_matches ! (
217
+ self . tcx. def_kind( def_id) ,
218
+ DefKind :: Const | DefKind :: AnonConst | DefKind :: InlineConst
219
+ ) ;
206
220
// In some situations def_id will have generic parameters within scope, but they aren't allowed
207
221
// to be used. So we can't use `Instance::mono`, instead we feed unresolved generic parameters
208
222
// into `const_eval` which will return `ErrorHandled::TooGeneric` if any of them are
209
223
// encountered.
210
224
let args = GenericArgs :: identity_for_item ( self . tcx , def_id) ;
211
- let instance = ty:: Instance :: new ( def_id, self . tcx . erase_regions ( args) ) ;
212
- let cid = GlobalId { instance, promoted : None } ;
213
225
let typing_env = ty:: TypingEnv :: post_analysis ( self . tcx , def_id) ;
226
+ let instance = ty:: Instance :: expect_resolve (
227
+ self . tcx ,
228
+ typing_env,
229
+ def_id,
230
+ self . tcx . erase_regions ( args) ,
231
+ DUMMY_SP ,
232
+ ) ;
233
+ let cid = GlobalId { instance, promoted : None } ;
214
234
// Const-eval shouldn't depend on lifetimes at all, so we can erase them, which should
215
235
// improve caching of queries.
216
236
let inputs = self . tcx . erase_regions ( typing_env. as_query_input ( cid) ) ;
0 commit comments