Skip to content

Commit 76affa5

Browse files
committed
rustc: Split 'tcx into 'gcx and 'tcx for InferCtxt and its users.
1 parent 166dbc3 commit 76affa5

File tree

160 files changed

+1296
-1189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+1296
-1189
lines changed

src/librustc/cfg/construct.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use syntax::ptr::P;
1919
use hir::{self, PatKind};
2020

2121
struct CFGBuilder<'a, 'tcx: 'a> {
22-
tcx: TyCtxt<'a, 'tcx>,
22+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
2323
graph: CFGGraph,
2424
fn_exit: CFGIndex,
2525
loop_scopes: Vec<LoopScope>,
@@ -32,8 +32,8 @@ struct LoopScope {
3232
break_index: CFGIndex, // where to go on a `break
3333
}
3434

35-
pub fn construct(tcx: TyCtxt,
36-
blk: &hir::Block) -> CFG {
35+
pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
36+
blk: &hir::Block) -> CFG {
3737
let mut graph = graph::Graph::new();
3838
let entry = graph.add_node(CFGNodeData::Entry);
3939

src/librustc/cfg/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ pub type CFGNode = graph::Node<CFGNodeData>;
5858
pub type CFGEdge = graph::Edge<CFGEdgeData>;
5959

6060
impl CFG {
61-
pub fn new(tcx: TyCtxt,
62-
blk: &hir::Block) -> CFG {
61+
pub fn new<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
62+
blk: &hir::Block) -> CFG {
6363
construct::construct(tcx, blk)
6464
}
6565

src/librustc/dep_graph/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ use super::dep_node::DepNode;
2222
/// read edge from the corresponding AST node. This is used in
2323
/// compiler passes to automatically record the item that they are
2424
/// working on.
25-
pub fn visit_all_items_in_krate<'a, 'tcx, V, F>(tcx: TyCtxt<'a, 'tcx>,
25+
pub fn visit_all_items_in_krate<'a, 'tcx, V, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
2626
mut dep_node_fn: F,
2727
visitor: &mut V)
2828
where F: FnMut(DefId) -> DepNode<DefId>, V: Visitor<'tcx>
2929
{
3030
struct TrackingVisitor<'visit, 'tcx: 'visit, F: 'visit, V: 'visit> {
31-
tcx: TyCtxt<'visit, 'tcx>,
31+
tcx: TyCtxt<'visit, 'tcx, 'tcx>,
3232
dep_node_fn: &'visit mut F,
3333
visitor: &'visit mut V
3434
}

src/librustc/hir/pat_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub fn simple_name<'a>(pat: &'a hir::Pat) -> Option<ast::Name> {
209209
}
210210
}
211211

212-
pub fn def_to_path(tcx: TyCtxt, id: DefId) -> hir::Path {
212+
pub fn def_to_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> hir::Path {
213213
let name = tcx.item_name(id);
214214
hir::Path::from_ident(DUMMY_SP, hir::Ident::from_name(name))
215215
}

src/librustc/infer/bivariate.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ use ty::{self, Ty, TyCtxt};
3232
use ty::TyVar;
3333
use ty::relate::{Relate, RelateResult, TypeRelation};
3434

35-
pub struct Bivariate<'a, 'tcx: 'a> {
36-
fields: CombineFields<'a, 'tcx>
35+
pub struct Bivariate<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
36+
fields: CombineFields<'a, 'gcx, 'tcx>
3737
}
3838

