Skip to content

Commit 73fc7af

Browse files
committed
rustdoc: pass around decoration info by ref
1 parent cd805f0 commit 73fc7af

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/librustdoc/html/highlight.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub(super) fn write_code(
233233
out: &mut impl Write,
234234
src: &str,
235235
href_context: Option<HrefContext<'_, '_>>,
236-
decoration_info: Option<DecorationInfo>,
236+
decoration_info: Option<&DecorationInfo>,
237237
) {
238238
// This replace allows to fix how the code source with DOS backline characters is displayed.
239239
let src = src.replace("\r\n", "\n");
@@ -510,12 +510,12 @@ struct Decorations {
510510
}
511511

512512
impl Decorations {
513-
fn new(info: DecorationInfo) -> Self {
513+
fn new(info: &DecorationInfo) -> Self {
514514
// Extract tuples (start, end, kind) into separate sequences of (start, kind) and (end).
515515
let (mut starts, mut ends): (Vec<_>, Vec<_>) = info
516516
.0
517-
.into_iter()
518-
.flat_map(|(kind, ranges)| ranges.into_iter().map(move |(lo, hi)| ((lo, kind), hi)))
517+
.iter()
518+
.flat_map(|(&kind, ranges)| ranges.into_iter().map(move |&(lo, hi)| ((lo, kind), hi)))
519519
.unzip();
520520

521521
// Sort the sequences in document order.
@@ -542,7 +542,7 @@ struct Classifier<'src> {
542542
impl<'src> Classifier<'src> {
543543
/// Takes as argument the source code to HTML-ify, the rust edition to use and the source code
544544
/// file span which will be used later on by the `span_correspondence_map`.
545-
fn new(src: &str, file_span: Span, decoration_info: Option<DecorationInfo>) -> Classifier<'_> {
545+
fn new(src: &'src str, file_span: Span, decoration_info: Option<&DecorationInfo>) -> Self {
546546
let tokens = PeekIter::new(TokenIter { src, cursor: Cursor::new(src) });
547547
let decorations = decoration_info.map(Decorations::new);
548548
Classifier {

src/librustdoc/html/highlight/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ let a = 4;";
7878
decorations.insert("example2", vec![(22, 32)]);
7979

8080
let mut html = Buffer::new();
81-
write_code(&mut html, src, None, Some(DecorationInfo(decorations)));
81+
write_code(&mut html, src, None, Some(&DecorationInfo(decorations)));
8282
expect_file!["fixtures/decorations.html"].assert_eq(&html.into_inner());
8383
});
8484
}

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &Context<'_>, item: &clean
25772577
file_span,
25782578
cx,
25792579
&cx.root_path(),
2580-
highlight::DecorationInfo(decoration_info),
2580+
&highlight::DecorationInfo(decoration_info),
25812581
sources::SourceContext::Embedded(sources::ScrapedInfo {
25822582
needs_expansion,
25832583
offset: line_min,

src/librustdoc/html/sources.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl SourceCollector<'_, '_> {
249249
file_span,
250250
self.cx,
251251
&root_path,
252-
highlight::DecorationInfo::default(),
252+
&highlight::DecorationInfo::default(),
253253
SourceContext::Standalone { file_path },
254254
)
255255
},
@@ -328,7 +328,7 @@ pub(crate) fn print_src(
328328
file_span: rustc_span::Span,
329329
context: &Context<'_>,
330330
root_path: &str,
331-
decoration_info: highlight::DecorationInfo,
331+
decoration_info: &highlight::DecorationInfo,
332332
source_context: SourceContext<'_>,
333333
) {
334334
let current_href = context

0 commit comments

Comments
 (0)