-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b381d3a
commit e216c00
Showing
4 changed files
with
230 additions
and
9 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
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,52 @@ | ||
fn s() -> String { | ||
let a = String::new(); | ||
dbg!(a); | ||
return a; //~ ERROR use of moved value: | ||
} | ||
|
||
fn m() -> String { | ||
let a = String::new(); | ||
dbg!(1, 2, a, 1, 2); | ||
return a; //~ ERROR use of moved value: | ||
} | ||
|
||
fn t(a: String) -> String { | ||
let b: String = "".to_string(); | ||
dbg!(a, b); | ||
return b; //~ ERROR use of moved value: | ||
} | ||
|
||
fn x(a: String) -> String { | ||
let b: String = "".to_string(); | ||
dbg!(a, b); | ||
return a; //~ ERROR use of moved value: | ||
} | ||
|
||
|
||
|
||
macro_rules! my_dbg { | ||
() => { | ||
eprintln!("[{}:{}:{}]", file!(), line!(), column!()) | ||
}; | ||
($val:expr $(,)?) => { | ||
match $val { | ||
tmp => { | ||
eprintln!("[{}:{}:{}] {} = {:#?}", | ||
file!(), line!(), column!(), stringify!($val), &tmp); | ||
tmp | ||
} | ||
} | ||
}; | ||
($($val:expr),+ $(,)?) => { | ||
($(my_dbg!($val)),+,) | ||
}; | ||
} | ||
|
||
|
||
fn test_my_dbg() -> String { | ||
let b: String = "".to_string(); | ||
my_dbg!(b, 1); | ||
return b; //~ ERROR use of moved value: | ||
} | ||
|
||
fn main() {} |
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,85 @@ | ||
error[E0382]: use of moved value: `a` | ||
--> $DIR/issue-120327-dbg.rs:4:12 | ||
| | ||
LL | let a = String::new(); | ||
| - move occurs because `a` has type `String`, which does not implement the `Copy` trait | ||
LL | dbg!(a); | ||
| ------- value moved here | ||
LL | return a; | ||
| ^ value used here after move | ||
| | ||
help: consider borrowing instead of transferring ownership | ||
| | ||
LL | dbg!(&a); | ||
| + | ||
|
||
error[E0382]: use of moved value: `a` | ||
--> $DIR/issue-120327-dbg.rs:10:12 | ||
| | ||
LL | let a = String::new(); | ||
| - move occurs because `a` has type `String`, which does not implement the `Copy` trait | ||
LL | dbg!(1, 2, a, 1, 2); | ||
| ------------------- value moved here | ||
LL | return a; | ||
| ^ value used here after move | ||
| | ||
help: consider borrowing instead of transferring ownership | ||
| | ||
LL | dbg!(1, 2, &a, 1, 2); | ||
| + | ||
|
||
error[E0382]: use of moved value: `b` | ||
--> $DIR/issue-120327-dbg.rs:16:12 | ||
| | ||
LL | let b: String = "".to_string(); | ||
| - move occurs because `b` has type `String`, which does not implement the `Copy` trait | ||
LL | dbg!(a, b); | ||
| ---------- value moved here | ||
LL | return b; | ||
| ^ value used here after move | ||
| | ||
help: consider borrowing instead of transferring ownership | ||
| | ||
LL | dbg!(a, &b); | ||
| + | ||
|
||
error[E0382]: use of moved value: `a` | ||
--> $DIR/issue-120327-dbg.rs:22:12 | ||
| | ||
LL | fn x(a: String) -> String { | ||
| - move occurs because `a` has type `String`, which does not implement the `Copy` trait | ||
LL | let b: String = "".to_string(); | ||
LL | dbg!(a, b); | ||
| ---------- value moved here | ||
LL | return a; | ||
| ^ value used here after move | ||
| | ||
help: consider borrowing instead of transferring ownership | ||
| | ||
LL | dbg!(&a, b); | ||
| + | ||
|
||
error[E0382]: use of moved value: `b` | ||
--> $DIR/issue-120327-dbg.rs:49:12 | ||
| | ||
LL | tmp => { | ||
| --- value moved here | ||
... | ||
LL | let b: String = "".to_string(); | ||
| - move occurs because `b` has type `String`, which does not implement the `Copy` trait | ||
LL | my_dbg!(b, 1); | ||
LL | return b; | ||
| ^ value used here after move | ||
| | ||
help: consider borrowing instead of transferring ownership | ||
| | ||
LL | my_dbg!(&b, 1); | ||
| + | ||
help: borrow this binding in the pattern to avoid moving the value | ||
| | ||
LL | ref tmp => { | ||
| +++ | ||
|
||
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