Repository navigation
Report a non-literal #[doc = ...] instead of skipping it - #71
Merged
Merged
Conversation
Manishearth
reviewed
Oct 22, 2026
| { | ||
| return Err(syn::Error::new_spanned( | ||
| value, | ||
| "displaydoc can only read doc comments that are string literals; give the format with #[displaydoc(\"...\")] instead", |
Collaborator
There was a problem hiding this comment.
Suggested change
| "displaydoc can only read doc comments that are string literals; give the format with #[displaydoc(\"...\")] instead", | |
| "displaydoc can only read doc comments that are string literals; supply the Display text with #[displaydoc(\"...\")] instead", |
Contributor
Author
|
applied it, and updated tests/ui/non_string_doc_expr.stderr to match. the ui tests pass on nightly |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #61.
A
#[doc = ...]whose value isn't a string literal, such as#[doc = include_str!("...")], used to make the derive panic with "not implemented". Since #69, which I wrote to skip#[doc(alias = "...")]and#[doc(hidden)], it's skipped silently instead. That's arguably worse here: a struct then gets noDisplayimpl at all, and the error only shows up wherever the type is formatted, as "Foodoesn't implementstd::fmt::Display".display()now returns a compile error, spanned on the value, when a#[doc = ...]value isn't a string literal:A type with
#[displaydoc("...")]is unaffected, since that attribute is read first. #69 isn't released yet, so compared with 0.2.7 this replaces the panic with a proper error.Tests:
tests/ui/non_string_doc_expr.rswith its.stderr, added tocompile_tests.rs. On master the file compiles, because the derive skips the attribute and emits nothing, so thecompile_failcase fails there.cargo teston stable 1.99.1 passes (the UI tests are ignored off nightly). The UI tests pass on nightly-2026-10-22.cargo fmt --checkandcargo clippy --all-targetsare clean.CHANGELOG.mdhas an entry under Unreleased.