Use revisions for NLL in traits

This commit is contained in:
Jack Huey 2022-05-22 00:26:21 -04:00
parent 34a3154bd9
commit b16bd7c3e2
6 changed files with 110 additions and 26 deletions

View File

@ -1,5 +1,5 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/type-checking-test-3.rs:13:13 --> $DIR/type-checking-test-3.rs:16:13
| |
LL | let _ = x as &dyn Bar<'a>; // Error LL | let _ = x as &dyn Bar<'a>; // Error
| ^ lifetime mismatch | ^ lifetime mismatch
@ -7,14 +7,14 @@ LL | let _ = x as &dyn Bar<'a>; // Error
= note: expected trait object `dyn Bar<'a>` = note: expected trait object `dyn Bar<'a>`
found trait object `dyn Bar<'static>` found trait object `dyn Bar<'static>`
note: the lifetime `'a` as defined here... note: the lifetime `'a` as defined here...
--> $DIR/type-checking-test-3.rs:12:16 --> $DIR/type-checking-test-3.rs:15:16
| |
LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) { LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
| ^^ | ^^
= note: ...does not necessarily outlive the static lifetime = note: ...does not necessarily outlive the static lifetime
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/type-checking-test-3.rs:18:13 --> $DIR/type-checking-test-3.rs:22:13
| |
LL | let _ = x as &dyn Bar<'static>; // Error LL | let _ = x as &dyn Bar<'static>; // Error
| ^ lifetime mismatch | ^ lifetime mismatch
@ -22,7 +22,7 @@ LL | let _ = x as &dyn Bar<'static>; // Error
= note: expected trait object `dyn Bar<'static>` = note: expected trait object `dyn Bar<'static>`
found trait object `dyn Bar<'a>` found trait object `dyn Bar<'a>`
note: the lifetime `'a` as defined here... note: the lifetime `'a` as defined here...
--> $DIR/type-checking-test-3.rs:17:16 --> $DIR/type-checking-test-3.rs:21:16
| |
LL | fn test_wrong2<'a>(x: &dyn Foo<'a>) { LL | fn test_wrong2<'a>(x: &dyn Foo<'a>) {
| ^^ | ^^

View File

@ -0,0 +1,18 @@
error: lifetime may not live long enough
--> $DIR/type-checking-test-3.rs:16:13
|
LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
| -- lifetime `'a` defined here
LL | let _ = x as &dyn Bar<'a>; // Error
| ^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
error: lifetime may not live long enough
--> $DIR/type-checking-test-3.rs:22:13
|
LL | fn test_wrong2<'a>(x: &dyn Foo<'a>) {
| -- lifetime `'a` defined here
LL | let _ = x as &dyn Bar<'static>; // Error
| ^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
error: aborting due to 2 previous errors

View File

@ -1,4 +1,7 @@
// revisions: base nll
// ignore-compare-mode-nll // ignore-compare-mode-nll
//[nll] compile-flags: -Z borrowck=mir
#![feature(trait_upcasting)] #![feature(trait_upcasting)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
@ -11,12 +14,14 @@ fn test_correct(x: &dyn Foo<'static>) {
fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) { fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
let _ = x as &dyn Bar<'a>; // Error let _ = x as &dyn Bar<'a>; // Error
//~^ ERROR mismatched types //[base]~^ ERROR mismatched types
//[nll]~^^ ERROR lifetime may not live long enough
} }
fn test_wrong2<'a>(x: &dyn Foo<'a>) { fn test_wrong2<'a>(x: &dyn Foo<'a>) {
let _ = x as &dyn Bar<'static>; // Error let _ = x as &dyn Bar<'static>; // Error
//~^ ERROR mismatched types //[base]~^ ERROR mismatched types
//[nll]~^^ ERROR lifetime may not live long enough
} }
fn main() {} fn main() {}

View File

