Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a0baf252
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,发现更多精彩内容 >>
未验证
提交
a0baf252
编写于
3月 01, 2022
作者:
M
Matthias Krüger
提交者:
GitHub
3月 01, 2022
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #94465 - c410-f3r:more-let-chains, r=Dylan-DPC
6 - Make more use of `let_chains` Continuation of #94376. cc #53667
上级
c531b01e
fe94f78b
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
97 addition
and
118 deletion
+97
-118
compiler/rustc_mir_build/src/build/expr/stmt.rs
compiler/rustc_mir_build/src/build/expr/stmt.rs
+13
-15
compiler/rustc_mir_build/src/build/matches/mod.rs
compiler/rustc_mir_build/src/build/matches/mod.rs
+5
-7
compiler/rustc_mir_build/src/build/mod.rs
compiler/rustc_mir_build/src/build/mod.rs
+6
-8
compiler/rustc_mir_build/src/check_unsafety.rs
compiler/rustc_mir_build/src/check_unsafety.rs
+15
-19
compiler/rustc_mir_build/src/lib.rs
compiler/rustc_mir_build/src/lib.rs
+4
-3
compiler/rustc_mir_build/src/thir/pattern/check_match.rs
compiler/rustc_mir_build/src/thir/pattern/check_match.rs
+36
-42
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
+10
-14
compiler/rustc_mir_build/src/thir/pattern/mod.rs
compiler/rustc_mir_build/src/thir/pattern/mod.rs
+8
-10
未找到文件。
compiler/rustc_mir_build/src/build/expr/stmt.rs
浏览文件 @
a0baf252
...
...
@@ -116,9 +116,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// it is usually better to focus on `the_value` rather
// than the entirety of block(s) surrounding it.
let
adjusted_span
=
(||
{
if
let
ExprKind
::
Block
{
body
}
=
&
expr
.kind
{
if
let
Some
(
tail_expr
)
=
body
.expr
{
let
mut
expr
=
&
this
.thir
[
tail_expr
];
if
let
ExprKind
::
Block
{
body
}
=
&
expr
.kind
&&
let
Some
(
tail_ex
)
=
body
.expr
{
let
mut
expr
=
&
this
.thir
[
tail_ex
];
while
let
ExprKind
::
Block
{
body
:
Block
{
expr
:
Some
(
nested_expr
),
..
},
}
...
...
@@ -132,7 +131,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
});
return
Some
(
expr
.span
);
}
}
None
})();
...
...
compiler/rustc_mir_build/src/build/matches/mod.rs
浏览文件 @
a0baf252
...
...
@@ -1597,14 +1597,12 @@ fn test_candidates<'pat, 'b, 'c>(
}
// Insert a Shallow borrow of any places that is switched on.
if
let
Some
(
fb
)
=
fake_borrows
{
if
let
Ok
(
match_place_resolved
)
=
if
let
Some
(
fb
)
=
fake_borrows
&&
let
Ok
(
match_place_resolved
)
=
match_place
.clone
()
.try_upvars_resolved
(
self
.tcx
,
self
.typeck_results
)
{
let
resolved_place
=
match_place_resolved
.into_place
(
self
.tcx
,
self
.typeck_results
);
fb
.insert
(
resolved_place
);
}
}
// perform the test, branching to one of N blocks. For each of
// those N possible outcomes, create a (initially empty)
...
...
compiler/rustc_mir_build/src/build/mod.rs
浏览文件 @
a0baf252
...
...
@@ -877,8 +877,7 @@ fn args_and_body(
let
arg_local
=
self
.local_decls
.push
(
LocalDecl
::
with_source_info
(
ty
,
source_info
));
// If this is a simple binding pattern, give debuginfo a nice name.
if
let
Some
(
arg
)
=
arg_opt
{
if
let
Some
(
ident
)
=
arg
.pat
.simple_ident
()
{
if
let
Some
(
arg
)
=
arg_opt
&&
let
Some
(
ident
)
=
arg
.pat
.simple_ident
()
{
self
.var_debug_info
.push
(
VarDebugInfo
{
name
:
ident
.name
,
source_info
,
...
...
@@ -886,7 +885,6 @@ fn args_and_body(
});
}
}
}
let
tcx
=
self
.tcx
;
let
tcx_hir
=
tcx
.hir
();
...
...
compiler/rustc_mir_build/src/check_unsafety.rs
浏览文件 @
a0baf252
...
...
@@ -416,8 +416,7 @@ fn visit_expr(&mut self, expr: &Expr<'tcx>) {
}
ExprKind
::
Field
{
lhs
,
..
}
=>
{
let
lhs
=
&
self
.thir
[
lhs
];
if
let
ty
::
Adt
(
adt_def
,
_
)
=
lhs
.ty
.kind
()
{
if
adt_def
.is_union
()
{
if
let
ty
::
Adt
(
adt_def
,
_
)
=
lhs
.ty
.kind
()
&&
adt_def
.is_union
()
{
if
let
Some
((
assigned_ty
,
assignment_span
))
=
self
.assignment_info
{
// To avoid semver hazard, we only consider `Copy` and `ManuallyDrop` non-dropping.
if
!
(
assigned_ty
...
...
@@ -435,7 +434,6 @@ fn visit_expr(&mut self, expr: &Expr<'tcx>) {
}
}
}
}
ExprKind
::
Assign
{
lhs
,
rhs
}
|
ExprKind
::
AssignOp
{
lhs
,
rhs
,
..
}
=>
{
let
lhs
=
&
self
.thir
[
lhs
];
// First, check whether we are mutating a layout constrained field
...
...
@@ -476,12 +474,10 @@ fn visit_expr(&mut self, expr: &Expr<'tcx>) {
}
ExprKind
::
Let
{
expr
:
expr_id
,
..
}
=>
{
let
let_expr
=
&
self
.thir
[
expr_id
];
if
let
ty
::
Adt
(
adt_def
,
_
)
=
let_expr
.ty
.kind
()
{
if
adt_def
.is_union
()
{
if
let
ty
::
Adt
(
adt_def
,
_
)
=
let_expr
.ty
.kind
()
&&
adt_def
.is_union
()
{
self
.requires_unsafe
(
expr
.span
,
AccessToUnionField
);
}
}
}
_
=>
{}
}
visit
::
walk_expr
(
self
,
expr
);
...
...
compiler/rustc_mir_build/src/lib.rs
浏览文件 @
a0baf252
//! Construction of MIR from HIR.
//!
//! This crate also contains the match exhaustiveness and usefulness checking.
#![allow(rustc::potential_query_instability)]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(control_flow_enum)]
#![feature(crate_visibility_modifier)]
#![feature(
bool_to_option
)]
#![feature(
let_chains
)]
#![feature(let_else)]
#![feature(once_cell)]
#![feature(min_specialization)]
#![feature(once_cell)]
#![recursion_limit
=
"256"
]
#![allow(rustc::potential_query_instability)]
#[macro_use]
extern
crate
tracing
;
...
...
compiler/rustc_mir_build/src/thir/pattern/check_match.rs
浏览文件 @
a0baf252
...
...
@@ -315,13 +315,12 @@ fn check_for_bindings_named_same_as_variants(
rf
:
RefutableFlag
,
)
{
pat
.walk_always
(|
p
|
{
if
let
hir
::
PatKind
::
Binding
(
_
,
_
,
ident
,
None
)
=
p
.kind
{
if
let
Some
(
ty
::
BindByValue
(
hir
::
Mutability
::
Not
))
=
if
let
hir
::
PatKind
::
Binding
(
_
,
_
,
ident
,
None
)
=
p
.kind
&&
let
Some
(
ty
::
BindByValue
(
hir
::
Mutability
::
Not
))
=
cx
.typeck_results
.extract_binding_mode
(
cx
.tcx.sess
,
p
.hir_id
,
p
.span
)
{
let
pat_ty
=
cx
.typeck_results
.pat_ty
(
p
)
.peel_refs
();
if
let
ty
::
Adt
(
edef
,
_
)
=
pat_ty
.kind
()
{
if
edef
.is_enum
()
&&
let
pat_ty
=
cx
.typeck_results
.pat_ty
(
p
)
.peel_refs
()
&&
let
ty
::
Adt
(
edef
,
_
)
=
pat_ty
.kind
()
&&
edef
.is_enum
()
&&
edef
.variants
.iter
()
.any
(|
variant
|
{
variant
.ident
(
cx
.tcx
)
==
ident
&&
variant
.ctor_kind
==
CtorKind
::
Const
})
...
...
@@ -354,9 +353,6 @@ fn check_for_bindings_named_same_as_variants(
},
)
}
}
}
}
});
}
...
...
@@ -622,11 +618,9 @@ fn maybe_point_at_variant<'a, 'p: 'a, 'tcx: 'a>(
let
mut
covered
=
vec!
[];
for
pattern
in
patterns
{
if
let
Variant
(
variant_index
)
=
pattern
.ctor
()
{
if
let
ty
::
Adt
(
this_def
,
_
)
=
pattern
.ty
()
.kind
()
{
if
this_def
.did
!=
def
.did
{
if
let
ty
::
Adt
(
this_def
,
_
)
=
pattern
.ty
()
.kind
()
&&
this_def
.did
!=
def
.did
{
continue
;
}
}
let
sp
=
def
.variants
[
*
variant_index
]
.ident
(
cx
.tcx
)
.span
;
if
covered
.contains
(
&
sp
)
{
// Don't point at variants that have already been covered due to other patterns to avoid
...
...
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
浏览文件 @
a0baf252
...
...
@@ -680,8 +680,7 @@ fn as_slice(&self) -> Option<Slice> {
///
/// This means that the variant has a stdlib unstable feature marking it.
pub
(
super
)
fn
is_unstable_variant
(
&
self
,
pcx
:
PatCtxt
<
'_
,
'_
,
'tcx
>
)
->
bool
{
if
let
Constructor
::
Variant
(
idx
)
=
self
{
if
let
ty
::
Adt
(
adt
,
_
)
=
pcx
.ty
.kind
()
{
if
let
Constructor
::
Variant
(
idx
)
=
self
&&
let
ty
::
Adt
(
adt
,
_
)
=
pcx
.ty
.kind
()
{
let
variant_def_id
=
adt
.variants
[
*
idx
]
.def_id
;
// Filter variants that depend on a disabled unstable feature.
return
matches!
(
...
...
@@ -689,19 +688,16 @@ pub(super) fn is_unstable_variant(&self, pcx: PatCtxt<'_, '_, 'tcx>) -> bool {
EvalResult
::
Deny
{
..
}
);
}
}
false
}
/// Checks if the `Constructor` is a `Constructor::Variant` with a `#[doc(hidden)]`
/// attribute.
pub
(
super
)
fn
is_doc_hidden_variant
(
&
self
,
pcx
:
PatCtxt
<
'_
,
'_
,
'tcx
>
)
->
bool
{
if
let
Constructor
::
Variant
(
idx
)
=
self
{
if
let
ty
::
Adt
(
adt
,
_
)
=
pcx
.ty
.kind
()
{
if
let
Constructor
::
Variant
(
idx
)
=
self
&&
let
ty
::
Adt
(
adt
,
_
)
=
pcx
.ty
.kind
()
{
let
variant_def_id
=
adt
.variants
[
*
idx
]
.def_id
;
return
pcx
.cx.tcx
.is_doc_hidden
(
variant_def_id
);
}
}
false
}
...
...
compiler/rustc_mir_build/src/thir/pattern/mod.rs
浏览文件 @
a0baf252
...
...
@@ -790,8 +790,7 @@ fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
};
}
if
let
ty
::
Str
=
ty
.kind
()
{
if
let
(
if
let
ty
::
Str
=
ty
.kind
()
&&
let
(
ty
::
ConstKind
::
Value
(
a_val
@
ConstValue
::
Slice
{
..
}),
ty
::
ConstKind
::
Value
(
b_val
@
ConstValue
::
Slice
{
..
}),
)
=
(
a
.val
(),
b
.val
())
...
...
@@ -800,6 +799,5 @@ fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
let
b_bytes
=
get_slice_bytes
(
&
tcx
,
b_val
);
return
from_bool
(
a_bytes
==
b_bytes
);
}
}
fallback
()
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录