@@ -12,12 +12,13 @@ use rustc_hir::lang_items::LangItem;
12
12
use rustc_hir:: { def:: Res , ItemKind , Node , PathSegment } ;
13
13
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
14
14
use rustc_infer:: infer:: { RegionVariableOrigin , TyCtxtInferExt } ;
15
+ use rustc_infer:: traits:: Obligation ;
15
16
use rustc_middle:: hir:: nested_filter;
16
17
use rustc_middle:: ty:: fold:: TypeFoldable ;
17
18
use rustc_middle:: ty:: layout:: { LayoutError , MAX_SIMD_LANES } ;
18
19
use rustc_middle:: ty:: subst:: GenericArgKind ;
19
20
use rustc_middle:: ty:: util:: { Discr , IntTypeExt } ;
20
- use rustc_middle:: ty:: { self , ParamEnv , Ty , TyCtxt } ;
21
+ use rustc_middle:: ty:: { self , ParamEnv , ToPredicate , Ty , TyCtxt } ;
21
22
use rustc_session:: lint:: builtin:: { UNINHABITED_STATIC , UNSUPPORTED_CALLING_CONVENTIONS } ;
22
23
use rustc_span:: symbol:: sym;
23
24
use rustc_span:: { self , MultiSpan , Span } ;
@@ -674,6 +675,13 @@ fn check_opaque_meets_bounds<'tcx>(
674
675
}
675
676
}
676
677
678
+ // Additionally require the hidden type to be well-formed with only the generics of the opaque type.
679
+ // Defining use functions may have more bounds than the opaque type, which is ok, as long as the
680
+ // hidden type is well formed even without those bounds.
681
+ let predicate =
682
+ ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( hidden_type. into ( ) ) ) . to_predicate ( tcx) ;
683
+ inh. register_predicate ( Obligation :: new ( misc_cause, param_env, predicate) ) ;
684
+
677
685
// Check that all obligations are satisfied by the implementation's
678
686
// version.
679
687
let errors = inh. fulfillment_cx . borrow_mut ( ) . select_all_or_error ( & infcx) ;
0 commit comments