@@ -59,7 +59,10 @@ pub fn type_check<'a, 'gcx, 'tcx>(
59
59
}
60
60
61
61
fn mirbug ( tcx : TyCtxt , span : Span , msg : & str ) {
62
- tcx. sess . diagnostic ( ) . span_bug ( span, msg) ;
62
+ // We sometimes see MIR failures (notably predicate failures) due to
63
+ // the fact that we check rvalue sized predicates here. So use `delay_span_bug`
64
+ // to avoid reporting bugs in those cases.
65
+ tcx. sess . diagnostic ( ) . delay_span_bug ( span, msg) ;
63
66
}
64
67
65
68
macro_rules! span_mirbug {
@@ -171,7 +174,44 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
171
174
) ;
172
175
173
176
let expected_ty = match constant. literal {
174
- Literal :: Value { value } => value. ty ,
177
+ Literal :: Value { value } => {
178
+ if let ConstVal :: Function ( def_id, ..) = value. val {
179
+ let tcx = self . tcx ( ) ;
180
+ let type_checker = & mut self . cx ;
181
+
182
+ // FIXME -- For now, use the substitutions from
183
+ // `value.ty` rather than `value.val`. The
184
+ // renumberer will rewrite them to independent
185
+ // sets of regions; in principle, we ought to
186
+ // derive the type of the `value.val` from "first
187
+ // principles" and equate with value.ty, but as we
188
+ // are transitioning to the miri-based system, we
189
+ // don't have a handy function for that, so for
190
+ // now we just ignore `value.val` regions.
191
+ let substs = match value. ty . sty {
192
+ ty:: TyFnDef ( ty_def_id, substs) => {
193
+ assert_eq ! ( def_id, ty_def_id) ;
194
+ substs
195
+ }
196
+ _ => {
197
+ span_bug ! (
198
+ self . last_span,
199
+ "unexpected type for constant function: {:?}" ,
200
+ value. ty
201
+ )
202
+ }
203
+ } ;
204
+
205
+ let instantiated_predicates =
206
+ tcx. predicates_of ( def_id) . instantiate ( tcx, substs) ;
207
+ let predicates =
208
+ type_checker. normalize ( & instantiated_predicates. predicates , location) ;
209
+ type_checker. prove_predicates ( & predicates, location) ;
210
+ }
211
+
212
+ value. ty
213
+ }
214
+
175
215
Literal :: Promoted { .. } => {
176
216
// FIXME -- promoted MIR return types reference
177
217
// various "free regions" (e.g., scopes and things)
0 commit comments