Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
37954df1
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,发现更多精彩内容 >>
提交
37954df1
编写于
3月 09, 2019
作者:
L
ljedrz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc: some HirIdification
上级
b7110791
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
23 addition
and
30 deletion
+23
-30
src/librustdoc/core.rs
src/librustdoc/core.rs
+0
-9
src/librustdoc/passes/collect_intra_doc_links.rs
src/librustdoc/passes/collect_intra_doc_links.rs
+13
-11
src/librustdoc/visit_ast.rs
src/librustdoc/visit_ast.rs
+10
-10
未找到文件。
src/librustdoc/core.rs
浏览文件 @
37954df1
...
...
@@ -166,15 +166,6 @@ pub fn next_def_id(&self, crate_num: CrateNum) -> DefId {
/// Like the function of the same name on the HIR map, but skips calling it on fake DefIds.
/// (This avoids a slice-index-out-of-bounds panic.)
pub
fn
as_local_node_id
(
&
self
,
def_id
:
DefId
)
->
Option
<
ast
::
NodeId
>
{
if
self
.all_fake_def_ids
.borrow
()
.contains
(
&
def_id
)
{
None
}
else
{
self
.tcx
.hir
()
.as_local_node_id
(
def_id
)
}
}
// FIXME(@ljedrz): remove the NodeId variant
pub
fn
as_local_hir_id
(
&
self
,
def_id
:
DefId
)
->
Option
<
HirId
>
{
if
self
.all_fake_def_ids
.borrow
()
.contains
(
&
def_id
)
{
None
...
...
src/librustdoc/passes/collect_intra_doc_links.rs
浏览文件 @
37954df1
...
...
@@ -38,7 +38,7 @@ pub fn collect_intra_doc_links(krate: Crate, cx: &DocContext<'_>) -> Crate {
struct
LinkCollector
<
'a
,
'tcx
>
{
cx
:
&
'a
DocContext
<
'tcx
>
,
mod_ids
:
Vec
<
ast
::
Node
Id
>
,
mod_ids
:
Vec
<
hir
::
Hir
Id
>
,
}
impl
<
'a
,
'tcx
>
LinkCollector
<
'a
,
'tcx
>
{
...
...
@@ -55,7 +55,7 @@ fn resolve(&self,
path_str
:
&
str
,
ns
:
Namespace
,
current_item
:
&
Option
<
String
>
,
parent_id
:
Option
<
ast
::
Node
Id
>
)
parent_id
:
Option
<
hir
::
Hir
Id
>
)
->
Result
<
(
Def
,
Option
<
String
>
),
()
>
{
let
cx
=
self
.cx
;
...
...
@@ -64,8 +64,9 @@ fn resolve(&self,
// path.
if
let
Some
(
id
)
=
parent_id
.or
(
self
.mod_ids
.last
()
.cloned
())
{
// FIXME: `with_scope` requires the `NodeId` of a module.
let
node_id
=
cx
.tcx
.hir
()
.hir_to_node_id
(
id
);
let
result
=
cx
.enter_resolver
(|
resolver
|
{
resolver
.with_scope
(
id
,
|
resolver
|
{
resolver
.with_scope
(
node_
id
,
|
resolver
|
{
resolver
.resolve_str_path_error
(
DUMMY_SP
,
&
path_str
,
ns
==
ValueNS
)
})
});
...
...
@@ -127,7 +128,8 @@ fn resolve(&self,
}
// FIXME: `with_scope` requires the `NodeId` of a module.
let
ty
=
cx
.enter_resolver
(|
resolver
|
resolver
.with_scope
(
id
,
|
resolver
|
{
let
node_id
=
cx
.tcx
.hir
()
.hir_to_node_id
(
id
);
let
ty
=
cx
.enter_resolver
(|
resolver
|
resolver
.with_scope
(
node_id
,
|
resolver
|
{
resolver
.resolve_str_path_error
(
DUMMY_SP
,
&
path
,
false
)
}))
?
;
match
ty
.def
{
...
...
@@ -215,11 +217,11 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
};
// FIXME: get the resolver to work with non-local resolve scopes.
let
parent_node
=
self
.cx
.as_local_
node_id
(
item
.def_id
)
.and_then
(|
node
_id
|
{
let
parent_node
=
self
.cx
.as_local_
hir_id
(
item
.def_id
)
.and_then
(|
hir
_id
|
{
// FIXME: this fails hard for impls in non-module scope, but is necessary for the
// current `resolve()` implementation.
match
self
.cx.tcx
.hir
()
.get_module_parent_node
(
node
_id
)
{
id
if
id
!=
node
_id
=>
Some
(
id
),
match
self
.cx.tcx
.hir
()
.get_module_parent_node
(
hir
_id
)
{
id
if
id
!=
hir
_id
=>
Some
(
id
),
_
=>
None
,
}
});
...
...
@@ -238,9 +240,9 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
}
}
else
{
match
parent_node
.or
(
self
.mod_ids
.last
()
.cloned
())
{
Some
(
parent
)
if
parent
!=
ast
::
CRATE_NODE
_ID
=>
{
Some
(
parent
)
if
parent
!=
hir
::
CRATE_HIR
_ID
=>
{
// FIXME: can we pull the parent module's name from elsewhere?
Some
(
self
.cx.tcx
.hir
()
.name
(
parent
)
.to_string
())
Some
(
self
.cx.tcx
.hir
()
.name
_by_hir_id
(
parent
)
.to_string
())
}
_
=>
None
,
}
...
...
@@ -257,7 +259,7 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
};
if
item
.is_mod
()
&&
item
.attrs.inner_docs
{
self
.mod_ids
.push
(
self
.cx.tcx
.hir
()
.hir_to_node_id
(
item_hir_id
.unwrap
()
));
self
.mod_ids
.push
(
item_hir_id
.unwrap
(
));
}
let
cx
=
self
.cx
;
...
...
@@ -391,7 +393,7 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
}
if
item
.is_mod
()
&&
!
item
.attrs.inner_docs
{
self
.mod_ids
.push
(
self
.cx.tcx
.hir
()
.hir_to_node_id
(
item_hir_id
.unwrap
()
));
self
.mod_ids
.push
(
item_hir_id
.unwrap
(
));
}
if
item
.is_mod
()
{
...
...
src/librustdoc/visit_ast.rs
浏览文件 @
37954df1
...
...
@@ -31,7 +31,7 @@ pub struct RustdocVisitor<'a, 'tcx> {
pub
module
:
Module
,
pub
attrs
:
hir
::
HirVec
<
ast
::
Attribute
>
,
pub
cx
:
&
'a
core
::
DocContext
<
'tcx
>
,
view_item_stack
:
FxHashSet
<
ast
::
Node
Id
>
,
view_item_stack
:
FxHashSet
<
hir
::
Hir
Id
>
,
inlining
:
bool
,
/// Are the current module and all of its parents public?
inside_public_path
:
bool
,
...
...
@@ -44,7 +44,7 @@ pub fn new(
)
->
RustdocVisitor
<
'a
,
'tcx
>
{
// If the root is re-exported, terminate all recursion.
let
mut
stack
=
FxHashSet
::
default
();
stack
.insert
(
ast
::
CRATE_NODE
_ID
);
stack
.insert
(
hir
::
CRATE_HIR
_ID
);
RustdocVisitor
{
module
:
Module
::
new
(
None
),
attrs
:
hir
::
HirVec
::
new
(),
...
...
@@ -271,13 +271,13 @@ fn maybe_inline_local(&mut self,
om
:
&
mut
Module
,
please_inline
:
bool
)
->
bool
{
fn
inherits_doc_hidden
(
cx
:
&
core
::
DocContext
<
'_
>
,
mut
node
:
ast
::
Node
Id
)
->
bool
{
fn
inherits_doc_hidden
(
cx
:
&
core
::
DocContext
<
'_
>
,
mut
node
:
hir
::
Hir
Id
)
->
bool
{
while
let
Some
(
id
)
=
cx
.tcx
.hir
()
.get_enclosing_scope
(
node
)
{
node
=
id
;
if
cx
.tcx
.hir
()
.attrs
(
node
)
.lists
(
"doc"
)
.has_word
(
"hidden"
)
{
if
cx
.tcx
.hir
()
.attrs
_by_hir_id
(
node
)
.lists
(
"doc"
)
.has_word
(
"hidden"
)
{
return
true
;
}
if
node
==
ast
::
CRATE_NODE
_ID
{
if
node
==
hir
::
CRATE_HIR
_ID
{
break
;
}
}
...
...
@@ -326,21 +326,21 @@ fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: ast::NodeId) -> bool
return
false
}
let
def_
node_id
=
match
tcx
.hir
()
.as_local_node
_id
(
def_did
)
{
let
def_
hir_id
=
match
tcx
.hir
()
.as_local_hir
_id
(
def_did
)
{
Some
(
n
)
=>
n
,
None
=>
return
false
};
let
is_private
=
!
self
.cx.renderinfo
.borrow
()
.access_levels
.is_public
(
def_did
);
let
is_hidden
=
inherits_doc_hidden
(
self
.cx
,
def_
node
_id
);
let
is_hidden
=
inherits_doc_hidden
(
self
.cx
,
def_
hir
_id
);
// Only inline if requested or if the item would otherwise be stripped.
if
(
!
please_inline
&&
!
is_private
&&
!
is_hidden
)
||
is_no_inline
{
return
false
}
if
!
self
.view_item_stack
.insert
(
def_
node
_id
)
{
return
false
}
if
!
self
.view_item_stack
.insert
(
def_
hir
_id
)
{
return
false
}
let
ret
=
match
tcx
.hir
()
.get
(
def_node
_id
)
{
let
ret
=
match
tcx
.hir
()
.get
_by_hir_id
(
def_hir
_id
)
{
Node
::
Item
(
&
hir
::
Item
{
node
:
hir
::
ItemKind
::
Mod
(
ref
m
),
..
})
if
glob
=>
{
let
prev
=
mem
::
replace
(
&
mut
self
.inlining
,
true
);
for
i
in
&
m
.item_ids
{
...
...
@@ -373,7 +373,7 @@ fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: ast::NodeId) -> bool
}
_
=>
false
,
};
self
.view_item_stack
.remove
(
&
def_
node
_id
);
self
.view_item_stack
.remove
(
&
def_
hir
_id
);
ret
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录