Skip to content

Fails when using #[doc = include_str!(...)] #36

@Nemo157

Description

@Nemo157
#[derive(displaydoc::Display)]
#[doc = include_str!("main.rs")]
pub struct Foo;

fn main() {
    println!("{}", Foo);
}

results in

   Compiling foo v0.1.0 (/tmp/tmp.0izm8rLLjV/foo)
error: expected literal
 --> src/main.rs:2:9
  |
2 | #[doc = include_str!("main.rs")]
  |         ^^^^^^^^^^^

error[E0277]: `Foo` doesn't implement `std::fmt::Display`
 --> src/main.rs:6:20
  |
6 |     println!("{}", Foo);
  |                    ^^^ `Foo` cannot be formatted with the default formatter
  |
  = help: the trait `std::fmt::Display` is not implemented for `Foo`
  = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
  = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `foo` due to 2 previous errors

I'm not sure whether this is possible to support with the formatting support; without it you can just replicate the include_str!(...) call into the output code, but I assume formatting requires parsing the string to detect the formatted fields since unused fields are an error. This could potentially be detected and a better error message emitted though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions