From ec45882b42a07303ae3682898124ee8ae035baba Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 13 Nov 2019 00:35:57 +0900 Subject: [PATCH 1/4] Add test for issue-30904 --- src/test/ui/unboxed-closures/issue-30904.rs | 36 +++++++++++++++++++ .../ui/unboxed-closures/issue-30904.stderr | 24 +++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/test/ui/unboxed-closures/issue-30904.rs create mode 100644 src/test/ui/unboxed-closures/issue-30904.stderr 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 0000000000000..eec5e962b431e --- /dev/null +++ b/src/test/ui/unboxed-closures/issue-30904.rs @@ -0,0 +1,36 @@ +#![feature(fn_traits, unboxed_closures)] + +fn test FnOnce<(&'x str,)>>(_: F) {} + +struct Compose(F,G); +impl FnOnce<(T,)> for Compose +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 0000000000000..943cbe0ccc297 --- /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 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`. From bae9832f714e7244bedc34eac40273eb6e915ed7 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 13 Nov 2019 00:36:20 +0900 Subject: [PATCH 2/4] Add test for issue-40231 --- src/test/ui/issues/issue-40231-1.rs | 54 +++++++++++++++++++++++++++++ src/test/ui/issues/issue-40231-2.rs | 54 +++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/test/ui/issues/issue-40231-1.rs create mode 100644 src/test/ui/issues/issue-40231-2.rs 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 0000000000000..999399ec8d34c --- /dev/null +++ b/src/test/ui/issues/issue-40231-1.rs @@ -0,0 +1,54 @@ +// check-pass + +#![allow(dead_code)] + +trait Structure: 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 Structure 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; + +struct SeStr where S: Structure, E: Encoding { + _data: S::RefTarget, +} + +impl SeStr where S: Structure, 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 0000000000000..780433b28c596 --- /dev/null +++ b/src/test/ui/issues/issue-40231-2.rs @@ -0,0 +1,54 @@ +// check-pass + +#![allow(dead_code)] + +trait Structure: 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 Structure 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: >::RefTarget, +} + +impl SUtf16Str { + pub unsafe fn from_ptr<'a>(ptr: >::FfiPtr) + -> Option<&'a Self> { + std::mem::transmute::::Unit]>, _>( + >::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() }; +} From 412f0006f520357d220882b57eef501999b44c9a Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 13 Nov 2019 00:36:38 +0900 Subject: [PATCH 3/4] Add test for issue-52432 --- src/test/ui/consts/issue-52432.rs | 10 ++++++++++ src/test/ui/consts/issue-52432.stderr | 28 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/test/ui/consts/issue-52432.rs create mode 100644 src/test/ui/consts/issue-52432.stderr diff --git a/src/test/ui/consts/issue-52432.rs b/src/test/ui/consts/issue-52432.rs new file mode 100644 index 0000000000000..2d4c939f47d79 --- /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 0000000000000..e9539d24118a0 --- /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`. From 74d45afbf5473d1b255629e786e074060dcc7ec2 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 13 Nov 2019 00:37:00 +0900 Subject: [PATCH 4/4] Add test for issue-63279 --- src/test/ui/type-alias-impl-trait/issue-63279.rs | 9 +++++++++ .../ui/type-alias-impl-trait/issue-63279.stderr | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/issue-63279.rs create mode 100644 src/test/ui/type-alias-impl-trait/issue-63279.stderr 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 0000000000000..586ff7a31587f --- /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 0000000000000..a5065241fc74d --- /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`.