Description
I tried this code:
/// ```
/// define_component!(
/// #[derive(Debug)]
/// ##[min(0.0))]
/// ##[max(100.0))]
/// ##[default(50.0)]
/// pub Fuel(pub f32);
/// );
/// ```
macro_rules! define_component {
(
$(#[$attr:meta])*
##[min($min:expr)]
##[max($max:expr)]
##[default($default:expr)]
$self_vis:vis $self:ident($inner_vis:vis $inner:ty);
) => {};
}
The define_component
macro uses a single hash sign #
to represent a normal attribute (e.g. #[derive(Debug)]
), and uses a double hash sign ##
to represent an argument specific to that macro (e.g. ##[min(0.0)]
).
I ran cargo doc --document-private-items --open
and opened the generated define_component
page.
I expected to see this happen:
define_component!(
#[derive(Debug)]
##[min(0.0))]
##[max(100.0))]
##[default(50.0)]
pub Fuel(pub f32);
);
Instead, this happened:
define_component!(
#[derive(Debug)]
#[min(0.0))]
#[max(100.0))]
#[default(50.0)]
pub Fuel(pub f32);
);
##
were replaced by #
. (e.g. ##[min(0.0)]
became #[min(0.0)]
)
I think rustdoc should keep code blocks as written (except for coloring, etc.). This is because code blocks are generally expected to be enclosed in the HTML <pre>
tag, which defines preformatted text.
In other words, code blocks are preformatted and should be kept as written.
Perhaps the following code is related:
rust/src/librustdoc/html/markdown.rs
Lines 169 to 172 in 2831701
Workaround
If the doc comment starts with ```text
instead of ```
, this problem does not occur.
Meta
rustdoc --version --verbose
:
rustdoc 1.74.0 (79e9716c9 2023-11-13)
binary: rustdoc
commit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962
commit-date: 2023-11-13
host: x86_64-unknown-linux-gnu
release: 1.74.0
LLVM version: 17.0.4