@@ -71,14 +71,14 @@ crate struct SyntaxRange {
71
71
}
72
72
73
73
impl SyntaxRange {
74
- fn new ( span : rustc_span:: Span , file : & SourceFile ) -> Self {
74
+ fn new ( span : rustc_span:: Span , file : & SourceFile ) -> Option < Self > {
75
75
let get_pos = |bytepos : BytePos | file. original_relative_byte_pos ( bytepos) . 0 ;
76
- let get_line = |bytepos : BytePos | file. lookup_line ( bytepos) . unwrap ( ) ;
76
+ let get_line = |bytepos : BytePos | file. lookup_line ( bytepos) ;
77
77
78
- SyntaxRange {
78
+ Some ( SyntaxRange {
79
79
byte_span : ( get_pos ( span. lo ( ) ) , get_pos ( span. hi ( ) ) ) ,
80
- line_span : ( get_line ( span. lo ( ) ) , get_line ( span. hi ( ) ) ) ,
81
- }
80
+ line_span : ( get_line ( span. lo ( ) ) ? , get_line ( span. hi ( ) ) ? ) ,
81
+ } )
82
82
}
83
83
}
84
84
@@ -95,12 +95,12 @@ impl CallLocation {
95
95
ident_span : rustc_span:: Span ,
96
96
enclosing_item_span : rustc_span:: Span ,
97
97
source_file : & SourceFile ,
98
- ) -> Self {
99
- CallLocation {
100
- call_expr : SyntaxRange :: new ( expr_span, source_file) ,
101
- call_ident : SyntaxRange :: new ( ident_span, source_file) ,
102
- enclosing_item : SyntaxRange :: new ( enclosing_item_span, source_file) ,
103
- }
98
+ ) -> Option < Self > {
99
+ Some ( CallLocation {
100
+ call_expr : SyntaxRange :: new ( expr_span, source_file) ? ,
101
+ call_ident : SyntaxRange :: new ( ident_span, source_file) ? ,
102
+ enclosing_item : SyntaxRange :: new ( enclosing_item_span, source_file) ? ,
103
+ } )
104
104
}
105
105
}
106
106
@@ -178,7 +178,7 @@ where
178
178
// If this span comes from a macro expansion, then the source code may not actually show
179
179
// a use of the given item, so it would be a poor example. Hence, we skip all uses in macros.
180
180
if call_span. from_expansion ( ) {
181
- trace ! ( "Rejecting expr from macro: {:?}" , call_span ) ;
181
+ trace ! ( "Rejecting expr from macro: {call_span :?}" ) ;
182
182
return ;
183
183
}
184
184
@@ -188,7 +188,7 @@ where
188
188
. hir ( )
189
189
. span_with_body ( tcx. hir ( ) . local_def_id_to_hir_id ( tcx. hir ( ) . get_parent_item ( ex. hir_id ) ) ) ;
190
190
if enclosing_item_span. from_expansion ( ) {
191
- trace ! ( "Rejecting expr ({:?}) from macro item: {:?}" , call_span , enclosing_item_span ) ;
191
+ trace ! ( "Rejecting expr ({call_span :?}) from macro item: {enclosing_item_span :?}" ) ;
192
192
return ;
193
193
}
194
194
@@ -224,11 +224,27 @@ where
224
224
} ;
225
225
226
226
if let Some ( file_path) = file_path {
227
- let abs_path = fs:: canonicalize ( file_path. clone ( ) ) . unwrap ( ) ;
227
+ let abs_path = match fs:: canonicalize ( file_path. clone ( ) ) {
228
+ Ok ( abs_path) => abs_path,
229
+ Err ( _) => {
230
+ trace ! ( "Could not canonicalize file path: {}" , file_path. display( ) ) ;
231
+ return ;
232
+ }
233
+ } ;
234
+
228
235
let cx = & self . cx ;
236
+ let clean_span = crate :: clean:: types:: Span :: new ( call_span) ;
237
+ let url = match cx. href_from_span ( clean_span, false ) {
238
+ Some ( url) => url,
239
+ None => {
240
+ trace ! (
241
+ "Rejecting expr ({call_span:?}) whose clean span ({clean_span:?}) cannot be turned into a link"
242
+ ) ;
243
+ return ;
244
+ }
245
+ } ;
246
+
229
247
let mk_call_data = || {
230
- let clean_span = crate :: clean:: types:: Span :: new ( call_span) ;
231
- let url = cx. href_from_span ( clean_span, false ) . unwrap ( ) ;
232
248
let display_name = file_path. display ( ) . to_string ( ) ;
233
249
let edition = call_span. edition ( ) ;
234
250
CallData { locations : Vec :: new ( ) , url, display_name, edition }
@@ -240,7 +256,14 @@ where
240
256
trace ! ( "Including expr: {:?}" , call_span) ;
241
257
let enclosing_item_span =
242
258
source_map. span_extend_to_prev_char ( enclosing_item_span, '\n' , false ) ;
243
- let location = CallLocation :: new ( call_span, ident_span, enclosing_item_span, & file) ;
259
+ let location =
260
+ match CallLocation :: new ( call_span, ident_span, enclosing_item_span, & file) {
261
+ Some ( location) => location,
262
+ None => {
263
+ trace ! ( "Could not get serializable call location for {call_span:?}" ) ;
264
+ return ;
265
+ }
266
+ } ;
244
267
fn_entries. entry ( abs_path) . or_insert_with ( mk_call_data) . locations . push ( location) ;
245
268
}
246
269
}
@@ -274,8 +297,8 @@ crate fn run(
274
297
. map ( |( crate_num, _) | * * crate_num)
275
298
. collect :: < Vec < _ > > ( ) ;
276
299
277
- debug ! ( "All crates in TyCtxt: {:?}" , all_crates ) ;
278
- debug ! ( "Scrape examples target_crates: {:?}" , target_crates ) ;
300
+ debug ! ( "All crates in TyCtxt: {all_crates :?}" ) ;
301
+ debug ! ( "Scrape examples target_crates: {target_crates :?}" ) ;
279
302
280
303
// Run call-finder on all items
281
304
let mut calls = FxHashMap :: default ( ) ;
0 commit comments