Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5f9e2638
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,发现更多精彩内容 >>
提交
5f9e2638
编写于
7月 08, 2019
作者:
S
Shotaro Yamada
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support nested `impl Trait`
上级
9beff383
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
25 deletion
+41
-25
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+33
-25
src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs
src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs
+2
-0
src/test/rustdoc/inline_cross/impl_trait.rs
src/test/rustdoc/inline_cross/impl_trait.rs
+6
-0
未找到文件。
src/librustdoc/clean/mod.rs
浏览文件 @
5f9e2638
...
...
@@ -1720,11 +1720,13 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
ty
::
GenericParamDefKind
::
Const
{
..
}
=>
None
,
})
.collect
::
<
Vec
<
GenericParamDef
>>
();
// (param index, def id of trait) -> (name, type)
let
mut
impl_trait_proj
=
FxHashMap
::
<
(
u32
,
DefId
),
Vec
<
(
String
,
Type
)
>>
::
default
();
// param index -> [(DefId of trait, associated type name, type)]
let
mut
impl_trait_proj
=
FxHashMap
::
<
u32
,
Vec
<
(
DefId
,
String
,
Ty
<
'tcx
>
)
>>
::
default
();
let
mut
where_predicates
=
preds
.predicates
.iter
()
.flat_map
(|(
p
,
_
)|
{
let
mut
projection
=
None
;
let
param_idx
=
(||
{
if
let
Some
(
trait_ref
)
=
p
.to_opt_poly_trait_ref
()
{
if
let
ty
::
Param
(
param
)
=
trait_ref
.self_ty
()
.sty
{
...
...
@@ -1734,8 +1736,9 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
if
let
ty
::
Param
(
param
)
=
outlives
.skip_binder
()
.0
.sty
{
return
Some
(
param
.index
);
}
}
else
if
let
ty
::
Predicate
::
Projection
(
proj
)
=
p
{
if
let
ty
::
Param
(
param
)
=
proj
.skip_binder
()
.projection_ty
.self_ty
()
.sty
{
}
else
if
let
ty
::
Predicate
::
Projection
(
p
)
=
p
{
if
let
ty
::
Param
(
param
)
=
p
.skip_binder
()
.projection_ty
.self_ty
()
.sty
{
projection
=
Some
(
p
);
return
Some
(
param
.index
);
}
}
...
...
@@ -1755,16 +1758,15 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
.filter
(|
b
|
!
b
.is_sized_bound
(
cx
))
);
let
proj
=
match
&
p
{
WherePredicate
::
EqPredicate
{
lhs
,
rhs
}
=>
Some
((
lhs
,
rhs
))
.and_then
(|(
lhs
,
rhs
)|
Some
((
lhs
.projection
()
?
,
rhs
))),
_
=>
None
,
};
if
let
Some
(((
_
,
trait_did
,
name
),
rhs
))
=
proj
{
let
proj
=
projection
.map
(|
p
|
(
p
.skip_binder
()
.projection_ty
.clean
(
cx
),
p
.skip_binder
()
.ty
));
if
let
Some
(((
_
,
trait_did
,
name
),
rhs
))
=
proj
.as_ref
()
.and_then
(|(
lhs
,
rhs
)|
Some
((
lhs
.projection
()
?
,
rhs
)))
{
impl_trait_proj
.entry
(
(
param_idx
,
trait_did
)
)
.entry
(
param_idx
)
.or_default
()
.push
((
name
.to_string
(),
rhs
.clone
()
));
.push
((
trait_did
,
name
.to_string
(),
rhs
));
}
return
None
;
...
...
@@ -1775,18 +1777,6 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
})
.collect
::
<
Vec
<
_
>>
();
for
((
param_idx
,
trait_did
),
bounds
)
in
impl_trait_proj
{
for
(
name
,
rhs
)
in
bounds
{
simplify
::
merge_bounds
(
cx
,
impl_trait
.get_mut
(
&
param_idx
.into
())
.unwrap
(),
trait_did
,
&
name
,
&
rhs
,
);
}
}
// Move `TraitPredicate`s to the front.
for
(
_
,
bounds
)
in
impl_trait
.iter_mut
()
{
bounds
.sort_by_key
(|
b
|
if
let
GenericBound
::
TraitBound
(
..
)
=
b
{
...
...
@@ -1796,7 +1786,25 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
});
}
cx
.impl_trait_bounds
.borrow_mut
()
.extend
(
impl_trait
);
for
(
param
,
mut
bounds
)
in
impl_trait
{
if
let
crate
::
core
::
ImplTraitParam
::
ParamIndex
(
idx
)
=
param
{
if
let
Some
(
proj
)
=
impl_trait_proj
.remove
(
&
idx
)
{
for
(
trait_did
,
name
,
rhs
)
in
proj
{
simplify
::
merge_bounds
(
cx
,
&
mut
bounds
,
trait_did
,
&
name
,
&
rhs
.clean
(
cx
),
);
}
}
}
else
{
unreachable!
();
}
cx
.impl_trait_bounds
.borrow_mut
()
.insert
(
param
,
bounds
);
}
// Type parameters and have a Sized bound by default unless removed with
// ?Sized. Scan through the predicates and mark any type parameter with
...
...
src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs
浏览文件 @
5f9e2638
...
...
@@ -4,6 +4,8 @@ pub fn func<'a>(_x: impl Clone + Into<Vec<u8>> + 'a) {}
pub
fn
func2
<
T
>
(
_
x
:
impl
Deref
<
Target
=
Option
<
T
>>
+
Iterator
<
Item
=
T
>
,
_
y
:
impl
Iterator
<
Item
=
u8
>
)
{}
pub
fn
func3
(
_
x
:
impl
Iterator
<
Item
=
impl
Iterator
<
Item
=
u8
>>
+
Clone
)
{}
pub
struct
Foo
;
impl
Foo
{
...
...
src/test/rustdoc/inline_cross/impl_trait.rs
浏览文件 @
5f9e2638
...
...
@@ -8,11 +8,17 @@
pub
use
impl_trait_aux
::
func
;
// @has impl_trait/fn.func2.html
// @has - '//pre[@class="rust fn"]' "func2<T>("
// @has - '//pre[@class="rust fn"]' "_x: impl Deref<Target = Option<T>> + Iterator<Item = T>,"
// @has - '//pre[@class="rust fn"]' "_y: impl Iterator<Item = u8>)"
// @!has - '//pre[@class="rust fn"]' 'where'
pub
use
impl_trait_aux
::
func2
;
// @has impl_trait/fn.func3.html
// @has - '//pre[@class="rust fn"]' "func3(_x: impl Clone + Iterator<Item = impl Iterator<Item = u8>>)"
// @!has - '//pre[@class="rust fn"]' 'where'
pub
use
impl_trait_aux
::
func3
;
// @has impl_trait/struct.Foo.html
// @has - '//code[@id="method.v"]' "pub fn method<'a>(_x: impl Clone + Into<Vec<u8>> + 'a)"
// @!has - '//code[@id="method.v"]' 'where'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录