39-
impl<'a, 'tcx> Bivariate<'a, 'tcx> {
40-
pub fn new(fields: CombineFields<'a, 'tcx>) -> Bivariate<'a, 'tcx> {
39+
impl<'a, 'tcx> Bivariate<'a, 'tcx, 'tcx> {
40+
pub fn new(fields: CombineFields<'a, 'tcx, 'tcx>) -> Bivariate<'a, 'tcx, 'tcx> {
4141
Bivariate { fields: fields }
4242
}
4343
}
4444

45-
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Bivariate<'a, 'tcx> {
45+
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Bivariate<'a, 'tcx, 'tcx> {
4646
fn tag(&self) -> &'static str { "Bivariate" }
4747

48-
fn tcx(&self) -> TyCtxt<'a, 'tcx> { self.fields.tcx() }
48+
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.fields.tcx() }
4949

5050
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
5151

src/librustc/infer/combine.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ use syntax::ast;
5252
use syntax::codemap::Span;
5353

5454
#[derive(Clone)]
55-
pub struct CombineFields<'a, 'tcx: 'a> {
56-
pub infcx: &'a InferCtxt<'a, 'tcx>,
55+
pub struct CombineFields<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
56+
pub infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
5757
pub a_is_expected: bool,
5858
pub trace: TypeTrace<'tcx>,
5959
pub cause: Option<ty::relate::Cause>,
6060
pub obligations: PredicateObligations<'tcx>,
6161
}
6262

63-
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
63+
impl<'a, 'tcx> InferCtxt<'a, 'tcx, 'tcx> {
6464
pub fn super_combine_tys<R>(&self,
6565
relation: &mut R,
6666
a: Ty<'tcx>,
@@ -150,35 +150,35 @@ fn unify_float_variable(&self,
150150
}
151151
}
152152

153-
impl<'a, 'tcx> CombineFields<'a, 'tcx> {
154-
pub fn tcx(&self) -> TyCtxt<'a, 'tcx> {
153+
impl<'a, 'tcx> CombineFields<'a, 'tcx, 'tcx> {
154+
pub fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
155155
self.infcx.tcx
156156
}
157157

158-
pub fn switch_expected(&self) -> CombineFields<'a, 'tcx> {
158+
pub fn switch_expected(&self) -> CombineFields<'a, 'tcx, 'tcx> {
159159
CombineFields {
160160
a_is_expected: !self.a_is_expected,
161161
..(*self).clone()
162162
}
163163
}
164164

165-
pub fn equate(&self) -> Equate<'a, 'tcx> {
165+
pub fn equate(&self) -> Equate<'a, 'tcx, 'tcx> {
166166
Equate::new(self.clone())
167167
}
168168

169-
pub fn bivariate(&self) -> Bivariate<'a, 'tcx> {
169+
pub fn bivariate(&self) -> Bivariate<'a, 'tcx, 'tcx> {
170170
Bivariate::new(self.clone())
171171
}
172172

173-
pub fn sub(&self) -> Sub<'a, 'tcx> {
173+
pub fn sub(&self) -> Sub<'a, 'tcx, 'tcx> {
174174
Sub::new(self.clone())
175175
}
176176

177-
pub fn lub(&self) -> Lub<'a, 'tcx> {
177+
pub fn lub(&self) -> Lub<'a, 'tcx, 'tcx> {
178178
Lub::new(self.clone())
179179
}
180180

181-
pub fn glb(&self) -> Glb<'a, 'tcx> {
181+
pub fn glb(&self) -> Glb<'a, 'tcx, 'tcx> {
182182
Glb::new(self.clone())
183183
}
184184

@@ -291,16 +291,16 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
291291
}
292292
}
293293

294-
struct Generalizer<'cx, 'tcx:'cx> {
295-
infcx: &'cx InferCtxt<'cx, 'tcx>,
294+
struct Generalizer<'cx, 'gcx: 'cx+'tcx, 'tcx: 'cx> {
295+
infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
296296
span: Span,
297297
for_vid: ty::TyVid,
298298
make_region_vars: bool,
299299
cycle_detected: bool,
300300
}
301301

302-
impl<'cx, 'tcx> ty::fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
303-
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx> {
302+
impl<'cx, 'tcx> ty::fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx, 'tcx> {
303+
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
304304
self.infcx.tcx
305305
}
306306

src/librustc/infer/equate.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use ty::relate::{Relate, RelateResult, TypeRelation};
1919
use traits::PredicateObligations;
2020

2121
/// Ensures `a` is made equal to `b`. Returns `a` on success.
22-
pub struct Equate<'a, 'tcx: 'a> {
23-
fields: CombineFields<'a, 'tcx>
22+
pub struct Equate<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
23+
fields: CombineFields<'a, 'gcx, 'tcx>
2424
}
2525

