Rollup merge of #137633 - compiler-errors:no-implied-bounds-hack-unless-bevy, r=lcnr
Only use implied bounds hack if bevy, and use deeply normalize in implied bounds hack Consolidates the implied bounds computation mode into a single function, which deeply normalizes, and if it's in **compat** mode (for bevy), it extracts outlives bounds from the infcx. Previously, we were using the implied bounds compat mode in two cases: 1. During WF, if it detects `ParamSet` 2. EVERYWHERE ELSE (lol) -- e.g. borrowck, predicate entailment, etc. While I think this is fine, and the net effect was just that we emitted fewer diagnostics, it makes me uncomfortable that all crates were using the supposed "compat" code. Fixes #137767
This commit is contained in:
commit
6c60abf51a
19 changed files with 264 additions and 269 deletions
|
@ -126,13 +126,14 @@ where
|
|||
|
||||
let infcx_compat = infcx.fork();
|
||||
|
||||
// We specifically want to call the non-compat version of `implied_bounds_tys`; we do this always.
|
||||
// We specifically want to *disable* the implied bounds hack, first,
|
||||
// so we can detect when failures are due to bevy's implied bounds.
|
||||
let outlives_env = OutlivesEnvironment::new_with_implied_bounds_compat(
|
||||
&infcx,
|
||||
body_def_id,
|
||||
param_env,
|
||||
assumed_wf_types.iter().copied(),
|
||||
false,
|
||||
true,
|
||||
);
|
||||
|
||||
lint_redundant_lifetimes(tcx, body_def_id, &outlives_env);
|
||||
|
@ -142,53 +143,22 @@ where
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
let is_bevy = assumed_wf_types.visit_with(&mut ContainsBevyParamSet { tcx }).is_break();
|
||||
|
||||
// If we have set `no_implied_bounds_compat`, then do not attempt compatibility.
|
||||
// We could also just always enter if `is_bevy`, and call `implied_bounds_tys`,
|
||||
// but that does result in slightly more work when this option is set and
|
||||
// just obscures what we mean here anyways. Let's just be explicit.
|
||||
if is_bevy && !infcx.tcx.sess.opts.unstable_opts.no_implied_bounds_compat {
|
||||
let outlives_env = OutlivesEnvironment::new_with_implied_bounds_compat(
|
||||
&infcx,
|
||||
body_def_id,
|
||||
param_env,
|
||||
assumed_wf_types,
|
||||
true,
|
||||
);
|
||||
let errors_compat = infcx_compat.resolve_regions_with_outlives_env(&outlives_env);
|
||||
if errors_compat.is_empty() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(infcx_compat.err_ctxt().report_region_errors(body_def_id, &errors_compat))
|
||||
}
|
||||
let outlives_env = OutlivesEnvironment::new_with_implied_bounds_compat(
|
||||
&infcx_compat,
|
||||
body_def_id,
|
||||
param_env,
|
||||
assumed_wf_types,
|
||||
// Don't *disable* the implied bounds hack; though this will only apply
|
||||
// the implied bounds hack if this contains `bevy_ecs`'s `ParamSet` type.
|
||||
false,
|
||||
);
|
||||
let errors_compat = infcx_compat.resolve_regions_with_outlives_env(&outlives_env);
|
||||
if errors_compat.is_empty() {
|
||||
// FIXME: Once we fix bevy, this would be the place to insert a warning
|
||||
// to upgrade bevy.
|
||||
Ok(())
|
||||
} else {
|
||||
Err(infcx.err_ctxt().report_region_errors(body_def_id, &errors))
|
||||
}
|
||||
}
|
||||
|
||||
struct ContainsBevyParamSet<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ContainsBevyParamSet<'tcx> {
|
||||
type Result = ControlFlow<()>;
|
||||
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
|
||||
// We only care to match `ParamSet<T>` or `&ParamSet<T>`.
|
||||
match t.kind() {
|
||||
ty::Adt(def, _) => {
|
||||
if self.tcx.item_name(def.did()) == sym::ParamSet
|
||||
&& self.tcx.crate_name(def.did().krate) == sym::bevy_ecs
|
||||
{
|
||||
return ControlFlow::Break(());
|
||||
}
|
||||
}
|
||||
ty::Ref(_, ty, _) => ty.visit_with(self)?,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
ControlFlow::Continue(())
|
||||
Err(infcx_compat.err_ctxt().report_region_errors(body_def_id, &errors_compat))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue