Merge remote-tracking branch 'upstream/master' into rustup
This commit is contained in:
commit
5f031561ef
139 changed files with 2370 additions and 884 deletions
5
tests/ui/author/macro_in_closure.rs
Normal file
5
tests/ui/author/macro_in_closure.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
fn main() {
|
||||
#[clippy::author]
|
||||
let print_text = |x| println!("{}", x);
|
||||
print_text("hello");
|
||||
}
|
||||
39
tests/ui/author/macro_in_closure.stdout
Normal file
39
tests/ui/author/macro_in_closure.stdout
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
if let StmtKind::Local(local) = stmt.kind
|
||||
&& let Some(init) = local.init
|
||||
&& let ExprKind::Closure(CaptureBy::Ref, fn_decl, body_id, _, None) = init.kind
|
||||
&& let FnRetTy::DefaultReturn(_) = fn_decl.output
|
||||
&& expr = &cx.tcx.hir().body(body_id).value
|
||||
&& let ExprKind::Block(block, None) = expr.kind
|
||||
&& block.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e) = block.stmts[0].kind
|
||||
&& let ExprKind::Call(func, args) = e.kind
|
||||
&& let ExprKind::Path(ref qpath) = func.kind
|
||||
&& match_qpath(qpath, &["$crate", "io", "_print"])
|
||||
&& args.len() == 1
|
||||
&& let ExprKind::Call(func1, args1) = args[0].kind
|
||||
&& let ExprKind::Path(ref qpath1) = func1.kind
|
||||
&& args1.len() == 2
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind
|
||||
&& let ExprKind::Array(elements) = inner.kind
|
||||
&& elements.len() == 2
|
||||
&& let ExprKind::Lit(ref lit) = elements[0].kind
|
||||
&& let LitKind::Str(s, _) = lit.node
|
||||
&& s.as_str() == ""
|
||||
&& let ExprKind::Lit(ref lit1) = elements[1].kind
|
||||
&& let LitKind::Str(s1, _) = lit1.node
|
||||
&& s1.as_str() == "\n"
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args1[1].kind
|
||||
&& let ExprKind::Array(elements1) = inner1.kind
|
||||
&& elements1.len() == 1
|
||||
&& let ExprKind::Call(func2, args2) = elements1[0].kind
|
||||
&& let ExprKind::Path(ref qpath2) = func2.kind
|
||||
&& args2.len() == 1
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind
|
||||
&& let ExprKind::Path(ref qpath3) = inner2.kind
|
||||
&& match_qpath(qpath3, &["x"])
|
||||
&& block.expr.is_none()
|
||||
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind
|
||||
&& name.as_str() == "print_text"
|
||||
{
|
||||
// report your lint here
|
||||
}
|
||||
8
tests/ui/author/macro_in_loop.rs
Normal file
8
tests/ui/author/macro_in_loop.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
fn main() {
|
||||
#[clippy::author]
|
||||
for i in 0..1 {
|
||||
println!("{}", i);
|
||||
}
|
||||
}
|
||||
48
tests/ui/author/macro_in_loop.stdout
Normal file
48
tests/ui/author/macro_in_loop.stdout
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr)
|
||||
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind
|
||||
&& name.as_str() == "i"
|
||||
&& let ExprKind::Struct(qpath, fields, None) = arg.kind
|
||||
&& matches!(qpath, QPath::LangItem(LangItem::Range, _))
|
||||
&& fields.len() == 2
|
||||
&& fields[0].ident.as_str() == "start"
|
||||
&& let ExprKind::Lit(ref lit) = fields[0].expr.kind
|
||||
&& let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node
|
||||
&& fields[1].ident.as_str() == "end"
|
||||
&& let ExprKind::Lit(ref lit1) = fields[1].expr.kind
|
||||
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node
|
||||
&& let ExprKind::Block(block, None) = body.kind
|
||||
&& block.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e) = block.stmts[0].kind
|
||||
&& let ExprKind::Block(block1, None) = e.kind
|
||||
&& block1.stmts.len() == 1
|
||||
&& let StmtKind::Semi(e1) = block1.stmts[0].kind
|
||||
&& let ExprKind::Call(func, args) = e1.kind
|
||||
&& let ExprKind::Path(ref qpath1) = func.kind
|
||||
&& match_qpath(qpath1, &["$crate", "io", "_print"])
|
||||
&& args.len() == 1
|
||||
&& let ExprKind::Call(func1, args1) = args[0].kind
|
||||
&& let ExprKind::Path(ref qpath2) = func1.kind
|
||||
&& args1.len() == 2
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind
|
||||
&& let ExprKind::Array(elements) = inner.kind
|
||||
&& elements.len() == 2
|
||||
&& let ExprKind::Lit(ref lit2) = elements[0].kind
|
||||
&& let LitKind::Str(s, _) = lit2.node
|
||||
&& s.as_str() == ""
|
||||
&& let ExprKind::Lit(ref lit3) = elements[1].kind
|
||||
&& let LitKind::Str(s1, _) = lit3.node
|
||||
&& s1.as_str() == "\n"
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args1[1].kind
|
||||
&& let ExprKind::Array(elements1) = inner1.kind
|
||||
&& elements1.len() == 1
|
||||
&& let ExprKind::Call(func2, args2) = elements1[0].kind
|
||||
&& let ExprKind::Path(ref qpath3) = func2.kind
|
||||
&& args2.len() == 1
|
||||
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind
|
||||
&& let ExprKind::Path(ref qpath4) = inner2.kind
|
||||
&& match_qpath(qpath4, &["i"])
|
||||
&& block1.expr.is_none()
|
||||
&& block.expr.is_none()
|
||||
{
|
||||
// report your lint here
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
#![allow(clippy::non_canonical_clone_impl, clippy::non_canonical_partial_ord_impl, dead_code)]
|
||||
#![warn(clippy::expl_impl_clone_on_copy)]
|
||||
|
||||
|
||||
#[derive(Copy)]
|
||||
struct Qux;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> $DIR/derive.rs:8:1
|
||||
--> $DIR/derive.rs:7:1
|
||||
|
|
||||
LL | / impl Clone for Qux {
|
||||
LL | |
|
||||
|
|
@ -10,7 +10,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> $DIR/derive.rs:8:1
|
||||
--> $DIR/derive.rs:7:1
|
||||
|
|
||||
LL | / impl Clone for Qux {
|
||||
LL | |
|
||||
|
|
@ -23,7 +23,7 @@ LL | | }
|
|||
= help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]`
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> $DIR/derive.rs:33:1
|
||||
--> $DIR/derive.rs:32:1
|
||||
|
|
||||
LL | / impl<'a> Clone for Lt<'a> {
|
||||
LL | |
|
||||
|
|
@ -34,7 +34,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> $DIR/derive.rs:33:1
|
||||
--> $DIR/derive.rs:32:1
|
||||
|
|
||||
LL | / impl<'a> Clone for Lt<'a> {
|
||||
LL | |
|
||||
|
|
@ -45,7 +45,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> $DIR/derive.rs:45:1
|
||||
--> $DIR/derive.rs:44:1
|
||||
|
|
||||
LL | / impl Clone for BigArray {
|
||||
LL | |
|
||||
|
|
@ -56,7 +56,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> $DIR/derive.rs:45:1
|
||||
--> $DIR/derive.rs:44:1
|
||||
|
|
||||
LL | / impl Clone for BigArray {
|
||||
LL | |
|
||||
|
|
@ -67,7 +67,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> $DIR/derive.rs:57:1
|
||||
--> $DIR/derive.rs:56:1
|
||||
|
|
||||
LL | / impl Clone for FnPtr {
|
||||
LL | |
|
||||
|
|
@ -78,7 +78,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> $DIR/derive.rs:57:1
|
||||
--> $DIR/derive.rs:56:1
|
||||
|
|
||||
LL | / impl Clone for FnPtr {
|
||||
LL | |
|
||||
|
|
@ -89,7 +89,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: you are implementing `Clone` explicitly on a `Copy` type
|
||||
--> $DIR/derive.rs:78:1
|
||||
--> $DIR/derive.rs:77:1
|
||||
|
|
||||
LL | / impl<T: Clone> Clone for Generic2<T> {
|
||||
LL | |
|
||||
|
|
@ -100,7 +100,7 @@ LL | | }
|
|||
| |_^
|
||||
|
|
||||
note: consider deriving `Clone` or removing `Copy`
|
||||
--> $DIR/derive.rs:78:1
|
||||
--> $DIR/derive.rs:77:1
|
||||
|
|
||||
LL | / impl<T: Clone> Clone for Generic2<T> {
|
||||
LL | |
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ mod rustc_ok {
|
|||
|
||||
#[expect(illegal_floating_point_literal_pattern)]
|
||||
match x {
|
||||
5.0 => {}
|
||||
6.0 => {}
|
||||
_ => {}
|
||||
5.0 => {},
|
||||
6.0 => {},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,9 +41,9 @@ mod rustc_warn {
|
|||
#[expect(illegal_floating_point_literal_pattern)]
|
||||
//~^ ERROR: this lint expectation is unfulfilled
|
||||
match x {
|
||||
5 => {}
|
||||
6 => {}
|
||||
_ => {}
|
||||
5 => {},
|
||||
6 => {},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,17 +14,20 @@ impl Bar {
|
|||
|
||||
fn main() {
|
||||
let x = vec![2, 3, 5];
|
||||
let _ = x.first(); // Use x.first()
|
||||
let _ = x.first();
|
||||
//~^ ERROR: accessing first element with `x.get(0)`
|
||||
let _ = x.get(1);
|
||||
let _ = x[0];
|
||||
|
||||
let y = [2, 3, 5];
|
||||
let _ = y.first(); // Use y.first()
|
||||
let _ = y.first();
|
||||
//~^ ERROR: accessing first element with `y.get(0)`
|
||||
let _ = y.get(1);
|
||||
let _ = y[0];
|
||||
|
||||
let z = &[2, 3, 5];
|
||||
let _ = z.first(); // Use z.first()
|
||||
let _ = z.first();
|
||||
//~^ ERROR: accessing first element with `z.get(0)`
|
||||
let _ = z.get(1);
|
||||
let _ = z[0];
|
||||
|
||||
|
|
@ -37,4 +40,8 @@ fn main() {
|
|||
|
||||
let bar = Bar { arr: [0, 1, 2] };
|
||||
let _ = bar.get(0); // Do not lint, because Bar is struct.
|
||||
|
||||
let non_primitives = [vec![1, 2], vec![3, 4]];
|
||||
let _ = non_primitives.first();
|
||||
//~^ ERROR: accessing first element with `non_primitives.get(0)`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,17 +14,20 @@ impl Bar {
|
|||
|
||||
fn main() {
|
||||
let x = vec![2, 3, 5];
|
||||
let _ = x.get(0); // Use x.first()
|
||||
let _ = x.get(0);
|
||||
//~^ ERROR: accessing first element with `x.get(0)`
|
||||
let _ = x.get(1);
|
||||
let _ = x[0];
|
||||
|
||||
let y = [2, 3, 5];
|
||||
let _ = y.get(0); // Use y.first()
|
||||
let _ = y.get(0);
|
||||
//~^ ERROR: accessing first element with `y.get(0)`
|
||||
let _ = y.get(1);
|
||||
let _ = y[0];
|
||||
|
||||
let z = &[2, 3, 5];
|
||||
let _ = z.get(0); // Use z.first()
|
||||
let _ = z.get(0);
|
||||
//~^ ERROR: accessing first element with `z.get(0)`
|
||||
let _ = z.get(1);
|
||||
let _ = z[0];
|
||||
|
||||
|
|
@ -37,4 +40,8 @@ fn main() {
|
|||
|
||||
let bar = Bar { arr: [0, 1, 2] };
|
||||
let _ = bar.get(0); // Do not lint, because Bar is struct.
|
||||
|
||||
let non_primitives = [vec![1, 2], vec![3, 4]];
|
||||
let _ = non_primitives.get(0);
|
||||
//~^ ERROR: accessing first element with `non_primitives.get(0)`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,29 @@
|
|||
error: accessing first element with `x.get(0)`
|
||||
--> $DIR/get_first.rs:17:13
|
||||
|
|
||||
LL | let _ = x.get(0); // Use x.first()
|
||||
LL | let _ = x.get(0);
|
||||
| ^^^^^^^^ help: try: `x.first()`
|
||||
|
|
||||
= note: `-D clippy::get-first` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::get_first)]`
|
||||
|
||||
error: accessing first element with `y.get(0)`
|
||||
--> $DIR/get_first.rs:22:13
|
||||
--> $DIR/get_first.rs:23:13
|
||||
|
|
||||
LL | let _ = y.get(0); // Use y.first()
|
||||
LL | let _ = y.get(0);
|
||||
| ^^^^^^^^ help: try: `y.first()`
|
||||
|
||||
error: accessing first element with `z.get(0)`
|
||||
--> $DIR/get_first.rs:27:13
|
||||
--> $DIR/get_first.rs:29:13
|
||||
|
|
||||
LL | let _ = z.get(0); // Use z.first()
|
||||
LL | let _ = z.get(0);
|
||||
| ^^^^^^^^ help: try: `z.first()`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: accessing first element with `non_primitives.get(0)`
|
||||
--> $DIR/get_first.rs:45:13
|
||||
|
|
||||
LL | let _ = non_primitives.get(0);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `non_primitives.first()`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,47 @@
|
|||
#![allow(unused)]
|
||||
#![warn(clippy::impl_trait_in_params)]
|
||||
|
||||
//@no-rustfix
|
||||
pub trait Trait {}
|
||||
pub trait AnotherTrait<T> {}
|
||||
|
||||
// Should warn
|
||||
pub fn a(_: impl Trait) {}
|
||||
//~^ ERROR: '`impl Trait` used as a function parameter'
|
||||
//~| NOTE: `-D clippy::impl-trait-in-params` implied by `-D warnings`
|
||||
//~^ ERROR: `impl Trait` used as a function parameter
|
||||
pub fn c<C: Trait>(_: C, _: impl Trait) {}
|
||||
//~^ ERROR: '`impl Trait` used as a function parameter'
|
||||
fn d(_: impl AnotherTrait<u32>) {}
|
||||
//~^ ERROR: `impl Trait` used as a function parameter
|
||||
|
||||
// Shouldn't warn
|
||||
|
||||
pub fn b<B: Trait>(_: B) {}
|
||||
fn e<T: AnotherTrait<u32>>(_: T) {}
|
||||
fn d(_: impl AnotherTrait<u32>) {}
|
||||
|
||||
//------ IMPLS
|
||||
|
||||
pub trait Public {
|
||||
// See test in ui-toml for a case where avoid-breaking-exported-api is set to false
|
||||
fn t(_: impl Trait);
|
||||
fn tt<T: Trait>(_: T) {}
|
||||
}
|
||||
|
||||
trait Private {
|
||||
// This shouldn't lint
|
||||
fn t(_: impl Trait);
|
||||
fn tt<T: Trait>(_: T) {}
|
||||
}
|
||||
|
||||
struct S;
|
||||
impl S {
|
||||
pub fn h(_: impl Trait) {} //~ ERROR: `impl Trait` used as a function parameter
|
||||
fn i(_: impl Trait) {}
|
||||
pub fn j<J: Trait>(_: J) {}
|
||||
pub fn k<K: AnotherTrait<u32>>(_: K, _: impl AnotherTrait<u32>) {} //~ ERROR: `impl Trait` used as a function parameter
|
||||
}
|
||||
|
||||
// Trying with traits
|
||||
impl Public for S {
|
||||
fn t(_: impl Trait) {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: '`impl Trait` used as a function parameter'
|
||||
--> $DIR/impl_trait_in_params.rs:8:13
|
||||
error: `impl Trait` used as a function parameter
|
||||
--> $DIR/impl_trait_in_params.rs:9:13
|
||||
|
|
||||
LL | pub fn a(_: impl Trait) {}
|
||||
| ^^^^^^^^^^
|
||||
|
|
@ -11,7 +11,7 @@ help: add a type parameter
|
|||
LL | pub fn a<{ /* Generic name */ }: Trait>(_: impl Trait) {}
|
||||
| +++++++++++++++++++++++++++++++
|
||||
|
||||
error: '`impl Trait` used as a function parameter'
|
||||
error: `impl Trait` used as a function parameter
|
||||
--> $DIR/impl_trait_in_params.rs:11:29
|
||||
|
|
||||
LL | pub fn c<C: Trait>(_: C, _: impl Trait) {}
|
||||
|
|
@ -22,5 +22,27 @@ help: add a type parameter
|
|||
LL | pub fn c<C: Trait, { /* Generic name */ }: Trait>(_: C, _: impl Trait) {}
|
||||
| +++++++++++++++++++++++++++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: `impl Trait` used as a function parameter
|
||||
--> $DIR/impl_trait_in_params.rs:36:17
|
||||
|
|
||||
LL | pub fn h(_: impl Trait) {}
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: add a type parameter
|
||||
|
|
||||
LL | pub fn h<{ /* Generic name */ }: Trait>(_: impl Trait) {}
|
||||
| +++++++++++++++++++++++++++++++
|
||||
|
||||
error: `impl Trait` used as a function parameter
|
||||
--> $DIR/impl_trait_in_params.rs:39:45
|
||||
|
|
||||
LL | pub fn k<K: AnotherTrait<u32>>(_: K, _: impl AnotherTrait<u32>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add a type parameter
|
||||
|
|
||||
LL | pub fn k<K: AnotherTrait<u32>, { /* Generic name */ }: AnotherTrait<u32>>(_: K, _: impl AnotherTrait<u32>) {}
|
||||
| +++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -122,3 +122,37 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn issue11635() {
|
||||
// A little more involved than the original repro in the issue, but this tests that it correctly
|
||||
// works for more than one deref step
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
pub struct Thing(Vec<u8>);
|
||||
pub struct Thing2(Thing);
|
||||
|
||||
impl Deref for Thing {
|
||||
type Target = [u8];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Thing2 {
|
||||
type Target = Thing;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a Thing2 {
|
||||
type Item = &'a u8;
|
||||
type IntoIter = <&'a [u8] as IntoIterator>::IntoIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.iter()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#![warn(clippy::manual_filter_map)]
|
||||
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
|
||||
#![allow(clippy::useless_vec)]
|
||||
#![allow(clippy::struct_field_names)]
|
||||
|
||||
fn main() {
|
||||
// is_some(), unwrap()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#![warn(clippy::manual_filter_map)]
|
||||
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
|
||||
#![allow(clippy::useless_vec)]
|
||||
#![allow(clippy::struct_field_names)]
|
||||
|
||||
fn main() {
|
||||
// is_some(), unwrap()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:8:19
|
||||
--> $DIR/manual_filter_map.rs:9:19
|
||||
|
|
||||
LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_opt(a))`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_filter_map.rs:8:30
|
||||
--> $DIR/manual_filter_map.rs:9:30
|
||||
|
|
||||
LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap());
|
||||
| ^^^^^^^^^^
|
||||
|
|
@ -13,31 +13,31 @@ LL | let _ = (0..).filter(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap
|
|||
= help: to override `-D warnings` add `#[allow(clippy::manual_filter_map)]`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:11:19
|
||||
--> $DIR/manual_filter_map.rs:12:19
|
||||
|
|
||||
LL | let _ = (0..).filter(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi"));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_opt(a))`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_filter_map.rs:11:31
|
||||
--> $DIR/manual_filter_map.rs:12:31
|
||||
|
|
||||
LL | let _ = (0..).filter(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi"));
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:14:19
|
||||
--> $DIR/manual_filter_map.rs:15:19
|
||||
|
|
||||
LL | let _ = (0..).filter(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `filter_map(|a| to_res(a).ok())`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_filter_map.rs:14:31
|
||||
--> $DIR/manual_filter_map.rs:15:31
|
||||
|
|
||||
LL | let _ = (0..).filter(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1));
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:17:10
|
||||
--> $DIR/manual_filter_map.rs:18:10
|
||||
|
|
||||
LL | .filter(|&x| to_ref(to_opt(x)).is_some())
|
||||
| __________^
|
||||
|
|
@ -45,13 +45,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap());
|
|||
| |____________________________________________^ help: try: `filter_map(|y| *to_ref(to_opt(y)))`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_filter_map.rs:17:22
|
||||
--> $DIR/manual_filter_map.rs:18:22
|
||||
|
|
||||
LL | .filter(|&x| to_ref(to_opt(x)).is_some())
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:20:10
|
||||
--> $DIR/manual_filter_map.rs:21:10
|
||||
|
|
||||
LL | .filter(|x| to_ref(to_opt(*x)).is_some())
|
||||
| __________^
|
||||
|
|
@ -59,13 +59,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap());
|
|||
| |____________________________________________^ help: try: `filter_map(|y| *to_ref(to_opt(y)))`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_filter_map.rs:20:21
|
||||
--> $DIR/manual_filter_map.rs:21:21
|
||||
|
|
||||
LL | .filter(|x| to_ref(to_opt(*x)).is_some())
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:24:10
|
||||
--> $DIR/manual_filter_map.rs:25:10
|
||||
|
|
||||
LL | .filter(|&x| to_ref(to_res(x)).is_ok())
|
||||
| __________^
|
||||
|
|
@ -73,13 +73,13 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap());
|
|||
| |____________________________________________^ help: try: `filter_map(|y| to_ref(to_res(y)).ok())`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_filter_map.rs:24:22
|
||||
--> $DIR/manual_filter_map.rs:25:22
|
||||
|
|
||||
LL | .filter(|&x| to_ref(to_res(x)).is_ok())
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:27:10
|
||||
--> $DIR/manual_filter_map.rs:28:10
|
||||
|
|
||||
LL | .filter(|x| to_ref(to_res(*x)).is_ok())
|
||||
| __________^
|
||||
|
|
@ -87,13 +87,13 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap());
|
|||
| |____________________________________________^ help: try: `filter_map(|y| to_ref(to_res(y)).ok())`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_filter_map.rs:27:21
|
||||
--> $DIR/manual_filter_map.rs:28:21
|
||||
|
|
||||
LL | .filter(|x| to_ref(to_res(*x)).is_ok())
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:33:27
|
||||
--> $DIR/manual_filter_map.rs:34:27
|
||||
|
|
||||
LL | iter::<Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())`
|
||||
|
|
@ -102,79 +102,79 @@ LL | iter::<Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap()
|
|||
= help: to override `-D warnings` add `#[allow(clippy::manual_find_map)]`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:34:28
|
||||
--> $DIR/manual_filter_map.rs:35:28
|
||||
|
|
||||
LL | iter::<&Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:35:31
|
||||
--> $DIR/manual_filter_map.rs:36:31
|
||||
|
|
||||
LL | iter::<&Option<String>>().find(|x| x.is_some()).map(|x| x.as_deref().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:36:31
|
||||
--> $DIR/manual_filter_map.rs:37:31
|
||||
|
|
||||
LL | iter::<Option<&String>>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned())`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_filter_map.rs:36:41
|
||||
--> $DIR/manual_filter_map.rs:37:41
|
||||
|
|
||||
LL | iter::<Option<&String>>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap());
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:38:30
|
||||
--> $DIR/manual_filter_map.rs:39:30
|
||||
|
|
||||
LL | iter::<Result<u8, ()>>().find(|x| x.is_ok()).map(|x| x.unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:39:31
|
||||
--> $DIR/manual_filter_map.rs:40:31
|
||||
|
|
||||
LL | iter::<&Result<u8, ()>>().find(|x| x.is_ok()).map(|x| x.unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:40:32
|
||||
--> $DIR/manual_filter_map.rs:41:32
|
||||
|
|
||||
LL | iter::<&&Result<u8, ()>>().find(|x| x.is_ok()).map(|x| x.unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:41:31
|
||||
--> $DIR/manual_filter_map.rs:42:31
|
||||
|
|
||||
LL | iter::<Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:42:32
|
||||
--> $DIR/manual_filter_map.rs:43:32
|
||||
|
|
||||
LL | iter::<&Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:43:35
|
||||
--> $DIR/manual_filter_map.rs:44:35
|
||||
|
|
||||
LL | iter::<&Result<String, ()>>().find(|x| x.is_ok()).map(|x| x.as_deref().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:44:35
|
||||
--> $DIR/manual_filter_map.rs:45:35
|
||||
|
|
||||
LL | iter::<Result<&String, ()>>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned().ok())`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_filter_map.rs:44:45
|
||||
--> $DIR/manual_filter_map.rs:45:45
|
||||
|
|
||||
LL | iter::<Result<&String, ()>>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap());
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:92:10
|
||||
--> $DIR/manual_filter_map.rs:93:10
|
||||
|
|
||||
LL | .filter(|f| f.option_field.is_some())
|
||||
| __________^
|
||||
|
|
@ -182,7 +182,7 @@ LL | | .map(|f| f.option_field.clone().unwrap());
|
|||
| |_________________________________________________^ help: try: `filter_map(|f| f.option_field.clone())`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:97:10
|
||||
--> $DIR/manual_filter_map.rs:98:10
|
||||
|
|
||||
LL | .filter(|f| f.ref_field.is_some())
|
||||
| __________^
|
||||
|
|
@ -190,7 +190,7 @@ LL | | .map(|f| f.ref_field.cloned().unwrap());
|
|||
| |_______________________________________________^ help: try: `filter_map(|f| f.ref_field.cloned())`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:102:10
|
||||
--> $DIR/manual_filter_map.rs:103:10
|
||||
|
|
||||
LL | .filter(|f| f.ref_field.is_some())
|
||||
| __________^
|
||||
|
|
@ -198,7 +198,7 @@ LL | | .map(|f| f.ref_field.copied().unwrap());
|
|||
| |_______________________________________________^ help: try: `filter_map(|f| f.ref_field.copied())`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:107:10
|
||||
--> $DIR/manual_filter_map.rs:108:10
|
||||
|
|
||||
LL | .filter(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -206,7 +206,7 @@ LL | | .map(|f| f.result_field.clone().unwrap());
|
|||
| |_________________________________________________^ help: try: `filter_map(|f| f.result_field.clone().ok())`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:112:10
|
||||
--> $DIR/manual_filter_map.rs:113:10
|
||||
|
|
||||
LL | .filter(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -214,7 +214,7 @@ LL | | .map(|f| f.result_field.as_ref().unwrap());
|
|||
| |__________________________________________________^ help: try: `filter_map(|f| f.result_field.as_ref().ok())`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:117:10
|
||||
--> $DIR/manual_filter_map.rs:118:10
|
||||
|
|
||||
LL | .filter(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -222,7 +222,7 @@ LL | | .map(|f| f.result_field.as_deref().unwrap());
|
|||
| |____________________________________________________^ help: try: `filter_map(|f| f.result_field.as_deref().ok())`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:122:10
|
||||
--> $DIR/manual_filter_map.rs:123:10
|
||||
|
|
||||
LL | .filter(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -230,7 +230,7 @@ LL | | .map(|f| f.result_field.as_mut().unwrap());
|
|||
| |__________________________________________________^ help: try: `filter_map(|f| f.result_field.as_mut().ok())`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:127:10
|
||||
--> $DIR/manual_filter_map.rs:128:10
|
||||
|
|
||||
LL | .filter(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -238,7 +238,7 @@ LL | | .map(|f| f.result_field.as_deref_mut().unwrap());
|
|||
| |________________________________________________________^ help: try: `filter_map(|f| f.result_field.as_deref_mut().ok())`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:132:10
|
||||
--> $DIR/manual_filter_map.rs:133:10
|
||||
|
|
||||
LL | .filter(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -246,7 +246,7 @@ LL | | .map(|f| f.result_field.to_owned().unwrap());
|
|||
| |____________________________________________________^ help: try: `filter_map(|f| f.result_field.to_owned().ok())`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:145:27
|
||||
--> $DIR/manual_filter_map.rs:146:27
|
||||
|
|
||||
LL | let _x = iter.clone().filter(|x| matches!(x, Enum::A(_))).map(|x| match x {
|
||||
| ___________________________^
|
||||
|
|
@ -256,7 +256,7 @@ LL | | });
|
|||
| |______^ help: try: `filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })`
|
||||
|
||||
error: `filter(..).map(..)` can be simplified as `filter_map(..)`
|
||||
--> $DIR/manual_filter_map.rs:155:10
|
||||
--> $DIR/manual_filter_map.rs:156:10
|
||||
|
|
||||
LL | .filter(|x| matches!(x, Enum::A(_)))
|
||||
| __________^
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#![warn(clippy::manual_find_map)]
|
||||
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
|
||||
#![allow(clippy::useless_vec)]
|
||||
#![allow(clippy::struct_field_names)]
|
||||
|
||||
fn main() {
|
||||
// is_some(), unwrap()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#![warn(clippy::manual_find_map)]
|
||||
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure
|
||||
#![allow(clippy::useless_vec)]
|
||||
#![allow(clippy::struct_field_names)]
|
||||
|
||||
fn main() {
|
||||
// is_some(), unwrap()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:8:19
|
||||
--> $DIR/manual_find_map.rs:9:19
|
||||
|
|
||||
LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_opt(a))`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_find_map.rs:8:28
|
||||
--> $DIR/manual_find_map.rs:9:28
|
||||
|
|
||||
LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap());
|
||||
| ^^^^^^^^^^
|
||||
|
|
@ -13,31 +13,31 @@ LL | let _ = (0..).find(|n| to_opt(*n).is_some()).map(|a| to_opt(a).unwrap()
|
|||
= help: to override `-D warnings` add `#[allow(clippy::manual_find_map)]`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:11:19
|
||||
--> $DIR/manual_find_map.rs:12:19
|
||||
|
|
||||
LL | let _ = (0..).find(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi"));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_opt(a))`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_find_map.rs:11:29
|
||||
--> $DIR/manual_find_map.rs:12:29
|
||||
|
|
||||
LL | let _ = (0..).find(|&n| to_opt(n).is_some()).map(|a| to_opt(a).expect("hi"));
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:14:19
|
||||
--> $DIR/manual_find_map.rs:15:19
|
||||
|
|
||||
LL | let _ = (0..).find(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|a| to_res(a).ok())`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_find_map.rs:14:29
|
||||
--> $DIR/manual_find_map.rs:15:29
|
||||
|
|
||||
LL | let _ = (0..).find(|&n| to_res(n).is_ok()).map(|a| to_res(a).unwrap_or(1));
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:17:10
|
||||
--> $DIR/manual_find_map.rs:18:10
|
||||
|
|
||||
LL | .find(|&x| to_ref(to_opt(x)).is_some())
|
||||
| __________^
|
||||
|
|
@ -45,13 +45,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap());
|
|||
| |____________________________________________^ help: try: `find_map(|y| *to_ref(to_opt(y)))`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_find_map.rs:17:20
|
||||
--> $DIR/manual_find_map.rs:18:20
|
||||
|
|
||||
LL | .find(|&x| to_ref(to_opt(x)).is_some())
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:20:10
|
||||
--> $DIR/manual_find_map.rs:21:10
|
||||
|
|
||||
LL | .find(|x| to_ref(to_opt(*x)).is_some())
|
||||
| __________^
|
||||
|
|
@ -59,13 +59,13 @@ LL | | .map(|y| to_ref(to_opt(y)).unwrap());
|
|||
| |____________________________________________^ help: try: `find_map(|y| *to_ref(to_opt(y)))`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_find_map.rs:20:19
|
||||
--> $DIR/manual_find_map.rs:21:19
|
||||
|
|
||||
LL | .find(|x| to_ref(to_opt(*x)).is_some())
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:24:10
|
||||
--> $DIR/manual_find_map.rs:25:10
|
||||
|
|
||||
LL | .find(|&x| to_ref(to_res(x)).is_ok())
|
||||
| __________^
|
||||
|
|
@ -73,13 +73,13 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap());
|
|||
| |____________________________________________^ help: try: `find_map(|y| to_ref(to_res(y)).ok())`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_find_map.rs:24:20
|
||||
--> $DIR/manual_find_map.rs:25:20
|
||||
|
|
||||
LL | .find(|&x| to_ref(to_res(x)).is_ok())
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:27:10
|
||||
--> $DIR/manual_find_map.rs:28:10
|
||||
|
|
||||
LL | .find(|x| to_ref(to_res(*x)).is_ok())
|
||||
| __________^
|
||||
|
|
@ -87,109 +87,109 @@ LL | | .map(|y| to_ref(to_res(y)).unwrap());
|
|||
| |____________________________________________^ help: try: `find_map(|y| to_ref(to_res(y)).ok())`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_find_map.rs:27:19
|
||||
--> $DIR/manual_find_map.rs:28:19
|
||||
|
|
||||
LL | .find(|x| to_ref(to_res(*x)).is_ok())
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:33:26
|
||||
--> $DIR/manual_find_map.rs:34:26
|
||||
|
|
||||
LL | iter::<Option<u8>>().find(|x| x.is_some()).map(|x| x.unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x)`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:34:27
|
||||
--> $DIR/manual_find_map.rs:35:27
|
||||
|
|
||||
LL | iter::<&Option<u8>>().find(|x| x.is_some()).map(|x| x.unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| *x)`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:35:28
|
||||
--> $DIR/manual_find_map.rs:36:28
|
||||
|
|
||||
LL | iter::<&&Option<u8>>().find(|x| x.is_some()).map(|x| x.unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| **x)`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:36:27
|
||||
--> $DIR/manual_find_map.rs:37:27
|
||||
|
|
||||
LL | iter::<Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:37:28
|
||||
--> $DIR/manual_find_map.rs:38:28
|
||||
|
|
||||
LL | iter::<&Option<&u8>>().find(|x| x.is_some()).map(|x| x.cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:38:31
|
||||
--> $DIR/manual_find_map.rs:39:31
|
||||
|
|
||||
LL | iter::<&Option<String>>().find(|x| x.is_some()).map(|x| x.as_deref().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:39:31
|
||||
--> $DIR/manual_find_map.rs:40:31
|
||||
|
|
||||
LL | iter::<Option<&String>>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned())`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_find_map.rs:39:41
|
||||
--> $DIR/manual_find_map.rs:40:41
|
||||
|
|
||||
LL | iter::<Option<&String>>().find(|&x| to_ref(x).is_some()).map(|y| to_ref(y).cloned().unwrap());
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:41:30
|
||||
--> $DIR/manual_find_map.rs:42:30
|
||||
|
|
||||
LL | iter::<Result<u8, ()>>().find(|x| x.is_ok()).map(|x| x.unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:42:31
|
||||
--> $DIR/manual_find_map.rs:43:31
|
||||
|
|
||||
LL | iter::<&Result<u8, ()>>().find(|x| x.is_ok()).map(|x| x.unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:43:32
|
||||
--> $DIR/manual_find_map.rs:44:32
|
||||
|
|
||||
LL | iter::<&&Result<u8, ()>>().find(|x| x.is_ok()).map(|x| x.unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:44:31
|
||||
--> $DIR/manual_find_map.rs:45:31
|
||||
|
|
||||
LL | iter::<Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:45:32
|
||||
--> $DIR/manual_find_map.rs:46:32
|
||||
|
|
||||
LL | iter::<&Result<&u8, ()>>().find(|x| x.is_ok()).map(|x| x.cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.cloned().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:46:35
|
||||
--> $DIR/manual_find_map.rs:47:35
|
||||
|
|
||||
LL | iter::<&Result<String, ()>>().find(|x| x.is_ok()).map(|x| x.as_deref().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|x| x.as_deref().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:47:35
|
||||
--> $DIR/manual_find_map.rs:48:35
|
||||
|
|
||||
LL | iter::<Result<&String, ()>>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `find_map(|y| to_ref(y).cloned().ok())`
|
||||
|
|
||||
note: the suggestion might change the behavior of the program when merging `filter` and `map`, because this expression potentially contains side effects and will only execute once
|
||||
--> $DIR/manual_find_map.rs:47:45
|
||||
--> $DIR/manual_find_map.rs:48:45
|
||||
|
|
||||
LL | iter::<Result<&String, ()>>().find(|&x| to_ref(x).is_ok()).map(|y| to_ref(y).cloned().unwrap());
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:95:10
|
||||
--> $DIR/manual_find_map.rs:96:10
|
||||
|
|
||||
LL | .find(|f| f.option_field.is_some())
|
||||
| __________^
|
||||
|
|
@ -197,7 +197,7 @@ LL | | .map(|f| f.option_field.clone().unwrap());
|
|||
| |_________________________________________________^ help: try: `find_map(|f| f.option_field.clone())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:100:10
|
||||
--> $DIR/manual_find_map.rs:101:10
|
||||
|
|
||||
LL | .find(|f| f.ref_field.is_some())
|
||||
| __________^
|
||||
|
|
@ -205,7 +205,7 @@ LL | | .map(|f| f.ref_field.cloned().unwrap());
|
|||
| |_______________________________________________^ help: try: `find_map(|f| f.ref_field.cloned())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:105:10
|
||||
--> $DIR/manual_find_map.rs:106:10
|
||||
|
|
||||
LL | .find(|f| f.ref_field.is_some())
|
||||
| __________^
|
||||
|
|
@ -213,7 +213,7 @@ LL | | .map(|f| f.ref_field.copied().unwrap());
|
|||
| |_______________________________________________^ help: try: `find_map(|f| f.ref_field.copied())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:110:10
|
||||
--> $DIR/manual_find_map.rs:111:10
|
||||
|
|
||||
LL | .find(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -221,7 +221,7 @@ LL | | .map(|f| f.result_field.clone().unwrap());
|
|||
| |_________________________________________________^ help: try: `find_map(|f| f.result_field.clone().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:115:10
|
||||
--> $DIR/manual_find_map.rs:116:10
|
||||
|
|
||||
LL | .find(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -229,7 +229,7 @@ LL | | .map(|f| f.result_field.as_ref().unwrap());
|
|||
| |__________________________________________________^ help: try: `find_map(|f| f.result_field.as_ref().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:120:10
|
||||
--> $DIR/manual_find_map.rs:121:10
|
||||
|
|
||||
LL | .find(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -237,7 +237,7 @@ LL | | .map(|f| f.result_field.as_deref().unwrap());
|
|||
| |____________________________________________________^ help: try: `find_map(|f| f.result_field.as_deref().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:125:10
|
||||
--> $DIR/manual_find_map.rs:126:10
|
||||
|
|
||||
LL | .find(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -245,7 +245,7 @@ LL | | .map(|f| f.result_field.as_mut().unwrap());
|
|||
| |__________________________________________________^ help: try: `find_map(|f| f.result_field.as_mut().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:130:10
|
||||
--> $DIR/manual_find_map.rs:131:10
|
||||
|
|
||||
LL | .find(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
@ -253,7 +253,7 @@ LL | | .map(|f| f.result_field.as_deref_mut().unwrap());
|
|||
| |________________________________________________________^ help: try: `find_map(|f| f.result_field.as_deref_mut().ok())`
|
||||
|
||||
error: `find(..).map(..)` can be simplified as `find_map(..)`
|
||||
--> $DIR/manual_find_map.rs:135:10
|
||||
--> $DIR/manual_find_map.rs:136:10
|
||||
|
|
||||
LL | .find(|f| f.result_field.is_ok())
|
||||
| __________^
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ fn msrv_1_23() {
|
|||
assert!(matches!(b'1', b'0'..=b'9'));
|
||||
assert!(matches!('X', 'A'..='Z'));
|
||||
assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
|
||||
assert!(matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F'));
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.24"]
|
||||
|
|
@ -40,14 +41,17 @@ fn msrv_1_24() {
|
|||
assert!(b'1'.is_ascii_digit());
|
||||
assert!('X'.is_ascii_uppercase());
|
||||
assert!('x'.is_ascii_alphabetic());
|
||||
assert!('x'.is_ascii_hexdigit());
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.46"]
|
||||
fn msrv_1_46() {
|
||||
const FOO: bool = matches!('x', '0'..='9');
|
||||
const BAR: bool = matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F');
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.47"]
|
||||
fn msrv_1_47() {
|
||||
const FOO: bool = 'x'.is_ascii_digit();
|
||||
const BAR: bool = 'x'.is_ascii_hexdigit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ fn msrv_1_23() {
|
|||
assert!(matches!(b'1', b'0'..=b'9'));
|
||||
assert!(matches!('X', 'A'..='Z'));
|
||||
assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
|
||||
assert!(matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F'));
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.24"]
|
||||
|
|
@ -40,14 +41,17 @@ fn msrv_1_24() {
|
|||
assert!(matches!(b'1', b'0'..=b'9'));
|
||||
assert!(matches!('X', 'A'..='Z'));
|
||||
assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
|
||||
assert!(matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F'));
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.46"]
|
||||
fn msrv_1_46() {
|
||||
const FOO: bool = matches!('x', '0'..='9');
|
||||
const BAR: bool = matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F');
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.47"]
|
||||
fn msrv_1_47() {
|
||||
const FOO: bool = matches!('x', '0'..='9');
|
||||
const BAR: bool = matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,28 +98,40 @@ LL | ('A'..='Z').contains(cool_letter);
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cool_letter.is_ascii_uppercase()`
|
||||
|
||||
error: manual check for common ascii range
|
||||
--> $DIR/manual_is_ascii_check.rs:40:13
|
||||
--> $DIR/manual_is_ascii_check.rs:41:13
|
||||
|
|
||||
LL | assert!(matches!(b'1', b'0'..=b'9'));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b'1'.is_ascii_digit()`
|
||||
|
||||
error: manual check for common ascii range
|
||||
--> $DIR/manual_is_ascii_check.rs:41:13
|
||||
--> $DIR/manual_is_ascii_check.rs:42:13
|
||||
|
|
||||
LL | assert!(matches!('X', 'A'..='Z'));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'X'.is_ascii_uppercase()`
|
||||
|
||||
error: manual check for common ascii range
|
||||
--> $DIR/manual_is_ascii_check.rs:42:13
|
||||
--> $DIR/manual_is_ascii_check.rs:43:13
|
||||
|
|
||||
LL | assert!(matches!('x', 'A'..='Z' | 'a'..='z'));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_alphabetic()`
|
||||
|
||||
error: manual check for common ascii range
|
||||
--> $DIR/manual_is_ascii_check.rs:52:23
|
||||
--> $DIR/manual_is_ascii_check.rs:44:13
|
||||
|
|
||||
LL | assert!(matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F'));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_hexdigit()`
|
||||
|
||||
error: manual check for common ascii range
|
||||
--> $DIR/manual_is_ascii_check.rs:55:23
|
||||
|
|
||||
LL | const FOO: bool = matches!('x', '0'..='9');
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_digit()`
|
||||
|
||||
error: aborting due to 20 previous errors
|
||||
error: manual check for common ascii range
|
||||
--> $DIR/manual_is_ascii_check.rs:56:23
|
||||
|
|
||||
LL | const BAR: bool = matches!('x', '0'..='9' | 'a'..='f' | 'A'..='F');
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'x'.is_ascii_hexdigit()`
|
||||
|
||||
error: aborting due to 22 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ fn main() {
|
|||
});
|
||||
let _: Result<u32, u32> = Ok(1);
|
||||
let _: Result<u32, u32> = Ok(1).map_err(|a: u32| a * 42);
|
||||
// : u32 guides type inference
|
||||
let _ = Ok(1).map_err(|a: u32| a);
|
||||
let _ = Ok(1).map_err(std::convert::identity::<u32>);
|
||||
}
|
||||
|
||||
fn not_identity(x: &u16) -> u16 {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ fn main() {
|
|||
});
|
||||
let _: Result<u32, u32> = Ok(1).map_err(|a| a);
|
||||
let _: Result<u32, u32> = Ok(1).map_err(|a: u32| a * 42);
|
||||
// : u32 guides type inference
|
||||
let _ = Ok(1).map_err(|a: u32| a);
|
||||
let _ = Ok(1).map_err(std::convert::identity::<u32>);
|
||||
}
|
||||
|
||||
fn not_identity(x: &u16) -> u16 {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![allow(irrefutable_let_patterns, nonstandard_style, unused)]
|
||||
#![allow(clippy::struct_field_names)]
|
||||
#![warn(clippy::min_ident_chars)]
|
||||
|
||||
extern crate proc_macros;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:8:8
|
||||
--> $DIR/min_ident_chars.rs:9:8
|
||||
|
|
||||
LL | struct A {
|
||||
| ^
|
||||
|
|
@ -8,169 +8,169 @@ LL | struct A {
|
|||
= help: to override `-D warnings` add `#[allow(clippy::min_ident_chars)]`
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:9:5
|
||||
--> $DIR/min_ident_chars.rs:10:5
|
||||
|
|
||||
LL | a: u32,
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:11:5
|
||||
--> $DIR/min_ident_chars.rs:12:5
|
||||
|
|
||||
LL | A: u32,
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:12:5
|
||||
--> $DIR/min_ident_chars.rs:13:5
|
||||
|
|
||||
LL | I: u32,
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:15:8
|
||||
--> $DIR/min_ident_chars.rs:16:8
|
||||
|
|
||||
LL | struct B(u32);
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:17:8
|
||||
--> $DIR/min_ident_chars.rs:18:8
|
||||
|
|
||||
LL | struct O {
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:18:5
|
||||
--> $DIR/min_ident_chars.rs:19:5
|
||||
|
|
||||
LL | o: u32,
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:23:6
|
||||
--> $DIR/min_ident_chars.rs:24:6
|
||||
|
|
||||
LL | enum C {
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:24:5
|
||||
--> $DIR/min_ident_chars.rs:25:5
|
||||
|
|
||||
LL | D,
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:25:5
|
||||
--> $DIR/min_ident_chars.rs:26:5
|
||||
|
|
||||
LL | E,
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:26:5
|
||||
--> $DIR/min_ident_chars.rs:27:5
|
||||
|
|
||||
LL | F,
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:50:9
|
||||
--> $DIR/min_ident_chars.rs:51:9
|
||||
|
|
||||
LL | let h = 1;
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:51:9
|
||||
--> $DIR/min_ident_chars.rs:52:9
|
||||
|
|
||||
LL | let e = 2;
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:52:9
|
||||
--> $DIR/min_ident_chars.rs:53:9
|
||||
|
|
||||
LL | let l = 3;
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:53:9
|
||||
--> $DIR/min_ident_chars.rs:54:9
|
||||
|
|
||||
LL | let l = 4;
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:54:9
|
||||
--> $DIR/min_ident_chars.rs:55:9
|
||||
|
|
||||
LL | let o = 6;
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:58:10
|
||||
--> $DIR/min_ident_chars.rs:59:10
|
||||
|
|
||||
LL | let (h, o, w) = (1, 2, 3);
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:58:13
|
||||
--> $DIR/min_ident_chars.rs:59:13
|
||||
|
|
||||
LL | let (h, o, w) = (1, 2, 3);
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:59:10
|
||||
--> $DIR/min_ident_chars.rs:60:10
|
||||
|
|
||||
LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:59:14
|
||||
--> $DIR/min_ident_chars.rs:60:14
|
||||
|
|
||||
LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:59:17
|
||||
--> $DIR/min_ident_chars.rs:60:17
|
||||
|
|
||||
LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:61:16
|
||||
--> $DIR/min_ident_chars.rs:62:16
|
||||
|
|
||||
LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {}
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:61:19
|
||||
--> $DIR/min_ident_chars.rs:62:19
|
||||
|
|
||||
LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {}
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:61:29
|
||||
--> $DIR/min_ident_chars.rs:62:29
|
||||
|
|
||||
LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {}
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:65:9
|
||||
--> $DIR/min_ident_chars.rs:66:9
|
||||
|
|
||||
LL | let o = 1;
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:66:9
|
||||
--> $DIR/min_ident_chars.rs:67:9
|
||||
|
|
||||
LL | let o = O { o };
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:80:4
|
||||
--> $DIR/min_ident_chars.rs:81:4
|
||||
|
|
||||
LL | fn b() {}
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:81:21
|
||||
--> $DIR/min_ident_chars.rs:82:21
|
||||
|
|
||||
LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 {
|
||||
| ^
|
||||
|
||||
error: this ident consists of a single char
|
||||
--> $DIR/min_ident_chars.rs:81:29
|
||||
--> $DIR/min_ident_chars.rs:82:29
|
||||
|
|
||||
LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 {
|
||||
| ^
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#![allow(unused)]
|
||||
#![allow(clippy::struct_field_names)]
|
||||
#![warn(clippy::misnamed_getters)]
|
||||
|
||||
struct A {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#![allow(unused)]
|
||||
#![allow(clippy::struct_field_names)]
|
||||
#![warn(clippy::misnamed_getters)]
|
||||
|
||||
struct A {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:11:5
|
||||
--> $DIR/misnamed_getters.rs:12:5
|
||||
|
|
||||
LL | / fn a(&self) -> &u8 {
|
||||
LL | |
|
||||
|
|
@ -13,7 +13,7 @@ LL | | }
|
|||
= help: to override `-D warnings` add `#[allow(clippy::misnamed_getters)]`
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:16:5
|
||||
--> $DIR/misnamed_getters.rs:17:5
|
||||
|
|
||||
LL | / fn a_mut(&mut self) -> &mut u8 {
|
||||
LL | |
|
||||
|
|
@ -23,7 +23,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:21:5
|
||||
--> $DIR/misnamed_getters.rs:22:5
|
||||
|
|
||||
LL | / fn b(self) -> u8 {
|
||||
LL | |
|
||||
|
|
@ -33,7 +33,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:26:5
|
||||
--> $DIR/misnamed_getters.rs:27:5
|
||||
|
|
||||
LL | / fn b_mut(&mut self) -> &mut u8 {
|
||||
LL | |
|
||||
|
|
@ -43,7 +43,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:31:5
|
||||
--> $DIR/misnamed_getters.rs:32:5
|
||||
|
|
||||
LL | / fn c(&self) -> &u8 {
|
||||
LL | |
|
||||
|
|
@ -53,7 +53,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:36:5
|
||||
--> $DIR/misnamed_getters.rs:37:5
|
||||
|
|
||||
LL | / fn c_mut(&mut self) -> &mut u8 {
|
||||
LL | |
|
||||
|
|
@ -63,7 +63,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:48:5
|
||||
--> $DIR/misnamed_getters.rs:49:5
|
||||
|
|
||||
LL | / unsafe fn a(&self) -> &u8 {
|
||||
LL | |
|
||||
|
|
@ -73,7 +73,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:52:5
|
||||
--> $DIR/misnamed_getters.rs:53:5
|
||||
|
|
||||
LL | / unsafe fn a_mut(&mut self) -> &mut u8 {
|
||||
LL | |
|
||||
|
|
@ -83,7 +83,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:57:5
|
||||
--> $DIR/misnamed_getters.rs:58:5
|
||||
|
|
||||
LL | / unsafe fn b(self) -> u8 {
|
||||
LL | |
|
||||
|
|
@ -93,7 +93,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:62:5
|
||||
--> $DIR/misnamed_getters.rs:63:5
|
||||
|
|
||||
LL | / unsafe fn b_mut(&mut self) -> &mut u8 {
|
||||
LL | |
|
||||
|
|
@ -103,7 +103,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:75:5
|
||||
--> $DIR/misnamed_getters.rs:76:5
|
||||
|
|
||||
LL | / unsafe fn a_unchecked(&self) -> &u8 {
|
||||
LL | |
|
||||
|
|
@ -113,7 +113,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:79:5
|
||||
--> $DIR/misnamed_getters.rs:80:5
|
||||
|
|
||||
LL | / unsafe fn a_unchecked_mut(&mut self) -> &mut u8 {
|
||||
LL | |
|
||||
|
|
@ -123,7 +123,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:84:5
|
||||
--> $DIR/misnamed_getters.rs:85:5
|
||||
|
|
||||
LL | / unsafe fn b_unchecked(self) -> u8 {
|
||||
LL | |
|
||||
|
|
@ -133,7 +133,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:89:5
|
||||
--> $DIR/misnamed_getters.rs:90:5
|
||||
|
|
||||
LL | / unsafe fn b_unchecked_mut(&mut self) -> &mut u8 {
|
||||
LL | |
|
||||
|
|
@ -143,7 +143,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:122:5
|
||||
--> $DIR/misnamed_getters.rs:123:5
|
||||
|
|
||||
LL | / fn a(&self) -> &u8 {
|
||||
LL | |
|
||||
|
|
@ -153,7 +153,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:126:5
|
||||
--> $DIR/misnamed_getters.rs:127:5
|
||||
|
|
||||
LL | / fn a_mut(&mut self) -> &mut u8 {
|
||||
LL | |
|
||||
|
|
@ -163,7 +163,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:131:5
|
||||
--> $DIR/misnamed_getters.rs:132:5
|
||||
|
|
||||
LL | / fn d(&self) -> &u8 {
|
||||
LL | |
|
||||
|
|
@ -173,7 +173,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: getter function appears to return the wrong field
|
||||
--> $DIR/misnamed_getters.rs:135:5
|
||||
--> $DIR/misnamed_getters.rs:136:5
|
||||
|
|
||||
LL | / fn d_mut(&mut self) -> &mut u8 {
|
||||
LL | |
|
||||
|
|
|
|||
|
|
@ -147,4 +147,11 @@ fn _field_fn_ptr(x: unsafe fn()) {
|
|||
}
|
||||
}
|
||||
|
||||
// await expands to an unsafe block with several operations, but this is fine.: #11312
|
||||
async fn await_desugaring_silent() {
|
||||
async fn helper() {}
|
||||
|
||||
helper().await;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
clippy::equatable_if_let,
|
||||
clippy::needless_if,
|
||||
clippy::needless_return,
|
||||
clippy::self_named_constructors
|
||||
clippy::self_named_constructors,
|
||||
clippy::struct_field_names
|
||||
)]
|
||||
|
||||
use std::cell::Cell;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
clippy::equatable_if_let,
|
||||
clippy::needless_if,
|
||||
clippy::needless_return,
|
||||
clippy::self_named_constructors
|
||||
clippy::self_named_constructors,
|
||||
clippy::struct_field_names
|
||||
)]
|
||||
|
||||
use std::cell::Cell;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:40:5
|
||||
--> $DIR/fixable.rs:41:5
|
||||
|
|
||||
LL | / if x {
|
||||
LL | | true
|
||||
|
|
@ -12,7 +12,7 @@ LL | | };
|
|||
= help: to override `-D warnings` add `#[allow(clippy::needless_bool)]`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:45:5
|
||||
--> $DIR/fixable.rs:46:5
|
||||
|
|
||||
LL | / if x {
|
||||
LL | | false
|
||||
|
|
@ -22,7 +22,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `!x`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:50:5
|
||||
--> $DIR/fixable.rs:51:5
|
||||
|
|
||||
LL | / if x && y {
|
||||
LL | | false
|
||||
|
|
@ -32,7 +32,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `!(x && y)`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:58:5
|
||||
--> $DIR/fixable.rs:59:5
|
||||
|
|
||||
LL | / if a == b {
|
||||
LL | | false
|
||||
|
|
@ -42,7 +42,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `a != b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:63:5
|
||||
--> $DIR/fixable.rs:64:5
|
||||
|
|
||||
LL | / if a != b {
|
||||
LL | | false
|
||||
|
|
@ -52,7 +52,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `a == b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:68:5
|
||||
--> $DIR/fixable.rs:69:5
|
||||
|
|
||||
LL | / if a < b {
|
||||
LL | | false
|
||||
|
|
@ -62,7 +62,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `a >= b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:73:5
|
||||
--> $DIR/fixable.rs:74:5
|
||||
|
|
||||
LL | / if a <= b {
|
||||
LL | | false
|
||||
|
|
@ -72,7 +72,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `a > b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:78:5
|
||||
--> $DIR/fixable.rs:79:5
|
||||
|
|
||||
LL | / if a > b {
|
||||
LL | | false
|
||||
|
|
@ -82,7 +82,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `a <= b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:83:5
|
||||
--> $DIR/fixable.rs:84:5
|
||||
|
|
||||
LL | / if a >= b {
|
||||
LL | | false
|
||||
|
|
@ -92,7 +92,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `a < b`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:111:5
|
||||
--> $DIR/fixable.rs:112:5
|
||||
|
|
||||
LL | / if x {
|
||||
LL | | return true;
|
||||
|
|
@ -102,7 +102,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `return x`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:119:5
|
||||
--> $DIR/fixable.rs:120:5
|
||||
|
|
||||
LL | / if x {
|
||||
LL | | return false;
|
||||
|
|
@ -112,7 +112,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `return !x`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:127:5
|
||||
--> $DIR/fixable.rs:128:5
|
||||
|
|
||||
LL | / if x && y {
|
||||
LL | | return true;
|
||||
|
|
@ -122,7 +122,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `return x && y`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:135:5
|
||||
--> $DIR/fixable.rs:136:5
|
||||
|
|
||||
LL | / if x && y {
|
||||
LL | | return false;
|
||||
|
|
@ -132,7 +132,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `return !(x && y)`
|
||||
|
||||
error: equality checks against true are unnecessary
|
||||
--> $DIR/fixable.rs:143:8
|
||||
--> $DIR/fixable.rs:144:8
|
||||
|
|
||||
LL | if x == true {};
|
||||
| ^^^^^^^^^ help: try simplifying it as shown: `x`
|
||||
|
|
@ -141,25 +141,25 @@ LL | if x == true {};
|
|||
= help: to override `-D warnings` add `#[allow(clippy::bool_comparison)]`
|
||||
|
||||
error: equality checks against false can be replaced by a negation
|
||||
--> $DIR/fixable.rs:147:8
|
||||
--> $DIR/fixable.rs:148:8
|
||||
|
|
||||
LL | if x == false {};
|
||||
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
|
||||
|
||||
error: equality checks against true are unnecessary
|
||||
--> $DIR/fixable.rs:157:8
|
||||
--> $DIR/fixable.rs:158:8
|
||||
|
|
||||
LL | if x == true {};
|
||||
| ^^^^^^^^^ help: try simplifying it as shown: `x`
|
||||
|
||||
error: equality checks against false can be replaced by a negation
|
||||
--> $DIR/fixable.rs:158:8
|
||||
--> $DIR/fixable.rs:159:8
|
||||
|
|
||||
LL | if x == false {};
|
||||
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:167:12
|
||||
--> $DIR/fixable.rs:168:12
|
||||
|
|
||||
LL | } else if returns_bool() {
|
||||
| ____________^
|
||||
|
|
@ -170,7 +170,7 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `{ !returns_bool() }`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:180:5
|
||||
--> $DIR/fixable.rs:181:5
|
||||
|
|
||||
LL | / if unsafe { no(4) } & 1 != 0 {
|
||||
LL | | true
|
||||
|
|
@ -180,13 +180,13 @@ LL | | };
|
|||
| |_____^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:185:30
|
||||
--> $DIR/fixable.rs:186:30
|
||||
|
|
||||
LL | let _brackets_unneeded = if unsafe { no(4) } & 1 != 0 { true } else { false };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `unsafe { no(4) } & 1 != 0`
|
||||
|
||||
error: this if-then-else expression returns a bool literal
|
||||
--> $DIR/fixable.rs:188:9
|
||||
--> $DIR/fixable.rs:189:9
|
||||
|
|
||||
LL | if unsafe { no(4) } & 1 != 0 { true } else { false }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `(unsafe { no(4) } & 1 != 0)`
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
/// unimplemented!();
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// With an explicit return type it should lint too
|
||||
/// ```edition2015
|
||||
/// fn main() -> () {
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
/// unimplemented!();
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// This should, too.
|
||||
/// ```rust
|
||||
/// fn main() {
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
/// unimplemented!();
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// This one too.
|
||||
/// ```no_run
|
||||
/// // the fn is not always the first line
|
||||
|
|
|
|||
|
|
@ -270,6 +270,38 @@ pub async fn closure4(n: &mut usize) {
|
|||
})();
|
||||
}
|
||||
|
||||
// Should not warn.
|
||||
async fn _f(v: &mut Vec<()>) {
|
||||
let x = || v.pop();
|
||||
_ = || || x;
|
||||
}
|
||||
|
||||
struct Data<T: ?Sized> {
|
||||
value: T,
|
||||
}
|
||||
// Unsafe functions should not warn.
|
||||
unsafe fn get_mut_unchecked<T>(ptr: &mut NonNull<Data<T>>) -> &mut T {
|
||||
&mut (*ptr.as_ptr()).value
|
||||
}
|
||||
// Unsafe blocks should not warn.
|
||||
fn get_mut_unchecked2<T>(ptr: &mut NonNull<Data<T>>) -> &mut T {
|
||||
unsafe { &mut (*ptr.as_ptr()).value }
|
||||
}
|
||||
|
||||
fn set_true(b: &mut bool) {
|
||||
*b = true;
|
||||
}
|
||||
|
||||
// Should not warn.
|
||||
fn true_setter(b: &mut bool) -> impl FnOnce() + '_ {
|
||||
move || set_true(b)
|
||||
}
|
||||
|
||||
// Should not warn.
|
||||
fn filter_copy<T: Copy>(predicate: &mut impl FnMut(T) -> bool) -> impl FnMut(&T) -> bool + '_ {
|
||||
move |&item| predicate(item)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut u = 0;
|
||||
let mut v = vec![0];
|
||||
|
|
|
|||
|
|
@ -117,6 +117,14 @@ fn macros() {
|
|||
let x = 1;
|
||||
let x = x;
|
||||
}
|
||||
|
||||
let x = 10;
|
||||
macro_rules! rebind_outer_macro {
|
||||
($x:ident) => {
|
||||
let x = x;
|
||||
};
|
||||
}
|
||||
rebind_outer_macro!(y);
|
||||
}
|
||||
|
||||
struct WithDrop(usize);
|
||||
|
|
|
|||
|
|
@ -157,13 +157,13 @@ LL | let x = 1;
|
|||
| ^
|
||||
|
||||
error: redundant redefinition of a binding `a`
|
||||
--> $DIR/redundant_locals.rs:144:5
|
||||
--> $DIR/redundant_locals.rs:152:5
|
||||
|
|
||||
LL | let a = a;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: `a` is initially defined here
|
||||
--> $DIR/redundant_locals.rs:142:9
|
||||
--> $DIR/redundant_locals.rs:150:9
|
||||
|
|
||||
LL | let a = WithoutDrop(1);
|
||||
| ^
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#![warn(clippy::rest_pat_in_fully_bound_structs)]
|
||||
#![allow(clippy::struct_field_names)]
|
||||
|
||||
struct A {
|
||||
a: i32,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unnecessary use of `..` pattern in struct binding. All fields were already bound
|
||||
--> $DIR/rest_pat_in_fully_bound_structs.rs:22:9
|
||||
--> $DIR/rest_pat_in_fully_bound_structs.rs:23:9
|
||||
|
|
||||
LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -9,7 +9,7 @@ LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint
|
|||
= help: to override `-D warnings` add `#[allow(clippy::rest_pat_in_fully_bound_structs)]`
|
||||
|
||||
error: unnecessary use of `..` pattern in struct binding. All fields were already bound
|
||||
--> $DIR/rest_pat_in_fully_bound_structs.rs:24:9
|
||||
--> $DIR/rest_pat_in_fully_bound_structs.rs:25:9
|
||||
|
|
||||
LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -17,7 +17,7 @@ LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint
|
|||
= help: consider removing `..` from this binding
|
||||
|
||||
error: unnecessary use of `..` pattern in struct binding. All fields were already bound
|
||||
--> $DIR/rest_pat_in_fully_bound_structs.rs:31:9
|
||||
--> $DIR/rest_pat_in_fully_bound_structs.rs:32:9
|
||||
|
|
||||
LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
331
tests/ui/struct_fields.rs
Normal file
331
tests/ui/struct_fields.rs
Normal file
|
|
@ -0,0 +1,331 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
|
||||
#![warn(clippy::struct_field_names)]
|
||||
#![allow(unused)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate proc_macros;
|
||||
|
||||
struct Data1 {
|
||||
field_data1: u8,
|
||||
//~^ ERROR: field name ends with the struct's name
|
||||
another: u8,
|
||||
foo: u8,
|
||||
bar: u8,
|
||||
}
|
||||
|
||||
struct Data2 {
|
||||
another: u8,
|
||||
foo: u8,
|
||||
data2_field: u8,
|
||||
//~^ ERROR: field name starts with the struct's name
|
||||
bar: u8,
|
||||
}
|
||||
|
||||
struct StructData {
|
||||
//~^ ERROR: all fields have the same postfix: `data`
|
||||
movable_data: u8,
|
||||
fixed_data: u8,
|
||||
invisible_data: u8,
|
||||
}
|
||||
|
||||
struct DataStruct {
|
||||
//~^ ERROR: all fields have the same prefix: `data`
|
||||
data_movable: u8,
|
||||
data_fixed: u8,
|
||||
data_invisible: u8,
|
||||
}
|
||||
|
||||
struct DoublePrefix {
|
||||
//~^ ERROR: all fields have the same prefix: `some_data`
|
||||
some_data_a: bool,
|
||||
some_data_b: bool,
|
||||
some_data_c: bool,
|
||||
}
|
||||
|
||||
struct DoublePostfix {
|
||||
//~^ ERROR: all fields have the same postfix: `some_data`
|
||||
a_some_data: bool,
|
||||
b_some_data: bool,
|
||||
c_some_data: bool,
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
struct NotSnakeCase {
|
||||
//~^ ERROR: all fields have the same postfix: `someData`
|
||||
a_someData: bool,
|
||||
b_someData: bool,
|
||||
c_someData: bool,
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct NotSnakeCase2 {
|
||||
//~^ ERROR: all fields have the same prefix: `someData`
|
||||
someData_c: bool,
|
||||
someData_b: bool,
|
||||
someData_a_b: bool,
|
||||
}
|
||||
|
||||
// no error, threshold is 3 fiels by default
|
||||
struct Fooo {
|
||||
foo: u8,
|
||||
bar: u8,
|
||||
}
|
||||
|
||||
struct NonCaps {
|
||||
//~^ ERROR: all fields have the same prefix: `prefix`
|
||||
prefix_的: u8,
|
||||
prefix_tea: u8,
|
||||
prefix_cake: u8,
|
||||
}
|
||||
|
||||
// should not lint
|
||||
#[allow(clippy::struct_field_names)]
|
||||
pub mod allowed {
|
||||
pub struct PubAllowed {
|
||||
some_this: u8,
|
||||
some_that: u8,
|
||||
some_other_what: u8,
|
||||
}
|
||||
}
|
||||
|
||||
// should not lint
|
||||
struct SomeData {
|
||||
foo: u8,
|
||||
bar: bool,
|
||||
path: u8,
|
||||
answer: u8,
|
||||
}
|
||||
|
||||
// should not lint
|
||||
pub struct NetworkLayer {
|
||||
layer1: Vec<u8>,
|
||||
layer2: Vec<u8>,
|
||||
layer3: Vec<u8>,
|
||||
layer4: Vec<u8>,
|
||||
}
|
||||
|
||||
//should not lint
|
||||
struct North {
|
||||
normal: u8,
|
||||
no_left: u8,
|
||||
no_right: u8,
|
||||
}
|
||||
|
||||
mod issue8324_from_enum_variant_names {
|
||||
// 8324: enum_variant_names warns even if removing the suffix would leave an empty string
|
||||
struct Phase {
|
||||
pre_lookup: u8,
|
||||
lookup: u8,
|
||||
post_lookup: u8,
|
||||
}
|
||||
}
|
||||
|
||||
mod issue9018_from_enum_variant_names {
|
||||
struct DoLint {
|
||||
//~^ ERROR: all fields have the same prefix: `_type`
|
||||
_type_create: u8,
|
||||
_type_read: u8,
|
||||
_type_update: u8,
|
||||
_type_destroy: u8,
|
||||
}
|
||||
|
||||
struct DoLint2 {
|
||||
//~^ ERROR: all fields have the same prefix: `__type`
|
||||
__type_create: u8,
|
||||
__type_read: u8,
|
||||
__type_update: u8,
|
||||
__type_destroy: u8,
|
||||
}
|
||||
|
||||
struct DoLint3 {
|
||||
//~^ ERROR: all fields have the same prefix: `___type`
|
||||
___type_create: u8,
|
||||
___type_read: u8,
|
||||
___type_update: u8,
|
||||
___type_destroy: u8,
|
||||
}
|
||||
|
||||
struct DoLint4 {
|
||||
//~^ ERROR: all fields have the same postfix: `_`
|
||||
create_: u8,
|
||||
read_: u8,
|
||||
update_: u8,
|
||||
destroy_: u8,
|
||||
}
|
||||
|
||||
struct DoLint5 {
|
||||
//~^ ERROR: all fields have the same postfix: `__`
|
||||
create__: u8,
|
||||
read__: u8,
|
||||
update__: u8,
|
||||
destroy__: u8,
|
||||
}
|
||||
|
||||
struct DoLint6 {
|
||||
//~^ ERROR: all fields have the same postfix: `___`
|
||||
create___: u8,
|
||||
read___: u8,
|
||||
update___: u8,
|
||||
destroy___: u8,
|
||||
}
|
||||
|
||||
struct DoLintToo {
|
||||
//~^ ERROR: all fields have the same postfix: `type`
|
||||
_create_type: u8,
|
||||
_update_type: u8,
|
||||
_delete_type: u8,
|
||||
}
|
||||
|
||||
struct DoNotLint {
|
||||
_foo: u8,
|
||||
_bar: u8,
|
||||
_baz: u8,
|
||||
}
|
||||
|
||||
struct DoNotLint2 {
|
||||
__foo: u8,
|
||||
__bar: u8,
|
||||
__baz: u8,
|
||||
}
|
||||
}
|
||||
|
||||
mod allow_attributes_on_fields {
|
||||
struct Struct {
|
||||
#[allow(clippy::struct_field_names)]
|
||||
struct_starts_with: u8,
|
||||
#[allow(clippy::struct_field_names)]
|
||||
ends_with_struct: u8,
|
||||
foo: u8,
|
||||
}
|
||||
}
|
||||
|
||||
// food field should not lint
|
||||
struct Foo {
|
||||
food: i32,
|
||||
a: i32,
|
||||
b: i32,
|
||||
}
|
||||
|
||||
struct Proxy {
|
||||
proxy: i32,
|
||||
//~^ ERROR: field name starts with the struct's name
|
||||
unrelated1: bool,
|
||||
unrelated2: bool,
|
||||
}
|
||||
|
||||
// should not lint
|
||||
pub struct RegexT {
|
||||
__buffer: i32,
|
||||
__allocated: i32,
|
||||
__used: i32,
|
||||
}
|
||||
|
||||
mod macro_tests {
|
||||
macro_rules! mk_struct {
|
||||
() => {
|
||||
struct MacroStruct {
|
||||
some_a: i32,
|
||||
some_b: i32,
|
||||
some_c: i32,
|
||||
}
|
||||
};
|
||||
}
|
||||
mk_struct!();
|
||||
//~^ ERROR: all fields have the same prefix: `some`
|
||||
|
||||
macro_rules! mk_struct2 {
|
||||
() => {
|
||||
struct Macrobaz {
|
||||
macrobaz_a: i32,
|
||||
some_b: i32,
|
||||
some_c: i32,
|
||||
}
|
||||
};
|
||||
}
|
||||
mk_struct2!();
|
||||
//~^ ERROR: field name starts with the struct's name
|
||||
|
||||
macro_rules! mk_struct_with_names {
|
||||
($struct_name:ident, $field:ident) => {
|
||||
struct $struct_name {
|
||||
$field: i32,
|
||||
other_something: i32,
|
||||
other_field: i32,
|
||||
}
|
||||
};
|
||||
}
|
||||
// expands to `struct Foo { foo: i32, ... }`
|
||||
mk_struct_with_names!(Foo, foo);
|
||||
//~^ ERROR: field name starts with the struct's name
|
||||
|
||||
// expands to a struct with all fields starting with `other` but should not
|
||||
// be linted because some fields come from the macro definition and the other from the input
|
||||
mk_struct_with_names!(Some, other_data);
|
||||
|
||||
// should not lint when names come from different places
|
||||
macro_rules! mk_struct_with_field_name {
|
||||
($field_name:ident) => {
|
||||
struct Baz {
|
||||
one: i32,
|
||||
two: i32,
|
||||
$field_name: i32,
|
||||
}
|
||||
};
|
||||
}
|
||||
mk_struct_with_field_name!(baz_three);
|
||||
|
||||
// should not lint when names come from different places
|
||||
macro_rules! mk_struct_with_field_name {
|
||||
($field_name:ident) => {
|
||||
struct Bazilisk {
|
||||
baz_one: i32,
|
||||
baz_two: i32,
|
||||
$field_name: i32,
|
||||
}
|
||||
};
|
||||
}
|
||||
mk_struct_with_field_name!(baz_three);
|
||||
|
||||
macro_rules! mk_struct_full_def {
|
||||
($struct_name:ident, $field1:ident, $field2:ident, $field3:ident) => {
|
||||
struct $struct_name {
|
||||
$field1: i32,
|
||||
$field2: i32,
|
||||
$field3: i32,
|
||||
}
|
||||
};
|
||||
}
|
||||
mk_struct_full_def!(PrefixData, some_data, some_meta, some_other);
|
||||
//~^ ERROR: all fields have the same prefix: `some`
|
||||
}
|
||||
|
||||
// should not lint on external code
|
||||
external! {
|
||||
struct DataExternal {
|
||||
field_data1: u8,
|
||||
another: u8,
|
||||
foo: u8,
|
||||
bar: u8,
|
||||
}
|
||||
|
||||
struct NotSnakeCaseExternal {
|
||||
someData_c: bool,
|
||||
someData_b: bool,
|
||||
someData_a_b: bool,
|
||||
}
|
||||
|
||||
struct DoublePrefixExternal {
|
||||
some_data_a: bool,
|
||||
some_data_b: bool,
|
||||
some_data_c: bool,
|
||||
}
|
||||
|
||||
struct StructDataExternal {
|
||||
movable_data: u8,
|
||||
fixed_data: u8,
|
||||
invisible_data: u8,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
265
tests/ui/struct_fields.stderr
Normal file
265
tests/ui/struct_fields.stderr
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
error: field name ends with the struct's name
|
||||
--> $DIR/struct_fields.rs:10:5
|
||||
|
|
||||
LL | field_data1: u8,
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::struct-field-names` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::struct_field_names)]`
|
||||
|
||||
error: field name starts with the struct's name
|
||||
--> $DIR/struct_fields.rs:20:5
|
||||
|
|
||||
LL | data2_field: u8,
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: all fields have the same postfix: `data`
|
||||
--> $DIR/struct_fields.rs:25:1
|
||||
|
|
||||
LL | / struct StructData {
|
||||
LL | |
|
||||
LL | | movable_data: u8,
|
||||
LL | | fixed_data: u8,
|
||||
LL | | invisible_data: u8,
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: remove the postfixes
|
||||
|
||||
error: all fields have the same prefix: `data`
|
||||
--> $DIR/struct_fields.rs:32:1
|
||||
|
|
||||
LL | / struct DataStruct {
|
||||
LL | |
|
||||
LL | | data_movable: u8,
|
||||
LL | | data_fixed: u8,
|
||||
LL | | data_invisible: u8,
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: remove the prefixes
|
||||
|
||||
error: all fields have the same prefix: `some_data`
|
||||
--> $DIR/struct_fields.rs:39:1
|
||||
|
|
||||
LL | / struct DoublePrefix {
|
||||
LL | |
|
||||
LL | | some_data_a: bool,
|
||||
LL | | some_data_b: bool,
|
||||
LL | | some_data_c: bool,
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: remove the prefixes
|
||||
|
||||
error: all fields have the same postfix: `some_data`
|
||||
--> $DIR/struct_fields.rs:46:1
|
||||
|
|
||||
LL | / struct DoublePostfix {
|
||||
LL | |
|
||||
LL | | a_some_data: bool,
|
||||
LL | | b_some_data: bool,
|
||||
LL | | c_some_data: bool,
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: remove the postfixes
|
||||
|
||||
error: all fields have the same postfix: `someData`
|
||||
--> $DIR/struct_fields.rs:54:1
|
||||
|
|
||||
LL | / struct NotSnakeCase {
|
||||
LL | |
|
||||
LL | | a_someData: bool,
|
||||
LL | | b_someData: bool,
|
||||
LL | | c_someData: bool,
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: remove the postfixes
|
||||
|
||||
error: all fields have the same prefix: `someData`
|
||||
--> $DIR/struct_fields.rs:61:1
|
||||
|
|
||||
LL | / struct NotSnakeCase2 {
|
||||
LL | |
|
||||
LL | | someData_c: bool,
|
||||
LL | | someData_b: bool,
|
||||
LL | | someData_a_b: bool,
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: remove the prefixes
|
||||
|
||||
error: all fields have the same prefix: `prefix`
|
||||
--> $DIR/struct_fields.rs:74:1
|
||||
|
|
||||
LL | / struct NonCaps {
|
||||
LL | |
|
||||
LL | | prefix_的: u8,
|
||||
LL | | prefix_tea: u8,
|
||||
LL | | prefix_cake: u8,
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= help: remove the prefixes
|
||||
|
||||
error: all fields have the same prefix: `_type`
|
||||
--> $DIR/struct_fields.rs:124:5
|
||||
|
|
||||
LL | / struct DoLint {
|
||||
LL | |
|
||||
LL | | _type_create: u8,
|
||||
LL | | _type_read: u8,
|
||||
LL | | _type_update: u8,
|
||||
LL | | _type_destroy: u8,
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: remove the prefixes
|
||||
|
||||
error: all fields have the same prefix: `__type`
|
||||
--> $DIR/struct_fields.rs:132:5
|
||||
|
|
||||
LL | / struct DoLint2 {
|
||||
LL | |
|
||||
LL | | __type_create: u8,
|
||||
LL | | __type_read: u8,
|
||||
LL | | __type_update: u8,
|
||||
LL | | __type_destroy: u8,
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: remove the prefixes
|
||||
|
||||
error: all fields have the same prefix: `___type`
|
||||
--> $DIR/struct_fields.rs:140:5
|
||||
|
|
||||
LL | / struct DoLint3 {
|
||||
LL | |
|
||||
LL | | ___type_create: u8,
|
||||
LL | | ___type_read: u8,
|
||||
LL | | ___type_update: u8,
|
||||
LL | | ___type_destroy: u8,
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: remove the prefixes
|
||||
|
||||
error: all fields have the same postfix: `_`
|
||||
--> $DIR/struct_fields.rs:148:5
|
||||
|
|
||||
LL | / struct DoLint4 {
|
||||
LL | |
|
||||
LL | | create_: u8,
|
||||
LL | | read_: u8,
|
||||
LL | | update_: u8,
|
||||
LL | | destroy_: u8,
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: remove the postfixes
|
||||
|
||||
error: all fields have the same postfix: `__`
|
||||
--> $DIR/struct_fields.rs:156:5
|
||||
|
|
||||
LL | / struct DoLint5 {
|
||||
LL | |
|
||||
LL | | create__: u8,
|
||||
LL | | read__: u8,
|
||||
LL | | update__: u8,
|
||||
LL | | destroy__: u8,
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: remove the postfixes
|
||||
|
||||
error: all fields have the same postfix: `___`
|
||||
--> $DIR/struct_fields.rs:164:5
|
||||
|
|
||||
LL | / struct DoLint6 {
|
||||
LL | |
|
||||
LL | | create___: u8,
|
||||
LL | | read___: u8,
|
||||
LL | | update___: u8,
|
||||
LL | | destroy___: u8,
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: remove the postfixes
|
||||
|
||||
error: all fields have the same postfix: `type`
|
||||
--> $DIR/struct_fields.rs:172:5
|
||||
|
|
||||
LL | / struct DoLintToo {
|
||||
LL | |
|
||||
LL | | _create_type: u8,
|
||||
LL | | _update_type: u8,
|
||||
LL | | _delete_type: u8,
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= help: remove the postfixes
|
||||
|
||||
error: field name starts with the struct's name
|
||||
--> $DIR/struct_fields.rs:210:5
|
||||
|
|
||||
LL | proxy: i32,
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: all fields have the same prefix: `some`
|
||||
--> $DIR/struct_fields.rs:226:13
|
||||
|
|
||||
LL | / struct MacroStruct {
|
||||
LL | | some_a: i32,
|
||||
LL | | some_b: i32,
|
||||
LL | | some_c: i32,
|
||||
LL | | }
|
||||
| |_____________^
|
||||
...
|
||||
LL | mk_struct!();
|
||||
| ------------ in this macro invocation
|
||||
|
|
||||
= help: remove the prefixes
|
||||
= note: this error originates in the macro `mk_struct` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: field name starts with the struct's name
|
||||
--> $DIR/struct_fields.rs:239:17
|
||||
|
|
||||
LL | macrobaz_a: i32,
|
||||
| ^^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | mk_struct2!();
|
||||
| ------------- in this macro invocation
|
||||
|
|
||||
= note: this error originates in the macro `mk_struct2` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: field name starts with the struct's name
|
||||
--> $DIR/struct_fields.rs:251:17
|
||||
|
|
||||
LL | $field: i32,
|
||||
| ^^^^^^^^^^^
|
||||
...
|
||||
LL | mk_struct_with_names!(Foo, foo);
|
||||
| ------------------------------- in this macro invocation
|
||||
|
|
||||
= note: this error originates in the macro `mk_struct_with_names` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: all fields have the same prefix: `some`
|
||||
--> $DIR/struct_fields.rs:291:13
|
||||
|
|
||||
LL | / struct $struct_name {
|
||||
LL | | $field1: i32,
|
||||
LL | | $field2: i32,
|
||||
LL | | $field3: i32,
|
||||
LL | | }
|
||||
| |_____________^
|
||||
...
|
||||
LL | mk_struct_full_def!(PrefixData, some_data, some_meta, some_other);
|
||||
| ----------------------------------------------------------------- in this macro invocation
|
||||
|
|
||||
= help: remove the prefixes
|
||||
= note: this error originates in the macro `mk_struct_full_def` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 21 previous errors
|
||||
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
#![warn(clippy::temporary_assignment)]
|
||||
#![allow(const_item_mutation)]
|
||||
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: assignment to temporary
|
||||
--> $DIR/temporary_assignment.rs:48:5
|
||||
--> $DIR/temporary_assignment.rs:47:5
|
||||
|
|
||||
LL | Struct { field: 0 }.field = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -8,7 +8,7 @@ LL | Struct { field: 0 }.field = 1;
|
|||
= help: to override `-D warnings` add `#[allow(clippy::temporary_assignment)]`
|
||||
|
||||
error: assignment to temporary
|
||||
--> $DIR/temporary_assignment.rs:51:5
|
||||
--> $DIR/temporary_assignment.rs:50:5
|
||||
|
|
||||
LL | / MultiStruct {
|
||||
LL | |
|
||||
|
|
@ -19,13 +19,13 @@ LL | | .field = 1;
|
|||
| |______________^
|
||||
|
||||
error: assignment to temporary
|
||||
--> $DIR/temporary_assignment.rs:57:5
|
||||
--> $DIR/temporary_assignment.rs:56:5
|
||||
|
|
||||
LL | ArrayStruct { array: [0] }.array[0] = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: assignment to temporary
|
||||
--> $DIR/temporary_assignment.rs:59:5
|
||||
--> $DIR/temporary_assignment.rs:58:5
|
||||
|
|
||||
LL | (0, 0).0 = 1;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
|
|||
8
tests/ui/to_string_in_format_args_incremental.rs
Normal file
8
tests/ui/to_string_in_format_args_incremental.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
//@compile-flags: -C incremental=target/debug/test/incr
|
||||
|
||||
// see https://github.com/rust-lang/rust-clippy/issues/10969
|
||||
|
||||
fn main() {
|
||||
let s = "Hello, world!";
|
||||
println!("{}", s.to_string());
|
||||
}
|
||||
11
tests/ui/to_string_in_format_args_incremental.stderr
Normal file
11
tests/ui/to_string_in_format_args_incremental.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error: `to_string` applied to a type that implements `Display` in `println!` args
|
||||
--> $DIR/to_string_in_format_args_incremental.rs:7:21
|
||||
|
|
||||
LL | println!("{}", s.to_string());
|
||||
| ^^^^^^^^^^^^ help: remove this
|
||||
|
|
||||
= note: `-D clippy::to-string-in-format-args` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::to_string_in_format_args)]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
#![allow(clippy::map_identity)]
|
||||
#![allow(clippy::needless_borrow)]
|
||||
#![allow(clippy::unnecessary_literal_unwrap)]
|
||||
#![allow(clippy::unit_arg)]
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
|
|
@ -76,6 +77,8 @@ fn main() {
|
|||
let _ = opt.ok_or(2);
|
||||
let _ = nested_tuple_opt.unwrap_or(Some((1, 2)));
|
||||
let _ = cond.then_some(astronomers_pi);
|
||||
let _ = true.then_some({});
|
||||
let _ = true.then_some({});
|
||||
|
||||
// Should lint - Builtin deref
|
||||
let r = &1;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#![allow(clippy::map_identity)]
|
||||
#![allow(clippy::needless_borrow)]
|
||||
#![allow(clippy::unnecessary_literal_unwrap)]
|
||||
#![allow(clippy::unit_arg)]
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
|
|
@ -76,6 +77,8 @@ fn main() {
|
|||
let _ = opt.ok_or_else(|| 2);
|
||||
let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
|
||||
let _ = cond.then(|| astronomers_pi);
|
||||
let _ = true.then(|| -> _ {});
|
||||
let _ = true.then(|| {});
|
||||
|
||||
// Should lint - Builtin deref
|
||||
let r = &1;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:68:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:69:13
|
||||
|
|
||||
LL | let _ = opt.unwrap_or_else(|| 2);
|
||||
| ^^^^--------------------
|
||||
|
|
@ -10,7 +10,7 @@ LL | let _ = opt.unwrap_or_else(|| 2);
|
|||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_lazy_evaluations)]`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:69:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:70:13
|
||||
|
|
||||
LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
|
||||
| ^^^^---------------------------------
|
||||
|
|
@ -18,7 +18,7 @@ LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:70:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:71:13
|
||||
|
|
||||
LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
|
||||
| ^^^^-------------------------------------
|
||||
|
|
@ -26,7 +26,7 @@ LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:72:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:73:13
|
||||
|
|
||||
LL | let _ = opt.and_then(|_| ext_opt);
|
||||
| ^^^^---------------------
|
||||
|
|
@ -34,7 +34,7 @@ LL | let _ = opt.and_then(|_| ext_opt);
|
|||
| help: use `and(..)` instead: `and(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:73:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:74:13
|
||||
|
|
||||
LL | let _ = opt.or_else(|| ext_opt);
|
||||
| ^^^^-------------------
|
||||
|
|
@ -42,7 +42,7 @@ LL | let _ = opt.or_else(|| ext_opt);
|
|||
| help: use `or(..)` instead: `or(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:74:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:75:13
|
||||
|
|
||||
LL | let _ = opt.or_else(|| None);
|
||||
| ^^^^----------------
|
||||
|
|
@ -50,7 +50,7 @@ LL | let _ = opt.or_else(|| None);
|
|||
| help: use `or(..)` instead: `or(None)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:75:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:76:13
|
||||
|
|
||||
LL | let _ = opt.get_or_insert_with(|| 2);
|
||||
| ^^^^------------------------
|
||||
|
|
@ -58,7 +58,7 @@ LL | let _ = opt.get_or_insert_with(|| 2);
|
|||
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:76:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:77:13
|
||||
|
|
||||
LL | let _ = opt.ok_or_else(|| 2);
|
||||
| ^^^^----------------
|
||||
|
|
@ -66,7 +66,7 @@ LL | let _ = opt.ok_or_else(|| 2);
|
|||
| help: use `ok_or(..)` instead: `ok_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:77:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:78:13
|
||||
|
|
||||
LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
|
||||
| ^^^^^^^^^^^^^^^^^-------------------------------
|
||||
|
|
@ -74,15 +74,31 @@ LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(Some((1, 2)))`
|
||||
|
||||
error: unnecessary closure used with `bool::then`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:78:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:79:13
|
||||
|
|
||||
LL | let _ = cond.then(|| astronomers_pi);
|
||||
| ^^^^^-----------------------
|
||||
| |
|
||||
| help: use `then_some(..)` instead: `then_some(astronomers_pi)`
|
||||
|
||||
error: unnecessary closure used with `bool::then`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:80:13
|
||||
|
|
||||
LL | let _ = true.then(|| -> _ {});
|
||||
| ^^^^^----------------
|
||||
| |
|
||||
| help: use `then_some(..)` instead: `then_some({})`
|
||||
|
||||
error: unnecessary closure used with `bool::then`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:81:13
|
||||
|
|
||||
LL | let _ = true.then(|| {});
|
||||
| ^^^^^-----------
|
||||
| |
|
||||
| help: use `then_some(..)` instead: `then_some({})`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:82:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:85:13
|
||||
|
|
||||
LL | let _ = Some(1).unwrap_or_else(|| *r);
|
||||
| ^^^^^^^^---------------------
|
||||
|
|
@ -90,7 +106,7 @@ LL | let _ = Some(1).unwrap_or_else(|| *r);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(*r)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:84:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:87:13
|
||||
|
|
||||
LL | let _ = Some(1).unwrap_or_else(|| *b);
|
||||
| ^^^^^^^^---------------------
|
||||
|
|
@ -98,7 +114,7 @@ LL | let _ = Some(1).unwrap_or_else(|| *b);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(*b)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:86:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:89:13
|
||||
|
|
||||
LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r);
|
||||
| ^^^^^^^^^^^^^^^^^---------------------
|
||||
|
|
@ -106,7 +122,7 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(&r)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:87:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:90:13
|
||||
|
|
||||
LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b);
|
||||
| ^^^^^^^^^^^^^^^^^---------------------
|
||||
|
|
@ -114,7 +130,7 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(&b)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:90:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:93:13
|
||||
|
|
||||
LL | let _ = Some(10).unwrap_or_else(|| 2);
|
||||
| ^^^^^^^^^--------------------
|
||||
|
|
@ -122,7 +138,7 @@ LL | let _ = Some(10).unwrap_or_else(|| 2);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:91:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:94:13
|
||||
|
|
||||
LL | let _ = Some(10).and_then(|_| ext_opt);
|
||||
| ^^^^^^^^^---------------------
|
||||
|
|
@ -130,7 +146,7 @@ LL | let _ = Some(10).and_then(|_| ext_opt);
|
|||
| help: use `and(..)` instead: `and(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:92:28
|
||||
--> $DIR/unnecessary_lazy_eval.rs:95:28
|
||||
|
|
||||
LL | let _: Option<usize> = None.or_else(|| ext_opt);
|
||||
| ^^^^^-------------------
|
||||
|
|
@ -138,7 +154,7 @@ LL | let _: Option<usize> = None.or_else(|| ext_opt);
|
|||
| help: use `or(..)` instead: `or(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:93:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:96:13
|
||||
|
|
||||
LL | let _ = None.get_or_insert_with(|| 2);
|
||||
| ^^^^^------------------------
|
||||
|
|
@ -146,7 +162,7 @@ LL | let _ = None.get_or_insert_with(|| 2);
|
|||
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:94:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:97:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = None.ok_or_else(|| 2);
|
||||
| ^^^^^----------------
|
||||
|
|
@ -154,7 +170,7 @@ LL | let _: Result<usize, usize> = None.ok_or_else(|| 2);
|
|||
| help: use `ok_or(..)` instead: `ok_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:95:28
|
||||
--> $DIR/unnecessary_lazy_eval.rs:98:28
|
||||
|
|
||||
LL | let _: Option<usize> = None.or_else(|| None);
|
||||
| ^^^^^----------------
|
||||
|
|
@ -162,7 +178,7 @@ LL | let _: Option<usize> = None.or_else(|| None);
|
|||
| help: use `or(..)` instead: `or(None)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:98:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:101:13
|
||||
|
|
||||
LL | let _ = deep.0.unwrap_or_else(|| 2);
|
||||
| ^^^^^^^--------------------
|
||||
|
|
@ -170,7 +186,7 @@ LL | let _ = deep.0.unwrap_or_else(|| 2);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:99:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:102:13
|
||||
|
|
||||
LL | let _ = deep.0.and_then(|_| ext_opt);
|
||||
| ^^^^^^^---------------------
|
||||
|
|
@ -178,7 +194,7 @@ LL | let _ = deep.0.and_then(|_| ext_opt);
|
|||
| help: use `and(..)` instead: `and(ext_opt)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:100:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:103:13
|
||||
|
|
||||
LL | let _ = deep.0.or_else(|| None);
|
||||
| ^^^^^^^----------------
|
||||
|
|
@ -186,7 +202,7 @@ LL | let _ = deep.0.or_else(|| None);
|
|||
| help: use `or(..)` instead: `or(None)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:101:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:104:13
|
||||
|
|
||||
LL | let _ = deep.0.get_or_insert_with(|| 2);
|
||||
| ^^^^^^^------------------------
|
||||
|
|
@ -194,7 +210,7 @@ LL | let _ = deep.0.get_or_insert_with(|| 2);
|
|||
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:102:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:105:13
|
||||
|
|
||||
LL | let _ = deep.0.ok_or_else(|| 2);
|
||||
| ^^^^^^^----------------
|
||||
|
|
@ -202,7 +218,7 @@ LL | let _ = deep.0.ok_or_else(|| 2);
|
|||
| help: use `ok_or(..)` instead: `ok_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:132:28
|
||||
--> $DIR/unnecessary_lazy_eval.rs:135:28
|
||||
|
|
||||
LL | let _: Option<usize> = None.or_else(|| Some(3));
|
||||
| ^^^^^-------------------
|
||||
|
|
@ -210,7 +226,7 @@ LL | let _: Option<usize> = None.or_else(|| Some(3));
|
|||
| help: use `or(..)` instead: `or(Some(3))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:133:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:136:13
|
||||
|
|
||||
LL | let _ = deep.0.or_else(|| Some(3));
|
||||
| ^^^^^^^-------------------
|
||||
|
|
@ -218,7 +234,7 @@ LL | let _ = deep.0.or_else(|| Some(3));
|
|||
| help: use `or(..)` instead: `or(Some(3))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Option::None`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:134:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:137:13
|
||||
|
|
||||
LL | let _ = opt.or_else(|| Some(3));
|
||||
| ^^^^-------------------
|
||||
|
|
@ -226,7 +242,7 @@ LL | let _ = opt.or_else(|| Some(3));
|
|||
| help: use `or(..)` instead: `or(Some(3))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:140:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:143:13
|
||||
|
|
||||
LL | let _ = res2.unwrap_or_else(|_| 2);
|
||||
| ^^^^^---------------------
|
||||
|
|
@ -234,7 +250,7 @@ LL | let _ = res2.unwrap_or_else(|_| 2);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:141:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:144:13
|
||||
|
|
||||
LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
|
||||
| ^^^^^----------------------------------
|
||||
|
|
@ -242,7 +258,7 @@ LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:142:13
|
||||
--> $DIR/unnecessary_lazy_eval.rs:145:13
|
||||
|
|
||||
LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
|
||||
| ^^^^^--------------------------------------
|
||||
|
|
@ -250,7 +266,7 @@ LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
|
|||
| help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:164:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:167:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
|
||||
| ^^^^--------------------
|
||||
|
|
@ -258,7 +274,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
|
|||
| help: use `and(..)` instead: `and(Err(2))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:165:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:168:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
|
||||
| ^^^^---------------------------------
|
||||
|
|
@ -266,7 +282,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
|
|||
| help: use `and(..)` instead: `and(Err(astronomers_pi))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:166:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:169:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field));
|
||||
| ^^^^-------------------------------------
|
||||
|
|
@ -274,7 +290,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field))
|
|||
| help: use `and(..)` instead: `and(Err(ext_str.some_field))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:168:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:171:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
|
||||
| ^^^^------------------
|
||||
|
|
@ -282,7 +298,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
|
|||
| help: use `or(..)` instead: `or(Ok(2))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:169:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:172:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
|
||||
| ^^^^-------------------------------
|
||||
|
|
@ -290,7 +306,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
|
|||
| help: use `or(..)` instead: `or(Ok(astronomers_pi))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:170:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:173:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
|
||||
| ^^^^-----------------------------------
|
||||
|
|
@ -298,7 +314,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
|
|||
| help: use `or(..)` instead: `or(Ok(ext_str.some_field))`
|
||||
|
||||
error: unnecessary closure used to substitute value for `Result::Err`
|
||||
--> $DIR/unnecessary_lazy_eval.rs:171:35
|
||||
--> $DIR/unnecessary_lazy_eval.rs:174:35
|
||||
|
|
||||
LL | let _: Result<usize, usize> = res.
|
||||
| ___________________________________^
|
||||
|
|
@ -312,5 +328,5 @@ LL | | or_else(|_| Ok(ext_str.some_field));
|
|||
| |
|
||||
| help: use `or(..)` instead: `or(Ok(ext_str.some_field))`
|
||||
|
||||
error: aborting due to 38 previous errors
|
||||
error: aborting due to 40 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -25,3 +25,8 @@ fn main() {
|
|||
let arr = [(Some(1),)];
|
||||
Some(&0).and_then(|&i| arr[i].0);
|
||||
}
|
||||
|
||||
fn issue11672() {
|
||||
// Return type annotation helps type inference and removing it can break code
|
||||
let _ = true.then(|| -> &[u8] { &[] });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,5 +25,13 @@ LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2);
|
|||
| |
|
||||
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: unnecessary closure used with `bool::then`
|
||||
--> $DIR/unnecessary_lazy_eval_unfixable.rs:31:13
|
||||
|
|
||||
LL | let _ = true.then(|| -> &[u8] { &[] });
|
||||
| ^^^^^-------------------------
|
||||
| |
|
||||
| help: use `then_some(..)` instead: `then_some({ &[] })`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue