Skip to content

Commit e5df0cc

Browse files
committed
adjust tests for removal of unsized_locals
1 parent d5f1c26 commit e5df0cc

File tree

5 files changed

+77
-21
lines changed

5 files changed

+77
-21
lines changed

tests/fail/unsized-local.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![feature(unsized_locals)]
2+
#![allow(incomplete_features)]
3+
4+
fn main() {
5+
pub trait Foo {
6+
fn foo(self) -> String;
7+
}
8+
9+
struct A;
10+
11+
impl Foo for A {
12+
fn foo(self) -> String {
13+
format!("hello")
14+
}
15+
}
16+
17+
let x = *(Box::new(A) as Box<dyn Foo>); //~ERROR unsized locals are not supported
18+
assert_eq!(x.foo(), format!("hello"));
19+
20+
// I'm not sure whether we want this to work
21+
let x = Box::new(A) as Box<dyn Foo>;
22+
assert_eq!(x.foo(), format!("hello"));
23+
}

tests/fail/unsized-local.stderr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unsupported operation: unsized locals are not supported
2+
--> $DIR/unsized-local.rs:LL:CC
3+
|
4+
LL | let x = *(Box::new(A) as Box<dyn Foo>);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsized locals are not supported
6+
|
7+
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
8+
= note: backtrace:
9+
= note: inside `main` at $DIR/unsized-local.rs:LL:CC
10+
11+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
12+
13+
error: aborting due to previous error
14+

tests/pass/dyn-traits.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#![feature(unsized_locals, unsized_fn_params)]
2-
#![allow(incomplete_features)]
3-
41
fn ref_box_dyn() {
52
struct Struct(i32);
63

@@ -75,6 +72,9 @@ fn box_box_trait() {
7572
assert!(unsafe { DROPPED });
7673
}
7774

75+
// Disabled for now: unsized locals are not supported,
76+
// their current MIR encoding is just not great.
77+
/*
7878
fn unsized_dyn() {
7979
pub trait Foo {
8080
fn foo(self) -> String;
@@ -95,7 +95,6 @@ fn unsized_dyn() {
9595
let x = Box::new(A) as Box<dyn Foo>;
9696
assert_eq!(x.foo(), format!("hello"));
9797
}
98-
9998
fn unsized_dyn_autoderef() {
10099
pub trait Foo {
101100
fn foo(self) -> String;
@@ -140,12 +139,9 @@ fn unsized_dyn_autoderef() {
140139
let x = Box::new(|| "hello".to_owned()) as Box<dyn FnMut() -> String>;
141140
assert_eq!(&x.foo() as &str, "hello");
142141
}
142+
*/
143143

144144
fn main() {
145145
ref_box_dyn();
146146
box_box_trait();
147-
148-
// "exotic" receivers
149-
unsized_dyn();
150-
unsized_dyn_autoderef();
151147
}

tests/pass/unsized-tuple-impls.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/pass/unsized.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![feature(unsized_tuple_coercion)]
2+
#![feature(unsized_fn_params)]
3+
4+
use std::mem;
5+
6+
fn unsized_tuple() {
7+
let x: &(i32, i32, [i32]) = &(0, 1, [2, 3]);
8+
let y: &(i32, i32, [i32]) = &(0, 1, [2, 3, 4]);
9+
let mut a = [y, x];
10+
a.sort();
11+
assert_eq!(a, [x, y]);
12+
13+
assert_eq!(&format!("{:?}", a), "[(0, 1, [2, 3]), (0, 1, [2, 3, 4])]");
14+
assert_eq!(mem::size_of_val(x), 16);
15+
}
16+
17+
fn unsized_params() {
18+
pub fn f0(_f: dyn FnOnce()) {}
19+
pub fn f1(_s: str) {}
20+
pub fn f2(_x: i32, _y: [i32]) {}
21+
pub fn f3(_p: dyn Send) {}
22+
23+
let c: Box<dyn FnOnce()> = Box::new(|| {});
24+
f0(*c);
25+
let foo = "foo".to_string().into_boxed_str();
26+
f1(*foo);
27+
let sl: Box::<[i32]> = [0, 1, 2].to_vec().into_boxed_slice();
28+
f2(5, *sl);
29+
let p: Box<dyn Send> = Box::new((1, 2));
30+
f3(*p);
31+
}
32+
33+
fn main() {
34+
unsized_tuple();
35+
unsized_params();
36+
}

0 commit comments

Comments
 (0)