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

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

Open
Nemo157 opened this issue Sep 29, 2021 · 0 comments
Open

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

Nemo157 opened this issue Sep 29, 2021 · 0 comments

Comments

@Nemo157
Copy link

Nemo157 commented Sep 29, 2021

#[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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant