summaryrefslogtreecommitdiffstats
path: root/tests/ui/function-pointer
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/function-pointer
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/function-pointer')
-rw-r--r--tests/ui/function-pointer/function-pointer-comparison-issue-54685.rs30
-rw-r--r--tests/ui/function-pointer/issue-102289.rs54
-rw-r--r--tests/ui/function-pointer/sized-ret-with-binder.rs15
-rw-r--r--tests/ui/function-pointer/unsized-ret.rs15
-rw-r--r--tests/ui/function-pointer/unsized-ret.stderr35
5 files changed, 149 insertions, 0 deletions
diff --git a/tests/ui/function-pointer/function-pointer-comparison-issue-54685.rs b/tests/ui/function-pointer/function-pointer-comparison-issue-54685.rs
new file mode 100644
index 000000000..855749c14
--- /dev/null
+++ b/tests/ui/function-pointer/function-pointer-comparison-issue-54685.rs
@@ -0,0 +1,30 @@
+// compile-flags: -C opt-level=3
+// run-pass
+
+fn foo(_i: i32) -> i32 {
+ 1
+}
+fn bar(_i: i32) -> i32 {
+ 1
+}
+
+fn main() {
+ let x: fn(i32) -> i32 = foo;
+ let y: fn(i32) -> i32 = bar;
+
+ let s1;
+ if x == y {
+ s1 = "same".to_string();
+ } else {
+ s1 = format!("{:?}, {:?}", x, y);
+ }
+
+ let s2;
+ if x == y {
+ s2 = "same".to_string();
+ } else {
+ s2 = format!("{:?}, {:?}", x, y);
+ }
+
+ assert_eq!(s1, s2);
+}
diff --git a/tests/ui/function-pointer/issue-102289.rs b/tests/ui/function-pointer/issue-102289.rs
new file mode 100644
index 000000000..de394ca9a
--- /dev/null
+++ b/tests/ui/function-pointer/issue-102289.rs
@@ -0,0 +1,54 @@
+// check-pass
+
+pub(crate) trait Parser: Sized {
+ type Output;
+ fn parse(&mut self, _input: &str) -> Result<(), ()> {
+ loop {}
+ }
+ fn map<F, B>(self, _f: F) -> Map<Self, F>
+ where
+ F: FnMut(Self::Output) -> B,
+ {
+ todo!()
+ }
+}
+
+pub(crate) struct Chainl1<P, Op>(P, Op);
+impl<P, Op> Parser for Chainl1<P, Op>
+where
+ P: Parser,
+ Op: Parser,
+ Op::Output: FnOnce(P::Output, P::Output) -> P::Output,
+{
+ type Output = P::Output;
+}
+pub(crate) fn chainl1<P, Op>(_parser: P, _op: Op) -> Chainl1<P, Op>
+where
+ P: Parser,
+ Op: Parser,
+ Op::Output: FnOnce(P::Output, P::Output) -> P::Output,
+{
+ loop {}
+}
+
+pub(crate) struct Map<P, F>(P, F);
+impl<A, B, P, F> Parser for Map<P, F>
+where
+ P: Parser<Output = A>,
+ F: FnMut(A) -> B,
+{
+ type Output = B;
+}
+
+impl Parser for u32 {
+ type Output = ();
+}
+
+pub fn chainl1_error_consume() {
+ fn first<T, U>(t: T, _: U) -> T {
+ t
+ }
+ let _ = chainl1(1, 1.map(|_| first)).parse("");
+}
+
+fn main() {}
diff --git a/tests/ui/function-pointer/sized-ret-with-binder.rs b/tests/ui/function-pointer/sized-ret-with-binder.rs
new file mode 100644
index 000000000..104ac4d22
--- /dev/null
+++ b/tests/ui/function-pointer/sized-ret-with-binder.rs
@@ -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 ())>();
+}
diff --git a/tests/ui/function-pointer/unsized-ret.rs b/tests/ui/function-pointer/unsized-ret.rs
new file mode 100644
index 000000000..79009c5cb
--- /dev/null
+++ b/tests/ui/function-pointer/unsized-ret.rs
@@ -0,0 +1,15 @@
+#![feature(fn_traits)]
+#![feature(unboxed_closures)]
+#![feature(tuple_trait)]
+
+fn foo<F: Fn<T>, T:std::marker::Tuple>(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
+}
diff --git a/tests/ui/function-pointer/unsized-ret.stderr b/tests/ui/function-pointer/unsized-ret.stderr
new file mode 100644
index 000000000..6f430687e
--- /dev/null
+++ b/tests/ui/function-pointer/unsized-ret.stderr
@@ -0,0 +1,35 @@
+error[E0277]: the size for values of type `str` cannot be known at compilation time
+ --> $DIR/unsized-ret.rs:10: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:5:11
+ |
+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:13: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 Display + 'a)`
+note: required by a bound in `foo`
+ --> $DIR/unsized-ret.rs:5:11
+ |
+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
+
+For more information about this error, try `rustc --explain E0277`.