Skip to content

Commit 2969bd9

Browse files
committed
Don't emit IMPLIED_BOUNDS_FROM_TRAIT_IMPL for Bevy dependents
1 parent 4d629f5 commit 2969bd9

File tree

9 files changed

+58
-13
lines changed

9 files changed

+58
-13
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ fn check_opaque_meets_bounds<'tcx>(
355355
// Can have different predicates to their defining use
356356
hir::OpaqueTyOrigin::TyAlias { .. } => {
357357
let wf_tys = ocx.assumed_wf_types_and_report_errors(param_env, def_id)?;
358-
let implied_bounds = infcx.implied_bounds_tys_compat(param_env, def_id, wf_tys);
358+
let implied_bounds = infcx.implied_bounds_tys_compat(param_env, def_id, &wf_tys);
359359
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
360360
ocx.resolve_regions_and_report_errors(defining_use_anchor, &outlives_env)?;
361361
}

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ fn compare_method_predicate_entailment<'tcx>(
404404
// lifetime parameters.
405405
let outlives_env = OutlivesEnvironment::with_bounds(
406406
param_env,
407-
infcx.implied_bounds_tys_compat(param_env, impl_m_def_id, wf_tys),
407+
infcx.implied_bounds_tys_compat(param_env, impl_m_def_id, &wf_tys),
408408
);
409409
let errors = infcx.resolve_regions(&outlives_env);
410410
if !errors.is_empty() {
@@ -880,7 +880,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
880880
// lifetime parameters.
881881
let outlives_env = OutlivesEnvironment::with_bounds(
882882
param_env,
883-
infcx.implied_bounds_tys_compat(param_env, impl_m_def_id, wf_tys),
883+
infcx.implied_bounds_tys_compat(param_env, impl_m_def_id, &wf_tys),
884884
);
885885
ocx.resolve_regions_and_report_errors(impl_m_def_id, &outlives_env)?;
886886

@@ -2240,7 +2240,8 @@ pub(super) fn check_type_bounds<'tcx>(
22402240

22412241
// Finally, resolve all regions. This catches wily misuses of
22422242
// lifetime parameters.
2243-
let implied_bounds = infcx.implied_bounds_tys_compat(param_env, impl_ty_def_id, assumed_wf_types);
2243+
let implied_bounds =
2244+
infcx.implied_bounds_tys_compat(param_env, impl_ty_def_id, &assumed_wf_types);
22442245
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
22452246
ocx.resolve_regions_and_report_errors(impl_ty_def_id, &outlives_env)
22462247
}

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
161161
}
162162
let outlives_env = OutlivesEnvironment::with_bounds(
163163
param_env,
164-
infcx.implied_bounds_tys_compat(param_env, impl_m.def_id.expect_local(), implied_wf_types),
164+
infcx.implied_bounds_tys_compat(param_env, impl_m.def_id.expect_local(), &implied_wf_types),
165165
);
166166
let errors = infcx.resolve_regions(&outlives_env);
167167
if !errors.is_empty() {

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_infer::infer::outlives::obligations::TypeOutlives;
1313
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
1414
use rustc_middle::mir::ConstraintCategory;
1515
use rustc_middle::query::Providers;
16+
use rustc_middle::ty::print::with_no_trimmed_paths;
1617
use rustc_middle::ty::trait_def::TraitSpecializationKind;
1718
use rustc_middle::ty::{
1819
self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
@@ -126,6 +127,7 @@ where
126127

127128
let infcx_compat = infcx.fork();
128129

130+
debug!(?assumed_wf_types);
129131
let implied_bounds = infcx.implied_bounds_tys(param_env, &assumed_wf_types);
130132
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
131133

@@ -135,13 +137,26 @@ where
135137
}
136138

137139
let implied_bounds =
138-
infcx_compat.implied_bounds_tys_compat(param_env, body_def_id, assumed_wf_types);
140+
infcx_compat.implied_bounds_tys_compat(param_env, body_def_id, &assumed_wf_types);
139141
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
140142
let errors_compat = infcx_compat.resolve_regions(&outlives_env);
141143
if !errors_compat.is_empty() {
142144
return Err(infcx_compat.err_ctxt().report_region_errors(body_def_id, &errors_compat));
143145
}
144146

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+
145160
let hir_id = tcx.local_def_id_to_hir_id(body_def_id);
146161
let (lint_level, _) = tcx
147162
.lint_level_at_node(rustc_session::lint::builtin::IMPLIED_BOUNDS_FROM_TRAIT_IMPL, hir_id);
@@ -752,7 +767,7 @@ fn resolve_regions_with_wf_tys<'tcx>(
752767
let infcx = tcx.infer_ctxt().build();
753768
let outlives_environment = OutlivesEnvironment::with_bounds(
754769
param_env,
755-
infcx.implied_bounds_tys_compat(param_env, id, wf_tys.clone()),
770+
infcx.implied_bounds_tys_compat(param_env, id, wf_tys),
756771
);
757772
let region_bound_pairs = outlives_environment.region_bound_pairs();
758773

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ fn get_impl_args(
202202
return Err(guar);
203203
}
204204

205-
let implied_bounds = infcx.implied_bounds_tys_compat(param_env, impl1_def_id, assumed_wf_types);
205+
let implied_bounds =
206+
infcx.implied_bounds_tys_compat(param_env, impl1_def_id, &assumed_wf_types);
206207
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
207208
let _ = ocx.resolve_regions_and_report_errors(impl1_def_id, &outlives_env);
208209
let Ok(impl2_args) = infcx.fully_resolve(impl2_args) else {

compiler/rustc_trait_selection/src/traits/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub fn all_fields_implement_trait<'tcx>(
194194
infcx.implied_bounds_tys_compat(
195195
param_env,
196196
parent_cause.body_id,
197-
FxIndexSet::from_iter([self_type]),
197+
&FxIndexSet::from_iter([self_type]),
198198
),
199199
);
200200
let errors = infcx.resolve_regions(&outlives_env);

compiler/rustc_trait_selection/src/traits/outlives_bounds.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub trait InferCtxtExt<'a, 'tcx> {
2323
&'a self,
2424
param_env: ty::ParamEnv<'tcx>,
2525
body_id: LocalDefId,
26-
tys: FxIndexSet<Ty<'tcx>>,
26+
tys: &'a FxIndexSet<Ty<'tcx>>,
2727
) -> BoundsCompat<'a, 'tcx>;
2828

2929
fn implied_bounds_tys(
@@ -132,10 +132,9 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
132132
&'a self,
133133
param_env: ParamEnv<'tcx>,
134134
body_id: LocalDefId,
135-
tys: FxIndexSet<Ty<'tcx>>,
135+
tys: &'a FxIndexSet<Ty<'tcx>>,
136136
) -> BoundsCompat<'a, 'tcx> {
137-
tys.into_iter()
138-
.flat_map(move |ty| self.implied_outlives_bounds_compat(param_env, body_id, ty))
137+
tys.iter().flat_map(move |ty| self.implied_outlives_bounds_compat(param_env, body_id, *ty))
139138
}
140139

141140
fn implied_bounds_tys(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub mod system {
2+
pub trait WorldQuery {}
3+
impl WorldQuery for &u8 {}
4+
5+
pub struct Query<Q: WorldQuery>(Q);
6+
7+
pub trait SystemParam {
8+
type State;
9+
}
10+
impl<Q: WorldQuery + 'static> SystemParam for Query<Q> {
11+
type State = ();
12+
// `Q: 'static` is required because we need the TypeId of Q ...
13+
}
14+
15+
pub struct ParamSet<T: SystemParam>(T) where T::State: Sized;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// aux-crate:bevy_ecs=bevy_ecs.rs
2+
// check-pass
3+
4+
// We currently special case bevy from emitting the `IMPLIED_BOUNDS_FROM_TRAIT_IMPL` lint.
5+
// Otherwise, we would expect this to hit the lint.
6+
7+
extern crate bevy_ecs;
8+
9+
use bevy_ecs::system::*;
10+
11+
fn handler<'a>(_: ParamSet<Query<&'a u8>>) {}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)