26-
impl<'a, 'tcx> Equate<'a, 'tcx> {
27-
pub fn new(fields: CombineFields<'a, 'tcx>) -> Equate<'a, 'tcx> {
26+
impl<'a, 'tcx> Equate<'a, 'tcx, 'tcx> {
27+
pub fn new(fields: CombineFields<'a, 'tcx, 'tcx>) -> Equate<'a, 'tcx, 'tcx> {
2828
Equate { fields: fields }
2929
}
3030

@@ -33,10 +33,10 @@ impl<'a, 'tcx> Equate<'a, 'tcx> {
3333
}
3434
}
3535

36-
impl<'a, 'tcx> TypeRelation<'a,'tcx> for Equate<'a, 'tcx> {
36+
impl<'a, 'tcx> TypeRelation<'a,'tcx> for Equate<'a, 'tcx, 'tcx> {
3737
fn tag(&self) -> &'static str { "Equate" }
3838

39-
fn tcx(&self) -> TyCtxt<'a, 'tcx> { self.fields.tcx() }
39+
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.fields.tcx() }
4040

4141
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
4242

src/librustc/infer/error_reporting.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ use syntax::codemap::{self, Pos, Span};
9595
use syntax::parse::token;
9696
use syntax::ptr::P;
9797

98-
impl<'a, 'tcx> TyCtxt<'a, 'tcx> {
98+
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
9999
pub fn note_and_explain_region(self,
100100
err: &mut DiagnosticBuilder,
101101
prefix: &str,
@@ -112,8 +112,9 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx> {
112112
}
113113
}
114114

115-
fn explain_span(tcx: TyCtxt, heading: &str, span: Span)
116-
-> (String, Option<Span>) {
115+
fn explain_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
116+
heading: &str, span: Span)
117+
-> (String, Option<Span>) {
117118
let lo = tcx.sess.codemap().lookup_char_pos_adj(span.lo);
118119
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize()),
119120
Some(span))
@@ -301,7 +302,7 @@ trait ErrorReportingHelpers<'tcx> {
301302
span: Span);
302303
}
303304

304-
impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
305+
impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
305306
fn report_region_errors(&self,
306307
errors: &Vec<RegionResolutionError<'tcx>>) {
307308
debug!("report_region_errors(): {} errors to start", errors.len());
@@ -474,10 +475,10 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
474475
}
475476
}
476477

477-
fn free_regions_from_same_fn(tcx: TyCtxt,
478-
sub: Region,
479-
sup: Region)
480-
-> Option<FreeRegionsFromSameFn> {
478+
fn free_regions_from_same_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
479+
sub: Region,
480+
sup: Region)
481+
-> Option<FreeRegionsFromSameFn> {
481482
debug!("free_regions_from_same_fn(sub={:?}, sup={:?})", sub, sup);
482483
let (scope_id, fr1, fr2) = match (sub, sup) {
483484
(ReFree(fr1), ReFree(fr2)) => {
@@ -1109,7 +1110,7 @@ struct RebuildPathInfo<'a> {
11091110
}
11101111

11111112
struct Rebuilder<'a, 'tcx: 'a> {
1112-
tcx: TyCtxt<'a, 'tcx>,
1113+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
11131114
fn_decl: &'a hir::FnDecl,
11141115
expl_self_opt: Option<&'a hir::ExplicitSelf_>,
11151116
generics: &'a hir::Generics,
@@ -1125,7 +1126,7 @@ enum FreshOrKept {
11251126
}
11261127

11271128
impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
1128-
fn new(tcx: TyCtxt<'a, 'tcx>,
1129+
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11291130
fn_decl: &'a hir::FnDecl,
11301131
expl_self_opt: Option<&'a hir::ExplicitSelf_>,
11311132
generics: &'a hir::Generics,
@@ -1641,7 +1642,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
16411642
}
16421643
}
16431644

1644-
impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
1645+
impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
16451646
fn give_expl_lifetime_param(&self,
16461647
err: &mut DiagnosticBuilder,
16471648
decl: &hir::FnDecl,
@@ -1904,34 +1905,34 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
19041905
}
19051906

19061907
pub trait Resolvable<'tcx> {
1907-
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx>) -> Self;
1908+
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx, 'tcx>) -> Self;
19081909
}
19091910

19101911
impl<'tcx> Resolvable<'tcx> for Ty<'tcx> {
1911-
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx>) -> Ty<'tcx> {
1912+
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
19121913
infcx.resolve_type_vars_if_possible(self)
19131914
}
19141915
}
19151916

19161917
impl<'tcx> Resolvable<'tcx> for ty::TraitRef<'tcx> {
1917-
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx>)
1918+
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx, 'tcx>)
19181919
-> ty::TraitRef<'tcx> {
19191920
infcx.resolve_type_vars_if_possible(self)
19201921
}
19211922
}
19221923

