@@ -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 is_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,7 @@ 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) = is_real_and_local ( span, sess) . and_then ( |file| file. into_local_path ( ) ) else {
73
70
return ;
74
71
} ;
75
72
if self . local_sources . contains_key ( & * p) {
@@ -135,8 +132,7 @@ impl DocVisitor<'_> for SourceCollector<'_, '_> {
135
132
// If we're not rendering sources, there's nothing to do.
136
133
// If we're including source files, and we haven't seen this file yet,
137
134
// then we need to render it out to the filesystem.
138
- if is_real_and_local ( span, sess) {
139
- let filename = span. filename ( sess) ;
135
+ if let Some ( filename) = is_real_and_local ( span, sess) {
140
136
let span = span. inner ( ) ;
141
137
let pos = sess. source_map ( ) . lookup_source_file ( span. lo ( ) ) ;
142
138
let file_span = span. with_lo ( pos. start_pos ) . with_hi ( pos. end_position ( ) ) ;
@@ -152,7 +148,7 @@ impl DocVisitor<'_> for SourceCollector<'_, '_> {
152
148
span,
153
149
format ! (
154
150
"failed to render source code for `{filename}`: {e}" ,
155
- filename = filename. prefer_local ( ) ,
151
+ filename = filename. to_string_lossy ( FileNameDisplayPreference :: Local ) ,
156
152
) ,
157
153
) ;
158
154
false
@@ -168,18 +164,13 @@ impl SourceCollector<'_, '_> {
168
164
/// Renders the given filename into its corresponding HTML source file.
169
165
fn emit_source (
170
166
& mut self ,
171
- filename : & FileName ,
167
+ file : & RealFileName ,
172
168
file_span : rustc_span:: Span ,
173
169
) -> 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 ( ( ) ) ,
170
+ let p = if let Some ( local_path) = file. local_path ( ) {
171
+ local_path. to_path_buf ( )
172
+ } else {
173
+ unreachable ! ( "only the current crate should have sources emitted" ) ;
183
174
} ;
184
175
if self . emitted_local_sources . contains ( & * p) {
185
176
// We've already emitted this source
@@ -233,8 +224,10 @@ impl SourceCollector<'_, '_> {
233
224
cur. push ( & fname) ;
234
225
235
226
let title = format ! ( "{} - source" , src_fname. to_string_lossy( ) ) ;
236
- let desc =
237
- format ! ( "Source of the Rust file `{}`." , filename. prefer_remapped_unconditionaly( ) ) ;
227
+ let desc = format ! (
228
+ "Source of the Rust file `{}`." ,
229
+ file. to_string_lossy( FileNameDisplayPreference :: Remapped )
230
+ ) ;
238
231
let page = layout:: Page {
239
232
title : & title,
240
233
css_class : "src" ,
0 commit comments