Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2cc26398
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,发现更多精彩内容 >>
提交
2cc26398
编写于
4月 29, 2021
作者:
T
Timothée Delabrouille
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
only store locations in extern_locations
上级
7d09dba7
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
47 addition
and
43 deletion
+47
-43
src/librustdoc/clean/types.rs
src/librustdoc/clean/types.rs
+18
-17
src/librustdoc/formats/cache.rs
src/librustdoc/formats/cache.rs
+3
-7
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+11
-9
src/librustdoc/html/render/context.rs
src/librustdoc/html/render/context.rs
+9
-5
src/librustdoc/json/mod.rs
src/librustdoc/json/mod.rs
+6
-5
未找到文件。
src/librustdoc/clean/types.rs
浏览文件 @
2cc26398
...
...
@@ -106,38 +106,39 @@ fn def_id(&self) -> DefId {
crate
fn
location
(
&
self
,
extern_url
:
Option
<&
str
>
,
ast_attrs
:
&
[
ast
::
Attribute
],
dst
:
&
std
::
path
::
Path
,
tcx
:
TyCtxt
<
'_
>
,
)
->
ExternalLocation
{
use
ExternalLocation
::
*
;
fn
to_remote
(
url
:
impl
ToString
)
->
ExternalLocation
{
let
mut
url
=
url
.to_string
();
if
!
url
.ends_with
(
'/'
)
{
url
.push
(
'/'
);
}
Remote
(
url
)
}
// See if there's documentation generated into the local directory
// WARNING: since rustdoc creates these directories as it generates documentation, this check is only accurate before rendering starts.
// Make sure to call `location()` by that time.
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
);
return
to_remote
(
url
);
}
// Failing that, see if there's an attribute specifying where to find this
// external crate
ast_attrs
let
did
=
DefId
{
krate
:
self
.crate_num
,
index
:
CRATE_DEF_INDEX
};
tcx
.get_attrs
(
did
)
.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
)
})
.map
(
to_remote
)
.next
()
.unwrap_or
(
Unknown
)
// Well, at least we tried.
}
...
...
@@ -433,7 +434,7 @@ pub fn from_def_id_and_attrs_and_parts(
let
relative_to
=
&
cx
.current
;
if
let
Some
(
ref
fragment
)
=
*
fragment
{
let
url
=
match
cx
.cache
()
.extern_locations
.get
(
&
self
.def_id.krate
)
{
Some
(
&
(
_
,
_
,
ExternalLocation
::
Local
)
)
=>
{
Some
(
ExternalLocation
::
Local
)
=>
{
if
relative_to
[
0
]
==
"std"
{
let
depth
=
relative_to
.len
()
-
1
;
"../"
.repeat
(
depth
)
...
...
@@ -442,10 +443,10 @@ pub fn from_def_id_and_attrs_and_parts(
format!
(
"{}std/"
,
"../"
.repeat
(
depth
))
}
}
Some
(
&
(
_
,
_
,
ExternalLocation
::
Remote
(
ref
s
)
))
=>
{
Some
(
ExternalLocation
::
Remote
(
ref
s
))
=>
{
format!
(
"{}/std/"
,
s
.trim_end_matches
(
'/'
))
}
Some
(
&
(
_
,
_
,
ExternalLocation
::
Unknown
)
)
|
None
=>
format!
(
Some
(
ExternalLocation
::
Unknown
)
|
None
=>
format!
(
"https://doc.rust-lang.org/{}/std/"
,
crate
::
doc_rust_lang_org_channel
(),
),
...
...
src/librustdoc/formats/cache.rs
浏览文件 @
2cc26398
use
std
::
collections
::
BTreeMap
;
use
std
::
mem
;
use
std
::
path
::
{
Path
,
PathBuf
}
;
use
std
::
path
::
Path
;
use
rustc_data_structures
::
fx
::{
FxHashMap
,
FxHashSet
};
use
rustc_hir
::
def_id
::{
CrateNum
,
DefId
,
CRATE_DEF_INDEX
};
use
rustc_middle
::
middle
::
privacy
::
AccessLevels
;
use
rustc_middle
::
ty
::
TyCtxt
;
use
rustc_span
::
symbol
::
sym
;
use
rustc_span
::
Symbol
;
use
crate
::
clean
::{
self
,
GetDefId
};
use
crate
::
fold
::
DocFolder
;
...
...
@@ -71,7 +70,7 @@
crate
implementors
:
FxHashMap
<
DefId
,
Vec
<
Impl
>>
,
/// Cache of where external crate documentation can be found.
crate
extern_locations
:
FxHashMap
<
CrateNum
,
(
Symbol
,
PathBuf
,
ExternalLocation
)
>
,
crate
extern_locations
:
FxHashMap
<
CrateNum
,
ExternalLocation
>
,
/// Cache of where documentation for primitives can be found.
crate
primitive_locations
:
FxHashMap
<
clean
::
PrimitiveType
,
DefId
>
,
...
...
@@ -157,10 +156,7 @@ impl Cache {
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
,
e
.src_root
(
tcx
),
e
.location
(
extern_url
,
tcx
.get_attrs
(
did
),
&
dst
,
tcx
)),
);
self
.extern_locations
.insert
(
n
,
e
.location
(
extern_url
,
&
dst
,
tcx
));
self
.external_paths
.insert
(
did
,
(
vec!
[
name
.to_string
()],
ItemType
::
Module
));
}
...
...
src/librustdoc/html/format.rs
浏览文件 @
2cc26398
...
...
@@ -16,7 +16,7 @@
use
rustc_span
::
def_id
::{
DefId
,
CRATE_DEF_INDEX
};
use
rustc_target
::
spec
::
abi
::
Abi
;
use
crate
::
clean
::{
self
,
utils
::
find_nearest_parent_module
,
PrimitiveType
};
use
crate
::
clean
::{
self
,
utils
::
find_nearest_parent_module
,
ExternalCrate
,
PrimitiveType
};
use
crate
::
formats
::
item_type
::
ItemType
;
use
crate
::
html
::
escape
::
Escape
;
use
crate
::
html
::
render
::
cache
::
ExternalLocation
;
...
...
@@ -461,14 +461,14 @@ fn to_module_fqp(shortty: ItemType, fqp: &[String]) -> &[String] {
fqp
,
shortty
,
match
cache
.extern_locations
[
&
did
.krate
]
{
(
..
,
ExternalLocation
::
Remote
(
ref
s
)
)
=>
{
ExternalLocation
::
Remote
(
ref
s
)
=>
{
let
s
=
s
.trim_end_matches
(
'/'
);
let
mut
s
=
vec!
[
&
s
[
..
]];
s
.extend
(
module_fqp
[
..
]
.iter
()
.map
(
String
::
as_str
));
s
}
(
..
,
ExternalLocation
::
Local
)
=>
href_relative_parts
(
module_fqp
,
relative_to
),
(
..
,
ExternalLocation
::
Unknown
)
=>
return
None
,
ExternalLocation
::
Local
=>
href_relative_parts
(
module_fqp
,
relative_to
),
ExternalLocation
::
Unknown
=>
return
None
,
},
)
}
...
...
@@ -574,12 +574,14 @@ fn primitive_link(
Some
(
&
def_id
)
=>
{
let
cname_str
;
let
loc
=
match
m
.extern_locations
[
&
def_id
.krate
]
{
(
ref
cname
,
_
,
ExternalLocation
::
Remote
(
ref
s
))
=>
{
cname_str
=
cname
.as_str
();
ExternalLocation
::
Remote
(
ref
s
)
=>
{
cname_str
=
ExternalCrate
{
crate_num
:
def_id
.krate
}
.name
(
cx
.tcx
())
.as_str
();
Some
(
vec!
[
s
.trim_end_matches
(
'/'
),
&
cname_str
[
..
]])
}
(
ref
cname
,
_
,
ExternalLocation
::
Local
)
=>
{
cname_str
=
cname
.as_str
();
ExternalLocation
::
Local
=>
{
cname_str
=
ExternalCrate
{
crate_num
:
def_id
.krate
}
.name
(
cx
.tcx
())
.as_str
();
Some
(
if
cx
.current
.first
()
.map
(|
x
|
&
x
[
..
])
==
Some
(
&
cname_str
[
..
])
{
iter
::
repeat
(
".."
)
.take
(
cx
.current
.len
()
-
1
)
.collect
()
}
else
{
...
...
@@ -587,7 +589,7 @@ fn primitive_link(
iter
::
repeat
(
".."
)
.take
(
cx
.current
.len
())
.chain
(
cname
)
.collect
()
})
}
(
..
,
ExternalLocation
::
Unknown
)
=>
None
,
ExternalLocation
::
Unknown
=>
None
,
};
if
let
Some
(
loc
)
=
loc
{
write!
(
...
...
src/librustdoc/html/render/context.rs
浏览文件 @
2cc26398
...
...
@@ -18,7 +18,7 @@
use
super
::
write_shared
::
write_shared
;
use
super
::{
print_sidebar
,
settings
,
AllTypes
,
NameDoc
,
StylePath
,
BASIC_KEYWORDS
};
use
crate
::
clean
;
use
crate
::
clean
::{
self
,
ExternalCrate
}
;
use
crate
::
config
::
RenderOptions
;
use
crate
::
docfs
::{
DocFS
,
PathError
};
use
crate
::
error
::
Error
;
...
...
@@ -304,12 +304,16 @@ pub(super) fn src_href(&self, item: &clean::Item) -> Option<String> {
}
}
else
{
let
(
krate
,
src_root
)
=
match
*
self
.cache.extern_locations
.get
(
&
cnum
)
?
{
(
name
,
ref
src
,
ExternalLocation
::
Local
)
=>
(
name
,
src
),
(
name
,
ref
src
,
ExternalLocation
::
Remote
(
ref
s
))
=>
{
ExternalLocation
::
Local
=>
{
let
e
=
ExternalCrate
{
crate_num
:
cnum
};
(
e
.name
(
self
.tcx
()),
e
.src_root
(
self
.tcx
()))
}
ExternalLocation
::
Remote
(
ref
s
)
=>
{
root
=
s
.to_string
();
(
name
,
src
)
let
e
=
ExternalCrate
{
crate_num
:
cnum
};
(
e
.name
(
self
.tcx
()),
e
.src_root
(
self
.tcx
()))
}
(
_
,
_
,
ExternalLocation
::
Unknown
)
=>
return
None
,
ExternalLocation
::
Unknown
=>
return
None
,
};
sources
::
clean_path
(
&
src_root
,
file
,
false
,
|
component
|
{
...
...
src/librustdoc/json/mod.rs
浏览文件 @
2cc26398
...
...
@@ -17,7 +17,7 @@
use
rustdoc_json_types
as
types
;
use
crate
::
clean
;
use
crate
::
clean
::{
self
,
ExternalCrate
}
;
use
crate
::
config
::
RenderOptions
;
use
crate
::
error
::
Error
;
use
crate
::
formats
::
cache
::
Cache
;
...
...
@@ -218,12 +218,13 @@ fn after_krate(&mut self) -> Result<(), Error> {
.cache
.extern_locations
.iter
()
.map
(|(
k
,
v
)|
{
.map
(|(
crate_num
,
external_location
)|
{
let
e
=
ExternalCrate
{
crate_num
:
*
crate_num
};
(
k
.as_u32
(),
crate_num
.as_u32
(),
types
::
ExternalCrate
{
name
:
v
.0
.to_string
(),
html_root_url
:
match
&
v
.2
{
name
:
e
.name
(
self
.tcx
)
.to_string
(),
html_root_url
:
match
external_location
{
ExternalLocation
::
Remote
(
s
)
=>
Some
(
s
.clone
()),
_
=>
None
,
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录