Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
6a4396b9
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
6a4396b9
编写于
6月 24, 2020
作者:
J
Joseph Ryan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract `Cache` and other types from `html` module
上级
5bc97946
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
808 addition
and
752 deletion
+808
-752
src/librustdoc/clean/types.rs
src/librustdoc/clean/types.rs
+4
-3
src/librustdoc/config.rs
src/librustdoc/config.rs
+1
-1
src/librustdoc/core.rs
src/librustdoc/core.rs
+2
-2
src/librustdoc/formats/cache.rs
src/librustdoc/formats/cache.rs
+498
-0
src/librustdoc/formats/item_type.rs
src/librustdoc/formats/item_type.rs
+1
-1
src/librustdoc/formats/mod.rs
src/librustdoc/formats/mod.rs
+19
-97
src/librustdoc/formats/renderer.rs
src/librustdoc/formats/renderer.rs
+112
-0
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+11
-9
src/librustdoc/html/mod.rs
src/librustdoc/html/mod.rs
+9
-0
src/librustdoc/html/render/cache.rs
src/librustdoc/html/render/cache.rs
+12
-489
src/librustdoc/html/render/mod.rs
src/librustdoc/html/render/mod.rs
+137
-137
src/librustdoc/lib.rs
src/librustdoc/lib.rs
+2
-13
未找到文件。
src/librustdoc/clean/types.rs
浏览文件 @
6a4396b9
...
@@ -32,8 +32,9 @@
...
@@ -32,8 +32,9 @@
use
crate
::
clean
::
types
::
Type
::{
QPath
,
ResolvedPath
};
use
crate
::
clean
::
types
::
Type
::{
QPath
,
ResolvedPath
};
use
crate
::
core
::
DocContext
;
use
crate
::
core
::
DocContext
;
use
crate
::
doctree
;
use
crate
::
doctree
;
use
crate
::
html
::
item_type
::
ItemType
;
use
crate
::
formats
::
cache
::
cache
;
use
crate
::
html
::
render
::{
cache
,
ExternalLocation
};
use
crate
::
formats
::
item_type
::
ItemType
;
use
crate
::
html
::
render
::
cache
::
ExternalLocation
;
use
self
::
FnRetTy
::
*
;
use
self
::
FnRetTy
::
*
;
use
self
::
ItemEnum
::
*
;
use
self
::
ItemEnum
::
*
;
...
@@ -1172,7 +1173,7 @@ impl GetDefId for Type {
...
@@ -1172,7 +1173,7 @@ impl GetDefId for Type {
fn
def_id
(
&
self
)
->
Option
<
DefId
>
{
fn
def_id
(
&
self
)
->
Option
<
DefId
>
{
match
*
self
{
match
*
self
{
ResolvedPath
{
did
,
..
}
=>
Some
(
did
),
ResolvedPath
{
did
,
..
}
=>
Some
(
did
),
Primitive
(
p
)
=>
c
rate
::
html
::
render
::
c
ache
()
.primitive_locations
.get
(
&
p
)
.cloned
(),
Primitive
(
p
)
=>
cache
()
.primitive_locations
.get
(
&
p
)
.cloned
(),
BorrowedRef
{
type_
:
box
Generic
(
..
),
..
}
=>
{
BorrowedRef
{
type_
:
box
Generic
(
..
),
..
}
=>
{
Primitive
(
PrimitiveType
::
Reference
)
.def_id
()
Primitive
(
PrimitiveType
::
Reference
)
.def_id
()
}
}
...
...
src/librustdoc/config.rs
浏览文件 @
6a4396b9
...
@@ -254,7 +254,7 @@ pub struct RenderOptions {
...
@@ -254,7 +254,7 @@ pub struct RenderOptions {
/// Temporary storage for data obtained during `RustdocVisitor::clean()`.
/// Temporary storage for data obtained during `RustdocVisitor::clean()`.
/// Later on moved into `CACHE_KEY`.
/// Later on moved into `CACHE_KEY`.
#[derive(Default)]
#[derive(Default
,
Clone
)]
pub
struct
RenderInfo
{
pub
struct
RenderInfo
{
pub
inlined
:
FxHashSet
<
DefId
>
,
pub
inlined
:
FxHashSet
<
DefId
>
,
pub
external_paths
:
crate
::
core
::
ExternalPaths
,
pub
external_paths
:
crate
::
core
::
ExternalPaths
,
...
...
src/librustdoc/core.rs
浏览文件 @
6a4396b9
...
@@ -44,9 +44,9 @@
...
@@ -44,9 +44,9 @@
pub
struct
DocContext
<
'tcx
>
{
pub
struct
DocContext
<
'tcx
>
{
pub
tcx
:
TyCtxt
<
'tcx
>
,
pub
tcx
:
TyCtxt
<
'tcx
>
,
pub
resolver
:
Rc
<
RefCell
<
interface
::
BoxedResolver
>>
,
pub
resolver
:
Rc
<
RefCell
<
interface
::
BoxedResolver
>>
,
/// Later on moved into `
html::render
::CACHE_KEY`
/// Later on moved into `
formats::cache
::CACHE_KEY`
pub
renderinfo
:
RefCell
<
RenderInfo
>
,
pub
renderinfo
:
RefCell
<
RenderInfo
>
,
/// Later on moved through `clean::Crate` into `
html::render
::CACHE_KEY`
/// Later on moved through `clean::Crate` into `
formats::cache
::CACHE_KEY`
pub
external_traits
:
Rc
<
RefCell
<
FxHashMap
<
DefId
,
clean
::
Trait
>>>
,
pub
external_traits
:
Rc
<
RefCell
<
FxHashMap
<
DefId
,
clean
::
Trait
>>>
,
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
/// the same time.
/// the same time.
...
...
src/librustdoc/formats/cache.rs
0 → 100644
浏览文件 @
6a4396b9
此差异已折叠。
点击以展开。
src/librustdoc/
html
/item_type.rs
→
src/librustdoc/
formats
/item_type.rs
浏览文件 @
6a4396b9
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
/// The search index uses item types encoded as smaller numbers which equal to
/// The search index uses item types encoded as smaller numbers which equal to
/// discriminants. JavaScript then is used to decode them into the original value.
/// discriminants. JavaScript then is used to decode them into the original value.
/// Consequently, every change to this type should be synchronized to
/// Consequently, every change to this type should be synchronized to
/// the `itemTypes` mapping table in `static/main.js`.
/// the `itemTypes` mapping table in `
html/
static/main.js`.
///
///
/// In addition, code in `html::render` uses this enum to generate CSS classes, page prefixes, and
/// In addition, code in `html::render` uses this enum to generate CSS classes, page prefixes, and
/// module headings. If you are adding to this enum and want to ensure that the sidebar also prints
/// module headings. If you are adding to this enum and want to ensure that the sidebar also prints
...
...
src/librustdoc/formats/mod.rs
浏览文件 @
6a4396b9
use
std
::
cell
::
RefCell
;
pub
mod
cache
;
use
std
::
rc
::
Rc
;
pub
mod
item_type
;
pub
mod
renderer
;
use
rustc_span
::
edition
::
Edition
;
pub
use
renderer
::{
FormatRenderer
,
Renderer
}
;
use
crate
::
clean
;
use
rustc_span
::
def_id
::
DefId
;
use
crate
::
config
::{
RenderInfo
,
RenderOptions
};
use
crate
::
error
::
Error
;
pub
trait
FormatRenderer
:
Clone
{
type
Output
:
FormatRenderer
;
fn
init
(
krate
:
clean
::
Crate
,
options
:
RenderOptions
,
renderinfo
:
RenderInfo
,
diag
:
&
rustc_errors
::
Handler
,
edition
:
Edition
,
parent
:
Rc
<
RefCell
<
Renderer
>>
,
)
->
Result
<
(
Self
::
Output
,
clean
::
Crate
),
Error
>
;
/// Renders a single non-module item. This means no recursive sub-item rendering is required.
fn
item
(
&
mut
self
,
item
:
clean
::
Item
)
->
Result
<
(),
Error
>
;
/// Renders a module. Doesn't need to handle recursing into children, the driver does that
use
crate
::
clean
;
/// automatically.
use
crate
::
clean
::
types
::
GetDefId
;
fn
mod_item_in
(
&
mut
self
,
item
:
&
clean
::
Item
,
item_name
:
&
str
,
module
:
&
clean
::
Module
,
)
->
Result
<
(),
Error
>
;
/// Runs after recursively rendering all sub-items of a module.
fn
mod_item_out
(
&
mut
self
)
->
Result
<
(),
Error
>
;
/// Post processing hook for cleanup and dumping output to files.
fn
after_krate
(
&
mut
self
,
krate
:
&
clean
::
Crate
)
->
Result
<
(),
Error
>
;
/// Called after everything else to write out errors.
/// Metadata about implementations for a type or trait.
fn
after_run
(
&
mut
self
,
diag
:
&
rustc_errors
::
Handler
)
->
Result
<
(),
Error
>
;
#[derive(Clone,
Debug)]
pub
struct
Impl
{
pub
impl_item
:
clean
::
Item
,
}
}
#[derive(Clone)]
impl
Impl
{
pub
struct
Renderer
;
pub
fn
inner_impl
(
&
self
)
->
&
clean
::
Impl
{
match
self
.impl_item.inner
{
impl
Renderer
{
clean
::
ImplItem
(
ref
impl_
)
=>
impl_
,
pub
fn
new
()
->
Renderer
{
_
=>
panic!
(
"non-impl item found in impl"
),
Renderer
}
/// Main method for rendering a crate.
pub
fn
run
<
T
:
FormatRenderer
+
Clone
>
(
self
,
krate
:
clean
::
Crate
,
options
:
RenderOptions
,
renderinfo
:
RenderInfo
,
diag
:
&
rustc_errors
::
Handler
,
edition
:
Edition
,
)
->
Result
<
(),
Error
>
{
let
rself
=
Rc
::
new
(
RefCell
::
new
(
self
));
let
(
mut
renderer
,
mut
krate
)
=
T
::
init
(
krate
,
options
,
renderinfo
,
diag
,
edition
,
rself
.clone
())
?
;
let
mut
item
=
match
krate
.module
.take
()
{
Some
(
i
)
=>
i
,
None
=>
return
Ok
(()),
};
item
.name
=
Some
(
krate
.name
.clone
());
// Render the crate documentation
let
mut
work
=
vec!
[(
renderer
.clone
(),
item
)];
while
let
Some
((
mut
cx
,
item
))
=
work
.pop
()
{
if
item
.is_mod
()
{
// modules are special because they add a namespace. We also need to
// recurse into the items of the module as well.
let
name
=
item
.name
.as_ref
()
.unwrap
()
.to_string
();
if
name
.is_empty
()
{
panic!
(
"Unexpected module with empty name"
);
}
let
module
=
match
item
.inner
{
clean
::
StrippedItem
(
box
clean
::
ModuleItem
(
ref
m
))
|
clean
::
ModuleItem
(
ref
m
)
=>
m
,
_
=>
unreachable!
(),
};
cx
.mod_item_in
(
&
item
,
&
name
,
module
)
?
;
let
module
=
match
item
.inner
{
clean
::
StrippedItem
(
box
clean
::
ModuleItem
(
m
))
|
clean
::
ModuleItem
(
m
)
=>
m
,
_
=>
unreachable!
(),
};
for
it
in
module
.items
{
info!
(
"Adding {:?} to worklist"
,
it
.name
);
work
.push
((
cx
.clone
(),
it
));
}
cx
.mod_item_out
()
?
;
}
else
if
item
.name
.is_some
()
{
cx
.item
(
item
)
?
;
}
}
}
}
renderer
.after_krate
(
&
krate
)
?
;
pub
fn
trait_did
(
&
self
)
->
Option
<
DefId
>
{
renderer
.after_run
(
diag
)
self
.inner_impl
()
.trait_
.def_id
(
)
}
}
}
}
src/librustdoc/formats/renderer.rs
0 → 100644
浏览文件 @
6a4396b9
use
std
::
sync
::
Arc
;
use
rustc_span
::
edition
::
Edition
;
use
crate
::
clean
;
use
crate
::
config
::{
RenderInfo
,
RenderOptions
};
use
crate
::
error
::
Error
;
use
crate
::
formats
::
cache
::{
Cache
,
CACHE_KEY
};
pub
trait
FormatRenderer
:
Clone
{
type
Output
:
FormatRenderer
;
fn
init
(
krate
:
clean
::
Crate
,
options
:
RenderOptions
,
renderinfo
:
RenderInfo
,
edition
:
Edition
,
cache
:
&
mut
Cache
,
)
->
Result
<
(
Self
::
Output
,
clean
::
Crate
),
Error
>
;
/// Renders a single non-module item. This means no recursive sub-item rendering is required.
fn
item
(
&
mut
self
,
item
:
clean
::
Item
,
cache
:
&
Cache
)
->
Result
<
(),
Error
>
;
/// Renders a module (doesn't need to handle recursing into children).
fn
mod_item_in
(
&
mut
self
,
item
:
&
clean
::
Item
,
item_name
:
&
str
,
cache
:
&
Cache
,
)
->
Result
<
(),
Error
>
;
/// Runs after recursively rendering all sub-items of a module.
fn
mod_item_out
(
&
mut
self
,
name
:
&
str
)
->
Result
<
(),
Error
>
;
/// Post processing hook for cleanup and dumping output to files.
fn
after_krate
(
&
mut
self
,
krate
:
&
clean
::
Crate
,
cache
:
&
Cache
)
->
Result
<
(),
Error
>
;
/// Called after everything else to write out errors.
fn
after_run
(
&
mut
self
,
diag
:
&
rustc_errors
::
Handler
)
->
Result
<
(),
Error
>
;
}
#[derive(Clone)]
pub
struct
Renderer
;
impl
Renderer
{
pub
fn
new
()
->
Renderer
{
Renderer
}
/// Main method for rendering a crate.
pub
fn
run
<
T
:
FormatRenderer
+
Clone
>
(
self
,
krate
:
clean
::
Crate
,
options
:
RenderOptions
,
renderinfo
:
RenderInfo
,
diag
:
&
rustc_errors
::
Handler
,
edition
:
Edition
,
)
->
Result
<
(),
Error
>
{
let
(
krate
,
mut
cache
)
=
Cache
::
from_krate
(
renderinfo
.clone
(),
options
.document_private
,
&
options
.extern_html_root_urls
,
&
options
.output
,
krate
,
);
let
(
mut
renderer
,
mut
krate
)
=
T
::
init
(
krate
,
options
,
renderinfo
,
edition
,
&
mut
cache
)
?
;
let
cache
=
Arc
::
new
(
cache
);
// Freeze the cache now that the index has been built. Put an Arc into TLS for future
// parallelization opportunities
CACHE_KEY
.with
(|
v
|
*
v
.borrow_mut
()
=
cache
.clone
());
let
mut
item
=
match
krate
.module
.take
()
{
Some
(
i
)
=>
i
,
None
=>
return
Ok
(()),
};
item
.name
=
Some
(
krate
.name
.clone
());
// Render the crate documentation
let
mut
work
=
vec!
[(
renderer
.clone
(),
item
)];
while
let
Some
((
mut
cx
,
item
))
=
work
.pop
()
{
if
item
.is_mod
()
{
// modules are special because they add a namespace. We also need to
// recurse into the items of the module as well.
let
name
=
item
.name
.as_ref
()
.unwrap
()
.to_string
();
if
name
.is_empty
()
{
panic!
(
"Unexpected module with empty name"
);
}
cx
.mod_item_in
(
&
item
,
&
name
,
&
cache
)
?
;
let
module
=
match
item
.inner
{
clean
::
StrippedItem
(
box
clean
::
ModuleItem
(
m
))
|
clean
::
ModuleItem
(
m
)
=>
m
,
_
=>
unreachable!
(),
};
for
it
in
module
.items
{
info!
(
"Adding {:?} to worklist"
,
it
.name
);
work
.push
((
cx
.clone
(),
it
));
}
cx
.mod_item_out
(
&
name
)
?
;
}
else
if
item
.name
.is_some
()
{
cx
.item
(
item
,
&
cache
)
?
;
}
}
renderer
.after_krate
(
&
krate
,
&
cache
)
?
;
renderer
.after_run
(
diag
)
}
}
src/librustdoc/html/format.rs
浏览文件 @
6a4396b9
...
@@ -11,13 +11,15 @@
...
@@ -11,13 +11,15 @@
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
rustc_hir
as
hir
;
use
rustc_hir
as
hir
;
use
rustc_
hir
::
def_id
::
DefId
;
use
rustc_
span
::
def_id
::
DefId
;
use
rustc_target
::
spec
::
abi
::
Abi
;
use
rustc_target
::
spec
::
abi
::
Abi
;
use
crate
::
clean
::{
self
,
PrimitiveType
};
use
crate
::
clean
::{
self
,
PrimitiveType
};
use
crate
::
formats
::
cache
::
cache
;
use
crate
::
formats
::
item_type
::
ItemType
;
use
crate
::
html
::
escape
::
Escape
;
use
crate
::
html
::
escape
::
Escape
;
use
crate
::
html
::
item_type
::
ItemType
;
use
crate
::
html
::
render
::
cache
::
ExternalLocation
;
use
crate
::
html
::
render
::
{
self
,
cache
,
CURRENT_DEPTH
}
;
use
crate
::
html
::
render
::
CURRENT_DEPTH
;
pub
trait
Print
{
pub
trait
Print
{
fn
print
(
self
,
buffer
:
&
mut
Buffer
);
fn
print
(
self
,
buffer
:
&
mut
Buffer
);
...
@@ -493,9 +495,9 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
...
@@ -493,9 +495,9 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
fqp
,
fqp
,
shortty
,
shortty
,
match
cache
.extern_locations
[
&
did
.krate
]
{
match
cache
.extern_locations
[
&
did
.krate
]
{
(
..
,
render
::
Remote
(
ref
s
))
=>
s
.to_string
(),
(
..
,
ExternalLocation
::
Remote
(
ref
s
))
=>
s
.to_string
(),
(
..
,
render
::
Local
)
=>
"../"
.repeat
(
depth
),
(
..
,
ExternalLocation
::
Local
)
=>
"../"
.repeat
(
depth
),
(
..
,
render
::
Unknown
)
=>
return
None
,
(
..
,
ExternalLocation
::
Unknown
)
=>
return
None
,
},
},
)
)
}
}
...
@@ -574,12 +576,12 @@ fn primitive_link(
...
@@ -574,12 +576,12 @@ fn primitive_link(
}
}
Some
(
&
def_id
)
=>
{
Some
(
&
def_id
)
=>
{
let
loc
=
match
m
.extern_locations
[
&
def_id
.krate
]
{
let
loc
=
match
m
.extern_locations
[
&
def_id
.krate
]
{
(
ref
cname
,
_
,
render
::
Remote
(
ref
s
))
=>
Some
((
cname
,
s
.to_string
())),
(
ref
cname
,
_
,
ExternalLocation
::
Remote
(
ref
s
))
=>
Some
((
cname
,
s
.to_string
())),
(
ref
cname
,
_
,
render
::
Local
)
=>
{
(
ref
cname
,
_
,
ExternalLocation
::
Local
)
=>
{
let
len
=
CURRENT_DEPTH
.with
(|
s
|
s
.get
());
let
len
=
CURRENT_DEPTH
.with
(|
s
|
s
.get
());
Some
((
cname
,
"../"
.repeat
(
len
)))
Some
((
cname
,
"../"
.repeat
(
len
)))
}
}
(
..
,
render
::
Unknown
)
=>
None
,
(
..
,
ExternalLocation
::
Unknown
)
=>
None
,
};
};
if
let
Some
((
cname
,
root
))
=
loc
{
if
let
Some
((
cname
,
root
))
=
loc
{
write!
(
write!
(
...
...
src/librustdoc/html/mod.rs
0 → 100644
浏览文件 @
6a4396b9
crate
mod
escape
;
crate
mod
format
;
crate
mod
highlight
;
crate
mod
layout
;
pub
mod
markdown
;
pub
mod
render
;
crate
mod
sources
;
crate
mod
static_files
;
crate
mod
toc
;
src/librustdoc/html/render/cache.rs
浏览文件 @
6a4396b9
此差异已折叠。
点击以展开。
src/librustdoc/html/render.rs
→
src/librustdoc/html/render
/mod
.rs
浏览文件 @
6a4396b9
此差异已折叠。
点击以展开。
src/librustdoc/lib.rs
浏览文件 @
6a4396b9
...
@@ -66,19 +66,8 @@
...
@@ -66,19 +66,8 @@
#[macro_use]
#[macro_use]
mod
error
;
mod
error
;
mod
fold
;
mod
fold
;
mod
formats
;
crate
mod
formats
;
pub
mod
html
{
crate
mod
html
;
crate
mod
escape
;
crate
mod
format
;
crate
mod
highlight
;
crate
mod
item_type
;
crate
mod
layout
;
pub
mod
markdown
;
crate
mod
render
;
crate
mod
sources
;
crate
mod
static_files
;
crate
mod
toc
;
}
mod
markdown
;
mod
markdown
;
mod
passes
;
mod
passes
;
mod
test
;
mod
test
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录