Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

borrow diagnostic of dbg! leaks implementation #128312

Closed
lolbinarycat opened this issue Jul 28, 2024 · 1 comment
Closed

borrow diagnostic of dbg! leaks implementation #128312

lolbinarycat opened this issue Jul 28, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lolbinarycat
Copy link
Contributor

Code

fn main() {
    let s = String::from("hello");
    dbg!(s);
    drop(s);
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0382]: use of moved value: `s`
 --> src/main.rs:4:10
  |
2 |     let s = String::from("hello");
  |         - move occurs because `s` has type `String`, which does not implement the `Copy` trait
3 |     dbg!(s);
  |     ------- value moved here
4 |     drop(s);
  |          ^ value used here after move
  |
help: borrow this binding in the pattern to avoid moving the value
 --> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs:364:13
  |
36|             ref tmp => {
  |             +++

For more information about this error, try `rustc --explain E0382`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Desired output

Compiling playground v0.0.1 (/playground)
error[E0382]: use of moved value: `s`
 --> src/main.rs:4:10
  |
2 |     let s = String::from("hello");
  |         - move occurs because `s` has type `String`, which does not implement the `Copy` trait
3 |     dbg!(s);
  |     ------- value moved here
4 |     drop(s);
  |          ^ value used here after move
  |
help: borrow here
  |
3 |     dbg!(&s);
  |

Rationale and extra context

No response

Other cases

No response

Rust Version

1.79.0

Anything else?

No response

@lolbinarycat lolbinarycat added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 28, 2024
@fmease
Copy link
Member

fmease commented Jul 29, 2024

Duplicate of #120327.
Fixed on nightly via #120990.

Nightly output:

error[E0382]: use of moved value: `s`
 --> bw.rs:4:10
  |
2 |     let s = String::from("hello");
  |         - move occurs because `s` has type `String`, which does not implement the `Copy` trait
3 |     dbg!(s);
  |     ------- value moved here
4 |     drop(s);
  |          ^ value used here after move
  |
help: consider borrowing instead of transferring ownership
  |
3 |     dbg!(&s);
  |          +

In the future please double-check that the issue hasn't already been fixed on nightly before submitting a new GH issue. Thanks!

@fmease fmease closed this as completed Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants