Skip to content

Commit 31a07b0

Browse files
committed
rustc_typeck: Generalize over 'tcx != 'gcx.
1 parent 3a30136 commit 31a07b0

33 files changed

+942
-888
lines changed

src/librustc/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
8989
float_unification_table: RefCell<UnificationTable<ty::FloatVid>>,
9090

9191
// For region variables.
92-
region_vars: RegionVarBindings<'a, 'tcx>,
92+
region_vars: RegionVarBindings<'a, 'gcx, 'tcx>,
9393

9494
pub parameter_environment: ty::ParameterEnvironment<'gcx>,
9595

src/librustc/infer/region_inference/graphviz.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ graphs will be printed. \n\
5353
");
5454
}
5555

56-
pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a, 'tcx>,
57-
subject_node: ast::NodeId) {
56+
pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
57+
region_vars: &RegionVarBindings<'a, 'gcx, 'tcx>,
58+
subject_node: ast::NodeId)
59+
{
5860
let tcx = region_vars.tcx;
5961

6062
if !region_vars.tcx.sess.opts.debugging_opts.print_region_graph {
@@ -118,8 +120,8 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
118120
}
119121
}
120122

121-
struct ConstraintGraph<'a, 'tcx: 'a> {
122-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
123+
struct ConstraintGraph<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
124+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
123125
graph_name: String,
124126
map: &'a FnvHashMap<Constraint, SubregionOrigin<'tcx>>,
125127
node_ids: FnvHashMap<Node, usize>,
@@ -138,11 +140,11 @@ enum Edge {
138140
EnclScope(CodeExtent, CodeExtent),
139141
}
140142

