about summary refs log tree commit diff
path: root/src/test/ui/function-pointer
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-06 17:48:33 +0000
committerbors <bors@rust-lang.org>2022-11-06 17:48:33 +0000
commit7eef946fc0e0eff40e588eab77b09b287accbec3 (patch)
tree3c9fa64a5180e9c7e8ac7950c96ff3e32b169b94 /src/test/ui/function-pointer
parent1e1e5b8d98750a162335f64ec3c792ce80c9866c (diff)
parentff8f84ccf6b208e41713da911333f20676472a48 (diff)
downloadrust-7eef946fc0e0eff40e588eab77b09b287accbec3.tar.gz
rust-7eef946fc0e0eff40e588eab77b09b287accbec3.zip
Auto merge of #99943 - compiler-errors:tuple-trait, r=jackh726
Implement `std::marker::Tuple`, use it in `extern "rust-call"` and `Fn`-family traits

Implements rust-lang/compiler-team#537

I made a few opinionated decisions in this implementation, specifically:
1. Enforcing `extern "rust-call"` on fn items during wfcheck,
2. Enforcing this for all functions (not just ones that have bodies),
3. Gating this `Tuple` marker trait behind its own feature, instead of grouping it into (e.g.) `unboxed_closures`.

Still needing to be done:
1. Enforce that `extern "rust-call"` `fn`-ptrs are well-formed only if they have 1/2 args and the second one implements `Tuple`. (Doing this would fix ICE in #66696.)
2. Deny all explicit/user `impl`s of the `Tuple` trait, kinda like `Sized`.
3. Fixing `Tuple` trait built-in impl for chalk, so that chalkification tests are un-broken.

Open questions:
1. Does this need t-lang or t-libs signoff?

Fixes #99820
Diffstat (limited to 'src/test/ui/function-pointer')
-rw-r--r--src/test/ui/function-pointer/unsized-ret.rs3
-rw-r--r--src/test/ui/function-pointer/unsized-ret.stderr12
2 files changed, 8 insertions, 7 deletions
diff --git a/src/test/ui/function-pointer/unsized-ret.rs b/src/test/ui/function-pointer/unsized-ret.rs
index 60af5769d6d..79009c5cb6c 100644
--- a/src/test/ui/function-pointer/unsized-ret.rs
+++ b/src/test/ui/function-pointer/unsized-ret.rs
@@ -1,7 +1,8 @@
 #![feature(fn_traits)]
 #![feature(unboxed_closures)]
+#![feature(tuple_trait)]
 
-fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
+fn foo<F: Fn<T>, T:std::marker::Tuple>(f: Option<F>, t: T) {
     let y = (f.unwrap()).call(t);
 }
 
diff --git a/src/test/ui/function-pointer/unsized-ret.stderr b/src/test/ui/function-pointer/unsized-ret.stderr
index bec3e2aa3fe..40bf7a3898a 100644
--- a/src/test/ui/function-pointer/unsized-ret.stderr
+++ b/src/test/ui/function-pointer/unsized-ret.stderr
@@ -1,5 +1,5 @@
 error[E0277]: the size for values of type `str` cannot be known at compilation time
-  --> $DIR/unsized-ret.rs:9:27
+  --> $DIR/unsized-ret.rs:10:27
    |
 LL |     foo::<fn() -> str, _>(None, ());
    |     --------------------- ^^^^ doesn't have a size known at compile-time
@@ -9,13 +9,13 @@ LL |     foo::<fn() -> str, _>(None, ());
    = 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
+  --> $DIR/unsized-ret.rs:5:11
    |
-LL | fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
+LL | fn foo<F: Fn<T>, T:std::marker::Tuple>(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
+  --> $DIR/unsized-ret.rs:13:66
    |
 LL |     foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&(),));
    |     ------------------------------------------------------------ ^^^^ doesn't have a size known at compile-time
@@ -25,9 +25,9 @@ LL |     foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&()
    = 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
+  --> $DIR/unsized-ret.rs:5:11
    |
-LL | fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
+LL | fn foo<F: Fn<T>, T:std::marker::Tuple>(f: Option<F>, t: T) {
    |           ^^^^^ required by this bound in `foo`
 
 error: aborting due to 2 previous errors