mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
Add more tests on unsized locals autoderef and borrowck.
This commit is contained in:
parent
1c4864708f
commit
2f7ea4a872
47
src/test/run-pass/unsized-locals/autoderef.rs
Normal file
47
src/test/run-pass/unsized-locals/autoderef.rs
Normal file
@ -0,0 +1,47 @@
|
||||
#![feature(unsized_locals)]
|
||||
|
||||
pub trait Foo {
|
||||
fn foo(self) -> String;
|
||||
}
|
||||
|
||||
impl Foo for [char] {
|
||||
fn foo(self) -> String {
|
||||
self.iter().collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl Foo for str {
|
||||
fn foo(self) -> String {
|
||||
self.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl Foo for dyn FnMut() -> String {
|
||||
fn foo(mut self) -> String {
|
||||
self()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let x = *(Box::new(['h', 'e', 'l', 'l', 'o']) as Box<[char]>);
|
||||
assert_eq!(&x.foo() as &str, "hello");
|
||||
|
||||
let x = Box::new(['h', 'e', 'l', 'l', 'o']) as Box<[char]>;
|
||||
assert_eq!(&x.foo() as &str, "hello");
|
||||
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
assert_eq!(&x.foo() as &str, "hello");
|
||||
|
||||
let x = *("hello".to_owned().into_boxed_str());
|
||||
assert_eq!(&x.foo() as &str, "hello");
|
||||
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
assert_eq!(&x.foo() as &str, "hello");
|
||||
|
||||
let x = *(Box::new(|| "hello".to_owned()) as Box<dyn FnMut() -> String>);
|
||||
assert_eq!(&x.foo() as &str, "hello");
|
||||
|
||||
let x = Box::new(|| "hello".to_owned()) as Box<dyn FnMut() -> String>;
|
||||
assert_eq!(&x.foo() as &str, "hello");
|
||||
}
|
51
src/test/ui/unsized-locals/borrow-after-move.nll.stderr
Normal file
51
src/test/ui/unsized-locals/borrow-after-move.nll.stderr
Normal file
@ -0,0 +1,51 @@
|
||||
error[E0382]: borrow of moved value: `x`
|
||||
--> $DIR/borrow-after-move.rs:20:24
|
||||
|
|
||||
LL | let y = *x;
|
||||
| -- value moved here
|
||||
LL | drop_unsized(y);
|
||||
LL | println!("{}", &x);
|
||||
| ^^ value borrowed here after move
|
||||
|
||||
error[E0382]: borrow of moved value: `y`
|
||||
--> $DIR/borrow-after-move.rs:22:24
|
||||
|
|
||||
LL | drop_unsized(y);
|
||||
| - value moved here
|
||||
...
|
||||
LL | println!("{}", &y);
|
||||
| ^^ value borrowed here after move
|
||||
|
|
||||
= note: move occurs because `y` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: borrow of moved value: `x`
|
||||
--> $DIR/borrow-after-move.rs:30:24
|
||||
|
|
||||
LL | let y = *x;
|
||||
| -- value moved here
|
||||
LL | y.foo();
|
||||
LL | println!("{}", &x);
|
||||
| ^^ value borrowed here after move
|
||||
|
||||
error[E0382]: borrow of moved value: `y`
|
||||
--> $DIR/borrow-after-move.rs:32:24
|
||||
|
|
||||
LL | y.foo();
|
||||
| - value moved here
|
||||
...
|
||||
LL | println!("{}", &y);
|
||||
| ^^ value borrowed here after move
|
||||
|
|
||||
= note: move occurs because `y` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: borrow of moved value: `x`
|
||||
--> $DIR/borrow-after-move.rs:39:24
|
||||
|
|
||||
LL | x.foo();
|
||||
| - value moved here
|
||||
LL | println!("{}", &x);
|
||||
| ^^ value borrowed here after move
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0382`.
|
42
src/test/ui/unsized-locals/borrow-after-move.rs
Normal file
42
src/test/ui/unsized-locals/borrow-after-move.rs
Normal file
@ -0,0 +1,42 @@
|
||||
#![feature(unsized_locals)]
|
||||
|
||||
pub trait Foo {
|
||||
fn foo(self) -> String;
|
||||
}
|
||||
|
||||
impl Foo for str {
|
||||
fn foo(self) -> String {
|
||||
self.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
fn drop_unsized<T: ?Sized>(_: T) {}
|
||||
|
||||
fn main() {
|
||||
{
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
let y = *x;
|
||||
drop_unsized(y);
|
||||
println!("{}", &x);
|
||||
//~^ERROR use of moved value
|
||||
println!("{}", &y);
|
||||
//~^ERROR use of moved value
|
||||
}
|
||||
|
||||
{
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
let y = *x;
|
||||
y.foo();
|
||||
println!("{}", &x);
|
||||
//~^ERROR use of moved value
|
||||
println!("{}", &y);
|
||||
//~^ERROR use of moved value
|
||||
}
|
||||
|
||||
{
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
x.foo();
|
||||
println!("{}", &x);
|
||||
//~^ERROR use of moved value
|
||||
}
|
||||
}
|
57
src/test/ui/unsized-locals/borrow-after-move.stderr
Normal file
57
src/test/ui/unsized-locals/borrow-after-move.stderr
Normal file
@ -0,0 +1,57 @@
|
||||
error[E0382]: use of moved value: `x`
|
||||
--> $DIR/borrow-after-move.rs:20:25
|
||||
|
|
||||
LL | let y = *x;
|
||||
| - value moved here
|
||||
LL | drop_unsized(y);
|
||||
LL | println!("{}", &x);
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `*x` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `y`
|
||||
--> $DIR/borrow-after-move.rs:22:25
|
||||
|
|
||||
LL | drop_unsized(y);
|
||||
| - value moved here
|
||||
...
|
||||
LL | println!("{}", &y);
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `y` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `x`
|
||||
--> $DIR/borrow-after-move.rs:30:25
|
||||
|
|
||||
LL | let y = *x;
|
||||
| - value moved here
|
||||
LL | y.foo();
|
||||
LL | println!("{}", &x);
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `*x` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `y`
|
||||
--> $DIR/borrow-after-move.rs:32:25
|
||||
|
|
||||
LL | y.foo();
|
||||
| - value moved here
|
||||
...
|
||||
LL | println!("{}", &y);
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `y` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `x`
|
||||
--> $DIR/borrow-after-move.rs:39:25
|
||||
|
|
||||
LL | x.foo();
|
||||
| - value moved here
|
||||
LL | println!("{}", &x);
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `*x` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0382`.
|
55
src/test/ui/unsized-locals/double-move.nll.stderr
Normal file
55
src/test/ui/unsized-locals/double-move.nll.stderr
Normal file
@ -0,0 +1,55 @@
|
||||
error[E0382]: use of moved value: `y`
|
||||
--> $DIR/double-move.rs:20:22
|
||||
|
|
||||
LL | drop_unsized(y);
|
||||
| - value moved here
|
||||
LL | drop_unsized(y); //~ERROR use of moved value
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `y` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `x`
|
||||
--> $DIR/double-move.rs:26:22
|
||||
|
|
||||
LL | let _y = *x;
|
||||
| -- value moved here
|
||||
LL | drop_unsized(x); //~ERROR use of moved value
|
||||
| ^ value used here after move
|
||||
|
||||
error[E0382]: use of moved value: `*x`
|
||||
--> $DIR/double-move.rs:32:18
|
||||
|
|
||||
LL | drop_unsized(x);
|
||||
| - value moved here
|
||||
LL | let _y = *x; //~ERROR use of moved value
|
||||
| ^^ value used here after move
|
||||
|
||||
error[E0382]: use of moved value: `y`
|
||||
--> $DIR/double-move.rs:39:9
|
||||
|
|
||||
LL | y.foo();
|
||||
| - value moved here
|
||||
LL | y.foo(); //~ERROR use of moved value
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `y` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `*x`
|
||||
--> $DIR/double-move.rs:45:9
|
||||
|
|
||||
LL | let _y = *x;
|
||||
| -- value moved here
|
||||
LL | x.foo(); //~ERROR use of moved value
|
||||
| ^ value used here after move
|
||||
|
||||
error[E0382]: use of moved value: `*x`
|
||||
--> $DIR/double-move.rs:51:18
|
||||
|
|
||||
LL | x.foo();
|
||||
| - value moved here
|
||||
LL | let _y = *x; //~ERROR use of moved value
|
||||
| ^^ value used here after move
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0382`.
|
53
src/test/ui/unsized-locals/double-move.rs
Normal file
53
src/test/ui/unsized-locals/double-move.rs
Normal file
@ -0,0 +1,53 @@
|
||||
#![feature(unsized_locals)]
|
||||
|
||||
pub trait Foo {
|
||||
fn foo(self) -> String;
|
||||
}
|
||||
|
||||
impl Foo for str {
|
||||
fn foo(self) -> String {
|
||||
self.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
fn drop_unsized<T: ?Sized>(_: T) {}
|
||||
|
||||
fn main() {
|
||||
{
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
let y = *x;
|
||||
drop_unsized(y);
|
||||
drop_unsized(y); //~ERROR use of moved value
|
||||
}
|
||||
|
||||
{
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
let _y = *x;
|
||||
drop_unsized(x); //~ERROR use of moved value
|
||||
}
|
||||
|
||||
{
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
drop_unsized(x);
|
||||
let _y = *x; //~ERROR use of moved value
|
||||
}
|
||||
|
||||
{
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
let y = *x;
|
||||
y.foo();
|
||||
y.foo(); //~ERROR use of moved value
|
||||
}
|
||||
|
||||
{
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
let _y = *x;
|
||||
x.foo(); //~ERROR use of moved value
|
||||
}
|
||||
|
||||
{
|
||||
let x = "hello".to_owned().into_boxed_str();
|
||||
x.foo();
|
||||
let _y = *x; //~ERROR use of moved value
|
||||
}
|
||||
}
|
63
src/test/ui/unsized-locals/double-move.stderr
Normal file
63
src/test/ui/unsized-locals/double-move.stderr
Normal file
@ -0,0 +1,63 @@
|
||||
error[E0382]: use of moved value: `y`
|
||||
--> $DIR/double-move.rs:20:22
|
||||
|
|
||||
LL | drop_unsized(y);
|
||||
| - value moved here
|
||||
LL | drop_unsized(y); //~ERROR use of moved value
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `y` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `x`
|
||||
--> $DIR/double-move.rs:26:22
|
||||
|
|
||||
LL | let _y = *x;
|
||||
| -- value moved here
|
||||
LL | drop_unsized(x); //~ERROR use of moved value
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `*x` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `*x`
|
||||
--> $DIR/double-move.rs:32:13
|
||||
|
|
||||
LL | drop_unsized(x);
|
||||
| - value moved here
|
||||
LL | let _y = *x; //~ERROR use of moved value
|
||||
| ^^ value used here after move
|
||||
|
|
||||
= note: move occurs because `x` has type `std::boxed::Box<str>`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `y`
|
||||
--> $DIR/double-move.rs:39:9
|
||||
|
|
||||
LL | y.foo();
|
||||
| - value moved here
|
||||
LL | y.foo(); //~ERROR use of moved value
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `y` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `*x`
|
||||
--> $DIR/double-move.rs:45:9
|
||||
|
|
||||
LL | let _y = *x;
|
||||
| -- value moved here
|
||||
LL | x.foo(); //~ERROR use of moved value
|
||||
| ^ value used here after move
|
||||
|
|
||||
= note: move occurs because `*x` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error[E0382]: use of moved value: `*x`
|
||||
--> $DIR/double-move.rs:51:13
|
||||
|
|
||||
LL | x.foo();
|
||||
| - value moved here
|
||||
LL | let _y = *x; //~ERROR use of moved value
|
||||
| ^^ value used here after move
|
||||
|
|
||||
= note: move occurs because `*x` has type `str`, which does not implement the `Copy` trait
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0382`.
|
Loading…
Reference in New Issue
Block a user