Skip to content

Commit b354ae9

Browse files
committed
rustc: move the SelfSpace before TypeSpace in Substs.
1 parent e314636 commit b354ae9

15 files changed

+82
-82
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
182182
let rps = self.region_vars_for_defs(obligation.cause.span, rps);
183183
let mut substs = subst::Substs::new(
184184
subst::VecPerParamSpace::empty(),
185-
subst::VecPerParamSpace::new(rps, Vec::new(), Vec::new()));
185+
subst::VecPerParamSpace::new(Vec::new(), rps, Vec::new()));
186186
self.type_vars_for_defs(obligation.cause.span,
187187
TypeSpace,
188188
&mut substs,

src/librustc/traits/select.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
16021602
return;
16031603
}
16041604
};
1605-
let target = obligation.predicate.0.input_types()[0];
1605+
let target = obligation.predicate.skip_binder().input_types()[1];
16061606

16071607
debug!("assemble_candidates_for_unsizing(source={:?}, target={:?})",
16081608
source, target);
@@ -2476,7 +2476,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
24762476
// regions here. See the comment there for more details.
24772477
let source = self.infcx.shallow_resolve(
24782478
tcx.no_late_bound_regions(&obligation.self_ty()).unwrap());
2479-
let target = self.infcx.shallow_resolve(obligation.predicate.0.input_types()[0]);
2479+
let target = obligation.predicate.skip_binder().input_types()[1];
2480+
let target = self.infcx.shallow_resolve(target);
24802481

24812482
debug!("confirm_builtin_unsize_candidate(source={:?}, target={:?})",
24822483
source, target);

src/librustc/ty/subst.rs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
4848
r: Vec<ty::Region>)
4949
-> Substs<'tcx>
5050
{
51-
Substs::new(VecPerParamSpace::new(t, Vec::new(), Vec::new()),
52-
VecPerParamSpace::new(r, Vec::new(), Vec::new()))
51+
Substs::new(VecPerParamSpace::new(vec![], t, vec![]),
52+
VecPerParamSpace::new(vec![], r, vec![]))
5353
}
5454

5555
pub fn new_trait(t: Vec<Ty<'tcx>>,
5656
r: Vec<ty::Region>,
5757
s: Ty<'tcx>)
5858
-> Substs<'tcx>
5959
{
60-
Substs::new(VecPerParamSpace::new(t, vec!(s), Vec::new()),
61-
VecPerParamSpace::new(r, Vec::new(), Vec::new()))
60+
Substs::new(VecPerParamSpace::new(vec![s], t, vec![]),
61+
VecPerParamSpace::new(vec![], r, vec![]))
6262
}
6363

6464
pub fn empty() -> Substs<'tcx> {
@@ -169,28 +169,28 @@ impl<'tcx> Decodable for &'tcx Substs<'tcx> {
169169
#[derive(PartialOrd, Ord, PartialEq, Eq, Copy,
170170
Clone, Hash, RustcEncodable, RustcDecodable, Debug)]
171171
pub enum ParamSpace {
172-
TypeSpace, // Type parameters attached to a type definition, trait, or impl
173172
SelfSpace, // Self parameter on a trait
173+
TypeSpace, // Type parameters attached to a type definition, trait, or impl
174174
FnSpace, // Type parameters attached to a method or fn
175175
}
176176

