Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherited always has TypeckResults available #99709

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions compiler/rustc_typeck/src/check/inherited.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::callee::DeferredCallResolution;
use super::MaybeInProgressTables;

use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
Expand Down Expand Up @@ -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>>>,

Expand Down Expand Up @@ -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()),
Expand Down
29 changes: 1 addition & 28 deletions compiler/rustc_typeck/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down