Merge remote-tracking branch 'upstream/master' into rustup

This commit is contained in:
Eduardo Broto 2020-11-23 23:02:12 +01:00
commit 209ab1885c
149 changed files with 3152 additions and 900 deletions

View file

@ -1,7 +1,19 @@
#[warn(clippy::as_conversions)]
// aux-build:macro_rules.rs
#![warn(clippy::as_conversions)]
#[macro_use]
extern crate macro_rules;
fn with_external_macro() {
as_conv_with_arg!(0u32 as u64);
as_conv!();
}
fn main() {
let i = 0u32 as u64;
let j = &i as *const u64 as *mut u64;
with_external_macro();
}

View file

@ -1,5 +1,5 @@
error: using a potentially dangerous silent `as` conversion
--> $DIR/as_conversions.rs:4:13
--> $DIR/as_conversions.rs:14:13
|
LL | let i = 0u32 as u64;
| ^^^^^^^^^^^
@ -8,7 +8,7 @@ LL | let i = 0u32 as u64;
= help: consider using a safe wrapper for this conversion
error: using a potentially dangerous silent `as` conversion
--> $DIR/as_conversions.rs:6:13
--> $DIR/as_conversions.rs:16:13
|
LL | let j = &i as *const u64 as *mut u64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -16,7 +16,7 @@ LL | let j = &i as *const u64 as *mut u64;
= help: consider using a safe wrapper for this conversion
error: using a potentially dangerous silent `as` conversion
--> $DIR/as_conversions.rs:6:13
--> $DIR/as_conversions.rs:16:13
|
LL | let j = &i as *const u64 as *mut u64;
| ^^^^^^^^^^^^^^^^

View file

@ -70,3 +70,17 @@ macro_rules! ref_arg_function {
fn fun_example(ref _x: usize) {}
};
}
#[macro_export]
macro_rules! as_conv_with_arg {
(0u32 as u64) => {
()
};
}
#[macro_export]
macro_rules! as_conv {
() => {
0u32 as u64
};
}

View file

@ -0,0 +1,16 @@
// this file solely exists to test constants defined in foreign crates.
// As the most common case is the `http` crate, it replicates `http::HeadewrName`'s structure.
#![allow(clippy::declare_interior_mutable_const)]
use std::sync::atomic::AtomicUsize;
enum Private<T> {
ToBeUnfrozen(T),
Frozen(usize),
}
pub struct Wrapper(Private<AtomicUsize>);
pub const WRAPPED_PRIVATE_UNFROZEN_VARIANT: Wrapper = Wrapper(Private::ToBeUnfrozen(AtomicUsize::new(6)));
pub const WRAPPED_PRIVATE_FROZEN_VARIANT: Wrapper = Wrapper(Private::Frozen(7));

View file

@ -0,0 +1,101 @@
// aux-build:helper.rs
#![warn(clippy::borrow_interior_mutable_const)]
#![allow(clippy::declare_interior_mutable_const)]
// this file (mostly) replicates its `declare` counterpart. Please see it for more discussions.
extern crate helper;
use std::cell::Cell;
use std::sync::atomic::AtomicUsize;
enum OptionalCell {
Unfrozen(Cell<bool>),
Frozen,
}
const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true));
const FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
fn borrow_optional_cell() {
let _ = &UNFROZEN_VARIANT; //~ ERROR interior mutability
let _ = &FROZEN_VARIANT;
}
trait AssocConsts {
const TO_BE_UNFROZEN_VARIANT: OptionalCell;
const TO_BE_FROZEN_VARIANT: OptionalCell;
const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false));
const DEFAULTED_ON_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
fn function() {
// This is the "suboptimal behavior" mentioned in `is_value_unfrozen`
// caused by a similar reason to unfrozen types without any default values
// get linted even if it has frozen variants'.
let _ = &Self::TO_BE_FROZEN_VARIANT; //~ ERROR interior mutable
// The lint ignores default values because an impl of this trait can set
// an unfrozen variant to `DEFAULTED_ON_FROZEN_VARIANT` and use the default impl for `function`.
let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT; //~ ERROR interior mutable
}
}
impl AssocConsts for u64 {
const TO_BE_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false));
const TO_BE_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
fn function() {
let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
let _ = &<Self as AssocConsts>::TO_BE_FROZEN_VARIANT;
let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT; //~ ERROR interior mutable
let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT;
}
}
trait AssocTypes {
type ToBeUnfrozen;
const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen>;
const TO_BE_FROZEN_VARIANT: Option<Self::ToBeUnfrozen>;
// there's no need to test here because it's the exactly same as `trait::AssocTypes`
fn function();
}
impl AssocTypes for u64 {
type ToBeUnfrozen = AtomicUsize;
const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR interior mutable
const TO_BE_FROZEN_VARIANT: Option<Self::ToBeUnfrozen> = None;
fn function() {
let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
let _ = &<Self as AssocTypes>::TO_BE_FROZEN_VARIANT;
}
}
enum BothOfCellAndGeneric<T> {
Unfrozen(Cell<*const T>),
Generic(*const T),
Frozen(usize),
}
impl<T> BothOfCellAndGeneric<T> {
const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable
const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable
const FROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Frozen(5);
fn function() {
let _ = &Self::UNFROZEN_VARIANT; //~ ERROR interior mutability
let _ = &Self::GENERIC_VARIANT; //~ ERROR interior mutability
let _ = &Self::FROZEN_VARIANT;
}
}
fn main() {
// constants defined in foreign crates
let _ = &helper::WRAPPED_PRIVATE_UNFROZEN_VARIANT; //~ ERROR interior mutability
let _ = &helper::WRAPPED_PRIVATE_FROZEN_VARIANT;
}

View file

@ -0,0 +1,75 @@
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:22:14
|
LL | let _ = &UNFROZEN_VARIANT; //~ ERROR interior mutability
| ^^^^^^^^^^^^^^^^
|
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:37:18
|
LL | let _ = &Self::TO_BE_FROZEN_VARIANT; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:41:18
|
LL | let _ = &Self::DEFAULTED_ON_FROZEN_VARIANT; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:50:18
|
LL | let _ = &<Self as AssocConsts>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:52:18
|
LL | let _ = &Self::DEFAULTED_ON_UNFROZEN_VARIANT; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:74:18
|
LL | let _ = &<Self as AssocTypes>::TO_BE_UNFROZEN_VARIANT; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:91:18
|
LL | let _ = &Self::UNFROZEN_VARIANT; //~ ERROR interior mutability
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:92:18
|
LL | let _ = &Self::GENERIC_VARIANT; //~ ERROR interior mutability
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:99:14
|
LL | let _ = &helper::WRAPPED_PRIVATE_UNFROZEN_VARIANT; //~ ERROR interior mutability
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: aborting due to 9 previous errors

View file

@ -19,33 +19,7 @@ const NO_ANN: &dyn Display = &70;
static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
const ONCE_INIT: Once = Once::new();
trait Trait<T> {
type AssocType;
const ATOMIC: AtomicUsize;
const INPUT: T;
const ASSOC: Self::AssocType;
fn function() {
let _ = &Self::INPUT;
let _ = &Self::ASSOC;
}
}
impl Trait<u32> for u64 {
type AssocType = AtomicUsize;
const ATOMIC: AtomicUsize = AtomicUsize::new(9);
const INPUT: u32 = 10;
const ASSOC: Self::AssocType = AtomicUsize::new(11);
fn function() {
let _ = &Self::INPUT;
let _ = &Self::ASSOC; //~ ERROR interior mutability
}
}
// This is just a pointer that can be safely dereferended,
// This is just a pointer that can be safely dereferenced,
// it's semantically the same as `&'static T`;
// but it isn't allowed to make a static reference from an arbitrary integer value at the moment.
// For more information, please see the issue #5918.
@ -100,7 +74,7 @@ fn main() {
let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
let _ = &*ATOMIC_TUPLE.1; //~ ERROR interior mutability
let _ = &*ATOMIC_TUPLE.1;
let _ = &ATOMIC_TUPLE.2;
let _ = (&&&&ATOMIC_TUPLE).0;
let _ = (&&&&ATOMIC_TUPLE).2;
@ -124,9 +98,6 @@ fn main() {
assert_eq!(STATIC_TUPLE.0.load(Ordering::SeqCst), 3);
assert!(STATIC_TUPLE.1.is_empty());
u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
assert_eq!(NO_ANN.to_string(), "70"); // should never lint this.
let _ = &CELL_REF.0;

View file

@ -1,22 +1,14 @@
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:44:18
--> $DIR/others.rs:54:5
|
LL | let _ = &Self::ASSOC; //~ ERROR interior mutability
| ^^^^^^^^^^^
LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
| ^^^^^^
|
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:80:5
|
LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
| ^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:81:16
--> $DIR/others.rs:55:16
|
LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
| ^^^^^^
@ -24,7 +16,7 @@ LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutabi
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:84:22
--> $DIR/others.rs:58:22
|
LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
| ^^^^^^^^^
@ -32,7 +24,7 @@ LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:85:25
--> $DIR/others.rs:59:25
|
LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
| ^^^^^^^^^
@ -40,7 +32,7 @@ LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:86:27
--> $DIR/others.rs:60:27
|
LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
| ^^^^^^^^^
@ -48,7 +40,7 @@ LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:87:26
--> $DIR/others.rs:61:26
|
LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
| ^^^^^^^^^
@ -56,7 +48,7 @@ LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:98:14
--> $DIR/others.rs:72:14
|
LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -64,7 +56,7 @@ LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:99:14
--> $DIR/others.rs:73:14
|
LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -72,7 +64,7 @@ LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:100:19
--> $DIR/others.rs:74:19
|
LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -80,7 +72,7 @@ LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:101:14
--> $DIR/others.rs:75:14
|
LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -88,7 +80,7 @@ LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:102:13
--> $DIR/others.rs:76:13
|
LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -96,7 +88,7 @@ LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mu
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:108:13
--> $DIR/others.rs:82:13
|
LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
| ^^^^^^^^^^^^
@ -104,7 +96,7 @@ LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:113:5
--> $DIR/others.rs:87:5
|
LL | CELL.set(2); //~ ERROR interior mutability
| ^^^^
@ -112,28 +104,12 @@ LL | CELL.set(2); //~ ERROR interior mutability
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:114:16
--> $DIR/others.rs:88:16
|
LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
| ^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:127:5
|
LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
| ^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/borrow_interior_mutable_const.rs:128:16
|
LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
| ^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: aborting due to 17 previous errors
error: aborting due to 14 previous errors

View file

@ -0,0 +1,202 @@
#![warn(clippy::borrow_interior_mutable_const)]
#![allow(clippy::declare_interior_mutable_const)]
// this file replicates its `declare` counterpart. Please see it for more discussions.
use std::borrow::Cow;
use std::cell::Cell;
use std::sync::atomic::{AtomicUsize, Ordering};
trait ConcreteTypes {
const ATOMIC: AtomicUsize;
const STRING: String;
fn function() {
let _ = &Self::ATOMIC; //~ ERROR interior mutable
let _ = &Self::STRING;
}
}
impl ConcreteTypes for u64 {
const ATOMIC: AtomicUsize = AtomicUsize::new(9);
const STRING: String = String::new();
fn function() {
// Lint this again since implementers can choose not to borrow it.
let _ = &Self::ATOMIC; //~ ERROR interior mutable
let _ = &Self::STRING;
}
}
// a helper trait used below
trait ConstDefault {
const DEFAULT: Self;
}
trait GenericTypes<T, U> {
const TO_REMAIN_GENERIC: T;
const TO_BE_CONCRETE: U;
fn function() {
let _ = &Self::TO_REMAIN_GENERIC;
}
}
impl<T: ConstDefault> GenericTypes<T, AtomicUsize> for Vec<T> {
const TO_REMAIN_GENERIC: T = T::DEFAULT;
const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11);
fn function() {
let _ = &Self::TO_REMAIN_GENERIC;
let _ = &Self::TO_BE_CONCRETE; //~ ERROR interior mutable
}
}
// a helper type used below
pub struct Wrapper<T>(T);
trait AssocTypes {
type ToBeFrozen;
type ToBeUnfrozen;
type ToBeGenericParam;
const TO_BE_FROZEN: Self::ToBeFrozen;
const TO_BE_UNFROZEN: Self::ToBeUnfrozen;
const WRAPPED_TO_BE_UNFROZEN: Wrapper<Self::ToBeUnfrozen>;
const WRAPPED_TO_BE_GENERIC_PARAM: Wrapper<Self::ToBeGenericParam>;
fn function() {
let _ = &Self::TO_BE_FROZEN;
let _ = &Self::WRAPPED_TO_BE_UNFROZEN;
}
}
impl<T: ConstDefault> AssocTypes for Vec<T> {
type ToBeFrozen = u16;
type ToBeUnfrozen = AtomicUsize;
type ToBeGenericParam = T;
const TO_BE_FROZEN: Self::ToBeFrozen = 12;
const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13);
const WRAPPED_TO_BE_UNFROZEN: Wrapper<Self::ToBeUnfrozen> = Wrapper(AtomicUsize::new(14));
const WRAPPED_TO_BE_GENERIC_PARAM: Wrapper<Self::ToBeGenericParam> = Wrapper(T::DEFAULT);
fn function() {
let _ = &Self::TO_BE_FROZEN;
let _ = &Self::TO_BE_UNFROZEN; //~ ERROR interior mutable
let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR interior mutable
let _ = &Self::WRAPPED_TO_BE_GENERIC_PARAM;
}
}
// a helper trait used below
trait AssocTypesHelper {
type NotToBeBounded;
type ToBeBounded;
const NOT_TO_BE_BOUNDED: Self::NotToBeBounded;
}
trait AssocTypesFromGenericParam<T>
where
T: AssocTypesHelper<ToBeBounded = AtomicUsize>,
{
const NOT_BOUNDED: T::NotToBeBounded;
const BOUNDED: T::ToBeBounded;
fn function() {
let _ = &Self::NOT_BOUNDED;
let _ = &Self::BOUNDED; //~ ERROR interior mutable
}
}
impl<T> AssocTypesFromGenericParam<T> for Vec<T>
where
T: AssocTypesHelper<ToBeBounded = AtomicUsize>,
{
const NOT_BOUNDED: T::NotToBeBounded = T::NOT_TO_BE_BOUNDED;
const BOUNDED: T::ToBeBounded = AtomicUsize::new(15);
fn function() {
let _ = &Self::NOT_BOUNDED;
let _ = &Self::BOUNDED; //~ ERROR interior mutable
}
}
trait SelfType: Sized {
const SELF: Self;
const WRAPPED_SELF: Option<Self>;
fn function() {
let _ = &Self::SELF;
let _ = &Self::WRAPPED_SELF;
}
}
impl SelfType for u64 {
const SELF: Self = 16;
const WRAPPED_SELF: Option<Self> = Some(20);
fn function() {
let _ = &Self::SELF;
let _ = &Self::WRAPPED_SELF;
}
}
impl SelfType for AtomicUsize {
const SELF: Self = AtomicUsize::new(17);
const WRAPPED_SELF: Option<Self> = Some(AtomicUsize::new(21));
fn function() {
let _ = &Self::SELF; //~ ERROR interior mutable
let _ = &Self::WRAPPED_SELF; //~ ERROR interior mutable
}
}
trait BothOfCellAndGeneric<T> {
const DIRECT: Cell<T>;
const INDIRECT: Cell<*const T>;
fn function() {
let _ = &Self::DIRECT;
let _ = &Self::INDIRECT; //~ ERROR interior mutable
}
}
impl<T: ConstDefault> BothOfCellAndGeneric<T> for Vec<T> {
const DIRECT: Cell<T> = Cell::new(T::DEFAULT);
const INDIRECT: Cell<*const T> = Cell::new(std::ptr::null());
fn function() {
let _ = &Self::DIRECT;
let _ = &Self::INDIRECT; //~ ERROR interior mutable
}
}
struct Local<T>(T);
impl<T> Local<T>
where
T: ConstDefault + AssocTypesHelper<ToBeBounded = AtomicUsize>,
{
const ATOMIC: AtomicUsize = AtomicUsize::new(18);
const COW: Cow<'static, str> = Cow::Borrowed("tuvwxy");
const GENERIC_TYPE: T = T::DEFAULT;
const ASSOC_TYPE: T::NotToBeBounded = T::NOT_TO_BE_BOUNDED;
const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19);
fn function() {
let _ = &Self::ATOMIC; //~ ERROR interior mutable
let _ = &Self::COW;
let _ = &Self::GENERIC_TYPE;
let _ = &Self::ASSOC_TYPE;
let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR interior mutable
}
}
fn main() {
u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
}

