Skip to content

Commit 45fdf97

Browse files
Removed util.rs
Per suggestion of @oli-obk. This file was rather short and joining it did not cause mod.rs to become significantly bigger.
1 parent c8162c2 commit 45fdf97

File tree

2 files changed

+64
-77
lines changed

2 files changed

+64
-77
lines changed

compiler/rustc_typeck/src/check/mod.rs

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,21 @@ mod pat;
8282
mod place_op;
8383
mod regionck;
8484
mod upvar;
85-
mod util;
8685
mod wfcheck;
8786
pub mod writeback;
8887

8988
pub use fn_ctxt::FnCtxt;
9089

9190
use crate::astconv::AstConv;
9291
use crate::check::gather_locals::GatherLocalsVisitor;
93-
use crate::check::util::MaybeInProgressTables;
9492
use rustc_attr as attr;
9593
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
9694
use rustc_errors::{pluralize, struct_span_err, Applicability};
9795
use rustc_hir as hir;
9896
use rustc_hir::def::Res;
99-
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
97+
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
10098
use rustc_hir::intravisit::Visitor;
99+
use rustc_hir::itemlikevisit::ItemLikeVisitor;
101100
use rustc_hir::lang_items::LangItem;
102101
use rustc_hir::{HirIdMap, ItemKind, Node};
103102
use rustc_index::bit_set::BitSet;
@@ -126,7 +125,7 @@ use rustc_trait_selection::traits::error_reporting::recursive_type_with_infinite
126125
use rustc_trait_selection::traits::error_reporting::suggestions::ReturnsVisitor;
127126
use rustc_trait_selection::traits::{self, ObligationCauseCode, TraitEngine, TraitEngineExt};
128127

129-
use std::cell::RefCell;
128+
use std::cell::{Ref, RefCell, RefMut};
130129
use std::cmp;
131130
use std::ops::{self, Deref};
132131

@@ -586,10 +585,6 @@ pub fn check_wf_new(tcx: TyCtxt<'_>) {
586585

587586
pub fn provide(providers: &mut Providers) {
588587
method::provide(providers);
589-
use util::{
590-
check_impl_item_well_formed, check_item_well_formed, check_mod_item_types,
591-
check_trait_item_well_formed, typeck_item_bodies,
592-
};
593588
*providers = Providers {
594589
typeck_item_bodies,
595590
typeck_const_arg,
@@ -2720,6 +2715,67 @@ fn check_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics,
27202715
}
27212716
}
27222717

2718+
/// A wrapper for `InferCtxt`'s `in_progress_typeck_results` field.
2719+
#[derive(Copy, Clone)]
2720+
struct MaybeInProgressTables<'a, 'tcx> {
2721+
maybe_typeck_results: Option<&'a RefCell<ty::TypeckResults<'tcx>>>,
2722+
}
2723+
2724+
impl<'a, 'tcx> MaybeInProgressTables<'a, 'tcx> {
2725+
fn borrow(self) -> Ref<'a, ty::TypeckResults<'tcx>> {
2726+
match self.maybe_typeck_results {
2727+
Some(typeck_results) => typeck_results.borrow(),
2728+
None => bug!(
2729+
"MaybeInProgressTables: inh/fcx.typeck_results.borrow() with no typeck results"
2730+
),
2731+
}
2732+
}
2733+
2734+
fn borrow_mut(self) -> RefMut<'a, ty::TypeckResults<'tcx>> {
2735+
match self.maybe_typeck_results {
2736+
Some(typeck_results) => typeck_results.borrow_mut(),
2737+
None => bug!(
2738+
"MaybeInProgressTables: inh/fcx.typeck_results.borrow_mut() with no typeck results"
2739+
),
2740+
}
2741+
}
2742+
}
2743+
2744+
struct CheckItemTypesVisitor<'tcx> {
2745+
tcx: TyCtxt<'tcx>,
2746+
}
2747+
2748+
impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> {
2749+
fn visit_item(&mut self, i: &'tcx hir::Item<'tcx>) {
2750+
check_item_type(self.tcx, i);
2751+
}
2752+
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {}
2753+
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) {}
2754+
}
2755+
2756+
fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
2757+
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckItemTypesVisitor { tcx });
2758+
}
2759+
2760+
fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
2761+
wfcheck::check_item_well_formed(tcx, def_id);
2762+
}
2763+
2764+
fn check_trait_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
2765+
wfcheck::check_trait_item(tcx, def_id);
2766+
}
2767+
2768+
fn check_impl_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
2769+
wfcheck::check_impl_item(tcx, def_id);
2770+
}
2771+
2772+
fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) {
2773+
debug_assert!(crate_num == LOCAL_CRATE);
2774+
tcx.par_body_owners(|body_owner_def_id| {
2775+
tcx.ensure().typeck(body_owner_def_id);
2776+
});
2777+
}
2778+
27232779
fn fatally_break_rust(sess: &Session) {
27242780
let handler = sess.diagnostic();
27252781
handler.span_bug_no_panic(

compiler/rustc_typeck/src/check/util.rs

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)