Skip to content

Commit f1f209d

Browse files
committed
remove 'tcx from signature of InferCtxtBuilder and friends
1 parent e5bbb5d commit f1f209d

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

src/librustc/infer/mod.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -404,41 +404,42 @@ impl fmt::Display for FixupError {
404404
/// Helper type of a temporary returned by tcx.infer_ctxt().
405405
/// Necessary because we can't write the following bound:
406406
/// F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(InferCtxt<'b, 'gcx, 'tcx>).
407-
pub struct InferCtxtBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
407+
pub struct InferCtxtBuilder<'a, 'gcx: 'a> {
408408
global_tcx: TyCtxt<'a, 'gcx, 'gcx>,
409409
arena: DroplessArena,
410-
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
410+
fresh_table_owner: Option<DefId>,
411411
}
412412

413-
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
414-
pub fn infer_ctxt(self) -> InferCtxtBuilder<'a, 'gcx, 'tcx> {
413+
impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
414+
pub fn infer_ctxt(self) -> InferCtxtBuilder<'a, 'gcx> {
415415
InferCtxtBuilder {
416416
global_tcx: self,
417417
arena: DroplessArena::new(),
418-
fresh_tables: None,
419-
418+
fresh_table_owner: None,
420419
}
421420
}
422421
}
423422

