@@ -71,14 +71,14 @@ crate struct SyntaxRange {
7171}
7272
7373impl SyntaxRange {
74- fn new ( span : rustc_span:: Span , file : & SourceFile ) -> Self {
74+ fn new ( span : rustc_span:: Span , file : & SourceFile ) -> Option < Self > {
7575 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) ;
7777
78- SyntaxRange {
78+ Some ( SyntaxRange {
7979 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+ } )
8282 }
8383}
8484
@@ -95,12 +95,12 @@ impl CallLocation {
9595 ident_span : rustc_span:: Span ,
9696 enclosing_item_span : rustc_span:: Span ,
9797 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+ } )
104104 }
105105}
106106
@@ -178,7 +178,7 @@ where
178178 // If this span comes from a macro expansion, then the source code may not actually show
179179 // a use of the given item, so it would be a poor example. Hence, we skip all uses in macros.
180180 if call_span. from_expansion ( ) {
181- trace ! ( "Rejecting expr from macro: {:?}" , call_span ) ;
181+ trace ! ( "Rejecting expr from macro: {call_span :?}" ) ;
182182 return ;
183183 }
184184
@@ -188,7 +188,7 @@ where
188188 . hir ( )
189189 . span_with_body ( tcx. hir ( ) . local_def_id_to_hir_id ( tcx. hir ( ) . get_parent_item ( ex. hir_id ) ) ) ;
190190 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 :?}" ) ;
192192 return ;
193193 }
194194
@@ -224,11 +224,27 @@ where
224224 } ;
225225
226226 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+
228235 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+
229247 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 ( ) ;
232248 let display_name = file_path. display ( ) . to_string ( ) ;
233249 let edition = call_span. edition ( ) ;
234250 CallData { locations : Vec :: new ( ) , url, display_name, edition }
@@ -240,7 +256,14 @@ where
240256 trace ! ( "Including expr: {:?}" , call_span) ;
241257 let enclosing_item_span =
242258 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+ } ;
244267 fn_entries. entry ( abs_path) . or_insert_with ( mk_call_data) . locations . push ( location) ;
245268 }
246269 }
@@ -274,8 +297,8 @@ crate fn run(
274297 . map ( |( crate_num, _) | * * crate_num)
275298 . collect :: < Vec < _ > > ( ) ;
276299
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 :?}" ) ;
279302
280303 // Run call-finder on all items
281304 let mut calls = FxHashMap :: default ( ) ;
0 commit comments