View file

@ -0,0 +1,123 @@
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:15:18
|
LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
| ^^^^^^^^^^^^
|
= note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:26:18
|
LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:51:18
|
LL | let _ = &Self::TO_BE_CONCRETE; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:86:18
|
LL | let _ = &Self::TO_BE_UNFROZEN; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:87:18
|
LL | let _ = &Self::WRAPPED_TO_BE_UNFROZEN; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:109:18
|
LL | let _ = &Self::BOUNDED; //~ ERROR interior mutable
| ^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:122:18
|
LL | let _ = &Self::BOUNDED; //~ ERROR interior mutable
| ^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:151:18
|
LL | let _ = &Self::SELF; //~ ERROR interior mutable
| ^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:152:18
|
LL | let _ = &Self::WRAPPED_SELF; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:162:18
|
LL | let _ = &Self::INDIRECT; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:172:18
|
LL | let _ = &Self::INDIRECT; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:191:18
|
LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
| ^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:195:18
|
LL | let _ = &Self::BOUNDED_ASSOC_TYPE; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:200:5
|
LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
| ^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:201:16
|
LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
| ^^^^^^^^^^^
|
= help: assign this const to a local or static variable, and use the variable here
error: aborting due to 15 previous errors

View file

@ -19,7 +19,7 @@ LL | loop {}
| ^^^^^^^
|
= note: `-D clippy::empty-loop` implied by `-D warnings`
= help: You should either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
= help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body
error: aborting due to 2 previous errors

View file

@ -0,0 +1,11 @@
fn cmark_check() {
let mut link_err = false;
macro_rules! cmark_error {
($bad:expr) => {
*$bad = true;
};
}
cmark_error!(&mut link_err);
}
pub fn main() {}

View file

@ -0,0 +1,123 @@
#![warn(clippy::declare_interior_mutable_const)]
use std::cell::Cell;
use std::sync::atomic::AtomicUsize;
enum OptionalCell {
Unfrozen(Cell<bool>),
Frozen,
}
// a constant with enums should be linted only when the used variant is unfrozen (#3962).
const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true)); //~ ERROR interior mutable
const FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
const fn unfrozen_variant() -> OptionalCell {
OptionalCell::Unfrozen(Cell::new(false))
}
const fn frozen_variant() -> OptionalCell {
OptionalCell::Frozen
}
const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); //~ ERROR interior mutable
const FROZEN_VARIANT_FROM_FN: OptionalCell = frozen_variant();
enum NestedInnermost {
Unfrozen(AtomicUsize),
Frozen,
}
struct NestedInner {
inner: NestedInnermost,
}
enum NestedOuter {
NestedInner(NestedInner),
NotNested(usize),
}
struct NestedOutermost {
outer: NestedOuter,
}
// a constant with enums should be linted according to its value, no matter how structs involve.
const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost {
outer: NestedOuter::NestedInner(NestedInner {
inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)),
}),
}; //~ ERROR interior mutable
const NESTED_FROZEN_VARIANT: NestedOutermost = NestedOutermost {
outer: NestedOuter::NestedInner(NestedInner {
inner: NestedInnermost::Frozen,
}),
};
trait AssocConsts {
// When there's no default value, lint it only according to its type.
// Further details are on the corresponding code (`NonCopyConst::check_trait_item`).
const TO_BE_UNFROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable
const TO_BE_FROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable
// Lint default values accordingly.
const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); //~ ERROR interior mutable
const DEFAULTED_ON_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
}
// The lint doesn't trigger for an assoc constant in a trait impl with an unfrozen type even if it
// has enums. Further details are on the corresponding code in 'NonCopyConst::check_impl_item'.
impl AssocConsts for u64 {
const TO_BE_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false));
const TO_BE_FROZEN_VARIANT: OptionalCell = OptionalCell::Frozen;
// even if this sets an unfrozen variant, the lint ignores it.
const DEFAULTED_ON_FROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false));
}
// At first, I thought I'd need to check every patterns in `trait.rs`; but, what matters
// here are values; and I think substituted generics at definitions won't appear in MIR.
trait AssocTypes {
type ToBeUnfrozen;
const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen>;
const TO_BE_FROZEN_VARIANT: Option<Self::ToBeUnfrozen>;
}
impl AssocTypes for u64 {
type ToBeUnfrozen = AtomicUsize;
const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR interior mutable
const TO_BE_FROZEN_VARIANT: Option<Self::ToBeUnfrozen> = None;
}
// Use raw pointers since direct generics have a false negative at the type level.
enum BothOfCellAndGeneric<T> {
Unfrozen(Cell<*const T>),
Generic(*const T),
Frozen(usize),
}
impl<T> BothOfCellAndGeneric<T> {
const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable
// This is a false positive. The argument about this is on `is_value_unfrozen_raw`
const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable
const FROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Frozen(5);
// This is what is likely to be a false negative when one tries to fix
// the `GENERIC_VARIANT` false positive.
const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); //~ ERROR interior mutable
}
// associated types here is basically the same as the one above.
trait BothOfCellAndGenericWithAssocType {
type AssocType;
const UNFROZEN_VARIANT: BothOfCellAndGeneric<Self::AssocType> =
BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable
const GENERIC_VARIANT: BothOfCellAndGeneric<Self::AssocType> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable
const FROZEN_VARIANT: BothOfCellAndGeneric<Self::AssocType> = BothOfCellAndGeneric::Frozen(5);
}
fn main() {}

View file

@ -0,0 +1,89 @@
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:12:1
|
LL | const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true)); //~ ERROR interior mutable
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
|
= note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings`
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:23:1
|
LL | const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); //~ ERROR interior mutable
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:45:1
|
LL | const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost {
| ^----
| |
| _make this a static item (maybe with lazy_static)
| |
LL | | outer: NestedOuter::NestedInner(NestedInner {
LL | | inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)),
LL | | }),
LL | | }; //~ ERROR interior mutable
| |__^
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:59:5
|
LL | const TO_BE_UNFROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:60:5
|
LL | const TO_BE_FROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:63:5
|
LL | const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:89:5
|
LL | const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:101:5
|
LL | const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mut...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:104:5
|
LL | const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:110:5
|
LL | const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:117:5
|
LL | / const UNFROZEN_VARIANT: BothOfCellAndGeneric<Self::AssocType> =
LL | | BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable
| |____________________________________________________________________^
error: a `const` item should never be interior mutable
--> $DIR/enums.rs:119:5
|
LL | const GENERIC_VARIANT: BothOfCellAndGeneric<Self::AssocType> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mu...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 12 previous errors

View file

@ -0,0 +1,34 @@
#![warn(clippy::declare_interior_mutable_const)]
use std::borrow::Cow;
use std::cell::Cell;
use std::fmt::Display;
use std::sync::atomic::AtomicUsize;
use std::sync::Once;
const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
//~^ ERROR interior mutable
macro_rules! declare_const {
($name:ident: $ty:ty = $e:expr) => {
const $name: $ty = $e;
};
}
declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
// const ATOMIC_REF: &AtomicUsize = &AtomicUsize::new(7); // This will simply trigger E0492.
const INTEGER: u8 = 8;
const STRING: String = String::new();
const STR: &str = "012345";
const COW: Cow<str> = Cow::Borrowed("abcdef");
//^ note: a const item of Cow is used in the `postgres` package.
const NO_ANN: &dyn Display = &70;
static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
//^ there should be no lints on this line
fn main() {}

View file

@ -0,0 +1,39 @@
error: a `const` item should never be interior mutable
--> $DIR/others.rs:9:1
|
LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
|
= note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings`
error: a `const` item should never be interior mutable
--> $DIR/others.rs:10:1
|
LL | const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
error: a `const` item should never be interior mutable
--> $DIR/others.rs:11:1
|
LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
error: a `const` item should never be interior mutable
--> $DIR/others.rs:16:9
|
LL | const $name: $ty = $e;
| ^^^^^^^^^^^^^^^^^^^^^^
...
LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
| ------------------------------------------ in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 4 previous errors

View file

