tests: cases where we now do the right thing but did not before

Fixes #33684
This commit is contained in:
Niko Matsakis 2018-12-31 13:45:40 -05:00
parent d3c96ff152
commit c8e0a90dfc
19 changed files with 137 additions and 137 deletions

View File

@ -1,16 +1,19 @@
error[E0308]: mismatched types
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter 'a in generic type due to conflicting requirements
--> $DIR/hr-subtype.rs:39:26
|
LL | gimme::<$t1>(None::<$t2>);
| ^^^^^^^^^^^ expected concrete lifetime, found bound lifetime parameter 'a
| ^^^^^^^^^^^
...
LL | / check! { bound_a_b_ret_a_vs_bound_a_ret_a: (for<'a,'b> fn(&'a u32, &'b u32) -> &'a u32,
LL | | for<'a> fn(&'a u32, &'a u32) -> &'a u32) }
| |_________________________________________________________________________________________- in this macro invocation
|
= note: expected type `std::option::Option<for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32>`
found type `std::option::Option<for<'a> fn(&'a u32, &'a u32) -> &'a u32>`
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:26), 'b) })...
= note: ...but the lifetime must also be valid for lifetime RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:25), 'a) })...
= note: ...so that the expression is assignable:
expected std::option::Option<for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32>
found std::option::Option<for<'a> fn(&'a u32, &'a u32) -> &'a u32>
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0495`.

View File

@ -1,16 +1,14 @@
error[E0308]: mismatched types
--> $DIR/hr-subtype.rs:39:26
error: compilation successful
--> $DIR/hr-subtype.rs:96:1
|
LL | gimme::<$t1>(None::<$t2>);
| ^^^^^^^^^^^ expected concrete lifetime, found bound lifetime parameter 'a
...
LL | / check! { bound_a_b_vs_bound_a: (for<'a,'b> fn(&'a u32, &'b u32),
LL | | for<'a> fn(&'a u32, &'a u32)) }
| |__________________________________________________________________- in this macro invocation
|
= note: expected type `std::option::Option<for<'a, 'b> fn(&'a u32, &'b u32)>`
found type `std::option::Option<for<'a> fn(&'a u32, &'a u32)>`
LL | / fn main() {
LL | | //[bound_a_vs_bound_a]~^ ERROR compilation successful
LL | | //[bound_a_vs_bound_b]~^^ ERROR compilation successful
LL | | //[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
... |
LL | | //[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR compilation successful
LL | | }
| |_^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View File

@ -1,12 +1,12 @@
error: compilation successful
--> $DIR/hr-subtype.rs:100:1
--> $DIR/hr-subtype.rs:96:1
|
LL | / fn main() {
LL | | //[bound_a_vs_bound_a]~^ ERROR compilation successful
LL | | //[bound_a_vs_bound_b]~^^ ERROR compilation successful
LL | | //[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
LL | | //[bound_co_a_vs_bound_co_b]~^^^^ ERROR compilation successful
LL | | //[free_x_vs_free_x]~^^^^^ ERROR compilation successful
... |
LL | | //[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR compilation successful
LL | | }
| |_^

View File

