-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests on unsized locals autoderef and borrowck.
- Loading branch information
Showing
7 changed files
with
368 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |