@@ -14,20 +14,16 @@ use std::iter::Peekable;
14
14
use rustc_lexer:: { LiteralKind , TokenKind } ;
15
15
use rustc_span:: edition:: Edition ;
16
16
use rustc_span:: symbol:: Symbol ;
17
+ use rustc_span:: { BytePos , Span , DUMMY_SP } ;
17
18
18
19
use super :: format:: { self , Buffer } ;
19
- use super :: render:: { LightSpan , LinkFromSrc } ;
20
+ use super :: render:: LinkFromSrc ;
20
21
21
22
/// This type is needed in case we want to render links on items to allow to go to their definition.
22
23
crate struct ContextInfo < ' a , ' b , ' c > {
23
24
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 ,
31
27
/// This field is used to know "how far" from the top of the directory we are to link to either
32
28
/// documentation pages or other source pages.
33
29
crate root_path : & ' c str ,
@@ -86,7 +82,6 @@ fn write_header(out: &mut Buffer, class: Option<&str>, extra_content: Option<Buf
86
82
/// item definition.
87
83
///
88
84
/// 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.
90
85
fn write_code (
91
86
out : & mut Buffer ,
92
87
src : & str ,
@@ -95,7 +90,7 @@ fn write_code(
95
90
) {
96
91
// This replace allows to fix how the code source with DOS backline characters is displayed.
97
92
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 ) )
99
94
. highlight ( & mut |highlight| {
100
95
match highlight {
101
96
Highlight :: Token { text, class } => string ( out, Escape ( text) , class, & context_info) ,
@@ -118,14 +113,14 @@ enum Class {
118
113
KeyWord ,
119
114
// Keywords that do pointer/reference stuff.
120
115
RefKeyWord ,
121
- Self_ ( LightSpan ) ,
116
+ Self_ ( Span ) ,
122
117
Op ,
123
118
Macro ,
124
119
MacroNonTerminal ,
125
120
String ,
126
121
Number ,
127
122
Bool ,
128
- Ident ( LightSpan ) ,
123
+ Ident ( Span ) ,
129
124
Lifetime ,
130
125
PreludeTy ,
131
126
PreludeVal ,
@@ -158,7 +153,7 @@ impl Class {
158
153
159
154
/// In case this is an item which can be converted into a link to a definition, it'll contain
160
155
/// a "span" (a tuple representing `(lo, hi)` equivalent of `Span`).
161
- fn get_span ( self ) -> Option < LightSpan > {
156
+ fn get_span ( self ) -> Option < Span > {
162
157
match self {
163
158
Self :: Ident ( sp) | Self :: Self_ ( sp) => Some ( sp) ,
164
159
_ => None ,
@@ -213,15 +208,14 @@ struct Classifier<'a> {
213
208
in_macro_nonterminal : bool ,
214
209
edition : Edition ,
215
210
byte_pos : u32 ,
216
- file_span_lo : u32 ,
211
+ file_span : Span ,
217
212
src : & ' a str ,
218
213
}
219
214
220
215
impl < ' a > Classifier < ' a > {
221
216
/// 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 < ' _ > {
225
219
let tokens = TokenIter { src } . peekable ( ) ;
226
220
Classifier {
227
221
tokens,
@@ -230,15 +224,16 @@ impl<'a> Classifier<'a> {
230
224
in_macro_nonterminal : false ,
231
225
edition,
232
226
byte_pos : 0 ,
233
- file_span_lo ,
227
+ file_span ,
234
228
src,
235
229
}
236
230
}
237
231
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) )
242
237
}
243
238
244
239
/// Concatenate colons and idents as one when possible.
@@ -487,15 +482,13 @@ impl<'a> Classifier<'a> {
487
482
self . in_macro_nonterminal = false ;
488
483
Class :: MacroNonTerminal
489
484
}
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) ) ,
494
487
} ,
495
488
Some ( c) => c,
496
489
} ,
497
490
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) )
499
492
}
500
493
TokenKind :: Lifetime { .. } => Class :: Lifetime ,
501
494
} ;
@@ -560,7 +553,7 @@ fn string<T: Display>(
560
553
"self" | "Self" => write ! (
561
554
& mut path,
562
555
"<span class=\" {}\" >{}</span>" ,
563
- Class :: Self_ ( LightSpan :: dummy ( ) ) . as_html( ) ,
556
+ Class :: Self_ ( DUMMY_SP ) . as_html( ) ,
564
557
t
565
558
) ,
566
559
"crate" | "super" => {
0 commit comments