derive_more icon indicating copy to clipboard operation
derive_more copied to clipboard

Invalid syntax in Display fmt fails silently

Open krallin opened this issue 3 years ago • 3 comments
trafficstars

Consider this code:

use derive_more::Display;

#[derive(Display)]
#[display(fmt = "Stuff({})", .bar)]
pub struct Foo {
    bar: String
}

fn main() {
    println!("{}", Foo { bar: "test".into() });
}

This prints just test. Similarly, if you do this, it still prints test:

#[derive(Display)]
#[display(fmt = "Stuff({})", .barrrrrrr)]
pub struct Foo {
    bar: String
}

The correct syntax here would be to use just bar in the format, but that's not super obvious since no error is raised.

Perhaps this could be fixed to inform the user that the format is just wrong?

Thanks!

krallin avatar Feb 22 '22 13:02 krallin

cc @ilslv

tyranron avatar Feb 24 '22 15:02 tyranron

@tyranron should we add trybuild to test invalid inputs?

ilslv avatar Feb 25 '22 08:02 ilslv

@ilslv seems reasonable.

tyranron avatar Feb 25 '22 08:02 tyranron