Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c3491378
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
c3491378
编写于
4月 06, 2022
作者:
B
b-naber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
get rid of visit_constant in thir visitor
上级
14e3d038
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
27 addition
and
24 deletion
+27
-24
compiler/rustc_middle/src/thir/visit.rs
compiler/rustc_middle/src/thir/visit.rs
+8
-2
compiler/rustc_middle/src/ty/util.rs
compiler/rustc_middle/src/ty/util.rs
+8
-6
compiler/rustc_mir_build/src/thir/pattern/mod.rs
compiler/rustc_mir_build/src/thir/pattern/mod.rs
+2
-4
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
...ler/rustc_trait_selection/src/traits/const_evaluatable.rs
+0
-4
src/tools/clippy/clippy_lints/src/matches/overlapping_arms.rs
...tools/clippy/clippy_lints/src/matches/overlapping_arms.rs
+9
-8
未找到文件。
compiler/rustc_middle/src/thir/visit.rs
浏览文件 @
c3491378
use
super
::{
Arm
,
Block
,
Expr
,
ExprKind
,
Guard
,
InlineAsmOperand
,
Pat
,
PatKind
,
Stmt
,
StmtKind
,
Thir
,
};
use
crate
::
mir
::
ConstantKind
;
pub
trait
Visitor
<
'a
,
'tcx
:
'a
>
:
Sized
{
fn
thir
(
&
self
)
->
&
'a
Thir
<
'tcx
>
;
...
...
@@ -26,7 +25,14 @@ fn visit_pat(&mut self, pat: &Pat<'tcx>) {
walk_pat
(
self
,
pat
);
}
fn
visit_constant
(
&
mut
self
,
_
constant
:
ConstantKind
<
'tcx
>
)
{}
// Note: We don't have visitors for `ty::Const` and `mir::ConstantKind`
// (even though these types occur in THIR) for consistency and to reduce confusion,
// since the lazy creation of constants during thir construction causes most
// 'constants' to not be of type `ty::Const` or `mir::ConstantKind` at that
// stage (they are mostly still identified by `DefId` or `hir::Lit`, see
// the variants `Literal`, `NonHirLiteral` and `NamedConst` in `thir::ExprKind`).
// You have to manually visit `ty::Const` and `mir::ConstantKind` through the
// other `visit*` functions.
}
pub
fn
walk_expr
<
'a
,
'tcx
:
'a
,
V
:
Visitor
<
'a
,
'tcx
>>
(
visitor
:
&
mut
V
,
expr
:
&
Expr
<
'tcx
>
)
{
...
...
compiler/rustc_middle/src/ty/util.rs
浏览文件 @
c3491378
...
...
@@ -662,8 +662,8 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
impl
<
'tcx
>
Ty
<
'tcx
>
{
/// Returns the maximum value for the given numeric type (including `char`s)
/// or returns `None` if the type is not numeric.
pub
fn
numeric_max_val
(
self
,
tcx
:
TyCtxt
<
'tcx
>
)
->
Option
<
u128
>
{
match
self
.kind
()
{
pub
fn
numeric_max_val
(
self
,
tcx
:
TyCtxt
<
'tcx
>
)
->
Option
<
Const
<
'tcx
>
>
{
let
val
=
match
self
.kind
()
{
ty
::
Int
(
_
)
|
ty
::
Uint
(
_
)
=>
{
let
(
size
,
signed
)
=
int_size_and_signed
(
tcx
,
self
);
let
val
=
...
...
@@ -676,13 +676,14 @@ pub fn numeric_max_val(self, tcx: TyCtxt<'tcx>) -> Option<u128> {
ty
::
FloatTy
::
F64
=>
rustc_apfloat
::
ieee
::
Double
::
INFINITY
.to_bits
(),
}),
_
=>
None
,
}
};
val
.map
(|
v
|
Const
::
from_bits
(
tcx
,
v
,
ty
::
ParamEnv
::
empty
()
.and
(
self
)))
}
/// Returns the minimum value for the given numeric type (including `char`s)
/// or returns `None` if the type is not numeric.
pub
fn
numeric_min_val
(
self
,
tcx
:
TyCtxt
<
'tcx
>
)
->
Option
<
u128
>
{
match
self
.kind
()
{
pub
fn
numeric_min_val
(
self
,
tcx
:
TyCtxt
<
'tcx
>
)
->
Option
<
Const
<
'tcx
>
>
{
let
val
=
match
self
.kind
()
{
ty
::
Int
(
_
)
|
ty
::
Uint
(
_
)
=>
{
let
(
size
,
signed
)
=
int_size_and_signed
(
tcx
,
self
);
let
val
=
if
signed
{
size
.truncate
(
size
.signed_int_min
()
as
u128
)
}
else
{
0
};
...
...
@@ -694,7 +695,8 @@ pub fn numeric_min_val(self, tcx: TyCtxt<'tcx>) -> Option<u128> {
ty
::
FloatTy
::
F64
=>
(
-
::
rustc_apfloat
::
ieee
::
Double
::
INFINITY
)
.to_bits
(),
}),
_
=>
None
,
}
};
val
.map
(|
v
|
Const
::
from_bits
(
tcx
,
v
,
ty
::
ParamEnv
::
empty
()
.and
(
self
)))
}
/// Checks whether values of this type `T` are *moved* or *copied*
...
...
compiler/rustc_mir_build/src/thir/pattern/mod.rs
浏览文件 @
c3491378
...
...
@@ -183,12 +183,10 @@ fn normalize_range_pattern_ends(
Some
((
*
lo
,
*
hi
))
}
(
Some
(
PatKind
::
Constant
{
value
:
lo
}),
None
)
=>
{
let
hi
=
ty
.numeric_max_val
(
self
.tcx
)
?
;
Some
((
*
lo
,
ty
::
Const
::
from_bits
(
self
.tcx
,
hi
,
ty
::
ParamEnv
::
empty
()
.and
(
ty
))))
Some
((
*
lo
,
ty
.numeric_max_val
(
self
.tcx
)
?
))
}
(
None
,
Some
(
PatKind
::
Constant
{
value
:
hi
}))
=>
{
let
lo
=
ty
.numeric_min_val
(
self
.tcx
)
?
;
Some
((
ty
::
Const
::
from_bits
(
self
.tcx
,
lo
,
ty
::
ParamEnv
::
empty
()
.and
(
ty
)),
*
hi
))
Some
((
ty
.numeric_min_val
(
self
.tcx
)
?
,
*
hi
))
}
_
=>
None
,
}
...
...
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
浏览文件 @
c3491378
...
...
@@ -376,10 +376,6 @@ fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
visit
::
walk_pat
(
self
,
pat
);
}
}
fn
visit_constant
(
&
mut
self
,
ct
:
mir
::
ConstantKind
<
'tcx
>
)
{
self
.is_poly
|
=
ct
.has_param_types_or_consts
();
}
}
let
mut
is_poly_vis
=
IsThirPolymorphic
{
is_poly
:
false
,
thir
:
body
};
...
...
src/tools/clippy/clippy_lints/src/matches/overlapping_arms.rs
浏览文件 @
c3491378
use
clippy_utils
::
consts
::{
constant
,
constant_full_int
,
FullInt
};
use
clippy_utils
::
consts
::{
constant
,
constant_full_int
,
miri_to_const
,
FullInt
};
use
clippy_utils
::
diagnostics
::
span_lint_and_note
;
use
core
::
cmp
::
Ordering
;
use
rustc_hir
::{
Arm
,
Expr
,
PatKind
,
RangeEnd
};
...
...
@@ -32,15 +32,16 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
.filter_map
(|
arm
|
{
if
let
Arm
{
pat
,
guard
:
None
,
..
}
=
*
arm
{
if
let
PatKind
::
Range
(
ref
lhs
,
ref
rhs
,
range_end
)
=
pat
.kind
{
let
lhs_
val
=
match
lhs
{
Some
(
lhs
)
=>
constant
(
cx
,
cx
.typeck_results
(),
lhs
)
?
.0
.int_value
(
cx
,
ty
)
?
,
None
=>
FullInt
::
U
(
ty
.numeric_min_val
(
cx
.tcx
)
?
)
,
let
lhs_
const
=
match
lhs
{
Some
(
lhs
)
=>
constant
(
cx
,
cx
.typeck_results
(),
lhs
)
?
.0
,
None
=>
miri_to_const
(
ty
.numeric_min_val
(
cx
.tcx
)
?
)
?
,
};
let
rhs_
val
=
match
rhs
{
Some
(
rhs
)
=>
constant
(
cx
,
cx
.typeck_results
(),
rhs
)
?
.0
.int_value
(
cx
,
ty
)
?
,
None
=>
FullInt
::
U
(
ty
.numeric_max_val
(
cx
.tcx
)
?
)
,
let
rhs_
const
=
match
rhs
{
Some
(
rhs
)
=>
constant
(
cx
,
cx
.typeck_results
(),
rhs
)
?
.0
,
None
=>
miri_to_const
(
ty
.numeric_max_val
(
cx
.tcx
)
?
)
?
,
};
let
lhs_val
=
lhs_const
.int_value
(
cx
,
ty
)
?
;
let
rhs_val
=
rhs_const
.int_value
(
cx
,
ty
)
?
;
let
rhs_bound
=
match
range_end
{
RangeEnd
::
Included
=>
EndBound
::
Included
(
rhs_val
),
RangeEnd
::
Excluded
=>
EndBound
::
Excluded
(
rhs_val
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录