@ -2,37 +2,13 @@
use std::borrow::Cow;
use std::cell::Cell;
use std::fmt::Display;
use std::sync::atomic::AtomicUsize;
use std::sync::Once;
const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
//~^ ERROR interior mutable
macro_rules! declare_const {
($name:ident: $ty:ty = $e:expr) => {
const $name: $ty = $e;
};
}
declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
// const ATOMIC_REF: &AtomicUsize = &AtomicUsize::new(7); // This will simply trigger E0492.
const INTEGER: u8 = 8;
const STRING: String = String::new();
const STR: &str = "012345";
const COW: Cow<str> = Cow::Borrowed("abcdef");
//^ note: a const item of Cow is used in the `postgres` package.
const NO_ANN: &dyn Display = &70;
static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
//^ there should be no lints on this line
#[allow(clippy::declare_interior_mutable_const)]
const ONCE_INIT: Once = Once::new();
// a constant whose type is a concrete type should be linted at the definition site.
trait ConcreteTypes {

View file

@ -1,48 +1,13 @@
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:9:1
--> $DIR/traits.rs:15:5
|
LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
LL | const ATOMIC: AtomicUsize; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings`
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:10:1
|
LL | const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:11:1
|
LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| make this a static item (maybe with lazy_static)
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:16:9
|
LL | const $name: $ty = $e;
| ^^^^^^^^^^^^^^^^^^^^^^
...
LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
| ------------------------------------------ in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:39:5
|
LL | const ATOMIC: AtomicUsize; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:16:9
--> $DIR/traits.rs:9:9
|
LL | const $name: $ty = $e;
| ^^^^^^^^^^^^^^^^^^^^^^
@ -53,58 +18,58 @@ LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR i
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:67:5
--> $DIR/traits.rs:43:5
|
LL | const TO_BE_CONCRETE: AtomicUsize = AtomicUsize::new(11); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:92:5
--> $DIR/traits.rs:68:5
|
LL | const TO_BE_UNFROZEN: Self::ToBeUnfrozen = AtomicUsize::new(13); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:93:5
--> $DIR/traits.rs:69:5
|
LL | const WRAPPED_TO_BE_UNFROZEN: Wrapper<Self::ToBeUnfrozen> = Wrapper(AtomicUsize::new(14)); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:112:5
--> $DIR/traits.rs:88:5
|
LL | const BOUNDED: T::ToBeBounded; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:140:5
--> $DIR/traits.rs:116:5
|
LL | const SELF: Self = AtomicUsize::new(17); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:141:5
--> $DIR/traits.rs:117:5
|
LL | const WRAPPED_SELF: Option<Self> = Some(AtomicUsize::new(21)); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:149:5
--> $DIR/traits.rs:125:5
|
LL | const INDIRECT: Cell<*const T>; //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:165:5
--> $DIR/traits.rs:141:5
|
LL | const ATOMIC: AtomicUsize = AtomicUsize::new(18); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `const` item should never be interior mutable
--> $DIR/declare_interior_mutable_const.rs:171:5
--> $DIR/traits.rs:147:5
|
LL | const BOUNDED_ASSOC_TYPE: T::ToBeBounded = AtomicUsize::new(19); //~ ERROR interior mutable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 15 previous errors
error: aborting due to 11 previous errors

View file

@ -10,5 +10,6 @@
#[warn(clippy::regex_macro)]
#[warn(clippy::drop_bounds)]
#[warn(clippy::temporary_cstring_as_ptr)]
#[warn(clippy::panic_params)]
fn main() {}

View file

@ -72,11 +72,17 @@ error: lint `clippy::temporary_cstring_as_ptr` has been removed: `this lint has
LL | #[warn(clippy::temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: lint `clippy::panic_params` has been removed: `this lint has been uplifted to rustc and is now called `panic_fmt``
--> $DIR/deprecated.rs:13:8
|
LL | #[warn(clippy::panic_params)]
| ^^^^^^^^^^^^^^^^^^^^
error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon`
--> $DIR/deprecated.rs:1:8
|
LL | #[warn(clippy::str_to_string)]
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 13 previous errors
error: aborting due to 14 previous errors

View file

@ -1,4 +1,5 @@
// run-rustfix
#![warn(clippy::deref_addrof)]
fn get_number() -> usize {
10
@ -10,7 +11,6 @@ fn get_reference(n: &usize) -> &usize {
#[allow(clippy::many_single_char_names, clippy::double_parens)]
#[allow(unused_variables, unused_parens)]
#[warn(clippy::deref_addrof)]
fn main() {
let a = 10;
let aref = &a;
@ -37,3 +37,27 @@ fn main() {
let b = *aref;
}
#[rustfmt::skip]
macro_rules! m {
($visitor: expr) => {
$visitor
};
}
#[rustfmt::skip]
macro_rules! m_mut {
($visitor: expr) => {
$visitor
};
}
pub struct S;
impl S {
pub fn f(&self) -> &Self {
m!(self)
}
pub fn f_mut(&self) -> &Self {
m_mut!(self)
}
}

View file

@ -1,4 +1,5 @@
// run-rustfix
#![warn(clippy::deref_addrof)]
fn get_number() -> usize {
10
@ -10,7 +11,6 @@ fn get_reference(n: &usize) -> &usize {
#[allow(clippy::many_single_char_names, clippy::double_parens)]
#[allow(unused_variables, unused_parens)]
#[warn(clippy::deref_addrof)]
fn main() {
let a = 10;
let aref = &a;
@ -37,3 +37,27 @@ fn main() {
let b = **&aref;
}
#[rustfmt::skip]
macro_rules! m {
($visitor: expr) => {
*& $visitor
};
}
#[rustfmt::skip]
macro_rules! m_mut {
($visitor: expr) => {
*& mut $visitor
};
}
pub struct S;
impl S {
pub fn f(&self) -> &Self {
m!(self)
}
pub fn f_mut(&self) -> &Self {
m_mut!(self)
}
}

View file

@ -48,5 +48,27 @@ error: immediately dereferencing a reference
LL | let b = **&aref;
| ^^^^^^ help: try this: `aref`
error: aborting due to 8 previous errors
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:44:9
|
LL | *& $visitor
| ^^^^^^^^^^^ help: try this: `$visitor`
...
LL | m!(self)
| -------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:51:9
|
LL | *& mut $visitor
| ^^^^^^^^^^^^^^^ help: try this: `$visitor`
...
LL | m_mut!(self)
| ------------ in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 10 previous errors

View file

@ -1,4 +1,5 @@
#![warn(clippy::derive_ord_xor_partial_ord)]
#![allow(clippy::unnecessary_wraps)]
use std::cmp::Ordering;

View file

@ -1,12 +1,12 @@
error: you are deriving `Ord` but have implemented `PartialOrd` explicitly
--> $DIR/derive_ord_xor_partial_ord.rs:20:10
--> $DIR/derive_ord_xor_partial_ord.rs:21:10
|
LL | #[derive(Ord, PartialEq, Eq)]
| ^^^
|
= note: `-D clippy::derive-ord-xor-partial-ord` implied by `-D warnings`
note: `PartialOrd` implemented here
--> $DIR/derive_ord_xor_partial_ord.rs:23:1
--> $DIR/derive_ord_xor_partial_ord.rs:24:1
|
LL | / impl PartialOrd for DeriveOrd {
LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
@ -17,13 +17,13 @@ LL | | }
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: you are deriving `Ord` but have implemented `PartialOrd` explicitly
--> $DIR/derive_ord_xor_partial_ord.rs:29:10
--> $DIR/derive_ord_xor_partial_ord.rs:30:10
|
LL | #[derive(Ord, PartialEq, Eq)]
| ^^^
|
note: `PartialOrd` implemented here
--> $DIR/derive_ord_xor_partial_ord.rs:32:1
--> $DIR/derive_ord_xor_partial_ord.rs:33:1
|
LL | / impl PartialOrd<DeriveOrdWithExplicitTypeVariable> for DeriveOrdWithExplicitTypeVariable {
LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
@ -34,7 +34,7 @@ LL | | }
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: you are implementing `Ord` explicitly but have derived `PartialOrd`
--> $DIR/derive_ord_xor_partial_ord.rs:41:1
--> $DIR/derive_ord_xor_partial_ord.rs:42:1
|
LL | / impl std::cmp::Ord for DerivePartialOrd {
LL | | fn cmp(&self, other: &Self) -> Ordering {
@ -44,14 +44,14 @@ LL | | }
| |_^
|
note: `PartialOrd` implemented here
--> $DIR/derive_ord_xor_partial_ord.rs:38:10
--> $DIR/derive_ord_xor_partial_ord.rs:39:10
|
LL | #[derive(PartialOrd, PartialEq, Eq)]
| ^^^^^^^^^^
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: you are implementing `Ord` explicitly but have derived `PartialOrd`
--> $DIR/derive_ord_xor_partial_ord.rs:61:5
--> $DIR/derive_ord_xor_partial_ord.rs:62:5
|
LL | / impl Ord for DerivePartialOrdInUseOrd {
LL | | fn cmp(&self, other: &Self) -> Ordering {
@ -61,7 +61,7 @@ LL | | }
| |_____^
|
note: `PartialOrd` implemented here
--> $DIR/derive_ord_xor_partial_ord.rs:58:14
--> $DIR/derive_ord_xor_partial_ord.rs:59:14
|
LL | #[derive(PartialOrd, PartialEq, Eq)]
| ^^^^^^^^^^

View file

@ -1,6 +1,7 @@
// edition:2018
#![warn(clippy::missing_errors_doc)]
#![allow(clippy::result_unit_err)]
#![allow(clippy::unnecessary_wraps)]
use std::io;

View file

@ -1,5 +1,5 @@
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:7:1
--> $DIR/doc_errors.rs:8:1
|
LL | / pub fn pub_fn_missing_errors_header() -> Result<(), ()> {
LL | | unimplemented!();
@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::missing-errors-doc` implied by `-D warnings`
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:11:1
--> $DIR/doc_errors.rs:12:1
|
LL | / pub async fn async_pub_fn_missing_errors_header() -> Result<(), ()> {
LL | | unimplemented!();
@ -17,7 +17,7 @@ LL | | }
| |_^
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:16:1
--> $DIR/doc_errors.rs:17:1
|
LL | / pub fn pub_fn_returning_io_result() -> io::Result<()> {
LL | | unimplemented!();
@ -25,7 +25,7 @@ LL | | }
| |_^
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:21:1
--> $DIR/doc_errors.rs:22:1
|
LL | / pub async fn async_pub_fn_returning_io_result() -> io::Result<()> {
LL | | unimplemented!();
@ -33,7 +33,7 @@ LL | | }
| |_^
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:51:5
--> $DIR/doc_errors.rs:52:5
|
LL | / pub fn pub_method_missing_errors_header() -> Result<(), ()> {
LL | | unimplemented!();
@ -41,7 +41,7 @@ LL | | }
| |_____^
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:56:5
--> $DIR/doc_errors.rs:57:5
|
LL | / pub async fn async_pub_method_missing_errors_header() -> Result<(), ()> {
LL | | unimplemented!();
@ -49,7 +49,7 @@ LL | | }
| |_____^
error: docs for function returning `Result` missing `# Errors` section
--> $DIR/doc_errors.rs:85:5
--> $DIR/doc_errors.rs:86:5
|
LL | fn trait_method_missing_errors_header() -> Result<(), ()>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,6 +1,7 @@
#![warn(clippy::drop_ref)]
#![allow(clippy::toplevel_ref_arg)]
#![allow(clippy::map_err_ignore)]
#![allow(clippy::unnecessary_wraps)]
use std::mem::drop;

View file

@ -1,108 +1,108 @@
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:10:5
--> $DIR/drop_ref.rs:11:5
|
LL | drop(&SomeStruct);
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::drop-ref` implied by `-D warnings`
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:10:10
--> $DIR/drop_ref.rs:11:10
|
LL | drop(&SomeStruct);
| ^^^^^^^^^^^
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:13:5
--> $DIR/drop_ref.rs:14:5
|
LL | drop(&owned1);
| ^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:13:10
--> $DIR/drop_ref.rs:14:10
|
LL | drop(&owned1);
| ^^^^^^^
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:14:5
--> $DIR/drop_ref.rs:15:5
|
LL | drop(&&owned1);
| ^^^^^^^^^^^^^^
|
note: argument has type `&&SomeStruct`
--> $DIR/drop_ref.rs:14:10
--> $DIR/drop_ref.rs:15:10
|
LL | drop(&&owned1);
| ^^^^^^^^
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:15:5
--> $DIR/drop_ref.rs:16:5
|
LL | drop(&mut owned1);
| ^^^^^^^^^^^^^^^^^
|
note: argument has type `&mut SomeStruct`
--> $DIR/drop_ref.rs:15:10
--> $DIR/drop_ref.rs:16:10
|
LL | drop(&mut owned1);
| ^^^^^^^^^^^
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:19:5
--> $DIR/drop_ref.rs:20:5
|
LL | drop(reference1);
| ^^^^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:19:10
--> $DIR/drop_ref.rs:20:10
|
LL | drop(reference1);
| ^^^^^^^^^^
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:22:5
--> $DIR/drop_ref.rs:23:5
|
LL | drop(reference2);
| ^^^^^^^^^^^^^^^^
|
note: argument has type `&mut SomeStruct`
--> $DIR/drop_ref.rs:22:10
--> $DIR/drop_ref.rs:23:10
|
LL | drop(reference2);
| ^^^^^^^^^^
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:25:5
--> $DIR/drop_ref.rs:26:5
|
LL | drop(reference3);
| ^^^^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:25:10
--> $DIR/drop_ref.rs:26:10
|
LL | drop(reference3);
| ^^^^^^^^^^
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:30:5
--> $DIR/drop_ref.rs:31:5
|
LL | drop(&val);
| ^^^^^^^^^^
|
note: argument has type `&T`
--> $DIR/drop_ref.rs:30:10
--> $DIR/drop_ref.rs:31:10
|
LL | drop(&val);
| ^^^^
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing.
--> $DIR/drop_ref.rs:38:5
--> $DIR/drop_ref.rs:39:5
|
LL | std::mem::drop(&SomeStruct);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:38:20
--> $DIR/drop_ref.rs:39:20
|
LL | std::mem::drop(&SomeStruct);
| ^^^^^^^^^^^

View file

@ -5,7 +5,7 @@ LL | loop {}
| ^^^^^^^
|
= note: `-D clippy::empty-loop` implied by `-D warnings`
= help: You should either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
= help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body
error: empty `loop {}` wastes CPU cycles
--> $DIR/empty_loop.rs:11:9
@ -13,7 +13,7 @@ error: empty `loop {}` wastes CPU cycles
LL | loop {}
| ^^^^^^^
|
= help: You should either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
= help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body
error: empty `loop {}` wastes CPU cycles
--> $DIR/empty_loop.rs:15:9
@ -21,7 +21,7 @@ error: empty `loop {}` wastes CPU cycles
LL | 'inner: loop {}
| ^^^^^^^^^^^^^^^
|
= help: You should either use `panic!()` or add `std::thread::sleep(..);` to the loop body.
= help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body
error: aborting due to 3 previous errors

View file

@ -10,13 +10,18 @@ use core::panic::PanicInfo;
#[start]
fn main(argc: isize, argv: *const *const u8) -> isize {
// This should trigger the lint
loop {}
}
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
// This should NOT trigger the lint
loop {}
}
#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
extern "C" fn eh_personality() {
// This should also trigger the lint
loop {}
}

View file

@ -0,0 +1,19 @@
error: empty `loop {}` wastes CPU cycles
--> $DIR/empty_loop_no_std.rs:14:5
|
LL | loop {}
| ^^^^^^^
|
= note: `-D clippy::empty-loop` implied by `-D warnings`
= help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body
error: empty `loop {}` wastes CPU cycles
--> $DIR/empty_loop_no_std.rs:26:5
|
LL | loop {}
| ^^^^^^^
|
= help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body
error: aborting due to 2 previous errors

View file

@ -1,4 +1,5 @@
#![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::clippy::let_underscore_drop)]
#![allow(clippy::missing_docs_in_private_items)]
fn main() {

View file

@ -1,5 +1,5 @@
error: called `filter(..).map(..)` on an `Iterator`
--> $DIR/filter_methods.rs:5:21
--> $DIR/filter_methods.rs:6:21
|
LL | let _: Vec<_> = vec![5; 6].into_iter().filter(|&x| x == 0).map(|x| x * 2).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -8,7 +8,7 @@ LL | let _: Vec<_> = vec![5; 6].into_iter().filter(|&x| x == 0).map(|x| x *
= help: this is more succinctly expressed by calling `.filter_map(..)` instead
error: called `filter(..).flat_map(..)` on an `Iterator`
--> $DIR/filter_methods.rs:7:21
--> $DIR/filter_methods.rs:8:21
|
LL | let _: Vec<_> = vec![5_i8; 6]
| _____________________^
@ -20,7 +20,7 @@ LL | | .flat_map(|x| x.checked_mul(2))
= help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()`
error: called `filter_map(..).flat_map(..)` on an `Iterator`
--> $DIR/filter_methods.rs:13:21
--> $DIR/filter_methods.rs:14:21
|
LL | let _: Vec<_> = vec![5_i8; 6]
| _____________________^
@ -32,7 +32,7 @@ LL | | .flat_map(|x| x.checked_mul(2))
= help: this is more succinctly expressed by calling `.flat_map(..)` and filtering by returning `iter::empty()`
error: called `filter_map(..).map(..)` on an `Iterator`
--> $DIR/filter_methods.rs:19:21
--> $DIR/filter_methods.rs:20:21
|
LL | let _: Vec<_> = vec![5_i8; 6]
| _____________________^

View file

@ -1,5 +1,6 @@
#![warn(clippy::forget_ref)]
#![allow(clippy::toplevel_ref_arg)]
#![allow(clippy::unnecessary_wraps)]
use std::mem::forget;

View file

@ -1,108 +1,108 @@
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
--> $DIR/forget_ref.rs:9:5
--> $DIR/forget_ref.rs:10:5
|
LL | forget(&SomeStruct);
| ^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::forget-ref` implied by `-D warnings`
note: argument has type `&SomeStruct`
--> $DIR/forget_ref.rs:9:12
--> $DIR/forget_ref.rs:10:12
|
LL | forget(&SomeStruct);
| ^^^^^^^^^^^
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
--> $DIR/forget_ref.rs:12:5
--> $DIR/forget_ref.rs:13:5
|
LL | forget(&owned);
| ^^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/forget_ref.rs:12:12
--> $DIR/forget_ref.rs:13:12
|
LL | forget(&owned);
| ^^^^^^
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
--> $DIR/forget_ref.rs:13:5
--> $DIR/forget_ref.rs:14:5
|
LL | forget(&&owned);
| ^^^^^^^^^^^^^^^
|
note: argument has type `&&SomeStruct`
--> $DIR/forget_ref.rs:13:12
--> $DIR/forget_ref.rs:14:12
|
LL | forget(&&owned);
| ^^^^^^^
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
--> $DIR/forget_ref.rs:14:5
--> $DIR/forget_ref.rs:15:5
|
LL | forget(&mut owned);
| ^^^^^^^^^^^^^^^^^^
|
note: argument has type `&mut SomeStruct`
--> $DIR/forget_ref.rs:14:12
--> $DIR/forget_ref.rs:15:12
|
LL | forget(&mut owned);
| ^^^^^^^^^^
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
--> $DIR/forget_ref.rs:18:5
--> $DIR/forget_ref.rs:19:5
|
LL | forget(&*reference1);
| ^^^^^^^^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/forget_ref.rs:18:12
--> $DIR/forget_ref.rs:19:12
|
LL | forget(&*reference1);
| ^^^^^^^^^^^^
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
--> $DIR/forget_ref.rs:21:5
--> $DIR/forget_ref.rs:22:5
|
LL | forget(reference2);
| ^^^^^^^^^^^^^^^^^^
|
note: argument has type `&mut SomeStruct`
--> $DIR/forget_ref.rs:21:12
--> $DIR/forget_ref.rs:22:12
|
LL | forget(reference2);
| ^^^^^^^^^^
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
--> $DIR/forget_ref.rs:24:5
--> $DIR/forget_ref.rs:25:5
|
LL | forget(reference3);
| ^^^^^^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/forget_ref.rs:24:12
--> $DIR/forget_ref.rs:25:12
|
LL | forget(reference3);
| ^^^^^^^^^^
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
--> $DIR/forget_ref.rs:29:5
--> $DIR/forget_ref.rs:30:5
|
LL | forget(&val);
| ^^^^^^^^^^^^
|
note: argument has type `&T`
--> $DIR/forget_ref.rs:29:12
--> $DIR/forget_ref.rs:30:12
|
LL | forget(&val);
| ^^^^
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
--> $DIR/forget_ref.rs:37:5
--> $DIR/forget_ref.rs:38:5
|
LL | std::mem::forget(&SomeStruct);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: argument has type `&SomeStruct`
--> $DIR/forget_ref.rs:37:22
--> $DIR/forget_ref.rs:38:22
|
LL | std::mem::forget(&SomeStruct);
| ^^^^^^^^^^^

View file

@ -0,0 +1,19 @@
#![warn(clippy::let_underscore_drop)]
struct Droppable;
impl Drop for Droppable {
fn drop(&mut self) {}
}
fn main() {
let unit = ();
let boxed = Box::new(());
let droppable = Droppable;
let optional = Some(Droppable);
let _ = ();
let _ = Box::new(());
let _ = Droppable;
let _ = Some(Droppable);
}

View file

@ -0,0 +1,27 @@
error: non-binding `let` on a type that implements `Drop`
--> $DIR/let_underscore_drop.rs:16:5
|
LL | let _ = Box::new(());
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::let-underscore-drop` implied by `-D warnings`
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
error: non-binding `let` on a type that implements `Drop`
--> $DIR/let_underscore_drop.rs:17:5
|
LL | let _ = Droppable;
| ^^^^^^^^^^^^^^^^^^
|
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
error: non-binding `let` on a type that implements `Drop`
--> $DIR/let_underscore_drop.rs:18:5
|
LL | let _ = Some(Droppable);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
error: aborting due to 3 previous errors

View file

@ -1,4 +1,5 @@
#![warn(clippy::let_underscore_must_use)]
#![allow(clippy::unnecessary_wraps)]
// Debug implementations can fire this lint,
// so we shouldn't lint external macros

View file

@ -1,5 +1,5 @@
error: non-binding let on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:66:5
--> $DIR/let_underscore_must_use.rs:67:5
|
LL | let _ = f();
| ^^^^^^^^^^^^
@ -8,7 +8,7 @@ LL | let _ = f();
= help: consider explicitly using function result
error: non-binding let on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:67:5
--> $DIR/let_underscore_must_use.rs:68:5
|
LL | let _ = g();
| ^^^^^^^^^^^^
@ -16,7 +16,7 @@ LL | let _ = g();
= help: consider explicitly using expression value
error: non-binding let on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:69:5
--> $DIR/let_underscore_must_use.rs:70:5
|
LL | let _ = l(0_u32);
| ^^^^^^^^^^^^^^^^^
@ -24,7 +24,7 @@ LL | let _ = l(0_u32);
= help: consider explicitly using function result
error: non-binding let on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:73:5
--> $DIR/let_underscore_must_use.rs:74:5
|
LL | let _ = s.f();
| ^^^^^^^^^^^^^^
@ -32,7 +32,7 @@ LL | let _ = s.f();
= help: consider explicitly using function result
error: non-binding let on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:74:5
--> $DIR/let_underscore_must_use.rs:75:5
|
LL | let _ = s.g();
| ^^^^^^^^^^^^^^
@ -40,7 +40,7 @@ LL | let _ = s.g();
= help: consider explicitly using expression value
error: non-binding let on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:77:5
--> $DIR/let_underscore_must_use.rs:78:5
|
LL | let _ = S::h();
| ^^^^^^^^^^^^^^^
@ -48,7 +48,7 @@ LL | let _ = S::h();
= help: consider explicitly using function result
error: non-binding let on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:78:5
--> $DIR/let_underscore_must_use.rs:79:5
|
LL | let _ = S::p();
| ^^^^^^^^^^^^^^^
@ -56,7 +56,7 @@ LL | let _ = S::p();
= help: consider explicitly using expression value
error: non-binding let on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:80:5
--> $DIR/let_underscore_must_use.rs:81:5
|
LL | let _ = S::a();
| ^^^^^^^^^^^^^^^
@ -64,7 +64,7 @@ LL | let _ = S::a();
= help: consider explicitly using function result
error: non-binding let on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:82:5
--> $DIR/let_underscore_must_use.rs:83:5
|
LL | let _ = if true { Ok(()) } else { Err(()) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -72,7 +72,7 @@ LL | let _ = if true { Ok(()) } else { Err(()) };
= help: consider explicitly using expression value
error: non-binding let on a result of a `#[must_use]` function
--> $DIR/let_underscore_must_use.rs:86:5
--> $DIR/let_underscore_must_use.rs:87:5
|
LL | let _ = a.is_ok();
| ^^^^^^^^^^^^^^^^^^
@ -80,7 +80,7 @@ LL | let _ = a.is_ok();
= help: consider explicitly using function result
error: non-binding let on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:88:5
--> $DIR/let_underscore_must_use.rs:89:5
|
LL | let _ = a.map(|_| ());
| ^^^^^^^^^^^^^^^^^^^^^^
@ -88,7 +88,7 @@ LL | let _ = a.map(|_| ());
= help: consider explicitly using expression value
error: non-binding let on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:90:5
--> $DIR/let_underscore_must_use.rs:91:5
|
LL | let _ = a;
| ^^^^^^^^^^

View file

@ -7,7 +7,19 @@ use std::future::Future;
async fn fut() -> i32 { 42 }
async fn empty_fut() {}
#[rustfmt::skip]
async fn fut2() -> i32 { 42 }
#[rustfmt::skip]
async fn fut3() -> i32 { 42 }
async fn empty_fut() {}
#[rustfmt::skip]
async fn empty_fut2() {}
#[rustfmt::skip]
async fn empty_fut3() {}
async fn core_fut() -> i32 { 42 }

View file

@ -9,10 +9,30 @@ fn fut() -> impl Future<Output = i32> {
async { 42 }
}
#[rustfmt::skip]
fn fut2() ->impl Future<Output = i32> {
async { 42 }
}
#[rustfmt::skip]
fn fut3()-> impl Future<Output = i32> {
async { 42 }
}
fn empty_fut() -> impl Future<Output = ()> {
async {}
}
#[rustfmt::skip]
fn empty_fut2() ->impl Future<Output = ()> {
async {}
}
#[rustfmt::skip]
fn empty_fut3()-> impl Future<Output = ()> {
async {}
}
fn core_fut() -> impl core::future::Future<Output = i32> {
async move { 42 }
}

View file

@ -15,14 +15,44 @@ LL | fn fut() -> impl Future<Output = i32> { 42 }
| ^^^^^^
error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:12:1
--> $DIR/manual_async_fn.rs:13:1
|
LL | fn fut2() ->impl Future<Output = i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: make the function `async` and return the output of the future directly
|
LL | async fn fut2() -> i32 {
| ^^^^^^^^^^^^^^^^^^^^^^
help: move the body of the async block to the enclosing function
|
LL | fn fut2() ->impl Future<Output = i32> { 42 }
| ^^^^^^
error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:18:1
|
LL | fn fut3()-> impl Future<Output = i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: make the function `async` and return the output of the future directly
|
LL | async fn fut3() -> i32 {
| ^^^^^^^^^^^^^^^^^^^^^^
help: move the body of the async block to the enclosing function
|
LL | fn fut3()-> impl Future<Output = i32> { 42 }
| ^^^^^^
error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:22:1
|
LL | fn empty_fut() -> impl Future<Output = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: make the function `async` and remove the return type
|
LL | async fn empty_fut() {
LL | async fn empty_fut() {
| ^^^^^^^^^^^^^^^^^^^^
help: move the body of the async block to the enclosing function
|
@ -30,7 +60,37 @@ LL | fn empty_fut() -> impl Future<Output = ()> {}
| ^^
error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:16:1
--> $DIR/manual_async_fn.rs:27:1
|
LL | fn empty_fut2() ->impl Future<Output = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: make the function `async` and remove the return type
|
LL | async fn empty_fut2() {
| ^^^^^^^^^^^^^^^^^^^^^
help: move the body of the async block to the enclosing function
|
LL | fn empty_fut2() ->impl Future<Output = ()> {}
| ^^
error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:32:1
|
LL | fn empty_fut3()-> impl Future<Output = ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: make the function `async` and remove the return type
|
LL | async fn empty_fut3() {
| ^^^^^^^^^^^^^^^^^^^^^
help: move the body of the async block to the enclosing function
|
LL | fn empty_fut3()-> impl Future<Output = ()> {}
| ^^
error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:36:1
|
LL | fn core_fut() -> impl core::future::Future<Output = i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -45,7 +105,7 @@ LL | fn core_fut() -> impl core::future::Future<Output = i32> { 42 }
| ^^^^^^
error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:38:5
--> $DIR/manual_async_fn.rs:58:5
|
LL | fn inh_fut() -> impl Future<Output = i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -65,7 +125,7 @@ LL | let c = 21;
...
error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:73:1
--> $DIR/manual_async_fn.rs:93:1
|
LL | fn elided(_: &i32) -> impl Future<Output = i32> + '_ {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -80,7 +140,7 @@ LL | fn elided(_: &i32) -> impl Future<Output = i32> + '_ { 42 }
| ^^^^^^
error: this function can be simplified using the `async fn` syntax
--> $DIR/manual_async_fn.rs:82:1
--> $DIR/manual_async_fn.rs:102:1
|
LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future<Output = i32> + 'a + 'b {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -94,5 +154,5 @@ help: move the body of the async block to the enclosing function
LL | fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future<Output = i32> + 'a + 'b { 42 }
| ^^^^^^
error: aborting due to 6 previous errors
error: aborting due to 10 previous errors

View file

@ -28,7 +28,7 @@ fn main() {
// not applicable, or side isn't `Result::Err`
foo.map_or(Ok::<i32, &str>(1), |v| Ok(v));
// not applicatble, expr is not a `Result` value
// not applicable, expr is not a `Result` value
foo.map_or(42, |v| v);
// TODO patterns not covered yet

View file

@ -32,7 +32,7 @@ fn main() {
// not applicable, or side isn't `Result::Err`
foo.map_or(Ok::<i32, &str>(1), |v| Ok(v));
// not applicatble, expr is not a `Result` value
// not applicable, expr is not a `Result` value
foo.map_or(42, |v| v);
// TODO patterns not covered yet

View file

@ -1,6 +1,6 @@
// run-rustfix
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_variables, clippy::unnecessary_wraps)]
fn option_unwrap_or() {
// int case

View file

@ -1,6 +1,6 @@
// run-rustfix
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_variables, clippy::unnecessary_wraps)]
fn option_unwrap_or() {
// int case

View file

@ -2,6 +2,7 @@
#![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::iter_cloned_collect)]
#![allow(clippy::clone_on_copy, clippy::redundant_clone)]
#![allow(clippy::let_underscore_drop)]
#![allow(clippy::missing_docs_in_private_items)]
#![allow(clippy::redundant_closure_for_method_calls)]
#![allow(clippy::many_single_char_names)]
@ -44,4 +45,19 @@ fn main() {
let v = vec![&mut d];
let _: Vec<u32> = v.into_iter().map(|&mut x| x).collect();
}
// Issue #6299
{
let mut aa = 5;
let mut bb = 3;
let items = vec![&mut aa, &mut bb];
let _: Vec<_> = items.into_iter().map(|x| x.clone()).collect();
}
// Issue #6239 deref coercion and clone deref
{
use std::cell::RefCell;
let _ = Some(RefCell::new(String::new()).borrow()).map(|s| s.clone());
}
}

View file

@ -2,6 +2,7 @@
#![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::iter_cloned_collect)]
#![allow(clippy::clone_on_copy, clippy::redundant_clone)]
#![allow(clippy::let_underscore_drop)]
#![allow(clippy::missing_docs_in_private_items)]
#![allow(clippy::redundant_closure_for_method_calls)]
#![allow(clippy::many_single_char_names)]
@ -44,4 +45,19 @@ fn main() {
let v = vec![&mut d];
let _: Vec<u32> = v.into_iter().map(|&mut x| x).collect();
}
// Issue #6299
{
let mut aa = 5;
let mut bb = 3;
let items = vec![&mut aa, &mut bb];
let _: Vec<_> = items.into_iter().map(|x| x.clone()).collect();
}
// Issue #6239 deref coercion and clone deref
{
use std::cell::RefCell;
let _ = Some(RefCell::new(String::new()).borrow()).map(|s| s.clone());
}
}

View file

@ -1,5 +1,5 @@
error: you are using an explicit closure for copying elements
--> $DIR/map_clone.rs:10:22
--> $DIR/map_clone.rs:11:22
|
LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![5_i8; 6].iter().copied()`
@ -7,31 +7,31 @@ LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();
= note: `-D clippy::map-clone` implied by `-D warnings`
error: you are using an explicit closure for cloning elements
--> $DIR/map_clone.rs:11:26
--> $DIR/map_clone.rs:12:26
|
LL | let _: Vec<String> = vec![String::new()].iter().map(|x| x.clone()).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `vec![String::new()].iter().cloned()`
error: you are using an explicit closure for copying elements
--> $DIR/map_clone.rs:12:23
--> $DIR/map_clone.rs:13:23
|
LL | let _: Vec<u32> = vec![42, 43].iter().map(|&x| x).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![42, 43].iter().copied()`
error: you are using an explicit closure for copying elements
--> $DIR/map_clone.rs:14:26
--> $DIR/map_clone.rs:15:26
|
LL | let _: Option<u64> = Some(&16).map(|b| *b);
| ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&16).copied()`
error: you are using an explicit closure for copying elements
--> $DIR/map_clone.rs:15:25
--> $DIR/map_clone.rs:16:25
|
LL | let _: Option<u8> = Some(&1).map(|x| x.clone());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&1).copied()`
error: you are needlessly cloning iterator elements
--> $DIR/map_clone.rs:26:29
--> $DIR/map_clone.rs:27:29
|
LL | let _ = std::env::args().map(|v| v.clone());
| ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call

View file

@ -1,4 +1,5 @@
#![warn(clippy::map_err_ignore)]
#![allow(clippy::unnecessary_wraps)]
use std::convert::TryFrom;
use std::error::Error;
use std::fmt;

View file

@ -1,5 +1,5 @@
error: `map_err(|_|...` ignores the original error
--> $DIR/map_err.rs:22:32
--> $DIR/map_err.rs:23:32
|
LL | println!("{:?}", x.map_err(|_| Errors::Ignored));
| ^^^

View file

@ -1,8 +1,10 @@
// run-rustfix
#![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::let_underscore_drop)]
#![allow(clippy::missing_docs_in_private_items)]
#![allow(clippy::map_identity)]
#![allow(clippy::unnecessary_wraps)]
fn main() {
// mapping to Option on Iterator

View file

@ -1,8 +1,10 @@
// run-rustfix
#![warn(clippy::all, clippy::pedantic)]
#![allow(clippy::let_underscore_drop)]
#![allow(clippy::missing_docs_in_private_items)]
#![allow(clippy::map_identity)]
#![allow(clippy::unnecessary_wraps)]
fn main() {
// mapping to Option on Iterator

View file

@ -1,5 +1,5 @@
error: called `map(..).flatten()` on an `Iterator`
--> $DIR/map_flatten.rs:14:46
--> $DIR/map_flatten.rs:16:46
|
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `filter_map` instead: `.filter_map(option_id)`
@ -7,31 +7,31 @@ LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().coll
= note: `-D clippy::map-flatten` implied by `-D warnings`
error: called `map(..).flatten()` on an `Iterator`
--> $DIR/map_flatten.rs:15:46
--> $DIR/map_flatten.rs:17:46
|
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `filter_map` instead: `.filter_map(option_id_ref)`
error: called `map(..).flatten()` on an `Iterator`
--> $DIR/map_flatten.rs:16:46
--> $DIR/map_flatten.rs:18:46
|
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `filter_map` instead: `.filter_map(option_id_closure)`
error: called `map(..).flatten()` on an `Iterator`
--> $DIR/map_flatten.rs:17:46
--> $DIR/map_flatten.rs:19:46
|
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `filter_map` instead: `.filter_map(|x| x.checked_add(1))`
error: called `map(..).flatten()` on an `Iterator`
--> $DIR/map_flatten.rs:20:46
--> $DIR/map_flatten.rs:22:46
|
LL | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `flat_map` instead: `.flat_map(|x| 0..x)`
error: called `map(..).flatten()` on an `Option`
--> $DIR/map_flatten.rs:23:39
--> $DIR/map_flatten.rs:25:39
|
LL | let _: Option<_> = (Some(Some(1))).map(|x| x).flatten();
| ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `.and_then(|x| x)`

View file

@ -133,50 +133,6 @@ fn filter_next() {
let _ = foo.filter().next();
}
/// Checks implementation of `SEARCH_IS_SOME` lint.
#[rustfmt::skip]
fn search_is_some() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
let y = &&42;
// Check `find().is_some()`, single-line case.
let _ = v.iter().find(|&x| *x < 0).is_some();
let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
let _ = (0..1).find(|x| *x == 0).is_some();
let _ = v.iter().find(|x| **x == 0).is_some();
// Check `find().is_some()`, multi-line case.
let _ = v.iter().find(|&x| {
*x < 0
}
).is_some();
// Check `position().is_some()`, single-line case.
let _ = v.iter().position(|&x| x < 0).is_some();
// Check `position().is_some()`, multi-line case.
let _ = v.iter().position(|&x| {
x < 0
}
).is_some();
// Check `rposition().is_some()`, single-line case.
let _ = v.iter().rposition(|&x| x < 0).is_some();
// Check `rposition().is_some()`, multi-line case.
let _ = v.iter().rposition(|&x| {
x < 0
}
).is_some();
// Check that we don't lint if the caller is not an `Iterator`.
let foo = IteratorFalsePositives { foo: 0 };
let _ = foo.find().is_some();
let _ = foo.position().is_some();
let _ = foo.rposition().is_some();
}
fn main() {
filter_next();
search_is_some();
}

View file

@ -20,73 +20,5 @@ LL | | ).next();
|
= note: `-D clippy::filter-next` implied by `-D warnings`
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:143:22
|
LL | let _ = v.iter().find(|&x| *x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x < 0)`
|
= note: `-D clippy::search-is-some` implied by `-D warnings`
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:144:20
|
LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| **y == x)`
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:145:20
|
LL | let _ = (0..1).find(|x| *x == 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| x == 0)`
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:146:22
|
LL | let _ = v.iter().find(|x| **x == 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x == 0)`
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:149:13
|
LL | let _ = v.iter().find(|&x| {
| _____________^
LL | | *x < 0
LL | | }
LL | | ).is_some();
| |______________________________^
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:155:22
|
LL | let _ = v.iter().position(|&x| x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:158:13
|
LL | let _ = v.iter().position(|&x| {
| _____________^
LL | | x < 0
LL | | }
LL | | ).is_some();
| |______________________________^
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:164:22
|
LL | let _ = v.iter().rposition(|&x| x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
--> $DIR/methods.rs:167:13
|
LL | let _ = v.iter().rposition(|&x| {
| _____________^
LL | | x < 0
LL | | }
LL | | ).is_some();
| |______________________________^
error: aborting due to 11 previous errors
error: aborting due to 2 previous errors

View file

@ -1,5 +1,5 @@
#![warn(clippy::needless_lifetimes)]
#![allow(dead_code, clippy::needless_pass_by_value)]
#![allow(dead_code, clippy::needless_pass_by_value, clippy::unnecessary_wraps)]
fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}

View file

@ -2,6 +2,7 @@
#![warn(clippy::option_map_unit_fn)]
#![allow(unused)]
#![allow(clippy::unnecessary_wraps)]
fn do_nothing<T>(_: T) {}

View file

@ -2,6 +2,7 @@
#![warn(clippy::option_map_unit_fn)]
#![allow(unused)]
#![allow(clippy::unnecessary_wraps)]
fn do_nothing<T>(_: T) {}

View file

@ -1,5 +1,5 @@
error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:38:5
--> $DIR/option_map_unit_fn_fixable.rs:39:5
|
LL | x.field.map(do_nothing);
| ^^^^^^^^^^^^^^^^^^^^^^^-
@ -9,7 +9,7 @@ LL | x.field.map(do_nothing);
= note: `-D clippy::option-map-unit-fn` implied by `-D warnings`
error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:40:5
--> $DIR/option_map_unit_fn_fixable.rs:41:5
|
LL | x.field.map(do_nothing);
| ^^^^^^^^^^^^^^^^^^^^^^^-
@ -17,7 +17,7 @@ LL | x.field.map(do_nothing);
| help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }`
error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:42:5
--> $DIR/option_map_unit_fn_fixable.rs:43:5
|
LL | x.field.map(diverge);
| ^^^^^^^^^^^^^^^^^^^^-
@ -25,7 +25,7 @@ LL | x.field.map(diverge);
| help: try this: `if let Some(x_field) = x.field { diverge(x_field) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:48:5
--> $DIR/option_map_unit_fn_fixable.rs:49:5
|
LL | x.field.map(|value| x.do_option_nothing(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -33,7 +33,7 @@ LL | x.field.map(|value| x.do_option_nothing(value + captured));
| help: try this: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:50:5
--> $DIR/option_map_unit_fn_fixable.rs:51:5
|
LL | x.field.map(|value| { x.do_option_plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -41,7 +41,7 @@ LL | x.field.map(|value| { x.do_option_plus_one(value + captured); });
| help: try this: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:53:5
--> $DIR/option_map_unit_fn_fixable.rs:54:5
|
LL | x.field.map(|value| do_nothing(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -49,7 +49,7 @@ LL | x.field.map(|value| do_nothing(value + captured));
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:55:5
--> $DIR/option_map_unit_fn_fixable.rs:56:5
|
LL | x.field.map(|value| { do_nothing(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -57,7 +57,7 @@ LL | x.field.map(|value| { do_nothing(value + captured) });
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:57:5
--> $DIR/option_map_unit_fn_fixable.rs:58:5
|
LL | x.field.map(|value| { do_nothing(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -65,7 +65,7 @@ LL | x.field.map(|value| { do_nothing(value + captured); });
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:59:5
--> $DIR/option_map_unit_fn_fixable.rs:60:5
|
LL | x.field.map(|value| { { do_nothing(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -73,7 +73,7 @@ LL | x.field.map(|value| { { do_nothing(value + captured); } });
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:62:5
--> $DIR/option_map_unit_fn_fixable.rs:63:5
|
LL | x.field.map(|value| diverge(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -81,7 +81,7 @@ LL | x.field.map(|value| diverge(value + captured));
| help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:64:5
--> $DIR/option_map_unit_fn_fixable.rs:65:5
|
LL | x.field.map(|value| { diverge(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -89,7 +89,7 @@ LL | x.field.map(|value| { diverge(value + captured) });
| help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:66:5
--> $DIR/option_map_unit_fn_fixable.rs:67:5
|
LL | x.field.map(|value| { diverge(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -97,7 +97,7 @@ LL | x.field.map(|value| { diverge(value + captured); });
| help: try this: `if let Some(value) = x.field { diverge(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:68:5
--> $DIR/option_map_unit_fn_fixable.rs:69:5
|
LL | x.field.map(|value| { { diverge(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -105,7 +105,7 @@ LL | x.field.map(|value| { { diverge(value + captured); } });
| help: try this: `if let Some(value) = x.field { diverge(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:73:5
--> $DIR/option_map_unit_fn_fixable.rs:74:5
|
LL | x.field.map(|value| { let y = plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -113,7 +113,7 @@ LL | x.field.map(|value| { let y = plus_one(value + captured); });
| help: try this: `if let Some(value) = x.field { let y = plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:75:5
--> $DIR/option_map_unit_fn_fixable.rs:76:5
|
LL | x.field.map(|value| { plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -121,7 +121,7 @@ LL | x.field.map(|value| { plus_one(value + captured); });
| help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:77:5
--> $DIR/option_map_unit_fn_fixable.rs:78:5
|
LL | x.field.map(|value| { { plus_one(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -129,7 +129,7 @@ LL | x.field.map(|value| { { plus_one(value + captured); } });
| help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:80:5
--> $DIR/option_map_unit_fn_fixable.rs:81:5
|
LL | x.field.map(|ref value| { do_nothing(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -137,7 +137,7 @@ LL | x.field.map(|ref value| { do_nothing(value + captured) });
| help: try this: `if let Some(ref value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()`
--> $DIR/option_map_unit_fn_fixable.rs:82:5
--> $DIR/option_map_unit_fn_fixable.rs:83:5
|
LL | option().map(do_nothing);}
| ^^^^^^^^^^^^^^^^^^^^^^^^-

View file

@ -1,4 +1,5 @@
#![deny(clippy::option_option)]
#![allow(clippy::unnecessary_wraps)]
fn input(_: Option<Option<u8>>) {}
@ -72,8 +73,6 @@ mod issue_4298 {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
#[serde(borrow)]
// FIXME: should not lint here
#[allow(clippy::option_option)]
foo: Option<Option<Cow<'a, str>>>,
}

View file

@ -1,5 +1,5 @@
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> $DIR/option_option.rs:3:13
--> $DIR/option_option.rs:4:13
|
LL | fn input(_: Option<Option<u8>>) {}
| ^^^^^^^^^^^^^^^^^^
@ -11,55 +11,55 @@ LL | #![deny(clippy::option_option)]
| ^^^^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> $DIR/option_option.rs:5:16
--> $DIR/option_option.rs:6:16
|
LL | fn output() -> Option<Option<u8>> {
| ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> $DIR/option_option.rs:9:27
--> $DIR/option_option.rs:10:27
|
LL | fn output_nested() -> Vec<Option<Option<u8>>> {
| ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> $DIR/option_option.rs:14:30
--> $DIR/option_option.rs:15:30
|
LL | fn output_nested_nested() -> Option<Option<Option<u8>>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> $DIR/option_option.rs:19:8
--> $DIR/option_option.rs:20:8
|
LL | x: Option<Option<u8>>,
| ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> $DIR/option_option.rs:23:23
--> $DIR/option_option.rs:24:23
|
LL | fn struct_fn() -> Option<Option<u8>> {
| ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> $DIR/option_option.rs:29:22
--> $DIR/option_option.rs:30:22
|
LL | fn trait_fn() -> Option<Option<u8>>;
| ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> $DIR/option_option.rs:33:11
--> $DIR/option_option.rs:34:11
|
LL | Tuple(Option<Option<u8>>),
| ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> $DIR/option_option.rs:34:17
--> $DIR/option_option.rs:35:17
|
LL | Struct { x: Option<Option<u8>> },
| ^^^^^^^^^^^^^^^^^^
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
--> $DIR/option_option.rs:77:14
--> $DIR/option_option.rs:76:14
|
LL | foo: Option<Option<Cow<'a, str>>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -2,6 +2,7 @@
#![warn(clippy::or_fun_call)]
#![allow(dead_code)]
#![allow(clippy::unnecessary_wraps)]
use std::collections::BTreeMap;
use std::collections::HashMap;
@ -70,6 +71,15 @@ fn or_fun_call() {
let opt = Some(1);
let hello = "Hello";
let _ = opt.ok_or(format!("{} world.", hello));
// index
let map = HashMap::<u64, u64>::new();
let _ = Some(1).unwrap_or_else(|| map[&1]);
let map = BTreeMap::<u64, u64>::new();
let _ = Some(1).unwrap_or_else(|| map[&1]);
// don't lint index vec
let vec = vec![1];
let _ = Some(1).unwrap_or(vec[1]);
}
struct Foo(u8);

View file

@ -2,6 +2,7 @@
#![warn(clippy::or_fun_call)]
#![allow(dead_code)]
#![allow(clippy::unnecessary_wraps)]
use std::collections::BTreeMap;
use std::collections::HashMap;
@ -70,6 +71,15 @@ fn or_fun_call() {
let opt = Some(1);
let hello = "Hello";
let _ = opt.ok_or(format!("{} world.", hello));
// index
let map = HashMap::<u64, u64>::new();
let _ = Some(1).unwrap_or(map[&1]);
let map = BTreeMap::<u64, u64>::new();
let _ = Some(1).unwrap_or(map[&1]);
// don't lint index vec
let vec = vec![1];
let _ = Some(1).unwrap_or(vec[1]);
}
struct Foo(u8);

View file

@ -1,5 +1,5 @@
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:32:19
--> $DIR/or_fun_call.rs:33:19
|
LL | with_const_fn.unwrap_or(Duration::from_secs(5));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Duration::from_secs(5))`
@ -7,88 +7,100 @@ LL | with_const_fn.unwrap_or(Duration::from_secs(5));
= note: `-D clippy::or-fun-call` implied by `-D warnings`
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:35:22
--> $DIR/or_fun_call.rs:36:22
|
LL | with_constructor.unwrap_or(make());
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)`
error: use of `unwrap_or` followed by a call to `new`
--> $DIR/or_fun_call.rs:38:5
--> $DIR/or_fun_call.rs:39:5
|
LL | with_new.unwrap_or(Vec::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_new.unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:41:21
--> $DIR/or_fun_call.rs:42:21
|
LL | with_const_args.unwrap_or(Vec::with_capacity(12));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Vec::with_capacity(12))`
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:44:14
--> $DIR/or_fun_call.rs:45:14
|
LL | with_err.unwrap_or(make());
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| make())`
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:47:19
--> $DIR/or_fun_call.rs:48:19
|
LL | with_err_args.unwrap_or(Vec::with_capacity(12));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| Vec::with_capacity(12))`
error: use of `unwrap_or` followed by a call to `default`
--> $DIR/or_fun_call.rs:50:5
--> $DIR/or_fun_call.rs:51:5
|
LL | with_default_trait.unwrap_or(Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_default_trait.unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `default`
--> $DIR/or_fun_call.rs:53:5
--> $DIR/or_fun_call.rs:54:5
|
LL | with_default_type.unwrap_or(u64::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_default_type.unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
--> $DIR/or_fun_call.rs:56:5
--> $DIR/or_fun_call.rs:57:5
|
LL | with_vec.unwrap_or(vec![]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `with_vec.unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:59:21
--> $DIR/or_fun_call.rs:60:21
|
LL | without_default.unwrap_or(Foo::new());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(Foo::new)`
error: use of `or_insert` followed by a function call
--> $DIR/or_fun_call.rs:62:19
--> $DIR/or_fun_call.rs:63:19
|
LL | map.entry(42).or_insert(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(String::new)`
error: use of `or_insert` followed by a function call
--> $DIR/or_fun_call.rs:65:21
--> $DIR/or_fun_call.rs:66:21
|
LL | btree.entry(42).or_insert(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_insert_with(String::new)`
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:68:21
--> $DIR/or_fun_call.rs:69:21
|
LL | let _ = stringy.unwrap_or("".to_owned());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "".to_owned())`
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:77:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:79:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
error: use of `or` followed by a function call
--> $DIR/or_fun_call.rs:93:35
--> $DIR/or_fun_call.rs:103:35
|
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
error: use of `or` followed by a function call
--> $DIR/or_fun_call.rs:97:10
--> $DIR/or_fun_call.rs:107:10
|
LL | .or(Some(Bar(b, Duration::from_secs(2))));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some(Bar(b, Duration::from_secs(2))))`
error: aborting due to 15 previous errors
error: aborting due to 17 previous errors

View file

@ -1,4 +1,5 @@
#![warn(clippy::panic_in_result_fn)]
#![allow(clippy::unnecessary_wraps)]
struct A;

View file

@ -1,5 +1,5 @@
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
--> $DIR/panic_in_result_fn.rs:6:5
--> $DIR/panic_in_result_fn.rs:7:5
|
LL | / fn result_with_panic() -> Result<bool, String> // should emit lint
LL | | {
@ -10,14 +10,14 @@ LL | | }
= note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn.rs:8:9
--> $DIR/panic_in_result_fn.rs:9:9
|
LL | panic!("error");
| ^^^^^^^^^^^^^^^^
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
--> $DIR/panic_in_result_fn.rs:11:5
--> $DIR/panic_in_result_fn.rs:12:5
|
LL | / fn result_with_unimplemented() -> Result<bool, String> // should emit lint
LL | | {
@ -27,14 +27,14 @@ LL | | }
|
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn.rs:13:9
--> $DIR/panic_in_result_fn.rs:14:9
|
LL | unimplemented!();
| ^^^^^^^^^^^^^^^^^
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
--> $DIR/panic_in_result_fn.rs:16:5
--> $DIR/panic_in_result_fn.rs:17:5
|
LL | / fn result_with_unreachable() -> Result<bool, String> // should emit lint
LL | | {
@ -44,14 +44,14 @@ LL | | }
|
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn.rs:18:9
--> $DIR/panic_in_result_fn.rs:19:9
|
LL | unreachable!();
| ^^^^^^^^^^^^^^^
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
--> $DIR/panic_in_result_fn.rs:21:5
--> $DIR/panic_in_result_fn.rs:22:5
|
LL | / fn result_with_todo() -> Result<bool, String> // should emit lint
LL | | {
@ -61,14 +61,14 @@ LL | | }
|
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn.rs:23:9
--> $DIR/panic_in_result_fn.rs:24:9
|
LL | todo!("Finish this");
| ^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
--> $DIR/panic_in_result_fn.rs:52:1
--> $DIR/panic_in_result_fn.rs:53:1
|
LL | / fn function_result_with_panic() -> Result<bool, String> // should emit lint
LL | | {
@ -78,14 +78,14 @@ LL | | }
|
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn.rs:54:5
--> $DIR/panic_in_result_fn.rs:55:5
|
LL | panic!("error");
| ^^^^^^^^^^^^^^^^
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
--> $DIR/panic_in_result_fn.rs:67:1
--> $DIR/panic_in_result_fn.rs:68:1
|
LL | / fn main() -> Result<(), String> {
LL | | todo!("finish main method");
@ -95,7 +95,7 @@ LL | | }
|
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn.rs:68:5
--> $DIR/panic_in_result_fn.rs:69:5
|
LL | todo!("finish main method");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,5 +1,6 @@
// run-rustfix
#![allow(unreachable_code)]
#![allow(clippy::unnecessary_wraps)]
fn some_func(a: Option<u32>) -> Option<u32> {
a?;

View file

@ -1,5 +1,6 @@
// run-rustfix
#![allow(unreachable_code)]
#![allow(clippy::unnecessary_wraps)]
fn some_func(a: Option<u32>) -> Option<u32> {
if a.is_none() {

View file

@ -1,5 +1,5 @@
error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:5:5
--> $DIR/question_mark.rs:6:5
|
LL | / if a.is_none() {
LL | | return None;
@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::question-mark` implied by `-D warnings`
error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:50:9
--> $DIR/question_mark.rs:51:9
|
LL | / if (self.opt).is_none() {
LL | | return None;
@ -17,7 +17,7 @@ LL | | }
| |_________^ help: replace it with: `(self.opt)?;`
error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:54:9
--> $DIR/question_mark.rs:55:9
|
LL | / if self.opt.is_none() {
LL | | return None
@ -25,7 +25,7 @@ LL | | }
| |_________^ help: replace it with: `self.opt?;`
error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:58:17
--> $DIR/question_mark.rs:59:17
|
LL | let _ = if self.opt.is_none() {
| _________________^
@ -36,7 +36,7 @@ LL | | };
| |_________^ help: replace it with: `Some(self.opt?)`
error: this if-let-else may be rewritten with the `?` operator
--> $DIR/question_mark.rs:64:17
--> $DIR/question_mark.rs:65:17
|
LL | let _ = if let Some(x) = self.opt {
| _________________^
@ -47,7 +47,7 @@ LL | | };
| |_________^ help: replace it with: `self.opt?`
error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:81:9
--> $DIR/question_mark.rs:82:9
|
LL | / if self.opt.is_none() {
LL | | return None;
@ -55,7 +55,7 @@ LL | | }
| |_________^ help: replace it with: `self.opt.as_ref()?;`
error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:89:9
--> $DIR/question_mark.rs:90:9
|
LL | / if self.opt.is_none() {
LL | | return None;
@ -63,7 +63,7 @@ LL | | }
| |_________^ help: replace it with: `self.opt.as_ref()?;`
error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:97:9
--> $DIR/question_mark.rs:98:9
|
LL | / if self.opt.is_none() {
LL | | return None;
@ -71,7 +71,7 @@ LL | | }
| |_________^ help: replace it with: `self.opt.as_ref()?;`
error: this if-let-else may be rewritten with the `?` operator
--> $DIR/question_mark.rs:104:26
--> $DIR/question_mark.rs:105:26
|
LL | let v: &Vec<_> = if let Some(ref v) = self.opt {
| __________________________^
@ -82,7 +82,7 @@ LL | | };
| |_________^ help: replace it with: `self.opt.as_ref()?`
error: this if-let-else may be rewritten with the `?` operator
--> $DIR/question_mark.rs:114:17
--> $DIR/question_mark.rs:115:17
|
LL | let v = if let Some(v) = self.opt {
| _________________^
@ -93,7 +93,7 @@ LL | | };
| |_________^ help: replace it with: `self.opt?`
error: this block may be rewritten with the `?` operator
--> $DIR/question_mark.rs:129:5
--> $DIR/question_mark.rs:130:5
|
LL | / if f().is_none() {
LL | | return None;

View file

@ -38,4 +38,9 @@ fn main() {
x >= 8 || x >= 12;
x < 12 || 12 < x;
x >= 8 || x <= 12;
// Fix #6315
let y = 3.;
(0. ..1.).contains(&y);
!(0. ..=1.).contains(&y);
}

View file

@ -38,4 +38,9 @@ fn main() {
x >= 8 || x >= 12;
x < 12 || 12 < x;
x >= 8 || x <= 12;
// Fix #6315
let y = 3.;
y >= 0. && y < 1.;
y < 0. || y > 1.;
}

View file

@ -72,5 +72,17 @@ error: manual `!RangeInclusive::contains` implementation
LL | 999 < x || 1 > x;
| ^^^^^^^^^^^^^^^^ help: use: `!(1..=999).contains(&x)`
error: aborting due to 12 previous errors
error: manual `Range::contains` implementation
--> $DIR/range_contains.rs:44:5
|
LL | y >= 0. && y < 1.;
| ^^^^^^^^^^^^^^^^^ help: use: `(0. ..1.).contains(&y)`
error: manual `!RangeInclusive::contains` implementation
--> $DIR/range_contains.rs:45:5
|
LL | y < 0. || y > 1.;
| ^^^^^^^^^^^^^^^^ help: use: `!(0. ..=1.).contains(&y)`
error: aborting due to 14 previous errors

View file

@ -7,6 +7,7 @@
unused_must_use,
clippy::needless_bool,
clippy::match_like_matches_macro,
clippy::unnecessary_wraps,
deprecated
)]

View file

@ -7,6 +7,7 @@
unused_must_use,
clippy::needless_bool,
clippy::match_like_matches_macro,
clippy::unnecessary_wraps,
deprecated
)]

View file

@ -1,5 +1,5 @@
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:15:12
--> $DIR/redundant_pattern_matching.rs:16:12
|
LL | if let Ok(_) = &result {}
| -------^^^^^---------- help: try this: `if result.is_ok()`
@ -7,31 +7,31 @@ LL | if let Ok(_) = &result {}
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:17:12
--> $DIR/redundant_pattern_matching.rs:18:12
|
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
| -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching.rs:19:12
--> $DIR/redundant_pattern_matching.rs:20:12
|
LL | if let Err(_) = Err::<i32, i32>(42) {}
| -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:21:15
--> $DIR/redundant_pattern_matching.rs:22:15
|
LL | while let Ok(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching.rs:23:15
--> $DIR/redundant_pattern_matching.rs:24:15
|
LL | while let Err(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:33:5
--> $DIR/redundant_pattern_matching.rs:34:5
|
LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => true,
@ -40,7 +40,7 @@ LL | | };
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching.rs:38:5
--> $DIR/redundant_pattern_matching.rs:39:5
|
LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => false,
@ -49,7 +49,7 @@ LL | | };
| |_____^ help: try this: `Ok::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching.rs:43:5
--> $DIR/redundant_pattern_matching.rs:44:5
|
LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => false,
@ -58,7 +58,7 @@ LL | | };
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:48:5
--> $DIR/redundant_pattern_matching.rs:49:5
|
LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => true,
@ -67,73 +67,73 @@ LL | | };
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:53:20
--> $DIR/redundant_pattern_matching.rs:54:20
|
LL | let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
| -------^^^^^--------------------- help: try this: `if Ok::<usize, ()>(4).is_ok()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:59:20
--> $DIR/redundant_pattern_matching.rs:60:20
|
LL | let _ = if let Ok(_) = gen_res() {
| -------^^^^^------------ help: try this: `if gen_res().is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching.rs:61:19
--> $DIR/redundant_pattern_matching.rs:62:19
|
LL | } else if let Err(_) = gen_res() {
| -------^^^^^^------------ help: try this: `if gen_res().is_err()`
error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching.rs:84:19
--> $DIR/redundant_pattern_matching.rs:85:19
|
LL | while let Some(_) = r#try!(result_opt()) {}
| ----------^^^^^^^----------------------- help: try this: `while r#try!(result_opt()).is_some()`
error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching.rs:85:16
--> $DIR/redundant_pattern_matching.rs:86:16
|
LL | if let Some(_) = r#try!(result_opt()) {}
| -------^^^^^^^----------------------- help: try this: `if r#try!(result_opt()).is_some()`
error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching.rs:91:12
--> $DIR/redundant_pattern_matching.rs:92:12
|
LL | if let Some(_) = m!() {}
| -------^^^^^^^------- help: try this: `if m!().is_some()`
error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching.rs:92:15
--> $DIR/redundant_pattern_matching.rs:93:15
|
LL | while let Some(_) = m!() {}
| ----------^^^^^^^------- help: try this: `while m!().is_some()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:110:12
--> $DIR/redundant_pattern_matching.rs:111:12
|
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
| -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching.rs:112:12
--> $DIR/redundant_pattern_matching.rs:113:12
|
LL | if let Err(_) = Err::<i32, i32>(42) {}
| -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:114:15
--> $DIR/redundant_pattern_matching.rs:115:15
|
LL | while let Ok(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching.rs:116:15
--> $DIR/redundant_pattern_matching.rs:117:15
|
LL | while let Err(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_err()`
error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:118:5
--> $DIR/redundant_pattern_matching.rs:119:5
|
LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => true,
@ -142,7 +142,7 @@ LL | | };
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching.rs:123:5
--> $DIR/redundant_pattern_matching.rs:124:5
|
LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => false,

View file

@ -1,3 +1,4 @@
#![allow(clippy::unnecessary_wraps)]
#[warn(clippy::result_unit_err)]
#[allow(unused)]

View file

@ -1,5 +1,5 @@
error: this returns a `Result<_, ()>
--> $DIR/result_unit_error.rs:4:1
--> $DIR/result_unit_error.rs:5:1
|
LL | pub fn returns_unit_error() -> Result<u32, ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -8,7 +8,7 @@ LL | pub fn returns_unit_error() -> Result<u32, ()> {
= help: use a custom Error type instead
error: this returns a `Result<_, ()>
--> $DIR/result_unit_error.rs:13:5
--> $DIR/result_unit_error.rs:14:5
|
LL | fn get_that_error(&self) -> Result<bool, ()>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -16,7 +16,7 @@ LL | fn get_that_error(&self) -> Result<bool, ()>;
= help: use a custom Error type instead
error: this returns a `Result<_, ()>
--> $DIR/result_unit_error.rs:15:5
--> $DIR/result_unit_error.rs:16:5
|
LL | fn get_this_one_too(&self) -> Result<bool, ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -24,7 +24,7 @@ LL | fn get_this_one_too(&self) -> Result<bool, ()> {
= help: use a custom Error type instead
error: this returns a `Result<_, ()>
--> $DIR/result_unit_error.rs:33:5
--> $DIR/result_unit_error.rs:34:5
|
LL | pub fn unit_error(&self) -> Result<usize, ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -0,0 +1,38 @@
// aux-build:option_helpers.rs
extern crate option_helpers;
use option_helpers::IteratorFalsePositives;
#[warn(clippy::search_is_some)]
#[rustfmt::skip]
fn main() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
let y = &&42;
// Check `find().is_some()`, multi-line case.
let _ = v.iter().find(|&x| {
*x < 0
}
).is_some();
// Check `position().is_some()`, multi-line case.
let _ = v.iter().position(|&x| {
x < 0
}
).is_some();
// Check `rposition().is_some()`, multi-line case.
let _ = v.iter().rposition(|&x| {
x < 0
}
).is_some();
// Check that we don't lint if the caller is not an `Iterator` or string
let falsepos = IteratorFalsePositives { foo: 0 };
let _ = falsepos.find().is_some();
let _ = falsepos.position().is_some();
let _ = falsepos.rposition().is_some();
// check that we don't lint if `find()` is called with
// `Pattern` that is not a string
let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_some();
}

View file

@ -0,0 +1,39 @@
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some.rs:13:13
|
LL | let _ = v.iter().find(|&x| {
| _____________^
LL | | *x < 0
LL | | }
LL | | ).is_some();
| |______________________________^
|
= note: `-D clippy::search-is-some` implied by `-D warnings`
= help: this is more succinctly expressed by calling `any()`
error: called `is_some()` after searching an `Iterator` with `position`
--> $DIR/search_is_some.rs:19:13
|
LL | let _ = v.iter().position(|&x| {
| _____________^
LL | | x < 0
LL | | }
LL | | ).is_some();
| |______________________________^
|
= help: this is more succinctly expressed by calling `any()`
error: called `is_some()` after searching an `Iterator` with `rposition`
--> $DIR/search_is_some.rs:25:13
|
LL | let _ = v.iter().rposition(|&x| {
| _____________^
LL | | x < 0
LL | | }
LL | | ).is_some();
| |______________________________^
|
= help: this is more succinctly expressed by calling `any()`
error: aborting due to 3 previous errors

View file

@ -0,0 +1,35 @@
// run-rustfix
#![warn(clippy::search_is_some)]
fn main() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
let y = &&42;
// Check `find().is_some()`, single-line case.
let _ = v.iter().any(|x| *x < 0);
let _ = (0..1).any(|x| **y == x); // one dereference less
let _ = (0..1).any(|x| x == 0);
let _ = v.iter().any(|x| *x == 0);
// Check `position().is_some()`, single-line case.
let _ = v.iter().any(|&x| x < 0);
// Check `rposition().is_some()`, single-line case.
let _ = v.iter().any(|&x| x < 0);
let s1 = String::from("hello world");
let s2 = String::from("world");
// caller of `find()` is a `&`static str`
let _ = "hello world".contains("world");
let _ = "hello world".contains(&s2);
let _ = "hello world".contains(&s2[2..]);
// caller of `find()` is a `String`
let _ = s1.contains("world");
let _ = s1.contains(&s2);
let _ = s1.contains(&s2[2..]);
// caller of `find()` is slice of `String`
let _ = s1[2..].contains("world");
let _ = s1[2..].contains(&s2);
let _ = s1[2..].contains(&s2[2..]);
}

View file

@ -0,0 +1,35 @@
// run-rustfix
#![warn(clippy::search_is_some)]
fn main() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
let y = &&42;
// Check `find().is_some()`, single-line case.
let _ = v.iter().find(|&x| *x < 0).is_some();
let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
let _ = (0..1).find(|x| *x == 0).is_some();
let _ = v.iter().find(|x| **x == 0).is_some();
// Check `position().is_some()`, single-line case.
let _ = v.iter().position(|&x| x < 0).is_some();
// Check `rposition().is_some()`, single-line case.
let _ = v.iter().rposition(|&x| x < 0).is_some();
let s1 = String::from("hello world");
let s2 = String::from("world");
// caller of `find()` is a `&`static str`
let _ = "hello world".find("world").is_some();
let _ = "hello world".find(&s2).is_some();
let _ = "hello world".find(&s2[2..]).is_some();
// caller of `find()` is a `String`
let _ = s1.find("world").is_some();
let _ = s1.find(&s2).is_some();
let _ = s1.find(&s2[2..]).is_some();
// caller of `find()` is slice of `String`
let _ = s1[2..].find("world").is_some();
let _ = s1[2..].find(&s2).is_some();
let _ = s1[2..].find(&s2[2..]).is_some();
}

View file

@ -0,0 +1,94 @@
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:10:22
|
LL | let _ = v.iter().find(|&x| *x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x < 0)`
|
= note: `-D clippy::search-is-some` implied by `-D warnings`
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:11:20
|
LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| **y == x)`
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:12:20
|
LL | let _ = (0..1).find(|x| *x == 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| x == 0)`
error: called `is_some()` after searching an `Iterator` with `find`
--> $DIR/search_is_some_fixable.rs:13:22
|
LL | let _ = v.iter().find(|x| **x == 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|x| *x == 0)`
error: called `is_some()` after searching an `Iterator` with `position`
--> $DIR/search_is_some_fixable.rs:16:22
|
LL | let _ = v.iter().position(|&x| x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)`
error: called `is_some()` after searching an `Iterator` with `rposition`
--> $DIR/search_is_some_fixable.rs:19:22
|
LL | let _ = v.iter().rposition(|&x| x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `any()` instead: `any(|&x| x < 0)`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:24:27
|
LL | let _ = "hello world".find("world").is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:25:27
|
LL | let _ = "hello world".find(&s2).is_some();
| ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:26:27
|
LL | let _ = "hello world".find(&s2[2..]).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:28:16
|
LL | let _ = s1.find("world").is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:29:16
|
LL | let _ = s1.find(&s2).is_some();
| ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:30:16
|
LL | let _ = s1.find(&s2[2..]).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:32:21
|
LL | let _ = s1[2..].find("world").is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains("world")`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:33:21
|
LL | let _ = s1[2..].find(&s2).is_some();
| ^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2)`
error: called `is_some()` after calling `find()` on a string
--> $DIR/search_is_some_fixable.rs:34:21
|
LL | let _ = s1[2..].find(&s2[2..]).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `contains()` instead: `contains(&s2[2..])`
error: aborting due to 15 previous errors

View file

@ -0,0 +1,6 @@
// run-rustfix
#![warn(clippy::string_from_utf8_as_bytes)]
fn main() {
let _ = Some(&"Hello World!"[6..11]);
}

View file

@ -0,0 +1,6 @@
// run-rustfix
#![warn(clippy::string_from_utf8_as_bytes)]
fn main() {
let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]);
}

View file

@ -0,0 +1,10 @@
error: calling a slice of `as_bytes()` with `from_utf8` should be not necessary
--> $DIR/string_from_utf8_as_bytes.rs:5:13
|
LL | let _ = std::str::from_utf8(&"Hello World!".as_bytes()[6..11]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(&"Hello World!"[6..11])`
|
= note: `-D clippy::string-from-utf8-as-bytes` implied by `-D warnings`
error: aborting due to previous error

View file

@ -1,5 +1,4 @@
#![warn(clippy::temporary_assignment)]
#![allow(const_item_mutation)]
use std::ops::{Deref, DerefMut};

View file

@ -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;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -7,7 +7,7 @@ LL | Struct { field: 0 }.field = 1;
= note: `-D clippy::temporary-assignment` implied by `-D warnings`
error: assignment to temporary
--> $DIR/temporary_assignment.rs:49:5
--> $DIR/temporary_assignment.rs:48:5
|
LL | / MultiStruct {
LL | | structure: Struct { field: 0 },
@ -17,13 +17,13 @@ LL | | .field = 1;
| |______________^
error: assignment to temporary
--> $DIR/temporary_assignment.rs:54:5
--> $DIR/temporary_assignment.rs:53:5
|
LL | ArrayStruct { array: [0] }.array[0] = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: assignment to temporary
--> $DIR/temporary_assignment.rs:55:5
--> $DIR/temporary_assignment.rs:54:5
|
LL | (0, 0).0 = 1;
| ^^^^^^^^^^^^

View file

@ -2,6 +2,7 @@
// aux-build:macro_rules.rs
#![deny(clippy::try_err)]
#![allow(clippy::unnecessary_wraps)]
#[macro_use]
extern crate macro_rules;
@ -78,12 +79,46 @@ fn nested_error() -> Result<i32, i32> {
Ok(1)
}
// Bad suggestion when in macro (see #6242)
macro_rules! try_validation {
($e: expr) => {{
match $e {
Ok(_) => 0,
Err(_) => return Err(1),
}
}};
}
macro_rules! ret_one {
() => {
1
};
}
macro_rules! try_validation_in_macro {
($e: expr) => {{
match $e {
Ok(_) => 0,
Err(_) => return Err(ret_one!()),
}
}};
}
fn calling_macro() -> Result<i32, i32> {
// macro
try_validation!(Ok::<_, i32>(5));
// `Err` arg is another macro
try_validation_in_macro!(Ok::<_, i32>(5));
Ok(5)
}
fn main() {
basic_test().unwrap();
into_test().unwrap();
negative_test().unwrap();
closure_matches_test().unwrap();
closure_into_test().unwrap();
calling_macro().unwrap();
// We don't want to lint in external macros
try_err!();

View file

@ -2,6 +2,7 @@
// aux-build:macro_rules.rs
#![deny(clippy::try_err)]
#![allow(clippy::unnecessary_wraps)]
#[macro_use]
extern crate macro_rules;
@ -78,12 +79,46 @@ fn nested_error() -> Result<i32, i32> {
Ok(1)
}
// Bad suggestion when in macro (see #6242)
macro_rules! try_validation {
($e: expr) => {{
match $e {
Ok(_) => 0,
Err(_) => Err(1)?,
}
}};
}
macro_rules! ret_one {
() => {
1
};
}
macro_rules! try_validation_in_macro {
($e: expr) => {{
match $e {
Ok(_) => 0,
Err(_) => Err(ret_one!())?,
}
}};
}
fn calling_macro() -> Result<i32, i32> {
// macro
try_validation!(Ok::<_, i32>(5));
// `Err` arg is another macro
try_validation_in_macro!(Ok::<_, i32>(5));
Ok(5)
}
fn main() {
basic_test().unwrap();
into_test().unwrap();
negative_test().unwrap();
closure_matches_test().unwrap();
closure_into_test().unwrap();
calling_macro().unwrap();
// We don't want to lint in external macros
try_err!();

View file

@ -1,5 +1,5 @@
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:18:9
--> $DIR/try_err.rs:19:9
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err)`
@ -11,46 +11,68 @@ LL | #![deny(clippy::try_err)]
| ^^^^^^^^^^^^^^^
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:28:9
--> $DIR/try_err.rs:29:9
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err.into())`
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:48:17
--> $DIR/try_err.rs:49:17
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err)`
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:67:17
--> $DIR/try_err.rs:68:17
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err.into())`
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:106:9
--> $DIR/try_err.rs:87:23
|
LL | Err(_) => Err(1)?,
| ^^^^^^^ help: try this: `return Err(1)`
...
LL | try_validation!(Ok::<_, i32>(5));
| --------------------------------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:102:23
|
LL | Err(_) => Err(ret_one!())?,
| ^^^^^^^^^^^^^^^^ help: try this: `return Err(ret_one!())`
...
LL | try_validation_in_macro!(Ok::<_, i32>(5));
| ------------------------------------------ in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:141:9
|
LL | Err(foo!())?;
| ^^^^^^^^^^^^ help: try this: `return Err(foo!())`
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:113:9
--> $DIR/try_err.rs:148:9
|
LL | Err(io::ErrorKind::WriteZero)?
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))`
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:115:9
--> $DIR/try_err.rs:150:9
|
LL | Err(io::Error::new(io::ErrorKind::InvalidInput, "error"))?
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Err(io::Error::new(io::ErrorKind::InvalidInput, "error")))`
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:123:9
--> $DIR/try_err.rs:158:9
|
LL | Err(io::ErrorKind::NotFound)?
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into())))`
error: aborting due to 8 previous errors
error: aborting due to 10 previous errors

View file

@ -4,6 +4,7 @@
unused_must_use,
unused_variables,
clippy::unused_unit,
clippy::unnecessary_wraps,
clippy::or_fun_call
)]

View file

@ -1,5 +1,5 @@
error: passing a unit value to a function
--> $DIR/unit_arg.rs:29:5
--> $DIR/unit_arg.rs:30:5
|
LL | / foo({
LL | | 1;
@ -20,7 +20,7 @@ LL | foo(());
|
error: passing a unit value to a function
--> $DIR/unit_arg.rs:32:5
--> $DIR/unit_arg.rs:33:5
|
LL | foo(foo(1));
| ^^^^^^^^^^^
@ -32,7 +32,7 @@ LL | foo(());
|
error: passing a unit value to a function
--> $DIR/unit_arg.rs:33:5
--> $DIR/unit_arg.rs:34:5
|
LL | / foo({
LL | | foo(1);
@ -54,7 +54,7 @@ LL | foo(());
|
error: passing a unit value to a function
--> $DIR/unit_arg.rs:38:5
--> $DIR/unit_arg.rs:39:5
|
LL | / b.bar({
LL | | 1;
@ -74,7 +74,7 @@ LL | b.bar(());
|
error: passing unit values to a function
--> $DIR/unit_arg.rs:41:5
--> $DIR/unit_arg.rs:42:5
|
LL | taking_multiple_units(foo(0), foo(1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -87,7 +87,7 @@ LL | taking_multiple_units((), ());
|
error: passing unit values to a function
--> $DIR/unit_arg.rs:42:5
--> $DIR/unit_arg.rs:43:5
|
LL | / taking_multiple_units(foo(0), {
LL | | foo(1);
@ -110,7 +110,7 @@ LL | taking_multiple_units((), ());
|
error: passing unit values to a function
--> $DIR/unit_arg.rs:46:5
--> $DIR/unit_arg.rs:47:5
|
LL | / taking_multiple_units(
LL | | {
@ -140,7 +140,7 @@ LL | foo(2);
...
error: passing a unit value to a function
--> $DIR/unit_arg.rs:57:13
--> $DIR/unit_arg.rs:58:13
|
LL | None.or(Some(foo(2)));
| ^^^^^^^^^^^^
@ -154,7 +154,7 @@ LL | });
|
error: passing a unit value to a function
--> $DIR/unit_arg.rs:60:5
--> $DIR/unit_arg.rs:61:5
|
LL | foo(foo(()))
| ^^^^^^^^^^^^
@ -166,7 +166,7 @@ LL | foo(())
|
error: passing a unit value to a function
--> $DIR/unit_arg.rs:93:5
--> $DIR/unit_arg.rs:94:5
|
LL | Some(foo(1))
| ^^^^^^^^^^^^

View file

@ -20,4 +20,7 @@ fn main() {
foo!(a, i32);
foo!(b, f32);
foo!(c, f64);
// do not lint cast to cfg-dependant type
1 as std::os::raw::c_char;
}

View file

@ -1,7 +1,7 @@
// does not test any rustfixable lints
#![warn(clippy::clone_on_ref_ptr)]
#![allow(unused, clippy::redundant_clone)]
#![allow(unused, clippy::redundant_clone, clippy::unnecessary_wraps)]
use std::cell::RefCell;
use std::rc::{self, Rc};

View file

@ -0,0 +1,18 @@
#![warn(clippy::unnecessary_lazy_evaluations)]
struct Deep(Option<usize>);
#[derive(Copy, Clone)]
struct SomeStruct {
some_field: usize,
}
fn main() {
// fix will break type inference
let _ = Ok(1).unwrap_or_else(|()| 2);
mod e {
pub struct E;
}
let _ = Ok(1).unwrap_or_else(|e::E| 2);
let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2);
}

View file

@ -0,0 +1,22 @@
error: unnecessary closure used to substitute value for `Result::Err`
--> $DIR/unnecessary_lazy_eval_unfixable.rs:12:13
|
LL | let _ = Ok(1).unwrap_or_else(|()| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
|
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
error: unnecessary closure used to substitute value for `Result::Err`
--> $DIR/unnecessary_lazy_eval_unfixable.rs:16:13
|
LL | let _ = Ok(1).unwrap_or_else(|e::E| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
error: unnecessary closure used to substitute value for `Result::Err`
--> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13
|
LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)`
error: aborting due to 3 previous errors

View file

@ -0,0 +1,116 @@
#![warn(clippy::unnecessary_wraps)]
#![allow(clippy::no_effect)]
#![allow(clippy::needless_return)]
#![allow(clippy::if_same_then_else)]
#![allow(dead_code)]
// should be linted
fn func1(a: bool, b: bool) -> Option<i32> {
if a && b {
return Some(42);
}
if a {
Some(-1);
Some(2)
} else {
return Some(1337);
}
}
// should be linted
fn func2(a: bool, b: bool) -> Option<i32> {
if a && b {
return Some(10);
}
if a {
Some(20)
} else {
Some(30)
}
}
// public fns should not be linted
pub fn func3(a: bool) -> Option<i32> {
if a {
Some(1)
} else {
Some(1)
}
}
// should not be linted
fn func4(a: bool) -> Option<i32> {
if a {
Some(1)
} else {
None
}
}
// should be linted
fn func5() -> Option<i32> {
Some(1)
}
// should not be linted
fn func6() -> Option<i32> {
None
}
// should be linted
fn func7() -> Result<i32, ()> {
Ok(1)
}
// should not be linted
fn func8(a: bool) -> Result<i32, ()> {
if a {
Ok(1)
} else {
Err(())
}
}
// should not be linted
fn func9(a: bool) -> Result<i32, ()> {
Err(())
}
// should not be linted
fn func10() -> Option<()> {
unimplemented!()
}
struct A;
impl A {
// should not be linted
pub fn func11() -> Option<i32> {
Some(1)
}
// should be linted
fn func12() -> Option<i32> {
Some(1)
}
}
trait B {
// trait impls are not linted
fn func13() -> Option<i32> {
Some(1)
}
}
impl B for A {
// trait impls are not linted
fn func13() -> Option<i32> {
Some(0)
}
}
fn main() {
// method calls are not linted
func1(true, true);
func2(true, true);
}

View file

@ -0,0 +1,106 @@
error: this function's return value is unnecessarily wrapped by `Option`
--> $DIR/unnecessary_wraps.rs:8:1
|
LL | / fn func1(a: bool, b: bool) -> Option<i32> {
LL | | if a && b {
LL | | return Some(42);
LL | | }
... |
LL | | }
LL | | }
| |_^
|
= note: `-D clippy::unnecessary-wraps` implied by `-D warnings`
help: remove `Option` from the return type...
|
LL | fn func1(a: bool, b: bool) -> i32 {
| ^^^
help: ...and change the returning expressions
|
LL | return 42;
LL | }
LL | if a {
LL | Some(-1);
LL | 2
LL | } else {
...
error: this function's return value is unnecessarily wrapped by `Option`
--> $DIR/unnecessary_wraps.rs:21:1
|
LL | / fn func2(a: bool, b: bool) -> Option<i32> {
LL | | if a && b {
LL | | return Some(10);
LL | | }
... |
LL | | }
LL | | }
| |_^
|
help: remove `Option` from the return type...
|
LL | fn func2(a: bool, b: bool) -> i32 {
| ^^^
help: ...and change the returning expressions
|
LL | return 10;
LL | }
LL | if a {
LL | 20
LL | } else {
LL | 30
|
error: this function's return value is unnecessarily wrapped by `Option`
--> $DIR/unnecessary_wraps.rs:51:1
|
LL | / fn func5() -> Option<i32> {
LL | | Some(1)
LL | | }
| |_^
|
help: remove `Option` from the return type...
|
LL | fn func5() -> i32 {
| ^^^
help: ...and change the returning expressions
|
LL | 1
|
error: this function's return value is unnecessarily wrapped by `Result`
--> $DIR/unnecessary_wraps.rs:61:1
|
LL | / fn func7() -> Result<i32, ()> {
LL | | Ok(1)
LL | | }
| |_^
|
help: remove `Result` from the return type...
|
LL | fn func7() -> i32 {
| ^^^
help: ...and change the returning expressions
|
LL | 1
|
error: this function's return value is unnecessarily wrapped by `Option`
--> $DIR/unnecessary_wraps.rs:93:5
|
LL | / fn func12() -> Option<i32> {
LL | | Some(1)
LL | | }
| |_____^
|
help: remove `Option` from the return type...
|
LL | fn func12() -> i32 {
| ^^^
help: ...and change the returning expressions
|
LL | 1
|
error: aborting due to 5 previous errors

Some files were not shown because too many files have changed in this diff Show more