Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
50d221c9
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,发现更多精彩内容 >>
提交
50d221c9
编写于
12月 16, 2020
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace String with Symbol where possible
上级
268cbfeb
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
109 addition
and
106 deletion
+109
-106
src/librustdoc/clean/auto_trait.rs
src/librustdoc/clean/auto_trait.rs
+5
-6
src/librustdoc/clean/inline.rs
src/librustdoc/clean/inline.rs
+4
-4
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+30
-37
src/librustdoc/clean/simplify.rs
src/librustdoc/clean/simplify.rs
+3
-2
src/librustdoc/clean/types.rs
src/librustdoc/clean/types.rs
+10
-10
src/librustdoc/clean/utils.rs
src/librustdoc/clean/utils.rs
+22
-17
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+5
-8
src/librustdoc/html/render/cache.rs
src/librustdoc/html/render/cache.rs
+1
-1
src/librustdoc/json/conversions.rs
src/librustdoc/json/conversions.rs
+9
-5
src/librustdoc/passes/collect_intra_doc_links.rs
src/librustdoc/passes/collect_intra_doc_links.rs
+8
-5
src/librustdoc/passes/doc_test_lints.rs
src/librustdoc/passes/doc_test_lints.rs
+12
-11
未找到文件。
src/librustdoc/clean/auto_trait.rs
浏览文件 @
50d221c9
...
...
@@ -333,10 +333,9 @@ fn extract_for_generics(
match
br
{
// We only care about named late bound regions, as we need to add them
// to the 'for<>' section
ty
::
BrNamed
(
_
,
name
)
=>
Some
(
GenericParamDef
{
name
:
name
.to_string
(),
kind
:
GenericParamDefKind
::
Lifetime
,
}),
ty
::
BrNamed
(
_
,
name
)
=>
{
Some
(
GenericParamDef
{
name
,
kind
:
GenericParamDefKind
::
Lifetime
})
}
_
=>
None
,
}
})
...
...
@@ -569,7 +568,7 @@ fn param_env_to_generics(
}
WherePredicate
::
EqPredicate
{
lhs
,
rhs
}
=>
{
match
lhs
{
Type
::
QPath
{
name
:
ref
left_name
,
ref
self_type
,
ref
trait_
}
=>
{
Type
::
QPath
{
name
:
left_name
,
ref
self_type
,
ref
trait_
}
=>
{
let
ty
=
&*
self_type
;
match
**
trait_
{
Type
::
ResolvedPath
{
...
...
@@ -580,7 +579,7 @@ fn param_env_to_generics(
}
=>
{
let
mut
new_trait_path
=
trait_path
.clone
();
if
self
.is_fn_ty
(
tcx
,
trait_
)
&&
left_name
==
FN_OUTPUT_NAME
{
if
self
.is_fn_ty
(
tcx
,
trait_
)
&&
left_name
==
sym
::
Output
{
ty_to_fn
.entry
(
*
ty
.clone
())
.and_modify
(|
e
|
*
e
=
(
e
.0
.clone
(),
Some
(
rhs
.clone
())))
...
...
src/librustdoc/clean/inline.rs
浏览文件 @
50d221c9
...
...
@@ -12,7 +12,7 @@
use
rustc_middle
::
ty
;
use
rustc_mir
::
const_eval
::
is_min_const_fn
;
use
rustc_span
::
hygiene
::
MacroKind
;
use
rustc_span
::
symbol
::{
sym
,
Symbol
};
use
rustc_span
::
symbol
::{
kw
,
sym
,
Symbol
};
use
rustc_span
::
Span
;
use
crate
::
clean
::{
self
,
Attributes
,
GetDefId
,
ToSource
,
TypeKind
};
...
...
@@ -583,7 +583,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean:
for
pred
in
&
mut
g
.where_predicates
{
match
*
pred
{
clean
::
WherePredicate
::
BoundPredicate
{
ty
:
clean
::
Generic
(
ref
s
),
ref
mut
bounds
}
if
*
s
==
"Self"
=>
if
*
s
==
kw
::
SelfUpper
=>
{
bounds
.retain
(|
bound
|
match
*
bound
{
clean
::
GenericBound
::
TraitBound
(
...
...
@@ -606,7 +606,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean:
name
:
ref
_
name
,
},
ref
bounds
,
}
=>
!
(
bounds
.is_empty
()
||
*
s
==
"Self"
&&
did
==
trait_did
),
}
=>
!
(
bounds
.is_empty
()
||
*
s
==
kw
::
SelfUpper
&&
did
==
trait_did
),
_
=>
true
,
});
g
...
...
@@ -621,7 +621,7 @@ fn separate_supertrait_bounds(
let
mut
ty_bounds
=
Vec
::
new
();
g
.where_predicates
.retain
(|
pred
|
match
*
pred
{
clean
::
WherePredicate
::
BoundPredicate
{
ty
:
clean
::
Generic
(
ref
s
),
ref
bounds
}
if
*
s
==
"Self"
=>
if
*
s
==
kw
::
SelfUpper
=>
{
ty_bounds
.extend
(
bounds
.iter
()
.cloned
());
false
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
50d221c9
...
...
@@ -48,8 +48,6 @@
crate
use
self
::
types
::
Visibility
::{
Inherited
,
Public
};
crate
use
self
::
types
::
*
;
const
FN_OUTPUT_NAME
:
&
str
=
"Output"
;
crate
trait
Clean
<
T
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
T
;
}
...
...
@@ -329,10 +327,9 @@ fn clean(&self, cx: &DocContext<'_>) -> GenericBound {
.collect_referenced_late_bound_regions
(
&
poly_trait_ref
)
.into_iter
()
.filter_map
(|
br
|
match
br
{
ty
::
BrNamed
(
_
,
name
)
=>
Some
(
GenericParamDef
{
name
:
name
.to_string
(),
kind
:
GenericParamDefKind
::
Lifetime
,
}),
ty
::
BrNamed
(
_
,
name
)
=>
{
Some
(
GenericParamDef
{
name
,
kind
:
GenericParamDefKind
::
Lifetime
})
}
_
=>
None
,
})
.collect
();
...
...
@@ -546,7 +543,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
GenericBound
::
Outlives
(
_
)
=>
panic!
(
"cleaning a trait got a lifetime"
),
};
Type
::
QPath
{
name
:
cx
.tcx
.associated_item
(
self
.item_def_id
)
.ident.name
.clean
(
cx
)
,
name
:
cx
.tcx
.associated_item
(
self
.item_def_id
)
.ident.name
,
self_type
:
box
self
.self_ty
()
.clean
(
cx
),
trait_
:
box
trait_
,
}
...
...
@@ -556,14 +553,12 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
impl
Clean
<
GenericParamDef
>
for
ty
::
GenericParamDef
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
GenericParamDef
{
let
(
name
,
kind
)
=
match
self
.kind
{
ty
::
GenericParamDefKind
::
Lifetime
=>
{
(
self
.name
.to_string
(),
GenericParamDefKind
::
Lifetime
)
}
ty
::
GenericParamDefKind
::
Lifetime
=>
(
self
.name
,
GenericParamDefKind
::
Lifetime
),
ty
::
GenericParamDefKind
::
Type
{
has_default
,
synthetic
,
..
}
=>
{
let
default
=
if
has_default
{
Some
(
cx
.tcx
.type_of
(
self
.def_id
)
.clean
(
cx
))
}
else
{
None
};
(
self
.name
.clean
(
cx
)
,
self
.name
,
GenericParamDefKind
::
Type
{
did
:
self
.def_id
,
bounds
:
vec!
[],
// These are filled in from the where-clauses.
...
...
@@ -573,7 +568,7 @@ fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef {
)
}
ty
::
GenericParamDefKind
::
Const
{
..
}
=>
(
self
.name
.clean
(
cx
)
,
self
.name
,
GenericParamDefKind
::
Const
{
did
:
self
.def_id
,
ty
:
cx
.tcx
.type_of
(
self
.def_id
)
.clean
(
cx
),
...
...
@@ -599,14 +594,14 @@ fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef {
for
bound
in
bounds
{
s
.push_str
(
&
format!
(
" + {}"
,
bound
.name
.ident
()));
}
s
Symbol
::
intern
(
&
s
)
}
else
{
self
.name
.ident
()
.
to_string
()
self
.name
.ident
()
.
name
};
(
name
,
GenericParamDefKind
::
Lifetime
)
}
hir
::
GenericParamKind
::
Type
{
ref
default
,
synthetic
}
=>
(
self
.name
.ident
()
.name
.clean
(
cx
)
,
self
.name
.ident
()
.name
,
GenericParamDefKind
::
Type
{
did
:
cx
.tcx
.hir
()
.local_def_id
(
self
.hir_id
)
.to_def_id
(),
bounds
:
self
.bounds
.clean
(
cx
),
...
...
@@ -615,7 +610,7 @@ fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef {
},
),
hir
::
GenericParamKind
::
Const
{
ref
ty
}
=>
(
self
.name
.ident
()
.name
.clean
(
cx
)
,
self
.name
.ident
()
.name
,
GenericParamDefKind
::
Const
{
did
:
cx
.tcx
.hir
()
.local_def_id
(
self
.hir_id
)
.to_def_id
(),
ty
:
ty
.clean
(
cx
),
...
...
@@ -730,7 +725,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
.collect
::
<
Vec
<
GenericParamDef
>>
();
// param index -> [(DefId of trait, associated type name, type)]
let
mut
impl_trait_proj
=
FxHashMap
::
<
u32
,
Vec
<
(
DefId
,
S
tring
,
Ty
<
'tcx
>
)
>>
::
default
();
let
mut
impl_trait_proj
=
FxHashMap
::
<
u32
,
Vec
<
(
DefId
,
S
ymbol
,
Ty
<
'tcx
>
)
>>
::
default
();
let
where_predicates
=
preds
.predicates
...
...
@@ -778,11 +773,10 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
if
let
Some
(((
_
,
trait_did
,
name
),
rhs
))
=
proj
.as_ref
()
.and_then
(|(
lhs
,
rhs
)|
Some
((
lhs
.projection
()
?
,
rhs
)))
{
impl_trait_proj
.entry
(
param_idx
)
.or_default
()
.push
((
trait_did
,
name
.to_string
(),
rhs
,
));
impl_trait_proj
.entry
(
param_idx
)
.or_default
()
.push
((
trait_did
,
name
,
rhs
));
}
return
None
;
...
...
@@ -800,7 +794,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
if
let
crate
::
core
::
ImplTraitParam
::
ParamIndex
(
idx
)
=
param
{
if
let
Some
(
proj
)
=
impl_trait_proj
.remove
(
&
idx
)
{
for
(
trait_did
,
name
,
rhs
)
in
proj
{
simplify
::
merge_bounds
(
cx
,
&
mut
bounds
,
trait_did
,
&
name
,
&
rhs
.clean
(
cx
));
simplify
::
merge_bounds
(
cx
,
&
mut
bounds
,
trait_did
,
name
,
&
rhs
.clean
(
cx
));
}
}
}
else
{
...
...
@@ -936,9 +930,9 @@ fn clean(&self, cx: &DocContext<'_>) -> Arguments {
.iter
()
.enumerate
()
.map
(|(
i
,
ty
)|
{
let
mut
name
=
self
.1
.get
(
i
)
.map
(|
ident
|
ident
.
to_string
())
.unwrap_or_default
(
);
let
mut
name
=
self
.1
.get
(
i
)
.map
(|
ident
|
ident
.
name
)
.unwrap_or
(
kw
::
Invalid
);
if
name
.is_empty
()
{
name
=
"_"
.to_string
()
;
name
=
kw
::
Underscore
;
}
Argument
{
name
,
type_
:
ty
.clean
(
cx
)
}
})
...
...
@@ -995,7 +989,7 @@ fn clean(&self, cx: &DocContext<'_>) -> FnDecl {
.iter
()
.map
(|
t
|
Argument
{
type_
:
t
.clean
(
cx
),
name
:
names
.next
()
.map
_or_else
(||
String
::
new
(),
|
name
|
name
.to_string
()
),
name
:
names
.next
()
.map
(|
i
|
i
.name
)
.unwrap_or
(
kw
::
Invalid
),
})
.collect
(),
},
...
...
@@ -1150,12 +1144,12 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
};
let
self_arg_ty
=
sig
.input
(
0
)
.skip_binder
();
if
self_arg_ty
==
self_ty
{
decl
.inputs.values
[
0
]
.type_
=
Generic
(
String
::
from
(
"Self"
)
);
decl
.inputs.values
[
0
]
.type_
=
Generic
(
kw
::
SelfUpper
);
}
else
if
let
ty
::
Ref
(
_
,
ty
,
_
)
=
*
self_arg_ty
.kind
()
{
if
ty
==
self_ty
{
match
decl
.inputs.values
[
0
]
.type_
{
BorrowedRef
{
ref
mut
type_
,
..
}
=>
{
**
type_
=
Generic
(
String
::
from
(
"Self"
)
)
**
type_
=
Generic
(
kw
::
SelfUpper
)
}
_
=>
unreachable!
(),
}
...
...
@@ -1210,7 +1204,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
}
}
ty
::
AssocKind
::
Type
=>
{
let
my_name
=
self
.ident.name
.clean
(
cx
)
;
let
my_name
=
self
.ident.name
;
if
let
ty
::
TraitContainer
(
_
)
=
self
.container
{
let
bounds
=
cx
.tcx
.explicit_item_bounds
(
self
.def_id
);
...
...
@@ -1235,7 +1229,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
_
=>
return
None
,
}
match
**
self_type
{
Generic
(
ref
s
)
if
*
s
==
"Self"
=>
{}
Generic
(
ref
s
)
if
*
s
==
kw
::
SelfUpper
=>
{}
_
=>
return
None
,
}
Some
(
bounds
)
...
...
@@ -1408,7 +1402,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &DocContext<'_>) -> Type {
segments
:
trait_segments
.clean
(
cx
),
};
Type
::
QPath
{
name
:
p
.segments
.last
()
.expect
(
"segments were empty"
)
.ident.name
.clean
(
cx
)
,
name
:
p
.segments
.last
()
.expect
(
"segments were empty"
)
.ident.name
,
self_type
:
box
qself
.clean
(
cx
),
trait_
:
box
resolve_type
(
cx
,
trait_path
,
hir_id
),
}
...
...
@@ -1422,7 +1416,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &DocContext<'_>) -> Type {
};
let
trait_path
=
hir
::
Path
{
span
,
res
,
segments
:
&
[]
};
Type
::
QPath
{
name
:
segment
.ident.name
.clean
(
cx
)
,
name
:
segment
.ident.name
,
self_type
:
box
qself
.clean
(
cx
),
trait_
:
box
resolve_type
(
cx
,
trait_path
.clean
(
cx
),
hir_id
),
}
...
...
@@ -1625,7 +1619,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
let
mut
bindings
=
vec!
[];
for
pb
in
obj
.projection_bounds
()
{
bindings
.push
(
TypeBinding
{
name
:
cx
.tcx
.associated_item
(
pb
.item_def_id
())
.ident.name
.clean
(
cx
)
,
name
:
cx
.tcx
.associated_item
(
pb
.item_def_id
())
.ident.name
,
kind
:
TypeBindingKind
::
Equality
{
ty
:
pb
.skip_binder
()
.ty
.clean
(
cx
)
},
});
}
...
...
@@ -1644,7 +1638,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
if
let
Some
(
bounds
)
=
cx
.impl_trait_bounds
.borrow_mut
()
.remove
(
&
p
.index
.into
())
{
ImplTrait
(
bounds
)
}
else
{
Generic
(
p
.name
.to_string
()
)
Generic
(
p
.name
)
}
}
...
...
@@ -1702,8 +1696,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
.tcx
.associated_item
(
proj
.projection_ty.item_def_id
)
.ident
.name
.clean
(
cx
),
.name
,
kind
:
TypeBindingKind
::
Equality
{
ty
:
proj
.ty
.clean
(
cx
),
},
...
...
@@ -2339,7 +2332,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
impl
Clean
<
TypeBinding
>
for
hir
::
TypeBinding
<
'_
>
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
TypeBinding
{
TypeBinding
{
name
:
self
.ident.name
.clean
(
cx
)
,
kind
:
self
.kind
.clean
(
cx
)
}
TypeBinding
{
name
:
self
.ident.name
,
kind
:
self
.kind
.clean
(
cx
)
}
}
}
...
...
src/librustdoc/clean/simplify.rs
浏览文件 @
50d221c9
...
...
@@ -15,6 +15,7 @@
use
rustc_hir
::
def_id
::
DefId
;
use
rustc_middle
::
ty
;
use
rustc_span
::
Symbol
;
use
crate
::
clean
;
use
crate
::
clean
::
GenericArgs
as
PP
;
...
...
@@ -78,7 +79,7 @@
cx
:
&
clean
::
DocContext
<
'_
>
,
bounds
:
&
mut
Vec
<
clean
::
GenericBound
>
,
trait_did
:
DefId
,
name
:
&
str
,
name
:
Symbol
,
rhs
:
&
clean
::
Type
,
)
->
bool
{
!
bounds
.iter_mut
()
.any
(|
b
|
{
...
...
@@ -100,7 +101,7 @@
match
last
.args
{
PP
::
AngleBracketed
{
ref
mut
bindings
,
..
}
=>
{
bindings
.push
(
clean
::
TypeBinding
{
name
:
name
.to_string
()
,
name
,
kind
:
clean
::
TypeBindingKind
::
Equality
{
ty
:
rhs
.clone
()
},
});
}
...
...
src/librustdoc/clean/types.rs
浏览文件 @
50d221c9
...
...
@@ -949,7 +949,7 @@ impl GenericParamDefKind {
#[derive(Clone,
PartialEq,
Eq,
Debug,
Hash)]
crate
struct
GenericParamDef
{
crate
name
:
S
tring
,
crate
name
:
S
ymbol
,
crate
kind
:
GenericParamDefKind
,
}
...
...
@@ -1037,7 +1037,7 @@ impl FnDecl {
#[derive(Clone,
PartialEq,
Eq,
Debug,
Hash)]
crate
struct
Argument
{
crate
type_
:
Type
,
crate
name
:
S
tring
,
crate
name
:
S
ymbol
,
}
#[derive(Clone,
PartialEq,
Debug)]
...
...
@@ -1049,7 +1049,7 @@ impl FnDecl {
impl
Argument
{
crate
fn
to_self
(
&
self
)
->
Option
<
SelfTy
>
{
if
self
.name
!=
"self"
{
if
self
.name
!=
kw
::
SelfLower
{
return
None
;
}
if
self
.type_
.is_self_type
()
{
...
...
@@ -1117,7 +1117,7 @@ fn def_id(&self) -> Option<DefId> {
},
/// For parameterized types, so the consumer of the JSON don't go
/// looking for types which don't exist anywhere.
Generic
(
S
tring
),
Generic
(
S
ymbol
),
/// Primitives are the fixed-size numeric types (plus int/usize/float), char,
/// arrays, slices, and tuples.
Primitive
(
PrimitiveType
),
...
...
@@ -1136,7 +1136,7 @@ fn def_id(&self) -> Option<DefId> {
// `<Type as Trait>::Name`
QPath
{
name
:
S
tring
,
name
:
S
ymbol
,
self_type
:
Box
<
Type
>
,
trait_
:
Box
<
Type
>
,
},
...
...
@@ -1237,7 +1237,7 @@ impl Type {
crate
fn
is_self_type
(
&
self
)
->
bool
{
match
*
self
{
Generic
(
ref
name
)
=>
name
==
"Self"
,
Generic
(
name
)
=>
name
==
kw
::
SelfUpper
,
_
=>
false
,
}
}
...
...
@@ -1282,16 +1282,16 @@ impl Type {
}
}
crate
fn
projection
(
&
self
)
->
Option
<
(
&
Type
,
DefId
,
&
str
)
>
{
crate
fn
projection
(
&
self
)
->
Option
<
(
&
Type
,
DefId
,
Symbol
)
>
{
let
(
self_
,
trait_
,
name
)
=
match
self
{
QPath
{
ref
self_type
,
ref
trait_
,
ref
name
}
=>
(
self_type
,
trait_
,
name
),
QPath
{
ref
self_type
,
ref
trait_
,
name
}
=>
(
self_type
,
trait_
,
name
),
_
=>
return
None
,
};
let
trait_did
=
match
**
trait_
{
ResolvedPath
{
did
,
..
}
=>
did
,
_
=>
return
None
,
};
Some
((
&
self_
,
trait_did
,
name
))
Some
((
&
self_
,
trait_did
,
*
name
))
}
}
...
...
@@ -1816,7 +1816,7 @@ impl Import {
/// `A: Send + Sync` in `Foo<A: Send + Sync>`).
#[derive(Clone,
PartialEq,
Eq,
Debug,
Hash)]
crate
struct
TypeBinding
{
crate
name
:
S
tring
,
crate
name
:
S
ymbol
,
crate
kind
:
TypeBindingKind
,
}
...
...
src/librustdoc/clean/utils.rs
浏览文件 @
50d221c9
...
...
@@ -170,13 +170,13 @@ pub(super) fn external_path(
cx
:
&
DocContext
<
'_
>
,
recurse
:
i32
,
)
->
FxHashSet
<
(
Type
,
TypeKind
)
>
{
let
arg_s
=
arg
.print
()
.to_string
();
let
mut
res
=
FxHashSet
::
default
();
if
recurse
>=
10
{
// FIXME: remove this whole recurse thing when the recursion bug is fixed
return
res
;
}
if
arg
.is_full_generic
()
{
let
arg_s
=
Symbol
::
intern
(
&
arg
.print
()
.to_string
());
if
let
Some
(
where_pred
)
=
generics
.where_predicates
.iter
()
.find
(|
g
|
match
g
{
&
WherePredicate
::
BoundPredicate
{
ref
ty
,
..
}
=>
ty
.def_id
()
==
arg
.def_id
(),
_
=>
false
,
...
...
@@ -375,13 +375,13 @@ fn to_src(&self, cx: &DocContext<'_>) -> String {
}
}
crate
fn
name_from_pat
(
p
:
&
hir
::
Pat
<
'_
>
)
->
S
tring
{
crate
fn
name_from_pat
(
p
:
&
hir
::
Pat
<
'_
>
)
->
S
ymbol
{
use
rustc_hir
::
*
;
debug!
(
"trying to get a name from pattern: {:?}"
,
p
);
match
p
.kind
{
PatKind
::
Wild
=>
"_"
.to_string
()
,
PatKind
::
Binding
(
_
,
_
,
ident
,
_
)
=>
ident
.to_string
()
,
Symbol
::
intern
(
&
match
p
.kind
{
PatKind
::
Wild
=>
return
kw
::
Underscore
,
PatKind
::
Binding
(
_
,
_
,
ident
,
_
)
=>
return
ident
.name
,
PatKind
::
TupleStruct
(
ref
p
,
..
)
|
PatKind
::
Path
(
ref
p
)
=>
qpath_to_string
(
p
),
PatKind
::
Struct
(
ref
name
,
ref
fields
,
etc
)
=>
format!
(
"{} {{ {}{} }}"
,
...
...
@@ -393,32 +393,37 @@ fn to_src(&self, cx: &DocContext<'_>) -> String {
.join
(
", "
),
if
etc
{
", .."
}
else
{
""
}
),
PatKind
::
Or
(
ref
pats
)
=>
{
pats
.iter
()
.map
(|
p
|
name_from_pat
(
&**
p
))
.collect
::
<
Vec
<
String
>>
()
.join
(
" | "
)
}
PatKind
::
Or
(
ref
pats
)
=>
pats
.iter
()
.map
(|
p
|
name_from_pat
(
&**
p
)
.to_string
())
.collect
::
<
Vec
<
String
>>
()
.join
(
" | "
),
PatKind
::
Tuple
(
ref
elts
,
_
)
=>
format!
(
"({})"
,
elts
.iter
()
.map
(|
p
|
name_from_pat
(
&**
p
))
.collect
::
<
Vec
<
String
>>
()
.join
(
", "
)
elts
.iter
()
.map
(|
p
|
name_from_pat
(
&**
p
)
.to_string
())
.collect
::
<
Vec
<
String
>>
()
.join
(
", "
)
),
PatKind
::
Box
(
ref
p
)
=>
name_from_pat
(
&**
p
),
PatKind
::
Ref
(
ref
p
,
_
)
=>
name_from_pat
(
&**
p
),
PatKind
::
Box
(
ref
p
)
=>
return
name_from_pat
(
&**
p
),
PatKind
::
Ref
(
ref
p
,
_
)
=>
return
name_from_pat
(
&**
p
),
PatKind
::
Lit
(
..
)
=>
{
warn!
(
"tried to get argument name from PatKind::Lit, which is silly in function arguments"
);
"()"
.to_string
()
return
Symbol
::
intern
(
"()"
);
}
PatKind
::
Range
(
..
)
=>
panic!
(
"tried to get argument name from PatKind::Range,
\
which is not allowed in function arguments"
),
PatKind
::
Slice
(
ref
begin
,
ref
mid
,
ref
end
)
=>
{
let
begin
=
begin
.iter
()
.map
(|
p
|
name_from_pat
(
&**
p
));
let
begin
=
begin
.iter
()
.map
(|
p
|
name_from_pat
(
&**
p
)
.to_string
()
);
let
mid
=
mid
.as_ref
()
.map
(|
p
|
format!
(
"..{}"
,
name_from_pat
(
&**
p
)))
.into_iter
();
let
end
=
end
.iter
()
.map
(|
p
|
name_from_pat
(
&**
p
));
let
end
=
end
.iter
()
.map
(|
p
|
name_from_pat
(
&**
p
)
.to_string
()
);
format!
(
"[{}]"
,
begin
.chain
(
mid
)
.chain
(
end
)
.collect
::
<
Vec
<
_
>>
()
.join
(
", "
))
}
}
}
)
}
crate
fn
print_const
(
cx
:
&
DocContext
<
'_
>
,
n
:
&
'tcx
ty
::
Const
<
'_
>
)
->
String
{
...
...
@@ -534,10 +539,10 @@ fn print_const_with_custom_print_scalar(cx: &DocContext<'_>, ct: &'tcx ty::Const
let
is_generic
=
match
path
.res
{
Res
::
PrimTy
(
p
)
=>
return
Primitive
(
PrimitiveType
::
from
(
p
)),
Res
::
SelfTy
(
..
)
if
path
.segments
.len
()
==
1
=>
{
return
Generic
(
kw
::
SelfUpper
.to_string
()
);
return
Generic
(
kw
::
SelfUpper
);
}
Res
::
Def
(
DefKind
::
TyParam
,
_
)
if
path
.segments
.len
()
==
1
=>
{
return
Generic
(
format!
(
"{:#}"
,
path
.print
(
)));
return
Generic
(
Symbol
::
intern
(
&
format!
(
"{:#}"
,
path
.print
()
)));
}
Res
::
SelfTy
(
..
)
|
Res
::
Def
(
DefKind
::
TyParam
|
DefKind
::
AssocTy
,
_
)
=>
true
,
_
=>
false
,
...
...
src/librustdoc/html/format.rs
浏览文件 @
50d221c9
...
...
@@ -172,7 +172,7 @@ impl clean::GenericParamDef {
display_fn
(
move
|
f
|
match
self
.kind
{
clean
::
GenericParamDefKind
::
Lifetime
=>
write!
(
f
,
"{}"
,
self
.name
),
clean
::
GenericParamDefKind
::
Type
{
ref
bounds
,
ref
default
,
..
}
=>
{
f
.write_str
(
&
self
.name
)
?
;
f
.write_str
(
&
*
self
.name
.as_str
()
)
?
;
if
!
bounds
.is_empty
()
{
if
f
.alternate
()
{
...
...
@@ -193,13 +193,10 @@ impl clean::GenericParamDef {
Ok
(())
}
clean
::
GenericParamDefKind
::
Const
{
ref
ty
,
..
}
=>
{
f
.write_str
(
"const "
)
?
;
f
.write_str
(
&
self
.name
)
?
;
if
f
.alternate
()
{
write!
(
f
,
"
: {:#}"
,
ty
.print
())
write!
(
f
,
"
const {}: {:#}"
,
self
.name
,
ty
.print
())
}
else
{
write!
(
f
,
"
: {}"
,
ty
.print
())
write!
(
f
,
"
const {}: {}"
,
self
.name
,
ty
.print
())
}
}
})
...
...
@@ -638,7 +635,7 @@ fn tybounds(param_names: &Option<Vec<clean::GenericBound>>) -> impl fmt::Display
fn
fmt_type
(
t
:
&
clean
::
Type
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
,
use_absolute
:
bool
)
->
fmt
::
Result
{
match
*
t
{
clean
::
Generic
(
ref
name
)
=>
f
.write_str
(
name
),
clean
::
Generic
(
name
)
=>
write!
(
f
,
"{}"
,
name
),
clean
::
ResolvedPath
{
did
,
ref
param_names
,
ref
path
,
is_generic
}
=>
{
if
param_names
.is_some
()
{
f
.write_str
(
"dyn "
)
?
;
...
...
@@ -1203,7 +1200,7 @@ impl clean::ImportSource {
impl
clean
::
TypeBinding
{
crate
fn
print
(
&
self
)
->
impl
fmt
::
Display
+
'_
{
display_fn
(
move
|
f
|
{
f
.write_str
(
&
self
.name
)
?
;
f
.write_str
(
&
*
self
.name
.as_str
()
)
?
;
match
self
.kind
{
clean
::
TypeBindingKind
::
Equality
{
ref
ty
}
=>
{
if
f
.alternate
()
{
...
...
src/librustdoc/html/render/cache.rs
浏览文件 @
50d221c9
...
...
@@ -208,7 +208,7 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
});
Some
(
path_segment
.name
.clone
())
}
clean
::
Generic
(
ref
s
)
if
accept_generic
=>
Some
(
s
.clone
()),
clean
::
Generic
(
s
)
if
accept_generic
=>
Some
(
s
.to_string
()),
clean
::
Primitive
(
ref
p
)
=>
Some
(
format!
(
"{:?}"
,
p
)),
clean
::
BorrowedRef
{
ref
type_
,
..
}
=>
get_index_type_name
(
type_
,
accept_generic
),
// FIXME: add all from clean::Type.
...
...
src/librustdoc/json/conversions.rs
浏览文件 @
50d221c9
...
...
@@ -136,7 +136,7 @@ fn from(constant: clean::Constant) -> Self {
impl
From
<
clean
::
TypeBinding
>
for
TypeBinding
{
fn
from
(
binding
:
clean
::
TypeBinding
)
->
Self
{
TypeBinding
{
name
:
binding
.name
,
binding
:
binding
.kind
.into
()
}
TypeBinding
{
name
:
binding
.name
.to_string
()
,
binding
:
binding
.kind
.into
()
}
}
}
...
...
@@ -275,7 +275,7 @@ fn from(generics: clean::Generics) -> Self {
impl
From
<
clean
::
GenericParamDef
>
for
GenericParamDef
{
fn
from
(
generic_param
:
clean
::
GenericParamDef
)
->
Self
{
GenericParamDef
{
name
:
generic_param
.name
,
kind
:
generic_param
.kind
.into
()
}
GenericParamDef
{
name
:
generic_param
.name
.to_string
()
,
kind
:
generic_param
.kind
.into
()
}
}
}
...
...
@@ -351,7 +351,7 @@ fn from(ty: clean::Type) -> Self {
.map
(|
v
|
v
.into_iter
()
.map
(
Into
::
into
)
.collect
())
.unwrap_or_default
(),
},
Generic
(
s
)
=>
Type
::
Generic
(
s
),
Generic
(
s
)
=>
Type
::
Generic
(
s
.to_string
()
),
Primitive
(
p
)
=>
Type
::
Primitive
(
p
.as_str
()
.to_string
()),
BareFunction
(
f
)
=>
Type
::
FunctionPointer
(
Box
::
new
((
*
f
)
.into
())),
Tuple
(
t
)
=>
Type
::
Tuple
(
t
.into_iter
()
.map
(
Into
::
into
)
.collect
()),
...
...
@@ -370,7 +370,7 @@ fn from(ty: clean::Type) -> Self {
type_
:
Box
::
new
((
*
type_
)
.into
()),
},
QPath
{
name
,
self_type
,
trait_
}
=>
Type
::
QualifiedPath
{
name
,
name
:
name
.to_string
()
,
self_type
:
Box
::
new
((
*
self_type
)
.into
()),
trait_
:
Box
::
new
((
*
trait_
)
.into
()),
},
...
...
@@ -394,7 +394,11 @@ impl From<clean::FnDecl> for FnDecl {
fn
from
(
decl
:
clean
::
FnDecl
)
->
Self
{
let
clean
::
FnDecl
{
inputs
,
output
,
c_variadic
,
attrs
:
_
}
=
decl
;
FnDecl
{
inputs
:
inputs
.values
.into_iter
()
.map
(|
arg
|
(
arg
.name
,
arg
.type_
.into
()))
.collect
(),
inputs
:
inputs
.values
.into_iter
()
.map
(|
arg
|
(
arg
.name
.to_string
(),
arg
.type_
.into
()))
.collect
(),
output
:
match
output
{
clean
::
FnRetTy
::
Return
(
t
)
=>
Some
(
t
.into
()),
clean
::
FnRetTy
::
DefaultReturn
=>
None
,
...
...
src/librustdoc/passes/collect_intra_doc_links.rs
浏览文件 @
50d221c9
...
...
@@ -753,11 +753,14 @@ fn traits_implemented_by(cx: &DocContext<'_>, type_: DefId, module: DefId) -> Fx
///
/// These are common and we should just resolve to the trait in that case.
fn
is_derive_trait_collision
<
T
>
(
ns
:
&
PerNS
<
Result
<
(
Res
,
T
),
ResolutionFailure
<
'_
>>>
)
->
bool
{
matches!
(
*
ns
,
PerNS
{
type_ns
:
Ok
((
Res
::
Def
(
DefKind
::
Trait
,
_
),
_
)),
macro_ns
:
Ok
((
Res
::
Def
(
DefKind
::
Macro
(
MacroKind
::
Derive
),
_
),
_
)),
..
})
matches!
(
*
ns
,
PerNS
{
type_ns
:
Ok
((
Res
::
Def
(
DefKind
::
Trait
,
_
),
_
)),
macro_ns
:
Ok
((
Res
::
Def
(
DefKind
::
Macro
(
MacroKind
::
Derive
),
_
),
_
)),
..
}
)
}
impl
<
'a
,
'tcx
>
DocFolder
for
LinkCollector
<
'a
,
'tcx
>
{
...
...
src/librustdoc/passes/doc_test_lints.rs
浏览文件 @
50d221c9
...
...
@@ -58,18 +58,19 @@ fn add_test(&mut self, _: String, config: LangString, _: usize) {
}
crate
fn
should_have_doc_example
(
cx
:
&
DocContext
<
'_
>
,
item
:
&
clean
::
Item
)
->
bool
{
if
matches!
(
item
.kind
,
if
matches!
(
item
.kind
,
clean
::
StructFieldItem
(
_
)
|
clean
::
VariantItem
(
_
)
|
clean
::
AssocConstItem
(
_
,
_
)
|
clean
::
AssocTypeItem
(
_
,
_
)
|
clean
::
TypedefItem
(
_
,
_
)
|
clean
::
StaticItem
(
_
)
|
clean
::
ConstantItem
(
_
)
|
clean
::
ExternCrateItem
(
_
,
_
)
|
clean
::
ImportItem
(
_
)
|
clean
::
PrimitiveItem
(
_
)
|
clean
::
KeywordItem
(
_
)
|
clean
::
VariantItem
(
_
)
|
clean
::
AssocConstItem
(
_
,
_
)
|
clean
::
AssocTypeItem
(
_
,
_
)
|
clean
::
TypedefItem
(
_
,
_
)
|
clean
::
StaticItem
(
_
)
|
clean
::
ConstantItem
(
_
)
|
clean
::
ExternCrateItem
(
_
,
_
)
|
clean
::
ImportItem
(
_
)
|
clean
::
PrimitiveItem
(
_
)
|
clean
::
KeywordItem
(
_
)
)
{
return
false
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录