Skip to content

Commit eb222bf

Browse files
committed
Use revisions for NLL in associated-types
1 parent cc97875 commit eb222bf

32 files changed

+280
-130
lines changed

src/test/ui/associated-types/associated-types-eq-hr.stderr renamed to src/test/ui/associated-types/associated-types-eq-hr.base.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error[E0271]: type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
2-
--> $DIR/associated-types-eq-hr.rs:87:5
2+
--> $DIR/associated-types-eq-hr.rs:91:5
33
|
44
LL | foo::<UintStruct>();
55
| ^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
66
|
77
note: expected this to be `&isize`
8-
--> $DIR/associated-types-eq-hr.rs:26:14
8+
--> $DIR/associated-types-eq-hr.rs:30:14
99
|
1010
LL | type A = &'a usize;
1111
| ^^^^^^^^^
1212
= note: expected reference `&isize`
1313
found reference `&usize`
1414
note: required by a bound in `foo`
15-
--> $DIR/associated-types-eq-hr.rs:45:36
15+
--> $DIR/associated-types-eq-hr.rs:49:36
1616
|
1717
LL | fn foo<T>()
1818
| --- required by a bound in this
@@ -21,20 +21,20 @@ LL | T: for<'x> TheTrait<&'x isize, A = &'x isize>,
2121
| ^^^^^^^^^^^^^ required by this bound in `foo`
2222

2323
error[E0271]: type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
24-
--> $DIR/associated-types-eq-hr.rs:91:5
24+
--> $DIR/associated-types-eq-hr.rs:95:5
2525
|
2626
LL | bar::<IntStruct>();
2727
| ^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
2828
|
2929
note: expected this to be `&usize`
30-
--> $DIR/associated-types-eq-hr.rs:14:14
30+
--> $DIR/associated-types-eq-hr.rs:18:14
3131
|
3232
LL | type A = &'a isize;
3333
| ^^^^^^^^^
3434
= note: expected reference `&usize`
3535
found reference `&isize`
3636
note: required by a bound in `bar`
37-
--> $DIR/associated-types-eq-hr.rs:52:36
37+
--> $DIR/associated-types-eq-hr.rs:56:36
3838
|
3939
LL | fn bar<T>()
4040
| --- required by a bound in this
@@ -43,7 +43,7 @@ LL | T: for<'x> TheTrait<&'x isize, A = &'x usize>,
4343
| ^^^^^^^^^^^^^ required by this bound in `bar`
4444

4545
error: implementation of `TheTrait` is not general enough
46-
--> $DIR/associated-types-eq-hr.rs:96:5
46+
--> $DIR/associated-types-eq-hr.rs:100:5
4747
|
4848
LL | tuple_one::<Tuple>();
4949
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
@@ -52,7 +52,7 @@ LL | tuple_one::<Tuple>();
5252
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
5353

5454
error: implementation of `TheTrait` is not general enough
55-
--> $DIR/associated-types-eq-hr.rs:96:5
55+
--> $DIR/associated-types-eq-hr.rs:100:5
5656
|
5757
LL | tuple_one::<Tuple>();
5858
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
@@ -61,7 +61,7 @@ LL | tuple_one::<Tuple>();
6161
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
6262

6363
error: implementation of `TheTrait` is not general enough
64-
--> $DIR/associated-types-eq-hr.rs:102:5
64+
--> $DIR/associated-types-eq-hr.rs:106:5
6565
|
6666
LL | tuple_two::<Tuple>();
6767
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
@@ -70,7 +70,7 @@ LL | tuple_two::<Tuple>();
7070
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
7171

7272
error: implementation of `TheTrait` is not general enough
73-
--> $DIR/associated-types-eq-hr.rs:102:5
73+
--> $DIR/associated-types-eq-hr.rs:106:5
7474
|
7575
LL | tuple_two::<Tuple>();
7676
| ^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough
@@ -79,7 +79,7 @@ LL | tuple_two::<Tuple>();
7979
= note: ...but it actually implements `TheTrait<(&'2 isize, &'2 isize)>`, for some specific lifetime `'2`
8080

