Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3b47cdc4
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
3b47cdc4
编写于
2月 26, 2023
作者:
C
Camille GILLOT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Span to StmtKind::Let.
上级
28d74a9b
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
71 addition
and
2 deletion
+71
-2
compiler/rustc_middle/src/mir/mod.rs
compiler/rustc_middle/src/mir/mod.rs
+7
-0
compiler/rustc_middle/src/thir.rs
compiler/rustc_middle/src/thir.rs
+54
-2
compiler/rustc_middle/src/thir/visit.rs
compiler/rustc_middle/src/thir/visit.rs
+1
-0
compiler/rustc_mir_build/src/build/block.rs
compiler/rustc_mir_build/src/build/block.rs
+2
-0
compiler/rustc_mir_build/src/thir/cx/block.rs
compiler/rustc_mir_build/src/thir/cx/block.rs
+5
-0
compiler/rustc_mir_build/src/thir/print.rs
compiler/rustc_mir_build/src/thir/print.rs
+2
-0
未找到文件。
compiler/rustc_middle/src/mir/mod.rs
浏览文件 @
3b47cdc4
...
...
@@ -1984,6 +1984,13 @@ pub fn is_safe_to_remove(&self) -> bool {
}
impl
BorrowKind
{
pub
fn
mutability
(
&
self
)
->
Mutability
{
match
*
self
{
BorrowKind
::
Shared
|
BorrowKind
::
Shallow
|
BorrowKind
::
Unique
=>
Mutability
::
Not
,
BorrowKind
::
Mut
{
..
}
=>
Mutability
::
Mut
,
}
}
pub
fn
allows_two_phase_borrow
(
&
self
)
->
bool
{
match
*
self
{
BorrowKind
::
Shared
|
BorrowKind
::
Shallow
|
BorrowKind
::
Unique
=>
false
,
...
...
compiler/rustc_middle/src/thir.rs
浏览文件 @
3b47cdc4
...
...
@@ -227,6 +227,9 @@ pub enum StmtKind<'tcx> {
/// The lint level for this `let` statement.
lint_level
:
LintLevel
,
/// Span of the `let <PAT> = <INIT>` part.
span
:
Span
,
},
}
...
...
@@ -594,6 +597,55 @@ pub fn simple_ident(&self) -> Option<Symbol> {
_
=>
None
,
}
}
/// Call `f` on every "binding" in a pattern, e.g., on `a` in
/// `match foo() { Some(a) => (), None => () }`
pub
fn
each_binding
(
&
self
,
mut
f
:
impl
FnMut
(
Symbol
,
BindingMode
,
Ty
<
'tcx
>
,
Span
))
{
self
.walk_always
(|
p
|
{
if
let
PatKind
::
Binding
{
name
,
mode
,
ty
,
..
}
=
p
.kind
{
f
(
name
,
mode
,
ty
,
p
.span
);
}
});
}
/// Walk the pattern in left-to-right order.
///
/// If `it(pat)` returns `false`, the children are not visited.
pub
fn
walk
(
&
self
,
mut
it
:
impl
FnMut
(
&
Pat
<
'tcx
>
)
->
bool
)
{
self
.walk_
(
&
mut
it
)
}
fn
walk_
(
&
self
,
it
:
&
mut
impl
FnMut
(
&
Pat
<
'tcx
>
)
->
bool
)
{
if
!
it
(
self
)
{
return
;
}
use
PatKind
::
*
;
match
&
self
.kind
{
Wild
|
Range
(
..
)
|
Binding
{
subpattern
:
None
,
..
}
|
Constant
{
..
}
=>
{}
AscribeUserType
{
subpattern
,
..
}
|
Binding
{
subpattern
:
Some
(
subpattern
),
..
}
|
Deref
{
subpattern
}
=>
subpattern
.walk_
(
it
),
Leaf
{
subpatterns
}
|
Variant
{
subpatterns
,
..
}
=>
{
subpatterns
.iter
()
.for_each
(|
field
|
field
.pattern
.walk_
(
it
))
}
Or
{
pats
}
=>
pats
.iter
()
.for_each
(|
p
|
p
.walk_
(
it
)),
Array
{
box
ref
prefix
,
ref
slice
,
box
ref
suffix
}
|
Slice
{
box
ref
prefix
,
ref
slice
,
box
ref
suffix
}
=>
{
prefix
.iter
()
.chain
(
slice
.iter
())
.chain
(
suffix
.iter
())
.for_each
(|
p
|
p
.walk_
(
it
))
}
}
}
/// Walk the pattern in left-to-right order.
///
/// If you always want to recurse, prefer this method over `walk`.
pub
fn
walk_always
(
&
self
,
mut
it
:
impl
FnMut
(
&
Pat
<
'tcx
>
))
{
self
.walk
(|
p
|
{
it
(
p
);
true
})
}
}
impl
<
'tcx
>
IntoDiagnosticArg
for
Pat
<
'tcx
>
{
...
...
@@ -879,7 +931,7 @@ mod size_asserts {
static_assert_size!
(
ExprKind
<
'_
>
,
40
);
static_assert_size!
(
Pat
<
'_
>
,
72
);
static_assert_size!
(
PatKind
<
'_
>
,
56
);
static_assert_size!
(
Stmt
<
'_
>
,
48
);
static_assert_size!
(
StmtKind
<
'_
>
,
4
0
);
static_assert_size!
(
Stmt
<
'_
>
,
56
);
static_assert_size!
(
StmtKind
<
'_
>
,
4
8
);
// tidy-alphabetical-end
}
compiler/rustc_middle/src/thir/visit.rs
浏览文件 @
3b47cdc4
...
...
@@ -175,6 +175,7 @@ pub fn walk_stmt<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, stmt: &Stm
ref
pattern
,
lint_level
:
_
,
else_block
,
span
:
_
,
}
=>
{
if
let
Some
(
init
)
=
initializer
{
visitor
.visit_expr
(
&
visitor
.thir
()[
*
init
]);
...
...
compiler/rustc_mir_build/src/build/block.rs
浏览文件 @
3b47cdc4
...
...
@@ -115,6 +115,7 @@ fn ast_block_stmts(
initializer
:
Some
(
initializer
),
lint_level
,
else_block
:
Some
(
else_block
),
span
:
_
,
}
=>
{
// When lowering the statement `let <pat> = <expr> else { <else> };`,
// the `<else>` block is nested in the parent scope enclosing this statement.
...
...
@@ -278,6 +279,7 @@ fn ast_block_stmts(
initializer
,
lint_level
,
else_block
:
None
,
span
:
_
,
}
=>
{
let
ignores_expr_result
=
matches!
(
pattern
.kind
,
PatKind
::
Wild
);
this
.block_context
.push
(
BlockFrame
::
Statement
{
ignores_expr_result
});
...
...
compiler/rustc_mir_build/src/thir/cx/block.rs
浏览文件 @
3b47cdc4
...
...
@@ -105,6 +105,10 @@ fn mirror_stmts(
}
}
let
span
=
match
local
.init
{
Some
(
init
)
=>
local
.span
.with_hi
(
init
.span
.hi
()),
None
=>
local
.span
,
};
let
stmt
=
Stmt
{
kind
:
StmtKind
::
Let
{
remainder_scope
,
...
...
@@ -116,6 +120,7 @@ fn mirror_stmts(
initializer
:
local
.init
.map
(|
init
|
self
.mirror_expr
(
init
)),
else_block
,
lint_level
:
LintLevel
::
Explicit
(
local
.hir_id
),
span
,
},
opt_destruction_scope
:
opt_dxn_ext
,
};
...
...
compiler/rustc_mir_build/src/thir/print.rs
浏览文件 @
3b47cdc4
...
...
@@ -151,6 +151,7 @@ fn print_stmt(&mut self, stmt_id: StmtId, depth_lvl: usize) {
initializer
,
else_block
,
lint_level
,
span
,
}
=>
{
print_indented!
(
self
,
"kind: Let {"
,
depth_lvl
+
1
);
print_indented!
(
...
...
@@ -181,6 +182,7 @@ fn print_stmt(&mut self, stmt_id: StmtId, depth_lvl: usize) {
}
print_indented!
(
self
,
format!
(
"lint_level: {:?}"
,
lint_level
),
depth_lvl
+
2
);
print_indented!
(
self
,
format!
(
"span: {:?}"
,
span
),
depth_lvl
+
2
);
print_indented!
(
self
,
"}"
,
depth_lvl
+
1
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录