Open
Description
Code
#[derive(Clone, Debug)]
struct Point<T> {
v: T,
}
fn main() {
let a: Point<u8> = dbg!(Point { v: 42 });
let b: Point<u8> = dbg!(&a);
}
Current output
error[E0308]: mismatched types
--> test.rs:10:24
|
10 | let b: Point<u8> = 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<u8> = 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<u8> = 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
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Diagnostics: A structured suggestion resulting in incorrect code.Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcRelevant to the compiler team, which will review and decide on the PR/issue.