From 0c6c69f2e2106c7717275260e5bfc4712c640cc3 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 25 Jul 2022 13:11:07 +0200 Subject: [PATCH] `Inherited` always has `TypeckResults` available --- compiler/rustc_typeck/src/check/inherited.rs | 9 +++--- compiler/rustc_typeck/src/check/mod.rs | 29 +------------------- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_typeck/src/check/inherited.rs b/compiler/rustc_typeck/src/check/inherited.rs index 2f841fc277ded..a499179b95f10 100644 --- a/compiler/rustc_typeck/src/check/inherited.rs +++ b/compiler/rustc_typeck/src/check/inherited.rs @@ -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>, pub(super) locals: RefCell>>, @@ -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(>::new(tcx)), locals: RefCell::new(Default::default()), diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index b088fc9eddb85..17c2e4868aac7 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -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>>, -} - -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)); }