@@ -14,20 +14,16 @@ use std::iter::Peekable;
1414use rustc_lexer:: { LiteralKind , TokenKind } ;
1515use rustc_span:: edition:: Edition ;
1616use rustc_span:: symbol:: Symbol ;
17+ use rustc_span:: { BytePos , Span , DUMMY_SP } ;
1718
1819use super :: format:: { self , Buffer } ;
19- use super :: render:: { LightSpan , LinkFromSrc } ;
20+ use super :: render:: LinkFromSrc ;
2021
2122/// This type is needed in case we want to render links on items to allow to go to their definition.
2223crate struct ContextInfo < ' a , ' b , ' c > {
2324 crate context : & ' a Context < ' b > ,
24- /// This represents the "lo" bytes of the current file we're rendering. To get a [`Span`] from
25- /// it, you just need to add add your current byte position in the string and its length (to get
26- /// the "hi" part).
27- ///
28- /// This is used to create a [`LightSpan`] which is then used as an index in the `span_map` in
29- /// order to retrieve the definition's [`Span`] (which is used to generate the URL).
30- crate file_span_lo : u32 ,
25+ /// This span contains the current file we're going through.
26+ crate file_span : Span ,
3127 /// This field is used to know "how far" from the top of the directory we are to link to either
3228 /// documentation pages or other source pages.
3329 crate root_path : & ' c str ,
@@ -86,7 +82,6 @@ fn write_header(out: &mut Buffer, class: Option<&str>, extra_content: Option<Buf
8682/// item definition.
8783///
8884/// More explanations about spans and how we use them here are provided in the
89- /// [`LightSpan::new_in_file`] function documentation about how it works.
9085fn write_code (
9186 out : & mut Buffer ,
9287 src : & str ,
@@ -95,7 +90,7 @@ fn write_code(
9590) {
9691 // This replace allows to fix how the code source with DOS backline characters is displayed.
9792 let src = src. replace ( "\r \n " , "\n " ) ;
98- Classifier :: new ( & src, edition, context_info. as_ref ( ) . map ( |c| c. file_span_lo ) . unwrap_or ( 0 ) )
93+ Classifier :: new ( & src, edition, context_info. as_ref ( ) . map ( |c| c. file_span ) . unwrap_or ( DUMMY_SP ) )
9994 . highlight ( & mut |highlight| {
10095 match highlight {
10196 Highlight :: Token { text, class } => string ( out, Escape ( text) , class, & context_info) ,
@@ -118,14 +113,14 @@ enum Class {
118113 KeyWord ,
119114 // Keywords that do pointer/reference stuff.
120115 RefKeyWord ,
121- Self_ ( LightSpan ) ,
116+ Self_ ( Span ) ,
122117 Op ,
123118 Macro ,
124119 MacroNonTerminal ,
125120 String ,
126121 Number ,
127122 Bool ,
128- Ident ( LightSpan ) ,
123+ Ident ( Span ) ,
129124 Lifetime ,
130125 PreludeTy ,
131126 PreludeVal ,
@@ -158,7 +153,7 @@ impl Class {
158153
159154 /// In case this is an item which can be converted into a link to a definition, it'll contain
160155 /// a "span" (a tuple representing `(lo, hi)` equivalent of `Span`).
161- fn get_span ( self ) -> Option < LightSpan > {
156+ fn get_span ( self ) -> Option < Span > {
162157 match self {
163158 Self :: Ident ( sp) | Self :: Self_ ( sp) => Some ( sp) ,
164159 _ => None ,
@@ -213,15 +208,14 @@ struct Classifier<'a> {
213208 in_macro_nonterminal : bool ,
214209 edition : Edition ,
215210 byte_pos : u32 ,
216- file_span_lo : u32 ,
211+ file_span : Span ,
217212 src : & ' a str ,
218213}
219214
220215impl < ' a > Classifier < ' a > {
221216 /// Takes as argument the source code to HTML-ify, the rust edition to use and the source code
222- /// file "lo" byte which we be used later on by the `span_correspondance_map`. More explanations
223- /// are provided in the [`LightSpan::new_in_file`] function documentation about how it works.
224- fn new ( src : & str , edition : Edition , file_span_lo : u32 ) -> Classifier < ' _ > {
217+ /// file span which will be used later on by the `span_correspondance_map`.
218+ fn new ( src : & str , edition : Edition , file_span : Span ) -> Classifier < ' _ > {
225219 let tokens = TokenIter { src } . peekable ( ) ;
226220 Classifier {
227221 tokens,
@@ -230,15 +224,16 @@ impl<'a> Classifier<'a> {
230224 in_macro_nonterminal : false ,
231225 edition,
232226 byte_pos : 0 ,
233- file_span_lo ,
227+ file_span ,
234228 src,
235229 }
236230 }
237231
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)
232+ /// Convenient wrapper to create a [`Span`] from a position in the file.
233+ fn new_span ( & self , lo : u32 , text : & str ) -> Span {
234+ let hi = lo + text. len ( ) as u32 ;
235+ let file_lo = self . file_span . lo ( ) ;
236+ self . file_span . with_lo ( file_lo + BytePos ( lo) ) . with_hi ( file_lo + BytePos ( hi) )
242237 }
243238
244239 /// Concatenate colons and idents as one when possible.
@@ -487,15 +482,13 @@ impl<'a> Classifier<'a> {
487482 self . in_macro_nonterminal = false ;
488483 Class :: MacroNonTerminal
489484 }
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 ) ) ,
485+ "self" | "Self" => Class :: Self_ ( self . new_span ( before, text) ) ,
486+ _ => Class :: Ident ( self . new_span ( before, text) ) ,
494487 } ,
495488 Some ( c) => c,
496489 } ,
497490 TokenKind :: RawIdent | TokenKind :: UnknownPrefix => {
498- Class :: Ident ( self . new_light_span ( before, before + text. len ( ) as u32 ) )
491+ Class :: Ident ( self . new_span ( before, text) )
499492 }
500493 TokenKind :: Lifetime { .. } => Class :: Lifetime ,
501494 } ;
@@ -560,7 +553,7 @@ fn string<T: Display>(
560553 "self" | "Self" => write ! (
561554 & mut path,
562555 "<span class=\" {}\" >{}</span>" ,
563- Class :: Self_ ( LightSpan :: dummy ( ) ) . as_html( ) ,
556+ Class :: Self_ ( DUMMY_SP ) . as_html( ) ,
564557 t
565558 ) ,
566559 "crate" | "super" => {
0 commit comments