Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
64b5464f
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,发现更多精彩内容 >>
提交
64b5464f
编写于
12月 17, 2014
作者:
T
Tom Jakubowski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustdoc: Use Fn trait sugar for external paths
Fix #19909
上级
c639cf6e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
12 deletion
+46
-12
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+46
-12
未找到文件。
src/librustdoc/clean/mod.rs
浏览文件 @
64b5464f
...
...
@@ -515,21 +515,55 @@ fn clean(&self, cx: &DocContext) -> Vec<TyParamBound> {
}
}
fn
external_path
(
cx
:
&
DocContext
,
name
:
&
str
,
substs
:
&
subst
::
Substs
)
->
Path
{
fn
external_path_params
(
cx
:
&
DocContext
,
trait_did
:
Option
<
ast
::
DefId
>
,
substs
:
&
subst
::
Substs
)
->
PathParameters
{
use
rustc
::
middle
::
ty
::
sty
;
let
lifetimes
=
substs
.regions
()
.get_slice
(
subst
::
TypeSpace
)
.iter
()
.filter_map
(|
v
|
v
.clean
(
cx
))
.collect
();
let
types
=
substs
.types
.get_slice
(
subst
::
TypeSpace
)
.to_vec
();
let
types
=
types
.clean
(
cx
);
match
(
trait_did
,
cx
.tcx_opt
())
{
// Attempt to sugar an external path like Fn<(A, B,), C> to Fn(A, B) -> C
(
Some
(
did
),
Some
(
ref
tcx
))
if
tcx
.lang_items
.fn_trait_kind
(
did
)
.is_some
()
=>
{
assert_eq!
(
types
.len
(),
2
);
let
inputs
=
match
types
[
0
]
.sty
{
sty
::
ty_tup
(
ref
tys
)
=>
tys
.iter
()
.map
(|
t
|
t
.clean
(
cx
))
.collect
(),
_
=>
{
return
PathParameters
::
AngleBracketed
{
lifetimes
:
lifetimes
,
types
:
types
.clean
(
cx
)
}
}
};
let
output
=
match
types
[
1
]
.sty
{
sty
::
ty_tup
(
ref
v
)
if
v
.is_empty
()
=>
None
,
// -> ()
_
=>
Some
(
types
[
1
]
.clean
(
cx
))
};
PathParameters
::
Parenthesized
{
inputs
:
inputs
,
output
:
output
}
},
(
_
,
_
)
=>
{
PathParameters
::
AngleBracketed
{
lifetimes
:
lifetimes
,
types
:
types
.clean
(
cx
),
}
}
}
}
// trait_did should be set to a trait's DefId if called on a TraitRef, in order to sugar
// from Fn<(A, B,), C> to Fn(A, B) -> C
fn
external_path
(
cx
:
&
DocContext
,
name
:
&
str
,
trait_did
:
Option
<
ast
::
DefId
>
,
substs
:
&
subst
::
Substs
)
->
Path
{
Path
{
global
:
false
,
segments
:
vec!
[
PathSegment
{
name
:
name
.to_string
(),
params
:
PathParameters
::
AngleBracketed
{
lifetimes
:
lifetimes
,
types
:
types
,
}
params
:
external_path_params
(
cx
,
trait_did
,
substs
)
}],
}
}
...
...
@@ -544,16 +578,16 @@ fn clean(&self, cx: &DocContext) -> TyParamBound {
let
(
did
,
path
)
=
match
*
self
{
ty
::
BoundSend
=>
(
tcx
.lang_items
.send_trait
()
.unwrap
(),
external_path
(
cx
,
"Send"
,
&
empty
)),
external_path
(
cx
,
"Send"
,
None
,
&
empty
)),
ty
::
BoundSized
=>
(
tcx
.lang_items
.sized_trait
()
.unwrap
(),
external_path
(
cx
,
"Sized"
,
&
empty
)),
external_path
(
cx
,
"Sized"
,
None
,
&
empty
)),
ty
::
BoundCopy
=>
(
tcx
.lang_items
.copy_trait
()
.unwrap
(),
external_path
(
cx
,
"Copy"
,
&
empty
)),
external_path
(
cx
,
"Copy"
,
None
,
&
empty
)),
ty
::
BoundSync
=>
(
tcx
.lang_items
.sync_trait
()
.unwrap
(),
external_path
(
cx
,
"Sync"
,
&
empty
)),
external_path
(
cx
,
"Sync"
,
None
,
&
empty
)),
};
let
fqn
=
csearch
::
get_item_path
(
tcx
,
did
);
let
fqn
=
fqn
.into_iter
()
.map
(|
i
|
i
.to_string
())
.collect
();
...
...
@@ -586,7 +620,7 @@ fn clean(&self, cx: &DocContext) -> TyParamBound {
let
fqn
=
fqn
.into_iter
()
.map
(|
i
|
i
.to_string
())
.collect
::
<
Vec
<
String
>>
();
let
path
=
external_path
(
cx
,
fqn
.last
()
.unwrap
()
.as_slice
(),
&
self
.substs
);
Some
(
self
.def_id
),
&
self
.substs
);
cx
.external_paths
.borrow_mut
()
.as_mut
()
.unwrap
()
.insert
(
self
.def_id
,
(
fqn
,
TypeTrait
));
...
...
@@ -1437,7 +1471,7 @@ fn clean(&self, cx: &DocContext) -> Type {
_
=>
TypeEnum
,
};
let
path
=
external_path
(
cx
,
fqn
.last
()
.unwrap
()
.to_string
()
.as_slice
(),
substs
);
None
,
substs
);
cx
.external_paths
.borrow_mut
()
.as_mut
()
.unwrap
()
.insert
(
did
,
(
fqn
,
kind
));
ResolvedPath
{
path
:
path
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录