@@ -13,6 +13,7 @@ use rustc_infer::infer::outlives::obligations::TypeOutlives;
13
13
use rustc_infer:: infer:: { self , InferCtxt , TyCtxtInferExt } ;
14
14
use rustc_middle:: mir:: ConstraintCategory ;
15
15
use rustc_middle:: query:: Providers ;
16
+ use rustc_middle:: ty:: print:: with_no_trimmed_paths;
16
17
use rustc_middle:: ty:: trait_def:: TraitSpecializationKind ;
17
18
use rustc_middle:: ty:: {
18
19
self , AdtKind , GenericParamDefKind , ToPredicate , Ty , TyCtxt , TypeFoldable , TypeSuperVisitable ,
@@ -110,8 +111,6 @@ where
110
111
111
112
let assumed_wf_types = wfcx. ocx . assumed_wf_types_and_report_errors ( param_env, body_def_id) ?;
112
113
113
- let implied_bounds = infcx. implied_bounds_tys ( param_env, body_def_id, assumed_wf_types) ;
114
-
115
114
let errors = wfcx. select_all_or_error ( ) ;
116
115
if !errors. is_empty ( ) {
117
116
let err = infcx. err_ctxt ( ) . report_fulfillment_errors ( errors) ;
@@ -126,9 +125,60 @@ where
126
125
}
127
126
}
128
127
128
+ let infcx_compat = infcx. fork ( ) ;
129
+
130
+ debug ! ( ?assumed_wf_types) ;
131
+ let implied_bounds = infcx. implied_bounds_tys ( param_env, & assumed_wf_types) ;
129
132
let outlives_env = OutlivesEnvironment :: with_bounds ( param_env, implied_bounds) ;
130
133
131
- wfcx. ocx . resolve_regions_and_report_errors ( body_def_id, & outlives_env) ?;
134
+ let errors = infcx. resolve_regions ( & outlives_env) ;
135
+ if errors. is_empty ( ) {
136
+ return Ok ( ( ) ) ;
137
+ }
138
+
139
+ let implied_bounds =
140
+ infcx_compat. implied_bounds_tys_compat ( param_env, body_def_id, & assumed_wf_types) ;
141
+ let outlives_env = OutlivesEnvironment :: with_bounds ( param_env, implied_bounds) ;
142
+ let errors_compat = infcx_compat. resolve_regions ( & outlives_env) ;
143
+ if !errors_compat. is_empty ( ) {
144
+ return Err ( infcx_compat. err_ctxt ( ) . report_region_errors ( body_def_id, & errors_compat) ) ;
145
+ }
146
+
147
+ // We don't want to emit this for dependents of Bevy, for now.
148
+ for ty in assumed_wf_types. iter ( ) {
149
+ match ty. kind ( ) {
150
+ ty:: Adt ( def, _) => {
151
+ let adt_did = with_no_trimmed_paths ! ( infcx. tcx. def_path_str( def. 0 . did) ) ;
152
+ if adt_did == "bevy_ecs::system::ParamSet" {
153
+ return Ok ( ( ) ) ;
154
+ }
155
+ }
156
+ _ => { }
157
+ }
158
+ }
159
+
160
+ let hir_id = tcx. local_def_id_to_hir_id ( body_def_id) ;
161
+ let ( lint_level, _) = tcx
162
+ . lint_level_at_node ( rustc_session:: lint:: builtin:: IMPLIED_BOUNDS_FROM_TRAIT_IMPL , hir_id) ;
163
+ tcx. struct_span_lint_hir (
164
+ rustc_session:: lint:: builtin:: IMPLIED_BOUNDS_FROM_TRAIT_IMPL ,
165
+ hir_id,
166
+ tcx. def_span ( body_def_id) ,
167
+ format ! ( "{} is missing necessary lifetime bounds" , tcx. def_descr( body_def_id. into( ) ) ) ,
168
+ |lint| {
169
+ if !lint_level. is_error ( ) {
170
+ lint. note (
171
+ "to get more detailed errors, use `#[deny(implied_bounds_from_trait_impl)]`" ,
172
+ )
173
+ } else {
174
+ lint. note ( "more concrete lifetime errors are emitted below" )
175
+ }
176
+ } ,
177
+ ) ;
178
+ if true || lint_level. is_error ( ) {
179
+ infcx. err_ctxt ( ) . report_region_errors ( body_def_id, & errors) ;
180
+ }
181
+
132
182
infcx. tainted_by_errors ( ) . error_reported ( )
133
183
}
134
184
@@ -717,7 +767,7 @@ fn resolve_regions_with_wf_tys<'tcx>(
717
767
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
718
768
let outlives_environment = OutlivesEnvironment :: with_bounds (
719
769
param_env,
720
- infcx. implied_bounds_tys ( param_env, id, wf_tys. clone ( ) ) ,
770
+ infcx. implied_bounds_tys_compat ( param_env, id, wf_tys) ,
721
771
) ;
722
772
let region_bound_pairs = outlives_environment. region_bound_pairs ( ) ;
723
773
0 commit comments