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 · May be fixed by #440
Open

Unsized tail fields in derive(Display) #432

dtolnay opened this issue Dec 27, 2024 · 0 comments · May be fixed by #440
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
@tyranron tyranron linked a pull request Jan 19, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy