Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2f04892

Browse files
authoredFeb 2, 2025
Unrolled build for rust-lang#136279
Rollup merge of rust-lang#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.
2 parents 6dd75f0 + 3ae0239 commit 2f04892

File tree

34 files changed

+262
-206
lines changed

34 files changed

+262
-206
lines changed
 

‎compiler/rustc_ast_lowering/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,10 @@ fn compute_hir_hash(
418418
pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
419419
let sess = tcx.sess;
420420
// Queries that borrow `resolver_for_lowering`.
421-
tcx.ensure_with_value().output_filenames(());
422-
tcx.ensure_with_value().early_lint_checks(());
423-
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
424-
tcx.ensure_with_value().get_lang_items(());
421+
tcx.ensure_done().output_filenames(());
422+
tcx.ensure_done().early_lint_checks(());
423+
tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
424+
tcx.ensure_done().get_lang_items(());
425425
let (mut resolver, krate) = tcx.resolver_for_lowering().steal();
426426

427427
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);

‎compiler/rustc_codegen_cranelift/src/driver/aot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ pub(crate) fn run_aot(
692692

693693
if tcx.dep_graph.is_fully_enabled() {
694694
for cgu in cgus {
695-
tcx.ensure().codegen_unit(cgu.name());
695+
tcx.ensure_ok().codegen_unit(cgu.name());
696696
}
697697
}
698698

‎compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
634634
// unnecessarily.
635635
if tcx.dep_graph.is_fully_enabled() {
636636
for cgu in codegen_units {
637-
tcx.ensure().codegen_unit(cgu.name());
637+
tcx.ensure_ok().codegen_unit(cgu.name());
638638
}
639639
}
640640

‎compiler/rustc_driver_impl/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
317317
if let Some(pp_mode) = sess.opts.pretty {
318318
if pp_mode.needs_ast_map() {
319319
create_and_enter_global_ctxt(compiler, krate, |tcx| {
320-
tcx.ensure().early_lint_checks(());
320+
tcx.ensure_ok().early_lint_checks(());
321321
pretty::print(sess, pp_mode, pretty::PrintExtra::NeedsAstMap { tcx });
322322
passes::write_dep_info(tcx);
323323
});
@@ -365,7 +365,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
365365
return early_exit();
366366
}
367367

368-
tcx.ensure().analysis(());
368+
tcx.ensure_ok().analysis(());
369369

370370
if callbacks.after_analysis(compiler, tcx) == Compilation::Stop {
371371
return early_exit();

‎compiler/rustc_driver_impl/src/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'tcx> PrintExtra<'tcx> {
222222

223223
pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
224224
if ppm.needs_analysis() {
225-
ex.tcx().ensure().analysis(());
225+
ex.tcx().ensure_ok().analysis(());
226226
}
227227

228228
let (src, src_name) = get_source(sess);

‎compiler/rustc_hir_analysis/src/check/check.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -778,13 +778,13 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
778778
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
779779
match tcx.def_kind(def_id) {
780780
DefKind::Static { .. } => {
781-
tcx.ensure().typeck(def_id);
781+
tcx.ensure_ok().typeck(def_id);
782782
maybe_check_static_with_link_section(tcx, def_id);
783783
check_static_inhabited(tcx, def_id);
784784
check_static_linkage(tcx, def_id);
785785
}
786786
DefKind::Const => {
787-
tcx.ensure().typeck(def_id);
787+
tcx.ensure_ok().typeck(def_id);
788788
}
789789
DefKind::Enum => {
790790
check_enum(tcx, def_id);
@@ -804,7 +804,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
804804
DefKind::Impl { of_trait } => {
805805
if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) {
806806
if tcx
807-
.ensure()
807+
.ensure_ok()
808808
.coherent_trait(impl_trait_header.trait_ref.instantiate_identity().def_id)
809809
.is_ok()
810810
{
@@ -1042,7 +1042,7 @@ fn check_impl_items_against_trait<'tcx>(
10421042
continue;
10431043
};
10441044

1045-
let res = tcx.ensure().compare_impl_item(impl_item.expect_local());
1045+
let res = tcx.ensure_ok().compare_impl_item(impl_item.expect_local());
10461046

10471047
if res.is_ok() {
10481048
match ty_impl_item.kind {
@@ -1488,7 +1488,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
14881488

14891489
for v in def.variants() {
14901490
if let ty::VariantDiscr::Explicit(discr_def_id) = v.discr {
1491-
tcx.ensure().typeck(discr_def_id.expect_local());
1491+
tcx.ensure_ok().typeck(discr_def_id.expect_local());
14921492
}
14931493
}
14941494

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ pub(super) fn check_type_bounds<'tcx>(
20342034
) -> Result<(), ErrorGuaranteed> {
20352035
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
20362036
// other `Foo` impls are incoherent.
2037-
tcx.ensure().coherent_trait(impl_trait_ref.def_id)?;
2037+
tcx.ensure_ok().coherent_trait(impl_trait_ref.def_id)?;
20382038

20392039
let param_env = tcx.param_env(impl_ty.def_id);
20402040
debug!(?param_env);

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ fn check_associated_item(
10461046

10471047
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
10481048
// other `Foo` impls are incoherent.
1049-
tcx.ensure()
1049+
tcx.ensure_ok()
10501050
.coherent_trait(tcx.parent(item.trait_item_def_id.unwrap_or(item_id.into())))?;
10511051

10521052
let self_ty = match item.container {
@@ -1354,7 +1354,7 @@ fn check_impl<'tcx>(
13541354
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity();
13551355
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
13561356
// other `Foo` impls are incoherent.
1357-
tcx.ensure().coherent_trait(trait_ref.def_id)?;
1357+
tcx.ensure_ok().coherent_trait(trait_ref.def_id)?;
13581358
let trait_span = hir_trait_ref.path.span;
13591359
let trait_ref = wfcx.normalize(
13601360
trait_span,
@@ -2268,11 +2268,13 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
22682268
fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), ErrorGuaranteed> {
22692269
let items = tcx.hir_module_items(module);
22702270
let res = items
2271-
.par_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id))
2272-
.and(items.par_impl_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)))
2273-
.and(items.par_trait_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)))
2274-
.and(items.par_foreign_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)))
2275-
.and(items.par_opaques(|item| tcx.ensure().check_well_formed(item)));
2271+
.par_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id))
2272+
.and(items.par_impl_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)))
2273+
.and(items.par_trait_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)))
2274+
.and(
2275+
items.par_foreign_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)),
2276+
)
2277+
.and(items.par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
22762278
if module == LocalModDefId::CRATE_DEF_ID {
22772279
super::entry::check_for_entry_fn(tcx);
22782280
}

‎compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn visit_implementation_of_coerce_unsized(checker: &Checker<'_>) -> Result<(), E
192192
// errors; other parts of the code may demand it for the info of
193193
// course.
194194
let span = tcx.def_span(impl_did);
195-
tcx.at(span).ensure().coerce_unsized_info(impl_did)
195+
tcx.at(span).ensure_ok().coerce_unsized_info(impl_did)
196196
}
197197

198198
fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {

‎compiler/rustc_hir_analysis/src/coherence/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
151151
let Some(impls) = tcx.all_local_trait_impls(()).get(&def_id) else { return Ok(()) };
152152
// Trigger building the specialization graph for the trait. This will detect and report any
153153
// overlap errors.
154-
let mut res = tcx.ensure().specialization_graph_of(def_id);
154+
let mut res = tcx.ensure_ok().specialization_graph_of(def_id);
155155

156156
for &impl_def_id in impls {
157157
let trait_header = tcx.impl_trait_header(impl_def_id).unwrap();
@@ -162,7 +162,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
162162
.and(check_impl(tcx, impl_def_id, trait_ref, trait_def))
163163
.and(check_object_overlap(tcx, impl_def_id, trait_ref))
164164
.and(unsafety::check_item(tcx, impl_def_id, trait_header, trait_def))
165-
.and(tcx.ensure().orphan_check_impl(impl_def_id))
165+
.and(tcx.ensure_ok().orphan_check_impl(impl_def_id))
166166
.and(builtin::check_trait(tcx, def_id, impl_def_id, trait_header));
167167
}
168168

There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.