Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
4bfb0453
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,发现更多精彩内容 >>
提交
4bfb0453
编写于
3月 30, 2019
作者:
M
Matthew Jasper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Give match arms an HirId and a Span
上级
615c23f6
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
53 addition
and
10 deletion
+53
-10
src/librustc/hir/intravisit.rs
src/librustc/hir/intravisit.rs
+1
-0
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+8
-0
src/librustc/hir/map/collector.rs
src/librustc/hir/map/collector.rs
+10
-0
src/librustc/hir/map/mod.rs
src/librustc/hir/map/mod.rs
+7
-0
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+4
-0
src/librustc/hir/print.rs
src/librustc/hir/print.rs
+1
-1
src/librustc_passes/hir_stats.rs
src/librustc_passes/hir_stats.rs
+1
-1
src/librustc_typeck/check/_match.rs
src/librustc_typeck/check/_match.rs
+9
-6
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+1
-0
src/libsyntax/ext/build.rs
src/libsyntax/ext/build.rs
+2
-1
src/libsyntax/mut_visit.rs
src/libsyntax/mut_visit.rs
+5
-1
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+4
-0
未找到文件。
src/librustc/hir/intravisit.rs
浏览文件 @
4bfb0453
...
...
@@ -1102,6 +1102,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
}
pub
fn
walk_arm
<
'v
,
V
:
Visitor
<
'v
>>
(
visitor
:
&
mut
V
,
arm
:
&
'v
Arm
)
{
visitor
.visit_id
(
arm
.hir_id
);
walk_list!
(
visitor
,
visit_pat
,
&
arm
.pats
);
if
let
Some
(
ref
g
)
=
arm
.guard
{
match
g
{
...
...
src/librustc/hir/lowering.rs
浏览文件 @
4bfb0453
...
...
@@ -1313,7 +1313,10 @@ fn lower_token(&mut self, token: Token, span: Span) -> TokenStream {
}
fn
lower_arm
(
&
mut
self
,
arm
:
&
Arm
)
->
hir
::
Arm
{
let
LoweredNodeId
{
node_id
:
_
,
hir_id
}
=
self
.next_id
();
hir
::
Arm
{
hir_id
,
attrs
:
self
.lower_attrs
(
&
arm
.attrs
),
pats
:
arm
.pats
.iter
()
.map
(|
x
|
self
.lower_pat
(
x
))
.collect
(),
guard
:
match
arm
.guard
{
...
...
@@ -1321,6 +1324,7 @@ fn lower_arm(&mut self, arm: &Arm) -> hir::Arm {
_
=>
None
,
},
body
:
P
(
self
.lower_expr
(
&
arm
.body
)),
span
:
arm
.span
,
}
}
...
...
@@ -5023,10 +5027,14 @@ fn lower_trait_bound_modifier(&mut self, f: TraitBoundModifier) -> hir::TraitBou
// Helper methods for building HIR.
fn
arm
(
&
mut
self
,
pats
:
hir
::
HirVec
<
P
<
hir
::
Pat
>>
,
expr
:
P
<
hir
::
Expr
>
)
->
hir
::
Arm
{
let
LoweredNodeId
{
node_id
:
_
,
hir_id
}
=
self
.next_id
();
hir
::
Arm
{
hir_id
,
attrs
:
hir_vec!
[],
pats
,
guard
:
None
,
span
:
expr
.span
,
body
:
expr
,
}
}
...
...
src/librustc/hir/map/collector.rs
浏览文件 @
4bfb0453
...
...
@@ -430,6 +430,16 @@ fn visit_pat(&mut self, pat: &'hir Pat) {
});
}
fn
visit_arm
(
&
mut
self
,
arm
:
&
'hir
Arm
)
{
let
node
=
Node
::
Arm
(
arm
);
self
.insert
(
arm
.span
,
arm
.hir_id
,
node
);
self
.with_parent
(
arm
.hir_id
,
|
this
|
{
intravisit
::
walk_arm
(
this
,
arm
);
});
}
fn
visit_anon_const
(
&
mut
self
,
constant
:
&
'hir
AnonConst
)
{
self
.insert
(
DUMMY_SP
,
constant
.hir_id
,
Node
::
AnonConst
(
constant
));
...
...
src/librustc/hir/map/mod.rs
浏览文件 @
4bfb0453
...
...
@@ -373,6 +373,7 @@ fn def_kind(&self, node_id: NodeId) -> Option<DefKind> {
Node
::
Pat
(
_
)
|
Node
::
Binding
(
_
)
|
Node
::
Local
(
_
)
|
Node
::
Arm
(
_
)
|
Node
::
Lifetime
(
_
)
|
Node
::
Visibility
(
_
)
|
Node
::
Block
(
_
)
|
...
...
@@ -1000,6 +1001,7 @@ pub fn attrs_by_hir_id(&self, id: HirId) -> &'hir [ast::Attribute] {
Some
(
Node
::
Field
(
ref
f
))
=>
Some
(
&
f
.attrs
[
..
]),
Some
(
Node
::
Expr
(
ref
e
))
=>
Some
(
&*
e
.attrs
),
Some
(
Node
::
Stmt
(
ref
s
))
=>
Some
(
s
.node
.attrs
()),
Some
(
Node
::
Arm
(
ref
a
))
=>
Some
(
&*
a
.attrs
),
Some
(
Node
::
GenericParam
(
param
))
=>
Some
(
&
param
.attrs
[
..
]),
// Unit/tuple structs/variants take the attributes straight from
// the struct/variant definition.
...
...
@@ -1073,6 +1075,7 @@ pub fn span_by_hir_id(&self, hir_id: HirId) -> Span {
Some
(
Node
::
TraitRef
(
tr
))
=>
tr
.path.span
,
Some
(
Node
::
Binding
(
pat
))
=>
pat
.span
,
Some
(
Node
::
Pat
(
pat
))
=>
pat
.span
,
Some
(
Node
::
Arm
(
arm
))
=>
arm
.span
,
Some
(
Node
::
Block
(
block
))
=>
block
.span
,
Some
(
Node
::
Ctor
(
..
))
=>
match
self
.find_by_hir_id
(
self
.get_parent_node_by_hir_id
(
hir_id
))
...
...
@@ -1288,6 +1291,7 @@ pub fn print_node(&mut self, node: Node<'_>) -> io::Result<()> {
Node
::
TraitRef
(
a
)
=>
self
.print_trait_ref
(
&
a
),
Node
::
Binding
(
a
)
|
Node
::
Pat
(
a
)
=>
self
.print_pat
(
&
a
),
Node
::
Arm
(
a
)
=>
self
.print_arm
(
&
a
),
Node
::
Block
(
a
)
=>
{
use
syntax
::
print
::
pprust
::
PrintState
;
...
...
@@ -1417,6 +1421,9 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
Some
(
Node
::
Pat
(
_
))
=>
{
format!
(
"pat {}{}"
,
map
.hir_to_pretty_string
(
id
),
id_str
)
}
Some
(
Node
::
Arm
(
_
))
=>
{
format!
(
"arm {}{}"
,
map
.hir_to_pretty_string
(
id
),
id_str
)
}
Some
(
Node
::
Block
(
_
))
=>
{
format!
(
"block {}{}"
,
map
.hir_to_pretty_string
(
id
),
id_str
)
}
...
...
src/librustc/hir/mod.rs
浏览文件 @
4bfb0453
...
...
@@ -1228,6 +1228,9 @@ pub struct Local {
/// `<pats> (if <guard>) => <body>`.
#[derive(Clone,
RustcEncodable,
RustcDecodable,
Debug,
HashStable)]
pub
struct
Arm
{
#[stable_hasher(ignore)]
pub
hir_id
:
HirId
,
pub
span
:
Span
,
pub
attrs
:
HirVec
<
Attribute
>
,
/// Multiple patterns can be combined with `|`
pub
pats
:
HirVec
<
P
<
Pat
>>
,
...
...
@@ -2656,6 +2659,7 @@ pub enum Node<'hir> {
TraitRef
(
&
'hir
TraitRef
),
Binding
(
&
'hir
Pat
),
Pat
(
&
'hir
Pat
),
Arm
(
&
'hir
Arm
),
Block
(
&
'hir
Block
),
Local
(
&
'hir
Local
),
MacroDef
(
&
'hir
MacroDef
),
...
...
src/librustc/hir/print.rs
浏览文件 @
4bfb0453
...
...
@@ -1862,7 +1862,7 @@ pub fn print_pat(&mut self, pat: &hir::Pat) -> io::Result<()> {
self
.ann
.post
(
self
,
AnnNode
::
Pat
(
pat
))
}
fn
print_arm
(
&
mut
self
,
arm
:
&
hir
::
Arm
)
->
io
::
Result
<
()
>
{
pub
fn
print_arm
(
&
mut
self
,
arm
:
&
hir
::
Arm
)
->
io
::
Result
<
()
>
{
// I have no idea why this check is necessary, but here it
// is :(
if
arm
.attrs
.is_empty
()
{
...
...
src/librustc_passes/hir_stats.rs
浏览文件 @
4bfb0453
...
...
@@ -149,7 +149,7 @@ fn visit_stmt(&mut self, s: &'v hir::Stmt) {
}
fn
visit_arm
(
&
mut
self
,
a
:
&
'v
hir
::
Arm
)
{
self
.record
(
"Arm"
,
Id
::
No
ne
,
a
);
self
.record
(
"Arm"
,
Id
::
No
de
(
a
.hir_id
)
,
a
);
hir_visit
::
walk_arm
(
self
,
a
)
}
...
...
src/librustc_typeck/check/_match.rs
浏览文件 @
4bfb0453
...
...
@@ -781,14 +781,17 @@ fn if_fallback_coercion(
fn
maybe_get_coercion_reason
(
&
self
,
hir_id
:
hir
::
HirId
,
span
:
Span
)
->
Option
<
(
Span
,
String
)
>
{
use
hir
::
Node
::{
Block
,
Item
,
Local
};
let
node
=
self
.tcx
.hir
()
.get_by_hir_id
(
self
.tcx
.hir
()
.get_parent_node_by_hir_id
(
self
.tcx
.hir
()
.get_parent_node_by_hir_id
(
hir_id
),
));
let
hir
=
self
.tcx
.hir
();
let
arm_id
=
hir
.get_parent_node_by_hir_id
(
hir_id
);
let
match_id
=
hir
.get_parent_node_by_hir_id
(
arm_id
);
let
containing_id
=
hir
.get_parent_node_by_hir_id
(
match_id
);
let
node
=
hir
.get_by_hir_id
(
containing_id
);
if
let
Block
(
block
)
=
node
{
// check that the body's parent is an fn
let
parent
=
self
.tcx
.hir
()
.get_by_hir_id
(
self
.tcx
.hir
()
.get_parent_node_by_hir_id
(
self
.tcx
.hir
()
.get_parent_node_by_hir_id
(
block
.hir_id
),
let
parent
=
hir
.get_by_hir_id
(
hir
.get_parent_node_by_hir_id
(
hir
.get_parent_node_by_hir_id
(
block
.hir_id
),
),
);
if
let
(
Some
(
expr
),
Item
(
hir
::
Item
{
...
...
src/libsyntax/ast.rs
浏览文件 @
4bfb0453
...
...
@@ -908,6 +908,7 @@ pub struct Arm {
pub
pats
:
Vec
<
P
<
Pat
>>
,
pub
guard
:
Option
<
Guard
>
,
pub
body
:
P
<
Expr
>
,
pub
span
:
Span
,
}
#[derive(Clone,
RustcEncodable,
RustcDecodable,
Debug)]
...
...
src/libsyntax/ext/build.rs
浏览文件 @
4bfb0453
...
...
@@ -890,12 +890,13 @@ fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
self
.pat_tuple_struct
(
span
,
path
,
vec!
[
pat
])
}
fn
arm
(
&
self
,
_
span
:
Span
,
pats
:
Vec
<
P
<
ast
::
Pat
>>
,
expr
:
P
<
ast
::
Expr
>
)
->
ast
::
Arm
{
fn
arm
(
&
self
,
span
:
Span
,
pats
:
Vec
<
P
<
ast
::
Pat
>>
,
expr
:
P
<
ast
::
Expr
>
)
->
ast
::
Arm
{
ast
::
Arm
{
attrs
:
vec!
[],
pats
,
guard
:
None
,
body
:
expr
,
span
,
}
}
...
...
src/libsyntax/mut_visit.rs
浏览文件 @
4bfb0453
...
...
@@ -392,11 +392,15 @@ pub fn noop_visit_use_tree<T: MutVisitor>(use_tree: &mut UseTree, vis: &mut T) {
vis
.visit_span
(
span
);
}
pub
fn
noop_visit_arm
<
T
:
MutVisitor
>
(
Arm
{
attrs
,
pats
,
guard
,
body
}:
&
mut
Arm
,
vis
:
&
mut
T
)
{
pub
fn
noop_visit_arm
<
T
:
MutVisitor
>
(
Arm
{
attrs
,
pats
,
guard
,
body
,
span
}:
&
mut
Arm
,
vis
:
&
mut
T
,
)
{
visit_attrs
(
attrs
,
vis
);
visit_vec
(
pats
,
|
pat
|
vis
.visit_pat
(
pat
));
visit_opt
(
guard
,
|
guard
|
vis
.visit_guard
(
guard
));
vis
.visit_expr
(
body
);
vis
.visit_span
(
span
);
}
pub
fn
noop_visit_guard
<
T
:
MutVisitor
>
(
g
:
&
mut
Guard
,
vis
:
&
mut
T
)
{
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
4bfb0453
...
...
@@ -3946,6 +3946,7 @@ fn parse_match_expr(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<E
crate
fn
parse_arm
(
&
mut
self
)
->
PResult
<
'a
,
Arm
>
{
let
attrs
=
self
.parse_outer_attributes
()
?
;
let
lo
=
self
.span
;
let
pats
=
self
.parse_pats
()
?
;
let
guard
=
if
self
.eat_keyword
(
keywords
::
If
)
{
Some
(
Guard
::
If
(
self
.parse_expr
()
?
))
...
...
@@ -3965,6 +3966,8 @@ fn parse_match_expr(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<E
let
require_comma
=
classify
::
expr_requires_semi_to_be_stmt
(
&
expr
)
&&
self
.token
!=
token
::
CloseDelim
(
token
::
Brace
);
let
hi
=
self
.span
;
if
require_comma
{
let
cm
=
self
.sess
.source_map
();
self
.expect_one_of
(
&
[
token
::
Comma
],
&
[
token
::
CloseDelim
(
token
::
Brace
)])
...
...
@@ -4008,6 +4011,7 @@ fn parse_match_expr(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<E
pats
,
guard
,
body
:
expr
,
span
:
lo
.to
(
hi
),
})
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录