Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
87760e5f
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,发现更多精彩内容 >>
提交
87760e5f
编写于
8月 30, 2018
作者:
Q
QuietMisdreavus
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
collect auto-/blanket-impls during collect-trait-impls
上级
e854d399
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
65 addition
and
63 deletion
+65
-63
src/librustdoc/clean/inline.rs
src/librustdoc/clean/inline.rs
+7
-21
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+19
-41
src/librustdoc/passes/collect_trait_impls.rs
src/librustdoc/passes/collect_trait_impls.rs
+39
-1
未找到文件。
src/librustdoc/clean/inline.rs
浏览文件 @
87760e5f
...
...
@@ -29,8 +29,6 @@
self
,
GetDefId
,
ToSource
,
get_auto_traits_with_def_id
,
get_blanket_impls_with_def_id
,
};
use
super
::
Clean
;
...
...
@@ -56,7 +54,7 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa
let
inner
=
match
def
{
Def
::
Trait
(
did
)
=>
{
record_extern_fqn
(
cx
,
did
,
clean
::
TypeKind
::
Trait
);
ret
.extend
(
build_impls
(
cx
,
did
,
false
));
ret
.extend
(
build_impls
(
cx
,
did
));
clean
::
TraitItem
(
build_external_trait
(
cx
,
did
))
}
Def
::
Fn
(
did
)
=>
{
...
...
@@ -65,27 +63,27 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa
}
Def
::
Struct
(
did
)
=>
{
record_extern_fqn
(
cx
,
did
,
clean
::
TypeKind
::
Struct
);
ret
.extend
(
build_impls
(
cx
,
did
,
true
));
ret
.extend
(
build_impls
(
cx
,
did
));
clean
::
StructItem
(
build_struct
(
cx
,
did
))
}
Def
::
Union
(
did
)
=>
{
record_extern_fqn
(
cx
,
did
,
clean
::
TypeKind
::
Union
);
ret
.extend
(
build_impls
(
cx
,
did
,
true
));
ret
.extend
(
build_impls
(
cx
,
did
));
clean
::
UnionItem
(
build_union
(
cx
,
did
))
}
Def
::
TyAlias
(
did
)
=>
{
record_extern_fqn
(
cx
,
did
,
clean
::
TypeKind
::
Typedef
);
ret
.extend
(
build_impls
(
cx
,
did
,
false
));
ret
.extend
(
build_impls
(
cx
,
did
));
clean
::
TypedefItem
(
build_type_alias
(
cx
,
did
),
false
)
}
Def
::
Enum
(
did
)
=>
{
record_extern_fqn
(
cx
,
did
,
clean
::
TypeKind
::
Enum
);
ret
.extend
(
build_impls
(
cx
,
did
,
true
));
ret
.extend
(
build_impls
(
cx
,
did
));
clean
::
EnumItem
(
build_enum
(
cx
,
did
))
}
Def
::
ForeignTy
(
did
)
=>
{
record_extern_fqn
(
cx
,
did
,
clean
::
TypeKind
::
Foreign
);
ret
.extend
(
build_impls
(
cx
,
did
,
false
));
ret
.extend
(
build_impls
(
cx
,
did
));
clean
::
ForeignTypeItem
}
// Never inline enum variants but leave them shown as re-exports.
...
...
@@ -275,7 +273,7 @@ fn build_type_alias(cx: &DocContext, did: DefId) -> clean::Typedef {
}
}
pub
fn
build_impls
(
cx
:
&
DocContext
,
did
:
DefId
,
auto_traits
:
bool
)
->
Vec
<
clean
::
Item
>
{
pub
fn
build_impls
(
cx
:
&
DocContext
,
did
:
DefId
)
->
Vec
<
clean
::
Item
>
{
let
tcx
=
cx
.tcx
;
let
mut
impls
=
Vec
::
new
();
...
...
@@ -283,18 +281,6 @@ pub fn build_impls(cx: &DocContext, did: DefId, auto_traits: bool) -> Vec<clean:
build_impl
(
cx
,
did
,
&
mut
impls
);
}
if
auto_traits
{
let
auto_impls
=
get_auto_traits_with_def_id
(
cx
,
did
);
{
let
mut
renderinfo
=
cx
.renderinfo
.borrow_mut
();
let
new_impls
:
Vec
<
clean
::
Item
>
=
auto_impls
.into_iter
()
.filter
(|
i
|
renderinfo
.inlined
.insert
(
i
.def_id
))
.collect
();
impls
.extend
(
new_impls
);
}
impls
.extend
(
get_blanket_impls_with_def_id
(
cx
,
did
));
}
impls
}
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
87760e5f
...
...
@@ -576,9 +576,9 @@ fn clean(&self, cx: &DocContext) -> Item {
let
mut
items
:
Vec
<
Item
>
=
vec!
[];
items
.extend
(
self
.extern_crates
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.imports
.iter
()
.flat_map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.structs
.iter
()
.
flat_
map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.unions
.iter
()
.
flat_
map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.enums
.iter
()
.
flat_
map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.structs
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.unions
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.enums
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.fns
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.foreigns
.iter
()
.flat_map
(|
x
|
x
.clean
(
cx
)));
items
.extend
(
self
.mods
.iter
()
.map
(|
x
|
x
.clean
(
cx
)));
...
...
@@ -2813,14 +2813,10 @@ pub struct Union {
pub
fields_stripped
:
bool
,
}
impl
Clean
<
Vec
<
Item
>>
for
doctree
::
Struct
{
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
Vec
<
Item
>
{
let
name
=
self
.name
.clean
(
cx
);
let
mut
ret
=
get_auto_traits_with_node_id
(
cx
,
self
.id
,
name
.clone
());
ret
.extend
(
get_blanket_impls_with_node_id
(
cx
,
self
.id
,
name
.clone
()));
ret
.push
(
Item
{
name
:
Some
(
name
),
impl
Clean
<
Item
>
for
doctree
::
Struct
{
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
attrs
:
self
.attrs
.clean
(
cx
),
source
:
self
.whence
.clean
(
cx
),
def_id
:
cx
.tcx.hir
.local_def_id
(
self
.id
),
...
...
@@ -2833,20 +2829,14 @@ fn clean(&self, cx: &DocContext) -> Vec<Item> {
fields
:
self
.fields
.clean
(
cx
),
fields_stripped
:
false
,
}),
});
ret
}
}
}
impl
Clean
<
Vec
<
Item
>>
for
doctree
::
Union
{
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
Vec
<
Item
>
{
let
name
=
self
.name
.clean
(
cx
);
let
mut
ret
=
get_auto_traits_with_node_id
(
cx
,
self
.id
,
name
.clone
());
ret
.extend
(
get_blanket_impls_with_node_id
(
cx
,
self
.id
,
name
.clone
()));
ret
.push
(
Item
{
name
:
Some
(
name
),
impl
Clean
<
Item
>
for
doctree
::
Union
{
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
attrs
:
self
.attrs
.clean
(
cx
),
source
:
self
.whence
.clean
(
cx
),
def_id
:
cx
.tcx.hir
.local_def_id
(
self
.id
),
...
...
@@ -2859,9 +2849,7 @@ fn clean(&self, cx: &DocContext) -> Vec<Item> {
fields
:
self
.fields
.clean
(
cx
),
fields_stripped
:
false
,
}),
});
ret
}
}
}
...
...
@@ -2892,14 +2880,10 @@ pub struct Enum {
pub
variants_stripped
:
bool
,
}
impl
Clean
<
Vec
<
Item
>>
for
doctree
::
Enum
{
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
Vec
<
Item
>
{
let
name
=
self
.name
.clean
(
cx
);
let
mut
ret
=
get_auto_traits_with_node_id
(
cx
,
self
.id
,
name
.clone
());
ret
.extend
(
get_blanket_impls_with_node_id
(
cx
,
self
.id
,
name
.clone
()));
ret
.push
(
Item
{
name
:
Some
(
name
),
impl
Clean
<
Item
>
for
doctree
::
Enum
{
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
Item
{
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
attrs
:
self
.attrs
.clean
(
cx
),
source
:
self
.whence
.clean
(
cx
),
def_id
:
cx
.tcx.hir
.local_def_id
(
self
.id
),
...
...
@@ -2911,9 +2895,7 @@ fn clean(&self, cx: &DocContext) -> Vec<Item> {
generics
:
self
.generics
.clean
(
cx
),
variants_stripped
:
false
,
}),
});
ret
}
}
}
...
...
@@ -3442,11 +3424,7 @@ fn build_deref_target_impls(cx: &DocContext,
let
primitive
=
match
*
target
{
ResolvedPath
{
did
,
..
}
if
did
.is_local
()
=>
continue
,
ResolvedPath
{
did
,
..
}
=>
{
// We set the last parameter to false to avoid looking for auto-impls for traits
// and therefore avoid an ICE.
// The reason behind this is that auto-traits don't propagate through Deref so
// we're not supposed to synthesise impls for them.
ret
.extend
(
inline
::
build_impls
(
cx
,
did
,
false
));
ret
.extend
(
inline
::
build_impls
(
cx
,
did
));
continue
}
_
=>
match
target
.primitive_type
()
{
...
...
src/librustdoc/passes/collect_trait_impls.rs
浏览文件 @
87760e5f
...
...
@@ -12,14 +12,20 @@
use
super
::
Pass
;
use
core
::
DocContext
;
use
fold
::
DocFolder
;
pub
const
COLLECT_TRAIT_IMPLS
:
Pass
=
Pass
::
early
(
"collect-trait-impls"
,
collect_trait_impls
,
"retrieves trait impls for items in the crate"
);
pub
fn
collect_trait_impls
(
mut
krate
:
Crate
,
cx
:
&
DocContext
)
->
Crate
{
pub
fn
collect_trait_impls
(
krate
:
Crate
,
cx
:
&
DocContext
)
->
Crate
{
let
mut
synth
=
SyntheticImplCollector
::
new
(
cx
);
let
mut
krate
=
synth
.fold_crate
(
krate
);
if
let
Some
(
ref
mut
it
)
=
krate
.module
{
if
let
ModuleItem
(
Module
{
ref
mut
items
,
..
})
=
it
.inner
{
items
.extend
(
synth
.impls
);
for
&
cnum
in
cx
.tcx
.crates
()
.iter
()
{
for
&
did
in
cx
.tcx
.all_trait_implementations
(
cnum
)
.iter
()
{
inline
::
build_impl
(
cx
,
did
,
items
);
...
...
@@ -90,3 +96,35 @@ pub fn collect_trait_impls(mut krate: Crate, cx: &DocContext) -> Crate {
krate
}
struct
SyntheticImplCollector
<
'a
,
'tcx
:
'a
,
'rcx
:
'a
,
'cstore
:
'rcx
>
{
cx
:
&
'a
DocContext
<
'a
,
'tcx
,
'rcx
,
'cstore
>
,
impls
:
Vec
<
Item
>
,
}
impl
<
'a
,
'tcx
,
'rcx
,
'cstore
>
SyntheticImplCollector
<
'a
,
'tcx
,
'rcx
,
'cstore
>
{
fn
new
(
cx
:
&
'a
DocContext
<
'a
,
'tcx
,
'rcx
,
'cstore
>
)
->
Self
{
SyntheticImplCollector
{
cx
,
impls
:
Vec
::
new
(),
}
}
}
impl
<
'a
,
'tcx
,
'rcx
,
'cstore
>
DocFolder
for
SyntheticImplCollector
<
'a
,
'tcx
,
'rcx
,
'cstore
>
{
fn
fold_item
(
&
mut
self
,
i
:
Item
)
->
Option
<
Item
>
{
if
i
.is_struct
()
||
i
.is_enum
()
||
i
.is_union
()
{
if
let
(
Some
(
node_id
),
Some
(
name
))
=
(
self
.cx.tcx.hir
.as_local_node_id
(
i
.def_id
),
i
.name
.clone
())
{
self
.impls
.extend
(
get_auto_traits_with_node_id
(
self
.cx
,
node_id
,
name
.clone
()));
self
.impls
.extend
(
get_blanket_impls_with_node_id
(
self
.cx
,
node_id
,
name
));
}
else
{
self
.impls
.extend
(
get_auto_traits_with_def_id
(
self
.cx
,
i
.def_id
));
self
.impls
.extend
(
get_blanket_impls_with_def_id
(
self
.cx
,
i
.def_id
));
}
}
self
.fold_item_recur
(
i
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录