@ -1,12 +1,12 @@
error: compilation successful
--> $DIR/hr-subtype.rs:100:1
--> $DIR/hr-subtype.rs:96:1
|
LL | / fn main() {
LL | | //[bound_a_vs_bound_a]~^ ERROR compilation successful
LL | | //[bound_a_vs_bound_b]~^^ ERROR compilation successful
LL | | //[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
LL | | //[bound_co_a_vs_bound_co_b]~^^^^ ERROR compilation successful
LL | | //[free_x_vs_free_x]~^^^^^ ERROR compilation successful
... |
LL | | //[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR compilation successful
LL | | }
| |_^

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/hr-subtype.rs:39:26
|
LL | gimme::<$t1>(None::<$t2>);
| ^^^^^^^^^^^ expected concrete lifetime, found bound lifetime parameter 'a
| ^^^^^^^^^^^ lifetime mismatch
...
LL | / check! { bound_a_vs_free_x: (for<'a> fn(&'a u32),
LL | | fn(&'x u32)) }
@ -10,6 +10,16 @@ LL | | fn(&'x u32)) }
|
= note: expected type `std::option::Option<for<'a> fn(&'a u32)>`
found type `std::option::Option<fn(&'x u32)>`
= note: lifetime RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:23), 'a) })...
note: ...does not necessarily outlive the lifetime 'x as defined on the function body at 48:22
--> $DIR/hr-subtype.rs:48:22
|
LL | fn supertype<'x,'y:'x,'z:'y>() {
| ^^
...
LL | / check! { bound_a_vs_free_x: (for<'a> fn(&'a u32),
LL | | fn(&'x u32)) }
| |___________________________________________- in this macro invocation
error: aborting due to previous error

View File

@ -1,16 +1,14 @@
error[E0308]: mismatched types
--> $DIR/hr-subtype.rs:39:26
error: compilation successful
--> $DIR/hr-subtype.rs:96:1
|
LL | gimme::<$t1>(None::<$t2>);
| ^^^^^^^^^^^ expected concrete lifetime, found bound lifetime parameter 'a
...
LL | / check! { bound_co_a_b_vs_bound_co_a: (for<'a,'b> fn(Co<'a>, Co<'b>),
LL | | for<'a> fn(Co<'a>, Co<'a>)) }
| |______________________________________________________________________- in this macro invocation
|
= note: expected type `std::option::Option<for<'a, 'b> fn(Co<'a>, Co<'b>)>`
found type `std::option::Option<for<'a> fn(Co<'a>, Co<'a>)>`
LL | / fn main() {
LL | | //[bound_a_vs_bound_a]~^ ERROR compilation successful
LL | | //[bound_a_vs_bound_b]~^^ ERROR compilation successful
LL | | //[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
... |
LL | | //[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR compilation successful
LL | | }
| |_^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View File

@ -1,16 +1,14 @@
error[E0308]: mismatched types
--> $DIR/hr-subtype.rs:39:26
error: compilation successful
--> $DIR/hr-subtype.rs:96:1
|
LL | gimme::<$t1>(None::<$t2>);
| ^^^^^^^^^^^ expected concrete lifetime, found bound lifetime parameter 'a
...
LL | / check! { bound_co_a_co_b_ret_contra_a: (for<'a,'b> fn(Co<'a>, Co<'b>) -> Contra<'a>,
LL | | for<'a> fn(Co<'a>, Co<'a>) -> Contra<'a>) }
| |______________________________________________________________________________________- in this macro invocation
|
= note: expected type `std::option::Option<for<'a, 'b> fn(Co<'a>, Co<'b>) -> Contra<'a>>`
found type `std::option::Option<for<'a> fn(Co<'a>, Co<'a>) -> Contra<'a>>`
LL | / fn main() {
LL | | //[bound_a_vs_bound_a]~^ ERROR compilation successful
LL | | //[bound_a_vs_bound_b]~^^ ERROR compilation successful
LL | | //[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
... |
LL | | //[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR compilation successful
LL | | }
| |_^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View File

@ -1,12 +1,12 @@
error: compilation successful
--> $DIR/hr-subtype.rs:100:1
--> $DIR/hr-subtype.rs:96:1
|
LL | / fn main() {
LL | | //[bound_a_vs_bound_a]~^ ERROR compilation successful
LL | | //[bound_a_vs_bound_b]~^^ ERROR compilation successful
LL | | //[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
LL | | //[bound_co_a_vs_bound_co_b]~^^^^ ERROR compilation successful
LL | | //[free_x_vs_free_x]~^^^^^ ERROR compilation successful
... |
LL | | //[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR compilation successful
LL | | }
| |_^

View File

@ -1,16 +1,14 @@
error[E0308]: mismatched types
--> $DIR/hr-subtype.rs:39:26
error: compilation successful
--> $DIR/hr-subtype.rs:96:1
|
LL | gimme::<$t1>(None::<$t2>);
| ^^^^^^^^^^^ expected concrete lifetime, found bound lifetime parameter 'a
...
LL | / check! { bound_contra_a_contra_b_ret_co_a: (for<'a,'b> fn(Contra<'a>, Contra<'b>) -> Co<'a>,
LL | | for<'a> fn(Contra<'a>, Contra<'a>) -> Co<'a>) }
| |______________________________________________________________________________________________- in this macro invocation
|
= note: expected type `std::option::Option<for<'a, 'b> fn(Contra<'a>, Contra<'b>) -> Co<'a>>`
found type `std::option::Option<for<'a> fn(Contra<'a>, Contra<'a>) -> Co<'a>>`
LL | / fn main() {
LL | | //[bound_a_vs_bound_a]~^ ERROR compilation successful
LL | | //[bound_a_vs_bound_b]~^^ ERROR compilation successful
LL | | //[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
... |
LL | | //[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR compilation successful
LL | | }
| |_^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View File

@ -1,16 +1,19 @@
error[E0308]: mismatched types
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter 'a in generic type due to conflicting requirements
--> $DIR/hr-subtype.rs:39:26
|
LL | gimme::<$t1>(None::<$t2>);
| ^^^^^^^^^^^ expected concrete lifetime, found bound lifetime parameter 'a
| ^^^^^^^^^^^
...
LL | / check! { bound_inv_a_b_vs_bound_inv_a: (for<'a,'b> fn(Inv<'a>, Inv<'b>),
LL | | for<'a> fn(Inv<'a>, Inv<'a>)) }
| |__________________________________________________________________________- in this macro invocation
|
= note: expected type `std::option::Option<for<'a, 'b> fn(Inv<'a>, Inv<'b>)>`
found type `std::option::Option<for<'a> fn(Inv<'a>, Inv<'a>)>`
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:25), 'a) })...
= note: ...but the lifetime must also be valid for lifetime RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:26), 'b) })...
= note: ...so that the expression is assignable:
expected std::option::Option<for<'a, 'b> fn(Inv<'a>, Inv<'b>)>
found std::option::Option<for<'a> fn(Inv<'a>, Inv<'a>)>
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0495`.

View File

@ -1,12 +1,12 @@
error: compilation successful
--> $DIR/hr-subtype.rs:100:1
--> $DIR/hr-subtype.rs:96:1
|
LL | / fn main() {
LL | | //[bound_a_vs_bound_a]~^ ERROR compilation successful
LL | | //[bound_a_vs_bound_b]~^^ ERROR compilation successful
LL | | //[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
LL | | //[bound_co_a_vs_bound_co_b]~^^^^ ERROR compilation successful
LL | | //[free_x_vs_free_x]~^^^^^ ERROR compilation successful
... |
LL | | //[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR compilation successful
LL | | }
| |_^

View File

@ -1,12 +1,12 @@
error: compilation successful
--> $DIR/hr-subtype.rs:100:1
--> $DIR/hr-subtype.rs:96:1
|
LL | / fn main() {
LL | | //[bound_a_vs_bound_a]~^ ERROR compilation successful
LL | | //[bound_a_vs_bound_b]~^^ ERROR compilation successful
LL | | //[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
LL | | //[bound_co_a_vs_bound_co_b]~^^^^ ERROR compilation successful
LL | | //[free_x_vs_free_x]~^^^^^ ERROR compilation successful
... |
LL | | //[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR compilation successful
LL | | }
| |_^

View File

@ -31,21 +31,17 @@ macro_rules! check {
#[cfg($rev)]
fn subtype<'x,'y:'x,'z:'y>() {
gimme::<$t2>(None::<$t1>);
//[free_inv_x_vs_free_inv_y]~^ ERROR mismatched types
//[free_inv_x_vs_free_inv_y]~^ ERROR
}
#[cfg($rev)]
fn supertype<'x,'y:'x,'z:'y>() {
gimme::<$t1>(None::<$t2>);
//[bound_a_vs_free_x]~^ ERROR mismatched types
//[free_x_vs_free_y]~^^ ERROR mismatched types
//[bound_inv_a_b_vs_bound_inv_a]~^^^ ERROR mismatched types
//[bound_a_b_ret_a_vs_bound_a_ret_a]~^^^^ ERROR mismatched types
//[free_inv_x_vs_free_inv_y]~^^^^^ ERROR mismatched types
//[bound_a_b_vs_bound_a]~^^^^^^ ERROR mismatched types
//[bound_co_a_b_vs_bound_co_a]~^^^^^^^ ERROR mismatched types
//[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^ ERROR mismatched types
//[bound_co_a_co_b_ret_contra_a]~^^^^^^^^^ ERROR mismatched types
//[bound_a_vs_free_x]~^ ERROR
//[free_x_vs_free_y]~^^ ERROR
//[bound_inv_a_b_vs_bound_inv_a]~^^^ ERROR
//[bound_a_b_ret_a_vs_bound_a_ret_a]~^^^^ ERROR
//[free_inv_x_vs_free_inv_y]~^^^^^ ERROR
}
}
}
@ -103,4 +99,8 @@ fn main() {
//[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
//[bound_co_a_vs_bound_co_b]~^^^^ ERROR compilation successful
//[free_x_vs_free_x]~^^^^^ ERROR compilation successful
//[bound_a_b_vs_bound_a]~^^^^^^ ERROR compilation successful
//[bound_co_a_co_b_ret_contra_a]~^^^^^^^ ERROR compilation successful
//[bound_co_a_b_vs_bound_co_a]~^^^^^^^^ ERROR compilation successful
//[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^^ ERROR compilation successful
}

View File

@ -1,11 +1,16 @@
// Test that we give a note when the old LUB/GLB algorithm would have
// succeeded but the new code (which is stricter) gives an error.
// succeeded but the new code (which requires equality) gives an
// error. However, now that we handle subtyping correctly, we no
// longer get an error, because we recognize these two types as
// equivalent!
//
// compile-pass
fn foo(
x: fn(&u8, &u8),
y: for<'a> fn(&'a u8, &'a u8),
) {
let z = match 22 { //~ ERROR incompatible types
let z = match 22 {
0 => x,
_ => y,
};

View File

@ -1,17 +0,0 @@
error[E0308]: match arms have incompatible types
--> $DIR/old-lub-glb-hr.rs:8:13
|
LL | let z = match 22 { //~ ERROR incompatible types
| _____________^
LL | | 0 => x,
LL | | _ => y,
| | - match arm with an incompatible type
LL | | };
| |_____^ expected bound lifetime parameter, found concrete lifetime
|
= note: expected type `for<'r, 's> fn(&'r u8, &'s u8)`
found type `for<'a> fn(&'a u8, &'a u8)`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View File

@ -37,8 +37,7 @@ fn baz(x: &S) -> &S {
fn supply_F() {
want_F(foo);
// FIXME(#33684) -- this should be a subtype, but current alg. rejects it incorrectly
want_F(bar); //~ ERROR E0308
want_F(bar);
want_F(baz);
}
@ -46,11 +45,7 @@ fn supply_F() {
fn supply_G() {
want_G(foo);
want_G(bar);
want_G(baz);
//~^ ERROR mismatched types
//~| expected type `for<'cx> fn(&'cx S) -> &'static S`
//~| found type `for<'r> fn(&'r S) -> &'r S {baz}`
//~| expected concrete lifetime, found bound lifetime parameter 'cx
want_G(baz); //~ ERROR
}
pub fn main() {

View File

@ -1,21 +1,15 @@
error[E0308]: mismatched types
--> $DIR/regions-fn-subtyping-return-static-fail.rs:41:12
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in generic type due to conflicting requirements
--> $DIR/regions-fn-subtyping-return-static-fail.rs:48:12
|
LL | want_F(bar); //~ ERROR E0308
| ^^^ expected concrete lifetime, found bound lifetime parameter 'cx
LL | want_G(baz); //~ ERROR
| ^^^
|
= note: expected type `for<'cx> fn(&'cx S) -> &'cx S`
found type `for<'a> fn(&'a S) -> &S {bar::<'_>}`
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U3, name: BrNamed(crate0:DefIndex(1:11), 'cx) })...
= note: ...but the lifetime must also be valid for the static lifetime...
= note: ...so that the expression is assignable:
expected for<'cx> fn(&'cx S) -> &'static S
found for<'r> fn(&'r S) -> &'r S
error[E0308]: mismatched types
--> $DIR/regions-fn-subtyping-return-static-fail.rs:49:12
|
LL | want_G(baz);
| ^^^ expected concrete lifetime, found bound lifetime parameter 'cx
|
= note: expected type `for<'cx> fn(&'cx S) -> &'static S`
found type `for<'r> fn(&'r S) -> &'r S {baz}`
error: aborting due to previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0495`.

View File

@ -5,6 +5,8 @@
// *ANY* lifetime and returns a reference with the 'static lifetime.
// This can safely be considered to be an instance of `F` because all
// lifetimes are sublifetimes of 'static.
//
// compile-pass
#![allow(dead_code)]
#![allow(unused_variables)]
@ -37,8 +39,7 @@ fn baz(x: &S) -> &S {
fn supply_F() {
want_F(foo);
// FIXME(#33684) -- this should be a subtype, but current alg. rejects it incorrectly
want_F(bar); //~ ERROR E0308
want_F(bar);
want_F(baz);
}

View File

@ -1,12 +1,26 @@
error[E0308]: mismatched types
--> $DIR/regions-fn-subtyping-return-static.rs:41:12
warning: function `want_F` should have a snake case name such as `want_f`
--> $DIR/regions-fn-subtyping-return-static.rs:18:1
|
LL | want_F(bar); //~ ERROR E0308
| ^^^ expected concrete lifetime, found bound lifetime parameter 'cx
LL | fn want_F(f: F) { }
| ^^^^^^^^^^^^^^^^^^^
|
= note: expected type `for<'cx> fn(&'cx S) -> &'cx S`
found type `for<'a> fn(&'a S) -> &S {bar::<'_>}`
= note: #[warn(non_snake_case)] on by default
error: aborting due to previous error
warning: function `want_G` should have a snake case name such as `want_g`
--> $DIR/regions-fn-subtyping-return-static.rs:22:1
|
LL | fn want_G(f: G) { }
| ^^^^^^^^^^^^^^^^^^^
warning: function `supply_F` should have a snake case name such as `supply_f`
--> $DIR/regions-fn-subtyping-return-static.rs:39:1
|
LL | / fn supply_F() {
LL | | want_F(foo);
LL | |
LL | | want_F(bar);
LL | |
LL | | want_F(baz);
LL | | }
| |_^
For more information about this error, try `rustc --explain E0308`.