424-
impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
423+
impl<'a, 'gcx> InferCtxtBuilder<'a, 'gcx> {
425424
/// Used only by `rustc_typeck` during body type-checking/inference,
426425
/// will initialize `in_progress_tables` with fresh `TypeckTables`.
427426
pub fn with_fresh_in_progress_tables(mut self, table_owner: DefId) -> Self {
428-
self.fresh_tables = Some(RefCell::new(ty::TypeckTables::empty(Some(table_owner))));
427+
self.fresh_table_owner = Some(table_owner);
429428
self
430429
}
431430

432-
pub fn enter<R>(&'tcx mut self, f: impl FnOnce(&InferCtxt<'_, 'gcx, 'tcx>) -> R) -> R {
431+
pub fn enter<'tcx, R>(&'tcx mut self, f: impl FnOnce(&InferCtxt<'_, 'gcx, 'tcx>) -> R) -> R {
433432
let InferCtxtBuilder {
434433
global_tcx,
435434
ref arena,
436-
ref fresh_tables,
435+
fresh_table_owner,
437436
} = *self;
438-
let in_progress_tables = fresh_tables.as_ref();
437+
let in_progress_tables = fresh_table_owner.map(|table_owner| {
438+
RefCell::new(ty::TypeckTables::empty(Some(table_owner)))
439+
});
439440
global_tcx.enter_local(arena, |tcx| f(&InferCtxt {
440441
tcx,
441-
in_progress_tables,
442+
in_progress_tables: in_progress_tables.as_ref(),
442443
projection_cache: RefCell::new(traits::ProjectionCache::new()),
443444
type_variables: RefCell::new(type_variable::TypeVariableTable::new()),
444445
int_unification_table: RefCell::new(ut::UnificationTable::new()),

src/librustc_typeck/check/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,14 @@ impl<'a, 'gcx, 'tcx> Deref for FnCtxt<'a, 'gcx, 'tcx> {
587587
/// Helper type of a temporary returned by Inherited::build(...).
588588
/// Necessary because we can't write the following bound:
589589
/// F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(Inherited<'b, 'gcx, 'tcx>).
590-
pub struct InheritedBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
591-
infcx: infer::InferCtxtBuilder<'a, 'gcx, 'tcx>,
590+
pub struct InheritedBuilder<'a, 'gcx: 'a> {
591+
infcx: infer::InferCtxtBuilder<'a, 'gcx>,
592592
def_id: DefId,
593593
}
594594

595595
impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
596596
pub fn build(tcx: TyCtxt<'a, 'gcx, 'gcx>, def_id: DefId)
597-
-> InheritedBuilder<'a, 'gcx, 'tcx> {
597+
-> InheritedBuilder<'a, 'gcx> {
598598
let hir_id_root = if def_id.is_local() {
599599
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
600600
let hir_id = tcx.hir.definitions().node_to_hir_id(node_id);
@@ -610,10 +610,11 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
610610
}
611611
}
612612

613-
impl<'a, 'gcx, 'tcx> InheritedBuilder<'a, 'gcx, 'tcx> {
614-
fn enter<F, R>(&'tcx mut self, f: F) -> R
615-
where F: for<'b> FnOnce(Inherited<'b, 'gcx, 'tcx>) -> R
616-
{
613+
impl<'a, 'gcx> InheritedBuilder<'a, 'gcx> {
614+
fn enter<'tcx, R>(
615+
&'tcx mut self,
616+
f: impl FnOnce(Inherited<'_, 'gcx, 'tcx>) -> R,
617+
) -> R {
617618
let def_id = self.def_id;
618619
self.infcx.enter(|infcx| f(Inherited::new(infcx, def_id)))
619620
}

src/librustc_typeck/check/wfcheck.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,22 @@ pub struct CheckTypeWellFormedVisitor<'a, 'tcx:'a> {
3434
/// Helper type of a temporary returned by .for_item(...).
3535
/// Necessary because we can't write the following bound:
3636
/// F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(FnCtxt<'b, 'gcx, 'tcx>).
37-
struct CheckWfFcxBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
38-
inherited: super::InheritedBuilder<'a, 'gcx, 'tcx>,
37+
struct CheckWfFcxBuilder<'a, 'gcx: 'a> {
38+
inherited: super::InheritedBuilder<'a, 'gcx>,
3939
code: ObligationCauseCode<'gcx>,
4040
id: ast::NodeId,
4141
span: Span,
42-
param_env: ty::ParamEnv<'tcx>,
42+
param_env: ty::ParamEnv<'gcx>,
4343
}
4444

45-
impl<'a, 'gcx, 'tcx> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
46-
fn with_fcx<F>(&'tcx mut self, f: F) where
47-
F: for<'b> FnOnce(&FnCtxt<'b, 'gcx, 'tcx>,
48-
&mut CheckTypeWellFormedVisitor<'b, 'gcx>) -> Vec<Ty<'tcx>>
49-
{
45+
impl<'a, 'gcx> CheckWfFcxBuilder<'a, 'gcx> {
46+
fn with_fcx<'tcx>(
47+
&'tcx mut self,
48+
f: impl for<'b> FnOnce(
49+
&FnCtxt<'b, 'gcx, 'tcx>,
50+
&mut CheckTypeWellFormedVisitor<'b, 'gcx>,
51+
) -> Vec<Ty<'tcx>>,
52+
) {
5053
let code = self.code.clone();
5154
let id = self.id;
5255
let span = self.span;
@@ -203,13 +206,11 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
203206
})
204207
}
205208

206-
fn for_item<'tcx>(&self, item: &hir::Item)
207-
-> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
209+
fn for_item(&self, item: &hir::Item) -> CheckWfFcxBuilder<'a, 'gcx> {
208210
self.for_id(item.id, item.span)
209211
}
210212

211-
fn for_id<'tcx>(&self, id: ast::NodeId, span: Span)
212-
-> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
213+
fn for_id(&self, id: ast::NodeId, span: Span) -> CheckWfFcxBuilder<'a, 'gcx> {
213214
let def_id = self.tcx.hir.local_def_id(id);
214215
CheckWfFcxBuilder {
215216
inherited: Inherited::build(self.tcx, def_id),

src/librustc_typeck/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ This API is completely unstable and subject to change.
8888
#![feature(slice_patterns)]
8989
#![feature(i128_type)]
9090
#![cfg_attr(stage0, feature(never_type))]
91+
#![feature(underscore_lifetimes)]
92+
#![feature(universal_impl_trait)]
9193

9294
#[macro_use] extern crate log;
9395
#[macro_use] extern crate syntax;

0 commit comments

Comments
 (0)