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

Unsized tail fields in derive(Display) #432

Open
dtolnay opened this issue Dec 27, 2024 · 0 comments
Open

Unsized tail fields in derive(Display) #432

dtolnay opened this issue Dec 27, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@dtolnay
Copy link

dtolnay commented Dec 27, 2024

use derive_more::Display;

#[derive(Display, Debug)]
#[display("{head}.{tail}")]
struct Struct {
    head: char,
    tail: str,
}

fn main() {
    let dat = [51i32, 3028017];
    let s = unsafe { &*(&raw const dat as *const [i32] as *const Struct) };
    println!("{:?}", s);
    println!("{}", s);
}

The derived Debug impl prints Struct { head: '3', tail: "14" } but the Display impl does not compile.

error[E0277]: the size for values of type `str` cannot be known at compilation time
   --> src/main.rs:3:10
    |
3   | #[derive(Display, Debug)]
    |          ^^^^^^^ doesn't have a size known at compile-time
4   | #[display("{head}.{tail}")]
    |                   ------ required by a bound introduced by this call
    |
    = help: the trait `Sized` is not implemented for `str`
note: required by an implicit `Sized` bound in `derive_more::core::fmt::rt::Argument::<'_>::new_display`
   --> $RUSTUP_HOME/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/rt.rs:113:24
    |
113 |     pub fn new_display<T: Display>(x: &T) -> Argument<'_> {
    |                        ^ required by the implicit `Sized` requirement on this type parameter in `Argument::<'_>::new_display`
    = note: this error originates in the macro `$crate::format_args` which comes from the expansion of the derive macro `Display` (in Nightly builds, run with -Z macro-backtrace for more info)
@tyranron tyranron added this to the 2.0.0 milestone Dec 30, 2024
@tyranron tyranron self-assigned this Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants