Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
beb2f364
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,发现更多精彩内容 >>
提交
beb2f364
编写于
6月 20, 2022
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix panic by checking if `CStore` has the crate data we want before actually querying it
上级
987c7315
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
6 deletion
+18
-6
compiler/rustc_metadata/src/creader.rs
compiler/rustc_metadata/src/creader.rs
+4
-0
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+14
-6
未找到文件。
compiler/rustc_metadata/src/creader.rs
浏览文件 @
beb2f364
...
...
@@ -133,6 +133,10 @@ fn alloc_new_crate_num(&mut self) -> CrateNum {
CrateNum
::
new
(
self
.metas
.len
()
-
1
)
}
pub
fn
has_crate_data
(
&
self
,
cnum
:
CrateNum
)
->
bool
{
self
.metas
[
cnum
]
.is_some
()
}
pub
(
crate
)
fn
get_crate_data
(
&
self
,
cnum
:
CrateNum
)
->
CrateMetadataRef
<
'_
>
{
let
cdata
=
self
.metas
[
cnum
]
.as_ref
()
...
...
src/librustdoc/html/format.rs
浏览文件 @
beb2f364
...
...
@@ -565,7 +565,7 @@ fn generate_macro_def_id_path(
def_id
:
DefId
,
cx
:
&
Context
<
'_
>
,
root_path
:
Option
<&
str
>
,
)
->
(
String
,
ItemType
,
Vec
<
Symbol
>
)
{
)
->
Result
<
(
String
,
ItemType
,
Vec
<
Symbol
>
),
HrefError
>
{
let
tcx
=
cx
.shared.tcx
;
let
crate_name
=
tcx
.crate_name
(
def_id
.krate
)
.to_string
();
let
cache
=
cx
.cache
();
...
...
@@ -583,9 +583,15 @@ fn generate_macro_def_id_path(
})
.collect
();
let
relative
=
fqp
.iter
()
.map
(|
elem
|
elem
.to_string
());
let
cstore
=
CStore
::
from_tcx
(
tcx
);
// We need this to prevent a `panic` when this function is used from intra doc links...
if
!
cstore
.has_crate_data
(
def_id
.krate
)
{
debug!
(
"No data for crate {}"
,
crate_name
);
return
Err
(
HrefError
::
NotInExternalCache
);
}
// Check to see if it is a macro 2.0 or built-in macro.
// More information in <https://rust-lang.github.io/rfcs/1584-macros.html>.
let
is_macro_2
=
match
CStore
::
from_tcx
(
tcx
)
.load_macro_untracked
(
def_id
,
tcx
.sess
)
{
let
is_macro_2
=
match
cstore
.load_macro_untracked
(
def_id
,
tcx
.sess
)
{
LoadedMacro
::
MacroDef
(
def
,
_
)
=>
{
// If `ast_def.macro_rules` is `true`, then it's not a macro 2.0.
matches!
(
&
def
.kind
,
ast
::
ItemKind
::
MacroDef
(
ast_def
)
if
!
ast_def
.macro_rules
)
...
...
@@ -601,7 +607,8 @@ fn generate_macro_def_id_path(
if
path
.len
()
<
2
{
// The minimum we can have is the crate name followed by the macro name. If shorter, then
// it means that that `relative` was empty, which is an error.
panic!
(
"macro path cannot be empty!"
);
debug!
(
"macro path cannot be empty!"
);
return
Err
(
HrefError
::
NotInExternalCache
);
}
if
let
Some
(
last
)
=
path
.last_mut
()
{
...
...
@@ -618,10 +625,11 @@ fn generate_macro_def_id_path(
format!
(
"{}{}/{}"
,
root_path
.unwrap_or
(
""
),
crate_name
,
path
.join
(
"/"
))
}
ExternalLocation
::
Unknown
=>
{
panic!
(
"crate {} not in cache when linkifying macros"
,
crate_name
)
debug!
(
"crate {} not in cache when linkifying macros"
,
crate_name
);
return
Err
(
HrefError
::
NotInExternalCache
);
}
};
(
url
,
ItemType
::
Macro
,
fqp
)
Ok
((
url
,
ItemType
::
Macro
,
fqp
)
)
}
pub
(
crate
)
fn
href_with_root_path
(
...
...
@@ -680,7 +688,7 @@ fn to_module_fqp(shortty: ItemType, fqp: &[Symbol]) -> &[Symbol] {
},
)
}
else
if
matches!
(
def_kind
,
DefKind
::
Macro
(
_
))
{
return
Ok
(
generate_macro_def_id_path
(
did
,
cx
,
root_path
)
);
return
generate_macro_def_id_path
(
did
,
cx
,
root_path
);
}
else
{
return
Err
(
HrefError
::
NotInExternalCache
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录