Skip to content

Commit 8f72d81

Browse files
committed
rustc: Generalize a minimum set of functions over 'tcx != 'gcx.
1 parent f0b2b3c commit 8f72d81

Some content is hidden

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

43 files changed

+1144
-1018
lines changed

src/librustc/infer/bivariate.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@ pub struct Bivariate<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
3636
fields: CombineFields<'a, 'gcx, 'tcx>
3737
}
3838

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

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

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

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

52-
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
53-
variance: ty::Variance,
54-
a: &T,
55-
b: &T)
56-
-> RelateResult<'tcx, T>
52+
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
53+
variance: ty::Variance,
54+
a: &T,
55+
b: &T)
56+
-> RelateResult<'tcx, T>
5757
{
5858
match variance {
5959
// If we have Foo<A> and Foo is invariant w/r/t A,
@@ -107,7 +107,7 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Bivariate<'a, 'tcx, 'tcx> {
107107

108108
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
109109
-> RelateResult<'tcx, ty::Binder<T>>
110-
where T: Relate<'a,'tcx>
110+
where T: Relate<'tcx>
111111
{
112112
let a1 = self.tcx().erase_late_bound_regions(a);
113113
let b1 = self.tcx().erase_late_bound_regions(b);

src/librustc/infer/combine.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ pub struct CombineFields<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
6060
pub obligations: PredicateObligations<'tcx>,
6161
}
6262

63-
impl<'a, 'tcx> InferCtxt<'a, 'tcx, 'tcx> {
63+
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
6464
pub fn super_combine_tys<R>(&self,
6565
relation: &mut R,
6666
a: Ty<'tcx>,
6767
b: Ty<'tcx>)
6868
-> RelateResult<'tcx, Ty<'tcx>>
69-
where R: TypeRelation<'a,'tcx>
69+
where R: TypeRelation<'a, 'gcx, 'tcx>
7070
{
7171
let a_is_expected = relation.a_is_expected();
7272

@@ -150,35 +150,35 @@ fn unify_float_variable(&self,
150150
}
151151
}
152152

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

158-
pub fn switch_expected(&self) -> CombineFields<'a, 'tcx, 'tcx> {
158+
pub fn switch_expected(&self) -> CombineFields<'a, 'gcx, '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, 'tcx> {
165+
pub fn equate(&self) -> Equate<'a, 'gcx, 'tcx> {
166166
Equate::new(self.clone())
167167
}
168168

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

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

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

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

@@ -299,8 +299,8 @@ struct Generalizer<'cx, 'gcx: 'cx+'tcx, 'tcx: 'cx> {
299299
cycle_detected: bool,
300300
}
301301

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

src/librustc/infer/equate.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use super::combine::CombineFields;
12-
use super::higher_ranked::HigherRankedRelations;
1312
use super::{Subtype};
1413
use super::type_variable::{EqTo};
1514

@@ -23,8 +22,8 @@ pub struct Equate<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
2322
fields: CombineFields<'a, 'gcx, 'tcx>
2423
}
2524

26-
impl<'a, 'tcx> Equate<'a, 'tcx, 'tcx> {
27-
pub fn new(fields: CombineFields<'a, 'tcx, 'tcx>) -> Equate<'a, 'tcx, 'tcx> {
25+
impl<'a, 'gcx, 'tcx> Equate<'a, 'gcx, 'tcx> {
26+
pub fn new(fields: CombineFields<'a, 'gcx, 'tcx>) -> Equate<'a, 'gcx, 'tcx> {
2827
Equate { fields: fields }
2928
}
3029

@@ -33,18 +32,18 @@ impl<'a, 'tcx> Equate<'a, 'tcx, 'tcx> {
3332
}
3433
}
3534

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

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

4140
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
4241

43-
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
44-
_: ty::Variance,
45-
a: &T,
46-
b: &T)
47-
-> RelateResult<'tcx, T>
42+
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
43+
_: ty::Variance,
44+
a: &T,
45+
b: &T)
46+
-> RelateResult<'tcx, T>
4847
{
4948
self.relate(a, b)
5049
}
@@ -92,7 +91,7 @@ impl<'a, 'tcx> TypeRelation<'a,'tcx> for Equate<'a, 'tcx, 'tcx> {
9291

9392
fn binders<T>(&mut self, a: &ty::Binder<T>, b: &ty::Binder<T>)
9493
-> RelateResult<'tcx, ty::Binder<T>>
95-
where T: Relate<'a, 'tcx>
94+
where T: Relate<'tcx>
9695
{
9796
self.fields.higher_ranked_sub(a, b)?;
9897
self.fields.higher_ranked_sub(b, a)

src/librustc/infer/error_reporting.rs

Lines changed: 31 additions & 105 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, 'tcx> {
98+
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
9999
pub fn note_and_explain_region(self,
100100
err: &mut DiagnosticBuilder,
101101
prefix: &str,
@@ -112,9 +112,9 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
112112
}
113113
}
114114

115-
fn explain_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
116-
heading: &str, span: Span)
117-
-> (String, Option<Span>) {
115+
fn explain_span<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
116+
heading: &str, span: Span)
117+
-> (String, Option<Span>) {
118118
let lo = tcx.sess.codemap().lookup_char_pos_adj(span.lo);
119119
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize()),
120120
Some(span))
@@ -228,83 +228,9 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
228228
}
229229
}
230230

