-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Check WF of source type's signature on fn pointer cast #129021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ check-pass | ||
//@ known-bug: #25860 | ||
|
||
static UNIT: &'static &'static () = &&(); | ||
|
||
fn foo<'a, 'b, T>(_: &'a &'b (), v: &'b T, _: &()) -> &'a T { v } | ||
|
||
fn bad<'a, T>(x: &'a T) -> &'static T { | ||
let f: fn(_, &'a T, &()) -> &'static T = foo; | ||
f(UNIT, x, &()) | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Regression test for #129021. | ||
|
||
static UNIT: &'static &'static () = &&(); | ||
|
||
fn foo<'a: 'a, 'b: 'b, T>(_: &'a &'b (), v: &'b T) -> &'a T { v } | ||
|
||
fn bad<'a, T>(x: &'a T) -> &'static T { | ||
let f: fn(_, &'a T) -> &'static T = foo; | ||
//~^ ERROR lifetime may not live long enough | ||
f(UNIT, x) | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/implied-bounds-on-nested-references-plus-variance-early-bound.rs:8:12 | ||
| | ||
LL | fn bad<'a, T>(x: &'a T) -> &'static T { | ||
| -- lifetime `'a` defined here | ||
LL | let f: fn(_, &'a T) -> &'static T = foo; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` | ||
|
||
error: aborting due to 1 previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Regression test for #129021. | ||
|
||
trait ToArg<T> { | ||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type Arg; | ||
} | ||
impl<T, U> ToArg<T> for U { | ||
type Arg = T; | ||
} | ||
|
||
fn extend_inner<'a, 'b>(x: &'a str) -> <&'b &'a () as ToArg<&'b str>>::Arg { x } | ||
fn extend<'a, 'b>(x: &'a str) -> &'b str { | ||
(extend_inner as fn(_) -> _)(x) | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
|
||
fn main() { | ||
let y = extend(&String::from("Hello World")); | ||
println!("{}", y); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/implied-bounds-on-nested-references-plus-variance-unnormalized.rs:12:5 | ||
| | ||
LL | fn extend<'a, 'b>(x: &'a str) -> &'b str { | ||
| -- -- lifetime `'b` defined here | ||
| | | ||
| lifetime `'a` defined here | ||
LL | (extend_inner as fn(_) -> _)(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 1 previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
//@ check-pass | ||
//@ known-bug: #25860 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I should probably rewrite this test to continue being a known-bug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just make it higher-ranked in one more arg or sth... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, and also add "regression test for X" |
||
// Should fail. The combination of variance and implied bounds for nested | ||
// references allows us to infer a longer lifetime than we can prove. | ||
// Regression test for #129021. | ||
|
||
static UNIT: &'static &'static () = &&(); | ||
|
||
fn foo<'a, 'b, T>(_: &'a &'b (), v: &'b T) -> &'a T { v } | ||
|
||
fn bad<'a, T>(x: &'a T) -> &'static T { | ||
let f: fn(_, &'a T) -> &'static T = foo; | ||
//~^ ERROR lifetime may not live long enough | ||
f(UNIT, x) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/implied-bounds-on-nested-references-plus-variance.rs:8:12 | ||
| | ||
LL | fn bad<'a, T>(x: &'a T) -> &'static T { | ||
| -- lifetime `'a` defined here | ||
LL | let f: fn(_, &'a T) -> &'static T = foo; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` | ||
|
||
error: aborting due to 1 previous error | ||
|
Uh oh!
There was an error while loading. Please reload this page.