Skip to content

Commit cb3a04b

Browse files
committed
rustdoc: avoid excessive HTML generated in example sources
1 parent ba4ae13 commit cb3a04b

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/librustdoc/html/render/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2899,11 +2899,7 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
28992899
cx,
29002900
&cx.root_path(),
29012901
highlight::DecorationInfo(decoration_info),
2902-
sources::SourceContext::Embedded {
2903-
url: &call_data.url,
2904-
offset: line_min,
2905-
needs_expansion,
2906-
},
2902+
sources::SourceContext::Embedded { offset: line_min, needs_expansion },
29072903
);
29082904
write!(w, "</div></div>");
29092905

src/librustdoc/html/sources.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ where
256256
}
257257
}
258258

259-
pub(crate) enum SourceContext<'a> {
259+
pub(crate) enum SourceContext {
260260
Standalone,
261-
Embedded { url: &'a str, offset: usize, needs_expansion: bool },
261+
Embedded { offset: usize, needs_expansion: bool },
262262
}
263263

264264
/// Wrapper struct to render the source code of a file. This will do things like
@@ -270,7 +270,7 @@ pub(crate) fn print_src(
270270
context: &Context<'_>,
271271
root_path: &str,
272272
decoration_info: highlight::DecorationInfo,
273-
source_context: SourceContext<'_>,
273+
source_context: SourceContext,
274274
) {
275275
let lines = s.lines().count();
276276
let mut line_numbers = Buffer::empty_from(buf);
@@ -286,12 +286,12 @@ pub(crate) fn print_src(
286286
writeln!(line_numbers, "<a href=\"#{line}\" id=\"{line}\">{line}</a>")
287287
}
288288
}
289-
SourceContext::Embedded { url, offset, needs_expansion } => {
289+
SourceContext::Embedded { offset, needs_expansion } => {
290290
extra =
291291
if needs_expansion { Some(r#"<span class="expand">&varr;</span>"#) } else { None };
292292
for line_number in 1..=lines {
293293
let line = line_number + offset;
294-
writeln!(line_numbers, "<a href=\"{root_path}{url}#{line}\">{line}</a>")
294+
writeln!(line_numbers, "<span>{line}</span>")
295295
}
296296
}
297297
}

src/librustdoc/html/static/css/rustdoc.css

+3-2
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ ul.block, .block li {
575575
border-color: var(--example-line-numbers-border-color);
576576
}
577577

578-
.src-line-numbers a {
578+
.src-line-numbers a, .src-line-numbers span {
579579
color: var(--src-line-numbers-span-color);
580580
}
581581
.src-line-numbers :target {
@@ -2061,7 +2061,8 @@ in storage.js
20612061
padding: 14px 0;
20622062
}
20632063

2064-
.scraped-example .code-wrapper .src-line-numbers a {
2064+
.scraped-example .code-wrapper .src-line-numbers a,
2065+
.scraped-example .code-wrapper .src-line-numbers span {
20652066
padding: 0 14px;
20662067
}
20672068

0 commit comments

Comments
 (0)