Skip to content

Commit

Permalink
Rollup merge of #66331 - JohnTitor:add-tests, r=Centril
Browse files Browse the repository at this point in the history
Add some tests for fixed ICEs

Closes #30904 (fixed between nightly-2019-07-14 and nightly-2019-07-31)
Closes #40231 (example 1 is fixed in 1.32.0, example 2 is fixed in 1.38.0)
Closes #52432 (fixed in rustc 1.40.0-beta.1 (76b4053 2019-11-05))
Closes #63279 (fixed in rustc 1.40.0-nightly (246be7e 2019-10-25))

r? @Centril
  • Loading branch information
JohnTitor committed Nov 13, 2019
2 parents 60ba5c7 + 74d45af commit 5683fe5
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/test/ui/consts/issue-52432.rs
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 28 additions & 0 deletions src/test/ui/consts/issue-52432.stderr
Original file line number Diff line number Diff line change
@@ -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`.
54 changes: 54 additions & 0 deletions src/test/ui/issues/issue-40231-1.rs
Original file line number Diff line number Diff line change
@@ -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() };
}
54 changes: 54 additions & 0 deletions src/test/ui/issues/issue-40231-2.rs
Original file line number Diff line number Diff line change
@@ -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() };
}
9 changes: 9 additions & 0 deletions src/test/ui/type-alias-impl-trait/issue-63279.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![feature(type_alias_impl_trait)]

type Closure = impl FnOnce(); //~ ERROR: type mismatch resolving

fn c() -> Closure {
|| -> Closure { || () }
}

fn main() {}
13 changes: 13 additions & 0 deletions src/test/ui/type-alias-impl-trait/issue-63279.stderr
Original file line number Diff line number Diff line change
@@ -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`.
36 changes: 36 additions & 0 deletions src/test/ui/unboxed-closures/issue-30904.rs
Original file line number Diff line number Diff line change
@@ -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, |_| {}));
}
24 changes: 24 additions & 0 deletions src/test/ui/unboxed-closures/issue-30904.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 5683fe5

Please sign in to comment.