@@ -8,7 +8,7 @@ use rustc_errors::codes::*;
8
8
use rustc_hir:: def:: { CtorKind , DefKind } ;
9
9
use rustc_hir:: { Node , intravisit} ;
10
10
use rustc_infer:: infer:: { RegionVariableOrigin , TyCtxtInferExt } ;
11
- use rustc_infer:: traits:: Obligation ;
11
+ use rustc_infer:: traits:: { Obligation , ObligationCauseCode } ;
12
12
use rustc_lint_defs:: builtin:: {
13
13
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS , UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS ,
14
14
} ;
@@ -305,8 +305,32 @@ fn check_opaque_meets_bounds<'tcx>(
305
305
_ => re,
306
306
} ) ;
307
307
308
- let misc_cause = traits:: ObligationCause :: misc ( span, def_id) ;
308
+ // HACK: We eagerly instantiate some bounds to report better errors for them...
309
+ // This isn't necessary for correctness, since we register these bounds when
310
+ // equating the opaque below, but we should clean this up in the new solver.
311
+ for ( predicate, pred_span) in
312
+ tcx. explicit_item_bounds ( def_id) . iter_instantiated_copied ( tcx, args)
313
+ {
314
+ let predicate = predicate. fold_with ( & mut BottomUpFolder {
315
+ tcx,
316
+ ty_op : |ty| if ty == opaque_ty { hidden_ty } else { ty } ,
317
+ lt_op : |lt| lt,
318
+ ct_op : |ct| ct,
319
+ } ) ;
320
+
321
+ ocx. register_obligation ( Obligation :: new (
322
+ tcx,
323
+ ObligationCause :: new (
324
+ span,
325
+ def_id,
326
+ ObligationCauseCode :: WhereClause ( def_id. to_def_id ( ) , pred_span) ,
327
+ ) ,
328
+ param_env,
329
+ predicate,
330
+ ) ) ;
331
+ }
309
332
333
+ let misc_cause = ObligationCause :: misc ( span, def_id) ;
310
334
// FIXME: We should just register the item bounds here, rather than equating.
311
335
match ocx. eq ( & misc_cause, param_env, opaque_ty, hidden_ty) {
312
336
Ok ( ( ) ) => { }
0 commit comments