Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b7110791
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,发现更多精彩内容 >>
提交
b7110791
编写于
3月 09, 2019
作者:
L
ljedrz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hir: make NodeId methods depend on HirId ones
上级
16fd0f47
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
102 addition
and
118 deletion
+102
-118
src/librustc/hir/map/mod.rs
src/librustc/hir/map/mod.rs
+102
-118
未找到文件。
src/librustc/hir/map/mod.rs
浏览文件 @
b7110791
...
...
@@ -200,17 +200,16 @@ impl<'hir> Map<'hir> {
/// NodeId, no actual content was returned, so no read is needed.
pub
fn
read
(
&
self
,
id
:
NodeId
)
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
if
let
Some
(
entry
)
=
self
.map
.get
(
&
hir_id
)
{
self
.dep_graph
.read_index
(
entry
.dep_node
);
}
else
{
bug!
(
"called `HirMap::read()` with invalid `NodeId`: {:?}"
,
id
)
}
self
.read_by_hir_id
(
hir_id
);
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
read_by_hir_id
(
&
self
,
hir_id
:
HirId
)
{
let
node_id
=
self
.hir_to_node_id
(
hir_id
);
self
.read
(
node_id
);
if
let
Some
(
entry
)
=
self
.map
.get
(
&
hir_id
)
{
self
.dep_graph
.read_index
(
entry
.dep_node
);
}
else
{
bug!
(
"called `HirMap::read()` with invalid `HirId`: {:?}"
,
hir_id
)
}
}
#[inline]
...
...
@@ -458,17 +457,16 @@ pub fn body(&self, id: BodyId) -> &'hir Body {
pub
fn
fn_decl
(
&
self
,
node_id
:
ast
::
NodeId
)
->
Option
<
FnDecl
>
{
let
hir_id
=
self
.node_to_hir_id
(
node_id
);
if
let
Some
(
entry
)
=
self
.find_entry
(
hir_id
)
{
entry
.fn_decl
()
.cloned
()
}
else
{
bug!
(
"no entry for node_id `{}`"
,
node_id
)
}
self
.fn_decl_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
fn_decl_by_hir_id
(
&
self
,
hir_id
:
HirId
)
->
Option
<
FnDecl
>
{
let
node_id
=
self
.hir_to_node_id
(
hir_id
);
self
.fn_decl
(
node_id
)
if
let
Some
(
entry
)
=
self
.find_entry
(
hir_id
)
{
entry
.fn_decl
()
.cloned
()
}
else
{
bug!
(
"no entry for hir_id `{}`"
,
hir_id
)
}
}
/// Returns the `NodeId` that corresponds to the definition of
...
...
@@ -488,6 +486,11 @@ pub fn body_owner_def_id(&self, id: BodyId) -> DefId {
/// if the node is a body owner, otherwise returns `None`.
pub
fn
maybe_body_owned_by
(
&
self
,
id
:
NodeId
)
->
Option
<
BodyId
>
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.maybe_body_owned_by_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
maybe_body_owned_by_by_hir_id
(
&
self
,
hir_id
:
HirId
)
->
Option
<
BodyId
>
{
if
let
Some
(
entry
)
=
self
.find_entry
(
hir_id
)
{
if
self
.dep_graph
.is_fully_enabled
()
{
let
hir_id_owner
=
hir_id
.owner
;
...
...
@@ -497,16 +500,10 @@ pub fn maybe_body_owned_by(&self, id: NodeId) -> Option<BodyId> {
entry
.associated_body
()
}
else
{
bug!
(
"no entry for id `{}`"
,
id
)
bug!
(
"no entry for id `{}`"
,
hir_
id
)
}
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
maybe_body_owned_by_by_hir_id
(
&
self
,
id
:
HirId
)
->
Option
<
BodyId
>
{
let
node_id
=
self
.hir_to_node_id
(
id
);
self
.maybe_body_owned_by
(
node_id
)
}
/// Given a body owner's id, returns the `BodyId` associated with it.
pub
fn
body_owned_by
(
&
self
,
id
:
HirId
)
->
BodyId
{
self
.maybe_body_owned_by_by_hir_id
(
id
)
.unwrap_or_else
(||
{
...
...
@@ -516,7 +513,13 @@ pub fn body_owned_by(&self, id: HirId) -> BodyId {
}
pub
fn
body_owner_kind
(
&
self
,
id
:
NodeId
)
->
BodyOwnerKind
{
match
self
.get
(
id
)
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.body_owner_kind_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
body_owner_kind_by_hir_id
(
&
self
,
id
:
HirId
)
->
BodyOwnerKind
{
match
self
.get_by_hir_id
(
id
)
{
Node
::
Item
(
&
Item
{
node
:
ItemKind
::
Const
(
..
),
..
})
|
Node
::
TraitItem
(
&
TraitItem
{
node
:
TraitItemKind
::
Const
(
..
),
..
})
|
Node
::
ImplItem
(
&
ImplItem
{
node
:
ImplItemKind
::
Const
(
..
),
..
})
|
...
...
@@ -539,12 +542,6 @@ pub fn body_owner_kind(&self, id: NodeId) -> BodyOwnerKind {
}
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
body_owner_kind_by_hir_id
(
&
self
,
id
:
HirId
)
->
BodyOwnerKind
{
let
node_id
=
self
.hir_to_node_id
(
id
);
self
.body_owner_kind
(
node_id
)
}
pub
fn
ty_param_owner
(
&
self
,
id
:
HirId
)
->
HirId
{
match
self
.get_by_hir_id
(
id
)
{
Node
::
Item
(
&
Item
{
node
:
ItemKind
::
Trait
(
..
),
..
})
|
...
...
@@ -625,14 +622,15 @@ pub fn visit_item_likes_in_module<V>(&self, module: DefId, visitor: &mut V)
/// Retrieve the Node corresponding to `id`, panicking if it cannot
/// be found.
pub
fn
get
(
&
self
,
id
:
NodeId
)
->
Node
<
'hir
>
{
// read recorded by `find`
self
.
find
(
id
)
.unwrap_or_else
(||
bug!
(
"couldn't find node id {} in the AST map"
,
id
)
)
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.
get_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
get_by_hir_id
(
&
self
,
id
:
HirId
)
->
Node
<
'hir
>
{
let
node_id
=
self
.hir_to_node_id
(
id
);
self
.get
(
node_id
)
// read recorded by `find`
self
.find_by_hir_id
(
id
)
.unwrap_or_else
(||
bug!
(
"couldn't find hir id {} in the HIR map"
,
id
))
}
pub
fn
get_if_local
(
&
self
,
id
:
DefId
)
->
Option
<
Node
<
'hir
>>
{
...
...
@@ -669,6 +667,11 @@ pub fn get_generics_span(&self, id: DefId) -> Option<Span> {
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
pub
fn
find
(
&
self
,
id
:
NodeId
)
->
Option
<
Node
<
'hir
>>
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.find_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
find_by_hir_id
(
&
self
,
hir_id
:
HirId
)
->
Option
<
Node
<
'hir
>>
{
let
result
=
self
.find_entry
(
hir_id
)
.and_then
(|
entry
|
{
if
let
Node
::
Crate
=
entry
.node
{
None
...
...
@@ -682,12 +685,6 @@ pub fn find(&self, id: NodeId) -> Option<Node<'hir>> {
result
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
find_by_hir_id
(
&
self
,
hir_id
:
HirId
)
->
Option
<
Node
<
'hir
>>
{
let
node_id
=
self
.hir_to_node_id
(
hir_id
);
self
.find
(
node_id
)
}
/// Similar to `get_parent`; returns the parent node-id, or own `id` if there is
/// no parent. Note that the parent may be `CRATE_NODE_ID`, which is not itself
/// present in the map -- so passing the return value of get_parent_node to
...
...
@@ -700,6 +697,12 @@ pub fn find_by_hir_id(&self, hir_id: HirId) -> Option<Node<'hir>> {
/// that can happen if the ID is not in the map itself or is just weird).
pub
fn
get_parent_node
(
&
self
,
id
:
NodeId
)
->
NodeId
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
let
parent_hir_id
=
self
.get_parent_node_by_hir_id
(
hir_id
);
self
.hir_to_node_id
(
parent_hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
get_parent_node_by_hir_id
(
&
self
,
hir_id
:
HirId
)
->
HirId
{
if
self
.dep_graph
.is_fully_enabled
()
{
let
hir_id_owner
=
hir_id
.owner
;
let
def_path_hash
=
self
.definitions
.def_path_hash
(
hir_id_owner
);
...
...
@@ -708,15 +711,7 @@ pub fn get_parent_node(&self, id: NodeId) -> NodeId {
self
.find_entry
(
hir_id
)
.and_then
(|
x
|
x
.parent_node
())
.map
(|
x
|
self
.hir_to_node_id
(
x
))
.unwrap_or
(
id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
get_parent_node_by_hir_id
(
&
self
,
id
:
HirId
)
->
HirId
{
let
node_id
=
self
.hir_to_node_id
(
id
);
let
parent_node_id
=
self
.get_parent_node
(
node_id
);
self
.node_to_hir_id
(
parent_node_id
)
.unwrap_or
(
hir_id
)
}
/// Check if the node is an argument. An argument is a local variable whose
...
...
@@ -832,7 +827,13 @@ pub fn get_return_block(&self, id: HirId) -> Option<HirId> {
/// in a module, trait, or impl.
pub
fn
get_parent
(
&
self
,
id
:
NodeId
)
->
NodeId
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
let
parent_hid
=
match
self
.walk_parent_nodes
(
hir_id
,
|
node
|
match
*
node
{
let
parent_hir_id
=
self
.get_parent_item
(
hir_id
);
self
.hir_to_node_id
(
parent_hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
get_parent_item
(
&
self
,
hir_id
:
HirId
)
->
HirId
{
match
self
.walk_parent_nodes
(
hir_id
,
|
node
|
match
*
node
{
Node
::
Item
(
_
)
|
Node
::
ForeignItem
(
_
)
|
Node
::
TraitItem
(
_
)
|
...
...
@@ -841,75 +842,65 @@ pub fn get_parent(&self, id: NodeId) -> NodeId {
},
|
_
|
false
)
{
Ok
(
id
)
=>
id
,
Err
(
id
)
=>
id
,
};
self
.hir_to_node_id
(
parent_hid
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
get_parent_item
(
&
self
,
id
:
HirId
)
->
HirId
{
let
node_id
=
self
.hir_to_node_id
(
id
);
let
parent_node_id
=
self
.get_parent
(
node_id
);
self
.node_to_hir_id
(
parent_node_id
)
}
}
/// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no
/// module parent is in this map.
pub
fn
get_module_parent
(
&
self
,
id
:
NodeId
)
->
DefId
{
self
.local_def_id
(
self
.get_module_parent_node
(
id
))
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.get_module_parent_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
get_module_parent_by_hir_id
(
&
self
,
id
:
HirId
)
->
DefId
{
let
node_id
=
self
.hir_to_node_id
(
id
);
self
.get_module_parent
(
node_id
)
self
.local_def_id_from_hir_id
(
self
.get_module_parent_node
(
id
))
}
/// Returns the `
Node
Id` of `id`'s nearest module parent, or `id` itself if no
/// Returns the `
Hir
Id` of `id`'s nearest module parent, or `id` itself if no
/// module parent is in this map.
pub
fn
get_module_parent_node
(
&
self
,
id
:
NodeId
)
->
NodeId
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
let
parent_hid
=
match
self
.walk_parent_nodes
(
hir_id
,
|
node
|
match
*
node
{
pub
fn
get_module_parent_node
(
&
self
,
hir_id
:
HirId
)
->
HirId
{
match
self
.walk_parent_nodes
(
hir_id
,
|
node
|
match
*
node
{
Node
::
Item
(
&
Item
{
node
:
ItemKind
::
Mod
(
_
),
..
})
=>
true
,
_
=>
false
,
},
|
_
|
false
)
{
Ok
(
id
)
=>
id
,
Err
(
id
)
=>
id
,
};
self
.hir_to_node_id
(
parent_hid
)
}
}
/// Returns the nearest enclosing scope. A scope is an item or block.
/// FIXME: it is not clear to me that all items qualify as scopes -- statics
/// and associated types probably shouldn't, for example. Behavior in this
/// regard should be expected to be highly unstable.
pub
fn
get_enclosing_scope
(
&
self
,
id
:
NodeId
)
->
Option
<
NodeId
>
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
let
parent_hid
=
self
.walk_parent_nodes
(
hir_id
,
|
node
|
match
*
node
{
pub
fn
get_enclosing_scope
(
&
self
,
hir_id
:
HirId
)
->
Option
<
HirId
>
{
self
.walk_parent_nodes
(
hir_id
,
|
node
|
match
*
node
{
Node
::
Item
(
_
)
|
Node
::
ForeignItem
(
_
)
|
Node
::
TraitItem
(
_
)
|
Node
::
ImplItem
(
_
)
|
Node
::
Block
(
_
)
=>
true
,
_
=>
false
,
},
|
_
|
false
)
.ok
();
parent_hid
.map
(|
hid
|
self
.hir_to_node_id
(
hid
))
},
|
_
|
false
)
.ok
()
}
pub
fn
get_parent_did
(
&
self
,
id
:
NodeId
)
->
DefId
{
self
.local_def_id
(
self
.get_parent
(
id
))
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.get_parent_did_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
get_parent_did_by_hir_id
(
&
self
,
id
:
HirId
)
->
DefId
{
let
node_id
=
self
.hir_to_node_id
(
id
);
self
.get_parent_did
(
node_id
)
self
.local_def_id_from_hir_id
(
self
.get_parent_item
(
id
))
}
pub
fn
get_foreign_abi
(
&
self
,
id
:
NodeId
)
->
Abi
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.get_foreign_abi_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
get_foreign_abi_by_hir_id
(
&
self
,
hir_id
:
HirId
)
->
Abi
{
let
parent
=
self
.get_parent_item
(
hir_id
);
if
let
Some
(
entry
)
=
self
.find_entry
(
parent
)
{
if
let
Entry
{
...
...
@@ -922,17 +913,9 @@ pub fn get_foreign_abi(&self, id: NodeId) -> Abi {
bug!
(
"expected foreign mod or inlined parent, found {}"
,
self
.hir_to_string
(
parent
))
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
get_foreign_abi_by_hir_id
(
&
self
,
id
:
HirId
)
->
Abi
{
let
node_id
=
self
.hir_to_node_id
(
id
);
self
.get_foreign_abi
(
node_id
)
}
pub
fn
expect_item
(
&
self
,
id
:
NodeId
)
->
&
'hir
Item
{
match
self
.find
(
id
)
{
// read recorded by `find`
Some
(
Node
::
Item
(
item
))
=>
item
,
_
=>
bug!
(
"expected item, found {}"
,
self
.node_to_string
(
id
))
}
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.expect_item_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
...
...
@@ -987,21 +970,27 @@ pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem {
}
pub
fn
expect_expr
(
&
self
,
id
:
NodeId
)
->
&
'hir
Expr
{
match
self
.find
(
id
)
{
// read recorded by find
Some
(
Node
::
Expr
(
expr
))
=>
expr
,
_
=>
bug!
(
"expected expr, found {}"
,
self
.node_to_string
(
id
))
}
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.expect_expr_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
expect_expr_by_hir_id
(
&
self
,
id
:
HirId
)
->
&
'hir
Expr
{
let
node_id
=
self
.hir_to_node_id
(
id
);
self
.expect_expr
(
node_id
)
match
self
.find_by_hir_id
(
id
)
{
// read recorded by find
Some
(
Node
::
Expr
(
expr
))
=>
expr
,
_
=>
bug!
(
"expected expr, found {}"
,
self
.hir_to_string
(
id
))
}
}
/// Returns the name associated with the given NodeId's AST.
pub
fn
name
(
&
self
,
id
:
NodeId
)
->
Name
{
match
self
.get
(
id
)
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.name_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
name_by_hir_id
(
&
self
,
id
:
HirId
)
->
Name
{
match
self
.get_by_hir_id
(
id
)
{
Node
::
Item
(
i
)
=>
i
.ident.name
,
Node
::
ForeignItem
(
fi
)
=>
fi
.ident.name
,
Node
::
ImplItem
(
ii
)
=>
ii
.ident.name
,
...
...
@@ -1011,21 +1000,21 @@ pub fn name(&self, id: NodeId) -> Name {
Node
::
Lifetime
(
lt
)
=>
lt
.name
.ident
()
.name
,
Node
::
GenericParam
(
param
)
=>
param
.name
.ident
()
.name
,
Node
::
Binding
(
&
Pat
{
node
:
PatKind
::
Binding
(
_
,
_
,
l
,
_
),
..
})
=>
l
.name
,
Node
::
Ctor
(
..
)
=>
self
.name
(
self
.get_parent
(
id
)),
_
=>
bug!
(
"no name for {}"
,
self
.
node
_to_string
(
id
))
Node
::
Ctor
(
..
)
=>
self
.name
_by_hir_id
(
self
.get_parent_item
(
id
)),
_
=>
bug!
(
"no name for {}"
,
self
.
hir
_to_string
(
id
))
}
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
name_by_hir_id
(
&
self
,
id
:
HirId
)
->
Name
{
let
node_id
=
self
.hir_to_node_id
(
id
);
self
.name
(
node_id
)
}
/// Given a node ID, get a list of attributes associated with the AST
/// corresponding to the Node ID
pub
fn
attrs
(
&
self
,
id
:
NodeId
)
->
&
'hir
[
ast
::
Attribute
]
{
self
.read
(
id
);
// reveals attributes on the node
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.attrs_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
attrs_by_hir_id
(
&
self
,
id
:
HirId
)
->
&
'hir
[
ast
::
Attribute
]
{
self
.read_by_hir_id
(
id
);
// reveals attributes on the node
let
attrs
=
match
self
.find_entry
(
id
)
.map
(|
entry
|
entry
.node
)
{
Some
(
Node
::
Local
(
l
))
=>
Some
(
&
l
.attrs
[
..
]),
Some
(
Node
::
Item
(
i
))
=>
Some
(
&
i
.attrs
[
..
]),
...
...
@@ -1039,19 +1028,13 @@ pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] {
Some
(
Node
::
GenericParam
(
param
))
=>
Some
(
&
param
.attrs
[
..
]),
// Unit/tuple structs/variants take the attributes straight from
// the struct/variant definition.
Some
(
Node
::
Ctor
(
..
))
=>
return
self
.attrs
(
self
.get_parent
(
id
)),
Some
(
Node
::
Ctor
(
..
))
=>
return
self
.attrs
_by_hir_id
(
self
.get_parent_item
(
id
)),
Some
(
Node
::
Crate
)
=>
Some
(
&
self
.forest.krate.attrs
[
..
]),
_
=>
None
};
attrs
.unwrap_or
(
&
[])
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
attrs_by_hir_id
(
&
self
,
id
:
HirId
)
->
&
'hir
[
ast
::
Attribute
]
{
let
node_id
=
self
.hir_to_node_id
(
id
);
self
.attrs
(
node_id
)
}
/// Returns an iterator that yields the node id's with paths that
/// match `parts`. (Requires `parts` is non-empty.)
///
...
...
@@ -1071,6 +1054,11 @@ pub fn nodes_matching_suffix<'a>(&'a self, parts: &'a [String])
pub
fn
span
(
&
self
,
id
:
NodeId
)
->
Span
{
let
hir_id
=
self
.node_to_hir_id
(
id
);
self
.span_by_hir_id
(
hir_id
)
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
span_by_hir_id
(
&
self
,
hir_id
:
HirId
)
->
Span
{
self
.read_by_hir_id
(
hir_id
);
// reveals span from node
match
self
.find_entry
(
hir_id
)
.map
(|
entry
|
entry
.node
)
{
Some
(
Node
::
Item
(
item
))
=>
item
.span
,
...
...
@@ -1088,7 +1076,9 @@ pub fn span(&self, id: NodeId) -> Span {
Some
(
Node
::
Binding
(
pat
))
=>
pat
.span
,
Some
(
Node
::
Pat
(
pat
))
=>
pat
.span
,
Some
(
Node
::
Block
(
block
))
=>
block
.span
,
Some
(
Node
::
Ctor
(
..
))
=>
match
self
.find
(
self
.get_parent_node
(
id
))
{
Some
(
Node
::
Ctor
(
..
))
=>
match
self
.find_by_hir_id
(
self
.get_parent_node_by_hir_id
(
hir_id
))
{
Some
(
Node
::
Item
(
item
))
=>
item
.span
,
Some
(
Node
::
Variant
(
variant
))
=>
variant
.span
,
_
=>
unreachable!
(),
...
...
@@ -1102,16 +1092,10 @@ pub fn span(&self, id: NodeId) -> Span {
Some
(
Node
::
Local
(
local
))
=>
local
.span
,
Some
(
Node
::
MacroDef
(
macro_def
))
=>
macro_def
.span
,
Some
(
Node
::
Crate
)
=>
self
.forest.krate.span
,
None
=>
bug!
(
"hir::map::Map::span: id not in map: {:?}"
,
id
),
None
=>
bug!
(
"hir::map::Map::span: id not in map: {:?}"
,
hir_
id
),
}
}
// FIXME(@ljedrz): replace the NodeId variant
pub
fn
span_by_hir_id
(
&
self
,
id
:
HirId
)
->
Span
{
let
node_id
=
self
.hir_to_node_id
(
id
);
self
.span
(
node_id
)
}
pub
fn
span_if_local
(
&
self
,
id
:
DefId
)
->
Option
<
Span
>
{
self
.as_local_node_id
(
id
)
.map
(|
id
|
self
.span
(
id
))
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录