Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9cf2fa84
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,发现更多精彩内容 >>
提交
9cf2fa84
编写于
8月 17, 2020
作者:
J
Joshua Nelson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow reusing the code in `collect_trait_impls`
上级
06d6d3df
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
80 addition
and
87 deletion
+80
-87
src/librustdoc/clean/types.rs
src/librustdoc/clean/types.rs
+77
-52
src/librustdoc/clean/utils.rs
src/librustdoc/clean/utils.rs
+1
-1
src/librustdoc/lib.rs
src/librustdoc/lib.rs
+1
-0
src/librustdoc/passes/collect_trait_impls.rs
src/librustdoc/passes/collect_trait_impls.rs
+1
-34
未找到文件。
src/librustdoc/clean/types.rs
浏览文件 @
9cf2fa84
...
...
@@ -7,6 +7,7 @@
use
std
::
rc
::
Rc
;
use
std
::
sync
::
Arc
;
use
std
::{
slice
,
vec
};
use
std
::
lazy
::
SyncOnceCell
as
OnceCell
;
use
rustc_ast
::
attr
;
use
rustc_ast
::
util
::
comments
::
beautify_doc_string
;
...
...
@@ -26,7 +27,7 @@
use
rustc_span
::{
self
,
FileName
};
use
rustc_target
::
abi
::
VariantIdx
;
use
rustc_target
::
spec
::
abi
::
Abi
;
use
smallvec
::
SmallVec
;
use
smallvec
::
{
SmallVec
,
smallvec
}
;
use
crate
::
clean
::
cfg
::
Cfg
;
use
crate
::
clean
::
external_path
;
...
...
@@ -1266,61 +1267,85 @@ pub fn as_str(&self) -> &'static str {
}
}
pub
fn
impls
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
SmallVec
<
[
DefId
;
4
]
>
{
use
self
::
PrimitiveType
::
*
;
let
both
=
|
a
:
Option
<
DefId
>
,
b
:
Option
<
DefId
>
|
->
SmallVec
<
_
>
{
a
.into_iter
()
.chain
(
b
)
.collect
()
};
let
lang_items
=
tcx
.lang_items
();
let
primary_impl
=
match
self
{
Isize
=>
lang_items
.isize_impl
(),
I8
=>
lang_items
.i8_impl
(),
I16
=>
lang_items
.i16_impl
(),
I32
=>
lang_items
.i32_impl
(),
I64
=>
lang_items
.i64_impl
(),
I128
=>
lang_items
.i128_impl
(),
Usize
=>
lang_items
.usize_impl
(),
U8
=>
lang_items
.u8_impl
(),
U16
=>
lang_items
.u16_impl
(),
U32
=>
lang_items
.u32_impl
(),
U64
=>
lang_items
.u64_impl
(),
U128
=>
lang_items
.u128_impl
(),
F32
=>
return
both
(
lang_items
.f32_impl
(),
lang_items
.f32_runtime_impl
()),
F64
=>
return
both
(
lang_items
.f64_impl
(),
lang_items
.f64_runtime_impl
()),
Char
=>
lang_items
.char_impl
(),
Bool
=>
lang_items
.bool_impl
(),
Str
=>
return
both
(
lang_items
.str_impl
(),
lang_items
.str_alloc_impl
()),
Slice
=>
{
return
lang_items
.slice_impl
()
.into_iter
()
.chain
(
lang_items
.slice_u8_impl
())
.chain
(
lang_items
.slice_alloc_impl
())
.chain
(
lang_items
.slice_u8_alloc_impl
())
.collect
();
pub
fn
impls
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
&
SmallVec
<
[
DefId
;
4
]
>
{
Self
::
all_impls
(
tcx
)
.get
(
self
)
.expect
(
"missing impl for primitive type"
)
}
pub
fn
all_impls
(
tcx
:
TyCtxt
<
'_
>
)
->
&
'static
FxHashMap
<
PrimitiveType
,
SmallVec
<
[
DefId
;
4
]
>>
{
static
CELL
:
OnceCell
<
FxHashMap
<
PrimitiveType
,
SmallVec
<
[
DefId
;
4
]
>>>
=
OnceCell
::
new
();
CELL
.get_or_init
(
move
||
{
use
self
::
PrimitiveType
::
*
;
/// A macro to create a FxHashMap.
///
/// Example:
///
/// ```
/// let letters = map!{"a" => "b", "c" => "d"};
/// ```
///
/// Trailing commas are allowed.
/// Commas between elements are required (even if the expression is a block).
macro_rules!
map
{
(
$
(
$key
:
expr
=>
$val
:
expr
),
*
$
(,)
*
)
=>
{{
let
mut
map
=
::
rustc_data_structures
::
fx
::
FxHashMap
::
default
();
$
(
map
.insert
(
$key
,
$val
);
)
*
map
}}
}
Array
=>
lang_items
.array_impl
(),
Tuple
=>
None
,
Unit
=>
None
,
RawPointer
=>
{
return
lang_items
.const_ptr_impl
()
.into_iter
()
.chain
(
lang_items
.mut_ptr_impl
())
.chain
(
lang_items
.const_slice_ptr_impl
())
.chain
(
lang_items
.mut_slice_ptr_impl
())
.collect
();
}
Reference
=>
None
,
Fn
=>
None
,
Never
=>
None
,
};
primary_impl
.into_iter
()
.collect
()
let
single
=
|
a
:
Option
<
DefId
>
|
a
.into_iter
()
.collect
();
let
both
=
|
a
:
Option
<
DefId
>
,
b
:
Option
<
DefId
>
|
->
SmallVec
<
_
>
{
a
.into_iter
()
.chain
(
b
)
.collect
()
};
let
lang_items
=
tcx
.lang_items
();
map!
{
Isize
=>
single
(
lang_items
.isize_impl
()),
I8
=>
single
(
lang_items
.i8_impl
()),
I16
=>
single
(
lang_items
.i16_impl
()),
I32
=>
single
(
lang_items
.i32_impl
()),
I64
=>
single
(
lang_items
.i64_impl
()),
I128
=>
single
(
lang_items
.i128_impl
()),
Usize
=>
single
(
lang_items
.usize_impl
()),
U8
=>
single
(
lang_items
.u8_impl
()),
U16
=>
single
(
lang_items
.u16_impl
()),
U32
=>
single
(
lang_items
.u32_impl
()),
U64
=>
single
(
lang_items
.u64_impl
()),
U128
=>
single
(
lang_items
.u128_impl
()),
F32
=>
both
(
lang_items
.f32_impl
(),
lang_items
.f32_runtime_impl
()),
F64
=>
both
(
lang_items
.f64_impl
(),
lang_items
.f64_runtime_impl
()),
Char
=>
single
(
lang_items
.char_impl
()),
Bool
=>
single
(
lang_items
.bool_impl
()),
Str
=>
both
(
lang_items
.str_impl
(),
lang_items
.str_alloc_impl
()),
Slice
=>
{
lang_items
.slice_impl
()
.into_iter
()
.chain
(
lang_items
.slice_u8_impl
())
.chain
(
lang_items
.slice_alloc_impl
())
.chain
(
lang_items
.slice_u8_alloc_impl
())
.collect
()
},
Array
=>
single
(
lang_items
.array_impl
()),
Tuple
=>
smallvec!
[],
Unit
=>
smallvec!
[],
RawPointer
=>
{
lang_items
.const_ptr_impl
()
.into_iter
()
.chain
(
lang_items
.mut_ptr_impl
())
.chain
(
lang_items
.const_slice_ptr_impl
())
.chain
(
lang_items
.mut_slice_ptr_impl
())
.collect
()
},
Reference
=>
smallvec!
[],
Fn
=>
smallvec!
[],
Never
=>
smallvec!
[],
}
})
}
pub
fn
to_url_str
(
&
self
)
->
&
'static
str
{
self
.as_str
()
}
...
...
src/librustdoc/clean/utils.rs
浏览文件 @
9cf2fa84
...
...
@@ -369,7 +369,7 @@ pub fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut V
None
=>
continue
,
},
};
for
did
in
primitive
.impls
(
tcx
)
{
for
&
did
in
primitive
.impls
(
tcx
)
{
if
!
did
.is_local
()
{
inline
::
build_impl
(
cx
,
did
,
None
,
ret
);
}
...
...
src/librustdoc/lib.rs
浏览文件 @
9cf2fa84
...
...
@@ -12,6 +12,7 @@
#![feature(ptr_offset_from)]
#![feature(crate_visibility_modifier)]
#![feature(never_type)]
#![feature(once_cell)]
#![recursion_limit
=
"256"
]
#[macro_use]
...
...
src/librustdoc/passes/collect_trait_impls.rs
浏览文件 @
9cf2fa84
...
...
@@ -34,40 +34,7 @@ pub fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate {
}
// Also try to inline primitive impls from other crates.
let
lang_items
=
cx
.tcx
.lang_items
();
let
primitive_impls
=
[
lang_items
.isize_impl
(),
lang_items
.i8_impl
(),
lang_items
.i16_impl
(),
lang_items
.i32_impl
(),
lang_items
.i64_impl
(),
lang_items
.i128_impl
(),
lang_items
.usize_impl
(),
lang_items
.u8_impl
(),
lang_items
.u16_impl
(),
lang_items
.u32_impl
(),
lang_items
.u64_impl
(),
lang_items
.u128_impl
(),
lang_items
.f32_impl
(),
lang_items
.f64_impl
(),
lang_items
.f32_runtime_impl
(),
lang_items
.f64_runtime_impl
(),
lang_items
.bool_impl
(),
lang_items
.char_impl
(),
lang_items
.str_impl
(),
lang_items
.array_impl
(),
lang_items
.slice_impl
(),
lang_items
.slice_u8_impl
(),
lang_items
.str_alloc_impl
(),
lang_items
.slice_alloc_impl
(),
lang_items
.slice_u8_alloc_impl
(),
lang_items
.const_ptr_impl
(),
lang_items
.mut_ptr_impl
(),
lang_items
.const_slice_ptr_impl
(),
lang_items
.mut_slice_ptr_impl
(),
];
for
def_id
in
primitive_impls
.iter
()
.filter_map
(|
&
def_id
|
def_id
)
{
for
&
def_id
in
PrimitiveType
::
all_impls
(
cx
.tcx
)
.values
()
.flatten
()
{
if
!
def_id
.is_local
()
{
inline
::
build_impl
(
cx
,
def_id
,
None
,
&
mut
new_items
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录