Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
492ba34a
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,发现更多精彩内容 >>
提交
492ba34a
编写于
7月 04, 2021
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revert broken formatting
上级
1c1573d2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
25 addition
and
31 deletion
+25
-31
src/tools/clippy/clippy_utils/src/ty.rs
src/tools/clippy/clippy_utils/src/ty.rs
+25
-31
未找到文件。
src/tools/clippy/clippy_utils/src/ty.rs
浏览文件 @
492ba34a
...
@@ -146,26 +146,22 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
...
@@ -146,26 +146,22 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
match
ty
.kind
()
{
match
ty
.kind
()
{
ty
::
Adt
(
adt
,
_
)
=>
must_use_attr
(
cx
.tcx
.get_attrs
(
adt
.did
))
.is_some
(),
ty
::
Adt
(
adt
,
_
)
=>
must_use_attr
(
cx
.tcx
.get_attrs
(
adt
.did
))
.is_some
(),
ty
::
Foreign
(
ref
did
)
=>
must_use_attr
(
cx
.tcx
.get_attrs
(
*
did
))
.is_some
(),
ty
::
Foreign
(
ref
did
)
=>
must_use_attr
(
cx
.tcx
.get_attrs
(
*
did
))
.is_some
(),
ty
::
Slice
(
ty
)
ty
::
Slice
(
ty
)
|
ty
::
Array
(
ty
,
_
)
|
ty
::
RawPtr
(
ty
::
TypeAndMut
{
ty
,
..
})
|
ty
::
Ref
(
_
,
ty
,
_
)
=>
{
|
ty
::
Array
(
ty
,
_
)
|
ty
::
RawPtr
(
ty
::
TypeAndMut
{
ty
,
..
})
|
ty
::
Ref
(
_
,
ty
,
_
)
=>
{
// for the Array case we don't need to care for the len == 0 case
// for the Array case we don't need to care for the len == 0 case
// because we don't want to lint functions returning empty arrays
// because we don't want to lint functions returning empty arrays
is_must_use_ty
(
cx
,
*
ty
)
is_must_use_ty
(
cx
,
*
ty
)
}
}
,
ty
::
Tuple
(
substs
)
=>
substs
.types
()
.any
(|
ty
|
is_must_use_ty
(
cx
,
ty
)),
ty
::
Tuple
(
substs
)
=>
substs
.types
()
.any
(|
ty
|
is_must_use_ty
(
cx
,
ty
)),
ty
::
Opaque
(
ref
def_id
,
_
)
=>
{
ty
::
Opaque
(
ref
def_id
,
_
)
=>
{
for
(
predicate
,
_
)
in
cx
.tcx
.explicit_item_bounds
(
*
def_id
)
{
for
(
predicate
,
_
)
in
cx
.tcx
.explicit_item_bounds
(
*
def_id
)
{
if
let
ty
::
PredicateKind
::
Trait
(
trait_predicate
,
_
)
=
predicate
.kind
()
.skip_binder
()
if
let
ty
::
PredicateKind
::
Trait
(
trait_predicate
,
_
)
=
predicate
.kind
()
.skip_binder
()
{
{
if
must_use_attr
(
cx
.tcx
.get_attrs
(
trait_predicate
.trait_ref.def_id
))
.is_some
()
{
if
must_use_attr
(
cx
.tcx
.get_attrs
(
trait_predicate
.trait_ref.def_id
))
.is_some
()
{
return
true
;
return
true
;
}
}
}
}
}
}
false
false
}
}
,
ty
::
Dynamic
(
binder
,
_
)
=>
{
ty
::
Dynamic
(
binder
,
_
)
=>
{
for
predicate
in
binder
.iter
()
{
for
predicate
in
binder
.iter
()
{
if
let
ty
::
ExistentialPredicate
::
Trait
(
ref
trait_ref
)
=
predicate
.skip_binder
()
{
if
let
ty
::
ExistentialPredicate
::
Trait
(
ref
trait_ref
)
=
predicate
.skip_binder
()
{
...
@@ -175,7 +171,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
...
@@ -175,7 +171,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
}
}
}
}
false
false
}
}
,
_
=>
false
,
_
=>
false
,
}
}
}
}
...
@@ -185,11 +181,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
...
@@ -185,11 +181,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
// not succeed
// not succeed
/// Checks if `Ty` is normalizable. This function is useful
/// Checks if `Ty` is normalizable. This function is useful
/// to avoid crashes on `layout_of`.
/// to avoid crashes on `layout_of`.
pub
fn
is_normalizable
<
'tcx
>
(
pub
fn
is_normalizable
<
'tcx
>
(
cx
:
&
LateContext
<
'tcx
>
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
ty
:
Ty
<
'tcx
>
)
->
bool
{
cx
:
&
LateContext
<
'tcx
>
,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
ty
:
Ty
<
'tcx
>
,
)
->
bool
{
is_normalizable_helper
(
cx
,
param_env
,
ty
,
&
mut
FxHashMap
::
default
())
is_normalizable_helper
(
cx
,
param_env
,
ty
,
&
mut
FxHashMap
::
default
())
}
}
...
@@ -209,14 +201,15 @@ fn is_normalizable_helper<'tcx>(
...
@@ -209,14 +201,15 @@ fn is_normalizable_helper<'tcx>(
if
infcx
.at
(
&
cause
,
param_env
)
.normalize
(
ty
)
.is_ok
()
{
if
infcx
.at
(
&
cause
,
param_env
)
.normalize
(
ty
)
.is_ok
()
{
match
ty
.kind
()
{
match
ty
.kind
()
{
ty
::
Adt
(
def
,
substs
)
=>
def
.variants
.iter
()
.all
(|
variant
|
{
ty
::
Adt
(
def
,
substs
)
=>
def
.variants
.iter
()
.all
(|
variant
|
{
variant
.fields
.iter
()
.all
(|
field
|
{
variant
is_normalizable_helper
(
cx
,
param_env
,
field
.ty
(
cx
.tcx
,
substs
),
cache
)
.fields
})
.iter
()
.all
(|
field
|
is_normalizable_helper
(
cx
,
param_env
,
field
.ty
(
cx
.tcx
,
substs
),
cache
))
}),
}),
_
=>
ty
.walk
()
.all
(|
generic_arg
|
match
generic_arg
.unpack
()
{
_
=>
ty
.walk
()
.all
(|
generic_arg
|
match
generic_arg
.unpack
()
{
GenericArgKind
::
Type
(
inner_ty
)
if
inner_ty
!=
ty
=>
{
GenericArgKind
::
Type
(
inner_ty
)
if
inner_ty
!=
ty
=>
{
is_normalizable_helper
(
cx
,
param_env
,
inner_ty
,
cache
)
is_normalizable_helper
(
cx
,
param_env
,
inner_ty
,
cache
)
}
}
,
_
=>
true
,
// if inner_ty == ty, we've already checked it
_
=>
true
,
// if inner_ty == ty, we've already checked it
}),
}),
}
}
...
@@ -234,9 +227,7 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool {
...
@@ -234,9 +227,7 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool {
match
ty
.kind
()
{
match
ty
.kind
()
{
ty
::
Bool
|
ty
::
Char
|
ty
::
Int
(
_
)
|
ty
::
Uint
(
_
)
|
ty
::
Float
(
_
)
|
ty
::
Str
=>
true
,
ty
::
Bool
|
ty
::
Char
|
ty
::
Int
(
_
)
|
ty
::
Uint
(
_
)
|
ty
::
Float
(
_
)
|
ty
::
Str
=>
true
,
ty
::
Ref
(
_
,
inner
,
_
)
if
*
inner
.kind
()
==
ty
::
Str
=>
true
,
ty
::
Ref
(
_
,
inner
,
_
)
if
*
inner
.kind
()
==
ty
::
Str
=>
true
,
ty
::
Array
(
inner_type
,
_
)
|
ty
::
Slice
(
inner_type
)
=>
{
ty
::
Array
(
inner_type
,
_
)
|
ty
::
Slice
(
inner_type
)
=>
is_recursively_primitive_type
(
inner_type
),
is_recursively_primitive_type
(
inner_type
)
}
ty
::
Tuple
(
inner_types
)
=>
inner_types
.types
()
.all
(
is_recursively_primitive_type
),
ty
::
Tuple
(
inner_types
)
=>
inner_types
.types
()
.all
(
is_recursively_primitive_type
),
_
=>
false
,
_
=>
false
,
}
}
...
@@ -280,7 +271,11 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool {
...
@@ -280,7 +271,11 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool {
/// removed.
/// removed.
pub
fn
peel_mid_ty_refs
(
ty
:
Ty
<
'_
>
)
->
(
Ty
<
'_
>
,
usize
)
{
pub
fn
peel_mid_ty_refs
(
ty
:
Ty
<
'_
>
)
->
(
Ty
<
'_
>
,
usize
)
{
fn
peel
(
ty
:
Ty
<
'_
>
,
count
:
usize
)
->
(
Ty
<
'_
>
,
usize
)
{
fn
peel
(
ty
:
Ty
<
'_
>
,
count
:
usize
)
->
(
Ty
<
'_
>
,
usize
)
{
if
let
ty
::
Ref
(
_
,
ty
,
_
)
=
ty
.kind
()
{
peel
(
ty
,
count
+
1
)
}
else
{
(
ty
,
count
)
}
if
let
ty
::
Ref
(
_
,
ty
,
_
)
=
ty
.kind
()
{
peel
(
ty
,
count
+
1
)
}
else
{
(
ty
,
count
)
}
}
}
peel
(
ty
,
0
)
peel
(
ty
,
0
)
}
}
...
@@ -335,18 +330,17 @@ pub fn same_type_and_consts(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
...
@@ -335,18 +330,17 @@ pub fn same_type_and_consts(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
return
false
;
return
false
;
}
}
substs_a
.iter
()
.zip
(
substs_b
.iter
())
.all
(|(
arg_a
,
arg_b
)|
{
substs_a
match
(
arg_a
.unpack
(),
arg_b
.unpack
())
{
.iter
()
(
GenericArgKind
::
Const
(
inner_a
),
GenericArgKind
::
Const
(
inner_b
))
=>
{
.zip
(
substs_b
.iter
())
inner_a
==
inner_b
.all
(|(
arg_a
,
arg_b
)|
match
(
arg_a
.unpack
(),
arg_b
.unpack
())
{
}
(
GenericArgKind
::
Const
(
inner_a
),
GenericArgKind
::
Const
(
inner_b
))
=>
inner_a
==
inner_b
,
(
GenericArgKind
::
Type
(
type_a
),
GenericArgKind
::
Type
(
type_b
))
=>
{
(
GenericArgKind
::
Type
(
type_a
),
GenericArgKind
::
Type
(
type_b
))
=>
{
same_type_and_consts
(
type_a
,
type_b
)
same_type_and_consts
(
type_a
,
type_b
)
}
}
,
_
=>
true
,
_
=>
true
,
}
})
})
},
}
_
=>
a
==
b
,
_
=>
a
==
b
,
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录