Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
44d07df1
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,发现更多精彩内容 >>
未验证
提交
44d07df1
编写于
2月 19, 2018
作者:
A
Aaron Hill
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sort synthetic impls bounds before rendering
This removes the implicit dependency on the iteration order of FxHashMap
上级
87881799
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
5 deletion
+50
-5
src/librustdoc/clean/auto_trait.rs
src/librustdoc/clean/auto_trait.rs
+45
-0
src/test/rustdoc/synthetic_auto/complex.rs
src/test/rustdoc/synthetic_auto/complex.rs
+2
-2
src/test/rustdoc/synthetic_auto/lifetimes.rs
src/test/rustdoc/synthetic_auto/lifetimes.rs
+1
-1
src/test/rustdoc/synthetic_auto/project.rs
src/test/rustdoc/synthetic_auto/project.rs
+2
-2
未找到文件。
src/librustdoc/clean/auto_trait.rs
浏览文件 @
44d07df1
...
@@ -1354,12 +1354,57 @@ fn param_env_to_generics<'b, 'c, 'cx>(
...
@@ -1354,12 +1354,57 @@ fn param_env_to_generics<'b, 'c, 'cx>(
}
}
}
}
self
.sort_where_predicates
(
&
mut
existing_predicates
);
Generics
{
Generics
{
params
:
generic_params
,
params
:
generic_params
,
where_predicates
:
existing_predicates
,
where_predicates
:
existing_predicates
,
}
}
}
}
// Ensure that the predicates are in a consistent order. The precise
// ordering doesn't actually matter, but it's important that
// a given set of predicates always appears in the same order -
// both for visual consistency between 'rustdoc' runs, and to
// make writing tests much easier
fn
sort_where_predicates
(
&
self
,
predicates
:
&
mut
Vec
<
WherePredicate
>
)
{
// We should never have identical bounds - and if we do,
// they're visually identical as well. Therefore, using
// an unstable sort is fine.
predicates
.sort_unstable_by
(|
first
,
second
|
{
// This might look horrendously hacky, but it's actually not that bad.
//
// For performance reasons, we use several different FxHashMaps
// in the process of computing the final set of where predicates.
// However, the iteration order of a HashMap is completely unspecified.
// In fact, the iteration of an FxHashMap can even vary between platforms,
// since FxHasher has different behavior for 32-bit and 64-bit platforms.
//
// Obviously, it's extremely undesireable for documentation rendering
// to be depndent on the platform it's run on. Apart from being confusing
// to end users, it makes writing tests much more difficult, as predicates
// can appear in any order in the final result.
//
// To solve this problem, we sort WherePredicates by their Debug
// string. The thing to keep in mind is that we don't really
// care what the final order is - we're synthesizing an impl
// ourselves, so any order can be considered equally valid.
// By sorting the predicates, however, we ensure that for
// a given codebase, all auto-trait impls always render
// in exactly the same way.
//
// Using the Debug impementation for sorting prevents
// us from needing to write quite a bit of almost
// entirely useless code (e.g. how should two
// Types be sorted relative to each other).
// This approach is probably somewhat slower, but
// the small number of items involved (impls
// rarely have more than a few bounds) means
// that it shouldn't matter in practice.
format!
(
"{:?}"
,
first
)
.cmp
(
&
format!
(
"{:?}"
,
second
))
});
}
fn
is_fn_ty
(
&
self
,
tcx
:
&
TyCtxt
,
ty
:
&
Type
)
->
bool
{
fn
is_fn_ty
(
&
self
,
tcx
:
&
TyCtxt
,
ty
:
&
Type
)
->
bool
{
match
&
ty
{
match
&
ty
{
&&
Type
::
ResolvedPath
{
ref
did
,
..
}
=>
{
&&
Type
::
ResolvedPath
{
ref
did
,
..
}
=>
{
...
...
src/test/rustdoc/synthetic_auto/complex.rs
浏览文件 @
44d07df1
...
@@ -31,8 +31,8 @@ pub struct Foo<T> {
...
@@ -31,8 +31,8 @@ pub struct Foo<T> {
// @has complex/struct.NotOuter.html
// @has complex/struct.NotOuter.html
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]/*/code' "impl<'a, T, K: \
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]/*/code' "impl<'a, T, K: \
// ?Sized> Send for NotOuter<'a, T, K> where
'a: 'static,
K: for<'b> Fn((&'b bool, &'a u8)) \
// ?Sized> Send for NotOuter<'a, T, K> where K: for<'b> Fn((&'b bool, &'a u8)) \
// -> &'b i8,
<T as MyTrait<'a>>::MyItem: Copy, T: MyTrait<'a>
"
// -> &'b i8,
T: MyTrait<'a>, <T as MyTrait<'a>>::MyItem: Copy, 'a: 'static
"
pub
use
foo
::{
Foo
,
Inner
as
NotInner
,
MyTrait
as
NotMyTrait
,
Outer
as
NotOuter
};
pub
use
foo
::{
Foo
,
Inner
as
NotInner
,
MyTrait
as
NotMyTrait
,
Outer
as
NotOuter
};
...
...
src/test/rustdoc/synthetic_auto/lifetimes.rs
浏览文件 @
44d07df1
...
@@ -19,7 +19,7 @@ unsafe impl<'a, T> Send for Inner<'a, T>
...
@@ -19,7 +19,7 @@ unsafe impl<'a, T> Send for Inner<'a, T>
// @has lifetimes/struct.Foo.html
// @has lifetimes/struct.Foo.html
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]/*/code' "impl<'c, K> Send \
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]/*/code' "impl<'c, K> Send \
// for Foo<'c, K> where
'c: 'static, K: for<'b> Fn(&'b bool) -> &'c u8
"
// for Foo<'c, K> where
K: for<'b> Fn(&'b bool) -> &'c u8, 'c: 'static
"
//
//
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]/*/code' "impl<'c, K> Sync \
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]/*/code' "impl<'c, K> Sync \
// for Foo<'c, K> where K: Sync"
// for Foo<'c, K> where K: Sync"
...
...
src/test/rustdoc/synthetic_auto/project.rs
浏览文件 @
44d07df1
...
@@ -34,10 +34,10 @@ unsafe impl<'a, T> Sync for Inner<'a, T>
...
@@ -34,10 +34,10 @@ unsafe impl<'a, T> Sync for Inner<'a, T>
// @has project/struct.Foo.html
// @has project/struct.Foo.html
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]/*/code' "impl<'c, K> Send \
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]/*/code' "impl<'c, K> Send \
// for Foo<'c, K> where
'c: 'static, K: MyTrait<MyItem = bool>
"
// for Foo<'c, K> where
K: MyTrait<MyItem = bool>, 'c: 'static
"
//
//
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]/*/code' "impl<'c, K> Sync \
// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]/*/code' "impl<'c, K> Sync \
// for Foo<'c, K> where
'c: 'static, K: MyTrait, <K as MyTrait>::MyItem: OtherTrait
"
// for Foo<'c, K> where
K: MyTrait, <K as MyTrait>::MyItem: OtherTrait, 'c: 'static,
"
pub
struct
Foo
<
'c
,
K
:
'c
>
{
pub
struct
Foo
<
'c
,
K
:
'c
>
{
inner_field
:
Inner
<
'c
,
K
>
,
inner_field
:
Inner
<
'c
,
K
>
,
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录