Skip to content

Commit dc435ee

Browse files
committed
For hr-subtype test, use check-pass instead of rustc_error and split nll differences to separate test
1 parent 0a437b2 commit dc435ee

24 files changed

+164
-112
lines changed

src/test/ui/hr-subtype/hr-subtype.bound_a_b_ret_a_vs_bound_a_ret_a.nll.stderr renamed to src/test/ui/hr-subtype/hr-subtype-nll.bound_a_b_ret_a_vs_bound_a_ret_a.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/hr-subtype.rs:45:13
2+
--> $DIR/hr-subtype-nll.rs:60:13
33
|
44
LL | gimme::<$t1>(None::<$t2>);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other

src/test/ui/hr-subtype/hr-subtype.bound_a_vs_free_x.nll.stderr renamed to src/test/ui/hr-subtype/hr-subtype-nll.bound_a_vs_free_x.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/hr-subtype.rs:45:13
2+
--> $DIR/hr-subtype-nll.rs:60:13
33
|
44
LL | gimme::<$t1>(None::<$t2>);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other

src/test/ui/hr-subtype/hr-subtype.bound_inv_a_b_vs_bound_inv_a.nll.stderr renamed to src/test/ui/hr-subtype/hr-subtype-nll.bound_inv_a_b_vs_bound_inv_a.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/hr-subtype.rs:45:13
2+
--> $DIR/hr-subtype-nll.rs:60:13
33
|
44
LL | gimme::<$t1>(None::<$t2>);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
@@ -13,7 +13,7 @@ LL | | for<'a> fn(Inv<'a>, Inv<'a>)) }
1313
= note: this error originates in the macro `check` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

1515
error[E0308]: mismatched types
16-
--> $DIR/hr-subtype.rs:45:13
16+
--> $DIR/hr-subtype-nll.rs:60:13
1717
|
1818
LL | gimme::<$t1>(None::<$t2>);
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other