8181
error: implementation of `TheTrait` is not general enough
82-
--> $DIR/associated-types-eq-hr.rs:112:5
82+
--> $DIR/associated-types-eq-hr.rs:116:5
8383
|
8484
LL | tuple_four::<Tuple>();
8585
| ^^^^^^^^^^^^^^^^^^^ implementation of `TheTrait` is not general enough

src/test/ui/associated-types/associated-types-eq-hr.nll.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error[E0271]: type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
2-
--> $DIR/associated-types-eq-hr.rs:87:5
2+
--> $DIR/associated-types-eq-hr.rs:91:5
33
|
44
LL | foo::<UintStruct>();
55
| ^^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize>>::A == &'x isize`
66
|
77
note: expected this to be `&isize`
8-
--> $DIR/associated-types-eq-hr.rs:26:14
8+
--> $DIR/associated-types-eq-hr.rs:30:14
99
|
1010
LL | type A = &'a usize;
1111
| ^^^^^^^^^
1212
= note: expected reference `&isize`
1313
found reference `&usize`
1414
note: required by a bound in `foo`
15-
--> $DIR/associated-types-eq-hr.rs:45:36
15+
--> $DIR/associated-types-eq-hr.rs:49:36
1616
|
1717
LL | fn foo<T>()
1818
| --- required by a bound in this
@@ -21,20 +21,20 @@ LL | T: for<'x> TheTrait<&'x isize, A = &'x isize>,
2121
| ^^^^^^^^^^^^^ required by this bound in `foo`
2222

2323
error[E0271]: type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
24-
--> $DIR/associated-types-eq-hr.rs:91:5
24+
--> $DIR/associated-types-eq-hr.rs:95:5
2525
|
2626
LL | bar::<IntStruct>();
2727
| ^^^^^^^^^^^^^^^^ type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
2828
|
2929
note: expected this to be `&usize`
30-
--> $DIR/associated-types-eq-hr.rs:14:14
30+
--> $DIR/associated-types-eq-hr.rs:18:14
3131
|
3232
LL | type A = &'a isize;
3333
| ^^^^^^^^^
3434
= note: expected reference `&usize`
3535
found reference `&isize`
3636
note: required by a bound in `bar`
37-
--> $DIR/associated-types-eq-hr.rs:52:36
37+
--> $DIR/associated-types-eq-hr.rs:56:36
3838
|
3939
LL | fn bar<T>()
4040
| --- required by a bound in this

src/test/ui/associated-types/associated-types-eq-hr.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// revisions: base nll
2+
// ignore-compare-mode-nll
3+
//[nll] compile-flags: -Z borrowck=mir
4+
15
// Check testing of equality constraints in a higher-ranked context.
26

