Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 17780db

Browse files
committed
rustdoc: pass around decoration info by ref
1 parent a48e7b0 commit 17780db

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

src/librustdoc/html/highlight.rs

Lines changed: 5 additions & 5 deletions
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");
@@ -507,12 +507,12 @@ struct Decorations {
507507
}
508508

509509
impl Decorations {
510-
fn new(info: DecorationInfo) -> Self {
510+
fn new(info: &DecorationInfo) -> Self {
511511
// Extract tuples (start, end, kind) into separate sequences of (start, kind) and (end).
512512
let (mut starts, mut ends): (Vec<_>, Vec<_>) = info
513513
.0
514-
.into_iter()
515-
.flat_map(|(kind, ranges)| ranges.into_iter().map(move |(lo, hi)| ((lo, kind), hi)))
514+
.iter()
515+
.flat_map(|(&kind, ranges)| ranges.into_iter().map(move |&(lo, hi)| ((lo, kind), hi)))
516516
.unzip();
517517

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

src/librustdoc/html/highlight/tests.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

src/librustdoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![feature(rustc_private)]
66
#![feature(assert_matches)]
77
#![feature(box_patterns)]
8+
#![feature(debug_closure_helpers)]
89
#![feature(file_buffered)]
910
#![feature(if_let_guard)]
1011
#![feature(impl_trait_in_assoc_type)]

0 commit comments

Comments
 (0)