@@ -6,7 +6,8 @@ use rustc_hir as hir;
66use rustc_hir:: def:: DefKind ;
77use rustc_hir:: def_id:: { DefId , LocalDefId } ;
88use rustc_middle:: ty:: {
9- self , GenericPredicates , ImplTraitInTraitData , Ty , TyCtxt , TypeVisitable , TypeVisitor , Upcast ,
9+ self , GenericPredicates , ImplTraitInTraitData , Ty , TyCtxt , TypeVisitable , TypeVisitableExt ,
10+ TypeVisitor , Upcast ,
1011} ;
1112use rustc_middle:: { bug, span_bug} ;
1213use rustc_span:: symbol:: Ident ;
@@ -107,6 +108,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
107108 return ty:: GenericPredicates {
108109 parent : Some ( tcx. parent ( def_id. to_def_id ( ) ) ) ,
109110 predicates : tcx. arena . alloc_from_iter ( predicates) ,
111+ errored_due_to_unconstrained_params : Ok ( ( ) ) ,
110112 } ;
111113 }
112114
@@ -128,6 +130,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
128130 return ty:: GenericPredicates {
129131 parent : Some ( impl_def_id) ,
130132 predicates : tcx. arena . alloc_from_iter ( impl_predicates) ,
133+ errored_due_to_unconstrained_params : trait_assoc_predicates
134+ . errored_due_to_unconstrained_params ,
131135 } ;
132136 }
133137
@@ -153,6 +157,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
153157 // We use an `IndexSet` to preserve order of insertion.
154158 // Preserving the order of insertion is important here so as not to break UI tests.
155159 let mut predicates: FxIndexSet < ( ty:: Clause < ' _ > , Span ) > = FxIndexSet :: default ( ) ;
160+ let mut errored_due_to_unconstrained_params = Ok ( ( ) ) ;
156161
157162 let hir_generics = node. generics ( ) . unwrap_or ( NO_GENERICS ) ;
158163 if let Node :: Item ( item) = node {
@@ -319,11 +324,16 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
319324 if let Node :: Item ( & Item { kind : ItemKind :: Impl { .. } , .. } ) = node {
320325 let self_ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
321326 let trait_ref = tcx. impl_trait_ref ( def_id) . map ( ty:: EarlyBinder :: instantiate_identity) ;
322- cgp:: setup_constraining_predicates (
323- tcx,
324- & mut predicates,
325- trait_ref,
326- & mut cgp:: parameters_for_impl ( tcx, self_ty, trait_ref) ,
327+ let mut input_parameters = cgp:: parameters_for_impl ( tcx, self_ty, trait_ref) ;
328+ cgp:: setup_constraining_predicates ( tcx, & mut predicates, trait_ref, & mut input_parameters) ;
329+ errored_due_to_unconstrained_params = errored_due_to_unconstrained_params. and (
330+ self_ty. error_reported ( ) . and ( trait_ref. error_reported ( ) ) . and_then ( |( ) | {
331+ crate :: impl_wf_check:: enforce_impl_params_are_constrained (
332+ tcx,
333+ def_id,
334+ input_parameters,
335+ )
336+ } ) ,
327337 ) ;
328338 }
329339
@@ -338,6 +348,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
338348 ty:: GenericPredicates {
339349 parent : generics. parent ,
340350 predicates : tcx. arena . alloc_from_iter ( predicates) ,
351+ errored_due_to_unconstrained_params,
341352 }
342353}
343354
@@ -507,6 +518,8 @@ pub(super) fn explicit_predicates_of<'tcx>(
507518 ty:: GenericPredicates {
508519 parent : predicates_and_bounds. parent ,
509520 predicates : tcx. arena . alloc_slice ( & predicates) ,
521+ errored_due_to_unconstrained_params : predicates_and_bounds
522+ . errored_due_to_unconstrained_params ,
510523 }
511524 }
512525 } else {
@@ -558,6 +571,8 @@ pub(super) fn explicit_predicates_of<'tcx>(
558571 return GenericPredicates {
559572 parent : parent_preds. parent ,
560573 predicates : { tcx. arena . alloc_from_iter ( filtered_predicates) } ,
574+ errored_due_to_unconstrained_params : parent_preds
575+ . errored_due_to_unconstrained_params ,
561576 } ;
562577 }
563578 gather_explicit_predicates_of ( tcx, def_id)
0 commit comments