37
pub trait TheTrait<T> {
@@ -94,14 +98,14 @@ pub fn call_bar() {
9498

9599
pub fn call_tuple_one() {
96100
tuple_one::<Tuple>();
97-
//~^ ERROR implementation of `TheTrait` is not general enough
98-
//~| ERROR implementation of `TheTrait` is not general enough
101+
//[base]~^ ERROR implementation of `TheTrait` is not general enough
102+
//[base]~| ERROR implementation of `TheTrait` is not general enough
99103
}
100104

101105
pub fn call_tuple_two() {
102106
tuple_two::<Tuple>();
103-
//~^ ERROR implementation of `TheTrait` is not general enough
104-
//~| ERROR implementation of `TheTrait` is not general enough
107+
//[base]~^ ERROR implementation of `TheTrait` is not general enough
108+
//[base]~| ERROR implementation of `TheTrait` is not general enough
105109
}
106110

107111
pub fn call_tuple_three() {
@@ -110,7 +114,7 @@ pub fn call_tuple_three() {
110114

111115
pub fn call_tuple_four() {
112116
tuple_four::<Tuple>();
113-
//~^ ERROR implementation of `TheTrait` is not general enough
117+
//[base]~^ ERROR implementation of `TheTrait` is not general enough
114118
}
115119

116120
fn main() {}

src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn-body.stderr renamed to src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn-body.base.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0623]: lifetime mismatch
2-
--> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:22:40
2+
--> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:26:40
33
|
44
LL | x: <I as Foo<&'a isize>>::A,
55
| --------- these two types are declared with different lifetimes...

src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn-body.nll.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:22:29
2+
--> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:26:29
33
|
44
LL | fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>(
55
| -- -- lifetime `'b` defined here
@@ -12,7 +12,7 @@ LL | let z: I::A = if cond { x } else { y };
1212
= help: consider adding the following bound: `'a: 'b`
1313

1414
error: lifetime may not live long enough
15-
--> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:22:40
15+
--> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:26:40
1616
|
1717
LL | fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>(
1818
| -- -- lifetime `'b` defined here

src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn-body.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// ignore-compare-mode-nll
2+
// revisions: base nll
3+
// [nll]compile-flags: -Zborrowck=mir
4+
15
// Check projection of an associated type out of a higher-ranked
26
// trait-bound in the context of a function body.
37

@@ -20,7 +24,9 @@ fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>(
2024
{
2125
// x and y here have two distinct lifetimes:
2226
let z: I::A = if cond { x } else { y };
23-
//~^ ERROR lifetime mismatch
27+
//[base]~^ ERROR lifetime mismatch
28+
//[nll]~^^ ERROR lifetime may not live long enough
29+
//[nll]~| ERROR lifetime may not live long enough
2430
}
2531

2632
pub fn main() {}

src/test/ui/associated-types/associated-types-subtyping-1.stderr renamed to src/test/ui/associated-types/associated-types-subtyping-1.base.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0623]: lifetime mismatch
2-
--> $DIR/associated-types-subtyping-1.rs:26:38
2+
--> $DIR/associated-types-subtyping-1.rs:31:38
33
|
44
LL | fn method2<'a,'b,T>(x: &'a T, y: &'b T)
55
| ----- ----- these two types are declared with different lifetimes...
@@ -8,7 +8,7 @@ LL | let _c: <T as Trait<'b>>::Type = a;
88
| ^ ...but data from `y` flows into `x` here
99

1010
error[E0623]: lifetime mismatch
11-
--> $DIR/associated-types-subtyping-1.rs:35:38
11+
--> $DIR/associated-types-subtyping-1.rs:41:38
1212
|
1313
LL | fn method3<'a,'b,T>(x: &'a T, y: &'b T)
1414
| ----- ----- these two types are declared with different lifetimes...

src/test/ui/associated-types/associated-types-subtyping-1.nll.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/associated-types-subtyping-1.rs:24:12
2+
--> $DIR/associated-types-subtyping-1.rs:28:12
33
|
44
LL | fn method2<'a,'b,T>(x: &'a T, y: &'b T)
55
| -- -- lifetime `'b` defined here
@@ -12,7 +12,7 @@ LL | let a: <T as Trait<'a>>::Type = make_any();
1212
= help: consider adding the following bound: `'b: 'a`
1313

1414
error: lifetime may not live long enough
15-
--> $DIR/associated-types-subtyping-1.rs:35:13
15+
--> $DIR/associated-types-subtyping-1.rs:41:13
1616
|
1717
LL | fn method3<'a,'b,T>(x: &'a T, y: &'b T)
1818
| -- -- lifetime `'b` defined here

src/test/ui/associated-types/associated-types-subtyping-1.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// ignore-compare-mode-nll
2+
// revisions: base nll
3+
// [nll]compile-flags: -Zborrowck=mir
4+
15
#![allow(unused_variables)]
26

37
fn make_any<T>() -> T { loop {} }
@@ -22,8 +26,10 @@ fn method2<'a,'b,T>(x: &'a T, y: &'b T)
2226
{
2327
// Note that &'static T <: &'a T.
2428
let a: <T as Trait<'a>>::Type = make_any();
29+
//[nll]~^ ERROR lifetime may not live long enough
2530
let b: <T as Trait<'b>>::Type = make_any();
26-
let _c: <T as Trait<'b>>::Type = a; //~ ERROR E0623
31+
let _c: <T as Trait<'b>>::Type = a;
32+
//[base]~^ ERROR E0623
2733
}
2834

2935
fn method3<'a,'b,T>(x: &'a T, y: &'b T)
@@ -32,7 +38,9 @@ fn method3<'a,'b,T>(x: &'a T, y: &'b T)
3238
// Note that &'static T <: &'a T.
3339
let a: <T as Trait<'a>>::Type = make_any();
3440
let b: <T as Trait<'b>>::Type = make_any();
35-
let _c: <T as Trait<'a>>::Type = b; //~ ERROR E0623
41+
let _c: <T as Trait<'a>>::Type = b;
42+
//[base]~^ ERROR E0623
43+
//[nll]~^^ ERROR lifetime may not live long enough
3644
}
3745

3846
fn method4<'a,'b,T>(x: &'a T, y: &'b T)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0623]: lifetime mismatch
2+
--> $DIR/project-fn-ret-contravariant-nll.rs:51:5
3+
|
4+
LL | fn transmute<'a,'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) {
5+
| ------- ------------------
6+
| |
7+
| this parameter and the return type are declared with different lifetimes...
8+
...
9+
LL | (a, b)
10+
| ^ ...but data from `y` is returned here
11+
12+
error[E0623]: lifetime mismatch
13+
--> $DIR/project-fn-ret-contravariant-nll.rs:51:8
14+
|
15+
LL | fn transmute<'a,'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) {
16+
| ------- ------------------
17+
| |
18+
| this parameter and the return type are declared with different lifetimes...
19+
...
20+
LL | (a, b)
21+
| ^ ...but data from `x` is returned here
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0623`.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#![feature(unboxed_closures)]
2+
3+
// Test for projection cache. We should be able to project distinct
4+
// lifetimes from `foo` as we reinstantiate it multiple times, but not
5+
// if we do it just once. In this variant, the region `'a` is used in
6+
// an contravariant position, which affects the results.
7+
8+
// revisions: ok oneuse transmute krisskross
9+
//[ok] check-pass
10+
//[oneuse] check-pass
11+
12+
// ignore-compare-mode-nll
13+
// FIXME(nll): When stabilizing, this test should replace `project-fn-ret-contravariant.rs`
14+
// The two would normally be just revisions, but this test uses revisions heavily, so splitting into
15+
// a separate test is just easier.
16+
17+
#![allow(dead_code, unused_variables)]
18+
19+
fn foo<'a>() -> &'a u32 { loop { } }
20+
21+
fn bar<T>(t: T, x: T::Output) -> T::Output
22+
where T: FnOnce<()>
23+
{
24+
t()
25+
}
26+
27+
#[cfg(ok)] // two instantiations: OK
28+
fn baz<'a,'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) {
29+
let a = bar(foo, x);
30+
let b = bar(foo, y);
31+
(a, b)
32+
}
33+
34+
#[cfg(oneuse)] // one instantiation: OK (surprisingly)
35+
fn baz<'a,'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) {
36+
let f /* : fn() -> &'static u32 */ = foo; // <-- inferred type annotated
37+
let a = bar(f, x); // this is considered ok because fn args are contravariant...
38+
let b = bar(f, y); // ...and hence we infer T to distinct values in each call.
39+
(a, b)
40+
}
41+
42+
#[cfg(transmute)] // one instantiations: BAD
43+
fn baz<'a,'b>(x: &'a u32) -> &'static u32 {
44+
bar(foo, x) //[transmute]~ ERROR E0759
45+
}
46+
47+
#[cfg(krisskross)] // two instantiations, mixing and matching: BAD
48+
fn transmute<'a,'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) {
49+
let a = bar(foo, y);
50+
let b = bar(foo, x);
51+
(a, b) //[krisskross]~ ERROR lifetime mismatch [E0623]
52+
//[krisskross]~^ ERROR lifetime mismatch [E0623]
53+
}
54+
55+
fn main() { }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
2+
--> $DIR/project-fn-ret-contravariant-nll.rs:44:8
3+
|
4+
LL | fn baz<'a,'b>(x: &'a u32) -> &'static u32 {
5+
| ------- this data with lifetime `'a`...
6+
LL | bar(foo, x)
7+
| ^^^ - ...is used and required to live as long as `'static` here
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0759`.

0 commit comments

Comments
 (0)