Skip to content

borrow diagnostic of dbg! leaks implementation #128312

Description

@lolbinarycat

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions