Skip to content

Commit b1b794f

Browse files
authored
Rollup merge of rust-lang#66331 - JohnTitor:add-tests, r=Centril
Add some tests for fixed ICEs Closes rust-lang#30904 (fixed between nightly-2019-07-14 and nightly-2019-07-31) Closes rust-lang#40231 (example 1 is fixed in 1.32.0, example 2 is fixed in 1.38.0) Closes rust-lang#52432 (fixed in rustc 1.40.0-beta.1 (76b4053 2019-11-05)) Closes rust-lang#63279 (fixed in rustc 1.40.0-nightly (246be7e 2019-10-25)) r? @Centril
2 parents 7567b52 + 74d45af commit b1b794f

File tree

8 files changed

+228
-0
lines changed

8 files changed

+228
-0
lines changed

src/test/ui/consts/issue-52432.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(const_raw_ptr_to_usize_cast)]
2+
3+
fn main() {
4+
[(); &(static |x| {}) as *const _ as usize];
5+
//~^ ERROR: closures cannot be static
6+
//~| ERROR: type annotations needed
7+
[(); &(static || {}) as *const _ as usize];
8+
//~^ ERROR: closures cannot be static
9+
//~| ERROR: evaluation of constant value failed
10+
}

src/test/ui/consts/issue-52432.stderr

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error[E0697]: closures cannot be static
2+
--> $DIR/issue-52432.rs:4:12
3+
|
4+
LL | [(); &(static |x| {}) as *const _ as usize];
5+
| ^^^^^^^^^^
6+
7+
error[E0697]: closures cannot be static
8+
--> $DIR/issue-52432.rs:7:12
9+
|
10+
LL | [(); &(static || {}) as *const _ as usize];
11+
| ^^^^^^^^^
12+
13+
error[E0282]: type annotations needed
14+
--> $DIR/issue-52432.rs:4:20
15+
|
16+
LL | [(); &(static |x| {}) as *const _ as usize];
17+
| ^ consider giving this closure parameter a type
18+
19+
error[E0080]: evaluation of constant value failed
20+
--> $DIR/issue-52432.rs:7:10
21+
|
22+
LL | [(); &(static || {}) as *const _ as usize];
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
24+
25+
error: aborting due to 4 previous errors
26+
27+
Some errors have detailed explanations: E0080, E0282, E0697.
28+
For more information about an error, try `rustc --explain E0080`.

src/test/ui/issues/issue-40231-1.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// check-pass
2+
3+
#![allow(dead_code)]
4+
5+
trait Structure<E>: Sized where E: Encoding {
6+
type RefTarget: ?Sized;
7+
type FfiPtr;
8+
unsafe fn borrow_from_ffi_ptr<'a>(ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget>;
9+
}
10+
11+
enum Slice {}
12+
13+
impl<E> Structure<E> for Slice where E: Encoding {
14+
type RefTarget = [E::Unit];
15+
type FfiPtr = (*const E::FfiUnit, usize);
16+
unsafe fn borrow_from_ffi_ptr<'a>(_ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget> {
17+
panic!()
18+
}
19+
}
20+
21+
trait Encoding {
22+
type Unit: Unit;
23+
type FfiUnit;
24+
}
25+
26+
trait Unit {}
27+
28+
enum Utf16 {}
29+
30+
impl Encoding for Utf16 {
31+
type Unit = Utf16Unit;
32+
type FfiUnit = u16;
33+
}
34+
35+
struct Utf16Unit(pub u16);
36+
37+
impl Unit for Utf16Unit {}
38+
39+
type SUtf16Str = SeStr<Slice, Utf16>;
40+
41+
struct SeStr<S, E> where S: Structure<E>, E: Encoding {
42+
_data: S::RefTarget,
43+
}
44+
45+
impl<S, E> SeStr<S, E> where S: Structure<E>, E: Encoding {
46+
pub unsafe fn from_ptr<'a>(_ptr: S::FfiPtr) -> Option<&'a Self> {
47+
panic!()
48+
}
49+
}
50+
51+
fn main() {
52+
const TEXT_U16: &'static [u16] = &[];
53+
let _ = unsafe { SUtf16Str::from_ptr((TEXT_U16.as_ptr(), TEXT_U16.len())).unwrap() };
54+
}

src/test/ui/issues/issue-40231-2.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// check-pass
2+
3+
#![allow(dead_code)]
4+
5+
trait Structure<E>: Sized where E: Encoding {
6+
type RefTarget: ?Sized;
7+
type FfiPtr;
8+
unsafe fn borrow_from_ffi_ptr<'a>(ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget>;
9+
}
10+
11+
enum Slice {}
12+
13+
impl<E> Structure<E> for Slice where E: Encoding {
14+
type RefTarget = [E::Unit];
15+
type FfiPtr = (*const E::FfiUnit, usize);
16+
unsafe fn borrow_from_ffi_ptr<'a>(_ptr: Self::FfiPtr) -> Option<&'a Self::RefTarget> {
17+
panic!()
18+
}
19+
}
20+
21+
trait Encoding {
22+
type Unit: Unit;
23+
type FfiUnit;
24+
}
25+
26+
trait Unit {}
27+
28+
enum Utf16 {}
29+
30+
impl Encoding for Utf16 {
31+
type Unit = Utf16Unit;
32+
type FfiUnit = u16;
33+
}
34+
35+
struct Utf16Unit(pub u16);
36+
37+
impl Unit for Utf16Unit {}
38+
39+
struct SUtf16Str {
40+
_data: <Slice as Structure<Utf16>>::RefTarget,
41+
}
42+
43+
impl SUtf16Str {
44+
pub unsafe fn from_ptr<'a>(ptr: <Slice as Structure<Utf16>>::FfiPtr)
45+
-> Option<&'a Self> {
46+
std::mem::transmute::<Option<&[<Utf16 as Encoding>::Unit]>, _>(
47+
<Slice as Structure<Utf16>>::borrow_from_ffi_ptr(ptr))
48+
}
49+
}
50+
51+
fn main() {
52+
const TEXT_U16: &'static [u16] = &[];
53+
let _ = unsafe { SUtf16Str::from_ptr((TEXT_U16.as_ptr(), TEXT_U16.len())).unwrap() };
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Closure = impl FnOnce(); //~ ERROR: type mismatch resolving
4+
5+
fn c() -> Closure {
6+
|| -> Closure { || () }
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0271]: type mismatch resolving `<[closure@$DIR/issue-63279.rs:6:5: 6:28] as std::ops::FnOnce<()>>::Output == ()`
2+
--> $DIR/issue-63279.rs:3:1
3+
|
4+
LL | type Closure = impl FnOnce();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found ()
6+
|
7+
= note: expected type `Closure`
8+
found type `()`
9+
= note: the return type of a function must have a statically known size
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0271`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![feature(fn_traits, unboxed_closures)]
2+
3+
fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {}
4+
5+
struct Compose<F,G>(F,G);
6+
impl<T,F,G> FnOnce<(T,)> for Compose<F,G>
7+
where F: FnOnce<(T,)>, G: FnOnce<(F::Output,)> {
8+
type Output = G::Output;
9+
extern "rust-call" fn call_once(self, (x,): (T,)) -> G::Output {
10+
(self.1)((self.0)(x))
11+
}
12+
}
13+
14+
struct Str<'a>(&'a str);
15+
fn mk_str<'a>(s: &'a str) -> Str<'a> { Str(s) }
16+
17+
fn main() {
18+
let _: for<'a> fn(&'a str) -> Str<'a> = mk_str;
19+
// expected concrete lifetime, found bound lifetime parameter 'a
20+
let _: for<'a> fn(&'a str) -> Str<'a> = Str;
21+
//~^ ERROR: mismatched types
22+
23+
test(|_: &str| {});
24+
test(mk_str);
25+
// expected concrete lifetime, found bound lifetime parameter 'x
26+
test(Str); //~ ERROR: type mismatch in function arguments
27+
28+
test(Compose(|_: &str| {}, |_| {}));
29+
test(Compose(mk_str, |_| {}));
30+
// internal compiler error: cannot relate bound region:
31+
// ReLateBound(DebruijnIndex { depth: 2 },
32+
// BrNamed(DefId { krate: 0, node: DefIndex(6) => test::'x }, 'x(65)))
33+
//<= ReSkolemized(0,
34+
// BrNamed(DefId { krate: 0, node: DefIndex(6) => test::'x }, 'x(65)))
35+
test(Compose(Str, |_| {}));
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-30904.rs:20:45
3+
|
4+
LL | let _: for<'a> fn(&'a str) -> Str<'a> = Str;
5+
| ^^^ expected concrete lifetime, found bound lifetime parameter 'a
6+
|
7+
= note: expected type `for<'a> fn(&'a str) -> Str<'a>`
8+
found type `fn(&str) -> Str<'_> {Str::<'_>}`
9+
10+
error[E0631]: type mismatch in function arguments
11+
--> $DIR/issue-30904.rs:26:10
12+
|
13+
LL | fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {}
14+
| ---- -------------------------- required by this bound in `test`
15+
...
16+
LL | struct Str<'a>(&'a str);
17+
| ------------------------ found signature of `fn(&str) -> _`
18+
...
19+
LL | test(Str);
20+
| ^^^ expected signature of `for<'x> fn(&'x str) -> _`
21+
22+
error: aborting due to 2 previous errors
23+
24+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)