Skip to content

Commit 1a43beb

Browse files
authored
Rollup merge of #105530 - Nilstrieb:rustdoc-highlight-less-lifetimes, r=GuillaumeGomez
Clean up lifetimes in rustdoc syntax highlighting Removes a few lifetimes and renames some. r? ``@GuillaumeGomez``
2 parents 97aa7cb + 4850450 commit 1a43beb

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/librustdoc/html/highlight.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ use rustc_span::{BytePos, Span, DUMMY_SP};
2121
use super::format::{self, Buffer};
2222

2323
/// This type is needed in case we want to render links on items to allow to go to their definition.
24-
pub(crate) struct HrefContext<'a, 'b, 'c> {
25-
pub(crate) context: &'a Context<'b>,
24+
pub(crate) struct HrefContext<'a, 'tcx> {
25+
pub(crate) context: &'a Context<'tcx>,
2626
/// This span contains the current file we're going through.
2727
pub(crate) file_span: Span,
2828
/// This field is used to know "how far" from the top of the directory we are to link to either
2929
/// documentation pages or other source pages.
30-
pub(crate) root_path: &'c str,
30+
pub(crate) root_path: &'a str,
3131
/// This field is used to calculate precise local URLs.
32-
pub(crate) current_href: &'c str,
32+
pub(crate) current_href: String,
3333
}
3434