19231924
impl<'tcx> Resolvable<'tcx> for ty::PolyTraitRef<'tcx> {
19241925
fn resolve<'a>(&self,
1925-
infcx: &InferCtxt<'a, 'tcx>)
1926+
infcx: &InferCtxt<'a, 'tcx, 'tcx>)
19261927
-> ty::PolyTraitRef<'tcx>
19271928
{
19281929
infcx.resolve_type_vars_if_possible(self)
19291930
}
19301931
}
19311932

1932-
fn lifetimes_in_scope(tcx: TyCtxt,
1933-
scope_id: ast::NodeId)
1934-
-> Vec<hir::LifetimeDef> {
1933+
fn lifetimes_in_scope<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1934+
scope_id: ast::NodeId)
1935+
-> Vec<hir::LifetimeDef> {
19351936
let mut taken = Vec::new();
19361937
let parent = tcx.map.get_parent(scope_id);
19371938
let method_id_opt = match tcx.map.find(parent) {

src/librustc/infer/freshen.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ use std::collections::hash_map::{self, Entry};
3737
use super::InferCtxt;
3838
use super::unify_key::ToType;
3939

40-
pub struct TypeFreshener<'a, 'tcx:'a> {
41-
infcx: &'a InferCtxt<'a, 'tcx>,
40+
pub struct TypeFreshener<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
41+
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
4242
freshen_count: u32,
4343
freshen_map: hash_map::HashMap<ty::InferTy, Ty<'tcx>>,
4444
}
4545

46-
impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
47-
pub fn new(infcx: &'a InferCtxt<'a, 'tcx>) -> TypeFreshener<'a, 'tcx> {
46+
impl<'a, 'tcx> TypeFreshener<'a, 'tcx, 'tcx> {
47+
pub fn new(infcx: &'a InferCtxt<'a, 'tcx, 'tcx>) -> TypeFreshener<'a, 'tcx, 'tcx> {
4848
TypeFreshener {
4949
infcx: infcx,
5050
freshen_count: 0,
@@ -77,8 +77,8 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
7777
}
7878
}
7979

80-
impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
81-
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx> {
80+
impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx, 'tcx> {
81+
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
8282
self.infcx.tcx
8383
}
8484

src/librustc/infer/glb.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use ty::relate::{Relate, RelateResult, TypeRelation};
1919
use traits::PredicateObligations;
2020

2121
/// "Greatest lower bound" (common subtype)
22-
pub struct Glb<'a, 'tcx: 'a> {
23-
fields: CombineFields<'a, 'tcx>
22+
pub struct Glb<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
23+
fields: CombineFields<'a, 'gcx, 'tcx>
2424
}
2525

26-
impl<'a, 'tcx> Glb<'a, 'tcx> {
27-
pub fn new(fields: CombineFields<'a, 'tcx>) -> Glb<'a, 'tcx> {
26+
impl<'a, 'tcx> Glb<'a, 'tcx, 'tcx> {
27+
pub fn new(fields: CombineFields<'a, 'tcx, 'tcx>) -> Glb<'a, 'tcx, 'tcx> {
2828
Glb { fields: fields }
2929
}
3030

@@ -33,10 +33,10 @@ impl<'a, 'tcx> Glb<'a, 'tcx> {
3333
}
3434
}
3535

36-
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Glb<'a, 'tcx> {
36+
impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Glb<'a, 'tcx, 'tcx> {
3737
fn tag(&self) -> &'static str { "Glb" }
3838

39-
fn tcx(&self) -> TyCtxt<'a, 'tcx> { self.fields.tcx() }
39+
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> { self.fields.tcx() }
4040

4141
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
4242

@@ -76,8 +76,8 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Glb<'a, 'tcx> {
7676
}
7777
}
7878

79-
impl<'a, 'tcx> LatticeDir<'a,'tcx> for Glb<'a, 'tcx> {
80-
fn infcx(&self) -> &'a InferCtxt<'a,'tcx> {
79+
impl<'a, 'tcx> LatticeDir<'a,'tcx> for Glb<'a, 'tcx, 'tcx> {
80+
fn infcx(&self) -> &'a InferCtxt<'a, 'tcx, 'tcx> {
8181
self.fields.infcx
8282
}
8383

0 commit comments

Comments
 (0)