Implement simple codegen for unsized rvalues.
This commit is contained in:
parent
e2b95cb70e
commit
800f2c13a3
15 changed files with 388 additions and 20 deletions
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(unsized_locals)]
|
||||
|
||||
use std::fmt;
|
||||
|
||||
fn gen_foo() -> Box<fmt::Display> {
|
||||
Box::new(Box::new("foo"))
|
||||
}
|
||||
|
||||
fn foo(x: fmt::Display) {
|
||||
assert_eq!(x.to_string(), "foo");
|
||||
}
|
||||
|
||||
fn foo_indirect(x: fmt::Display) {
|
||||
foo(x);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo(*gen_foo());
|
||||
foo_indirect(*gen_foo());
|
||||
|
||||
{
|
||||
let x: fmt::Display = *gen_foo();
|
||||
foo(x);
|
||||
}
|
||||
|
||||
{
|
||||
let x: fmt::Display = *gen_foo();
|
||||
let y: fmt::Display = *gen_foo();
|
||||
foo(x);
|
||||
foo(y);
|
||||
}
|
||||
|
||||
{
|
||||
let mut cnt: usize = 3;
|
||||
let x = loop {
|
||||
let x: fmt::Display = *gen_foo();
|
||||
if cnt == 0 {
|
||||
break x;
|
||||
} else {
|
||||
cnt -= 1;
|
||||
}
|
||||
};
|
||||
foo(x);
|
||||
}
|
||||
|
||||
{
|
||||
let x: fmt::Display = *gen_foo();
|
||||
let x = if true {
|
||||
x
|
||||
} else {
|
||||
*gen_foo()
|
||||
};
|
||||
foo(x);
|
||||
}
|
||||
}
|
||||
17
src/test/run-pass/unsized-locals/reference-unsized-locals.rs
Normal file
17
src/test/run-pass/unsized-locals/reference-unsized-locals.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(unsized_locals)]
|
||||
|
||||
fn main() {
|
||||
let foo: Box<[u8]> = Box::new(*b"foo");
|
||||
let foo: [u8] = *foo;
|
||||
assert_eq!(&foo, b"foo" as &[u8]);
|
||||
}
|
||||
16
src/test/run-pass/unsized-locals/simple-unsized-locals.rs
Normal file
16
src/test/run-pass/unsized-locals/simple-unsized-locals.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(unsized_locals)]
|
||||
|
||||
fn main() {
|
||||
let foo: Box<[u8]> = Box::new(*b"foo");
|
||||
let _foo: [u8] = *foo;
|
||||
}
|
||||
45
src/test/run-pass/unsized-locals/unsized-exprs.rs
Normal file
45
src/test/run-pass/unsized-locals/unsized-exprs.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(unsized_tuple_coercion, unsized_locals)]
|
||||
|
||||
struct A<X: ?Sized>(X);
|
||||
|
||||
fn udrop<T: ?Sized>(_x: T) {}
|
||||
fn foo() -> Box<[u8]> {
|
||||
Box::new(*b"foo")
|
||||
}
|
||||
fn tfoo() -> Box<(i32, [u8])> {
|
||||
Box::new((42, *b"foo"))
|
||||
}
|
||||
fn afoo() -> Box<A<[u8]>> {
|
||||
Box::new(A(*b"foo"))
|
||||
}
|
||||
|
||||
impl std::ops::Add<i32> for A<[u8]> {
|
||||
type Output = ();
|
||||
fn add(self, _rhs: i32) -> Self::Output {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
udrop::<[u8]>(loop {
|
||||
break *foo();
|
||||
});
|
||||
udrop::<[u8]>(if true {
|
||||
*foo()
|
||||
} else {
|
||||
*foo()
|
||||
});
|
||||
udrop::<[u8]>({*foo()});
|
||||
#[allow(unused_parens)]
|
||||
udrop::<[u8]>((*foo()));
|
||||
udrop::<[u8]>((*tfoo()).1);
|
||||
*afoo() + 42;
|
||||
}
|
||||
20
src/test/run-pass/unsized-locals/unsized-parameters.rs
Normal file
20
src/test/run-pass/unsized-locals/unsized-parameters.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(unsized_locals)]
|
||||
|
||||
pub fn f0(_f: dyn FnOnce()) {}
|
||||
pub fn f1(_s: str) {}
|
||||
pub fn f2((_x, _y): (i32, [i32])) {}
|
||||
|
||||
fn main() {
|
||||
let foo = "foo".to_string().into_boxed_str();
|
||||
f1(*foo);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue