Inherited always has TypeckResults available

This commit is contained in:
lcnr 2022-07-25 13:11:07 +02:00
parent 2f320a224e
commit 0c6c69f2e2
2 changed files with 5 additions and 33 deletions

View File

@ -1,5 +1,4 @@
use super::callee::DeferredCallResolution;
use super::MaybeInProgressTables;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
@ -29,7 +28,7 @@ use std::ops::Deref;
pub struct Inherited<'a, 'tcx> {
pub(super) infcx: InferCtxt<'a, 'tcx>,
pub(super) typeck_results: super::MaybeInProgressTables<'a, 'tcx>,
pub(super) typeck_results: &'a RefCell<ty::TypeckResults<'tcx>>,
pub(super) locals: RefCell<HirIdMap<super::LocalTy<'tcx>>>,
@ -110,11 +109,11 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {
let tcx = infcx.tcx;
let item_id = tcx.hir().local_def_id_to_hir_id(def_id);
let body_id = tcx.hir().maybe_body_owned_by(item_id);
let typeck_results =
infcx.in_progress_typeck_results.expect("building `FnCtxt` without typeck results");
Inherited {
typeck_results: MaybeInProgressTables {
maybe_typeck_results: infcx.in_progress_typeck_results,
},
typeck_results,
infcx,
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new(tcx)),
locals: RefCell::new(Default::default()),

View File

@ -128,8 +128,7 @@ use rustc_target::spec::abi::Abi;
use rustc_trait_selection::traits;
use rustc_trait_selection::traits::error_reporting::recursive_type_with_infinite_size_error;
use rustc_trait_selection::traits::error_reporting::suggestions::ReturnsVisitor;
use std::cell::{Ref, RefCell, RefMut};
use std::cell::RefCell;
use crate::require_c_abi_if_c_variadic;
use crate::util::common::indenter;
@ -900,32 +899,6 @@ enum TupleArgumentsFlag {
TupleArguments,
}
/// A wrapper for `InferCtxt`'s `in_progress_typeck_results` field.
#[derive(Copy, Clone)]
struct MaybeInProgressTables<'a, 'tcx> {
maybe_typeck_results: Option<&'a RefCell<ty::TypeckResults<'tcx>>>,
}
impl<'a, 'tcx> MaybeInProgressTables<'a, 'tcx> {
fn borrow(self) -> Ref<'a, ty::TypeckResults<'tcx>> {
match self.maybe_typeck_results {
Some(typeck_results) => typeck_results.borrow(),
None => bug!(
"MaybeInProgressTables: inh/fcx.typeck_results.borrow() with no typeck results"
),
}
}
fn borrow_mut(self) -> RefMut<'a, ty::TypeckResults<'tcx>> {
match self.maybe_typeck_results {
Some(typeck_results) => typeck_results.borrow_mut(),
None => bug!(
"MaybeInProgressTables: inh/fcx.typeck_results.borrow_mut() with no typeck results"
),
}
}
}
fn typeck_item_bodies(tcx: TyCtxt<'_>, (): ()) {
tcx.hir().par_body_owners(|body_owner_def_id| tcx.ensure().typeck(body_owner_def_id));
}