diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2021-07-13 15:28:43 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2021-08-05 23:08:29 +0200 |
| commit | 0799528db785e49ad13044aac193b8be2153e202 (patch) | |
| tree | 0debe8a278d1e22e2bf7c94b45c4bd72f14cfd08 | |
| parent | fd69fa8670aaf67cde504acd097a2b4ddc74f88a (diff) | |
| download | rust-0799528db785e49ad13044aac193b8be2153e202.tar.gz rust-0799528db785e49ad13044aac193b8be2153e202.zip | |
* Rename LightSpan::empty into LightSpan::dummy
* Add Classifier::new_light_span to wrap LightSpan::new_in_file constructor
| -rw-r--r-- | src/librustdoc/html/highlight.rs | 40 | ||||
| -rw-r--r-- | src/librustdoc/html/render/span_map.rs | 2 |
2 files changed, 19 insertions, 23 deletions
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 47c870645ac..4555d98d2bf 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -235,6 +235,12 @@ impl<'a> Classifier<'a> { } } + /// Convenient wrapper around [`LightSpan::new_in_file`] to prevent passing the `file_span_lo` + /// argument every time. + fn new_light_span(&self, lo: u32, hi: u32) -> LightSpan { + LightSpan::new_in_file(self.file_span_lo, lo, hi) + } + /// Concatenate colons and idents as one when possible. fn get_full_ident_path(&mut self) -> Vec<(TokenKind, usize, usize)> { let start = self.byte_pos as usize; @@ -313,14 +319,12 @@ impl<'a> Classifier<'a> { .unwrap_or(false) { let tokens = self.get_full_ident_path(); - // We need this variable because `tokens` is consumed in the loop. - let skip = !tokens.is_empty(); - for (token, start, end) in tokens { - let text = &self.src[start..end]; - self.advance(token, text, sink, start as u32); + for (token, start, end) in &tokens { + let text = &self.src[*start..*end]; + self.advance(*token, text, sink, *start as u32); self.byte_pos += text.len() as u32; } - if skip { + if !tokens.is_empty() { continue; } } @@ -483,24 +487,16 @@ impl<'a> Classifier<'a> { self.in_macro_nonterminal = false; Class::MacroNonTerminal } - "self" | "Self" => Class::Self_(LightSpan::new_in_file( - self.file_span_lo, - before, - before + text.len() as u32, - )), - _ => Class::Ident(LightSpan::new_in_file( - self.file_span_lo, - before, - before + text.len() as u32, - )), + "self" | "Self" => { + Class::Self_(self.new_light_span(before, before + text.len() as u32)) + } + _ => Class::Ident(self.new_light_span(before, before + text.len() as u32)), }, Some(c) => c, }, - TokenKind::RawIdent | TokenKind::UnknownPrefix => Class::Ident(LightSpan::new_in_file( - self.file_span_lo, - before, - before + text.len() as u32, - )), + TokenKind::RawIdent | TokenKind::UnknownPrefix => { + Class::Ident(self.new_light_span(before, before + text.len() as u32)) + } TokenKind::Lifetime { .. } => Class::Lifetime, }; // Anything that didn't return above is the simple case where we the @@ -564,7 +560,7 @@ fn string<T: Display>( "self" | "Self" => write!( &mut path, "<span class=\"{}\">{}</span>", - Class::Self_(LightSpan::empty()).as_html(), + Class::Self_(LightSpan::dummy()).as_html(), t ), "crate" | "super" => { diff --git a/src/librustdoc/html/render/span_map.rs b/src/librustdoc/html/render/span_map.rs index b60f5f433f7..390ac88faf0 100644 --- a/src/librustdoc/html/render/span_map.rs +++ b/src/librustdoc/html/render/span_map.rs @@ -51,7 +51,7 @@ impl LightSpan { Self { lo: lo + file_span_lo, hi: hi + file_span_lo } } - crate fn empty() -> Self { + crate fn dummy() -> Self { Self { lo: 0, hi: 0 } } |
