Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0e879185
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,发现更多精彩内容 >>
提交
0e879185
编写于
3月 25, 2021
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
Auto merge of #6971 - flip1995:rustup, r=flip1995
Rustup r? `
@ghost
` changelog: none
上级
981ffa7c
40e68e59
变更
46
隐藏空白更改
内联
并排
Showing
46 changed file
with
145 addition
and
156 deletion
+145
-156
Cargo.toml
Cargo.toml
+1
-1
clippy_lints/Cargo.toml
clippy_lints/Cargo.toml
+1
-1
clippy_lints/src/attrs.rs
clippy_lints/src/attrs.rs
+1
-1
clippy_lints/src/escape.rs
clippy_lints/src/escape.rs
+3
-0
clippy_lints/src/inconsistent_struct_constructor.rs
clippy_lints/src/inconsistent_struct_constructor.rs
+1
-1
clippy_lints/src/lib.rs
clippy_lints/src/lib.rs
+0
-1
clippy_lints/src/lifetimes.rs
clippy_lints/src/lifetimes.rs
+1
-1
clippy_lints/src/loops/mut_range_bound.rs
clippy_lints/src/loops/mut_range_bound.rs
+3
-1
clippy_lints/src/manual_non_exhaustive.rs
clippy_lints/src/manual_non_exhaustive.rs
+3
-3
clippy_lints/src/matches.rs
clippy_lints/src/matches.rs
+1
-1
clippy_lints/src/methods/or_fun_call.rs
clippy_lints/src/methods/or_fun_call.rs
+1
-0
clippy_lints/src/missing_doc.rs
clippy_lints/src/missing_doc.rs
+1
-1
clippy_lints/src/needless_pass_by_value.rs
clippy_lints/src/needless_pass_by_value.rs
+3
-0
clippy_lints/src/non_copy_const.rs
clippy_lints/src/non_copy_const.rs
+9
-3
clippy_lints/src/pattern_type_mismatch.rs
clippy_lints/src/pattern_type_mismatch.rs
+2
-2
clippy_lints/src/redundant_field_names.rs
clippy_lints/src/redundant_field_names.rs
+2
-2
clippy_lints/src/suspicious_operation_groupings.rs
clippy_lints/src/suspicious_operation_groupings.rs
+1
-1
clippy_lints/src/types/borrowed_box.rs
clippy_lints/src/types/borrowed_box.rs
+2
-2
clippy_lints/src/types/mod.rs
clippy_lints/src/types/mod.rs
+3
-3
clippy_lints/src/unnested_or_patterns.rs
clippy_lints/src/unnested_or_patterns.rs
+1
-6
clippy_lints/src/utils/author.rs
clippy_lints/src/utils/author.rs
+2
-2
clippy_lints/src/utils/inspector.rs
clippy_lints/src/utils/inspector.rs
+2
-2
clippy_utils/Cargo.toml
clippy_utils/Cargo.toml
+1
-1
clippy_utils/src/ast_utils.rs
clippy_utils/src/ast_utils.rs
+11
-9
clippy_utils/src/consts.rs
clippy_utils/src/consts.rs
+5
-3
clippy_utils/src/higher.rs
clippy_utils/src/higher.rs
+1
-1
clippy_utils/src/hir_utils.rs
clippy_utils/src/hir_utils.rs
+8
-8
clippy_utils/src/lib.rs
clippy_utils/src/lib.rs
+4
-5
clippy_utils/src/usage.rs
clippy_utils/src/usage.rs
+3
-0
rust-toolchain
rust-toolchain
+1
-1
src/driver.rs
src/driver.rs
+8
-12
tests/ui/unnested_or_patterns.fixed
tests/ui/unnested_or_patterns.fixed
+0
-1
tests/ui/unnested_or_patterns.rs
tests/ui/unnested_or_patterns.rs
+0
-1
tests/ui/unnested_or_patterns.stderr
tests/ui/unnested_or_patterns.stderr
+16
-16
tests/ui/unnested_or_patterns2.fixed
tests/ui/unnested_or_patterns2.fixed
+0
-1
tests/ui/unnested_or_patterns2.rs
tests/ui/unnested_or_patterns2.rs
+0
-1
tests/ui/unnested_or_patterns2.stderr
tests/ui/unnested_or_patterns2.stderr
+8
-8
tests/ui/unnested_or_patterns3.rs
tests/ui/unnested_or_patterns3.rs
+0
-6
tests/ui/use_self.fixed
tests/ui/use_self.fixed
+12
-11
tests/ui/use_self.rs
tests/ui/use_self.rs
+12
-11
tests/ui/use_self.stderr
tests/ui/use_self.stderr
+2
-14
tests/ui/while_let_on_iterator.fixed
tests/ui/while_let_on_iterator.fixed
+0
-1
tests/ui/while_let_on_iterator.rs
tests/ui/while_let_on_iterator.rs
+0
-1
tests/ui/while_let_on_iterator.stderr
tests/ui/while_let_on_iterator.stderr
+7
-7
tests/ui/zero_sized_btreemap_values.stderr
tests/ui/zero_sized_btreemap_values.stderr
+1
-1
tests/ui/zero_sized_hashmap_values.stderr
tests/ui/zero_sized_hashmap_values.stderr
+1
-1
未找到文件。
Cargo.toml
浏览文件 @
0e879185
[package]
name
=
"clippy"
version
=
"0.1.5
2
"
version
=
"0.1.5
3
"
authors
=
[
"The Rust Clippy Developers"
]
description
=
"A bunch of helpful lints to avoid common pitfalls in Rust"
repository
=
"https://github.com/rust-lang/rust-clippy"
...
...
clippy_lints/Cargo.toml
浏览文件 @
0e879185
[package]
name
=
"clippy_lints"
# begin automatic update
version
=
"0.1.5
2
"
version
=
"0.1.5
3
"
# end automatic update
authors
=
[
"The Rust Clippy Developers"
]
description
=
"A bunch of helpful lints to avoid common pitfalls in Rust"
...
...
clippy_lints/src/attrs.rs
浏览文件 @
0e879185
...
...
@@ -564,7 +564,7 @@ fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute) {
// check for `rustfmt_skip` and `rustfmt::skip`
if
let
Some
(
skip_item
)
=
&
items
[
1
]
.meta_item
();
if
skip_item
.has_name
(
sym!
(
rustfmt_skip
))
||
skip_item
.path.segments
.last
()
.expect
(
"empty path in attribute"
)
.ident.name
==
sym
!
(
skip
)
;
skip_item
.path.segments
.last
()
.expect
(
"empty path in attribute"
)
.ident.name
==
sym
::
skip
;
// Only lint outer attributes, because custom inner attributes are unstable
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
if
let
AttrStyle
::
Outer
=
attr
.style
;
...
...
clippy_lints/src/escape.rs
浏览文件 @
0e879185
...
...
@@ -4,6 +4,7 @@
use
rustc_hir
::{
self
,
AssocItemKind
,
Body
,
FnDecl
,
HirId
,
HirIdSet
,
Impl
,
ItemKind
,
Node
};
use
rustc_infer
::
infer
::
TyCtxtInferExt
;
use
rustc_lint
::{
LateContext
,
LateLintPass
};
use
rustc_middle
::
mir
::
FakeReadCause
;
use
rustc_middle
::
ty
::{
self
,
TraitRef
,
Ty
};
use
rustc_session
::{
declare_tool_lint
,
impl_lint_pass
};
use
rustc_span
::
source_map
::
Span
;
...
...
@@ -184,6 +185,8 @@ fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) {
}
}
}
fn
fake_read
(
&
mut
self
,
_
:
rustc_typeck
::
expr_use_visitor
::
Place
<
'tcx
>
,
_
:
FakeReadCause
,
_
:
HirId
)
{}
}
impl
<
'a
,
'tcx
>
EscapeDelegate
<
'a
,
'tcx
>
{
...
...
clippy_lints/src/inconsistent_struct_constructor.rs
浏览文件 @
0e879185
...
...
@@ -120,7 +120,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
// Check whether the order of the fields in the constructor is consistent with the order in the
// definition.
fn
is_consistent_order
<
'tcx
>
(
fields
:
&
'tcx
[
hir
::
Field
<
'tcx
>
],
def_order_map
:
&
FxHashMap
<
Symbol
,
usize
>
)
->
bool
{
fn
is_consistent_order
<
'tcx
>
(
fields
:
&
'tcx
[
hir
::
Expr
Field
<
'tcx
>
],
def_order_map
:
&
FxHashMap
<
Symbol
,
usize
>
)
->
bool
{
let
mut
cur_idx
=
usize
::
MIN
;
for
f
in
fields
{
let
next_idx
=
def_order_map
[
&
f
.ident.name
];
...
...
clippy_lints/src/lib.rs
浏览文件 @
0e879185
...
...
@@ -5,7 +5,6 @@
#![feature(drain_filter)]
#![feature(in_band_lifetimes)]
#![feature(once_cell)]
#![feature(or_patterns)]
#![feature(rustc_private)]
#![feature(stmt_expr_attributes)]
#![feature(control_flow_enum)]
...
...
clippy_lints/src/lifetimes.rs
浏览文件 @
0e879185
...
...
@@ -388,7 +388,7 @@ fn visit_ty(&mut self, ty: &'tcx Ty<'_>) {
self
.nested_elision_site_lts
.append
(
&
mut
sub_visitor
.all_lts
());
return
;
},
TyKind
::
TraitObject
(
bounds
,
ref
lt
)
=>
{
TyKind
::
TraitObject
(
bounds
,
ref
lt
,
_
)
=>
{
if
!
lt
.is_elided
()
{
self
.unelided_trait_object_lifetime
=
true
;
}
...
...
clippy_lints/src/loops/mut_range_bound.rs
浏览文件 @
0e879185
...
...
@@ -5,7 +5,7 @@
use
rustc_hir
::{
BindingAnnotation
,
Expr
,
HirId
,
Node
,
PatKind
};
use
rustc_infer
::
infer
::
TyCtxtInferExt
;
use
rustc_lint
::
LateContext
;
use
rustc_middle
::
ty
;
use
rustc_middle
::
{
mir
::
FakeReadCause
,
ty
}
;
use
rustc_span
::
source_map
::
Span
;
use
rustc_typeck
::
expr_use_visitor
::{
ConsumeMode
,
Delegate
,
ExprUseVisitor
,
PlaceBase
,
PlaceWithHirId
};
...
...
@@ -107,6 +107,8 @@ fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
}
}
}
fn
fake_read
(
&
mut
self
,
_
:
rustc_typeck
::
expr_use_visitor
::
Place
<
'tcx
>
,
_
:
FakeReadCause
,
_
:
HirId
)
{}
}
impl
MutatePairDelegate
<
'_
,
'_
>
{
...
...
clippy_lints/src/manual_non_exhaustive.rs
浏览文件 @
0e879185
...
...
@@ -2,7 +2,7 @@
use
clippy_utils
::
meets_msrv
;
use
clippy_utils
::
source
::
snippet_opt
;
use
if_chain
::
if_chain
;
use
rustc_ast
::
ast
::{
Attribute
,
Item
,
ItemKind
,
StructFiel
d
,
Variant
,
VariantData
,
VisibilityKind
};
use
rustc_ast
::
ast
::{
Attribute
,
FieldDef
,
Item
,
ItemKin
d
,
Variant
,
VariantData
,
VisibilityKind
};
use
rustc_attr
as
attr
;
use
rustc_errors
::
Applicability
;
use
rustc_lint
::{
EarlyContext
,
EarlyLintPass
};
...
...
@@ -144,11 +144,11 @@ fn is_doc_hidden(attr: &Attribute) -> bool {
}
fn
check_manual_non_exhaustive_struct
(
cx
:
&
EarlyContext
<
'_
>
,
item
:
&
Item
,
data
:
&
VariantData
)
{
fn
is_private
(
field
:
&
StructField
)
->
bool
{
fn
is_private
(
field
:
&
FieldDef
)
->
bool
{
matches!
(
field
.vis.kind
,
VisibilityKind
::
Inherited
)
}
fn
is_non_exhaustive_marker
(
field
:
&
StructField
)
->
bool
{
fn
is_non_exhaustive_marker
(
field
:
&
FieldDef
)
->
bool
{
is_private
(
field
)
&&
field
.ty.kind
.is_unit
()
&&
field
.ident
.map_or
(
true
,
|
n
|
n
.as_str
()
.starts_with
(
'_'
))
}
...
...
clippy_lints/src/matches.rs
浏览文件 @
0e879185
...
...
@@ -29,7 +29,7 @@
use
rustc_span
::
sym
;
use
std
::
cmp
::
Ordering
;
use
std
::
collections
::
hash_map
::
Entry
;
use
std
::
collection
s
::
Bound
;
use
std
::
op
s
::
Bound
;
declare_clippy_lint!
{
/// **What it does:** Checks for matches with a single arm where an `if let`
...
...
clippy_lints/src/methods/or_fun_call.rs
浏览文件 @
0e879185
...
...
@@ -155,6 +155,7 @@ fn check_general_case<'tcx>(
}
}
}
if
args
.len
()
==
2
{
match
args
[
1
]
.kind
{
hir
::
ExprKind
::
Call
(
ref
fun
,
ref
or_args
)
=>
{
...
...
clippy_lints/src/missing_doc.rs
浏览文件 @
0e879185
...
...
@@ -188,7 +188,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
self
.check_missing_docs_attrs
(
cx
,
attrs
,
impl_item
.span
,
article
,
desc
);
}
fn
check_
struct_field
(
&
mut
self
,
cx
:
&
LateContext
<
'tcx
>
,
sf
:
&
'tcx
hir
::
StructField
<
'_
>
)
{
fn
check_
field_def
(
&
mut
self
,
cx
:
&
LateContext
<
'tcx
>
,
sf
:
&
'tcx
hir
::
FieldDef
<
'_
>
)
{
if
!
sf
.is_positional
()
{
let
attrs
=
cx
.tcx
.hir
()
.attrs
(
sf
.hir_id
);
self
.check_missing_docs_attrs
(
cx
,
attrs
,
sf
.span
,
"a"
,
"struct field"
);
...
...
clippy_lints/src/needless_pass_by_value.rs
浏览文件 @
0e879185
...
...
@@ -11,6 +11,7 @@
use
rustc_hir
::{
BindingAnnotation
,
Body
,
FnDecl
,
GenericArg
,
HirId
,
Impl
,
ItemKind
,
Node
,
PatKind
,
QPath
,
TyKind
};
use
rustc_infer
::
infer
::
TyCtxtInferExt
;
use
rustc_lint
::{
LateContext
,
LateLintPass
};
use
rustc_middle
::
mir
::
FakeReadCause
;
use
rustc_middle
::
ty
::{
self
,
TypeFoldable
};
use
rustc_session
::{
declare_lint_pass
,
declare_tool_lint
};
use
rustc_span
::
symbol
::
kw
;
...
...
@@ -333,4 +334,6 @@ fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _: HirId, mode: euv::Cons
fn
borrow
(
&
mut
self
,
_
:
&
euv
::
PlaceWithHirId
<
'tcx
>
,
_
:
HirId
,
_
:
ty
::
BorrowKind
)
{}
fn
mutate
(
&
mut
self
,
_
:
&
euv
::
PlaceWithHirId
<
'tcx
>
,
_
:
HirId
)
{}
fn
fake_read
(
&
mut
self
,
_
:
rustc_typeck
::
expr_use_visitor
::
Place
<
'tcx
>
,
_
:
FakeReadCause
,
_
:
HirId
)
{}
}
clippy_lints/src/non_copy_const.rs
浏览文件 @
0e879185
...
...
@@ -179,9 +179,15 @@ fn is_value_unfrozen_poly<'tcx>(cx: &LateContext<'tcx>, body_id: BodyId, ty: Ty<
fn
is_value_unfrozen_expr
<
'tcx
>
(
cx
:
&
LateContext
<
'tcx
>
,
hir_id
:
HirId
,
def_id
:
DefId
,
ty
:
Ty
<
'tcx
>
)
->
bool
{
let
substs
=
cx
.typeck_results
()
.node_substs
(
hir_id
);
let
result
=
cx
.tcx
.const_eval_resolve
(
cx
.param_env
,
ty
::
WithOptConstParam
::
unknown
(
def_id
),
substs
,
None
,
None
);
let
result
=
cx
.tcx
.const_eval_resolve
(
cx
.param_env
,
ty
::
Unevaluated
{
def
:
ty
::
WithOptConstParam
::
unknown
(
def_id
),
substs
,
promoted
:
None
,
},
None
,
);
is_value_unfrozen_raw
(
cx
,
result
,
ty
)
}
...
...
clippy_lints/src/pattern_type_mismatch.rs
浏览文件 @
0e879185
use
clippy_utils
::
diagnostics
::
span_lint_and_help
;
use
clippy_utils
::
last_path_segment
;
use
rustc_hir
::{
intravisit
,
Body
,
Expr
,
ExprKind
,
F
ieldPat
,
FnDecl
,
HirId
,
LocalSource
,
MatchSource
,
Mutability
,
Pat
,
PatKind
,
intravisit
,
Body
,
Expr
,
ExprKind
,
F
nDecl
,
HirId
,
LocalSource
,
MatchSource
,
Mutability
,
Pat
,
PatField
,
PatKind
,
QPath
,
Stmt
,
StmtKind
,
};
use
rustc_lint
::{
LateContext
,
LateLintPass
,
LintContext
};
...
...
@@ -282,7 +282,7 @@ fn find_first_mismatch_in_tuple<'tcx, I>(
fn
find_first_mismatch_in_struct
<
'tcx
>
(
cx
:
&
LateContext
<
'tcx
>
,
field_pats
:
&
[
FieldPat
<
'_
>
],
field_pats
:
&
[
PatField
<
'_
>
],
field_defs
:
&
[
FieldDef
],
substs_ref
:
SubstsRef
<
'tcx
>
,
)
->
Option
<
(
Span
,
Mutability
,
Level
)
>
{
...
...
clippy_lints/src/redundant_field_names.rs
浏览文件 @
0e879185
...
...
@@ -59,8 +59,8 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if
in_external_macro
(
cx
.sess
,
expr
.span
)
{
return
;
}
if
let
ExprKind
::
Struct
(
_
,
ref
fields
,
_
)
=
expr
.kind
{
for
field
in
fields
{
if
let
ExprKind
::
Struct
(
ref
se
)
=
expr
.kind
{
for
field
in
&
se
.
fields
{
if
field
.is_shorthand
{
continue
;
}
...
...
clippy_lints/src/suspicious_operation_groupings.rs
浏览文件 @
0e879185
...
...
@@ -565,7 +565,7 @@ fn ident_difference_expr_with_base_location(
|
(
Try
(
_
),
Try
(
_
))
|
(
Paren
(
_
),
Paren
(
_
))
|
(
Repeat
(
_
,
_
),
Repeat
(
_
,
_
))
|
(
Struct
(
_
,
_
,
_
),
Struct
(
_
,
_
,
_
))
|
(
Struct
(
_
),
Struct
(
_
))
|
(
MacCall
(
_
),
MacCall
(
_
))
|
(
LlvmInlineAsm
(
_
),
LlvmInlineAsm
(
_
))
|
(
InlineAsm
(
_
),
InlineAsm
(
_
))
...
...
clippy_lints/src/types/borrowed_box.rs
浏览文件 @
0e879185
...
...
@@ -50,7 +50,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
// Originally reported as the issue #3128.
let
inner_snippet
=
snippet
(
cx
,
inner
.span
,
".."
);
let
suggestion
=
match
&
inner
.kind
{
TyKind
::
TraitObject
(
bounds
,
lt_bound
)
if
bounds
.len
()
>
1
||
!
lt_bound
.is_elided
()
=>
{
TyKind
::
TraitObject
(
bounds
,
lt_bound
,
_
)
if
bounds
.len
()
>
1
||
!
lt_bound
.is_elided
()
=>
{
format!
(
"&{}({})"
,
ltopt
,
&
inner_snippet
)
},
TyKind
::
Path
(
qpath
)
...
...
@@ -86,7 +86,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
// Returns true if given type is `Any` trait.
fn
is_any_trait
(
t
:
&
hir
::
Ty
<
'_
>
)
->
bool
{
if_chain!
{
if
let
TyKind
::
TraitObject
(
ref
traits
,
_
)
=
t
.kind
;
if
let
TyKind
::
TraitObject
(
ref
traits
,
..
)
=
t
.kind
;
if
!
traits
.is_empty
();
// Only Send/Sync can be used as additional traits, so it is enough to
// check only the first trait.
...
...
clippy_lints/src/types/mod.rs
浏览文件 @
0e879185
...
...
@@ -268,7 +268,7 @@ fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _
self
.check_fn_decl
(
cx
,
decl
);
}
fn
check_
struct_field
(
&
mut
self
,
cx
:
&
LateContext
<
'_
>
,
field
:
&
hir
::
StructField
<
'_
>
)
{
fn
check_
field_def
(
&
mut
self
,
cx
:
&
LateContext
<
'_
>
,
field
:
&
hir
::
FieldDef
<
'_
>
)
{
self
.check_ty
(
cx
,
&
field
.ty
,
false
);
}
...
...
@@ -434,7 +434,7 @@ fn check_fn(
self
.check_fndecl
(
cx
,
decl
);
}
fn
check_
struct_field
(
&
mut
self
,
cx
:
&
LateContext
<
'tcx
>
,
field
:
&
'tcx
hir
::
StructField
<
'_
>
)
{
fn
check_
field_def
(
&
mut
self
,
cx
:
&
LateContext
<
'tcx
>
,
field
:
&
'tcx
hir
::
FieldDef
<
'_
>
)
{
// enum variants are also struct fields now
self
.check_type
(
cx
,
&
field
.ty
);
}
...
...
@@ -524,7 +524,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
// function types bring a lot of overhead
TyKind
::
BareFn
(
ref
bare
)
if
bare
.abi
==
Abi
::
Rust
=>
(
50
*
self
.nest
,
1
),
TyKind
::
TraitObject
(
ref
param_bounds
,
_
)
=>
{
TyKind
::
TraitObject
(
ref
param_bounds
,
_
,
_
)
=>
{
let
has_lifetime_parameters
=
param_bounds
.iter
()
.any
(|
bound
|
{
bound
.bound_generic_params
...
...
clippy_lints/src/unnested_or_patterns.rs
浏览文件 @
0e879185
...
...
@@ -73,11 +73,6 @@ fn check_local(&mut self, cx: &EarlyContext<'_>, l: &ast::Local) {
}
fn
lint_unnested_or_patterns
(
cx
:
&
EarlyContext
<
'_
>
,
pat
:
&
Pat
)
{
if
!
cx
.sess
.features_untracked
()
.or_patterns
{
// Do not suggest nesting the patterns if the feature `or_patterns` is not enabled.
return
;
}
if
let
Ident
(
..
,
None
)
|
Lit
(
_
)
|
Wild
|
Path
(
..
)
|
Range
(
..
)
|
Rest
|
MacCall
(
_
)
=
pat
.kind
{
// This is a leaf pattern, so cloning is unprofitable.
return
;
...
...
@@ -277,7 +272,7 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec<P<Pat>>, focus_idx: usize)
/// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal.
fn
extend_with_struct_pat
(
path1
:
&
ast
::
Path
,
fps1
:
&
mut
Vec
<
ast
::
FieldPat
>
,
fps1
:
&
mut
Vec
<
ast
::
PatField
>
,
rest1
:
bool
,
start
:
usize
,
alternatives
:
&
mut
Vec
<
P
<
Pat
>>
,
...
...
clippy_lints/src/utils/author.rs
浏览文件 @
0e879185
...
...
@@ -101,12 +101,12 @@ fn check_variant(&mut self, cx: &LateContext<'tcx>, var: &'tcx hir::Variant<'_>)
done
();
}
fn
check_
struct_field
(
&
mut
self
,
cx
:
&
LateContext
<
'tcx
>
,
field
:
&
'tcx
hir
::
StructField
<
'_
>
)
{
fn
check_
field_def
(
&
mut
self
,
cx
:
&
LateContext
<
'tcx
>
,
field
:
&
'tcx
hir
::
FieldDef
<
'_
>
)
{
if
!
has_attr
(
cx
,
field
.hir_id
)
{
return
;
}
prelude
();
PrintVisitor
::
new
(
"field"
)
.visit_
struct_field
(
field
);
PrintVisitor
::
new
(
"field"
)
.visit_
field_def
(
field
);
done
();
}
...
...
clippy_lints/src/utils/inspector.rs
浏览文件 @
0e879185
...
...
@@ -80,8 +80,8 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<
// }
// }
//
// fn check_
struct_field
(&mut self, cx: &LateContext<'tcx>, field: &'tcx
// hir::
StructField
) {
// fn check_
field_def
(&mut self, cx: &LateContext<'tcx>, field: &'tcx
// hir::
FieldDef
) {
// if !has_attr(&field.attrs) {
// return;
// }
...
...
clippy_utils/Cargo.toml
浏览文件 @
0e879185
[package]
name
=
"clippy_utils"
version
=
"0.1.5
2
"
version
=
"0.1.5
3
"
authors
=
[
"The Rust Clippy Developers"
]
edition
=
"2018"
publish
=
false
...
...
clippy_utils/src/ast_utils.rs
浏览文件 @
0e879185
...
...
@@ -66,7 +66,7 @@ pub fn eq_range_end(l: &RangeEnd, r: &RangeEnd) -> bool {
}
}
pub
fn
eq_field_pat
(
l
:
&
FieldPat
,
r
:
&
FieldPat
)
->
bool
{
pub
fn
eq_field_pat
(
l
:
&
PatField
,
r
:
&
PatField
)
->
bool
{
l
.is_placeholder
==
r
.is_placeholder
&&
eq_id
(
l
.ident
,
r
.ident
)
&&
eq_pat
(
&
l
.pat
,
&
r
.pat
)
...
...
@@ -168,14 +168,16 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
(
AddrOf
(
lbk
,
lm
,
le
),
AddrOf
(
rbk
,
rm
,
re
))
=>
lbk
==
rbk
&&
lm
==
rm
&&
eq_expr
(
le
,
re
),
(
Path
(
lq
,
lp
),
Path
(
rq
,
rp
))
=>
both
(
lq
,
rq
,
|
l
,
r
|
eq_qself
(
l
,
r
))
&&
eq_path
(
lp
,
rp
),
(
MacCall
(
l
),
MacCall
(
r
))
=>
eq_mac_call
(
l
,
r
),
(
Struct
(
lp
,
lfs
,
lb
),
Struct
(
rp
,
rfs
,
rb
))
=>
{
eq_path
(
lp
,
rp
)
&&
eq_struct_rest
(
lb
,
rb
)
&&
unordered_over
(
lfs
,
rfs
,
|
l
,
r
|
eq_field
(
l
,
r
))
(
Struct
(
lse
),
Struct
(
rse
))
=>
{
eq_path
(
&
lse
.path
,
&
rse
.path
)
&&
eq_struct_rest
(
&
lse
.rest
,
&
rse
.rest
)
&&
unordered_over
(
&
lse
.fields
,
&
rse
.fields
,
|
l
,
r
|
eq_field
(
l
,
r
))
},
_
=>
false
,
}
}
pub
fn
eq_field
(
l
:
&
Field
,
r
:
&
Field
)
->
bool
{
pub
fn
eq_field
(
l
:
&
ExprField
,
r
:
&
Expr
Field
)
->
bool
{
l
.is_placeholder
==
r
.is_placeholder
&&
eq_id
(
l
.ident
,
r
.ident
)
&&
eq_expr
(
&
l
.expr
,
&
r
.expr
)
...
...
@@ -359,7 +361,7 @@ pub fn eq_variant_data(l: &VariantData, r: &VariantData) -> bool {
}
}
pub
fn
eq_struct_field
(
l
:
&
StructField
,
r
:
&
StructField
)
->
bool
{
pub
fn
eq_struct_field
(
l
:
&
FieldDef
,
r
:
&
FieldDef
)
->
bool
{
l
.is_placeholder
==
r
.is_placeholder
&&
over
(
&
l
.attrs
,
&
r
.attrs
,
|
l
,
r
|
eq_attr
(
l
,
r
))
&&
eq_vis
(
&
l
.vis
,
&
r
.vis
)
...
...
@@ -406,6 +408,10 @@ pub fn eq_use_tree(l: &UseTree, r: &UseTree) -> bool {
eq_path
(
&
l
.prefix
,
&
r
.prefix
)
&&
eq_use_tree_kind
(
&
l
.kind
,
&
r
.kind
)
}
pub
fn
eq_anon_const
(
l
:
&
AnonConst
,
r
:
&
AnonConst
)
->
bool
{
eq_expr
(
&
l
.value
,
&
r
.value
)
}
pub
fn
eq_use_tree_kind
(
l
:
&
UseTreeKind
,
r
:
&
UseTreeKind
)
->
bool
{
use
UseTreeKind
::
*
;
match
(
l
,
r
)
{
...
...
@@ -416,10 +422,6 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
}
}
pub
fn
eq_anon_const
(
l
:
&
AnonConst
,
r
:
&
AnonConst
)
->
bool
{
eq_expr
(
&
l
.value
,
&
r
.value
)
}
pub
fn
eq_defaultness
(
l
:
Defaultness
,
r
:
Defaultness
)
->
bool
{
matches!
(
(
l
,
r
),
...
...
clippy_utils/src/consts.rs
浏览文件 @
0e879185
...
...
@@ -341,9 +341,11 @@ fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option<C
.tcx
.const_eval_resolve
(
self
.param_env
,
ty
::
WithOptConstParam
::
unknown
(
def_id
),
substs
,
None
,
ty
::
Unevaluated
{
def
:
ty
::
WithOptConstParam
::
unknown
(
def_id
),
substs
,
promoted
:
None
,
},
None
,
)
.ok
()
...
...
clippy_utils/src/higher.rs
浏览文件 @
0e879185
...
...
@@ -51,7 +51,7 @@ pub struct Range<'a> {
pub
fn
range
<
'a
>
(
expr
:
&
'a
hir
::
Expr
<
'_
>
)
->
Option
<
Range
<
'a
>>
{
/// Finds the field named `name` in the field. Always return `Some` for
/// convenience.
fn
get_field
<
'c
>
(
name
:
&
str
,
fields
:
&
'c
[
hir
::
Field
<
'_
>
])
->
Option
<&
'c
hir
::
Expr
<
'c
>>
{
fn
get_field
<
'c
>
(
name
:
&
str
,
fields
:
&
'c
[
hir
::
Expr
Field
<
'_
>
])
->
Option
<&
'c
hir
::
Expr
<
'c
>>
{
let
expr
=
&
fields
.iter
()
.find
(|
field
|
field
.ident.name
.as_str
()
==
name
)
?
.expr
;
Some
(
expr
)
...
...
clippy_utils/src/hir_utils.rs
浏览文件 @
0e879185
...
...
@@ -6,8 +6,8 @@
use
rustc_data_structures
::
stable_hasher
::{
HashStable
,
StableHasher
};
use
rustc_hir
::
def
::
Res
;
use
rustc_hir
::{
BinOpKind
,
Block
,
BlockCheckMode
,
BodyId
,
BorrowKind
,
CaptureBy
,
Expr
,
Expr
Kind
,
Field
,
FieldPat
,
FnRetTy
,
GenericArg
,
GenericArgs
,
Guard
,
HirId
,
InlineAsmOperand
,
Lifetime
,
LifetimeName
,
ParamName
,
Pat
,
PatKind
,
Path
,
BinOpKind
,
Block
,
BlockCheckMode
,
BodyId
,
BorrowKind
,
CaptureBy
,
Expr
,
Expr
Field
,
ExprKind
,
FnRetTy
,
GenericArg
,
GenericArg
s
,
Guard
,
HirId
,
InlineAsmOperand
,
Lifetime
,
LifetimeName
,
ParamName
,
Pat
,
PatField
,
PatKind
,
Path
,
PathSegment
,
QPath
,
Stmt
,
StmtKind
,
Ty
,
TyKind
,
TypeBinding
,
};
use
rustc_lexer
::{
tokenize
,
TokenKind
};
...
...
@@ -248,7 +248,7 @@ fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool {
(
&
ExprKind
::
Struct
(
ref
l_path
,
ref
lf
,
ref
lo
),
&
ExprKind
::
Struct
(
ref
r_path
,
ref
rf
,
ref
ro
))
=>
{
self
.eq_qpath
(
l_path
,
r_path
)
&&
both
(
lo
,
ro
,
|
l
,
r
|
self
.eq_expr
(
l
,
r
))
&&
over
(
lf
,
rf
,
|
l
,
r
|
self
.eq_field
(
l
,
r
))
&&
over
(
lf
,
rf
,
|
l
,
r
|
self
.eq_
expr_
field
(
l
,
r
))
},
(
&
ExprKind
::
Tup
(
l_tup
),
&
ExprKind
::
Tup
(
r_tup
))
=>
self
.eq_exprs
(
l_tup
,
r_tup
),
(
&
ExprKind
::
Unary
(
l_op
,
ref
le
),
&
ExprKind
::
Unary
(
r_op
,
ref
re
))
=>
l_op
==
r_op
&&
self
.eq_expr
(
le
,
re
),
...
...
@@ -263,7 +263,7 @@ fn eq_exprs(&mut self, left: &[Expr<'_>], right: &[Expr<'_>]) -> bool {
over
(
left
,
right
,
|
l
,
r
|
self
.eq_expr
(
l
,
r
))
}
fn
eq_
field
(
&
mut
self
,
left
:
&
Field
<
'_
>
,
right
:
&
Field
<
'_
>
)
->
bool
{
fn
eq_
expr_field
(
&
mut
self
,
left
:
&
ExprField
<
'_
>
,
right
:
&
Expr
Field
<
'_
>
)
->
bool
{
left
.ident.name
==
right
.ident.name
&&
self
.eq_expr
(
&
left
.expr
,
&
right
.expr
)
}
...
...
@@ -287,8 +287,8 @@ fn eq_lifetime(left: &Lifetime, right: &Lifetime) -> bool {
left
.name
==
right
.name
}
fn
eq_
fieldpat
(
&
mut
self
,
left
:
&
FieldPat
<
'_
>
,
right
:
&
FieldPat
<
'_
>
)
->
bool
{
let
(
FieldPat
{
ident
:
li
,
pat
:
lp
,
..
},
FieldPat
{
ident
:
ri
,
pat
:
rp
,
..
})
=
(
&
left
,
&
right
);
fn
eq_
pat_field
(
&
mut
self
,
left
:
&
PatField
<
'_
>
,
right
:
&
PatField
<
'_
>
)
->
bool
{
let
(
PatField
{
ident
:
li
,
pat
:
lp
,
..
},
PatField
{
ident
:
ri
,
pat
:
rp
,
..
})
=
(
&
left
,
&
right
);
li
.name
==
ri
.name
&&
self
.eq_pat
(
lp
,
rp
)
}
...
...
@@ -297,7 +297,7 @@ fn eq_pat(&mut self, left: &Pat<'_>, right: &Pat<'_>) -> bool {
match
(
&
left
.kind
,
&
right
.kind
)
{
(
&
PatKind
::
Box
(
ref
l
),
&
PatKind
::
Box
(
ref
r
))
=>
self
.eq_pat
(
l
,
r
),
(
&
PatKind
::
Struct
(
ref
lp
,
ref
la
,
..
),
&
PatKind
::
Struct
(
ref
rp
,
ref
ra
,
..
))
=>
{
self
.eq_qpath
(
lp
,
rp
)
&&
over
(
la
,
ra
,
|
l
,
r
|
self
.eq_
fieldpat
(
l
,
r
))
self
.eq_qpath
(
lp
,
rp
)
&&
over
(
la
,
ra
,
|
l
,
r
|
self
.eq_
pat_field
(
l
,
r
))
},
(
&
PatKind
::
TupleStruct
(
ref
lp
,
ref
la
,
ls
),
&
PatKind
::
TupleStruct
(
ref
rp
,
ref
ra
,
rs
))
=>
{
self
.eq_qpath
(
lp
,
rp
)
&&
over
(
la
,
ra
,
|
l
,
r
|
self
.eq_pat
(
l
,
r
))
&&
ls
==
rs
...
...
@@ -885,7 +885,7 @@ pub fn hash_tykind(&mut self, ty: &TyKind<'_>) {
TyKind
::
OpaqueDef
(
_
,
arg_list
)
=>
{
self
.hash_generic_args
(
arg_list
);
},
TyKind
::
TraitObject
(
_
,
lifetime
)
=>
{
TyKind
::
TraitObject
(
_
,
lifetime
,
_
)
=>
{
self
.hash_lifetime
(
lifetime
);
},
TyKind
::
Typeof
(
anon_const
)
=>
{
...
...
clippy_utils/src/lib.rs
浏览文件 @
0e879185
#![feature(box_patterns)]
#![feature(in_band_lifetimes)]
#![feature(or_patterns)]
#![feature(rustc_private)]
#![recursion_limit
=
"512"
]
#![allow(clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::must_use_candidate)]
...
...
@@ -61,9 +60,9 @@
use
rustc_hir
::
def_id
::{
DefId
,
LOCAL_CRATE
};
use
rustc_hir
::
intravisit
::{
self
,
NestedVisitorMap
,
Visitor
};
use
rustc_hir
::{
def
,
Arm
,
BindingAnnotation
,
Block
,
Body
,
Constness
,
CrateItem
,
Expr
,
ExprKind
,
F
nDecl
,
ForeignItem
,
GenericArgs
,
Generic
Param
,
HirId
,
Impl
,
ImplItem
,
ImplItemKind
,
Item
,
ItemKind
,
LangItem
,
Lifetime
,
Local
,
MacroDef
,
Ma
tchSource
,
Node
,
Param
,
Pat
,
PatKind
,
Path
,
PathSegment
,
QPath
,
Stmt
,
StructField
,
TraitItem
,
TraitItemKind
,
def
,
Arm
,
BindingAnnotation
,
Block
,
Body
,
Constness
,
CrateItem
,
Expr
,
ExprKind
,
F
ieldDef
,
FnDecl
,
ForeignItem
,
Generic
Args
,
GenericParam
,
HirId
,
Impl
,
ImplItem
,
ImplItemKind
,
Item
,
ItemKind
,
LangItem
,
Lifetime
,
Local
,
Ma
croDef
,
MatchSource
,
Node
,
Param
,
Pat
,
PatKind
,
Path
,
PathSegment
,
QPath
,
Stmt
,
TraitItem
,
TraitItemKind
,
TraitRef
,
TyKind
,
Variant
,
Visibility
,
};
use
rustc_lint
::{
LateContext
,
Level
,
Lint
,
LintContext
};
...
...
@@ -722,7 +721,7 @@ pub fn get_node_span(node: Node<'_>) -> Option<Span> {
|
Node
::
TraitItem
(
TraitItem
{
span
,
..
})
|
Node
::
ImplItem
(
ImplItem
{
span
,
..
})
|
Node
::
Variant
(
Variant
{
span
,
..
})
|
Node
::
Field
(
StructField
{
span
,
..
})
|
Node
::
Field
(
FieldDef
{
span
,
..
})
|
Node
::
Expr
(
Expr
{
span
,
..
})
|
Node
::
Stmt
(
Stmt
{
span
,
..
})
|
Node
::
PathSegment
(
PathSegment
{
...
...
clippy_utils/src/usage.rs
浏览文件 @
0e879185
...
...
@@ -8,6 +8,7 @@
use
rustc_infer
::
infer
::
TyCtxtInferExt
;
use
rustc_lint
::
LateContext
;
use
rustc_middle
::
hir
::
map
::
Map
;
use
rustc_middle
::
mir
::
FakeReadCause
;
use
rustc_middle
::
ty
;
use
rustc_typeck
::
expr_use_visitor
::{
ConsumeMode
,
Delegate
,
ExprUseVisitor
,
PlaceBase
,
PlaceWithHirId
};
...
...
@@ -77,6 +78,8 @@ fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind) {
fn
mutate
(
&
mut
self
,
cmt
:
&
PlaceWithHirId
<
'tcx
>
,
_
:
HirId
)
{
self
.update
(
&
cmt
)
}
fn
fake_read
(
&
mut
self
,
_
:
rustc_typeck
::
expr_use_visitor
::
Place
<
'tcx
>
,
_
:
FakeReadCause
,
_
:
HirId
)
{}
}
pub
struct
ParamBindingIdCollector
{
...
...
rust-toolchain
浏览文件 @
0e879185
[toolchain]
channel = "nightly-2021-03-
11
"
channel = "nightly-2021-03-
25
"
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
src/driver.rs
浏览文件 @
0e879185
...
...
@@ -15,7 +15,7 @@
extern
crate
rustc_span
;
use
rustc_interface
::
interface
;
use
rustc_session
::
Session
;
use
rustc_session
::
parse
::
ParseSess
;
use
rustc_span
::
symbol
::
Symbol
;
use
rustc_tools_util
::
VersionInfo
;
...
...
@@ -63,8 +63,8 @@ fn test_arg_value() {
assert_eq!
(
arg_value
(
args
,
"--foo"
,
|
_
|
true
),
None
);
}
fn
track_clippy_args
(
sess
:
&
Session
,
args_env_var
:
&
Option
<
String
>
)
{
sess
.parse_sess.env_depinfo
.borrow
_mut
()
.insert
((
fn
track_clippy_args
(
parse_sess
:
&
mut
ParseSess
,
args_env_var
:
&
Option
<
String
>
)
{
parse_sess
.env_depinfo
.get
_mut
()
.insert
((
Symbol
::
intern
(
"CLIPPY_ARGS"
),
args_env_var
.as_deref
()
.map
(
Symbol
::
intern
),
));
...
...
@@ -81,14 +81,9 @@ struct RustcCallbacks {
impl
rustc_driver
::
Callbacks
for
RustcCallbacks
{
fn
config
(
&
mut
self
,
config
:
&
mut
interface
::
Config
)
{
let
previous
=
config
.register_lints
.take
();
let
clippy_args_var
=
self
.clippy_args_var
.take
();
config
.register_lints
=
Some
(
Box
::
new
(
move
|
sess
,
lint_store
|
{
if
let
Some
(
ref
previous
)
=
previous
{
(
previous
)(
sess
,
lint_store
);
}
track_clippy_args
(
sess
,
&
clippy_args_var
);
config
.parse_sess_created
=
Some
(
Box
::
new
(
move
|
parse_sess
|
{
track_clippy_args
(
parse_sess
,
&
clippy_args_var
);
}));
}
}
...
...
@@ -101,6 +96,9 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
fn
config
(
&
mut
self
,
config
:
&
mut
interface
::
Config
)
{
let
previous
=
config
.register_lints
.take
();
let
clippy_args_var
=
self
.clippy_args_var
.take
();
config
.parse_sess_created
=
Some
(
Box
::
new
(
move
|
parse_sess
|
{
track_clippy_args
(
parse_sess
,
&
clippy_args_var
);
}));
config
.register_lints
=
Some
(
Box
::
new
(
move
|
sess
,
mut
lint_store
|
{
// technically we're ~guaranteed that this is none but might as well call anything that
// is there already. Certainly it can't hurt.
...
...
@@ -108,8 +106,6 @@ fn config(&mut self, config: &mut interface::Config) {
(
previous
)(
sess
,
lint_store
);
}
track_clippy_args
(
sess
,
&
clippy_args_var
);
let
conf
=
clippy_lints
::
read_conf
(
&
[],
&
sess
);
clippy_lints
::
register_plugins
(
&
mut
lint_store
,
&
sess
,
&
conf
);
clippy_lints
::
register_pre_expansion_lints
(
&
mut
lint_store
);
...
...
tests/ui/unnested_or_patterns.fixed
浏览文件 @
0e879185
// run-rustfix
#![feature(or_patterns)]
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
...
...
tests/ui/unnested_or_patterns.rs
浏览文件 @
0e879185
// run-rustfix
#![feature(or_patterns)]
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity,
clippy::match_ref_pats,
clippy::upper_case_acronyms)]
...
...
tests/ui/unnested_or_patterns.stderr
浏览文件 @
0e879185
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:
10
:12
--> $DIR/unnested_or_patterns.rs:
9
:12
|
LL | if let box 0 | box 2 = Box::new(0) {}
| ^^^^^^^^^^^^^
...
...
@@ -11,7 +11,7 @@ LL | if let box (0 | 2) = Box::new(0) {}
| ^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:1
1
:12
--> $DIR/unnested_or_patterns.rs:1
0
:12
|
LL | if let box ((0 | 1)) | box (2 | 3) | box 4 = Box::new(0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -22,7 +22,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:1
3
:12
--> $DIR/unnested_or_patterns.rs:1
2
:12
|
LL | if let &0 | C0 | &2 = &0 {}
| ^^^^^^^^^^^^
...
...
@@ -33,7 +33,7 @@ LL | if let &(0 | 2) | C0 = &0 {}
| ^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:1
4
:12
--> $DIR/unnested_or_patterns.rs:1
3
:12
|
LL | if let &mut 0 | &mut 2 = &mut 0 {}
| ^^^^^^^^^^^^^^^
...
...
@@ -44,7 +44,7 @@ LL | if let &mut (0 | 2) = &mut 0 {}
| ^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:1
5
:12
--> $DIR/unnested_or_patterns.rs:1
4
:12
|
LL | if let x @ 0 | x @ 2 = 0 {}
| ^^^^^^^^^^^^^
...
...
@@ -55,7 +55,7 @@ LL | if let x @ (0 | 2) = 0 {}
| ^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:1
6
:12
--> $DIR/unnested_or_patterns.rs:1
5
:12
|
LL | if let (0, 1) | (0, 2) | (0, 3) = (0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -66,7 +66,7 @@ LL | if let (0, 1 | 2 | 3) = (0, 0) {}
| ^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:1
7
:12
--> $DIR/unnested_or_patterns.rs:1
6
:12
|
LL | if let (1, 0) | (2, 0) | (3, 0) = (0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -77,7 +77,7 @@ LL | if let (1 | 2 | 3, 0) = (0, 0) {}
| ^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:1
8
:12
--> $DIR/unnested_or_patterns.rs:1
7
:12
|
LL | if let (x, ..) | (x, 1) | (x, 2) = (0, 1) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -88,7 +88,7 @@ LL | if let (x, ..) | (x, 1 | 2) = (0, 1) {}
| ^^^^^^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:1
9
:12
--> $DIR/unnested_or_patterns.rs:1
8
:12
|
LL | if let [0] | [1] = [0] {}
| ^^^^^^^^^
...
...
@@ -99,7 +99,7 @@ LL | if let [0 | 1] = [0] {}
| ^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:
20
:12
--> $DIR/unnested_or_patterns.rs:
19
:12
|
LL | if let [x, 0] | [x, 1] = [0, 1] {}
| ^^^^^^^^^^^^^^^
...
...
@@ -110,7 +110,7 @@ LL | if let [x, 0 | 1] = [0, 1] {}
| ^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:2
1
:12
--> $DIR/unnested_or_patterns.rs:2
0
:12
|
LL | if let [x, 0] | [x, 1] | [x, 2] = [0, 1] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -121,7 +121,7 @@ LL | if let [x, 0 | 1 | 2] = [0, 1] {}
| ^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:2
2
:12
--> $DIR/unnested_or_patterns.rs:2
1
:12
|
LL | if let [x, ..] | [x, 1] | [x, 2] = [0, 1] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -132,7 +132,7 @@ LL | if let [x, ..] | [x, 1 | 2] = [0, 1] {}
| ^^^^^^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:2
4
:12
--> $DIR/unnested_or_patterns.rs:2
3
:12
|
LL | if let TS(0, x) | TS(1, x) = TS(0, 0) {}
| ^^^^^^^^^^^^^^^^^^^
...
...
@@ -143,7 +143,7 @@ LL | if let TS(0 | 1, x) = TS(0, 0) {}
| ^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:2
5
:12
--> $DIR/unnested_or_patterns.rs:2
4
:12
|
LL | if let TS(1, 0) | TS(2, 0) | TS(3, 0) = TS(0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -154,7 +154,7 @@ LL | if let TS(1 | 2 | 3, 0) = TS(0, 0) {}
| ^^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:2
6
:12
--> $DIR/unnested_or_patterns.rs:2
5
:12
|
LL | if let TS(x, ..) | TS(x, 1) | TS(x, 2) = TS(0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -165,7 +165,7 @@ LL | if let TS(x, ..) | TS(x, 1 | 2) = TS(0, 0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns.rs:3
1
:12
--> $DIR/unnested_or_patterns.rs:3
0
:12
|
LL | if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
tests/ui/unnested_or_patterns2.fixed
浏览文件 @
0e879185
// run-rustfix
#![feature(or_patterns)]
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats)]
...
...
tests/ui/unnested_or_patterns2.rs
浏览文件 @
0e879185
// run-rustfix
#![feature(or_patterns)]
#![feature(box_patterns)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity,
clippy::match_ref_pats)]
...
...
tests/ui/unnested_or_patterns2.stderr
浏览文件 @
0e879185
error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:
10
:12
--> $DIR/unnested_or_patterns2.rs:
9
:12
|
LL | if let Some(Some(0)) | Some(Some(1)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -11,7 +11,7 @@ LL | if let Some(Some(0 | 1)) = None {}
| ^^^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:1
1
:12
--> $DIR/unnested_or_patterns2.rs:1
0
:12
|
LL | if let Some(Some(0)) | Some(Some(1) | Some(2)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -22,7 +22,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:1
2
:12
--> $DIR/unnested_or_patterns2.rs:1
1
:12
|
LL | if let Some(Some(0 | 1) | Some(2)) | Some(Some(3) | Some(4)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -33,7 +33,7 @@ LL | if let Some(Some(0 | 1 | 2 | 3 | 4)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:1
3
:12
--> $DIR/unnested_or_patterns2.rs:1
2
:12
|
LL | if let Some(Some(0) | Some(1 | 2)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -44,7 +44,7 @@ LL | if let Some(Some(0 | 1 | 2)) = None {}
| ^^^^^^^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:1
4
:12
--> $DIR/unnested_or_patterns2.rs:1
3
:12
|
LL | if let ((0,),) | ((1,) | (2,),) = ((0,),) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -55,7 +55,7 @@ LL | if let ((0 | 1 | 2,),) = ((0,),) {}
| ^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:1
5
:12
--> $DIR/unnested_or_patterns2.rs:1
4
:12
|
LL | if let 0 | (1 | 2) = 0 {}
| ^^^^^^^^^^^
...
...
@@ -66,7 +66,7 @@ LL | if let 0 | 1 | 2 = 0 {}
| ^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:1
6
:12
--> $DIR/unnested_or_patterns2.rs:1
5
:12
|
LL | if let box (0 | 1) | (box 2 | box (3 | 4)) = Box::new(0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -77,7 +77,7 @@ LL | if let box (0 | 1 | 2 | 3 | 4) = Box::new(0) {}
| ^^^^^^^^^^^^^^^^^^^^^^^
error: unnested or-patterns
--> $DIR/unnested_or_patterns2.rs:1
7
:12
--> $DIR/unnested_or_patterns2.rs:1
6
:12
|
LL | if let box box 0 | box (box 2 | box 4) = Box::new(Box::new(0)) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
tests/ui/unnested_or_patterns3.rs
已删除
100644 → 0
浏览文件 @
981ffa7c
#![warn(clippy::unnested_or_patterns)]
// Test that `unnested_or_patterns` does not trigger without enabling `or_patterns`
fn
main
()
{
if
let
(
0
,
1
)
|
(
0
,
2
)
|
(
0
,
3
)
=
(
0
,
0
)
{}
}
tests/ui/use_self.fixed
浏览文件 @
0e879185
...
...
@@ -312,17 +312,18 @@ mod issue4140 {
fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>;
}
impl<F, T> TryFrom<F> for T
where
T: From<F>,
{
type From = Self;
type To = Self;
fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
Ok(From::from(value))
}
}
// FIXME: Suggested fix results in infinite recursion.
// impl<F, T> TryFrom<F> for T
// where
// T: From<F>,
// {
// type From = Self::From;
// type To = Self::To;
// fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
// Ok(From::from(value))
// }
// }
impl From<bool> for i64 {
type From = bool;
...
...
tests/ui/use_self.rs
浏览文件 @
0e879185
...
...
@@ -312,17 +312,18 @@ pub trait TryFrom<T>
fn
try_from
(
value
:
T
)
->
Result
<
Self
,
Error
<
Self
::
From
,
Self
::
To
>>
;
}
impl
<
F
,
T
>
TryFrom
<
F
>
for
T
where
T
:
From
<
F
>
,
{
type
From
=
T
::
From
;
type
To
=
T
::
To
;
fn
try_from
(
value
:
F
)
->
Result
<
Self
,
Error
<
Self
::
From
,
Self
::
To
>>
{
Ok
(
From
::
from
(
value
))
}
}
// FIXME: Suggested fix results in infinite recursion.
// impl<F, T> TryFrom<F> for T
// where
// T: From<F>,
// {
// type From = Self::From;
// type To = Self::To;
// fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
// Ok(From::from(value))
// }
// }
impl
From
<
bool
>
for
i64
{
type
From
=
bool
;
...
...
tests/ui/use_self.stderr
浏览文件 @
0e879185
...
...
@@ -157,22 +157,10 @@ LL | Foo { value }
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:319:21
|
LL | type From = T::From;
| ^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:320:19
|
LL | type To = T::To;
| ^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:453:13
--> $DIR/use_self.rs:454:13
|
LL | A::new::<submod::B>(submod::B {})
| ^ help: use the applicable keyword: `Self`
error: aborting due to 2
9
previous errors
error: aborting due to 2
7
previous errors
tests/ui/while_let_on_iterator.fixed
浏览文件 @
0e879185
...
...
@@ -2,7 +2,6 @@
#![warn(clippy::while_let_on_iterator)]
#![allow(clippy::never_loop, unreachable_code, unused_mut)]
#![feature(or_patterns)]
fn base() {
let mut iter = 1..20;
...
...
tests/ui/while_let_on_iterator.rs
浏览文件 @
0e879185
...
...
@@ -2,7 +2,6 @@
#![warn(clippy::while_let_on_iterator)]
#![allow(clippy::never_loop,
unreachable_code,
unused_mut)]
#![feature(or_patterns)]
fn
base
()
{
let
mut
iter
=
1
..
20
;
...
...
tests/ui/while_let_on_iterator.stderr
浏览文件 @
0e879185
error: this loop could be written as a `for` loop
--> $DIR/while_let_on_iterator.rs:
9
:5
--> $DIR/while_let_on_iterator.rs:
8
:5
|
LL | while let Option::Some(x) = iter.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter`
...
...
@@ -7,37 +7,37 @@ LL | while let Option::Some(x) = iter.next() {
= note: `-D clippy::while-let-on-iterator` implied by `-D warnings`
error: this loop could be written as a `for` loop
--> $DIR/while_let_on_iterator.rs:1
4
:5
--> $DIR/while_let_on_iterator.rs:1
3
:5
|
LL | while let Some(x) = iter.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter`
error: this loop could be written as a `for` loop
--> $DIR/while_let_on_iterator.rs:1
9
:5
--> $DIR/while_let_on_iterator.rs:1
8
:5
|
LL | while let Some(_) = iter.next() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in iter`
error: this loop could be written as a `for` loop
--> $DIR/while_let_on_iterator.rs:10
2
:9
--> $DIR/while_let_on_iterator.rs:10
1
:9
|
LL | while let Some([..]) = it.next() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [..] in it`
error: this loop could be written as a `for` loop
--> $DIR/while_let_on_iterator.rs:10
9
:9
--> $DIR/while_let_on_iterator.rs:10
8
:9
|
LL | while let Some([_x]) = it.next() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [_x] in it`
error: this loop could be written as a `for` loop
--> $DIR/while_let_on_iterator.rs:12
2
:9
--> $DIR/while_let_on_iterator.rs:12
1
:9
|
LL | while let Some(x @ [_]) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x @ [_] in it`
error: this loop could be written as a `for` loop
--> $DIR/while_let_on_iterator.rs:15
4
:9
--> $DIR/while_let_on_iterator.rs:15
3
:9
|
LL | while let Some(_) = y.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in y`
...
...
tests/ui/zero_sized_btreemap_values.stderr
浏览文件 @
0e879185
...
...
@@ -83,7 +83,7 @@ error: map with zero-sized value type
--> $DIR/zero_sized_btreemap_values.rs:64:35
|
LL | let _: BTreeMap<String, ()> = BTreeMap::new();
| ^^^^^^^^
^^^^^
| ^^^^^^^^
|
= help: consider using a set instead
...
...
tests/ui/zero_sized_hashmap_values.stderr
浏览文件 @
0e879185
...
...
@@ -83,7 +83,7 @@ error: map with zero-sized value type
--> $DIR/zero_sized_hashmap_values.rs:64:34
|
LL | let _: HashMap<String, ()> = HashMap::new();
| ^^^^^^^
^^^^^
| ^^^^^^^
|
= help: consider using a set instead
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录