Skip to content

Commit e89efb8

Browse files
Remove unneeded whitespace generation and use CSS instead instead to align line numbers to the right
1 parent a64180f commit e89efb8

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/librustdoc/html/sources.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,22 +272,16 @@ crate fn print_src(
272272
) {
273273
let lines = s.lines().count();
274274
let mut line_numbers = Buffer::empty_from(buf);
275-
let mut cols = 0;
276-
let mut tmp = lines;
277-
while tmp > 0 {
278-
cols += 1;
279-
tmp /= 10;
280-
}
281275
line_numbers.write_str("<pre class=\"line-numbers\">");
282276
match source_context {
283277
SourceContext::Standalone => {
284278
for line in 1..=lines {
285-
writeln!(line_numbers, "<span id=\"{0}\">{0:1$}</span>", line, cols)
279+
writeln!(line_numbers, "<span id=\"{0}\">{0}</span>", line)
286280
}
287281
}
288282
SourceContext::Embedded { offset } => {
289283
for line in 1..=lines {
290-
writeln!(line_numbers, "<span>{0:1$}</span>", line + offset, cols)
284+
writeln!(line_numbers, "<span>{0}</span>", line + offset)
291285
}
292286
}
293287
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,9 @@ h2.location a {
541541
text-decoration: underline;
542542
}
543543

544+
.line-numbers {
545+
text-align: right;
546+
}
544547
.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
545548
width: 100%;
546549
overflow-x: auto;

0 commit comments

Comments
 (0)