src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.nll.stderr renamed to src/test/ui/hr-subtype/hr-subtype-nll.free_inv_x_vs_free_inv_y.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/hr-subtype.rs:39:13
2+
--> $DIR/hr-subtype-nll.rs:54:13
33
|
44
LL | fn subtype<'x, 'y: 'x, 'z: 'y>() {
55
| -- -- lifetime `'y` defined here
@@ -19,7 +19,7 @@ LL | | fn(Inv<'y>)) }
1919
= note: this error originates in the macro `check` (in Nightly builds, run with -Z macro-backtrace for more info)
2020

2121
error: lifetime may not live long enough
22-
--> $DIR/hr-subtype.rs:45:13
22+
--> $DIR/hr-subtype-nll.rs:60:13
2323
|
2424
LL | fn supertype<'x, 'y: 'x, 'z: 'y>() {
2525
| -- -- lifetime `'y` defined here

src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_y.nll.stderr renamed to src/test/ui/hr-subtype/hr-subtype-nll.free_x_vs_free_y.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/hr-subtype.rs:45:13
2+
--> $DIR/hr-subtype-nll.rs:60:13
33
|
44
LL | fn supertype<'x, 'y: 'x, 'z: 'y>() {
55
| -- -- lifetime `'y` defined here
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Targeted tests for the higher-ranked subtyping code.
2+
3+
#![allow(dead_code)]
4+
5+
// revisions: bound_a_vs_bound_a
6+
// revisions: bound_a_vs_bound_b
7+
// revisions: bound_inv_a_vs_bound_inv_b
8+
// revisions: bound_co_a_vs_bound_co_b
9+
// revisions: bound_a_vs_free_x
10+
// revisions: free_x_vs_free_x
11+
// revisions: free_x_vs_free_y
12+
// revisions: free_inv_x_vs_free_inv_y
13+
// revisions: bound_a_b_vs_bound_a
14+
// revisions: bound_co_a_b_vs_bound_co_a
15+
// revisions: bound_contra_a_contra_b_ret_co_a
16+
// revisions: bound_co_a_co_b_ret_contra_a
17+
// revisions: bound_inv_a_b_vs_bound_inv_a
18+
// revisions: bound_a_b_ret_a_vs_bound_a_ret_a
19+
20+
//[bound_a_vs_bound_a] check-pass
21+
//[bound_a_vs_bound_b] check-pass
22+
//[bound_inv_a_vs_bound_inv_b] check-pass
23+
//[bound_co_a_vs_bound_co_b] check-pass
24+
//[free_x_vs_free_x] check-pass
25+
//[bound_co_a_b_vs_bound_co_a] check-pass
26+
//[bound_co_a_co_b_ret_contra_a] check-pass
27+
//[bound_a_b_vs_bound_a] check-pass
28+
//[bound_contra_a_contra_b_ret_co_a] check-pass
29+
30+
// compile-flags: -Z borrowck=mir
31+
// ignore-compare-mode-nll
32+
// FIXME(nll): When stabilizing, this test should be replace with `hr-subtype.rs`
33+
// The two would normally be just revisions, but this test uses revisions heavily, so splitting into
34+
// a separate test is just easier.
35+
36+
fn gimme<T>(_: Option<T>) {}
37+
38+
struct Inv<'a> {
39+
x: *mut &'a u32,
40+
}
41+
42+
struct Co<'a> {
43+
x: fn(&'a u32),
44+
}
45+
46+
struct Contra<'a> {
47+
x: &'a u32,
48+
}
49+
50+
macro_rules! check {
51+
($rev:ident: ($t1:ty, $t2:ty)) => {
52+
#[cfg($rev)]
53+
fn subtype<'x, 'y: 'x, 'z: 'y>() {
54+
gimme::<$t2>(None::<$t1>);
55+
//[free_inv_x_vs_free_inv_y]~^ ERROR
56+
}
57+
58+
#[cfg($rev)]
59+
fn supertype<'x, 'y: 'x, 'z: 'y>() {
60+
gimme::<$t1>(None::<$t2>);
61+
//[bound_a_vs_free_x]~^ ERROR
62+
//[free_x_vs_free_y]~^^ ERROR
63+
//[bound_inv_a_b_vs_bound_inv_a]~^^^ ERROR
64+
//[bound_inv_a_b_vs_bound_inv_a]~| ERROR
65+
//[bound_a_b_ret_a_vs_bound_a_ret_a]~^^^^^ ERROR
66+
//[free_inv_x_vs_free_inv_y]~^^^^^^ ERROR
67+
}
68+
};
69+
}
70+
71+
// If both have bound regions, they are equivalent, regardless of
72+
// variant.
73+
check! { bound_a_vs_bound_a: (for<'a> fn(&'a u32),
74+
for<'a> fn(&'a u32)) }
75+
check! { bound_a_vs_bound_b: (for<'a> fn(&'a u32),
76+
for<'b> fn(&'b u32)) }
77+
check! { bound_inv_a_vs_bound_inv_b: (for<'a> fn(Inv<'a>),
78+
for<'b> fn(Inv<'b>)) }
79+
check! { bound_co_a_vs_bound_co_b: (for<'a> fn(Co<'a>),
80+
for<'b> fn(Co<'b>)) }
81+
82+
// Bound is a subtype of free.
83+
check! { bound_a_vs_free_x: (for<'a> fn(&'a u32),
84+
fn(&'x u32)) }
85+
86+
// Two free regions are relatable if subtyping holds.
87+
check! { free_x_vs_free_x: (fn(&'x u32),
88+
fn(&'x u32)) }
89+
check! { free_x_vs_free_y: (fn(&'x u32),
90+
fn(&'y u32)) }
91+
check! { free_inv_x_vs_free_inv_y: (fn(Inv<'x>),
92+
fn(Inv<'y>)) }
93+
94+
// Somewhat surprisingly, a fn taking two distinct bound lifetimes and
95+
// a fn taking one bound lifetime can be interchangeable, but only if
96+
// we are co- or contra-variant with respect to both lifetimes.
97+
//
98+
// The reason is:
99+
// - if we are covariant, then 'a and 'b can be set to the call-site
100+
// intersection;
101+
// - if we are contravariant, then 'a can be inferred to 'static.
102+
check! { bound_a_b_vs_bound_a: (for<'a,'b> fn(&'a u32, &'b u32),
103+
for<'a> fn(&'a u32, &'a u32)) }
104+
check! { bound_co_a_b_vs_bound_co_a: (for<'a,'b> fn(Co<'a>, Co<'b>),
105+
for<'a> fn(Co<'a>, Co<'a>)) }
106+
check! { bound_contra_a_contra_b_ret_co_a: (for<'a,'b> fn(Contra<'a>, Contra<'b>) -> Co<'a>,
107+
for<'a> fn(Contra<'a>, Contra<'a>) -> Co<'a>) }
108+
check! { bound_co_a_co_b_ret_contra_a: (for<'a,'b> fn(Co<'a>, Co<'b>) -> Contra<'a>,
109+
for<'a> fn(Co<'a>, Co<'a>) -> Contra<'a>) }
110+
111+
// If we make those lifetimes invariant, then the two types are not interchangeable.
112+
check! { bound_inv_a_b_vs_bound_inv_a: (for<'a,'b> fn(Inv<'a>, Inv<'b>),
113+
for<'a> fn(Inv<'a>, Inv<'a>)) }
114+
check! { bound_a_b_ret_a_vs_bound_a_ret_a: (for<'a,'b> fn(&'a u32, &'b u32) -> &'a u32,
115+
for<'a> fn(&'a u32, &'a u32) -> &'a u32) }
116+
117+
fn main() {}

src/test/ui/hr-subtype/hr-subtype.bound_a_b_ret_a_vs_bound_a_ret_a.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/hr-subtype.rs:45:26
2+
--> $DIR/hr-subtype.rs:59:26
33
|
44
LL | gimme::<$t1>(None::<$t2>);
55
| ^^^^^^^^^^^ one type is more general than the other

src/test/ui/hr-subtype/hr-subtype.bound_a_b_vs_bound_a.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/hr-subtype/hr-subtype.bound_a_vs_bound_a.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/hr-subtype/hr-subtype.bound_a_vs_bound_b.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/hr-subtype/hr-subtype.bound_a_vs_free_x.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/hr-subtype.rs:45:26
2+
--> $DIR/hr-subtype.rs:59:26
33
|
44
LL | gimme::<$t1>(None::<$t2>);
55
| ^^^^^^^^^^^ one type is more general than the other

src/test/ui/hr-subtype/hr-subtype.bound_co_a_b_vs_bound_co_a.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/hr-subtype/hr-subtype.bound_co_a_co_b_ret_contra_a.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/hr-subtype/hr-subtype.bound_co_a_vs_bound_co_b.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/hr-subtype/hr-subtype.bound_contra_a_contra_b_ret_co_a.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/hr-subtype/hr-subtype.bound_inv_a_b_vs_bound_inv_a.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/hr-subtype.rs:45:26
2+
--> $DIR/hr-subtype.rs:59:26
33
|
44
LL | gimme::<$t1>(None::<$t2>);
55
| ^^^^^^^^^^^ one type is more general than the other

src/test/ui/hr-subtype/hr-subtype.bound_inv_a_vs_bound_inv_b.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/hr-subtype/hr-subtype.free_inv_x_vs_free_inv_y.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/hr-subtype.rs:39:26
2+
--> $DIR/hr-subtype.rs:53:26
33
|
44
LL | gimme::<$t2>(None::<$t1>);
55
| ^^^^^^^^^^^ lifetime mismatch
@@ -11,7 +11,7 @@ LL | | fn(Inv<'y>)) }
1111
= note: expected enum `Option<fn(Inv<'y>)>`
1212
found enum `Option<fn(Inv<'x>)>`
1313
note: the lifetime `'x` as defined here...
14-
--> $DIR/hr-subtype.rs:38:20
14+
--> $DIR/hr-subtype.rs:52:20
1515
|
1616
LL | fn subtype<'x, 'y: 'x, 'z: 'y>() {
1717
| ^^
@@ -20,7 +20,7 @@ LL | / check! { free_inv_x_vs_free_inv_y: (fn(Inv<'x>),
2020
LL | | fn(Inv<'y>)) }
2121
| |______________- in this macro invocation
2222
note: ...does not necessarily outlive the lifetime `'y` as defined here
23-
--> $DIR/hr-subtype.rs:38:24
23+
--> $DIR/hr-subtype.rs:52:24
2424
|
2525
LL | fn subtype<'x, 'y: 'x, 'z: 'y>() {
2626
| ^^
@@ -31,7 +31,7 @@ LL | | fn(Inv<'y>)) }
3131
= note: this error originates in the macro `check` (in Nightly builds, run with -Z macro-backtrace for more info)
3232

3333
error[E0308]: mismatched types
34-
--> $DIR/hr-subtype.rs:45:26
34+
--> $DIR/hr-subtype.rs:59:26
3535
|
3636
LL | gimme::<$t1>(None::<$t2>);
3737
| ^^^^^^^^^^^ lifetime mismatch
@@ -43,7 +43,7 @@ LL | | fn(Inv<'y>)) }
4343
= note: expected enum `Option<fn(Inv<'x>)>`
4444
found enum `Option<fn(Inv<'y>)>`
4545
note: the lifetime `'x` as defined here...
46-
--> $DIR/hr-subtype.rs:44:22
46+
--> $DIR/hr-subtype.rs:58:22
4747
|
4848
LL | fn supertype<'x, 'y: 'x, 'z: 'y>() {
4949
| ^^
@@ -52,7 +52,7 @@ LL | / check! { free_inv_x_vs_free_inv_y: (fn(Inv<'x>),
5252
LL | | fn(Inv<'y>)) }
5353
| |______________- in this macro invocation
5454
note: ...does not necessarily outlive the lifetime `'y` as defined here
55-
--> $DIR/hr-subtype.rs:44:26
55+
--> $DIR/hr-subtype.rs:58:26
5656
|
5757
LL | fn supertype<'x, 'y: 'x, 'z: 'y>() {
5858
| ^^

src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_x.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/hr-subtype/hr-subtype.free_x_vs_free_y.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/hr-subtype.rs:45:26
2+
--> $DIR/hr-subtype.rs:59:26
33
|
44
LL | gimme::<$t1>(None::<$t2>);
55
| ^^^^^^^^^^^ lifetime mismatch
@@ -11,7 +11,7 @@ LL | | fn(&'y u32)) }
1111
= note: expected enum `Option<fn(&'x u32)>`
1212
found enum `Option<fn(&'y u32)>`
1313
note: the lifetime `'x` as defined here...
14-
--> $DIR/hr-subtype.rs:44:22
14+
--> $DIR/hr-subtype.rs:58:22
1515
|
1616
LL | fn supertype<'x, 'y: 'x, 'z: 'y>() {
1717
| ^^
@@ -20,7 +20,7 @@ LL | / check! { free_x_vs_free_y: (fn(&'x u32),
2020
LL | | fn(&'y u32)) }
2121
| |______________- in this macro invocation
2222
note: ...does not necessarily outlive the lifetime `'y` as defined here
23-
--> $DIR/hr-subtype.rs:44:26
23+
--> $DIR/hr-subtype.rs:58:26
2424
|
2525
LL | fn supertype<'x, 'y: 'x, 'z: 'y>() {
2626
| ^^

src/test/ui/hr-subtype/hr-subtype.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Targeted tests for the higher-ranked subtyping code.
22

3-
#![feature(rustc_attrs)]
43
#![allow(dead_code)]
54

65
// revisions: bound_a_vs_bound_a
@@ -18,6 +17,21 @@
1817
// revisions: bound_inv_a_b_vs_bound_inv_a
1918
// revisions: bound_a_b_ret_a_vs_bound_a_ret_a
2019

20+
//[bound_a_vs_bound_a] check-pass
21+
//[bound_a_vs_bound_b] check-pass
22+
//[bound_inv_a_vs_bound_inv_b] check-pass
23+
//[bound_co_a_vs_bound_co_b] check-pass
24+
//[free_x_vs_free_x] check-pass
25+
//[bound_co_a_b_vs_bound_co_a] check-pass
26+
//[bound_co_a_co_b_ret_contra_a] check-pass
27+
//[bound_a_b_vs_bound_a] check-pass
28+
//[bound_contra_a_contra_b_ret_co_a] check-pass
29+
30+
// ignore-compare-mode-nll
31+
// FIXME(nll): When stabilizing, this test should be replaced with `hr-subtype-nll.rs`
32+
// The two would normally be just revisions, but this test uses revisions heavily, so splitting into
33+
// a separate test is just easier.
34+
2135
fn gimme<T>(_: Option<T>) {}
2236

2337
struct Inv<'a> {
@@ -98,15 +112,4 @@ for<'a> fn(Inv<'a>, Inv<'a>)) }
98112
check! { bound_a_b_ret_a_vs_bound_a_ret_a: (for<'a,'b> fn(&'a u32, &'b u32) -> &'a u32,
99113
for<'a> fn(&'a u32, &'a u32) -> &'a u32) }
100114

101-
#[rustc_error]
102-
fn main() {
103-
//[bound_a_vs_bound_a]~^ ERROR fatal error triggered by #[rustc_error]
104-
//[bound_a_vs_bound_b]~^^ ERROR fatal error triggered by #[rustc_error]
105-
//[bound_inv_a_vs_bound_inv_b]~^^^ ERROR fatal error triggered by #[rustc_error]
106-
//[bound_co_a_vs_bound_co_b]~^^^^ ERROR fatal error triggered by #[rustc_error]
107-
//[free_x_vs_free_x]~^^^^^ ERROR fatal error triggered by #[rustc_error]
108-
//[bound_co_a_b_vs_bound_co_a]~^^^^^^ ERROR
109-
//[bound_co_a_co_b_ret_contra_a]~^^^^^^^ ERROR
110-
//[bound_a_b_vs_bound_a]~^^^^^^^^ ERROR
111-
//[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR
112-
}
115+
fn main() {}

0 commit comments

Comments
 (0)