Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7d09dba7
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,发现更多精彩内容 >>
提交
7d09dba7
编写于
4月 26, 2021
作者:
T
Timothée Delabrouille
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added methods src_root and location to External crate, remove extern_location function
上级
855c2d13
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
56 addition
and
56 deletion
+56
-56
src/librustdoc/clean/types.rs
src/librustdoc/clean/types.rs
+52
-0
src/librustdoc/formats/cache.rs
src/librustdoc/formats/cache.rs
+2
-11
src/librustdoc/html/render/cache.rs
src/librustdoc/html/render/cache.rs
+2
-45
未找到文件。
src/librustdoc/clean/types.rs
浏览文件 @
7d09dba7
...
...
@@ -4,6 +4,7 @@
use
std
::
hash
::{
Hash
,
Hasher
};
use
std
::
iter
::
FromIterator
;
use
std
::
lazy
::
SyncOnceCell
as
OnceCell
;
use
std
::
path
::
PathBuf
;
use
std
::
rc
::
Rc
;
use
std
::
sync
::
Arc
;
use
std
::{
slice
,
vec
};
...
...
@@ -90,6 +91,57 @@ fn def_id(&self) -> DefId {
tcx
.crate_name
(
self
.crate_num
)
}
crate
fn
src_root
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
PathBuf
{
match
self
.src
(
tcx
)
{
FileName
::
Real
(
ref
p
)
=>
match
p
.local_path
()
.parent
()
{
Some
(
p
)
=>
p
.to_path_buf
(),
None
=>
PathBuf
::
new
(),
},
_
=>
PathBuf
::
new
(),
}
}
/// Attempts to find where an external crate is located, given that we're
/// rendering in to the specified source destination.
crate
fn
location
(
&
self
,
extern_url
:
Option
<&
str
>
,
ast_attrs
:
&
[
ast
::
Attribute
],
dst
:
&
std
::
path
::
Path
,
tcx
:
TyCtxt
<
'_
>
,
)
->
ExternalLocation
{
use
ExternalLocation
::
*
;
// See if there's documentation generated into the local directory
let
local_location
=
dst
.join
(
&*
self
.name
(
tcx
)
.as_str
());
if
local_location
.is_dir
()
{
return
Local
;
}
if
let
Some
(
url
)
=
extern_url
{
let
mut
url
=
url
.to_string
();
if
!
url
.ends_with
(
'/'
)
{
url
.push
(
'/'
);
}
return
Remote
(
url
);
}
// Failing that, see if there's an attribute specifying where to find this
// external crate
ast_attrs
.lists
(
sym
::
doc
)
.filter
(|
a
|
a
.has_name
(
sym
::
html_root_url
))
.filter_map
(|
a
|
a
.value_str
())
.map
(|
url
|
{
let
mut
url
=
url
.to_string
();
if
!
url
.ends_with
(
'/'
)
{
url
.push
(
'/'
)
}
Remote
(
url
)
})
.next
()
.unwrap_or
(
Unknown
)
// Well, at least we tried.
}
crate
fn
keywords
(
&
self
,
tcx
:
TyCtxt
<
'_
>
)
->
ThinVec
<
(
DefId
,
Symbol
)
>
{
let
root
=
self
.def_id
();
...
...
src/librustdoc/formats/cache.rs
浏览文件 @
7d09dba7
...
...
@@ -6,7 +6,6 @@
use
rustc_hir
::
def_id
::{
CrateNum
,
DefId
,
CRATE_DEF_INDEX
};
use
rustc_middle
::
middle
::
privacy
::
AccessLevels
;
use
rustc_middle
::
ty
::
TyCtxt
;
use
rustc_span
::
source_map
::
FileName
;
use
rustc_span
::
symbol
::
sym
;
use
rustc_span
::
Symbol
;
...
...
@@ -15,7 +14,7 @@
use
crate
::
formats
::
item_type
::
ItemType
;
use
crate
::
formats
::
Impl
;
use
crate
::
html
::
markdown
::
short_markdown_summary
;
use
crate
::
html
::
render
::
cache
::{
extern_location
,
get_index_search_type
,
ExternalLocation
};
use
crate
::
html
::
render
::
cache
::{
get_index_search_type
,
ExternalLocation
};
use
crate
::
html
::
render
::
IndexItem
;
/// This cache is used to store information about the [`clean::Crate`] being
...
...
@@ -155,21 +154,13 @@ impl Cache {
// Cache where all our extern crates are located
// FIXME: this part is specific to HTML so it'd be nice to remove it from the common code
for
&
(
n
,
ref
e
)
in
&
krate
.externs
{
let
src_root
=
match
e
.src
(
tcx
)
{
FileName
::
Real
(
ref
p
)
=>
match
p
.local_path
()
.parent
()
{
Some
(
p
)
=>
p
.to_path_buf
(),
None
=>
PathBuf
::
new
(),
},
_
=>
PathBuf
::
new
(),
};
let
name
=
e
.name
(
tcx
);
let
extern_url
=
extern_html_root_urls
.get
(
&*
name
.as_str
())
.map
(|
u
|
&**
u
);
let
did
=
DefId
{
krate
:
n
,
index
:
CRATE_DEF_INDEX
};
self
.extern_locations
.insert
(
n
,
(
name
,
src_root
,
extern_location
(
e
,
extern_url
,
tcx
.get_attrs
(
did
),
&
dst
,
tcx
)),
(
name
,
e
.src_root
(
tcx
),
e
.location
(
extern_url
,
tcx
.get_attrs
(
did
),
&
dst
,
tcx
)),
);
self
.external_paths
.insert
(
did
,
(
vec!
[
name
.to_string
()],
ItemType
::
Module
));
}
...
...
src/librustdoc/html/render/cache.rs
浏览文件 @
7d09dba7
use
std
::
collections
::
BTreeMap
;
use
std
::
path
::
Path
;
use
rustc_ast
::
ast
;
use
rustc_data_structures
::
fx
::{
FxHashMap
,
FxHashSet
};
use
rustc_middle
::
ty
::
TyCtxt
;
use
rustc_span
::
symbol
::
{
sym
,
Symbol
}
;
use
rustc_span
::
symbol
::
Symbol
;
use
serde
::
ser
::{
Serialize
,
SerializeStruct
,
Serializer
};
use
crate
::
clean
;
use
crate
::
clean
::
types
::{
AttributesExt
,
FnDecl
,
FnRetTy
,
GenericBound
,
Generics
,
GetDefId
,
Type
,
WherePredicate
,
FnDecl
,
FnRetTy
,
GenericBound
,
Generics
,
GetDefId
,
Type
,
WherePredicate
,
};
use
crate
::
formats
::
cache
::
Cache
;
use
crate
::
formats
::
item_type
::
ItemType
;
...
...
@@ -26,47 +24,6 @@
Unknown
,
}
/// Attempts to find where an external crate is located, given that we're
/// rendering in to the specified source destination.
crate
fn
extern_location
(
e
:
&
clean
::
ExternalCrate
,
extern_url
:
Option
<&
str
>
,
ast_attrs
:
&
[
ast
::
Attribute
],
dst
:
&
Path
,
tcx
:
TyCtxt
<
'_
>
,
)
->
ExternalLocation
{
use
ExternalLocation
::
*
;
// See if there's documentation generated into the local directory
let
local_location
=
dst
.join
(
&*
e
.name
(
tcx
)
.as_str
());
if
local_location
.is_dir
()
{
return
Local
;
}
if
let
Some
(
url
)
=
extern_url
{
let
mut
url
=
url
.to_string
();
if
!
url
.ends_with
(
'/'
)
{
url
.push
(
'/'
);
}
return
Remote
(
url
);
}
// Failing that, see if there's an attribute specifying where to find this
// external crate
ast_attrs
.lists
(
sym
::
doc
)
.filter
(|
a
|
a
.has_name
(
sym
::
html_root_url
))
.filter_map
(|
a
|
a
.value_str
())
.map
(|
url
|
{
let
mut
url
=
url
.to_string
();
if
!
url
.ends_with
(
'/'
)
{
url
.push
(
'/'
)
}
Remote
(
url
)
})
.next
()
.unwrap_or
(
Unknown
)
// Well, at least we tried.
}
/// Builds the search index from the collected metadata
crate
fn
build_index
<
'tcx
>
(
krate
:
&
clean
::
Crate
,
cache
:
&
mut
Cache
,
tcx
:
TyCtxt
<
'tcx
>
)
->
String
{
let
mut
defid_to_pathid
=
FxHashMap
::
default
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录