1
Fork 0

Rename tcx.ensure() to tcx.ensure_ok()

This commit is contained in:
Zalathar 2025-01-30 16:20:09 +11:00
parent 854f22563c
commit 24cdaa146a
29 changed files with 186 additions and 160 deletions

View file

@ -692,7 +692,7 @@ pub(crate) fn run_aot(
if tcx.dep_graph.is_fully_enabled() { if tcx.dep_graph.is_fully_enabled() {
for cgu in cgus { for cgu in cgus {
tcx.ensure().codegen_unit(cgu.name()); tcx.ensure_ok().codegen_unit(cgu.name());
} }
} }

View file

@ -634,7 +634,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
// unnecessarily. // unnecessarily.
if tcx.dep_graph.is_fully_enabled() { if tcx.dep_graph.is_fully_enabled() {
for cgu in codegen_units { for cgu in codegen_units {
tcx.ensure().codegen_unit(cgu.name()); tcx.ensure_ok().codegen_unit(cgu.name());
} }
} }

View file

@ -317,7 +317,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
if let Some(pp_mode) = sess.opts.pretty { if let Some(pp_mode) = sess.opts.pretty {
if pp_mode.needs_ast_map() { if pp_mode.needs_ast_map() {
create_and_enter_global_ctxt(compiler, krate, |tcx| { create_and_enter_global_ctxt(compiler, krate, |tcx| {
tcx.ensure().early_lint_checks(()); tcx.ensure_ok().early_lint_checks(());
pretty::print(sess, pp_mode, pretty::PrintExtra::NeedsAstMap { tcx }); pretty::print(sess, pp_mode, pretty::PrintExtra::NeedsAstMap { tcx });
passes::write_dep_info(tcx); passes::write_dep_info(tcx);
}); });
@ -365,7 +365,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
return early_exit(); return early_exit();
} }
tcx.ensure().analysis(()); tcx.ensure_ok().analysis(());
if callbacks.after_analysis(compiler, tcx) == Compilation::Stop { if callbacks.after_analysis(compiler, tcx) == Compilation::Stop {
return early_exit(); return early_exit();

View file

@ -222,7 +222,7 @@ impl<'tcx> PrintExtra<'tcx> {
pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
if ppm.needs_analysis() { if ppm.needs_analysis() {
ex.tcx().ensure().analysis(()); ex.tcx().ensure_ok().analysis(());
} }
let (src, src_name) = get_source(sess); let (src, src_name) = get_source(sess);

View file

@ -778,13 +778,13 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) { pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
match tcx.def_kind(def_id) { match tcx.def_kind(def_id) {
DefKind::Static { .. } => { DefKind::Static { .. } => {
tcx.ensure().typeck(def_id); tcx.ensure_ok().typeck(def_id);
maybe_check_static_with_link_section(tcx, def_id); maybe_check_static_with_link_section(tcx, def_id);
check_static_inhabited(tcx, def_id); check_static_inhabited(tcx, def_id);
check_static_linkage(tcx, def_id); check_static_linkage(tcx, def_id);
} }
DefKind::Const => { DefKind::Const => {
tcx.ensure().typeck(def_id); tcx.ensure_ok().typeck(def_id);
} }
DefKind::Enum => { DefKind::Enum => {
check_enum(tcx, def_id); check_enum(tcx, def_id);
@ -804,7 +804,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
DefKind::Impl { of_trait } => { DefKind::Impl { of_trait } => {
if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) { if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) {
if tcx if tcx
.ensure() .ensure_ok()
.coherent_trait(impl_trait_header.trait_ref.instantiate_identity().def_id) .coherent_trait(impl_trait_header.trait_ref.instantiate_identity().def_id)
.is_ok() .is_ok()
{ {
@ -1042,7 +1042,7 @@ fn check_impl_items_against_trait<'tcx>(
continue; continue;
}; };
let res = tcx.ensure().compare_impl_item(impl_item.expect_local()); let res = tcx.ensure_ok().compare_impl_item(impl_item.expect_local());
if res.is_ok() { if res.is_ok() {
match ty_impl_item.kind { match ty_impl_item.kind {
@ -1488,7 +1488,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
for v in def.variants() { for v in def.variants() {
if let ty::VariantDiscr::Explicit(discr_def_id) = v.discr { if let ty::VariantDiscr::Explicit(discr_def_id) = v.discr {
tcx.ensure().typeck(discr_def_id.expect_local()); tcx.ensure_ok().typeck(discr_def_id.expect_local());
} }
} }

View file

@ -2034,7 +2034,7 @@ pub(super) fn check_type_bounds<'tcx>(
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case // Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
// other `Foo` impls are incoherent. // other `Foo` impls are incoherent.
tcx.ensure().coherent_trait(impl_trait_ref.def_id)?; tcx.ensure_ok().coherent_trait(impl_trait_ref.def_id)?;
let param_env = tcx.param_env(impl_ty.def_id); let param_env = tcx.param_env(impl_ty.def_id);
debug!(?param_env); debug!(?param_env);

View file

@ -1046,7 +1046,7 @@ fn check_associated_item(
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case // Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
// other `Foo` impls are incoherent. // other `Foo` impls are incoherent.
tcx.ensure() tcx.ensure_ok()
.coherent_trait(tcx.parent(item.trait_item_def_id.unwrap_or(item_id.into())))?; .coherent_trait(tcx.parent(item.trait_item_def_id.unwrap_or(item_id.into())))?;
let self_ty = match item.container { let self_ty = match item.container {
@ -1354,7 +1354,7 @@ fn check_impl<'tcx>(
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity(); let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity();
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case // Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
// other `Foo` impls are incoherent. // other `Foo` impls are incoherent.
tcx.ensure().coherent_trait(trait_ref.def_id)?; tcx.ensure_ok().coherent_trait(trait_ref.def_id)?;
let trait_span = hir_trait_ref.path.span; let trait_span = hir_trait_ref.path.span;
let trait_ref = wfcx.normalize( let trait_ref = wfcx.normalize(
trait_span, trait_span,
@ -2268,11 +2268,13 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), ErrorGuaranteed> { fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), ErrorGuaranteed> {
let items = tcx.hir_module_items(module); let items = tcx.hir_module_items(module);
let res = items let res = items
.par_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id)) .par_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id))
.and(items.par_impl_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id))) .and(items.par_impl_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)))
.and(items.par_trait_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id))) .and(items.par_trait_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)))
.and(items.par_foreign_items(|item| tcx.ensure().check_well_formed(item.owner_id.def_id))) .and(
.and(items.par_opaques(|item| tcx.ensure().check_well_formed(item))); items.par_foreign_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)),
)
.and(items.par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
if module == LocalModDefId::CRATE_DEF_ID { if module == LocalModDefId::CRATE_DEF_ID {
super::entry::check_for_entry_fn(tcx); super::entry::check_for_entry_fn(tcx);
} }

View file

@ -192,7 +192,7 @@ fn visit_implementation_of_coerce_unsized(checker: &Checker<'_>) -> Result<(), E
// errors; other parts of the code may demand it for the info of // errors; other parts of the code may demand it for the info of
// course. // course.
let span = tcx.def_span(impl_did); let span = tcx.def_span(impl_did);
tcx.at(span).ensure().coerce_unsized_info(impl_did) tcx.at(span).ensure_ok().coerce_unsized_info(impl_did)
} }
fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> { fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {

View file

@ -151,7 +151,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
let Some(impls) = tcx.all_local_trait_impls(()).get(&def_id) else { return Ok(()) }; let Some(impls) = tcx.all_local_trait_impls(()).get(&def_id) else { return Ok(()) };
// Trigger building the specialization graph for the trait. This will detect and report any // Trigger building the specialization graph for the trait. This will detect and report any
// overlap errors. // overlap errors.
let mut res = tcx.ensure().specialization_graph_of(def_id); let mut res = tcx.ensure_ok().specialization_graph_of(def_id);
for &impl_def_id in impls { for &impl_def_id in impls {
let trait_header = tcx.impl_trait_header(impl_def_id).unwrap(); 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>
.and(check_impl(tcx, impl_def_id, trait_ref, trait_def)) .and(check_impl(tcx, impl_def_id, trait_ref, trait_def))
.and(check_object_overlap(tcx, impl_def_id, trait_ref)) .and(check_object_overlap(tcx, impl_def_id, trait_ref))
.and(unsafety::check_item(tcx, impl_def_id, trait_header, trait_def)) .and(unsafety::check_item(tcx, impl_def_id, trait_header, trait_def))
.and(tcx.ensure().orphan_check_impl(impl_def_id)) .and(tcx.ensure_ok().orphan_check_impl(impl_def_id))
.and(builtin::check_trait(tcx, def_id, impl_def_id, trait_header)); .and(builtin::check_trait(tcx, def_id, impl_def_id, trait_header));
} }

View file

@ -292,16 +292,16 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
match param.kind { match param.kind {
hir::GenericParamKind::Lifetime { .. } => {} hir::GenericParamKind::Lifetime { .. } => {}
hir::GenericParamKind::Type { default: Some(_), .. } => { hir::GenericParamKind::Type { default: Some(_), .. } => {
self.tcx.ensure().type_of(param.def_id); self.tcx.ensure_ok().type_of(param.def_id);
} }
hir::GenericParamKind::Type { .. } => {} hir::GenericParamKind::Type { .. } => {}
hir::GenericParamKind::Const { default, .. } => { hir::GenericParamKind::Const { default, .. } => {
self.tcx.ensure().type_of(param.def_id); self.tcx.ensure_ok().type_of(param.def_id);
if let Some(default) = default { if let Some(default) = default {
// need to store default and type of default // need to store default and type of default
self.tcx.ensure().const_param_default(param.def_id); self.tcx.ensure_ok().const_param_default(param.def_id);
if let hir::ConstArgKind::Anon(ac) = default.kind { if let hir::ConstArgKind::Anon(ac) = default.kind {
self.tcx.ensure().type_of(ac.def_id); self.tcx.ensure_ok().type_of(ac.def_id);
} }
} }
} }
@ -312,8 +312,8 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
if let hir::ExprKind::Closure(closure) = expr.kind { if let hir::ExprKind::Closure(closure) = expr.kind {
self.tcx.ensure().generics_of(closure.def_id); self.tcx.ensure_ok().generics_of(closure.def_id);
self.tcx.ensure().codegen_fn_attrs(closure.def_id); self.tcx.ensure_ok().codegen_fn_attrs(closure.def_id);
// We do not call `type_of` for closures here as that // We do not call `type_of` for closures here as that
// depends on typecheck and would therefore hide // depends on typecheck and would therefore hide
// any further errors in case one typeck fails. // any further errors in case one typeck fails.
@ -325,15 +325,15 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
/// `check_item_type` ensures that it's called instead. /// `check_item_type` ensures that it's called instead.
fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) { fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) {
let def_id = opaque.def_id; let def_id = opaque.def_id;
self.tcx.ensure().generics_of(def_id); self.tcx.ensure_ok().generics_of(def_id);
self.tcx.ensure().predicates_of(def_id); self.tcx.ensure_ok().predicates_of(def_id);
self.tcx.ensure().explicit_item_bounds(def_id); self.tcx.ensure_ok().explicit_item_bounds(def_id);
self.tcx.ensure().explicit_item_self_bounds(def_id); self.tcx.ensure_ok().explicit_item_self_bounds(def_id);
self.tcx.ensure().item_bounds(def_id); self.tcx.ensure_ok().item_bounds(def_id);
self.tcx.ensure().item_self_bounds(def_id); self.tcx.ensure_ok().item_self_bounds(def_id);
if self.tcx.is_conditionally_const(def_id) { if self.tcx.is_conditionally_const(def_id) {
self.tcx.ensure().explicit_implied_const_bounds(def_id); self.tcx.ensure_ok().explicit_implied_const_bounds(def_id);
self.tcx.ensure().const_conditions(def_id); self.tcx.ensure_ok().const_conditions(def_id);
} }
intravisit::walk_opaque_ty(self, opaque); intravisit::walk_opaque_ty(self, opaque);
} }
@ -683,20 +683,20 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for item in *items { for item in *items {
let item = tcx.hir().foreign_item(item.id); let item = tcx.hir().foreign_item(item.id);
tcx.ensure().generics_of(item.owner_id); tcx.ensure_ok().generics_of(item.owner_id);
tcx.ensure().type_of(item.owner_id); tcx.ensure_ok().type_of(item.owner_id);
tcx.ensure().predicates_of(item.owner_id); tcx.ensure_ok().predicates_of(item.owner_id);
if tcx.is_conditionally_const(def_id) { if tcx.is_conditionally_const(def_id) {
tcx.ensure().explicit_implied_const_bounds(def_id); tcx.ensure_ok().explicit_implied_const_bounds(def_id);
tcx.ensure().const_conditions(def_id); tcx.ensure_ok().const_conditions(def_id);
} }
match item.kind { match item.kind {
hir::ForeignItemKind::Fn(..) => { hir::ForeignItemKind::Fn(..) => {
tcx.ensure().codegen_fn_attrs(item.owner_id); tcx.ensure_ok().codegen_fn_attrs(item.owner_id);
tcx.ensure().fn_sig(item.owner_id) tcx.ensure_ok().fn_sig(item.owner_id)
} }
hir::ForeignItemKind::Static(..) => { hir::ForeignItemKind::Static(..) => {
tcx.ensure().codegen_fn_attrs(item.owner_id); tcx.ensure_ok().codegen_fn_attrs(item.owner_id);
let mut visitor = HirPlaceholderCollector::default(); let mut visitor = HirPlaceholderCollector::default();
visitor.visit_foreign_item(item); visitor.visit_foreign_item(item);
placeholder_type_error( placeholder_type_error(
@ -713,40 +713,40 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
} }
} }
hir::ItemKind::Enum(..) => { hir::ItemKind::Enum(..) => {
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
lower_enum_variant_types(tcx, def_id.to_def_id()); lower_enum_variant_types(tcx, def_id.to_def_id());
} }
hir::ItemKind::Impl { .. } => { hir::ItemKind::Impl { .. } => {
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
tcx.ensure().impl_trait_header(def_id); tcx.ensure_ok().impl_trait_header(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
tcx.ensure().associated_items(def_id); tcx.ensure_ok().associated_items(def_id);
} }
hir::ItemKind::Trait(..) => { hir::ItemKind::Trait(..) => {
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure().trait_def(def_id); tcx.ensure_ok().trait_def(def_id);
tcx.at(it.span).explicit_super_predicates_of(def_id); tcx.at(it.span).explicit_super_predicates_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
tcx.ensure().associated_items(def_id); tcx.ensure_ok().associated_items(def_id);
} }
hir::ItemKind::TraitAlias(..) => { hir::ItemKind::TraitAlias(..) => {
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.at(it.span).explicit_implied_predicates_of(def_id); tcx.at(it.span).explicit_implied_predicates_of(def_id);
tcx.at(it.span).explicit_super_predicates_of(def_id); tcx.at(it.span).explicit_super_predicates_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
} }
hir::ItemKind::Struct(struct_def, _) | hir::ItemKind::Union(struct_def, _) => { hir::ItemKind::Struct(struct_def, _) | hir::ItemKind::Union(struct_def, _) => {
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
for f in struct_def.fields() { for f in struct_def.fields() {
tcx.ensure().generics_of(f.def_id); tcx.ensure_ok().generics_of(f.def_id);
tcx.ensure().type_of(f.def_id); tcx.ensure_ok().type_of(f.def_id);
tcx.ensure().predicates_of(f.def_id); tcx.ensure_ok().predicates_of(f.def_id);
} }
if let Some(ctor_def_id) = struct_def.ctor_def_id() { if let Some(ctor_def_id) = struct_def.ctor_def_id() {
@ -755,15 +755,15 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
} }
hir::ItemKind::TyAlias(..) => { hir::ItemKind::TyAlias(..) => {
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
} }
hir::ItemKind::Static(ty, ..) | hir::ItemKind::Const(ty, ..) => { hir::ItemKind::Static(ty, ..) | hir::ItemKind::Const(ty, ..) => {
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
if !ty.is_suggestable_infer_ty() { if !ty.is_suggestable_infer_ty() {
let mut visitor = HirPlaceholderCollector::default(); let mut visitor = HirPlaceholderCollector::default();
visitor.visit_item(it); visitor.visit_item(it);
@ -779,11 +779,11 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
} }
hir::ItemKind::Fn { .. } => { hir::ItemKind::Fn { .. } => {
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
tcx.ensure().fn_sig(def_id); tcx.ensure_ok().fn_sig(def_id);
tcx.ensure().codegen_fn_attrs(def_id); tcx.ensure_ok().codegen_fn_attrs(def_id);
} }
} }
} }
@ -791,18 +791,18 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
let trait_item = tcx.hir().trait_item(trait_item_id); let trait_item = tcx.hir().trait_item(trait_item_id);
let def_id = trait_item_id.owner_id; let def_id = trait_item_id.owner_id;
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
let icx = ItemCtxt::new(tcx, def_id.def_id); let icx = ItemCtxt::new(tcx, def_id.def_id);
match trait_item.kind { match trait_item.kind {
hir::TraitItemKind::Fn(..) => { hir::TraitItemKind::Fn(..) => {
tcx.ensure().codegen_fn_attrs(def_id); tcx.ensure_ok().codegen_fn_attrs(def_id);
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
tcx.ensure().fn_sig(def_id); tcx.ensure_ok().fn_sig(def_id);
} }
hir::TraitItemKind::Const(ty, body_id) => { hir::TraitItemKind::Const(ty, body_id) => {
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
if !tcx.dcx().has_stashed_diagnostic(ty.span, StashKey::ItemNoType) if !tcx.dcx().has_stashed_diagnostic(ty.span, StashKey::ItemNoType)
&& !(ty.is_suggestable_infer_ty() && body_id.is_some()) && !(ty.is_suggestable_infer_ty() && body_id.is_some())
{ {
@ -821,9 +821,9 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
} }
hir::TraitItemKind::Type(_, Some(_)) => { hir::TraitItemKind::Type(_, Some(_)) => {
tcx.ensure().item_bounds(def_id); tcx.ensure_ok().item_bounds(def_id);
tcx.ensure().item_self_bounds(def_id); tcx.ensure_ok().item_self_bounds(def_id);
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
// Account for `type T = _;`. // Account for `type T = _;`.
let mut visitor = HirPlaceholderCollector::default(); let mut visitor = HirPlaceholderCollector::default();
visitor.visit_trait_item(trait_item); visitor.visit_trait_item(trait_item);
@ -838,8 +838,8 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
} }
hir::TraitItemKind::Type(_, None) => { hir::TraitItemKind::Type(_, None) => {
tcx.ensure().item_bounds(def_id); tcx.ensure_ok().item_bounds(def_id);
tcx.ensure().item_self_bounds(def_id); tcx.ensure_ok().item_self_bounds(def_id);
// #74612: Visit and try to find bad placeholders // #74612: Visit and try to find bad placeholders
// even if there is no concrete type. // even if there is no concrete type.
let mut visitor = HirPlaceholderCollector::default(); let mut visitor = HirPlaceholderCollector::default();
@ -856,20 +856,20 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
} }
}; };
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
} }
fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
let def_id = impl_item_id.owner_id; let def_id = impl_item_id.owner_id;
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
let impl_item = tcx.hir().impl_item(impl_item_id); let impl_item = tcx.hir().impl_item(impl_item_id);
let icx = ItemCtxt::new(tcx, def_id.def_id); let icx = ItemCtxt::new(tcx, def_id.def_id);
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Fn(..) => { hir::ImplItemKind::Fn(..) => {
tcx.ensure().codegen_fn_attrs(def_id); tcx.ensure_ok().codegen_fn_attrs(def_id);
tcx.ensure().fn_sig(def_id); tcx.ensure_ok().fn_sig(def_id);
} }
hir::ImplItemKind::Type(_) => { hir::ImplItemKind::Type(_) => {
// Account for `type T = _;` // Account for `type T = _;`
@ -904,9 +904,9 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
} }
fn lower_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) { fn lower_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) {
tcx.ensure().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure().type_of(def_id); tcx.ensure_ok().type_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
} }
fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) { fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
@ -937,9 +937,9 @@ fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
); );
for f in &variant.fields { for f in &variant.fields {
tcx.ensure().generics_of(f.did); tcx.ensure_ok().generics_of(f.did);
tcx.ensure().type_of(f.did); tcx.ensure_ok().type_of(f.did);
tcx.ensure().predicates_of(f.did); tcx.ensure_ok().predicates_of(f.did);
} }
// Lower the ctor, if any. This also registers the variant as an item. // Lower the ctor, if any. This also registers the variant as an item.

View file

@ -62,7 +62,7 @@ pub(crate) fn check_impl_wf(
// Check that the args are constrained. We queryfied the check for ty/const params // Check that the args are constrained. We queryfied the check for ty/const params
// since unconstrained type/const params cause ICEs in projection, so we want to // since unconstrained type/const params cause ICEs in projection, so we want to
// detect those specifically and project those to `TyKind::Error`. // detect those specifically and project those to `TyKind::Error`.
let mut res = tcx.ensure().enforce_impl_non_lifetime_params_are_constrained(impl_def_id); let mut res = tcx.ensure_ok().enforce_impl_non_lifetime_params_are_constrained(impl_def_id);
res = res.and(enforce_impl_lifetime_params_are_constrained(tcx, impl_def_id)); res = res.and(enforce_impl_lifetime_params_are_constrained(tcx, impl_def_id));
if tcx.features().min_specialization() { if tcx.features().min_specialization() {

View file

@ -140,15 +140,15 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
tcx.sess.time("coherence_checking", || { tcx.sess.time("coherence_checking", || {
tcx.hir().par_for_each_module(|module| { tcx.hir().par_for_each_module(|module| {
let _ = tcx.ensure().check_mod_type_wf(module); let _ = tcx.ensure_ok().check_mod_type_wf(module);
}); });
for &trait_def_id in tcx.all_local_trait_impls(()).keys() { for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
let _ = tcx.ensure().coherent_trait(trait_def_id); let _ = tcx.ensure_ok().coherent_trait(trait_def_id);
} }
// these queries are executed for side-effects (error reporting): // these queries are executed for side-effects (error reporting):
let _ = tcx.ensure().crate_inherent_impls_validity_check(()); let _ = tcx.ensure_ok().crate_inherent_impls_validity_check(());
let _ = tcx.ensure().crate_inherent_impls_overlap_check(()); let _ = tcx.ensure_ok().crate_inherent_impls_overlap_check(());
}); });
if tcx.features().rustc_attrs() { if tcx.features().rustc_attrs() {
@ -167,12 +167,12 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
tcx.hir().par_body_owners(|item_def_id| { tcx.hir().par_body_owners(|item_def_id| {
let def_kind = tcx.def_kind(item_def_id); let def_kind = tcx.def_kind(item_def_id);
match def_kind { match def_kind {
DefKind::Static { .. } => tcx.ensure().eval_static_initializer(item_def_id), DefKind::Static { .. } => tcx.ensure_ok().eval_static_initializer(item_def_id),
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => { DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty()); let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
let cid = GlobalId { instance, promoted: None }; let cid = GlobalId { instance, promoted: None };
let typing_env = ty::TypingEnv::fully_monomorphized(); let typing_env = ty::TypingEnv::fully_monomorphized();
tcx.ensure().eval_to_const_value_raw(typing_env.as_query_input(cid)); tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(cid));
} }
_ => (), _ => (),
} }
@ -185,11 +185,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
tcx.hir().par_body_owners(|item_def_id| { tcx.hir().par_body_owners(|item_def_id| {
let def_kind = tcx.def_kind(item_def_id); let def_kind = tcx.def_kind(item_def_id);
if !matches!(def_kind, DefKind::AnonConst) { if !matches!(def_kind, DefKind::AnonConst) {
tcx.ensure().typeck(item_def_id); tcx.ensure_ok().typeck(item_def_id);
} }
}); });
tcx.ensure().check_unused_traits(()); tcx.ensure_ok().check_unused_traits(());
} }
/// Lower a [`hir::Ty`] to a [`Ty`]. /// Lower a [`hir::Ty`] to a [`Ty`].

View file

@ -49,7 +49,7 @@ pub(crate) fn check_legal_trait_for_method_call(
}; };
return Err(tcx.dcx().emit_err(errors::ExplicitDestructorCall { span, sugg })); return Err(tcx.dcx().emit_err(errors::ExplicitDestructorCall { span, sugg }));
} }
tcx.ensure().coherent_trait(trait_id) tcx.ensure_ok().coherent_trait(trait_id)
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -832,20 +832,20 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
sess.time("misc_checking_1", || { sess.time("misc_checking_1", || {
parallel!( parallel!(
{ {
sess.time("looking_for_entry_point", || tcx.ensure().entry_fn(())); sess.time("looking_for_entry_point", || tcx.ensure_ok().entry_fn(()));
sess.time("looking_for_derive_registrar", || { sess.time("looking_for_derive_registrar", || {
tcx.ensure().proc_macro_decls_static(()) tcx.ensure_ok().proc_macro_decls_static(())
}); });
CStore::from_tcx(tcx).report_unused_deps(tcx); CStore::from_tcx(tcx).report_unused_deps(tcx);
}, },
{ {
tcx.hir().par_for_each_module(|module| { tcx.hir().par_for_each_module(|module| {
tcx.ensure().check_mod_loops(module); tcx.ensure_ok().check_mod_loops(module);
tcx.ensure().check_mod_attrs(module); tcx.ensure_ok().check_mod_attrs(module);
tcx.ensure().check_mod_naked_functions(module); tcx.ensure_ok().check_mod_naked_functions(module);
tcx.ensure().check_mod_unstable_api_usage(module); tcx.ensure_ok().check_mod_unstable_api_usage(module);
}); });
}, },
{ {
@ -858,8 +858,8 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
// since they might not otherwise get called. // since they might not otherwise get called.
// This marks the corresponding crate-level attributes // This marks the corresponding crate-level attributes
// as used, and ensures that their values are valid. // as used, and ensures that their values are valid.
tcx.ensure().limits(()); tcx.ensure_ok().limits(());
tcx.ensure().stability_index(()); tcx.ensure_ok().stability_index(());
} }
); );
}); });
@ -883,13 +883,13 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
tcx.hir().par_body_owners(|def_id| { tcx.hir().par_body_owners(|def_id| {
// Run unsafety check because it's responsible for stealing and // Run unsafety check because it's responsible for stealing and
// deallocating THIR. // deallocating THIR.
tcx.ensure().check_unsafety(def_id); tcx.ensure_ok().check_unsafety(def_id);
tcx.ensure().mir_borrowck(def_id) tcx.ensure_ok().mir_borrowck(def_id)
}); });
}); });
sess.time("MIR_effect_checking", || { sess.time("MIR_effect_checking", || {
tcx.hir().par_body_owners(|def_id| { tcx.hir().par_body_owners(|def_id| {
tcx.ensure().has_ffi_unwind_calls(def_id); tcx.ensure_ok().has_ffi_unwind_calls(def_id);
// If we need to codegen, ensure that we emit all errors from // If we need to codegen, ensure that we emit all errors from
// `mir_drops_elaborated_and_const_checked` now, to avoid discovering // `mir_drops_elaborated_and_const_checked` now, to avoid discovering
@ -897,15 +897,15 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
if tcx.sess.opts.output_types.should_codegen() if tcx.sess.opts.output_types.should_codegen()
|| tcx.hir().body_const_context(def_id).is_some() || tcx.hir().body_const_context(def_id).is_some()
{ {
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id); tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id);
} }
}); });
}); });
sess.time("coroutine_obligations", || { sess.time("coroutine_obligations", || {
tcx.hir().par_body_owners(|def_id| { tcx.hir().par_body_owners(|def_id| {
if tcx.is_coroutine(def_id.to_def_id()) { if tcx.is_coroutine(def_id.to_def_id()) {
tcx.ensure().mir_coroutine_witnesses(def_id); tcx.ensure_ok().mir_coroutine_witnesses(def_id);
tcx.ensure().check_coroutine_obligations( tcx.ensure_ok().check_coroutine_obligations(
tcx.typeck_root_def_id(def_id.to_def_id()).expect_local(), tcx.typeck_root_def_id(def_id.to_def_id()).expect_local(),
); );
} }
@ -950,15 +950,16 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
sess.time("misc_checking_3", || { sess.time("misc_checking_3", || {
parallel!( parallel!(
{ {
tcx.ensure().effective_visibilities(()); tcx.ensure_ok().effective_visibilities(());
parallel!( parallel!(
{ {
tcx.ensure().check_private_in_public(()); tcx.ensure_ok().check_private_in_public(());
}, },
{ {
tcx.hir() tcx.hir().par_for_each_module(|module| {
.par_for_each_module(|module| tcx.ensure().check_mod_deathness(module)); tcx.ensure_ok().check_mod_deathness(module)
});
}, },
{ {
sess.time("lint_checking", || { sess.time("lint_checking", || {
@ -966,14 +967,14 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
}); });
}, },
{ {
tcx.ensure().clashing_extern_declarations(()); tcx.ensure_ok().clashing_extern_declarations(());
} }
); );
}, },
{ {
sess.time("privacy_checking_modules", || { sess.time("privacy_checking_modules", || {
tcx.hir().par_for_each_module(|module| { tcx.hir().par_for_each_module(|module| {
tcx.ensure().check_mod_privacy(module); tcx.ensure_ok().check_mod_privacy(module);
}); });
}); });
} }
@ -981,7 +982,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
// This check has to be run after all lints are done processing. We don't // This check has to be run after all lints are done processing. We don't
// define a lint filter, as all lint checks should have finished at this point. // define a lint filter, as all lint checks should have finished at this point.
sess.time("check_lint_expectations", || tcx.ensure().check_expectations(None)); sess.time("check_lint_expectations", || tcx.ensure_ok().check_expectations(None));
// This query is only invoked normally if a diagnostic is emitted that needs any // This query is only invoked normally if a diagnostic is emitted that needs any
// diagnostic item. If the crate compiles without checking any diagnostic items, // diagnostic item. If the crate compiles without checking any diagnostic items,
@ -1006,7 +1007,7 @@ fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
) )
}) => }) =>
{ {
tcx.ensure().trigger_delayed_bug(def_id); tcx.ensure_ok().trigger_delayed_bug(def_id);
} }
// Bare `#[rustc_error]`. // Bare `#[rustc_error]`.

View file

@ -458,7 +458,7 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|| { || {
tcx.sess.time("module_lints", || { tcx.sess.time("module_lints", || {
// Run per-module lints // Run per-module lints
tcx.hir().par_for_each_module(|module| tcx.ensure().lint_mod(module)); tcx.hir().par_for_each_module(|module| tcx.ensure_ok().lint_mod(module));
}); });
}, },
); );

View file

@ -165,7 +165,7 @@ macro_rules! provide_one {
// doesn't need to do this (and can't, as it would cause a query cycle). // doesn't need to do this (and can't, as it would cause a query cycle).
use rustc_middle::dep_graph::dep_kinds; use rustc_middle::dep_graph::dep_kinds;
if dep_kinds::$name != dep_kinds::crate_hash && $tcx.dep_graph.is_fully_enabled() { if dep_kinds::$name != dep_kinds::crate_hash && $tcx.dep_graph.is_fully_enabled() {
$tcx.ensure().crate_hash($def_id.krate); $tcx.ensure_ok().crate_hash($def_id.krate);
} }
let cdata = rustc_data_structures::sync::FreezeReadGuard::map(CStore::from_tcx($tcx), |c| { let cdata = rustc_data_structures::sync::FreezeReadGuard::map(CStore::from_tcx($tcx), |c| {

View file

@ -9,7 +9,7 @@ use super::{
ReportedErrorInfo, ReportedErrorInfo,
}; };
use crate::mir; use crate::mir;
use crate::query::TyCtxtEnsure; use crate::query::TyCtxtEnsureOk;
use crate::ty::visit::TypeVisitableExt; use crate::ty::visit::TypeVisitableExt;
use crate::ty::{self, GenericArgs, TyCtxt}; use crate::ty::{self, GenericArgs, TyCtxt};
@ -198,7 +198,7 @@ impl<'tcx> TyCtxt<'tcx> {
} }
} }
impl<'tcx> TyCtxtEnsure<'tcx> { impl<'tcx> TyCtxtEnsureOk<'tcx> {
/// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts /// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts
/// that can't take any generic arguments like const items or enum discriminants. If a /// that can't take any generic arguments like const items or enum discriminants. If a
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned. /// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.

View file

@ -91,7 +91,7 @@ pub use keys::{AsLocalKey, Key, LocalCrate};
pub mod on_disk_cache; pub mod on_disk_cache;
#[macro_use] #[macro_use]
pub mod plumbing; pub mod plumbing;
pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsure, TyCtxtEnsureWithValue}; pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureOk, TyCtxtEnsureWithValue};
// Each of these queries corresponds to a function pointer field in the // Each of these queries corresponds to a function pointer field in the
// `Providers` struct for requesting a value of that type, and a method // `Providers` struct for requesting a value of that type, and a method

View file

@ -88,7 +88,7 @@ impl<'tcx> Deref for TyCtxtAt<'tcx> {
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct TyCtxtEnsure<'tcx> { pub struct TyCtxtEnsureOk<'tcx> {
pub tcx: TyCtxt<'tcx>, pub tcx: TyCtxt<'tcx>,
} }
@ -98,11 +98,29 @@ pub struct TyCtxtEnsureWithValue<'tcx> {
} }
impl<'tcx> TyCtxt<'tcx> { impl<'tcx> TyCtxt<'tcx> {
/// Returns a transparent wrapper for `TyCtxt`, which ensures queries /// Wrapper that calls queries in a special "ensure OK" mode, for callers
/// are executed instead of just returning their results. /// that don't need the return value and just want to invoke a query for
/// its potential side-effect of emitting fatal errors.
///
/// This can be more efficient than a normal query call, because if the
/// query's inputs are all green, the call can return immediately without
/// needing to obtain a value (by decoding one from disk or by executing
/// the query).
///
/// (As with all query calls, execution is also skipped if the query result
/// is already cached in memory.)
///
/// ## WARNING
/// A subsequent normal call to the same query might still cause it to be
/// executed! This can occur when the inputs are all green, but the query's
/// result is not cached on disk, so the query must be executed to obtain a
/// return value.
///
/// Therefore, this call mode is not appropriate for callers that want to
/// ensure that the query is _never_ executed in the future.
#[inline(always)] #[inline(always)]
pub fn ensure(self) -> TyCtxtEnsure<'tcx> { pub fn ensure_ok(self) -> TyCtxtEnsureOk<'tcx> {
TyCtxtEnsure { tcx: self } TyCtxtEnsureOk { tcx: self }
} }
/// Returns a transparent wrapper for `TyCtxt`, which ensures queries /// Returns a transparent wrapper for `TyCtxt`, which ensures queries
@ -248,15 +266,15 @@ macro_rules! separate_provide_extern_decl {
}; };
} }
macro_rules! ensure_result { macro_rules! ensure_ok_result {
([][$ty:ty]) => { ( [] ) => {
() ()
}; };
([(ensure_forwards_result_if_red) $($rest:tt)*][$ty:ty]) => { ( [(ensure_forwards_result_if_red) $($rest:tt)*] ) => {
Result<(), ErrorGuaranteed> Result<(), ErrorGuaranteed>
}; };
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => { ( [$other:tt $($modifiers:tt)*] ) => {
ensure_result!([$($modifiers)*][$($args)*]) ensure_ok_result!( [$($modifiers)*] )
}; };
} }
@ -383,10 +401,13 @@ macro_rules! define_callbacks {
$($(#[$attr])* pub $name: queries::$name::Storage<'tcx>,)* $($(#[$attr])* pub $name: queries::$name::Storage<'tcx>,)*
} }
impl<'tcx> TyCtxtEnsure<'tcx> { impl<'tcx> TyCtxtEnsureOk<'tcx> {
$($(#[$attr])* $($(#[$attr])*
#[inline(always)] #[inline(always)]
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> ensure_result!([$($modifiers)*][$V]) { pub fn $name(
self,
key: query_helper_param_ty!($($K)*),
) -> ensure_ok_result!([$($modifiers)*]) {
query_ensure!( query_ensure!(
[$($modifiers)*] [$($modifiers)*]
self.tcx, self.tcx,

View file

@ -1957,7 +1957,7 @@ impl<'tcx> TyCtxt<'tcx> {
) -> &'tcx rustc_hir::def_path_hash_map::DefPathHashMap { ) -> &'tcx rustc_hir::def_path_hash_map::DefPathHashMap {
// Create a dependency to the crate to be sure we re-execute this when the amount of // Create a dependency to the crate to be sure we re-execute this when the amount of
// definitions change. // definitions change.
self.ensure().hir_crate(()); self.ensure_ok().hir_crate(());
// Freeze definitions once we start iterating on them, to prevent adding new ones // Freeze definitions once we start iterating on them, to prevent adding new ones
// while iterating. If some query needs to add definitions, it should be `ensure`d above. // while iterating. If some query needs to add definitions, it should be `ensure`d above.
self.untracked.definitions.freeze().def_path_hash_to_def_index_map() self.untracked.definitions.freeze().def_path_hash_to_def_index_map()

View file

@ -367,7 +367,7 @@ impl<'tcx> TyCtxt<'tcx> {
validate: impl Fn(Self, DefId) -> Result<(), ErrorGuaranteed>, validate: impl Fn(Self, DefId) -> Result<(), ErrorGuaranteed>,
) -> Option<ty::Destructor> { ) -> Option<ty::Destructor> {
let drop_trait = self.lang_items().drop_trait()?; let drop_trait = self.lang_items().drop_trait()?;
self.ensure().coherent_trait(drop_trait).ok()?; self.ensure_ok().coherent_trait(drop_trait).ok()?;
let ty = self.type_of(adt_did).instantiate_identity(); let ty = self.type_of(adt_did).instantiate_identity();
let mut dtor_candidate = None; let mut dtor_candidate = None;
@ -404,7 +404,7 @@ impl<'tcx> TyCtxt<'tcx> {
validate: impl Fn(Self, DefId) -> Result<(), ErrorGuaranteed>, validate: impl Fn(Self, DefId) -> Result<(), ErrorGuaranteed>,
) -> Option<ty::AsyncDestructor> { ) -> Option<ty::AsyncDestructor> {
let async_drop_trait = self.lang_items().async_drop_trait()?; let async_drop_trait = self.lang_items().async_drop_trait()?;
self.ensure().coherent_trait(async_drop_trait).ok()?; self.ensure_ok().coherent_trait(async_drop_trait).ok()?;
let ty = self.type_of(adt_did).instantiate_identity(); let ty = self.type_of(adt_did).instantiate_identity();
let mut dtor_candidate = None; let mut dtor_candidate = None;

View file

@ -68,7 +68,7 @@ pub fn build_mir<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> Body<'tcx> {
// "not all control paths return a value" is reported here. // "not all control paths return a value" is reported here.
// //
// maybe move the check to a MIR pass? // maybe move the check to a MIR pass?
tcx.ensure().check_liveness(def); tcx.ensure_ok().check_liveness(def);
// Don't steal here, instead steal in unsafeck. This is so that // Don't steal here, instead steal in unsafeck. This is so that
// pattern inline constants can be evaluated as part of building the // pattern inline constants can be evaluated as part of building the

View file

@ -1222,7 +1222,7 @@ fn collect_items_of_instance<'tcx>(
mode: CollectionMode, mode: CollectionMode,
) -> (MonoItems<'tcx>, MonoItems<'tcx>) { ) -> (MonoItems<'tcx>, MonoItems<'tcx>) {
// This item is getting monomorphized, do mono-time checks. // This item is getting monomorphized, do mono-time checks.
tcx.ensure().check_mono_item(instance); tcx.ensure_ok().check_mono_item(instance);
let body = tcx.instance_mir(instance.def); let body = tcx.instance_mir(instance.def);
// Naively, in "used" collection mode, all functions get added to *both* `used_items` and // Naively, in "used" collection mode, all functions get added to *both* `used_items` and

View file

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

View file

@ -575,7 +575,7 @@ fn report_conflicting_impls<'tcx>(
match used_to_be_allowed { match used_to_be_allowed {
None => { None => {
let reported = if overlap.with_impl.is_local() 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()); let mut err = tcx.dcx().struct_span_err(impl_span, msg());
err.code(E0119); 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 // Ensure that the impl is constrained, otherwise projection may give us
// bad unconstrained infer vars. // bad unconstrained infer vars.
if let Some(impl_def_id) = impl_def_id.as_local() { 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); 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 if assoc_item.item.container == ty::AssocItemContainer::Impl
&& let Some(impl_def_id) = assoc_item.item.container_id(tcx).as_local() && 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) Ok(assoc_item)

View file

@ -225,7 +225,7 @@ fn resolve_associated_item<'tcx>(
if trait_item_id != leaf_def.item.def_id if trait_item_id != leaf_def.item.def_id
&& let Some(leaf_def_item) = leaf_def.item.def_id.as_local() && let Some(leaf_def_item) = leaf_def.item.def_id.as_local()
{ {
tcx.ensure().compare_impl_item(leaf_def_item)?; tcx.ensure_ok().compare_impl_item(leaf_def_item)?;
} }
Some(ty::Instance::new(leaf_def.item.def_id, args)) Some(ty::Instance::new(leaf_def.item.def_id, args))

View file

@ -336,14 +336,14 @@ pub(crate) fn run_global_ctxt(
// NOTE: These are copy/pasted from typeck/lib.rs and should be kept in sync with those changes. // NOTE: These are copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
let _ = tcx.sess.time("wf_checking", || { let _ = tcx.sess.time("wf_checking", || {
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module)) tcx.hir().try_par_for_each_module(|module| tcx.ensure_ok().check_mod_type_wf(module))
}); });
tcx.dcx().abort_if_errors(); tcx.dcx().abort_if_errors();
tcx.sess.time("missing_docs", || rustc_lint::check_crate(tcx)); tcx.sess.time("missing_docs", || rustc_lint::check_crate(tcx));
tcx.sess.time("check_mod_attrs", || { tcx.sess.time("check_mod_attrs", || {
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_attrs(module)) tcx.hir().for_each_module(|module| tcx.ensure_ok().check_mod_attrs(module))
}); });
rustc_passes::stability::check_unused_or_stable_features(tcx); rustc_passes::stability::check_unused_or_stable_features(tcx);

View file

@ -21,6 +21,6 @@ impl<'tcx> LateLintPass<'tcx> for ClippyCtfe {
_: Span, _: Span,
defid: LocalDefId, defid: LocalDefId,
) { ) {
cx.tcx.ensure().mir_drops_elaborated_and_const_checked(defid); // Lint cx.tcx.ensure_ok().mir_drops_elaborated_and_const_checked(defid); // Lint
} }
} }