@@ -9,7 +9,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
9
9
use rustc_hir:: def_id:: LOCAL_CRATE ;
10
10
use rustc_middle:: ty:: TyCtxt ;
11
11
use rustc_session:: Session ;
12
- use rustc_span:: { FileName , sym} ;
12
+ use rustc_span:: { FileName , FileNameDisplayPreference , RealFileName , sym} ;
13
13
use tracing:: info;
14
14
15
15
use crate :: clean;
@@ -50,8 +50,14 @@ struct LocalSourcesCollector<'a, 'tcx> {
50
50
src_root : & ' a Path ,
51
51
}
52
52
53
- fn is_real_and_local ( span : clean:: Span , sess : & Session ) -> bool {
54
- span. cnum ( sess) == LOCAL_CRATE && span. filename ( sess) . is_real ( )
53
+ fn filename_real_and_local ( span : clean:: Span , sess : & Session ) -> Option < RealFileName > {
54
+ if span. cnum ( sess) == LOCAL_CRATE
55
+ && let FileName :: Real ( file) = span. filename ( sess)
56
+ {
57
+ Some ( file)
58
+ } else {
59
+ None
60
+ }
55
61
}
56
62
57
63
impl LocalSourcesCollector < ' _ , ' _ > {
@@ -60,16 +66,8 @@ impl LocalSourcesCollector<'_, '_> {
60
66
let span = item. span ( self . tcx ) ;
61
67
let Some ( span) = span else { return } ;
62
68
// skip all synthetic "files"
63
- if !is_real_and_local ( span, sess) {
64
- return ;
65
- }
66
- let filename = span. filename ( sess) ;
67
- let p = if let FileName :: Real ( file) = filename {
68
- match file. into_local_path ( ) {
69
- Some ( p) => p,
70
- None => return ,
71
- }
72
- } else {
69
+ let Some ( p) = filename_real_and_local ( span, sess) . and_then ( |file| file. into_local_path ( ) )
70
+ else {
73
71
return ;
74
72
} ;
75
73
if self . local_sources . contains_key ( & * p) {
@@ -135,8 +133,7 @@ impl DocVisitor<'_> for SourceCollector<'_, '_> {
135
133
// If we're not rendering sources, there's nothing to do.
136
134
// If we're including source files, and we haven't seen this file yet,
137
135
// then we need to render it out to the filesystem.
138
- if is_real_and_local ( span, sess) {
139
- let filename = span. filename ( sess) ;
136
+ if let Some ( filename) = filename_real_and_local ( span, sess) {
140
137
let span = span. inner ( ) ;
141
138
let pos = sess. source_map ( ) . lookup_source_file ( span. lo ( ) ) ;
142
139
let file_span = span. with_lo ( pos. start_pos ) . with_hi ( pos. end_position ( ) ) ;
@@ -152,7 +149,7 @@ impl DocVisitor<'_> for SourceCollector<'_, '_> {
152
149
span,
153
150
format ! (
154
151
"failed to render source code for `{filename}`: {e}" ,
155
- filename = filename. prefer_local ( ) ,
152
+ filename = filename. to_string_lossy ( FileNameDisplayPreference :: Local ) ,
156
153
) ,
157
154
) ;
158
155
false
@@ -168,18 +165,13 @@ impl SourceCollector<'_, '_> {
168
165
/// Renders the given filename into its corresponding HTML source file.
169
166
fn emit_source (
170
167
& mut self ,
171
- filename : & FileName ,
168
+ file : & RealFileName ,
172
169
file_span : rustc_span:: Span ,
173
170
) -> Result < ( ) , Error > {
174
- let p = match * filename {
175
- FileName :: Real ( ref file) => {
176
- if let Some ( local_path) = file. local_path ( ) {
177
- local_path. to_path_buf ( )
178
- } else {
179
- unreachable ! ( "only the current crate should have sources emitted" ) ;
180
- }
181
- }
182
- _ => return Ok ( ( ) ) ,
171
+ let p = if let Some ( local_path) = file. local_path ( ) {
172
+ local_path. to_path_buf ( )
173
+ } else {
174
+ unreachable ! ( "only the current crate should have sources emitted" ) ;
183
175
} ;
184
176
if self . emitted_local_sources . contains ( & * p) {
185
177
// We've already emitted this source
@@ -233,8 +225,10 @@ impl SourceCollector<'_, '_> {
233
225
cur. push ( & fname) ;
234
226
235
227
let title = format ! ( "{} - source" , src_fname. to_string_lossy( ) ) ;
236
- let desc =
237
- format ! ( "Source of the Rust file `{}`." , filename. prefer_remapped_unconditionaly( ) ) ;
228
+ let desc = format ! (
229
+ "Source of the Rust file `{}`." ,
230
+ file. to_string_lossy( FileNameDisplayPreference :: Remapped )
231
+ ) ;
238
232
let page = layout:: Page {
239
233
title : & title,
240
234
css_class : "src" ,
0 commit comments