Skip to content

Commit 3923108

Browse files
committed
Check associated types and consts for well-formedness
Because we don't check the well-formedness of region relationships of an impl's on the Self-type, or infer region relationss from them, many impls now have to specify their region relations, making this a [breaking-change]. The most common pattern I found that is now broken is that impl<'a, T> IntoIterator for &'a Collection<T> { type Item = &'a T; type IntoIter = ...; } now has to specify its `T: 'a` bound.
1 parent 892666a commit 3923108

File tree

20 files changed

+165
-121
lines changed

20 files changed

+165
-121
lines changed

src/libcollections/binary_heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ impl<T: Ord> IntoIterator for BinaryHeap<T> {
675675
}
676676

677677
#[stable(feature = "rust1", since = "1.0.0")]
678-
impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {
678+
impl<'a, T: 'a> IntoIterator for &'a BinaryHeap<T> where T: Ord {
679679
type Item = &'a T;
680680
type IntoIter = Iter<'a, T>;
681681

src/libcollections/btree/map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ impl<K, V> IntoIterator for BTreeMap<K, V> {
500500
}
501501

502502
#[stable(feature = "rust1", since = "1.0.0")]
503-
impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> {
503+
impl<'a, K: 'a, V: 'a> IntoIterator for &'a BTreeMap<K, V> {
504504
type Item = (&'a K, &'a V);
505505
type IntoIter = Iter<'a, K, V>;
506506

@@ -510,7 +510,7 @@ impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> {
510510
}
511511

512512
#[stable(feature = "rust1", since = "1.0.0")]
513-
impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> {
513+
impl<'a, K: 'a, V: 'a> IntoIterator for &'a mut BTreeMap<K, V> {
514514
type Item = (&'a K, &'a mut V);
515515
type IntoIter = IterMut<'a, K, V>;
516516

src/libcollections/btree/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ impl<T> IntoIterator for BTreeSet<T> {
490490
}
491491

492492
#[stable(feature = "rust1", since = "1.0.0")]
493-
impl<'a, T> IntoIterator for &'a BTreeSet<T> {
493+
impl<'a, T: 'a> IntoIterator for &'a BTreeSet<T> {
494494
type Item = &'a T;
495495
type IntoIter = Iter<'a, T>;
496496

src/libcollections/enum_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl<E:CLike> FromIterator<E> for EnumSet<E> {
272272
}
273273

274274
#[stable(feature = "rust1", since = "1.0.0")]
275-
impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike {
275+
impl<'a, E: 'a> IntoIterator for &'a EnumSet<E> where E: CLike {
276276
type Item = E;
277277
type IntoIter = Iter<E>;
278278

src/libcollections/linked_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ impl<T> IntoIterator for LinkedList<T> {
846846
}
847847

848848
#[stable(feature = "rust1", since = "1.0.0")]
849-
impl<'a, T> IntoIterator for &'a LinkedList<T> {
849+
impl<'a, T: 'a> IntoIterator for &'a LinkedList<T> {
850850
type Item = &'a T;
851851
type IntoIter = Iter<'a, T>;
852852

@@ -855,7 +855,7 @@ impl<'a, T> IntoIterator for &'a LinkedList<T> {
855855
}
856856
}
857857

858-
impl<'a, T> IntoIterator for &'a mut LinkedList<T> {
858+
impl<'a, T: 'a> IntoIterator for &'a mut LinkedList<T> {
859859
type Item = &'a mut T;
860860
type IntoIter = IterMut<'a, T>;
861861

src/libcollections/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ impl<T> IntoIterator for Vec<T> {
15621562
}
15631563

15641564
#[stable(feature = "rust1", since = "1.0.0")]
1565-
impl<'a, T> IntoIterator for &'a Vec<T> {
1565+
impl<'a, T: 'a> IntoIterator for &'a Vec<T> {
15661566
type Item = &'a T;
15671567
type IntoIter = slice::Iter<'a, T>;
15681568

@@ -1572,7 +1572,7 @@ impl<'a, T> IntoIterator for &'a Vec<T> {
15721572
}
15731573

15741574
#[stable(feature = "rust1", since = "1.0.0")]
1575-
impl<'a, T> IntoIterator for &'a mut Vec<T> {
1575+
impl<'a, T: 'a> IntoIterator for &'a mut Vec<T> {
15761576
type Item = &'a mut T;
15771577
type IntoIter = slice::IterMut<'a, T>;
15781578

src/libcollections/vec_deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ impl<T> IntoIterator for VecDeque<T> {
17571757
}
17581758

17591759
#[stable(feature = "rust1", since = "1.0.0")]
1760-
impl<'a, T> IntoIterator for &'a VecDeque<T> {
1760+
impl<'a, T: 'a> IntoIterator for &'a VecDeque<T> {
17611761
type Item = &'a T;
17621762
type IntoIter = Iter<'a, T>;
17631763

@@ -1767,7 +1767,7 @@ impl<'a, T> IntoIterator for &'a VecDeque<T> {
17671767
}
17681768

17691769
#[stable(feature = "rust1", since = "1.0.0")]
1770-
impl<'a, T> IntoIterator for &'a mut VecDeque<T> {
1770+
impl<'a, T: 'a> IntoIterator for &'a mut VecDeque<T> {
17711771
type Item = &'a mut T;
17721772
type IntoIter = IterMut<'a, T>;
17731773

src/libcollections/vec_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ impl<T> IntoIterator for VecMap<T> {
800800
}
801801

802802
#[stable(feature = "rust1", since = "1.0.0")]
803-
impl<'a, T> IntoIterator for &'a VecMap<T> {
803+
impl<'a, T: 'a> IntoIterator for &'a VecMap<T> {
804804
type Item = (usize, &'a T);
805805
type IntoIter = Iter<'a, T>;
806806

@@ -810,7 +810,7 @@ impl<'a, T> IntoIterator for &'a VecMap<T> {
810810
}
811811

812812
#[stable(feature = "rust1", since = "1.0.0")]
813-
impl<'a, T> IntoIterator for &'a mut VecMap<T> {
813+
impl<'a, T: 'a> IntoIterator for &'a mut VecMap<T> {
814814
type Item = (usize, &'a mut T);
815815
type IntoIter = IterMut<'a, T>;
816816

src/libcore/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ macro_rules! array_impls {
9494
}
9595

9696
#[stable(feature = "rust1", since = "1.0.0")]
97-
impl<'a, T> IntoIterator for &'a [T; $N] {
97+
impl<'a, T: 'a> IntoIterator for &'a [T; $N] {
9898
type Item = &'a T;
9999
type IntoIter = Iter<'a, T>;
100100

@@ -104,7 +104,7 @@ macro_rules! array_impls {
104104
}
105105

106106
#[stable(feature = "rust1", since = "1.0.0")]
107-
impl<'a, T> IntoIterator for &'a mut [T; $N] {
107+
impl<'a, T: 'a> IntoIterator for &'a mut [T; $N] {
108108
type Item = &'a mut T;
109109
type IntoIter = IterMut<'a, T>;
110110

src/libcore/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl<'a, T> Default for &'a [T] {
647647
//
648648

649649
#[stable(feature = "rust1", since = "1.0.0")]
650-
impl<'a, T> IntoIterator for &'a [T] {
650+
impl<'a, T: 'a> IntoIterator for &'a [T] {
651651
type Item = &'a T;
652652
type IntoIter = Iter<'a, T>;
653653

@@ -657,7 +657,7 @@ impl<'a, T> IntoIterator for &'a [T] {
657657
}
658658

659659
#[stable(feature = "rust1", since = "1.0.0")]
660-
impl<'a, T> IntoIterator for &'a mut [T] {
660+
impl<'a, T: 'a> IntoIterator for &'a mut [T] {
661661
type Item = &'a mut T;
662662
type IntoIter = IterMut<'a, T>;
663663

src/librustc/middle/subst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ impl<T> IntoIterator for VecPerParamSpace<T> {
538538
}
539539
}
540540

541-
impl<'a,T> IntoIterator for &'a VecPerParamSpace<T> {
541+
impl<'a, T: 'a> IntoIterator for &'a VecPerParamSpace<T> {
542542
type Item = &'a T;
543543
type IntoIter = Iter<'a, T>;
544544

src/librustc/middle/traits/select.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,10 +2982,10 @@ impl<'o,'tcx> TraitObligationStackList<'o,'tcx> {
29822982
}
29832983
}
29842984

2985-
impl<'o,'tcx> Iterator for TraitObligationStackList<'o,'tcx>{
2986-
type Item = &'o TraitObligationStack<'o,'tcx>;
2985+
impl<'o, 'tcx: 'o> Iterator for TraitObligationStackList<'o, 'tcx> {
2986+
type Item = &'o TraitObligationStack<'o, 'tcx>;
29872987

2988-
fn next(&mut self) -> Option<&'o TraitObligationStack<'o,'tcx>> {
2988+
fn next(&mut self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
29892989
match self.head {
29902990
Some(o) => {
29912991
*self = o.previous;
@@ -2996,7 +2996,7 @@ impl<'o,'tcx> Iterator for TraitObligationStackList<'o,'tcx>{
29962996
}
29972997
}
29982998

2999-
impl<'o,'tcx> Repr<'tcx> for TraitObligationStack<'o,'tcx> {
2999+
impl<'o, 'tcx> Repr<'tcx> for TraitObligationStack<'o, 'tcx> {
30003000
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
30013001
format!("TraitObligationStack({})",
30023002
self.obligation.repr(tcx))

src/librustc/middle/ty.rs

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,38 +2328,35 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
23282328
}
23292329
}
23302330

2331-
pub fn for_item(cx: &'a ctxt<'tcx>, id: NodeId) -> ParameterEnvironment<'a, 'tcx> {
2331+
pub fn for_item(cx: &'a ctxt<'tcx>, id: NodeId)
2332+
-> ParameterEnvironment<'a, 'tcx>
2333+
{
2334+
// TODO: use Self after a snapshot (or remove this comment)
2335+
ParameterEnvironment::for_item_inner(cx, id, construct_parameter_environment)
2336+
}
2337+
2338+
pub fn for_item_inner<T, F>(cx: &'a ctxt<'tcx>, id: NodeId, f: F) -> T
2339+
where F: FnOnce(&'a ctxt<'tcx>, Span, &Generics<'tcx>,
2340+
&GenericPredicates<'tcx>, NodeId) -> T {
23322341
match cx.map.find(id) {
23332342
Some(ast_map::NodeImplItem(ref impl_item)) => {
23342343
match impl_item.node {
23352344
ast::ConstImplItem(_, _) => {
23362345
let def_id = ast_util::local_def(id);
23372346
let scheme = lookup_item_type(cx, def_id);
23382347
let predicates = lookup_predicates(cx, def_id);
2339-
construct_parameter_environment(cx,
2340-
impl_item.span,
2341-
&scheme.generics,
2342-
&predicates,
2343-
id)
2348+
f(cx, impl_item.span, &scheme.generics, &predicates, id)
23442349
}
23452350
ast::MethodImplItem(_, ref body) => {
23462351
let method_def_id = ast_util::local_def(id);
23472352
match ty::impl_or_trait_item(cx, method_def_id) {
2348-
MethodTraitItem(ref method_ty) => {
2349-
let method_generics = &method_ty.generics;
2350-
let method_bounds = &method_ty.predicates;
2351-
construct_parameter_environment(
2352-
cx,
2353-
impl_item.span,
2354-
method_generics,
2355-
method_bounds,
2356-
body.id)
2357-
}
2358-
_ => {
2359-
cx.sess
2360-
.bug("ParameterEnvironment::for_item(): \
2361-
got non-method item from impl method?!")
2362-
}
2353+
MethodTraitItem(ref method_ty) => f(cx,
2354+
impl_item.span,
2355+
&method_ty.generics,
2356+
&method_ty.predicates,
2357+
body.id),
2358+
_ => cx.sess.bug("ParameterEnvironment::for_item(): \
2359+
got non-method item from impl method?!")
23632360
}
23642361
}
23652362
ast::TypeImplItem(_) => {
@@ -2378,11 +2375,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
23782375
let def_id = ast_util::local_def(id);
23792376
let scheme = lookup_item_type(cx, def_id);
23802377
let predicates = lookup_predicates(cx, def_id);
2381-
construct_parameter_environment(cx,
2382-
trait_item.span,
2383-
&scheme.generics,
2384-
&predicates,
2385-
id)
2378+
f(cx, trait_item.span, &scheme.generics, &predicates, id)
23862379
}
23872380
None => {
23882381
cx.sess.bug("ParameterEnvironment::from_item(): \
@@ -2401,22 +2394,14 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
24012394
ast::MethodTraitItem(_, Some(ref body)) => {
24022395
let method_def_id = ast_util::local_def(id);
24032396
match ty::impl_or_trait_item(cx, method_def_id) {
2404-
MethodTraitItem(ref method_ty) => {
2405-
let method_generics = &method_ty.generics;
2406-
let method_bounds = &method_ty.predicates;
2407-
construct_parameter_environment(
2408-
cx,
2409-
trait_item.span,
2410-
method_generics,
2411-
method_bounds,
2412-
body.id)
2413-
}
2414-
_ => {
2415-
cx.sess
2416-
.bug("ParameterEnvironment::for_item(): \
2417-
got non-method item from provided \
2418-
method?!")
2419-
}
2397+
MethodTraitItem(ref method_ty) => f(cx,
2398+
trait_item.span,
2399+
&method_ty.generics,
2400+
&method_ty.predicates,
2401+
body.id),
2402+
_ => cx.sess.bug("ParameterEnvironment::for_item(): \
2403+
got non-method item from provided \
2404+
method?!")
24202405
}
24212406
}
24222407
ast::TypeTraitItem(..) => {
@@ -2434,11 +2419,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
24342419
let fn_scheme = lookup_item_type(cx, fn_def_id);
24352420
let fn_predicates = lookup_predicates(cx, fn_def_id);
24362421

2437-
construct_parameter_environment(cx,
2438-
item.span,
2439-
&fn_scheme.generics,
2440-
&fn_predicates,
2441-
body.id)
2422+
f(cx, item.span, &fn_scheme.generics, &fn_predicates, body.id)
24422423
}
24432424
ast::ItemEnum(..) |
24442425
ast::ItemStruct(..) |
@@ -2448,11 +2429,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
24482429
let def_id = ast_util::local_def(id);
24492430
let scheme = lookup_item_type(cx, def_id);
24502431
let predicates = lookup_predicates(cx, def_id);
2451-
construct_parameter_environment(cx,
2452-
item.span,
2453-
&scheme.generics,
2454-
&predicates,
2455-
id)
2432+
f(cx, item.span, &scheme.generics, &predicates, id)
24562433
}
24572434
_ => {
24582435
cx.sess.span_bug(item.span,
@@ -2464,7 +2441,14 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
24642441
}
24652442
Some(ast_map::NodeExpr(..)) => {
24662443
// This is a convenience to allow closures to work.
2467-
ParameterEnvironment::for_item(cx, cx.map.get_parent(id))
2444+
ParameterEnvironment::for_item_inner(cx, cx.map.get_parent(id), f)
2445+
}
2446+
Some(ast_map::NodeForeignItem(ref item)) => {
2447+
let def_id = ast_util::local_def(id);
2448+
let scheme = lookup_item_type(cx, def_id);
2449+
let predicates = lookup_predicates(cx, def_id);
2450+
2451+
f(cx, item.span, &scheme.generics, &predicates, id)
24682452
}
24692453
_ => {
24702454
cx.sess.bug(&format!("ParameterEnvironment::from_item(): \

src/librustc_trans/trans/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub struct CrateContextIterator<'a, 'tcx: 'a> {
171171
index: usize,
172172
}
173173

174-
impl<'a, 'tcx> Iterator for CrateContextIterator<'a,'tcx> {
174+
impl<'a, 'tcx: 'a> Iterator for CrateContextIterator<'a, 'tcx> {
175175
type Item = CrateContext<'a, 'tcx>;
176176

177177
fn next(&mut self) -> Option<CrateContext<'a, 'tcx>> {
@@ -198,7 +198,7 @@ pub struct CrateContextMaybeIterator<'a, 'tcx: 'a> {
198198
origin: usize,
199199
}
200200

201-
impl<'a, 'tcx> Iterator for CrateContextMaybeIterator<'a, 'tcx> {
201+
impl<'a, 'tcx: 'a> Iterator for CrateContextMaybeIterator<'a, 'tcx> {
202202
type Item = (CrateContext<'a, 'tcx>, bool);
203203

204204
fn next(&mut self) -> Option<(CrateContext<'a, 'tcx>, bool)> {

0 commit comments

Comments
 (0)