1
Fork 0

Rollup merge of #136279 - Zalathar:ensure-ok, r=oli-obk

Rename `tcx.ensure()` to `tcx.ensure_ok()`, and improve the associated docs

This is all based on my archaeology for https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.60TyCtxtEnsure.60.

The main renamings are:
- `tcx.ensure()` → `tcx.ensure_ok()`
- `tcx.ensure_with_value()` → `tcx.ensure_done()`
- Query modifier `ensure_forwards_result_if_red` → `return_result_from_ensure_ok`

Hopefully these new names are a better fit for the *actual* function and purpose of these query call modes.
This commit is contained in:
Matthias Krüger 2025-02-02 12:31:55 +01:00 committed by GitHub
commit 58a5f891f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 262 additions and 206 deletions

View file

@ -179,7 +179,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
return e;
}
if let Err(guar) = self.tcx.ensure().coherent_trait(trait_pred.def_id()) {
if let Err(guar) = self.tcx.ensure_ok().coherent_trait(trait_pred.def_id()) {
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
// other `Foo` impls are incoherent.
return guar;
@ -511,8 +511,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
return e;
}
if let Err(guar) =
self.tcx.ensure().coherent_trait(self.tcx.parent(data.projection_term.def_id))
if let Err(guar) = self
.tcx
.ensure_ok()
.coherent_trait(self.tcx.parent(data.projection_term.def_id))
{
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
// other `Foo` impls are incoherent.

View file

@ -575,7 +575,7 @@ fn report_conflicting_impls<'tcx>(
match used_to_be_allowed {
None => {
let reported = if overlap.with_impl.is_local()
|| tcx.ensure().orphan_check_impl(impl_def_id).is_ok()
|| tcx.ensure_ok().orphan_check_impl(impl_def_id).is_ok()
{
let mut err = tcx.dcx().struct_span_err(impl_span, msg());
err.code(E0119);

View file

@ -379,7 +379,7 @@ pub(crate) fn assoc_def(
// Ensure that the impl is constrained, otherwise projection may give us
// bad unconstrained infer vars.
if let Some(impl_def_id) = impl_def_id.as_local() {
tcx.ensure().enforce_impl_non_lifetime_params_are_constrained(impl_def_id)?;
tcx.ensure_ok().enforce_impl_non_lifetime_params_are_constrained(impl_def_id)?;
}
let item = tcx.associated_item(impl_item_id);
@ -402,7 +402,7 @@ pub(crate) fn assoc_def(
if assoc_item.item.container == ty::AssocItemContainer::Impl
&& let Some(impl_def_id) = assoc_item.item.container_id(tcx).as_local()
{
tcx.ensure().enforce_impl_non_lifetime_params_are_constrained(impl_def_id)?;
tcx.ensure_ok().enforce_impl_non_lifetime_params_are_constrained(impl_def_id)?;
}
Ok(assoc_item)