@ -1,5 +1,5 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/type-checking-test-4.rs:17:13 --> $DIR/type-checking-test-4.rs:20:13
| |
LL | let _ = x as &dyn Bar<'static, 'a>; // Error LL | let _ = x as &dyn Bar<'static, 'a>; // Error
| ^ lifetime mismatch | ^ lifetime mismatch
@ -7,14 +7,14 @@ LL | let _ = x as &dyn Bar<'static, 'a>; // Error
= note: expected trait object `dyn Bar<'static, 'a>` = note: expected trait object `dyn Bar<'static, 'a>`
found trait object `dyn Bar<'static, 'static>` found trait object `dyn Bar<'static, 'static>`
note: the lifetime `'a` as defined here... note: the lifetime `'a` as defined here...
--> $DIR/type-checking-test-4.rs:16:16 --> $DIR/type-checking-test-4.rs:19:16
| |
LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) { LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
| ^^ | ^^
= note: ...does not necessarily outlive the static lifetime = note: ...does not necessarily outlive the static lifetime
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/type-checking-test-4.rs:22:13 --> $DIR/type-checking-test-4.rs:26:13
| |
LL | let _ = x as &dyn Bar<'a, 'static>; // Error LL | let _ = x as &dyn Bar<'a, 'static>; // Error
| ^ lifetime mismatch | ^ lifetime mismatch
@ -22,14 +22,14 @@ LL | let _ = x as &dyn Bar<'a, 'static>; // Error
= note: expected trait object `dyn Bar<'a, 'static>` = note: expected trait object `dyn Bar<'a, 'static>`
found trait object `dyn Bar<'static, 'static>` found trait object `dyn Bar<'static, 'static>`
note: the lifetime `'a` as defined here... note: the lifetime `'a` as defined here...
--> $DIR/type-checking-test-4.rs:21:16 --> $DIR/type-checking-test-4.rs:25:16
| |
LL | fn test_wrong2<'a>(x: &dyn Foo<'static>, y: &'a u32) { LL | fn test_wrong2<'a>(x: &dyn Foo<'static>, y: &'a u32) {
| ^^ | ^^
= note: ...does not necessarily outlive the static lifetime = note: ...does not necessarily outlive the static lifetime
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/type-checking-test-4.rs:27:27 --> $DIR/type-checking-test-4.rs:32:27
| |
LL | fn test_wrong3<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { LL | fn test_wrong3<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| ------------ this data with lifetime `'a`... | ------------ this data with lifetime `'a`...
@ -42,12 +42,12 @@ LL | y.get_b() // ERROR
| - ...is used here... | - ...is used here...
| |
note: ...and is required to live as long as `'static` here note: ...and is required to live as long as `'static` here
--> $DIR/type-checking-test-4.rs:29:5 --> $DIR/type-checking-test-4.rs:34:5
| |
LL | y.get_b() // ERROR LL | y.get_b() // ERROR
| ^^^^^^^^^ | ^^^^^^^^^
note: `'static` lifetime requirement introduced by the return type note: `'static` lifetime requirement introduced by the return type
--> $DIR/type-checking-test-4.rs:26:48 --> $DIR/type-checking-test-4.rs:31:48
| |
LL | fn test_wrong3<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { LL | fn test_wrong3<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| ^^^^^^^ `'static` requirement introduced here | ^^^^^^^ `'static` requirement introduced here
@ -56,7 +56,7 @@ LL | y.get_b() // ERROR
| --------- because of this returned expression | --------- because of this returned expression
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/type-checking-test-4.rs:33:5 --> $DIR/type-checking-test-4.rs:39:5
| |
LL | fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { LL | fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| ------------ this data with lifetime `'a`... | ------------ this data with lifetime `'a`...
@ -64,7 +64,7 @@ LL | <_ as Bar>::get_b(x) // ERROR
| ^^^^^^^^^^^^^^^^^ ...is used and required to live as long as `'static` here | ^^^^^^^^^^^^^^^^^ ...is used and required to live as long as `'static` here
| |
note: `'static` lifetime requirement introduced by the return type note: `'static` lifetime requirement introduced by the return type
--> $DIR/type-checking-test-4.rs:32:48 --> $DIR/type-checking-test-4.rs:38:48
| |
LL | fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { LL | fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| ^^^^^^^ `'static` requirement introduced here | ^^^^^^^ `'static` requirement introduced here
@ -72,7 +72,7 @@ LL | <_ as Bar>::get_b(x) // ERROR
| -------------------- because of this returned expression | -------------------- because of this returned expression
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/type-checking-test-4.rs:38:15 --> $DIR/type-checking-test-4.rs:45:15
| |
LL | fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { LL | fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| ------------ this data with lifetime `'a`... | ------------ this data with lifetime `'a`...
@ -80,7 +80,7 @@ LL | <_ as Bar<'_, '_>>::get_b(x) // ERROR
| ----------^^------------- ...is used and required to live as long as `'static` here | ----------^^------------- ...is used and required to live as long as `'static` here
| |
note: `'static` lifetime requirement introduced by the return type note: `'static` lifetime requirement introduced by the return type
--> $DIR/type-checking-test-4.rs:37:48 --> $DIR/type-checking-test-4.rs:44:48
| |
LL | fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { LL | fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| ^^^^^^^ `'static` requirement introduced here | ^^^^^^^ `'static` requirement introduced here
@ -88,7 +88,7 @@ LL | <_ as Bar<'_, '_>>::get_b(x) // ERROR
| ---------------------------- because of this returned expression | ---------------------------- because of this returned expression
error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/type-checking-test-4.rs:43:27 --> $DIR/type-checking-test-4.rs:51:27
| |
LL | fn test_wrong6<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { LL | fn test_wrong6<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| ------------ this data with lifetime `'a`... | ------------ this data with lifetime `'a`...
@ -104,12 +104,12 @@ LL | z.get_b() // ERROR
| - ...is used here... | - ...is used here...
| |
note: ...and is required to live as long as `'static` here note: ...and is required to live as long as `'static` here
--> $DIR/type-checking-test-4.rs:47:5 --> $DIR/type-checking-test-4.rs:55:5
| |
LL | z.get_b() // ERROR LL | z.get_b() // ERROR
| ^^^^^^^^^ | ^^^^^^^^^
note: `'static` lifetime requirement introduced by the return type note: `'static` lifetime requirement introduced by the return type
--> $DIR/type-checking-test-4.rs:42:48 --> $DIR/type-checking-test-4.rs:50:48
| |
LL | fn test_wrong6<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { LL | fn test_wrong6<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| ^^^^^^^ `'static` requirement introduced here | ^^^^^^^ `'static` requirement introduced here

View File

@ -0,0 +1,52 @@
error: lifetime may not live long enough
--> $DIR/type-checking-test-4.rs:20:13
|
LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
| -- lifetime `'a` defined here
LL | let _ = x as &dyn Bar<'static, 'a>; // Error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
error: lifetime may not live long enough
--> $DIR/type-checking-test-4.rs:26:13
|
LL | fn test_wrong2<'a>(x: &dyn Foo<'static>, y: &'a u32) {
| -- lifetime `'a` defined here
LL | let _ = x as &dyn Bar<'a, 'static>; // Error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
error: lifetime may not live long enough
--> $DIR/type-checking-test-4.rs:34:5
|
LL | fn test_wrong3<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| -- lifetime `'a` defined here
...
LL | y.get_b() // ERROR
| ^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
error: lifetime may not live long enough
--> $DIR/type-checking-test-4.rs:39:5
|
LL | fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| -- lifetime `'a` defined here
LL | <_ as Bar>::get_b(x) // ERROR
| ^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
error: lifetime may not live long enough
--> $DIR/type-checking-test-4.rs:45:5
|
LL | fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| -- lifetime `'a` defined here
LL | <_ as Bar<'_, '_>>::get_b(x) // ERROR
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
error: lifetime may not live long enough
--> $DIR/type-checking-test-4.rs:55:5
|
LL | fn test_wrong6<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
| -- lifetime `'a` defined here
...
LL | z.get_b() // ERROR
| ^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
error: aborting due to 6 previous errors

View File

@ -1,4 +1,7 @@
// revisions: base nll
// ignore-compare-mode-nll // ignore-compare-mode-nll
//[nll] compile-flags: -Z borrowck=mir
#![feature(trait_upcasting)] #![feature(trait_upcasting)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
@ -15,36 +18,42 @@ fn test_correct(x: &dyn Foo<'static>) {
fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) { fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
let _ = x as &dyn Bar<'static, 'a>; // Error let _ = x as &dyn Bar<'static, 'a>; // Error
//~^ ERROR mismatched types //[base]~^ ERROR mismatched types
//[nll]~^^ ERROR lifetime may not live long enough
} }
fn test_wrong2<'a>(x: &dyn Foo<'static>, y: &'a u32) { fn test_wrong2<'a>(x: &dyn Foo<'static>, y: &'a u32) {
let _ = x as &dyn Bar<'a, 'static>; // Error let _ = x as &dyn Bar<'a, 'static>; // Error
//~^ ERROR mismatched types //[base]~^ ERROR mismatched types
//[nll]~^^ ERROR lifetime may not live long enough
} }
fn test_wrong3<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { fn test_wrong3<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
let y = x as &dyn Bar<'_, '_>; let y = x as &dyn Bar<'_, '_>;
//~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement //[base]~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
y.get_b() // ERROR y.get_b() // ERROR
//[nll]~^ ERROR lifetime may not live long enough
} }
fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
<_ as Bar>::get_b(x) // ERROR <_ as Bar>::get_b(x) // ERROR
//~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement //[base]~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
//[nll]~^^ ERROR lifetime may not live long enough
} }
fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
<_ as Bar<'_, '_>>::get_b(x) // ERROR <_ as Bar<'_, '_>>::get_b(x) // ERROR
//~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement //[base]~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
//[nll]~^^ ERROR lifetime may not live long enough
} }
fn test_wrong6<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> { fn test_wrong6<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
let y = x as &dyn Bar<'_, '_>; let y = x as &dyn Bar<'_, '_>;
//~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement //[base]~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
y.get_b(); // ERROR y.get_b(); // ERROR
let z = y; let z = y;
z.get_b() // ERROR z.get_b() // ERROR
//[nll]~^ ERROR lifetime may not live long enough
} }
fn main() {} fn main() {}