141-
impl<'a, 'tcx> ConstraintGraph<'a, 'tcx> {
142-
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
143+
impl<'a, 'gcx, 'tcx> ConstraintGraph<'a, 'gcx, 'tcx> {
144+
fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
143145
name: String,
144146
map: &'a ConstraintMap<'tcx>)
145-
-> ConstraintGraph<'a, 'tcx> {
147+
-> ConstraintGraph<'a, 'gcx, 'tcx> {
146148
let mut i = 0;
147149
let mut node_ids = FnvHashMap();
148150
{
@@ -173,7 +175,7 @@ impl<'a, 'tcx> ConstraintGraph<'a, 'tcx> {
173175
}
174176
}
175177

176-
impl<'a, 'tcx> dot::Labeller<'a> for ConstraintGraph<'a, 'tcx> {
178+
impl<'a, 'gcx, 'tcx> dot::Labeller<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
177179
type Node = Node;
178180
type Edge = Edge;
179181
fn graph_id(&self) -> dot::Id {
@@ -226,7 +228,7 @@ fn edge_to_nodes(e: &Edge) -> (Node, Node) {
226228
}
227229
}
228230

229-
impl<'a, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'tcx> {
231+
impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
230232
type Node = Node;
231233
type Edge = Edge;
232234
fn nodes(&self) -> dot::Nodes<Node> {
@@ -258,10 +260,10 @@ impl<'a, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'tcx> {
258260

259261
pub type ConstraintMap<'tcx> = FnvHashMap<Constraint, SubregionOrigin<'tcx>>;
260262

261-
fn dump_region_constraints_to<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
262-
map: &ConstraintMap<'tcx>,
263-
path: &str)
264-
-> io::Result<()> {
263+
fn dump_region_constraints_to<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
264+
map: &ConstraintMap<'tcx>,
265+
path: &str)
266+
-> io::Result<()> {
265267
debug!("dump_region_constraints map (len: {}) path: {}",
266268
map.len(),
267269
path);

src/librustc/infer/region_inference/mod.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ impl SameRegions {
190190

191191
pub type CombineMap = FnvHashMap<TwoRegions, RegionVid>;
192192

193-
pub struct RegionVarBindings<'a, 'tcx: 'a> {
194-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
193+
pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
194+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
195195
var_origins: RefCell<Vec<RegionVariableOrigin>>,
196196

197197
// Constraints of the form `A <= B` introduced by the region
@@ -253,8 +253,8 @@ pub struct RegionSnapshot {
253253
skolemization_count: u32,
254254
}
255255

256-
impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
257-
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> RegionVarBindings<'a, 'tcx> {
256+
impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
257+
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> RegionVarBindings<'a, 'gcx, 'tcx> {
258258
RegionVarBindings {
259259
tcx: tcx,
260260
var_origins: RefCell::new(Vec::new()),
@@ -600,7 +600,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
600600
origin: SubregionOrigin<'tcx>,
601601
mut relate: F)
602602
-> Region
603-
where F: FnMut(&RegionVarBindings<'a, 'tcx>, Region, Region)
603+
where F: FnMut(&RegionVarBindings<'a, 'gcx, 'tcx>, Region, Region)
604604
{
605605
let vars = TwoRegions { a: a, b: b };
606606
match self.combine_map(t).borrow().get(&vars) {
@@ -816,7 +816,7 @@ struct RegionAndOrigin<'tcx> {
816816

817817
type RegionGraph = graph::Graph<(), Constraint>;
818818

819-
impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
819+
impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
820820
fn infer_variable_values(&self,
821821
free_regions: &FreeRegionMap,
822822
errors: &mut Vec<RegionResolutionError<'tcx>>,
@@ -1249,11 +1249,11 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
12491249
let WalkState {result, dup_found, ..} = state;
12501250
return (result, dup_found);
12511251

1252-
fn process_edges<'a, 'tcx>(this: &RegionVarBindings<'a, 'tcx>,
1253-
state: &mut WalkState<'tcx>,
1254-
graph: &RegionGraph,
1255-
source_vid: RegionVid,
1256-
dir: Direction) {
1252+
fn process_edges<'a, 'gcx, 'tcx>(this: &RegionVarBindings<'a, 'gcx, 'tcx>,
1253+
state: &mut WalkState<'tcx>,
1254+
graph: &RegionGraph,
1255+
source_vid: RegionVid,
1256+
dir: Direction) {
12571257
debug!("process_edges(source_vid={:?}, dir={:?})", source_vid, dir);
12581258

12591259
let source_node_index = NodeIndex(source_vid.index as usize);
@@ -1362,16 +1362,16 @@ impl<'tcx> fmt::Display for GenericKind<'tcx> {
13621362
}
13631363
}
13641364

1365-
impl<'a, 'tcx> GenericKind<'tcx> {
1366-
pub fn to_ty(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
1365+
impl<'a, 'gcx, 'tcx> GenericKind<'tcx> {
1366+
pub fn to_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
13671367
match *self {
13681368
GenericKind::Param(ref p) => p.to_ty(tcx),
13691369
GenericKind::Projection(ref p) => tcx.mk_projection(p.trait_ref.clone(), p.item_name),
13701370
}
13711371
}
13721372
}
13731373

1374-
impl<'a, 'tcx> VerifyBound {
1374+
impl<'a, 'gcx, 'tcx> VerifyBound {
13751375
fn for_each_region(&self, f: &mut FnMut(ty::Region)) {
13761376
match self {
13771377
&VerifyBound::AnyRegion(ref rs) |
@@ -1424,7 +1424,7 @@ impl<'a, 'tcx> VerifyBound {
14241424
}
14251425
}
14261426

1427-
fn is_met(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
1427+
fn is_met(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
14281428
free_regions: &FreeRegionMap,
14291429
var_values: &Vec<VarValue>,
14301430
min: ty::Region)

src/librustc/middle/astconv_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ty::{Ty, TyCtxt};
2020
use syntax::codemap::Span;
2121
use hir as ast;
2222

23-
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
23+
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2424
pub fn prohibit_type_params(self, segments: &[ast::PathSegment]) {
2525
for segment in segments {
2626
for typ in segment.parameters.types() {

src/librustc/middle/expr_use_visitor.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ enum OverloadedCallType {
209209
}
210210

211211
impl OverloadedCallType {
212-
fn from_trait_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_id: DefId)
213-
-> OverloadedCallType {
212+
fn from_trait_id(tcx: TyCtxt, trait_id: DefId) -> OverloadedCallType {
214213
for &(maybe_function_trait, overloaded_call_type) in &[
215214
(tcx.lang_items.fn_once_trait(), FnOnceOverloadedCall),
216215
(tcx.lang_items.fn_mut_trait(), FnMutOverloadedCall),
@@ -227,8 +226,7 @@ impl OverloadedCallType {
227226
bug!("overloaded call didn't map to known function trait")
228227
}
229228

230-
fn from_method_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, method_id: DefId)
231-
-> OverloadedCallType {
229+
fn from_method_id(tcx: TyCtxt, method_id: DefId) -> OverloadedCallType {
232230
let method = tcx.impl_or_trait_item(method_id);
233231
OverloadedCallType::from_trait_id(tcx, method.container().id())
234232
}
@@ -271,9 +269,9 @@ enum PassArgs {
271269
ByRef,
272270
}
273271

274-
impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> {
272+
impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
275273
pub fn new(delegate: &'a mut (Delegate<'tcx>+'a),
276-
infcx: &'a InferCtxt<'a, 'tcx, 'tcx>) -> Self
274+
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>) -> Self
277275
{
278276
ExprUseVisitor {
279277
mc: mc::MemCategorizationContext::new(infcx),
@@ -305,7 +303,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> {
305303
}
306304
}
307305

308-
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
306+
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
309307
self.mc.infcx.tcx
310308
}
311309

@@ -1184,10 +1182,10 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> {
11841182
}
11851183
}
11861184

1187-
fn copy_or_move<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx, 'tcx>,
1188-
cmt: &mc::cmt<'tcx>,
1189-
move_reason: MoveReason)
1190-
-> ConsumeMode
1185+
fn copy_or_move<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
1186+
cmt: &mc::cmt<'tcx>,
1187+
move_reason: MoveReason)
1188+
-> ConsumeMode
11911189
{
11921190
if infcx.type_moves_by_default(cmt.ty, cmt.span) {
11931191
Move(move_reason)

src/librustc/middle/free_region.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ impl FreeRegionMap {
120120

121121
/// Determines whether one region is a subregion of another. This is intended to run *after
122122
/// inference* and sadly the logic is somewhat duplicated with the code in infer.rs.
123-
pub fn is_subregion_of<'a, 'tcx>(&self,
124-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
125-
sub_region: ty::Region,
126-
super_region: ty::Region)
127-
-> bool {
123+
pub fn is_subregion_of(&self,
124+
tcx: TyCtxt,
125+
sub_region: ty::Region,
126+
super_region: ty::Region)
127+
-> bool {
128128
let result = sub_region == super_region || {
129129
match (sub_region, super_region) {
130130
(ty::ReEmpty, _) |

src/librustc/middle/mem_categorization.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,7 @@ impl MutabilityCategory {
302302
ret
303303
}
304304

305-
fn from_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
306-
id: ast::NodeId)
307-
-> MutabilityCategory {
305+
fn from_local(tcx: TyCtxt, id: ast::NodeId) -> MutabilityCategory {
308306
let ret = match tcx.map.get(id) {
309307
ast_map::NodeLocal(p) => match p.node {
310308
PatKind::Ident(bind_mode, _, _) => {
@@ -360,13 +358,13 @@ impl MutabilityCategory {
360358
}
361359
}
362360

363-
impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
364-
pub fn new(infcx: &'a InferCtxt<'a, 'tcx, 'tcx>)
365-
-> MemCategorizationContext<'a, 'tcx, 'tcx> {
361+
impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
362+
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>)
363+
-> MemCategorizationContext<'a, 'gcx, 'tcx> {
366364
MemCategorizationContext { infcx: infcx }
367365
}
368366

369-
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
367+
fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
370368
self.infcx.tcx
371369
}
372370

@@ -1074,9 +1072,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
10741072
slice_pat: &hir::Pat)
10751073
-> McResult<(cmt<'tcx>, hir::Mutability, ty::Region)> {
10761074
let slice_ty = self.node_ty(slice_pat.id)?;
1077-
let (slice_mutbl, slice_r) = vec_slice_info(self.tcx(),
1078-
slice_pat,
1079-
slice_ty);
1075+
let (slice_mutbl, slice_r) = vec_slice_info(slice_pat, slice_ty);
10801076
let context = InteriorOffsetKind::Pattern;
10811077
let cmt_vec = self.deref_vec(slice_pat, vec_cmt, context)?;
10821078
let cmt_slice = self.cat_index(slice_pat, cmt_vec, context)?;
@@ -1085,14 +1081,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
10851081
/// In a pattern like [a, b, ..c], normally `c` has slice type, but if you have [a, b,
10861082
/// ..ref c], then the type of `ref c` will be `&&[]`, so to extract the slice details we
10871083
/// have to recurse through rptrs.
1088-
fn vec_slice_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1089-
pat: &hir::Pat,
1090-
slice_ty: Ty)
1091-
-> (hir::Mutability, ty::Region) {
1084+
fn vec_slice_info(pat: &hir::Pat, slice_ty: Ty)
1085+
-> (hir::Mutability, ty::Region) {
10921086
match slice_ty.sty {
10931087
ty::TyRef(r, ref mt) => match mt.ty.sty {
10941088
ty::TySlice(_) => (mt.mutbl, *r),
1095-
_ => vec_slice_info(tcx, pat, mt.ty),
1089+
_ => vec_slice_info(pat, mt.ty),
10961090
},
10971091

10981092
_ => {
@@ -1140,15 +1134,15 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
11401134
}
11411135

11421136
pub fn cat_pattern<F>(&self, cmt: cmt<'tcx>, pat: &hir::Pat, mut op: F) -> McResult<()>
1143-
where F: FnMut(&MemCategorizationContext<'a, 'tcx, 'tcx>, cmt<'tcx>, &hir::Pat),
1137+
where F: FnMut(&MemCategorizationContext<'a, 'gcx, 'tcx>, cmt<'tcx>, &hir::Pat),
11441138
{
11451139
self.cat_pattern_(cmt, pat, &mut op)
11461140
}
11471141

11481142
// FIXME(#19596) This is a workaround, but there should be a better way to do this
11491143
fn cat_pattern_<F>(&self, cmt: cmt<'tcx>, pat: &hir::Pat, op: &mut F)
11501144
-> McResult<()>
1151-
where F : FnMut(&MemCategorizationContext<'a, 'tcx, 'tcx>, cmt<'tcx>, &hir::Pat),
1145+
where F : FnMut(&MemCategorizationContext<'a, 'gcx, 'tcx>, cmt<'tcx>, &hir::Pat),
11521146
{
11531147
// Here, `cmt` is the categorization for the value being
11541148
// matched and pat is the pattern it is being matched against.
@@ -1466,7 +1460,7 @@ impl<'tcx> cmt_<'tcx> {
14661460
}
14671461

14681462

1469-
pub fn descriptive_string<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String {
1463+
pub fn descriptive_string(&self, tcx: TyCtxt) -> String {
14701464
match self.cat {
14711465
Categorization::StaticItem => {
14721466
"static item".to_string()

0 commit comments

Comments
 (0)