Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e0162a8a
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
e0162a8a
编写于
5月 02, 2021
作者:
J
Justus K
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustdoc: Render `for<'_>` lifetimes in front of where bound
上级
312b894c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
104 addition
and
22 deletion
+104
-22
src/librustdoc/clean/auto_trait.rs
src/librustdoc/clean/auto_trait.rs
+6
-2
src/librustdoc/clean/inline.rs
src/librustdoc/clean/inline.rs
+7
-4
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+9
-2
src/librustdoc/clean/simplify.rs
src/librustdoc/clean/simplify.rs
+19
-9
src/librustdoc/clean/types.rs
src/librustdoc/clean/types.rs
+1
-1
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+19
-3
src/librustdoc/json/conversions.rs
src/librustdoc/json/conversions.rs
+2
-1
src/test/rustdoc/higher-ranked-trait-bounds.rs
src/test/rustdoc/higher-ranked-trait-bounds.rs
+41
-0
未找到文件。
src/librustdoc/clean/auto_trait.rs
浏览文件 @
e0162a8a
...
...
@@ -414,7 +414,11 @@ fn make_final_bounds(
let
mut
bounds_vec
=
bounds
.into_iter
()
.collect
();
self
.sort_where_bounds
(
&
mut
bounds_vec
);
Some
(
WherePredicate
::
BoundPredicate
{
ty
,
bounds
:
bounds_vec
})
Some
(
WherePredicate
::
BoundPredicate
{
ty
,
bounds
:
bounds_vec
,
bound_params
:
Vec
::
new
(),
})
})
.chain
(
lifetime_to_bounds
.into_iter
()
.filter
(|
&
(
_
,
ref
bounds
)|
!
bounds
.is_empty
())
.map
(
...
...
@@ -492,7 +496,7 @@ fn param_env_to_generics(
}
let
p
=
p
.unwrap
();
match
p
{
WherePredicate
::
BoundPredicate
{
ty
,
mut
bounds
}
=>
{
WherePredicate
::
BoundPredicate
{
ty
,
mut
bounds
,
..
}
=>
{
// Writing a projection trait bound of the form
// <T as Trait>::Name : ?Sized
// is illegal, because ?Sized bounds can only
...
...
src/librustdoc/clean/inline.rs
浏览文件 @
e0162a8a
...
...
@@ -566,9 +566,11 @@ fn build_macro(cx: &mut DocContext<'_>, did: DefId, name: Symbol) -> clean::Item
fn
filter_non_trait_generics
(
trait_did
:
DefId
,
mut
g
:
clean
::
Generics
)
->
clean
::
Generics
{
for
pred
in
&
mut
g
.where_predicates
{
match
*
pred
{
clean
::
WherePredicate
::
BoundPredicate
{
ty
:
clean
::
Generic
(
ref
s
),
ref
mut
bounds
}
if
*
s
==
kw
::
SelfUpper
=>
{
clean
::
WherePredicate
::
BoundPredicate
{
ty
:
clean
::
Generic
(
ref
s
),
ref
mut
bounds
,
..
}
if
*
s
==
kw
::
SelfUpper
=>
{
bounds
.retain
(|
bound
|
match
*
bound
{
clean
::
GenericBound
::
TraitBound
(
clean
::
PolyTrait
{
trait_
:
clean
::
ResolvedPath
{
did
,
..
},
..
},
...
...
@@ -591,6 +593,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean:
..
},
ref
bounds
,
..
}
=>
!
(
bounds
.is_empty
()
||
*
s
==
kw
::
SelfUpper
&&
did
==
trait_did
),
_
=>
true
,
});
...
...
@@ -605,7 +608,7 @@ fn separate_supertrait_bounds(
)
->
(
clean
::
Generics
,
Vec
<
clean
::
GenericBound
>
)
{
let
mut
ty_bounds
=
Vec
::
new
();
g
.where_predicates
.retain
(|
pred
|
match
*
pred
{
clean
::
WherePredicate
::
BoundPredicate
{
ty
:
clean
::
Generic
(
ref
s
),
ref
bounds
}
clean
::
WherePredicate
::
BoundPredicate
{
ty
:
clean
::
Generic
(
ref
s
),
ref
bounds
,
..
}
if
*
s
==
kw
::
SelfUpper
=>
{
ty_bounds
.extend
(
bounds
.iter
()
.cloned
());
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
e0162a8a
...
...
@@ -330,6 +330,7 @@ fn clean(&self, cx: &mut DocContext<'_>) -> WherePredicate {
hir
::
WherePredicate
::
BoundPredicate
(
ref
wbp
)
=>
WherePredicate
::
BoundPredicate
{
ty
:
wbp
.bounded_ty
.clean
(
cx
),
bounds
:
wbp
.bounds
.clean
(
cx
),
bound_params
:
wbp
.bound_generic_params
.into_iter
()
.map
(|
x
|
x
.clean
(
cx
))
.collect
(),
},
hir
::
WherePredicate
::
RegionPredicate
(
ref
wrp
)
=>
WherePredicate
::
RegionPredicate
{
...
...
@@ -370,6 +371,7 @@ fn clean(&self, cx: &mut DocContext<'_>) -> WherePredicate {
WherePredicate
::
BoundPredicate
{
ty
:
poly_trait_ref
.skip_binder
()
.self_ty
()
.clean
(
cx
),
bounds
:
vec!
[
poly_trait_ref
.clean
(
cx
)],
bound_params
:
Vec
::
new
(),
}
}
}
...
...
@@ -402,6 +404,7 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Option<WherePredicate> {
Some
(
WherePredicate
::
BoundPredicate
{
ty
:
ty
.clean
(
cx
),
bounds
:
vec!
[
GenericBound
::
Outlives
(
lt
.clean
(
cx
)
.expect
(
"failed to clean lifetimes"
))],
bound_params
:
Vec
::
new
(),
})
}
}
...
...
@@ -567,7 +570,9 @@ fn is_elided_lifetime(param: &hir::GenericParam<'_>) -> bool {
// to where predicates when such cases occur.
for
where_pred
in
&
mut
generics
.where_predicates
{
match
*
where_pred
{
WherePredicate
::
BoundPredicate
{
ty
:
Generic
(
ref
name
),
ref
mut
bounds
}
=>
{
WherePredicate
::
BoundPredicate
{
ty
:
Generic
(
ref
name
),
ref
mut
bounds
,
..
}
=>
{
if
bounds
.is_empty
()
{
for
param
in
&
mut
generics
.params
{
match
param
.kind
{
...
...
@@ -721,7 +726,7 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Generics {
// handled in cleaning associated types
let
mut
sized_params
=
FxHashSet
::
default
();
where_predicates
.retain
(|
pred
|
match
*
pred
{
WP
::
BoundPredicate
{
ty
:
Generic
(
ref
g
),
ref
bounds
}
=>
{
WP
::
BoundPredicate
{
ty
:
Generic
(
ref
g
),
ref
bounds
,
..
}
=>
{
if
bounds
.iter
()
.any
(|
b
|
b
.is_sized_bound
(
cx
))
{
sized_params
.insert
(
*
g
);
false
...
...
@@ -741,6 +746,7 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Generics {
where_predicates
.push
(
WP
::
BoundPredicate
{
ty
:
Type
::
Generic
(
tp
.name
),
bounds
:
vec!
[
GenericBound
::
maybe_sized
(
cx
)],
bound_params
:
Vec
::
new
(),
})
}
}
...
...
@@ -1117,6 +1123,7 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Item {
WherePredicate
::
BoundPredicate
{
ty
:
QPath
{
ref
name
,
ref
self_type
,
ref
trait_
,
..
},
ref
bounds
,
..
}
=>
(
name
,
self_type
,
trait_
,
bounds
),
_
=>
return
None
,
};
...
...
src/librustdoc/clean/simplify.rs
浏览文件 @
e0162a8a
...
...
@@ -24,16 +24,20 @@
crate
fn
where_clauses
(
cx
:
&
DocContext
<
'_
>
,
clauses
:
Vec
<
WP
>
)
->
Vec
<
WP
>
{
// First, partition the where clause into its separate components
let
mut
params
:
BTreeMap
<
_
,
Vec
<
_
>
>
=
BTreeMap
::
new
();
let
mut
params
:
BTreeMap
<
_
,
(
Vec
<
_
>
,
Vec
<
_
>
)
>
=
BTreeMap
::
new
();
let
mut
lifetimes
=
Vec
::
new
();
let
mut
equalities
=
Vec
::
new
();
let
mut
tybounds
=
Vec
::
new
();
for
clause
in
clauses
{
match
clause
{
WP
::
BoundPredicate
{
ty
,
bounds
}
=>
match
ty
{
clean
::
Generic
(
s
)
=>
params
.entry
(
s
)
.or_default
()
.extend
(
bounds
),
t
=>
tybounds
.push
((
t
,
bounds
)),
WP
::
BoundPredicate
{
ty
,
bounds
,
bound_params
}
=>
match
ty
{
clean
::
Generic
(
s
)
=>
{
let
(
b
,
p
)
=
params
.entry
(
s
)
.or_default
();
b
.extend
(
bounds
);
p
.extend
(
bound_params
);
}
t
=>
tybounds
.push
((
t
,
(
bounds
,
bound_params
))),
},
WP
::
RegionPredicate
{
lifetime
,
bounds
}
=>
{
lifetimes
.push
((
lifetime
,
bounds
));
...
...
@@ -54,7 +58,7 @@
clean
::
Generic
(
s
)
=>
s
,
_
=>
return
true
,
};
let
bounds
=
match
params
.get_mut
(
generic
)
{
let
(
bounds
,
_
)
=
match
params
.get_mut
(
generic
)
{
Some
(
bound
)
=>
bound
,
None
=>
return
true
,
};
...
...
@@ -67,10 +71,16 @@
clauses
.extend
(
lifetimes
.into_iter
()
.map
(|(
lt
,
bounds
)|
WP
::
RegionPredicate
{
lifetime
:
lt
,
bounds
}),
);
clauses
.extend
(
params
.into_iter
()
.map
(|(
k
,
v
)|
WP
::
BoundPredicate
{
ty
:
clean
::
Generic
(
k
),
bounds
:
v
}),
);
clauses
.extend
(
tybounds
.into_iter
()
.map
(|(
ty
,
bounds
)|
WP
::
BoundPredicate
{
ty
,
bounds
}));
clauses
.extend
(
params
.into_iter
()
.map
(|(
k
,
(
bounds
,
params
))|
WP
::
BoundPredicate
{
ty
:
clean
::
Generic
(
k
),
bounds
,
bound_params
:
params
,
}));
clauses
.extend
(
tybounds
.into_iter
()
.map
(|(
ty
,
(
bounds
,
bound_params
))|
WP
::
BoundPredicate
{
ty
,
bounds
,
bound_params
,
}));
clauses
.extend
(
equalities
.into_iter
()
.map
(|(
lhs
,
rhs
)|
WP
::
EqPredicate
{
lhs
,
rhs
}));
clauses
}
...
...
src/librustdoc/clean/types.rs
浏览文件 @
e0162a8a
...
...
@@ -1193,7 +1193,7 @@ impl Lifetime {
#[derive(Clone,
Debug)]
crate
enum
WherePredicate
{
BoundPredicate
{
ty
:
Type
,
bounds
:
Vec
<
GenericBound
>
},
BoundPredicate
{
ty
:
Type
,
bounds
:
Vec
<
GenericBound
>
,
bound_params
:
Vec
<
Lifetime
>
},
RegionPredicate
{
lifetime
:
Lifetime
,
bounds
:
Vec
<
GenericBound
>
},
EqPredicate
{
lhs
:
Type
,
rhs
:
Type
},
}
...
...
src/librustdoc/html/format.rs
浏览文件 @
e0162a8a
...
...
@@ -249,17 +249,33 @@ impl clean::Generics {
}
match
pred
{
clean
::
WherePredicate
::
BoundPredicate
{
ty
,
bounds
}
=>
{
clean
::
WherePredicate
::
BoundPredicate
{
ty
,
bounds
,
bound_params
}
=>
{
let
bounds
=
bounds
;
let
for_prefix
=
match
bound_params
.len
()
{
0
=>
String
::
new
(),
_
if
f
.alternate
()
=>
{
format!
(
"for<{:#}> "
,
comma_sep
(
bound_params
.iter
()
.map
(|
lt
|
lt
.print
()))
)
}
_
=>
format!
(
"for<{}> "
,
comma_sep
(
bound_params
.iter
()
.map
(|
lt
|
lt
.print
()))
),
};
if
f
.alternate
()
{
clause
.push_str
(
&
format!
(
"{:#}: {:#}"
,
"{}{:#}: {:#}"
,
for_prefix
,
ty
.print
(
cx
),
print_generic_bounds
(
bounds
,
cx
)
));
}
else
{
clause
.push_str
(
&
format!
(
"{}: {}"
,
"{}{}: {}"
,
for_prefix
,
ty
.print
(
cx
),
print_generic_bounds
(
bounds
,
cx
)
));
...
...
src/librustdoc/json/conversions.rs
浏览文件 @
e0162a8a
...
...
@@ -328,9 +328,10 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
fn
from_tcx
(
predicate
:
clean
::
WherePredicate
,
tcx
:
TyCtxt
<
'_
>
)
->
Self
{
use
clean
::
WherePredicate
::
*
;
match
predicate
{
BoundPredicate
{
ty
,
bounds
}
=>
WherePredicate
::
BoundPredicate
{
BoundPredicate
{
ty
,
bounds
,
..
}
=>
WherePredicate
::
BoundPredicate
{
ty
:
ty
.into_tcx
(
tcx
),
bounds
:
bounds
.into_iter
()
.map
(|
x
|
x
.into_tcx
(
tcx
))
.collect
(),
// FIXME: add `bound_params` to rustdoc-json-params?
},
RegionPredicate
{
lifetime
,
bounds
}
=>
WherePredicate
::
RegionPredicate
{
lifetime
:
lifetime
.0
.to_string
(),
...
...
src/test/rustdoc/higher-ranked-trait-bounds.rs
0 → 100644
浏览文件 @
e0162a8a
#![crate_name
=
"foo"
]
trait
A
<
'x
>
{}
// @has foo/fn.test1.html
// @has - '//pre' "pub fn test1<T>() where for<'a> &'a T: Iterator,"
pub
fn
test1
<
T
>
()
where
for
<
'a
>
&
'a
T
:
Iterator
,
{
}
// @has foo/fn.test2.html
// @has - '//pre' "pub fn test2<T>() where for<'a, 'b> &'a T: A<'b>,"
pub
fn
test2
<
T
>
()
where
for
<
'a
,
'b
>
&
'a
T
:
A
<
'b
>
,
{
}
// @has foo/fn.test3.html
// @has - '//pre' "pub fn test3<F>() where F: for<'a, 'b> Fn(&'a u8, &'b u8),"
pub
fn
test3
<
F
>
()
where
F
:
for
<
'a
,
'b
>
Fn
(
&
'a
u8
,
&
'b
u8
),
{
}
// @has foo/struct.Foo.html
pub
struct
Foo
<
'a
>
{
_
x
:
&
'a
u8
,
}
impl
<
'a
>
Foo
<
'a
>
{
// @has - '//code' "pub fn bar<T>() where T: A<'a>,"
pub
fn
bar
<
T
>
()
where
T
:
A
<
'a
>
,
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录