Inappropriate suggestion when mismatched types occur in the dbg!
macro · Issue #139253 · rust-lang/rust (original) (raw)
Code
#[derive(Clone, Debug)] struct Point { v: T, }
fn main() { let a: Point = dbg!(Point { v: 42 }); let b: Point = dbg!(&a); }
Current output
error[E0308]: mismatched types
--> test.rs:10:24
|
10 | let b: Point = dbg!(&a);
| ^^^^^^^^ expected Point<u8>
, found &Point<u8>
|
= note: expected struct Point<_>
found reference &Point<_>
= note: this error originates in the macro dbg
(in Nightly builds, run with -Z macro-backtrace for more info)
help: consider using clone here
--> /home/jl-jiang/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs:367:20
|
367| tmp.clone()
| ++++++++
error: aborting due to 1 previous error
For more information about this error, try rustc --explain E0308
.
Desired output
error[E0308]: mismatched types
--> test.rs:10:24
|
10 | let b: Point = dbg!(&a);
| ^^^^^^^^ expected Point<u8>
, found &Point<u8>
|
= note: expected struct Point<_>
found reference &Point<_>
= note: this error originates in the macro dbg
(in Nightly builds, run with -Z macro-backtrace for more info)
help: consider using clone here
--> test.rs:10:29
|
10 | let b: Point = dbg!(a.clone());
| +++++++
error: aborting due to 1 previous error
For more information about this error, try rustc --explain E0308
.
Rationale and extra context
No response
Other cases
Rust Version
rustc 1.88.0-nightly (e2014e876 2025-04-01) binary: rustc commit-hash: e2014e876e3efaa69bf51c19579adb16c3df5f81 commit-date: 2025-04-01 host: x86_64-unknown-linux-gnu release: 1.88.0-nightly LLVM version: 20.1.1
Anything else?
No response