rustdoc: pass around decoration info by ref

This commit is contained in:
Yotam Ofek 2025-01-14 11:45:21 +00:00
parent cd805f09ff
commit 73fc7af716
4 changed files with 9 additions and 9 deletions

View file

@ -233,7 +233,7 @@ pub(super) fn write_code(
out: &mut impl Write,
src: &str,
href_context: Option<HrefContext<'_, '_>>,
decoration_info: Option<DecorationInfo>,
decoration_info: Option<&DecorationInfo>,
) {
// This replace allows to fix how the code source with DOS backline characters is displayed.
let src = src.replace("\r\n", "\n");
@ -510,12 +510,12 @@ struct Decorations {
}
impl Decorations {
fn new(info: DecorationInfo) -> Self {
fn new(info: &DecorationInfo) -> Self {
// Extract tuples (start, end, kind) into separate sequences of (start, kind) and (end).
let (mut starts, mut ends): (Vec<_>, Vec<_>) = info
.0
.into_iter()
.flat_map(|(kind, ranges)| ranges.into_iter().map(move |(lo, hi)| ((lo, kind), hi)))
.iter()
.flat_map(|(&kind, ranges)| ranges.into_iter().map(move |&(lo, hi)| ((lo, kind), hi)))
.unzip();
// Sort the sequences in document order.
@ -542,7 +542,7 @@ struct Classifier<'src> {
impl<'src> Classifier<'src> {
/// Takes as argument the source code to HTML-ify, the rust edition to use and the source code
/// file span which will be used later on by the `span_correspondence_map`.
fn new(src: &str, file_span: Span, decoration_info: Option<DecorationInfo>) -> Classifier<'_> {
fn new(src: &'src str, file_span: Span, decoration_info: Option<&DecorationInfo>) -> Self {
let tokens = PeekIter::new(TokenIter { src, cursor: Cursor::new(src) });
let decorations = decoration_info.map(Decorations::new);
Classifier {

View file

@ -78,7 +78,7 @@ let a = 4;";
decorations.insert("example2", vec![(22, 32)]);
let mut html = Buffer::new();
write_code(&mut html, src, None, Some(DecorationInfo(decorations)));
write_code(&mut html, src, None, Some(&DecorationInfo(decorations)));
expect_file!["fixtures/decorations.html"].assert_eq(&html.into_inner());
});
}

View file

@ -2577,7 +2577,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &Context<'_>, item: &clean
file_span,
cx,
&cx.root_path(),
highlight::DecorationInfo(decoration_info),
&highlight::DecorationInfo(decoration_info),
sources::SourceContext::Embedded(sources::ScrapedInfo {
needs_expansion,
offset: line_min,

View file

@ -249,7 +249,7 @@ impl SourceCollector<'_, '_> {
file_span,
self.cx,
&root_path,
highlight::DecorationInfo::default(),
&highlight::DecorationInfo::default(),
SourceContext::Standalone { file_path },
)
},
@ -328,7 +328,7 @@ pub(crate) fn print_src(
file_span: rustc_span::Span,
context: &Context<'_>,
root_path: &str,
decoration_info: highlight::DecorationInfo,
decoration_info: &highlight::DecorationInfo,
source_context: SourceContext<'_>,
) {
let current_href = context