Skip to content

Commit b02eac3

Browse files
Restrict bevy hack
1 parent f44efbf commit b02eac3

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+26-28
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_lint_defs::builtin::SUPERTRAIT_ITEM_SHADOWING_DEFINITION;
1616
use rustc_macros::LintDiagnostic;
1717
use rustc_middle::mir::interpret::ErrorHandled;
1818
use rustc_middle::query::Providers;
19-
use rustc_middle::ty::print::with_no_trimmed_paths;
2019
use rustc_middle::ty::trait_def::TraitSpecializationKind;
2120
use rustc_middle::ty::{
2221
self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable,
@@ -143,33 +142,7 @@ where
143142
return Ok(());
144143
}
145144

146-
let is_bevy = 'is_bevy: {
147-
// We don't want to emit this for dependents of Bevy, for now.
148-
// See #119956
149-
let is_bevy_paramset = |def: ty::AdtDef<'_>| {
150-
let adt_did = with_no_trimmed_paths!(infcx.tcx.def_path_str(def.0.did));
151-
adt_did.contains("ParamSet")
152-
};
153-
for ty in assumed_wf_types.iter() {
154-
match ty.kind() {
155-
ty::Adt(def, _) => {
156-
if is_bevy_paramset(*def) {
157-
break 'is_bevy true;
158-
}
159-
}
160-
ty::Ref(_, ty, _) => match ty.kind() {
161-
ty::Adt(def, _) => {
162-
if is_bevy_paramset(*def) {
163-
break 'is_bevy true;
164-
}
165-
}
166-
_ => {}
167-
},
168-
_ => {}
169-
}
170-
}
171-
false
172-
};
145+
let is_bevy = assumed_wf_types.visit_with(&mut ContainsBevyParamSet { tcx }).is_break();
173146

174147
// If we have set `no_implied_bounds_compat`, then do not attempt compatibility.
175148
// We could also just always enter if `is_bevy`, and call `implied_bounds_tys`,
@@ -194,6 +167,31 @@ where
194167
}
195168
}
196169

170+
struct ContainsBevyParamSet<'tcx> {
171+
tcx: TyCtxt<'tcx>,
172+
}
173+
174+
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ContainsBevyParamSet<'tcx> {
175+
type Result = ControlFlow<()>;
176+
177+
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
178+
// We only care to match `ParamSet<T>` or `&ParamSet<T>`.
179+
match t.kind() {
180+
ty::Adt(def, _) => {
181+
if self.tcx.item_name(def.did()) == sym::ParamSet
182+
&& self.tcx.crate_name(def.did().krate) == sym::bevy_ecs
183+
{
184+
return ControlFlow::Break(());
185+
}
186+
}
187+
ty::Ref(_, ty, _) => ty.visit_with(self)?,
188+
_ => {}
189+
}
190+
191+
ControlFlow::Continue(())
192+
}
193+
}
194+
197195
fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGuaranteed> {
198196
let node = tcx.hir_node_by_def_id(def_id);
199197
let mut res = match node {

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ symbols! {
289289
OsString,
290290
Output,
291291
Param,
292+
ParamSet,
292293
PartialEq,
293294
PartialOrd,
294295
Path,
@@ -520,6 +521,7 @@ symbols! {
520521
bang,
521522
begin_panic,
522523
bench,
524+
bevy_ecs,
523525
bikeshed_guaranteed_no_drop,
524526
bin,
525527
binaryheap_iter,

compiler/rustc_type_ir/src/visit.rs

+7
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ impl<I: Interner, T: TypeVisitable<I>, Ix: Idx> TypeVisitable<I> for IndexVec<Ix
224224
}
225225
}
226226

227+
impl<I: Interner, T: TypeVisitable<I>, S> TypeVisitable<I> for indexmap::IndexSet<T, S> {
228+
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
229+
walk_visitable_list!(visitor, self.iter());
230+
V::Result::output()
231+
}
232+
}
233+
227234
pub trait Flags {
228235
fn flags(&self) -> TypeFlags;
229236
fn outer_exclusive_binder(&self) -> ty::DebruijnIndex;

tests/ui/implied-bounds/bevy_world_query.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![crate_name = "bevy_ecs"]
2+
13
//@ check-pass
24

35
// We currently special case bevy from erroring on incorrect implied bounds

0 commit comments

Comments
 (0)