Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
aefe7509
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,发现更多精彩内容 >>
提交
aefe7509
编写于
3月 07, 2019
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add bounds for return types as well
上级
6ae73e2f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
59 addition
and
30 deletion
+59
-30
src/librustdoc/clean/inline.rs
src/librustdoc/clean/inline.rs
+2
-1
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+33
-8
src/librustdoc/html/render.rs
src/librustdoc/html/render.rs
+12
-15
src/librustdoc/html/static/main.js
src/librustdoc/html/static/main.js
+12
-6
未找到文件。
src/librustdoc/clean/inline.rs
浏览文件 @
aefe7509
...
...
@@ -214,7 +214,7 @@ fn build_external_function(cx: &DocContext<'_>, did: DefId) -> clean::Function {
let
predicates
=
cx
.tcx
.predicates_of
(
did
);
let
generics
=
(
cx
.tcx
.generics_of
(
did
),
&
predicates
)
.clean
(
cx
);
let
decl
=
(
did
,
sig
)
.clean
(
cx
);
let
all_types
=
clean
::
get_all_types
(
&
generics
,
&
decl
,
cx
);
let
(
all_types
,
ret_types
)
=
clean
::
get_all_types
(
&
generics
,
&
decl
,
cx
);
clean
::
Function
{
decl
,
generics
,
...
...
@@ -225,6 +225,7 @@ fn build_external_function(cx: &DocContext<'_>, did: DefId) -> clean::Function {
asyncness
:
hir
::
IsAsync
::
NotAsync
,
},
all_types
,
ret_types
,
}
}
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
aefe7509
...
...
@@ -1751,7 +1751,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
}
// The point is to replace bounds with types.
pub
fn
get_real_types
(
fn
get_real_types
(
generics
:
&
Generics
,
arg
:
&
Type
,
cx
:
&
DocContext
<
'_
,
'_
,
'_
>
,
...
...
@@ -1822,7 +1822,7 @@ pub fn get_all_types(
generics
:
&
Generics
,
decl
:
&
FnDecl
,
cx
:
&
DocContext
<
'_
,
'_
,
'_
>
,
)
->
Vec
<
Type
>
{
)
->
(
Vec
<
Type
>
,
Vec
<
Type
>
)
{
let
mut
all_types
=
Vec
::
new
();
for
arg
in
decl
.inputs.values
.iter
()
{
if
arg
.type_
.is_self_type
()
{
...
...
@@ -1837,7 +1837,23 @@ pub fn get_all_types(
// FIXME: use a HashSet instead?
all_types
.sort_unstable_by
(|
a
,
b
|
a
.to_string
()
.partial_cmp
(
&
b
.to_string
())
.unwrap
());
all_types
.dedup
();
all_types
let
mut
ret_types
=
match
decl
.output
{
FunctionRetTy
::
Return
(
ref
return_type
)
=>
{
let
mut
ret
=
Vec
::
new
();
if
let
Some
(
mut
args
)
=
get_real_types
(
generics
,
&
return_type
,
cx
)
{
ret
.append
(
&
mut
args
);
}
else
{
ret
.push
(
return_type
.clone
());
}
ret
}
_
=>
Vec
::
new
(),
};
// FIXME: use a HashSet instead?
ret_types
.sort_unstable_by
(|
a
,
b
|
a
.to_string
()
.partial_cmp
(
&
b
.to_string
())
.unwrap
());
ret_types
.dedup
();
(
all_types
,
ret_types
)
}
#[derive(Clone,
RustcEncodable,
RustcDecodable,
Debug)]
...
...
@@ -1847,6 +1863,7 @@ pub struct Method {
pub
header
:
hir
::
FnHeader
,
pub
defaultness
:
Option
<
hir
::
Defaultness
>
,
pub
all_types
:
Vec
<
Type
>
,
pub
ret_types
:
Vec
<
Type
>
,
}
impl
<
'a
>
Clean
<
Method
>
for
(
&
'a
hir
::
MethodSig
,
&
'a
hir
::
Generics
,
hir
::
BodyId
,
...
...
@@ -1855,13 +1872,14 @@ fn clean(&self, cx: &DocContext<'_>) -> Method {
let
(
generics
,
decl
)
=
enter_impl_trait
(
cx
,
||
{
(
self
.1
.clean
(
cx
),
(
&*
self
.0
.decl
,
self
.2
)
.clean
(
cx
))
});
let
all_types
=
get_all_types
(
&
generics
,
&
decl
,
cx
);
let
(
all_types
,
ret_types
)
=
get_all_types
(
&
generics
,
&
decl
,
cx
);
Method
{
decl
,
generics
,
header
:
self
.0
.header
,
defaultness
:
self
.3
,
all_types
,
ret_types
,
}
}
}
...
...
@@ -1872,6 +1890,7 @@ pub struct TyMethod {
pub
decl
:
FnDecl
,
pub
generics
:
Generics
,
pub
all_types
:
Vec
<
Type
>
,
pub
ret_types
:
Vec
<
Type
>
,
}
#[derive(Clone,
RustcEncodable,
RustcDecodable,
Debug)]
...
...
@@ -1880,6 +1899,7 @@ pub struct Function {
pub
generics
:
Generics
,
pub
header
:
hir
::
FnHeader
,
pub
all_types
:
Vec
<
Type
>
,
pub
ret_types
:
Vec
<
Type
>
,
}
impl
Clean
<
Item
>
for
doctree
::
Function
{
...
...
@@ -1894,7 +1914,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
}
else
{
hir
::
Constness
::
NotConst
};
let
all_types
=
get_all_types
(
&
generics
,
&
decl
,
cx
);
let
(
all_types
,
ret_types
)
=
get_all_types
(
&
generics
,
&
decl
,
cx
);
Item
{
name
:
Some
(
self
.name
.clean
(
cx
)),
attrs
:
self
.attrs
.clean
(
cx
),
...
...
@@ -1908,6 +1928,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
generics
,
header
:
hir
::
FnHeader
{
constness
,
..
self
.header
},
all_types
,
ret_types
,
}),
}
}
...
...
@@ -2177,12 +2198,13 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
let
(
generics
,
decl
)
=
enter_impl_trait
(
cx
,
||
{
(
self
.generics
.clean
(
cx
),
(
&*
sig
.decl
,
&
names
[
..
])
.clean
(
cx
))
});
let
all_types
=
get_all_types
(
&
generics
,
&
decl
,
cx
);
let
(
all_types
,
ret_types
)
=
get_all_types
(
&
generics
,
&
decl
,
cx
);
TyMethodItem
(
TyMethod
{
header
:
sig
.header
,
decl
,
generics
,
all_types
,
ret_types
,
})
}
hir
::
TraitItemKind
::
Type
(
ref
bounds
,
ref
default
)
=>
{
...
...
@@ -2280,7 +2302,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
ty
::
ImplContainer
(
_
)
=>
true
,
ty
::
TraitContainer
(
_
)
=>
self
.defaultness
.has_value
()
};
let
all_types
=
get_all_types
(
&
generics
,
&
decl
,
cx
);
let
(
all_types
,
ret_types
)
=
get_all_types
(
&
generics
,
&
decl
,
cx
);
if
provided
{
let
constness
=
if
cx
.tcx
.is_min_const_fn
(
self
.def_id
)
{
hir
::
Constness
::
Const
...
...
@@ -2298,6 +2320,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
},
defaultness
:
Some
(
self
.defaultness
),
all_types
,
ret_types
,
})
}
else
{
TyMethodItem
(
TyMethod
{
...
...
@@ -2310,6 +2333,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
asyncness
:
hir
::
IsAsync
::
NotAsync
,
},
all_types
,
ret_types
,
})
}
}
...
...
@@ -3976,7 +4000,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
let
(
generics
,
decl
)
=
enter_impl_trait
(
cx
,
||
{
(
generics
.clean
(
cx
),
(
&**
decl
,
&
names
[
..
])
.clean
(
cx
))
});
let
all_types
=
get_all_types
(
&
generics
,
&
decl
,
cx
);
let
(
all_types
,
ret_types
)
=
get_all_types
(
&
generics
,
&
decl
,
cx
);
ForeignFunctionItem
(
Function
{
decl
,
generics
,
...
...
@@ -3987,6 +4011,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
asyncness
:
hir
::
IsAsync
::
NotAsync
,
},
all_types
,
ret_types
,
})
}
hir
::
ForeignItemKind
::
Static
(
ref
ty
,
mutbl
)
=>
{
...
...
src/librustdoc/html/render.rs
浏览文件 @
aefe7509
...
...
@@ -446,7 +446,7 @@ fn to_json(&self) -> Json {
}
Json
::
Array
(
data
)
}
None
=>
Json
::
Null
None
=>
Json
::
Null
,
}
}
}
...
...
@@ -455,7 +455,7 @@ fn to_json(&self) -> Json {
#[derive(Debug)]
struct
IndexItemFunctionType
{
inputs
:
Vec
<
Type
>
,
output
:
Option
<
Type
>
,
output
:
Vec
<
Type
>
,
}
impl
ToJson
for
IndexItemFunctionType
{
...
...
@@ -466,8 +466,8 @@ fn to_json(&self) -> Json {
}
else
{
let
mut
data
=
Vec
::
with_capacity
(
2
);
data
.push
(
self
.inputs
.to_json
());
if
let
Some
(
ref
output
)
=
self
.output
{
data
.push
(
output
.to_json
());
if
!
self
.output
.is_empty
()
{
data
.push
(
self
.
output
.to_json
());
}
Json
::
Array
(
data
)
}
...
...
@@ -5025,24 +5025,21 @@ fn make_item_keywords(it: &clean::Item) -> String {
}
fn
get_index_search_type
(
item
:
&
clean
::
Item
)
->
Option
<
IndexItemFunctionType
>
{
let
(
decl
,
all
_types
)
=
match
item
.inner
{
clean
::
FunctionItem
(
ref
f
)
=>
(
&
f
.
decl
,
&
f
.all
_types
),
clean
::
MethodItem
(
ref
m
)
=>
(
&
m
.
decl
,
&
m
.all
_types
),
clean
::
TyMethodItem
(
ref
m
)
=>
(
&
m
.
decl
,
&
m
.all
_types
),
let
(
all_types
,
ret
_types
)
=
match
item
.inner
{
clean
::
FunctionItem
(
ref
f
)
=>
(
&
f
.
all_types
,
&
f
.ret
_types
),
clean
::
MethodItem
(
ref
m
)
=>
(
&
m
.
all_types
,
&
m
.ret
_types
),
clean
::
TyMethodItem
(
ref
m
)
=>
(
&
m
.
all_types
,
&
m
.ret
_types
),
_
=>
return
None
,
};
let
inputs
=
all_types
.iter
()
.map
(|
arg
|
{
get_index_type
(
&
arg
)
})
.collect
();
let
output
=
match
decl
.output
{
clean
::
FunctionRetTy
::
Return
(
ref
return_type
)
=>
{
Some
(
get_index_type
(
return_type
))
},
_
=>
None
,
};
let
output
=
ret_types
.iter
()
.map
(|
arg
|
{
get_index_type
(
&
arg
)
})
.collect
();
Some
(
IndexItemFunctionType
{
inputs
:
inputs
,
output
:
output
})
Some
(
IndexItemFunctionType
{
inputs
,
output
})
}
fn
get_index_type
(
clean_type
:
&
clean
::
Type
)
->
Type
{
...
...
src/librustdoc/html/static/main.js
浏览文件 @
aefe7509
...
...
@@ -755,13 +755,19 @@ if (!DOMTokenList.prototype.remove) {
var
lev_distance
=
MAX_LEV_DISTANCE
+
1
;
if
(
obj
&&
obj
.
type
&&
obj
.
type
.
length
>
OUTPUT_DATA
)
{
var
tmp
=
checkType
(
obj
.
type
[
OUTPUT_DATA
],
val
,
literalSearch
)
;
if
(
literalSearch
===
true
&&
tmp
===
true
)
{
ret
urn
true
;
var
ret
=
obj
.
type
[
OUTPUT_DATA
]
;
if
(
!
obj
.
type
[
OUTPUT_DATA
].
length
)
{
ret
=
[
ret
]
;
}
lev_distance
=
Math
.
min
(
tmp
,
lev_distance
);
if
(
lev_distance
===
0
)
{
return
0
;
for
(
var
x
=
0
;
x
<
ret
.
length
;
++
x
)
{
var
tmp
=
checkType
(
ret
[
x
],
val
,
literalSearch
);
if
(
literalSearch
===
true
&&
tmp
===
true
)
{
return
true
;
}
lev_distance
=
Math
.
min
(
tmp
,
lev_distance
);
if
(
lev_distance
===
0
)
{
return
0
;
}
}
}
return
literalSearch
===
true
?
false
:
lev_distance
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录