Skip to content

Commit 0799528

Browse files
* Rename LightSpan::empty into LightSpan::dummy
* Add Classifier::new_light_span to wrap LightSpan::new_in_file constructor
1 parent fd69fa8 commit 0799528

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/librustdoc/html/highlight.rs

+18-22
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ impl<'a> Classifier<'a> {
235235
}
236236
}
237237

238+
/// Convenient wrapper around [`LightSpan::new_in_file`] to prevent passing the `file_span_lo`
239+
/// argument every time.
240+
fn new_light_span(&self, lo: u32, hi: u32) -> LightSpan {
241+
LightSpan::new_in_file(self.file_span_lo, lo, hi)
242+
}
243+
238244
/// Concatenate colons and idents as one when possible.
239245
fn get_full_ident_path(&mut self) -> Vec<(TokenKind, usize, usize)> {
240246
let start = self.byte_pos as usize;
@@ -313,14 +319,12 @@ impl<'a> Classifier<'a> {
313319
.unwrap_or(false)
314320
{
315321
let tokens = self.get_full_ident_path();
316-
// We need this variable because `tokens` is consumed in the loop.
317-
let skip = !tokens.is_empty();
318-
for (token, start, end) in tokens {
319-
let text = &self.src[start..end];
320-
self.advance(token, text, sink, start as u32);
322+
for (token, start, end) in &tokens {
323+
let text = &self.src[*start..*end];
324+
self.advance(*token, text, sink, *start as u32);
321325
self.byte_pos += text.len() as u32;
322326
}
323-
if skip {
327+
if !tokens.is_empty() {
324328
continue;
325329
}
326330
}
@@ -483,24 +487,16 @@ impl<'a> Classifier<'a> {
483487
self.in_macro_nonterminal = false;
484488
Class::MacroNonTerminal
485489
}
486-
"self" | "Self" => Class::Self_(LightSpan::new_in_file(
487-
self.file_span_lo,
488-
before,
489-
before + text.len() as u32,
490-
)),
491-
_ => Class::Ident(LightSpan::new_in_file(
492-
self.file_span_lo,
493-
before,
494-
before + text.len() as u32,
495-
)),
490+
"self" | "Self" => {
491+
Class::Self_(self.new_light_span(before, before + text.len() as u32))
492+
}
493+
_ => Class::Ident(self.new_light_span(before, before + text.len() as u32)),
496494
},
497495
Some(c) => c,
498496
},
499-
TokenKind::RawIdent | TokenKind::UnknownPrefix => Class::Ident(LightSpan::new_in_file(
500-
self.file_span_lo,
501-
before,
502-
before + text.len() as u32,
503-
)),
497+
TokenKind::RawIdent | TokenKind::UnknownPrefix => {
498+
Class::Ident(self.new_light_span(before, before + text.len() as u32))
499+
}
504500
TokenKind::Lifetime { .. } => Class::Lifetime,
505501
};
506502
// Anything that didn't return above is the simple case where we the
@@ -564,7 +560,7 @@ fn string<T: Display>(
564560
"self" | "Self" => write!(
565561
&mut path,
566562
"<span class=\"{}\">{}</span>",
567-
Class::Self_(LightSpan::empty()).as_html(),
563+
Class::Self_(LightSpan::dummy()).as_html(),
568564
t
569565
),
570566
"crate" | "super" => {

src/librustdoc/html/render/span_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl LightSpan {
5151
Self { lo: lo + file_span_lo, hi: hi + file_span_lo }
5252
}
5353

54-
crate fn empty() -> Self {
54+
crate fn dummy() -> Self {
5555
Self { lo: 0, hi: 0 }
5656
}
5757

0 commit comments

Comments
 (0)