3535
/// Decorations are represented as a map from CSS class to vector of character ranges.
@@ -70,7 +70,7 @@ pub(crate) fn render_source_with_highlighting(
7070
src: &str,
7171
out: &mut Buffer,
7272
line_numbers: Buffer,
73-
href_context: HrefContext<'_, '_, '_>,
73+
href_context: HrefContext<'_, '_>,
7474
decoration_info: DecorationInfo,
7575
extra: Option<&str>,
7676
) {
@@ -137,7 +137,7 @@ fn can_merge(class1: Option<Class>, class2: Option<Class>, text: &str) -> bool {
137137

138138
/// This type is used as a conveniency to prevent having to pass all its fields as arguments into
139139
/// the various functions (which became its methods).
140-
struct TokenHandler<'a, 'b, 'c, 'd, 'e> {
140+
struct TokenHandler<'a, 'tcx> {
141141
out: &'a mut Buffer,
142142
/// It contains the closing tag and the associated `Class`.
143143
closing_tags: Vec<(&'static str, Class)>,
@@ -149,11 +149,11 @@ struct TokenHandler<'a, 'b, 'c, 'd, 'e> {
149149
current_class: Option<Class>,
150150
/// We need to keep the `Class` for each element because it could contain a `Span` which is
151151
/// used to generate links.
152-
pending_elems: Vec<(&'b str, Option<Class>)>,
153-
href_context: Option<HrefContext<'c, 'd, 'e>>,
152+
pending_elems: Vec<(&'a str, Option<Class>)>,
153+
href_context: Option<HrefContext<'a, 'tcx>>,
154154
}
155155

156-
impl<'a, 'b, 'c, 'd, 'e> TokenHandler<'a, 'b, 'c, 'd, 'e> {
156+
impl<'a, 'tcx> TokenHandler<'a, 'tcx> {
157157
fn handle_exit_span(&mut self) {
158158
// We can't get the last `closing_tags` element using `pop()` because `closing_tags` is
159159
// being used in `write_pending_elems`.
@@ -205,7 +205,7 @@ impl<'a, 'b, 'c, 'd, 'e> TokenHandler<'a, 'b, 'c, 'd, 'e> {
205205
}
206206
}
207207

208-
impl<'a, 'b, 'c, 'd, 'e> Drop for TokenHandler<'a, 'b, 'c, 'd, 'e> {
208+
impl<'a, 'tcx> Drop for TokenHandler<'a, 'tcx> {
209209
/// When leaving, we need to flush all pending data to not have missing content.
210210
fn drop(&mut self) {
211211
if self.pending_exit_span.is_some() {
@@ -230,7 +230,7 @@ impl<'a, 'b, 'c, 'd, 'e> Drop for TokenHandler<'a, 'b, 'c, 'd, 'e> {
230230
fn write_code(
231231
out: &mut Buffer,
232232
src: &str,
233-
href_context: Option<HrefContext<'_, '_, '_>>,
233+
href_context: Option<HrefContext<'_, '_>>,
234234
decoration_info: Option<DecorationInfo>,
235235
) {
236236
// This replace allows to fix how the code source with DOS backline characters is displayed.
@@ -514,18 +514,18 @@ impl Decorations {
514514

515515
/// Processes program tokens, classifying strings of text by highlighting
516516
/// category (`Class`).
517-
struct Classifier<'a> {
518-
tokens: PeekIter<'a>,
517+
struct Classifier<'src> {
518+
tokens: PeekIter<'src>,
519519
in_attribute: bool,
520520
in_macro: bool,
521521
in_macro_nonterminal: bool,
522522
byte_pos: u32,
523523
file_span: Span,
524-
src: &'a str,
524+
src: &'src str,
525525
decorations: Option<Decorations>,
526526
}
527527

528-
impl<'a> Classifier<'a> {
528+
impl<'src> Classifier<'src> {
529529
/// Takes as argument the source code to HTML-ify, the rust edition to use and the source code
530530
/// file span which will be used later on by the `span_correspondance_map`.
531531
fn new(src: &str, file_span: Span, decoration_info: Option<DecorationInfo>) -> Classifier<'_> {
@@ -603,7 +603,7 @@ impl<'a> Classifier<'a> {
603603
///
604604
/// It returns the token's kind, the token as a string and its byte position in the source
605605
/// string.
606-
fn next(&mut self) -> Option<(TokenKind, &'a str, u32)> {
606+
fn next(&mut self) -> Option<(TokenKind, &'src str, u32)> {
607607
if let Some((kind, text)) = self.tokens.next() {
608608
let before = self.byte_pos;
609609
self.byte_pos += text.len() as u32;
@@ -618,7 +618,7 @@ impl<'a> Classifier<'a> {
618618
/// The general structure for this method is to iterate over each token,
619619
/// possibly giving it an HTML span with a class specifying what flavor of
620620
/// token is used.
621-
fn highlight(mut self, sink: &mut dyn FnMut(Highlight<'a>)) {
621+
fn highlight(mut self, sink: &mut dyn FnMut(Highlight<'src>)) {
622622
loop {
623623
if let Some(decs) = self.decorations.as_mut() {
624624
let byte_pos = self.byte_pos;
@@ -666,8 +666,8 @@ impl<'a> Classifier<'a> {
666666
fn advance(
667667
&mut self,
668668
token: TokenKind,
669-
text: &'a str,
670-
sink: &mut dyn FnMut(Highlight<'a>),
669+
text: &'src str,
670+
sink: &mut dyn FnMut(Highlight<'src>),
671671
before: u32,
672672
) {
673673
let lookahead = self.peek();
@@ -881,7 +881,7 @@ impl<'a> Classifier<'a> {
881881
fn enter_span(
882882
out: &mut Buffer,
883883
klass: Class,
884-
href_context: &Option<HrefContext<'_, '_, '_>>,
884+
href_context: &Option<HrefContext<'_, '_>>,
885885
) -> &'static str {
886886
string_without_closing_tag(out, "", Some(klass), href_context, true).expect(
887887
"internal error: enter_span was called with Some(klass) but did not return a \
@@ -914,7 +914,7 @@ fn string<T: Display>(
914914
out: &mut Buffer,
915915
text: T,
916916
klass: Option<Class>,
917-
href_context: &Option<HrefContext<'_, '_, '_>>,
917+
href_context: &Option<HrefContext<'_, '_>>,
918918
open_tag: bool,
919919
) {
920920
if let Some(closing_tag) = string_without_closing_tag(out, text, klass, href_context, open_tag)
@@ -936,7 +936,7 @@ fn string_without_closing_tag<T: Display>(
936936
out: &mut Buffer,
937937
text: T,
938938
klass: Option<Class>,
939-
href_context: &Option<HrefContext<'_, '_, '_>>,
939+
href_context: &Option<HrefContext<'_, '_>>,
940940
open_tag: bool,
941941
) -> Option<&'static str> {
942942
let Some(klass) = klass
@@ -985,7 +985,7 @@ fn string_without_closing_tag<T: Display>(
985985
// https://github.com/rust-lang/rust/blob/60f1a2fc4b535ead9c85ce085fdce49b1b097531/src/librustdoc/html/render/context.rs#L315-L338
986986
match href {
987987
LinkFromSrc::Local(span) => {
988-
context.href_from_span_relative(*span, href_context.current_href)
988+
context.href_from_span_relative(*span, &href_context.current_href)
989989
}
990990
LinkFromSrc::External(def_id) => {
991991
format::href_with_root_path(*def_id, context, Some(href_context.root_path))

src/librustdoc/html/sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub(crate) fn print_src(
276276
let mut line_numbers = Buffer::empty_from(buf);
277277
let extra;
278278
line_numbers.write_str("<pre class=\"src-line-numbers\">");
279-
let current_href = &context
279+
let current_href = context
280280
.href_from_span(clean::Span::new(file_span), false)
281281
.expect("only local crates should have sources emitted");
282282
match source_context {

0 commit comments

Comments
 (0)