231-
pub trait ErrorReporting<'tcx> {
232-
fn report_region_errors(&self,
233-
errors: &Vec<RegionResolutionError<'tcx>>);
234-
235-
fn process_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>)
236-
-> Option<Vec<RegionResolutionError<'tcx>>>;
237-
238-
fn report_type_error(&self,
239-
trace: TypeTrace<'tcx>,
240-
terr: &TypeError<'tcx>)
241-
-> DiagnosticBuilder<'tcx>;
242-
243-
fn check_and_note_conflicting_crates(&self,
244-
err: &mut DiagnosticBuilder,
245-
terr: &TypeError<'tcx>,
246-
sp: Span);
247-
248-
fn report_and_explain_type_error(&self,
249-
trace: TypeTrace<'tcx>,
250-
terr: &TypeError<'tcx>)
251-
-> DiagnosticBuilder<'tcx>;
252-
253-
fn values_str(&self, values: &ValuePairs<'tcx>) -> Option<(String, String)>;
254-
255-
fn expected_found_str<T: fmt::Display + Resolvable<'tcx> + TypeFoldable<'tcx>>(
256-
&self,
257-
exp_found: &ty::error::ExpectedFound<T>)
258-
-> Option<(String, String)>;
259-
260-
fn report_concrete_failure(&self,
261-
origin: SubregionOrigin<'tcx>,
262-
sub: Region,
263-
sup: Region)
264-
-> DiagnosticBuilder<'tcx>;
265-
266-
fn report_generic_bound_failure(&self,
267-
origin: SubregionOrigin<'tcx>,
268-
kind: GenericKind<'tcx>,
269-
sub: Region);
270-
271-
fn report_sub_sup_conflict(&self,
272-
var_origin: RegionVariableOrigin,
273-
sub_origin: SubregionOrigin<'tcx>,
274-
sub_region: Region,
275-
sup_origin: SubregionOrigin<'tcx>,
276-
sup_region: Region);
277-
278-
fn report_processed_errors(&self,
279-
origins: &[ProcessedErrorOrigin<'tcx>],
280-
same_regions: &[SameRegions]);
281-
282-
fn give_suggestion(&self, err: &mut DiagnosticBuilder, same_regions: &[SameRegions]);
283-
}
284-
285-
trait ErrorReportingHelpers<'tcx> {
286-
fn report_inference_failure(&self,
287-
var_origin: RegionVariableOrigin)
288-
-> DiagnosticBuilder<'tcx>;
289-
290-
fn note_region_origin(&self,
291-
err: &mut DiagnosticBuilder,
292-
origin: &SubregionOrigin<'tcx>);
293-
294-
fn give_expl_lifetime_param(&self,
295-
err: &mut DiagnosticBuilder,
296-
decl: &hir::FnDecl,
297-
unsafety: hir::Unsafety,
298-
constness: hir::Constness,
299-
name: ast::Name,
300-
opt_explicit_self: Option<&hir::ExplicitSelf_>,
301-
generics: &hir::Generics,
302-
span: Span);
303-
}
304-
305-
impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
306-
fn report_region_errors(&self,
307-
errors: &Vec<RegionResolutionError<'tcx>>) {
231+
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
232+
pub fn report_region_errors(&self,
233+
errors: &Vec<RegionResolutionError<'tcx>>) {
308234
debug!("report_region_errors(): {} errors to start", errors.len());
309235

310236
// try to pre-process the errors, which will group some of them
@@ -475,10 +401,10 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
475401
}
476402
}
477403

478-
fn free_regions_from_same_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
479-
sub: Region,
480-
sup: Region)
481-
-> Option<FreeRegionsFromSameFn> {
404+
fn free_regions_from_same_fn<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
405+
sub: Region,
406+
sup: Region)
407+
-> Option<FreeRegionsFromSameFn> {
482408
debug!("free_regions_from_same_fn(sub={:?}, sup={:?})", sub, sup);
483409
let (scope_id, fr1, fr2) = match (sub, sup) {
484410
(ReFree(fr1), ReFree(fr2)) => {
@@ -620,10 +546,10 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
620546
}
621547
}
622548

623-
fn report_and_explain_type_error(&self,
624-
trace: TypeTrace<'tcx>,
625-
terr: &TypeError<'tcx>)
626-
-> DiagnosticBuilder<'tcx> {
549+
pub fn report_and_explain_type_error(&self,
550+
trace: TypeTrace<'tcx>,
551+
terr: &TypeError<'tcx>)
552+
-> DiagnosticBuilder<'tcx> {
627553
let span = trace.origin.span();
628554
let mut err = self.report_type_error(trace, terr);
629555
self.tcx.note_and_explain_type_err(&mut err, terr, span);
@@ -1109,8 +1035,8 @@ struct RebuildPathInfo<'a> {
11091035
region_names: &'a HashSet<ast::Name>
11101036
}
11111037

1112-
struct Rebuilder<'a, 'tcx: 'a> {
1113-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
1038+
struct Rebuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
1039+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
11141040
fn_decl: &'a hir::FnDecl,
11151041
expl_self_opt: Option<&'a hir::ExplicitSelf_>,
11161042
generics: &'a hir::Generics,
@@ -1125,14 +1051,14 @@ enum FreshOrKept {
11251051
Kept
11261052
}
11271053

1128-
impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
1129-
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1054+
impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> {
1055+
fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
11301056
fn_decl: &'a hir::FnDecl,
11311057
expl_self_opt: Option<&'a hir::ExplicitSelf_>,
11321058
generics: &'a hir::Generics,
11331059
same_regions: &'a [SameRegions],
11341060
life_giver: &'a LifeGiver)
1135-
-> Rebuilder<'a, 'tcx> {
1061+
-> Rebuilder<'a, 'gcx, 'tcx> {
11361062
Rebuilder {
11371063
tcx: tcx,
11381064
fn_decl: fn_decl,
@@ -1642,7 +1568,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
16421568
}
16431569
}
16441570

1645-
impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
1571+
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
16461572
fn give_expl_lifetime_param(&self,
16471573
err: &mut DiagnosticBuilder,
16481574
decl: &hir::FnDecl,
@@ -1905,34 +1831,34 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx, 'tcx> {
19051831
}
19061832

19071833
pub trait Resolvable<'tcx> {
1908-
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx, 'tcx>) -> Self;
1834+
fn resolve<'a, 'gcx>(&self, infcx: &InferCtxt<'a, 'gcx, 'tcx>) -> Self;
19091835
}
19101836

19111837
impl<'tcx> Resolvable<'tcx> for Ty<'tcx> {
1912-
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
1838+
fn resolve<'a, 'gcx>(&self, infcx: &InferCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
19131839
infcx.resolve_type_vars_if_possible(self)
19141840
}
19151841
}
19161842

19171843
impl<'tcx> Resolvable<'tcx> for ty::TraitRef<'tcx> {
1918-
fn resolve<'a>(&self, infcx: &InferCtxt<'a, 'tcx, 'tcx>)
1919-
-> ty::TraitRef<'tcx> {
1844+
fn resolve<'a, 'gcx>(&self, infcx: &InferCtxt<'a, 'gcx, 'tcx>)
1845+
-> ty::TraitRef<'tcx> {
19201846
infcx.resolve_type_vars_if_possible(self)
19211847
}
19221848
}
19231849

19241850
impl<'tcx> Resolvable<'tcx> for ty::PolyTraitRef<'tcx> {
1925-
fn resolve<'a>(&self,
1926-
infcx: &InferCtxt<'a, 'tcx, 'tcx>)
1927-
-> ty::PolyTraitRef<'tcx>
1851+
fn resolve<'a, 'gcx>(&self,
1852+
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
1853+
-> ty::PolyTraitRef<'tcx>
19281854
{
19291855
infcx.resolve_type_vars_if_possible(self)
19301856
}
19311857
}
19321858

1933-
fn lifetimes_in_scope<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1934-
scope_id: ast::NodeId)
1935-
-> Vec<hir::LifetimeDef> {
1859+
fn lifetimes_in_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
1860+
scope_id: ast::NodeId)
1861+
-> Vec<hir::LifetimeDef> {
19361862
let mut taken = Vec::new();
19371863
let parent = tcx.map.get_parent(scope_id);
19381864
let method_id_opt = match tcx.map.find(parent) {

0 commit comments

Comments
 (0)