about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/test/ui/consts/issue-52432.rs10
-rw-r--r--src/test/ui/consts/issue-52432.stderr28
-rw-r--r--src/test/ui/issues/issue-40231-1.rs54
-rw-r--r--src/test/ui/issues/issue-40231-2.rs54
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-63279.rs9
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-63279.stderr13
-rw-r--r--src/test/ui/unboxed-closures/issue-30904.rs36
-rw-r--r--src/test/ui/unboxed-closures/issue-30904.stderr24
8 files changed, 228 insertions, 0 deletions
diff --git a/src/test/ui/consts/issue-52432.rs b/src/test/ui/consts/issue-52432.rs
new file mode 100644
index 00000000000..2d4c939f47d
--- /dev/null
+++ b/src/test/ui/consts/issue-52432.rs
@@ -0,0 +1,10 @@
+#![feature(const_raw_ptr_to_usize_cast)]
+
+fn main() {
+    [(); &(static |x| {}) as *const _ as usize];
+    //~^ ERROR: closures cannot be static
+    //~| ERROR: type annotations needed
+    [(); &(static || {}) as *const _ as usize];
+    //~^ ERROR: closures cannot be static
+    //~| ERROR: evaluation of constant value failed
+}
diff --git a/src/test/ui/consts/issue-52432.stderr b/src/test/ui/consts/issue-52432.stderr
new file mode 100644
index 00000000000..e9539d24118
--- /dev/null
+++ b/src/test/ui/consts/issue-52432.stderr
@@ -0,0 +1,28 @@
+error[E0697]: closures cannot be static
+  --> $DIR/issue-52432.rs:4:12
+   |
+LL |     [(); &(static |x| {}) as *const _ as usize];
+   |            ^^^^^^^^^^
+
+error[E0697]: closures cannot be static
+  --> $DIR/issue-52432.rs:7:12
+   |
+LL |     [(); &(static || {}) as *const _ as usize];
+   |            ^^^^^^^^^
+
+error[E0282]: type annotations needed
+  --> $DIR/issue-52432.rs:4:20
+   |
+LL |     [(); &(static |x| {}) as *const _ as usize];
+   |                    ^ consider giving this closure parameter a type
+
+error[E0080]: evaluation of constant value failed
+  --> $DIR/issue-52432.rs:7:10
+   |
+LL |     [(); &(static || {}) as *const _ as usize];
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0080, E0282, E0697.
+For more information about an error, try `rustc --explain E0080`.
diff --git a/src/test/ui/issues/issue-40231-1.rs b/src/test/ui/issues/issue-40231-1.rs
new file mode 100644
index 00000000000..999399ec8d3
--- /dev/null
+++ b/src/test/ui/issues/issue-40231-1.rs
@@ -0,0 +1,54 @@
+// check-pass
+
+#![allow(dead_code)]
+
+trait Structure<E>: Sized where E: Encoding {
+    type RefTarget: ?Sized;
+    type FfiPtr;
+    unsafe fn borrow_from_ffi_ptr<'a>(ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget>;
+}
+
+enum Slice {}
+
+impl<E> Structure<E> for Slice where E: Encoding {
+    type RefTarget = [E::Unit];
+    type FfiPtr = (*const E::FfiUnit, usize);
+    unsafe fn borrow_from_ffi_ptr<'a>(_ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget> {
+        panic!()
+    }
+}
+
+trait Encoding {
+    type Unit: Unit;
+    type FfiUnit;
+}
+
+trait Unit {}
+
+enum Utf16 {}
+
+impl Encoding for Utf16 {
+    type Unit = Utf16Unit;
+    type FfiUnit = u16;
+}
+
+struct Utf16Unit(pub u16);
+
+impl Unit for Utf16Unit {}
+
+type SUtf16Str = SeStr<Slice, Utf16>;
+
+struct SeStr<S, E> where S: Structure<E>, E: Encoding {
+    _data: S::RefTarget,
+}
+
+impl<S, E> SeStr<S, E> where S: Structure<E>, E: Encoding {
+    pub unsafe fn from_ptr<'a>(_ptr: S::FfiPtr) -> Option<&'a Self> {
+        panic!()
+    }
+}
+
+fn main() {
+    const TEXT_U16: &'static [u16] = &[];
+    let _ = unsafe { SUtf16Str::from_ptr((TEXT_U16.as_ptr(), TEXT_U16.len())).unwrap() };
+}
diff --git a/src/test/ui/issues/issue-40231-2.rs b/src/test/ui/issues/issue-40231-2.rs
new file mode 100644
index 00000000000..780433b28c5
--- /dev/null
+++ b/src/test/ui/issues/issue-40231-2.rs
@@ -0,0 +1,54 @@
+// check-pass
+
+#![allow(dead_code)]
+
+trait Structure<E>: Sized where E: Encoding {
+    type RefTarget: ?Sized;
+    type FfiPtr;
+    unsafe fn borrow_from_ffi_ptr<'a>(ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget>;
+}
+
+enum Slice {}
+
+impl<E> Structure<E> for Slice where E: Encoding {
+    type RefTarget = [E::Unit];
+    type FfiPtr = (*const E::FfiUnit, usize);
+    unsafe fn borrow_from_ffi_ptr<'a>(_ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget> {
+        panic!()
+    }
+}
+
+trait Encoding {
+    type Unit: Unit;
+    type FfiUnit;
+}
+
+trait Unit {}
+
+enum Utf16 {}
+
+impl Encoding for Utf16 {
+    type Unit = Utf16Unit;
+    type FfiUnit = u16;
+}
+
+struct Utf16Unit(pub u16);
+
+impl Unit for Utf16Unit {}
+
+struct SUtf16Str {
+    _data: <Slice as Structure<Utf16>>::RefTarget,
+}
+
+impl SUtf16Str {
+    pub unsafe fn from_ptr<'a>(ptr: <Slice as Structure<Utf16>>::FfiPtr)
+    -> Option<&'a Self> {
+        std::mem::transmute::<Option<&[<Utf16 as Encoding>::Unit]>, _>(
+            <Slice as Structure<Utf16>>::borrow_from_ffi_ptr(ptr))
+    }
+}
+
+fn main() {
+    const TEXT_U16: &'static [u16] = &[];
+    let _ = unsafe { SUtf16Str::from_ptr((TEXT_U16.as_ptr(), TEXT_U16.len())).unwrap() };
+}
diff --git a/src/test/ui/type-alias-impl-trait/issue-63279.rs b/src/test/ui/type-alias-impl-trait/issue-63279.rs
new file mode 100644
index 00000000000..586ff7a3158
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-63279.rs
@@ -0,0 +1,9 @@
+#![feature(type_alias_impl_trait)]
+
+type Closure = impl FnOnce(); //~ ERROR: type mismatch resolving
+
+fn c() -> Closure {
+    || -> Closure { || () }
+}
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/issue-63279.stderr b/src/test/ui/type-alias-impl-trait/issue-63279.stderr
new file mode 100644
index 00000000000..a5065241fc7
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-63279.stderr
@@ -0,0 +1,13 @@
+error[E0271]: type mismatch resolving `<[closure@$DIR/issue-63279.rs:6:5: 6:28] as std::ops::FnOnce<()>>::Output == ()`
+  --> $DIR/issue-63279.rs:3:1
+   |
+LL | type Closure = impl FnOnce();
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found ()
+   |
+   = note: expected type `Closure`
+              found type `()`
+   = note: the return type of a function must have a statically known size
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0271`.
diff --git a/src/test/ui/unboxed-closures/issue-30904.rs b/src/test/ui/unboxed-closures/issue-30904.rs
new file mode 100644
index 00000000000..eec5e962b43
--- /dev/null
+++ b/src/test/ui/unboxed-closures/issue-30904.rs
@@ -0,0 +1,36 @@
+#![feature(fn_traits, unboxed_closures)]
+
+fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {}
+
+struct Compose<F,G>(F,G);
+impl<T,F,G> FnOnce<(T,)> for Compose<F,G>
+where F: FnOnce<(T,)>, G: FnOnce<(F::Output,)> {
+    type Output = G::Output;
+    extern "rust-call" fn call_once(self, (x,): (T,)) -> G::Output {
+        (self.1)((self.0)(x))
+    }
+}
+
+struct Str<'a>(&'a str);
+fn mk_str<'a>(s: &'a str) -> Str<'a> { Str(s) }
+
+fn main() {
+    let _: for<'a> fn(&'a str) -> Str<'a> = mk_str;
+    // expected concrete lifetime, found bound lifetime parameter 'a
+    let _: for<'a> fn(&'a str) -> Str<'a> = Str;
+    //~^ ERROR: mismatched types
+
+    test(|_: &str| {});
+    test(mk_str);
+    // expected concrete lifetime, found bound lifetime parameter 'x
+    test(Str); //~ ERROR: type mismatch in function arguments
+
+    test(Compose(|_: &str| {}, |_| {}));
+    test(Compose(mk_str, |_| {}));
+    // internal compiler error: cannot relate bound region:
+    //   ReLateBound(DebruijnIndex { depth: 2 },
+    //     BrNamed(DefId { krate: 0, node: DefIndex(6) => test::'x }, 'x(65)))
+    //<= ReSkolemized(0,
+    //     BrNamed(DefId { krate: 0, node: DefIndex(6) => test::'x }, 'x(65)))
+    test(Compose(Str, |_| {}));
+}
diff --git a/src/test/ui/unboxed-closures/issue-30904.stderr b/src/test/ui/unboxed-closures/issue-30904.stderr
new file mode 100644
index 00000000000..943cbe0ccc2
--- /dev/null
+++ b/src/test/ui/unboxed-closures/issue-30904.stderr
@@ -0,0 +1,24 @@
+error[E0308]: mismatched types
+  --> $DIR/issue-30904.rs:20:45
+   |
+LL |     let _: for<'a> fn(&'a str) -> Str<'a> = Str;
+   |                                             ^^^ expected concrete lifetime, found bound lifetime parameter 'a
+   |
+   = note: expected type `for<'a> fn(&'a str) -> Str<'a>`
+              found type `fn(&str) -> Str<'_> {Str::<'_>}`
+
+error[E0631]: type mismatch in function arguments
+  --> $DIR/issue-30904.rs:26:10
+   |
+LL | fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {}
+   |    ----    -------------------------- required by this bound in `test`
+...
+LL | struct Str<'a>(&'a str);
+   | ------------------------ found signature of `fn(&str) -> _`
+...
+LL |     test(Str);
+   |          ^^^ expected signature of `for<'x> fn(&'x str) -> _`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.