-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fn pointers don't implement Fn/FnMut/FnOnce traits if its return type…
… is unsized
- Loading branch information
1 parent
98e1f04
commit 3b573c9
Showing
5 changed files
with
96 additions
and
2 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 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 @@ | ||
// check-pass | ||
|
||
#![feature(unboxed_closures)] | ||
|
||
fn is_fn<T: for<'a> Fn<(&'a (),)>>() {} | ||
fn is_fn2<T: for<'a, 'b> Fn<(&'a &'b (),)>>() {} | ||
|
||
struct Outlives<'a, 'b>(std::marker::PhantomData<&'a &'b ()>); | ||
|
||
fn main() { | ||
is_fn::<for<'a> fn(&'a ()) -> &'a ()>(); | ||
is_fn::<for<'a> fn(&'a ()) -> &'a dyn std::fmt::Debug>(); | ||
is_fn2::<for<'a, 'b> fn(&'a &'b ()) -> Outlives<'a, 'b>>(); | ||
is_fn2::<for<'a, 'b> fn(&'a &'b ()) -> (&'a (), &'a ())>(); | ||
} |
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 @@ | ||
#![feature(fn_traits)] | ||
#![feature(unboxed_closures)] | ||
|
||
fn foo<F: Fn<T>, T>(f: Option<F>, t: T) { | ||
let y = (f.unwrap()).call(t); | ||
} | ||
|
||
fn main() { | ||
foo::<fn() -> str, _>(None, ()); | ||
//~^ ERROR the size for values of type `str` cannot be known at compilation time | ||
|
||
foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&(),)); | ||
//~^ ERROR the size for values of type `(dyn std::fmt::Display + 'a)` cannot be known at compilation time | ||
} |
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,35 @@ | ||
error[E0277]: the size for values of type `str` cannot be known at compilation time | ||
--> $DIR/unsized-ret.rs:9:27 | ||
| | ||
LL | foo::<fn() -> str, _>(None, ()); | ||
| --------------------- ^^^^ doesn't have a size known at compile-time | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: within `fn() -> str`, the trait `Sized` is not implemented for `str` | ||
= note: required because it appears within the type `fn() -> str` | ||
note: required by a bound in `foo` | ||
--> $DIR/unsized-ret.rs:4:11 | ||
| | ||
LL | fn foo<F: Fn<T>, T>(f: Option<F>, t: T) { | ||
| ^^^^^ required by this bound in `foo` | ||
|
||
error[E0277]: the size for values of type `(dyn std::fmt::Display + 'a)` cannot be known at compilation time | ||
--> $DIR/unsized-ret.rs:12:66 | ||
| | ||
LL | foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&(),)); | ||
| ------------------------------------------------------------ ^^^^ doesn't have a size known at compile-time | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: within `for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a)`, the trait `for<'a> Sized` is not implemented for `(dyn std::fmt::Display + 'a)` | ||
= note: required because it appears within the type `for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a)` | ||
note: required by a bound in `foo` | ||
--> $DIR/unsized-ret.rs:4:11 | ||
| | ||
LL | fn foo<F: Fn<T>, T>(f: Option<F>, t: T) { | ||
| ^^^^^ required by this bound in `foo` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
3 changes: 2 additions & 1 deletion
3
src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr
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