@@ -6,14 +6,16 @@ use std::convert::From;
6
6
7
7
use rustc_ast:: ast;
8
8
use rustc_span:: def_id:: { DefId , CRATE_DEF_INDEX } ;
9
+ use rustc_span:: Pos ;
9
10
10
11
use crate :: clean;
11
12
use crate :: doctree;
12
13
use crate :: formats:: item_type:: ItemType ;
13
14
use crate :: json:: types:: * ;
15
+ use crate :: json:: JsonRenderer ;
14
16
15
- impl From < clean :: Item > for Option < Item > {
16
- fn from ( item : clean:: Item ) -> Self {
17
+ impl JsonRenderer {
18
+ pub ( super ) fn convert_item ( & self , item : clean:: Item ) -> Option < Item > {
17
19
let item_type = ItemType :: from ( & item) ;
18
20
let clean:: Item {
19
21
source,
@@ -32,7 +34,7 @@ impl From<clean::Item> for Option<Item> {
32
34
id : def_id. into ( ) ,
33
35
crate_id : def_id. krate . as_u32 ( ) ,
34
36
name,
35
- source : source . into ( ) ,
37
+ source : self . convert_span ( source ) ,
36
38
visibility : visibility. into ( ) ,
37
39
docs : attrs. collapsed_doc_value ( ) . unwrap_or_default ( ) ,
38
40
links : attrs
@@ -53,25 +55,23 @@ impl From<clean::Item> for Option<Item> {
53
55
} ) ,
54
56
}
55
57
}
56
- }
57
58
58
- impl From < clean:: Span > for Option < Span > {
59
- #[ allow( unreachable_code) ]
60
- fn from ( span : clean:: Span ) -> Self {
61
- // TODO: this should actually work
62
- // Unfortunately this requires rethinking the whole framework,
63
- // since this now needs a context and not just .into().
64
- match span. filename ( todo ! ( ) ) {
65
- rustc_span:: FileName :: Real ( name) => Some ( Span {
66
- filename : match name {
67
- rustc_span:: RealFileName :: Named ( path) => path,
68
- rustc_span:: RealFileName :: Devirtualized { local_path, virtual_name : _ } => {
69
- local_path
70
- }
71
- } ,
72
- begin : todo ! ( ) ,
73
- end : todo ! ( ) ,
74
- } ) ,
59
+ fn convert_span ( & self , span : clean:: Span ) -> Option < Span > {
60
+ match span. filename ( & self . sess ) {
61
+ rustc_span:: FileName :: Real ( name) => {
62
+ let hi = span. hi ( & self . sess ) ;
63
+ let lo = span. lo ( & self . sess ) ;
64
+ Some ( Span {
65
+ filename : match name {
66
+ rustc_span:: RealFileName :: Named ( path) => path,
67
+ rustc_span:: RealFileName :: Devirtualized { local_path, virtual_name : _ } => {
68
+ local_path
69
+ }
70
+ } ,
71
+ begin : ( lo. line , lo. col . to_usize ( ) ) ,
72
+ end : ( hi. line , hi. col . to_usize ( ) ) ,
73
+ } )
74
+ }
75
75
_ => None ,
76
76
}
77
77
}
0 commit comments