-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
136 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Regression test for #84533. | ||
|
||
use std::marker::PhantomData; | ||
|
||
fn foo<'b, 'a>() -> PhantomData<&'b &'a ()> { | ||
PhantomData | ||
} | ||
|
||
fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T { | ||
let f = foo::<'b, 'a>; | ||
//~^ ERROR lifetime may not live long enough | ||
f.baz(x) | ||
} | ||
|
||
trait Foo<'a, 'b, T: ?Sized> { | ||
fn baz(self, s: &'a T) -> &'b T; | ||
} | ||
impl<'a, 'b, R, F, T: ?Sized> Foo<'a, 'b, T> for F | ||
where | ||
F: Fn() -> R, | ||
R: ProofForConversion<'a, 'b, T>, | ||
{ | ||
fn baz(self, s: &'a T) -> &'b T { | ||
self().convert(s) | ||
} | ||
} | ||
|
||
trait ProofForConversion<'a, 'b, T: ?Sized> { | ||
fn convert(self, s: &'a T) -> &'b T; | ||
} | ||
impl<'a, 'b, T: ?Sized> ProofForConversion<'a, 'b, T> for PhantomData<&'b &'a ()> { | ||
fn convert(self, s: &'a T) -> &'b T { | ||
s | ||
} | ||
} | ||
|
||
fn main() { | ||
let d; | ||
{ | ||
let x = "Hello World".to_string(); | ||
d = extend_lifetime(&x); | ||
} | ||
println!("{}", d); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/wf-fn-def-check-sig-1.rs:10:13 | ||
| | ||
LL | fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T { | ||
| -- -- lifetime `'b` defined here | ||
| | | ||
| lifetime `'a` defined here | ||
LL | let f = foo::<'b, 'a>; | ||
| ^^^^^^^^^^^^^ requires that `'a` must outlive `'b` | ||
| | ||
= help: consider adding the following bound: `'a: 'b` | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Regression test for #84533 involving higher-ranked regions | ||
// in the return type. | ||
use std::marker::PhantomData; | ||
|
||
fn foo<'c, 'b, 'a>(_: &'c ()) -> (&'c (), PhantomData<&'b &'a ()>) { | ||
(&(), PhantomData) | ||
} | ||
|
||
fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T { | ||
let f = foo; | ||
f.baz(x) | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
|
||
trait Foo<'a, 'b, T: ?Sized> { | ||
fn baz(self, s: &'a T) -> &'b T; | ||
} | ||
impl<'a, 'b, R, F, T: ?Sized> Foo<'a, 'b, T> for F | ||
where | ||
F: for<'c> Fn(&'c ()) -> (&'c (), R), | ||
R: ProofForConversion<'a, 'b, T>, | ||
{ | ||
fn baz(self, s: &'a T) -> &'b T { | ||
self(&()).1.convert(s) | ||
} | ||
} | ||
|
||
trait ProofForConversion<'a, 'b, T: ?Sized> { | ||
fn convert(self, s: &'a T) -> &'b T; | ||
} | ||
impl<'a, 'b, T: ?Sized> ProofForConversion<'a, 'b, T> for PhantomData<&'b &'a ()> { | ||
fn convert(self, s: &'a T) -> &'b T { | ||
s | ||
} | ||
} | ||
|
||
fn main() { | ||
let d; | ||
{ | ||
let x = "Hello World".to_string(); | ||
d = extend_lifetime(&x); | ||
} | ||
println!("{}", d); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/wf-fn-def-check-sig-2.rs:11:5 | ||
| | ||
LL | fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T { | ||
| -- -- lifetime `'b` defined here | ||
| | | ||
| lifetime `'a` defined here | ||
LL | let f = foo; | ||
LL | f.baz(x) | ||
| ^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` | ||
| | ||
= help: consider adding the following bound: `'a: 'b` | ||
|
||
error: aborting due to previous error | ||
|