- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-rustdoc-uiArea: Rustdoc UI (generated HTML)Area: Rustdoc UI (generated HTML)C-bugCategory: This is a bug.Category: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.
Description
I tried this code:
pub struct WithConst<const N: usize>;
pub trait Trait<T> {}
macro_rules! spans_from_macro {
    () => {
        impl Trait<WithConst<42>> for WithConst<42> {}
        impl WithConst<42> {
            pub fn new() -> Self {
                Self
            }
        }
        pub struct Other {
            pub field: WithConst<42>,
        }
    };
}
// doc: impl Trait<WithConst<41>> for WithConst<41>
impl Trait<WithConst<41>> for WithConst<41> {}
// doc: impl Trait<WithConst<42>> for WithConst<{ _ }>
//      impl WithConst<{ _ }>
//      struct Other { pub field: WithConst<{ _ }> }
spans_from_macro!();I expected to see this happen: constants are formatted as either all { _ }, or all 42.
Instead, this happened: the one in the trait generic is formatted as the literal 42, while everywhere else it's formatted as { _ }.
I assume it's this:
rust/src/librustdoc/clean/utils.rs
Lines 436 to 438 in 8550f15
| if classification == Literal | |
| && !value.span.from_expansion() | |
| && let Ok(snippet) = tcx.sess.source_map().span_to_snippet(value.span) { | 
which can be expanded on to also format the literal if it's coming from a macro span by using the pretty printer.
Meta
rustc --version --verbose:
rustc 1.74.0-nightly (5c6a7e71c 2023-08-20)
binary: rustc
commit-hash: 5c6a7e71cd66705c31c9af94077901a220f0870c
commit-date: 2023-08-20
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0
Backtrace
N/A
@rustbot label A-rustdoc-ui T-rustdoc
Metadata
Metadata
Assignees
Labels
A-rustdoc-uiArea: Rustdoc UI (generated HTML)Area: Rustdoc UI (generated HTML)C-bugCategory: This is a bug.Category: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.