Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0e574fb3
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0e574fb3
编写于
12月 11, 2020
作者:
J
Joshua Nelson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the JSON backend
This was simpler than expected.
上级
4fa95b3a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
23 deletion
+25
-23
src/librustdoc/json/conversions.rs
src/librustdoc/json/conversions.rs
+21
-21
src/librustdoc/json/mod.rs
src/librustdoc/json/mod.rs
+4
-2
未找到文件。
src/librustdoc/json/conversions.rs
浏览文件 @
0e574fb3
...
...
@@ -6,14 +6,16 @@
use
rustc_ast
::
ast
;
use
rustc_span
::
def_id
::{
DefId
,
CRATE_DEF_INDEX
};
use
rustc_span
::
Pos
;
use
crate
::
clean
;
use
crate
::
doctree
;
use
crate
::
formats
::
item_type
::
ItemType
;
use
crate
::
json
::
types
::
*
;
use
crate
::
json
::
JsonRenderer
;
impl
From
<
clean
::
Item
>
for
Option
<
Item
>
{
fn
from
(
item
:
clean
::
Item
)
->
Self
{
impl
JsonRenderer
{
pub
(
super
)
fn
convert_item
(
&
self
,
item
:
clean
::
Item
)
->
Option
<
Item
>
{
let
item_type
=
ItemType
::
from
(
&
item
);
let
clean
::
Item
{
source
,
...
...
@@ -32,7 +34,7 @@ fn from(item: clean::Item) -> Self {
id
:
def_id
.into
(),
crate_id
:
def_id
.krate
.as_u32
(),
name
,
source
:
s
ource
.into
(
),
source
:
s
elf
.convert_span
(
source
),
visibility
:
visibility
.into
(),
docs
:
attrs
.collapsed_doc_value
()
.unwrap_or_default
(),
links
:
attrs
...
...
@@ -53,25 +55,23 @@ fn from(item: clean::Item) -> Self {
}),
}
}
}
impl
From
<
clean
::
Span
>
for
Option
<
Span
>
{
#[allow(unreachable_code)]
fn
from
(
span
:
clean
::
Span
)
->
Self
{
// TODO: this should actually work
// Unfortunately this requires rethinking the whole framework,
// since this now needs a context and not just .into().
match
span
.filename
(
todo!
())
{
rustc_span
::
FileName
::
Real
(
name
)
=>
Some
(
Span
{
filename
:
match
name
{
rustc_span
::
RealFileName
::
Named
(
path
)
=>
path
,
rustc_span
::
RealFileName
::
Devirtualized
{
local_path
,
virtual_name
:
_
}
=>
{
local_path
}
},
begin
:
todo!
(),
end
:
todo!
(),
}),
fn
convert_span
(
&
self
,
span
:
clean
::
Span
)
->
Option
<
Span
>
{
match
span
.filename
(
&
self
.sess
)
{
rustc_span
::
FileName
::
Real
(
name
)
=>
{
let
hi
=
span
.hi
(
&
self
.sess
);
let
lo
=
span
.lo
(
&
self
.sess
);
Some
(
Span
{
filename
:
match
name
{
rustc_span
::
RealFileName
::
Named
(
path
)
=>
path
,
rustc_span
::
RealFileName
::
Devirtualized
{
local_path
,
virtual_name
:
_
}
=>
{
local_path
}
},
begin
:
(
lo
.line
,
lo
.col
.to_usize
()),
end
:
(
hi
.line
,
hi
.col
.to_usize
()),
})
}
_
=>
None
,
}
}
...
...
src/librustdoc/json/mod.rs
浏览文件 @
0e574fb3
...
...
@@ -26,6 +26,7 @@
#[derive(Clone)]
crate
struct
JsonRenderer
{
sess
:
Lrc
<
Session
>
,
/// A mapping of IDs that contains all local items for this crate which gets output as a top
/// level field of the JSON blob.
index
:
Rc
<
RefCell
<
FxHashMap
<
types
::
Id
,
types
::
Item
>>>
,
...
...
@@ -126,11 +127,12 @@ fn init(
_
render_info
:
RenderInfo
,
_
edition
:
Edition
,
_
cache
:
&
mut
Cache
,
_
sess
:
Lrc
<
Session
>
,
sess
:
Lrc
<
Session
>
,
)
->
Result
<
(
Self
,
clean
::
Crate
),
Error
>
{
debug!
(
"Initializing json renderer"
);
Ok
((
JsonRenderer
{
sess
,
index
:
Rc
::
new
(
RefCell
::
new
(
FxHashMap
::
default
())),
out_path
:
options
.output
,
},
...
...
@@ -146,7 +148,7 @@ fn item(&mut self, item: clean::Item, cache: &Cache) -> Result<(), Error> {
item
.kind
.inner_items
()
.for_each
(|
i
|
self
.item
(
i
.clone
(),
cache
)
.unwrap
());
let
id
=
item
.def_id
;
if
let
Some
(
mut
new_item
)
=
item
.into
():
Option
<
types
::
Item
>
{
if
let
Some
(
mut
new_item
)
=
self
.convert_item
(
item
)
{
if
let
types
::
ItemEnum
::
TraitItem
(
ref
mut
t
)
=
new_item
.inner
{
t
.implementors
=
self
.get_trait_implementors
(
id
,
cache
)
}
else
if
let
types
::
ItemEnum
::
StructItem
(
ref
mut
s
)
=
new_item
.inner
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录