Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a2fb4b95
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,发现更多精彩内容 >>
提交
a2fb4b95
编写于
12月 16, 2020
作者:
J
Joshua Nelson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove `DefPath` from `Visibility` and calculate it on demand
上级
d8d3ab96
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
75 addition
and
61 deletion
+75
-61
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+11
-8
src/librustdoc/clean/types.rs
src/librustdoc/clean/types.rs
+2
-2
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+6
-5
src/librustdoc/html/render/mod.rs
src/librustdoc/html/render/mod.rs
+43
-31
src/librustdoc/json/conversions.rs
src/librustdoc/json/conversions.rs
+13
-15
未找到文件。
src/librustdoc/clean/mod.rs
浏览文件 @
a2fb4b95
...
@@ -1775,25 +1775,28 @@ fn clean(&self, cx: &DocContext<'_>) -> Visibility {
...
@@ -1775,25 +1775,28 @@ fn clean(&self, cx: &DocContext<'_>) -> Visibility {
hir
::
VisibilityKind
::
Inherited
=>
Visibility
::
Inherited
,
hir
::
VisibilityKind
::
Inherited
=>
Visibility
::
Inherited
,
hir
::
VisibilityKind
::
Crate
(
_
)
=>
{
hir
::
VisibilityKind
::
Crate
(
_
)
=>
{
let
krate
=
DefId
::
local
(
CRATE_DEF_INDEX
);
let
krate
=
DefId
::
local
(
CRATE_DEF_INDEX
);
Visibility
::
Restricted
(
krate
,
cx
.tcx
.def_path
(
krate
)
)
Visibility
::
Restricted
(
krate
)
}
}
hir
::
VisibilityKind
::
Restricted
{
ref
path
,
..
}
=>
{
hir
::
VisibilityKind
::
Restricted
{
ref
path
,
..
}
=>
{
let
path
=
path
.clean
(
cx
);
let
path
=
path
.clean
(
cx
);
let
did
=
register_res
(
cx
,
path
.res
);
let
did
=
register_res
(
cx
,
path
.res
);
Visibility
::
Restricted
(
did
,
cx
.tcx
.def_path
(
did
)
)
Visibility
::
Restricted
(
did
)
}
}
}
}
}
}
}
}
impl
Clean
<
Visibility
>
for
ty
::
Visibility
{
impl
Clean
<
Visibility
>
for
ty
::
Visibility
{
fn
clean
(
&
self
,
cx
:
&
DocContext
<
'_
>
)
->
Visibility
{
fn
clean
(
&
self
,
_
cx
:
&
DocContext
<
'_
>
)
->
Visibility
{
match
*
self
{
match
*
self
{
ty
::
Visibility
::
Public
=>
Visibility
::
Public
,
ty
::
Visibility
::
Public
=>
Visibility
::
Public
,
// NOTE: this is not quite right: `ty` uses `Invisible` to mean 'private',
// while rustdoc really does mean inherited. That means that for enum variants, such as
// `pub enum E { V }`, `V` will be marked as `Public` by `ty`, but as `Inherited` by rustdoc.
// This is the main reason `impl Clean for hir::Visibility` still exists; various parts of clean
// override `tcx.visibility` explicitly to make sure this distinction is captured.
ty
::
Visibility
::
Invisible
=>
Visibility
::
Inherited
,
ty
::
Visibility
::
Invisible
=>
Visibility
::
Inherited
,
ty
::
Visibility
::
Restricted
(
module
)
=>
{
ty
::
Visibility
::
Restricted
(
module
)
=>
Visibility
::
Restricted
(
module
),
Visibility
::
Restricted
(
module
,
cx
.tcx
.def_path
(
module
))
}
}
}
}
}
}
}
...
@@ -2303,14 +2306,14 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
...
@@ -2303,14 +2306,14 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
if
matchers
.len
()
<=
1
{
if
matchers
.len
()
<=
1
{
format!
(
format!
(
"{}macro {}{} {{
\n
...
\n
}}"
,
"{}macro {}{} {{
\n
...
\n
}}"
,
vis
.print_with_space
(),
vis
.print_with_space
(
cx
.tcx
),
name
,
name
,
matchers
.iter
()
.map
(|
span
|
span
.to_src
(
cx
))
.collect
::
<
String
>
(),
matchers
.iter
()
.map
(|
span
|
span
.to_src
(
cx
))
.collect
::
<
String
>
(),
)
)
}
else
{
}
else
{
format!
(
format!
(
"{}macro {} {{
\n
{}}}"
,
"{}macro {} {{
\n
{}}}"
,
vis
.print_with_space
(),
vis
.print_with_space
(
cx
.tcx
),
name
,
name
,
matchers
matchers
.iter
()
.iter
()
...
...
src/librustdoc/clean/types.rs
浏览文件 @
a2fb4b95
...
@@ -1569,11 +1569,11 @@ fn from(prim_ty: hir::PrimTy) -> PrimitiveType {
...
@@ -1569,11 +1569,11 @@ fn from(prim_ty: hir::PrimTy) -> PrimitiveType {
}
}
}
}
#[derive(Clone,
Debug)]
#[derive(C
opy,
C
lone,
Debug)]
crate
enum
Visibility
{
crate
enum
Visibility
{
Public
,
Public
,
Inherited
,
Inherited
,
Restricted
(
DefId
,
rustc_hir
::
definitions
::
DefPath
),
Restricted
(
DefId
),
}
}
impl
Visibility
{
impl
Visibility
{
...
...
src/librustdoc/html/format.rs
浏览文件 @
a2fb4b95
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
rustc_hir
as
hir
;
use
rustc_hir
as
hir
;
use
rustc_middle
::
ty
::
TyCtxt
;
use
rustc_span
::
def_id
::{
DefId
,
CRATE_DEF_INDEX
};
use
rustc_span
::
def_id
::{
DefId
,
CRATE_DEF_INDEX
};
use
rustc_target
::
spec
::
abi
::
Abi
;
use
rustc_target
::
spec
::
abi
::
Abi
;
...
@@ -1084,18 +1085,18 @@ impl Function<'_> {
...
@@ -1084,18 +1085,18 @@ impl Function<'_> {
}
}
impl
clean
::
Visibility
{
impl
clean
::
Visibility
{
crate
fn
print_with_space
(
&
self
)
->
impl
fmt
::
Display
+
'_
{
crate
fn
print_with_space
<
'tcx
>
(
self
,
tcx
:
TyCtxt
<
'tcx
>
)
->
impl
fmt
::
Display
+
'tcx
{
use
rustc_span
::
symbol
::
kw
;
use
rustc_span
::
symbol
::
kw
;
display_fn
(
move
|
f
|
match
*
self
{
display_fn
(
move
|
f
|
match
self
{
clean
::
Public
=>
f
.write_str
(
"pub "
),
clean
::
Public
=>
f
.write_str
(
"pub "
),
clean
::
Inherited
=>
Ok
(()),
clean
::
Inherited
=>
Ok
(()),
// If this is `pub(crate)`, `path` will be empty.
clean
::
Visibility
::
Restricted
(
did
)
if
did
.index
==
CRATE_DEF_INDEX
=>
{
clean
::
Visibility
::
Restricted
(
did
,
_
)
if
did
.index
==
CRATE_DEF_INDEX
=>
{
write!
(
f
,
"pub(crate) "
)
write!
(
f
,
"pub(crate) "
)
}
}
clean
::
Visibility
::
Restricted
(
did
,
ref
path
)
=>
{
clean
::
Visibility
::
Restricted
(
did
)
=>
{
f
.write_str
(
"pub("
)
?
;
f
.write_str
(
"pub("
)
?
;
let
path
=
tcx
.def_path
(
did
);
debug!
(
"path={:?}"
,
path
);
debug!
(
"path={:?}"
,
path
);
let
first_name
=
let
first_name
=
path
.data
[
0
]
.data
.get_opt_name
()
.expect
(
"modules are always named"
);
path
.data
[
0
]
.data
.get_opt_name
()
.expect
(
"modules are always named"
);
...
...
src/librustdoc/html/render/mod.rs
浏览文件 @
a2fb4b95
...
@@ -164,7 +164,7 @@
...
@@ -164,7 +164,7 @@
playground
:
Option
<
markdown
::
Playground
>
,
playground
:
Option
<
markdown
::
Playground
>
,
}
}
impl
Context
<
'_
>
{
impl
<
'tcx
>
Context
<
'tcx
>
{
fn
path
(
&
self
,
filename
:
&
str
)
->
PathBuf
{
fn
path
(
&
self
,
filename
:
&
str
)
->
PathBuf
{
// We use splitn vs Path::extension here because we might get a filename
// We use splitn vs Path::extension here because we might get a filename
// like `style.min.css` and we want to process that into
// like `style.min.css` and we want to process that into
...
@@ -176,6 +176,10 @@ fn path(&self, filename: &str) -> PathBuf {
...
@@ -176,6 +176,10 @@ fn path(&self, filename: &str) -> PathBuf {
self
.dst
.join
(
&
filename
)
self
.dst
.join
(
&
filename
)
}
}
fn
tcx
(
&
self
)
->
TyCtxt
<
'tcx
>
{
self
.shared.tcx
}
fn
sess
(
&
self
)
->
&
Session
{
fn
sess
(
&
self
)
->
&
Session
{
&
self
.shared.tcx.sess
&
self
.shared.tcx.sess
}
}
...
@@ -2147,14 +2151,14 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering
...
@@ -2147,14 +2151,14 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering
Some
(
ref
src
)
=>
write!
(
Some
(
ref
src
)
=>
write!
(
w
,
w
,
"<tr><td><code>{}extern crate {} as {};"
,
"<tr><td><code>{}extern crate {} as {};"
,
myitem
.visibility
.print_with_space
(),
myitem
.visibility
.print_with_space
(
cx
.tcx
()
),
anchor
(
myitem
.def_id
,
&*
src
.as_str
()),
anchor
(
myitem
.def_id
,
&*
src
.as_str
()),
name
name
),
),
None
=>
write!
(
None
=>
write!
(
w
,
w
,
"<tr><td><code>{}extern crate {};"
,
"<tr><td><code>{}extern crate {};"
,
myitem
.visibility
.print_with_space
(),
myitem
.visibility
.print_with_space
(
cx
.tcx
()
),
anchor
(
myitem
.def_id
,
&*
name
.as_str
())
anchor
(
myitem
.def_id
,
&*
name
.as_str
())
),
),
}
}
...
@@ -2165,7 +2169,7 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering
...
@@ -2165,7 +2169,7 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, idx1: usize, idx2: usize) -> Ordering
write!
(
write!
(
w
,
w
,
"<tr><td><code>{}{}</code></td></tr>"
,
"<tr><td><code>{}{}</code></td></tr>"
,
myitem
.visibility
.print_with_space
(),
myitem
.visibility
.print_with_space
(
cx
.tcx
()
),
import
.print
()
import
.print
()
);
);
}
}
...
@@ -2379,7 +2383,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
...
@@ -2379,7 +2383,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
write!
(
write!
(
w
,
w
,
"{vis}const {name}: {typ}"
,
"{vis}const {name}: {typ}"
,
vis
=
it
.visibility
.print_with_space
(),
vis
=
it
.visibility
.print_with_space
(
cx
.tcx
()
),
name
=
it
.name
.as_ref
()
.unwrap
(),
name
=
it
.name
.as_ref
()
.unwrap
(),
typ
=
c
.type_
.print
(),
typ
=
c
.type_
.print
(),
);
);
...
@@ -2413,7 +2417,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
...
@@ -2413,7 +2417,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
write!
(
write!
(
w
,
w
,
"{vis}static {mutability}{name}: {typ}</pre>"
,
"{vis}static {mutability}{name}: {typ}</pre>"
,
vis
=
it
.visibility
.print_with_space
(),
vis
=
it
.visibility
.print_with_space
(
cx
.tcx
()
),
mutability
=
s
.mutability
.print_with_space
(),
mutability
=
s
.mutability
.print_with_space
(),
name
=
it
.name
.as_ref
()
.unwrap
(),
name
=
it
.name
.as_ref
()
.unwrap
(),
typ
=
s
.type_
.print
()
typ
=
s
.type_
.print
()
...
@@ -2424,7 +2428,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
...
@@ -2424,7 +2428,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
fn
item_function
(
w
:
&
mut
Buffer
,
cx
:
&
Context
<
'_
>
,
it
:
&
clean
::
Item
,
f
:
&
clean
::
Function
)
{
fn
item_function
(
w
:
&
mut
Buffer
,
cx
:
&
Context
<
'_
>
,
it
:
&
clean
::
Item
,
f
:
&
clean
::
Function
)
{
let
header_len
=
format!
(
let
header_len
=
format!
(
"{}{}{}{}{:#}fn {}{:#}"
,
"{}{}{}{}{:#}fn {}{:#}"
,
it
.visibility
.print_with_space
(),
it
.visibility
.print_with_space
(
cx
.tcx
()
),
f
.header.constness
.print_with_space
(),
f
.header.constness
.print_with_space
(),
f
.header.asyncness
.print_with_space
(),
f
.header.asyncness
.print_with_space
(),
f
.header.unsafety
.print_with_space
(),
f
.header.unsafety
.print_with_space
(),
...
@@ -2439,7 +2443,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
...
@@ -2439,7 +2443,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
w
,
w
,
"{vis}{constness}{asyncness}{unsafety}{abi}fn
\
"{vis}{constness}{asyncness}{unsafety}{abi}fn
\
{name}{generics}{decl}{spotlight}{where_clause}</pre>"
,
{name}{generics}{decl}{spotlight}{where_clause}</pre>"
,
vis
=
it
.visibility
.print_with_space
(),
vis
=
it
.visibility
.print_with_space
(
cx
.tcx
()
),
constness
=
f
.header.constness
.print_with_space
(),
constness
=
f
.header.constness
.print_with_space
(),
asyncness
=
f
.header.asyncness
.print_with_space
(),
asyncness
=
f
.header.asyncness
.print_with_space
(),
unsafety
=
f
.header.unsafety
.print_with_space
(),
unsafety
=
f
.header.unsafety
.print_with_space
(),
...
@@ -2565,7 +2569,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
...
@@ -2565,7 +2569,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
write!
(
write!
(
w
,
w
,
"{}{}{}trait {}{}{}"
,
"{}{}{}trait {}{}{}"
,
it
.visibility
.print_with_space
(),
it
.visibility
.print_with_space
(
cx
.tcx
()
),
t
.unsafety
.print_with_space
(),
t
.unsafety
.print_with_space
(),
if
t
.is_auto
{
"auto "
}
else
{
""
},
if
t
.is_auto
{
"auto "
}
else
{
""
},
it
.name
.as_ref
()
.unwrap
(),
it
.name
.as_ref
()
.unwrap
(),
...
@@ -2585,21 +2589,21 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
...
@@ -2585,21 +2589,21 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
// FIXME: we should be using a derived_id for the Anchors here
// FIXME: we should be using a derived_id for the Anchors here
write!
(
w
,
"{{
\n
"
);
write!
(
w
,
"{{
\n
"
);
for
t
in
&
types
{
for
t
in
&
types
{
render_assoc_item
(
w
,
t
,
AssocItemLink
::
Anchor
(
None
),
ItemType
::
Trait
);
render_assoc_item
(
w
,
t
,
AssocItemLink
::
Anchor
(
None
),
ItemType
::
Trait
,
cx
);
write!
(
w
,
";
\n
"
);
write!
(
w
,
";
\n
"
);
}
}
if
!
types
.is_empty
()
&&
!
consts
.is_empty
()
{
if
!
types
.is_empty
()
&&
!
consts
.is_empty
()
{
w
.write_str
(
"
\n
"
);
w
.write_str
(
"
\n
"
);
}
}
for
t
in
&
consts
{
for
t
in
&
consts
{
render_assoc_item
(
w
,
t
,
AssocItemLink
::
Anchor
(
None
),
ItemType
::
Trait
);
render_assoc_item
(
w
,
t
,
AssocItemLink
::
Anchor
(
None
),
ItemType
::
Trait
,
cx
);
write!
(
w
,
";
\n
"
);
write!
(
w
,
";
\n
"
);
}
}
if
!
consts
.is_empty
()
&&
!
required
.is_empty
()
{
if
!
consts
.is_empty
()
&&
!
required
.is_empty
()
{
w
.write_str
(
"
\n
"
);
w
.write_str
(
"
\n
"
);
}
}
for
(
pos
,
m
)
in
required
.iter
()
.enumerate
()
{
for
(
pos
,
m
)
in
required
.iter
()
.enumerate
()
{
render_assoc_item
(
w
,
m
,
AssocItemLink
::
Anchor
(
None
),
ItemType
::
Trait
);
render_assoc_item
(
w
,
m
,
AssocItemLink
::
Anchor
(
None
),
ItemType
::
Trait
,
cx
);
write!
(
w
,
";
\n
"
);
write!
(
w
,
";
\n
"
);
if
pos
<
required
.len
()
-
1
{
if
pos
<
required
.len
()
-
1
{
...
@@ -2610,7 +2614,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
...
@@ -2610,7 +2614,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
w
.write_str
(
"
\n
"
);
w
.write_str
(
"
\n
"
);
}
}
for
(
pos
,
m
)
in
provided
.iter
()
.enumerate
()
{
for
(
pos
,
m
)
in
provided
.iter
()
.enumerate
()
{
render_assoc_item
(
w
,
m
,
AssocItemLink
::
Anchor
(
None
),
ItemType
::
Trait
);
render_assoc_item
(
w
,
m
,
AssocItemLink
::
Anchor
(
None
),
ItemType
::
Trait
,
cx
);
match
m
.kind
{
match
m
.kind
{
clean
::
MethodItem
(
ref
inner
,
_
)
clean
::
MethodItem
(
ref
inner
,
_
)
if
!
inner
.generics.where_predicates
.is_empty
()
=>
if
!
inner
.generics.where_predicates
.is_empty
()
=>
...
@@ -2659,7 +2663,7 @@ fn trait_item(
...
@@ -2659,7 +2663,7 @@ fn trait_item(
let
item_type
=
m
.type_
();
let
item_type
=
m
.type_
();
let
id
=
cx
.derive_id
(
format!
(
"{}.{}"
,
item_type
,
name
));
let
id
=
cx
.derive_id
(
format!
(
"{}.{}"
,
item_type
,
name
));
write!
(
w
,
"<h3 id=
\"
{id}
\"
class=
\"
method
\"
><code>"
,
id
=
id
,);
write!
(
w
,
"<h3 id=
\"
{id}
\"
class=
\"
method
\"
><code>"
,
id
=
id
,);
render_assoc_item
(
w
,
m
,
AssocItemLink
::
Anchor
(
Some
(
&
id
)),
ItemType
::
Impl
);
render_assoc_item
(
w
,
m
,
AssocItemLink
::
Anchor
(
Some
(
&
id
)),
ItemType
::
Impl
,
cx
);
write!
(
w
,
"</code>"
);
write!
(
w
,
"</code>"
);
render_stability_since
(
w
,
m
,
t
);
render_stability_since
(
w
,
m
,
t
);
write_srclink
(
cx
,
m
,
w
,
cache
);
write_srclink
(
cx
,
m
,
w
,
cache
);
...
@@ -2877,12 +2881,13 @@ fn assoc_const(
...
@@ -2877,12 +2881,13 @@ fn assoc_const(
_
default
:
Option
<&
String
>
,
_
default
:
Option
<&
String
>
,
link
:
AssocItemLink
<
'_
>
,
link
:
AssocItemLink
<
'_
>
,
extra
:
&
str
,
extra
:
&
str
,
cx
:
&
Context
<
'_
>
,
)
{
)
{
write!
(
write!
(
w
,
w
,
"{}{}const <a href=
\"
{}
\"
class=
\"
constant
\"
><b>{}</b></a>: {}"
,
"{}{}const <a href=
\"
{}
\"
class=
\"
constant
\"
><b>{}</b></a>: {}"
,
extra
,
extra
,
it
.visibility
.print_with_space
(),
it
.visibility
.print_with_space
(
cx
.tcx
()
),
naive_assoc_href
(
it
,
link
),
naive_assoc_href
(
it
,
link
),
it
.name
.as_ref
()
.unwrap
(),
it
.name
.as_ref
()
.unwrap
(),
ty
.print
()
ty
.print
()
...
@@ -2965,6 +2970,7 @@ fn render_assoc_item(
...
@@ -2965,6 +2970,7 @@ fn render_assoc_item(
item
:
&
clean
::
Item
,
item
:
&
clean
::
Item
,
link
:
AssocItemLink
<
'_
>
,
link
:
AssocItemLink
<
'_
>
,
parent
:
ItemType
,
parent
:
ItemType
,
cx
:
&
Context
<
'_
>
,
)
{
)
{
fn
method
(
fn
method
(
w
:
&
mut
Buffer
,
w
:
&
mut
Buffer
,
...
@@ -2974,6 +2980,7 @@ fn method(
...
@@ -2974,6 +2980,7 @@ fn method(
d
:
&
clean
::
FnDecl
,
d
:
&
clean
::
FnDecl
,
link
:
AssocItemLink
<
'_
>
,
link
:
AssocItemLink
<
'_
>
,
parent
:
ItemType
,
parent
:
ItemType
,
cx
:
&
Context
<
'_
>
,
)
{
)
{
let
name
=
meth
.name
.as_ref
()
.unwrap
();
let
name
=
meth
.name
.as_ref
()
.unwrap
();
let
anchor
=
format!
(
"#{}.{}"
,
meth
.type_
(),
name
);
let
anchor
=
format!
(
"#{}.{}"
,
meth
.type_
(),
name
);
...
@@ -2994,7 +3001,7 @@ fn method(
...
@@ -2994,7 +3001,7 @@ fn method(
};
};
let
mut
header_len
=
format!
(
let
mut
header_len
=
format!
(
"{}{}{}{}{}{:#}fn {}{:#}"
,
"{}{}{}{}{}{:#}fn {}{:#}"
,
meth
.visibility
.print_with_space
(),
meth
.visibility
.print_with_space
(
cx
.tcx
()
),
header
.constness
.print_with_space
(),
header
.constness
.print_with_space
(),
header
.asyncness
.print_with_space
(),
header
.asyncness
.print_with_space
(),
header
.unsafety
.print_with_space
(),
header
.unsafety
.print_with_space
(),
...
@@ -3016,7 +3023,7 @@ fn method(
...
@@ -3016,7 +3023,7 @@ fn method(
"{}{}{}{}{}{}{}fn <a href=
\"
{href}
\"
class=
\"
fnname
\"
>{name}</a>
\
"{}{}{}{}{}{}{}fn <a href=
\"
{href}
\"
class=
\"
fnname
\"
>{name}</a>
\
{generics}{decl}{spotlight}{where_clause}"
,
{generics}{decl}{spotlight}{where_clause}"
,
if
parent
==
ItemType
::
Trait
{
" "
}
else
{
""
},
if
parent
==
ItemType
::
Trait
{
" "
}
else
{
""
},
meth
.visibility
.print_with_space
(),
meth
.visibility
.print_with_space
(
cx
.tcx
()
),
header
.constness
.print_with_space
(),
header
.constness
.print_with_space
(),
header
.asyncness
.print_with_space
(),
header
.asyncness
.print_with_space
(),
header
.unsafety
.print_with_space
(),
header
.unsafety
.print_with_space
(),
...
@@ -3032,9 +3039,11 @@ fn method(
...
@@ -3032,9 +3039,11 @@ fn method(
}
}
match
item
.kind
{
match
item
.kind
{
clean
::
StrippedItem
(
..
)
=>
{}
clean
::
StrippedItem
(
..
)
=>
{}
clean
::
TyMethodItem
(
ref
m
)
=>
method
(
w
,
item
,
m
.header
,
&
m
.generics
,
&
m
.decl
,
link
,
parent
),
clean
::
TyMethodItem
(
ref
m
)
=>
{
method
(
w
,
item
,
m
.header
,
&
m
.generics
,
&
m
.decl
,
link
,
parent
,
cx
)
}
clean
::
MethodItem
(
ref
m
,
_
)
=>
{
clean
::
MethodItem
(
ref
m
,
_
)
=>
{
method
(
w
,
item
,
m
.header
,
&
m
.generics
,
&
m
.decl
,
link
,
parent
)
method
(
w
,
item
,
m
.header
,
&
m
.generics
,
&
m
.decl
,
link
,
parent
,
cx
)
}
}
clean
::
AssocConstItem
(
ref
ty
,
ref
default
)
=>
assoc_const
(
clean
::
AssocConstItem
(
ref
ty
,
ref
default
)
=>
assoc_const
(
w
,
w
,
...
@@ -3043,6 +3052,7 @@ fn method(
...
@@ -3043,6 +3052,7 @@ fn method(
default
.as_ref
(),
default
.as_ref
(),
link
,
link
,
if
parent
==
ItemType
::
Trait
{
" "
}
else
{
""
},
if
parent
==
ItemType
::
Trait
{
" "
}
else
{
""
},
cx
,
),
),
clean
::
AssocTypeItem
(
ref
bounds
,
ref
default
)
=>
assoc_type
(
clean
::
AssocTypeItem
(
ref
bounds
,
ref
default
)
=>
assoc_type
(
w
,
w
,
...
@@ -3066,7 +3076,7 @@ fn item_struct(
...
@@ -3066,7 +3076,7 @@ fn item_struct(
wrap_into_docblock
(
w
,
|
w
|
{
wrap_into_docblock
(
w
,
|
w
|
{
write!
(
w
,
"<pre class=
\"
rust struct
\"
>"
);
write!
(
w
,
"<pre class=
\"
rust struct
\"
>"
);
render_attributes
(
w
,
it
,
true
);
render_attributes
(
w
,
it
,
true
);
render_struct
(
w
,
it
,
Some
(
&
s
.generics
),
s
.struct_type
,
&
s
.fields
,
""
,
true
);
render_struct
(
w
,
it
,
Some
(
&
s
.generics
),
s
.struct_type
,
&
s
.fields
,
""
,
true
,
cx
);
write!
(
w
,
"</pre>"
)
write!
(
w
,
"</pre>"
)
});
});
...
@@ -3116,7 +3126,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
...
@@ -3116,7 +3126,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
wrap_into_docblock
(
w
,
|
w
|
{
wrap_into_docblock
(
w
,
|
w
|
{
write!
(
w
,
"<pre class=
\"
rust union
\"
>"
);
write!
(
w
,
"<pre class=
\"
rust union
\"
>"
);
render_attributes
(
w
,
it
,
true
);
render_attributes
(
w
,
it
,
true
);
render_union
(
w
,
it
,
Some
(
&
s
.generics
),
&
s
.fields
,
""
,
true
);
render_union
(
w
,
it
,
Some
(
&
s
.generics
),
&
s
.fields
,
""
,
true
,
cx
);
write!
(
w
,
"</pre>"
)
write!
(
w
,
"</pre>"
)
});
});
...
@@ -3165,7 +3175,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
...
@@ -3165,7 +3175,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
write!
(
write!
(
w
,
w
,
"{}enum {}{}{}"
,
"{}enum {}{}{}"
,
it
.visibility
.print_with_space
(),
it
.visibility
.print_with_space
(
cx
.tcx
()
),
it
.name
.as_ref
()
.unwrap
(),
it
.name
.as_ref
()
.unwrap
(),
e
.generics
.print
(),
e
.generics
.print
(),
WhereClause
{
gens
:
&
e
.generics
,
indent
:
0
,
end_newline
:
true
}
WhereClause
{
gens
:
&
e
.generics
,
indent
:
0
,
end_newline
:
true
}
...
@@ -3191,7 +3201,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
...
@@ -3191,7 +3201,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
write!
(
w
,
")"
);
write!
(
w
,
")"
);
}
}
clean
::
VariantKind
::
Struct
(
ref
s
)
=>
{
clean
::
VariantKind
::
Struct
(
ref
s
)
=>
{
render_struct
(
w
,
v
,
None
,
s
.struct_type
,
&
s
.fields
,
" "
,
false
);
render_struct
(
w
,
v
,
None
,
s
.struct_type
,
&
s
.fields
,
" "
,
false
,
cx
);
}
}
},
},
_
=>
unreachable!
(),
_
=>
unreachable!
(),
...
@@ -3335,11 +3345,12 @@ fn render_struct(
...
@@ -3335,11 +3345,12 @@ fn render_struct(
fields
:
&
[
clean
::
Item
],
fields
:
&
[
clean
::
Item
],
tab
:
&
str
,
tab
:
&
str
,
structhead
:
bool
,
structhead
:
bool
,
cx
:
&
Context
<
'_
>
,
)
{
)
{
write!
(
write!
(
w
,
w
,
"{}{}{}"
,
"{}{}{}"
,
it
.visibility
.print_with_space
(),
it
.visibility
.print_with_space
(
cx
.tcx
()
),
if
structhead
{
"struct "
}
else
{
""
},
if
structhead
{
"struct "
}
else
{
""
},
it
.name
.as_ref
()
.unwrap
()
it
.name
.as_ref
()
.unwrap
()
);
);
...
@@ -3359,7 +3370,7 @@ fn render_struct(
...
@@ -3359,7 +3370,7 @@ fn render_struct(
w
,
w
,
"
\n
{} {}{}: {},"
,
"
\n
{} {}{}: {},"
,
tab
,
tab
,
field
.visibility
.print_with_space
(),
field
.visibility
.print_with_space
(
cx
.tcx
()
),
field
.name
.as_ref
()
.unwrap
(),
field
.name
.as_ref
()
.unwrap
(),
ty
.print
()
ty
.print
()
);
);
...
@@ -3388,7 +3399,7 @@ fn render_struct(
...
@@ -3388,7 +3399,7 @@ fn render_struct(
match
field
.kind
{
match
field
.kind
{
clean
::
StrippedItem
(
box
clean
::
StructFieldItem
(
..
))
=>
write!
(
w
,
"_"
),
clean
::
StrippedItem
(
box
clean
::
StructFieldItem
(
..
))
=>
write!
(
w
,
"_"
),
clean
::
StructFieldItem
(
ref
ty
)
=>
{
clean
::
StructFieldItem
(
ref
ty
)
=>
{
write!
(
w
,
"{}{}"
,
field
.visibility
.print_with_space
(),
ty
.print
())
write!
(
w
,
"{}{}"
,
field
.visibility
.print_with_space
(
cx
.tcx
()
),
ty
.print
())
}
}
_
=>
unreachable!
(),
_
=>
unreachable!
(),
}
}
...
@@ -3416,11 +3427,12 @@ fn render_union(
...
@@ -3416,11 +3427,12 @@ fn render_union(
fields
:
&
[
clean
::
Item
],
fields
:
&
[
clean
::
Item
],
tab
:
&
str
,
tab
:
&
str
,
structhead
:
bool
,
structhead
:
bool
,
cx
:
&
Context
<
'_
>
,
)
{
)
{
write!
(
write!
(
w
,
w
,
"{}{}{}"
,
"{}{}{}"
,
it
.visibility
.print_with_space
(),
it
.visibility
.print_with_space
(
cx
.tcx
()
),
if
structhead
{
"union "
}
else
{
""
},
if
structhead
{
"union "
}
else
{
""
},
it
.name
.as_ref
()
.unwrap
()
it
.name
.as_ref
()
.unwrap
()
);
);
...
@@ -3435,7 +3447,7 @@ fn render_union(
...
@@ -3435,7 +3447,7 @@ fn render_union(
write!
(
write!
(
w
,
w
,
" {}{}: {},
\n
{}"
,
" {}{}: {},
\n
{}"
,
field
.visibility
.print_with_space
(),
field
.visibility
.print_with_space
(
cx
.tcx
()
),
field
.name
.as_ref
()
.unwrap
(),
field
.name
.as_ref
()
.unwrap
(),
ty
.print
(),
ty
.print
(),
tab
tab
...
@@ -3827,7 +3839,7 @@ fn doc_impl_item(
...
@@ -3827,7 +3839,7 @@ fn doc_impl_item(
let
id
=
cx
.derive_id
(
format!
(
"{}.{}"
,
item_type
,
name
));
let
id
=
cx
.derive_id
(
format!
(
"{}.{}"
,
item_type
,
name
));
write!
(
w
,
"<h4 id=
\"
{}
\"
class=
\"
{}{}
\"
>"
,
id
,
item_type
,
extra_class
);
write!
(
w
,
"<h4 id=
\"
{}
\"
class=
\"
{}{}
\"
>"
,
id
,
item_type
,
extra_class
);
write!
(
w
,
"<code>"
);
write!
(
w
,
"<code>"
);
render_assoc_item
(
w
,
item
,
link
.anchor
(
&
id
),
ItemType
::
Impl
);
render_assoc_item
(
w
,
item
,
link
.anchor
(
&
id
),
ItemType
::
Impl
,
cx
);
write!
(
w
,
"</code>"
);
write!
(
w
,
"</code>"
);
render_stability_since_raw
(
render_stability_since_raw
(
w
,
w
,
...
@@ -3849,7 +3861,7 @@ fn doc_impl_item(
...
@@ -3849,7 +3861,7 @@ fn doc_impl_item(
clean
::
AssocConstItem
(
ref
ty
,
ref
default
)
=>
{
clean
::
AssocConstItem
(
ref
ty
,
ref
default
)
=>
{
let
id
=
cx
.derive_id
(
format!
(
"{}.{}"
,
item_type
,
name
));
let
id
=
cx
.derive_id
(
format!
(
"{}.{}"
,
item_type
,
name
));
write!
(
w
,
"<h4 id=
\"
{}
\"
class=
\"
{}{}
\"
><code>"
,
id
,
item_type
,
extra_class
);
write!
(
w
,
"<h4 id=
\"
{}
\"
class=
\"
{}{}
\"
><code>"
,
id
,
item_type
,
extra_class
);
assoc_const
(
w
,
item
,
ty
,
default
.as_ref
(),
link
.anchor
(
&
id
),
""
);
assoc_const
(
w
,
item
,
ty
,
default
.as_ref
(),
link
.anchor
(
&
id
),
""
,
cx
);
write!
(
w
,
"</code>"
);
write!
(
w
,
"</code>"
);
render_stability_since_raw
(
render_stability_since_raw
(
w
,
w
,
...
@@ -4074,7 +4086,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, cache:
...
@@ -4074,7 +4086,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, cache:
write!
(
write!
(
w
,
w
,
" {}type {};
\n
}}</pre>"
,
" {}type {};
\n
}}</pre>"
,
it
.visibility
.print_with_space
(),
it
.visibility
.print_with_space
(
cx
.tcx
()
),
it
.name
.as_ref
()
.unwrap
(),
it
.name
.as_ref
()
.unwrap
(),
);
);
...
...
src/librustdoc/json/conversions.rs
浏览文件 @
a2fb4b95
...
@@ -35,7 +35,7 @@ pub(super) fn convert_item(&self, item: clean::Item) -> Option<Item> {
...
@@ -35,7 +35,7 @@ pub(super) fn convert_item(&self, item: clean::Item) -> Option<Item> {
crate_id
:
def_id
.krate
.as_u32
(),
crate_id
:
def_id
.krate
.as_u32
(),
name
:
name
.map
(|
sym
|
sym
.to_string
()),
name
:
name
.map
(|
sym
|
sym
.to_string
()),
source
:
self
.convert_span
(
source
),
source
:
self
.convert_span
(
source
),
visibility
:
visibility
.into
(
),
visibility
:
self
.convert_visibility
(
visibility
),
docs
:
attrs
.collapsed_doc_value
()
.unwrap_or_default
(),
docs
:
attrs
.collapsed_doc_value
()
.unwrap_or_default
(),
links
:
attrs
links
:
attrs
.links
.links
...
@@ -75,31 +75,29 @@ fn convert_span(&self, span: clean::Span) -> Option<Span> {
...
@@ -75,31 +75,29 @@ fn convert_span(&self, span: clean::Span) -> Option<Span> {
_
=>
None
,
_
=>
None
,
}
}
}
}
}
impl
From
<
rustc_attr
::
Deprecation
>
for
Deprecation
{
fn
from
(
deprecation
:
rustc_attr
::
Deprecation
)
->
Self
{
#[rustfmt::skip]
let
rustc_attr
::
Deprecation
{
since
,
note
,
is_since_rustc_version
:
_
,
suggestion
:
_
}
=
deprecation
;
Deprecation
{
since
:
since
.map
(|
s
|
s
.to_string
()),
note
:
note
.map
(|
s
|
s
.to_string
())
}
}
}
impl
From
<
clean
::
Visibility
>
for
Visibility
{
fn
convert_visibility
(
&
self
,
v
:
clean
::
Visibility
)
->
Visibility
{
fn
from
(
v
:
clean
::
Visibility
)
->
Self
{
use
clean
::
Visibility
::
*
;
use
clean
::
Visibility
::
*
;
match
v
{
match
v
{
Public
=>
Visibility
::
Public
,
Public
=>
Visibility
::
Public
,
Inherited
=>
Visibility
::
Default
,
Inherited
=>
Visibility
::
Default
,
Restricted
(
did
,
_
)
if
did
.index
==
CRATE_DEF_INDEX
=>
Visibility
::
Crate
,
Restricted
(
did
)
if
did
.index
==
CRATE_DEF_INDEX
=>
Visibility
::
Crate
,
Restricted
(
did
,
path
)
=>
Visibility
::
Restricted
{
Restricted
(
did
)
=>
Visibility
::
Restricted
{
parent
:
did
.into
(),
parent
:
did
.into
(),
path
:
path
.to_string_no_crate_verbose
(),
path
:
self
.tcx
.def_path
(
did
)
.to_string_no_crate_verbose
(),
},
},
}
}
}
}
}
}
impl
From
<
rustc_attr
::
Deprecation
>
for
Deprecation
{
fn
from
(
deprecation
:
rustc_attr
::
Deprecation
)
->
Self
{
#[rustfmt::skip]
let
rustc_attr
::
Deprecation
{
since
,
note
,
is_since_rustc_version
:
_
,
suggestion
:
_
}
=
deprecation
;
Deprecation
{
since
:
since
.map
(|
s
|
s
.to_string
()),
note
:
note
.map
(|
s
|
s
.to_string
())
}
}
}
impl
From
<
clean
::
GenericArgs
>
for
GenericArgs
{
impl
From
<
clean
::
GenericArgs
>
for
GenericArgs
{
fn
from
(
args
:
clean
::
GenericArgs
)
->
Self
{
fn
from
(
args
:
clean
::
GenericArgs
)
->
Self
{
use
clean
::
GenericArgs
::
*
;
use
clean
::
GenericArgs
::
*
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录