177177
impl ParamSpace {
178178
pub fn all() -> [ParamSpace; 3] {
179-
[TypeSpace, SelfSpace, FnSpace]
179+
[SelfSpace, TypeSpace, FnSpace]
180180
}
181181

182182
pub fn to_uint(self) -> usize {
183183
match self {
184-
TypeSpace => 0,
185-
SelfSpace => 1,
184+
SelfSpace => 0,
185+
TypeSpace => 1,
186186
FnSpace => 2,
187187
}
188188
}
189189

190190
pub fn from_uint(u: usize) -> ParamSpace {
191191
match u {
192-
0 => TypeSpace,
193-
1 => SelfSpace,
192+
0 => SelfSpace,
193+
1 => TypeSpace,
194194
2 => FnSpace,
195195
_ => bug!("Invalid ParamSpace: {}", u)
196196
}
@@ -209,64 +209,64 @@ pub struct VecPerParamSpace<T> {
209209
// Here is how the representation corresponds to the abstraction
210210
// i.e. the "abstraction function" AF:
211211
//
212-
// AF(self) = (self.content[..self.type_limit],
213-
// self.content[self.type_limit..self.self_limit],
214-
// self.content[self.self_limit..])
215-
type_limit: usize,
212+
// AF(self) = (self.content[..self.self_limit],
213+
// self.content[self.self_limit..self.type_limit],
214+
// self.content[self.type_limit..])
216215
self_limit: usize,
216+
type_limit: usize,
217217
content: Vec<T>,
218218
}
219219

220220
impl<T: fmt::Debug> fmt::Debug for VecPerParamSpace<T> {
221221
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
222222
write!(f, "[{:?};{:?};{:?}]",
223-
self.get_slice(TypeSpace),
224223
self.get_slice(SelfSpace),
224+
self.get_slice(TypeSpace),
225225
self.get_slice(FnSpace))
226226
}
227227
}
228228

229229
impl<T> VecPerParamSpace<T> {
230230
fn limits(&self, space: ParamSpace) -> (usize, usize) {
231231
match space {
232-
TypeSpace => (0, self.type_limit),
233-
SelfSpace => (self.type_limit, self.self_limit),
234-
FnSpace => (self.self_limit, self.content.len()),
232+
SelfSpace => (0, self.self_limit),
233+
TypeSpace => (self.self_limit, self.type_limit),
234+
FnSpace => (self.type_limit, self.content.len()),
235235
}
236236
}
237237

238238
pub fn empty() -> VecPerParamSpace<T> {
239239
VecPerParamSpace {
240-
type_limit: 0,
241240
self_limit: 0,
241+
type_limit: 0,
242242
content: Vec::new()
243243
}
244244
}
245245

246-
/// `t` is the type space.
247246
/// `s` is the self space.
247+
/// `t` is the type space.
248248
/// `f` is the fn space.
249-
pub fn new(t: Vec<T>, s: Vec<T>, f: Vec<T>) -> VecPerParamSpace<T> {
250-
let type_limit = t.len();
251-
let self_limit = type_limit + s.len();
249+
pub fn new(s: Vec<T>, t: Vec<T>, f: Vec<T>) -> VecPerParamSpace<T> {
250+
let self_limit = s.len();
251+
let type_limit = self_limit + t.len();
252252

253-
let mut content = t;
254-
content.extend(s);
253+
let mut content = s;
254+
content.extend(t);
255255
content.extend(f);
256256

257257
VecPerParamSpace {
258-
type_limit: type_limit,
259258
self_limit: self_limit,
259+
type_limit: type_limit,
260260
content: content,
261261
}
262262
}
263263

264-
fn new_internal(content: Vec<T>, type_limit: usize, self_limit: usize)
264+
fn new_internal(content: Vec<T>, self_limit: usize, type_limit: usize)
265265
-> VecPerParamSpace<T>
266266
{
267267
VecPerParamSpace {
268-
type_limit: type_limit,
269268
self_limit: self_limit,
269+
type_limit: type_limit,
270270
content: content,
271271
}
272272
}
@@ -278,8 +278,8 @@ impl<T> VecPerParamSpace<T> {
278278
pub fn push(&mut self, space: ParamSpace, value: T) {
279279
let (_, limit) = self.limits(space);
280280
match space {
281-
TypeSpace => { self.type_limit += 1; self.self_limit += 1; }
282-
SelfSpace => { self.self_limit += 1; }
281+
SelfSpace => { self.type_limit += 1; self.self_limit += 1; }
282+
TypeSpace => { self.type_limit += 1; }
283283
FnSpace => { }
284284
}
285285
self.content.insert(limit, value);
@@ -302,8 +302,8 @@ impl<T> VecPerParamSpace<T> {
302302
None
303303
} else {
304304
match space {
305-
TypeSpace => { self.type_limit -= 1; self.self_limit -= 1; }
306-
SelfSpace => { self.self_limit -= 1; }
305+
SelfSpace => { self.type_limit -= 1; self.self_limit -= 1; }
306+
TypeSpace => { self.type_limit -= 1; }
307307
FnSpace => {}
308308
}
309309
if self.content.is_empty() {
@@ -388,8 +388,7 @@ impl<T> VecPerParamSpace<T> {
388388
pub fn all_vecs<P>(&self, mut pred: P) -> bool where
389389
P: FnMut(&[T]) -> bool,
390390
{
391-
let spaces = [TypeSpace, SelfSpace, FnSpace];
392-
spaces.iter().all(|&space| { pred(self.get_slice(space)) })
391+
ParamSpace::all().iter().all(|&space| { pred(self.get_slice(space)) })
393392
}
394393

395394
pub fn all<P>(&self, pred: P) -> bool where P: FnMut(&T) -> bool {
@@ -407,17 +406,17 @@ impl<T> VecPerParamSpace<T> {
407406
pub fn map<U, P>(&self, pred: P) -> VecPerParamSpace<U> where P: FnMut(&T) -> U {
408407
let result = self.iter().map(pred).collect();
409408
VecPerParamSpace::new_internal(result,
410-
self.type_limit,
411-
self.self_limit)
409+
self.self_limit,
410+
self.type_limit)
412411
}
413412

414413
pub fn map_enumerated<U, P>(&self, pred: P) -> VecPerParamSpace<U> where
415414
P: FnMut((ParamSpace, usize, &T)) -> U,
416415
{
417416
let result = self.iter_enumerated().map(pred).collect();
418417
VecPerParamSpace::new_internal(result,
419-
self.type_limit,
420-
self.self_limit)
418+
self.self_limit,
419+
self.type_limit)
421420
}
422421

423422
pub fn with_slice(mut self, space: ParamSpace, slice: &[T])

src/librustc_trans/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,8 @@ pub fn custom_coerce_unsize_info<'scx, 'tcx>(scx: &SharedCrateContext<'scx, 'tcx
675675
source_ty: Ty<'tcx>,
676676
target_ty: Ty<'tcx>)
677677
-> CustomCoerceUnsized {
678-
let trait_substs = Substs::new(subst::VecPerParamSpace::new(vec![target_ty],
679-
vec![source_ty],
678+
let trait_substs = Substs::new(subst::VecPerParamSpace::new(vec![source_ty],
679+
vec![target_ty],
680680
Vec::new()),
681681
subst::VecPerParamSpace::empty());
682682

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2797,7 +2797,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
27972797
let rps = self.region_vars_for_defs(span, rps);
27982798
let mut substs = subst::Substs::new(
27992799
VecPerParamSpace::empty(),
2800-
VecPerParamSpace::new(rps, Vec::new(), Vec::new()));
2800+
VecPerParamSpace::new(Vec::new(), rps, Vec::new()));
28012801
self.type_vars_for_defs(span, ParamSpace::TypeSpace, &mut substs, tps);
28022802
let substd_ty = self.instantiate_type_scheme(span, &substs, &raw_ty);
28032803

src/test/codegen-units/item-collection/trait-method-default-impl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl SomeGenericTrait<u64> for i32 {
3737

3838
// For the non-generic foo(), we should generate a codegen-item even if it
3939
// is not called anywhere
40-
//~ TRANS_ITEM fn trait_method_default_impl::SomeGenericTrait[0]::foo[0]<u64, i32>
40+
//~ TRANS_ITEM fn trait_method_default_impl::SomeGenericTrait[0]::foo[0]<i32, u64>
4141
}
4242

4343
// Non-generic impl of generic trait
@@ -54,16 +54,16 @@ fn main() {
5454
//~ TRANS_ITEM fn trait_method_default_impl::SomeTrait[0]::bar[0]<i8, &str>
5555
let _ = 2i8.bar("&str");
5656

57-
//~ TRANS_ITEM fn trait_method_default_impl::SomeGenericTrait[0]::bar[0]<u64, i32, char>
57+
//~ TRANS_ITEM fn trait_method_default_impl::SomeGenericTrait[0]::bar[0]<i32, u64, char>
5858
0i32.bar(0u64, 'c');
5959

60-
//~ TRANS_ITEM fn trait_method_default_impl::SomeGenericTrait[0]::bar[0]<u64, i32, &str>
60+
//~ TRANS_ITEM fn trait_method_default_impl::SomeGenericTrait[0]::bar[0]<i32, u64, &str>
6161
0i32.bar(0u64, "&str");
6262

63-
//~ TRANS_ITEM fn trait_method_default_impl::SomeGenericTrait[0]::bar[0]<i8, u32, &[char; 1]>
63+
//~ TRANS_ITEM fn trait_method_default_impl::SomeGenericTrait[0]::bar[0]<u32, i8, &[char; 1]>
6464
0u32.bar(0i8, &['c']);
6565

66-
//~ TRANS_ITEM fn trait_method_default_impl::SomeGenericTrait[0]::bar[0]<i16, u32, ()>
66+
//~ TRANS_ITEM fn trait_method_default_impl::SomeGenericTrait[0]::bar[0]<u32, i16, ()>
6767
0u32.bar(0i16, ());
6868
}
6969

src/test/compile-fail/variance-associated-types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ trait Trait<'a> {
2020
}
2121

2222
#[rustc_variance]
23-
struct Foo<'a, T : Trait<'a>> { //~ ERROR ItemVariances(types=[[+];[];[]], regions=[[-];[];[]])
23+
struct Foo<'a, T : Trait<'a>> { //~ ERROR ItemVariances(types=[[];[+];[]], regions=[[];[-];[]])
2424
field: (T, &'a ())
2525
}
2626

2727
#[rustc_variance]
28-
struct Bar<'a, T : Trait<'a>> { //~ ERROR ItemVariances(types=[[o];[];[]], regions=[[o];[];[]])
28+
struct Bar<'a, T : Trait<'a>> { //~ ERROR ItemVariances(types=[[];[o];[]], regions=[[];[o];[]])
2929
field: <T as Trait<'a>>::Type
3030
}
3131

src/test/compile-fail/variance-object-types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::cell::Cell;
1818
// For better or worse, associated types are invariant, and hence we
1919
// get an invariant result for `'a`.
2020
#[rustc_variance]
21-
struct Foo<'a> { //~ ERROR regions=[[o];[];[]]
21+
struct Foo<'a> { //~ ERROR regions=[[];[o];[]]
2222
x: Box<Fn(i32) -> &'a i32 + 'static>
2323
}
2424

src/test/compile-fail/variance-region-bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#![feature(rustc_attrs)]
1414

1515
#[rustc_variance]
16-
trait Foo: 'static { //~ ERROR types=[[];[o];[]]
16+
trait Foo: 'static { //~ ERROR types=[[o];[];[]]
1717
}
1818

1919
#[rustc_variance]

src/test/compile-fail/variance-regions-direct.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Regions that just appear in normal spots are contravariant:
1717

1818
#[rustc_variance]
19-
struct Test2<'a, 'b, 'c> { //~ ERROR regions=[[-, -, -];[];[]]
19+
struct Test2<'a, 'b, 'c> { //~ ERROR regions=[[];[-, -, -];[]]
2020
x: &'a isize,
2121
y: &'b [isize],
2222
c: &'c str
@@ -25,7 +25,7 @@ struct Test2<'a, 'b, 'c> { //~ ERROR regions=[[-, -, -];[];[]]
2525
// Those same annotations in function arguments become covariant:
2626

2727
#[rustc_variance]
28-
struct Test3<'a, 'b, 'c> { //~ ERROR regions=[[+, +, +];[];[]]
28+
struct Test3<'a, 'b, 'c> { //~ ERROR regions=[[];[+, +, +];[]]
2929
x: extern "Rust" fn(&'a isize),
3030
y: extern "Rust" fn(&'b [isize]),
3131
c: extern "Rust" fn(&'c str),
@@ -34,15 +34,15 @@ struct Test3<'a, 'b, 'c> { //~ ERROR regions=[[+, +, +];[];[]]
3434
// Mutability induces invariance:
3535

3636
#[rustc_variance]
37-
struct Test4<'a, 'b:'a> { //~ ERROR regions=[[-, o];[];[]]
37+
struct Test4<'a, 'b:'a> { //~ ERROR regions=[[];[-, o];[]]
3838
x: &'a mut &'b isize,
3939
}
4040

4141
// Mutability induces invariance, even when in a
4242
// contravariant context:
4343

4444
#[rustc_variance]
45-
struct Test5<'a, 'b:'a> { //~ ERROR regions=[[+, o];[];[]]
45+
struct Test5<'a, 'b:'a> { //~ ERROR regions=[[];[+, o];[]]
4646
x: extern "Rust" fn(&'a mut &'b isize),
4747
}
4848

@@ -52,22 +52,22 @@ struct Test5<'a, 'b:'a> { //~ ERROR regions=[[+, o];[];[]]
5252
// argument list occurs in an invariant context.
5353

5454
#[rustc_variance]
55-
struct Test6<'a, 'b:'a> { //~ ERROR regions=[[-, o];[];[]]
55+
struct Test6<'a, 'b:'a> { //~ ERROR regions=[[];[-, o];[]]
5656
x: &'a mut extern "Rust" fn(&'b isize),
5757
}
5858

5959
// No uses at all is bivariant:
6060

6161
#[rustc_variance]
62-
struct Test7<'a> { //~ ERROR regions=[[*];[];[]]
62+
struct Test7<'a> { //~ ERROR regions=[[];[*];[]]
6363
//~^ ERROR parameter `'a` is never used
6464
x: isize
6565
}
6666

6767
// Try enums too.
6868

6969
#[rustc_variance]
70-
enum Test8<'a, 'b, 'c:'b> { //~ ERROR regions=[[+, -, o];[];[]]
70+
enum Test8<'a, 'b, 'c:'b> { //~ ERROR regions=[[];[+, -, o];[]]
7171
Test8A(extern "Rust" fn(&'a isize)),
7272
Test8B(&'b [isize]),
7373
Test8C(&'b mut &'c str),

0 commit comments

Comments
 (0)