forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#120990 - chenyukang:yukang-fix-120327-dbg, r=oli-obk Suggest a borrow when using dbg Fixes rust-lang#120327 r? ````@estebank````
- Loading branch information
Showing
4 changed files
with
252 additions
and
2 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,68 @@ | ||
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 test_not_macro() -> String { | ||
let a = String::new(); | ||
let _b = match a { | ||
tmp => { | ||
eprintln!("dbg: {}", tmp); | ||
tmp | ||
} | ||
}; | ||
return a; //~ ERROR use of moved value: | ||
} | ||
|
||
fn get_expr(_s: String) {} | ||
|
||
fn test() { | ||
let a: String = "".to_string(); | ||
let _res = get_expr(dbg!(a)); | ||
let _l = a.len(); //~ ERROR borrow 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,117 @@ | ||
error[E0382]: use of moved value: `a` | ||
--> $DIR/dbg-issue-120327.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/dbg-issue-120327.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/dbg-issue-120327.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/dbg-issue-120327.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/dbg-issue-120327.rs:46: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[E0382]: use of moved value: `a` | ||
--> $DIR/dbg-issue-120327.rs:57:12 | ||
| | ||
LL | let a = String::new(); | ||
| - move occurs because `a` has type `String`, which does not implement the `Copy` trait | ||
LL | let _b = match a { | ||
LL | tmp => { | ||
| --- value moved here | ||
... | ||
LL | return a; | ||
| ^ value used here after move | ||
| | ||
help: borrow this binding in the pattern to avoid moving the value | ||
| | ||
LL | ref tmp => { | ||
| +++ | ||
|
||
error[E0382]: borrow of moved value: `a` | ||
--> $DIR/dbg-issue-120327.rs:65:14 | ||
| | ||
LL | let a: String = "".to_string(); | ||
| - move occurs because `a` has type `String`, which does not implement the `Copy` trait | ||
LL | let _res = get_expr(dbg!(a)); | ||
| ------- value moved here | ||
LL | let _l = a.len(); | ||
| ^ value borrowed here after move | ||
| | ||
help: consider borrowing instead of transferring ownership | ||
| | ||
LL | let _res = get_expr(dbg!(&a)); | ||
| + | ||
|
||
error: aborting due to 7 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