mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Add version = "Two" to rustfmt.toml
Ignore UI tests since this change makes rustfmt less friendly with UI test comments.
This commit is contained in:
parent
5ae1e17e81
commit
ada8c72f3f
@ -123,13 +123,13 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType
|
||||
}
|
||||
if is_refcell_ref(cx, adt.did) {
|
||||
span_lint_and_note(
|
||||
cx,
|
||||
AWAIT_HOLDING_REFCELL_REF,
|
||||
ty_cause.span,
|
||||
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await",
|
||||
ty_cause.scope_span.or(Some(span)),
|
||||
"these are all the await points this ref is held through",
|
||||
);
|
||||
cx,
|
||||
AWAIT_HOLDING_REFCELL_REF,
|
||||
ty_cause.span,
|
||||
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await",
|
||||
ty_cause.scope_span.or(Some(span)),
|
||||
"these are all the await points this ref is held through",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,11 +145,7 @@ fn count_digits(s: &str) -> usize {
|
||||
.take_while(|c| *c != 'e' && *c != 'E')
|
||||
.fold(0, |count, c| {
|
||||
// leading zeros
|
||||
if c == '0' && count == 0 {
|
||||
count
|
||||
} else {
|
||||
count + 1
|
||||
}
|
||||
if c == '0' && count == 0 { count } else { count + 1 }
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -89,11 +89,7 @@ impl Finiteness {
|
||||
impl From<bool> for Finiteness {
|
||||
#[must_use]
|
||||
fn from(b: bool) -> Self {
|
||||
if b {
|
||||
Infinite
|
||||
} else {
|
||||
Finite
|
||||
}
|
||||
if b { Infinite } else { Finite }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
|
||||
self_type.to_string()
|
||||
),
|
||||
None,
|
||||
&format!("remove the inherent method from type `{}`", self_type.to_string())
|
||||
&format!("remove the inherent method from type `{}`", self_type.to_string()),
|
||||
);
|
||||
} else {
|
||||
span_lint_and_help(
|
||||
|
@ -3158,11 +3158,7 @@ fn detect_iter_and_into_iters<'tcx>(block: &'tcx Block<'tcx>, identifier: Ident)
|
||||
seen_other: false,
|
||||
};
|
||||
visitor.visit_block(block);
|
||||
if visitor.seen_other {
|
||||
None
|
||||
} else {
|
||||
Some(visitor.uses)
|
||||
}
|
||||
if visitor.seen_other { None } else { Some(visitor.uses) }
|
||||
}
|
||||
|
||||
fn shorten_needless_collect_span(expr: &Expr<'_>) -> Span {
|
||||
|
@ -73,11 +73,7 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn expr_span(&self) -> Option<Span> {
|
||||
if self.found {
|
||||
self.expr_span
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if self.found { self.expr_span } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,11 +416,7 @@ fn erode_from_back(s: &str) -> String {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ret.is_empty() {
|
||||
s.to_string()
|
||||
} else {
|
||||
ret
|
||||
}
|
||||
if ret.is_empty() { s.to_string() } else { ret }
|
||||
}
|
||||
|
||||
fn span_of_first_expr_in_block(block: &ast::Block) -> Option<Span> {
|
||||
|
@ -69,15 +69,11 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec
|
||||
..
|
||||
} = *span
|
||||
{
|
||||
if lit {
|
||||
Argument::True
|
||||
} else {
|
||||
Argument::False
|
||||
}
|
||||
if lit { Argument::True } else { Argument::False }
|
||||
} else {
|
||||
return; // The function is called with a literal
|
||||
// which is not a boolean literal. This is theoretically
|
||||
// possible, but not very likely.
|
||||
// The function is called with a literal which is not a boolean literal.
|
||||
// This is theoretically possible, but not very likely.
|
||||
return;
|
||||
}
|
||||
},
|
||||
_ => Argument::Unknown,
|
||||
|
@ -25,11 +25,7 @@ pub fn until(s: &str) -> usize {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
if up {
|
||||
last_i
|
||||
} else {
|
||||
s.len()
|
||||
}
|
||||
if up { last_i } else { s.len() }
|
||||
}
|
||||
|
||||
/// Returns index of the last camel-case component of `s`.
|
||||
|
@ -1563,12 +1563,12 @@ pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool {
|
||||
/// ```
|
||||
pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool {
|
||||
use rustc_trait_selection::traits;
|
||||
let predicates =
|
||||
cx.tcx
|
||||
.predicates_of(did)
|
||||
.predicates
|
||||
.iter()
|
||||
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
|
||||
let predicates = cx
|
||||
.tcx
|
||||
.predicates_of(did)
|
||||
.predicates
|
||||
.iter()
|
||||
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
|
||||
traits::impossible_predicates(
|
||||
cx.tcx,
|
||||
traits::elaborate_predicates(cx.tcx, predicates)
|
||||
|
@ -36,11 +36,7 @@ fn extract_clone_suggestions<'tcx>(
|
||||
abort: false,
|
||||
};
|
||||
visitor.visit_body(body);
|
||||
if visitor.abort {
|
||||
None
|
||||
} else {
|
||||
Some(visitor.spans)
|
||||
}
|
||||
if visitor.abort { None } else { Some(visitor.spans) }
|
||||
}
|
||||
|
||||
struct PtrCloneVisitor<'a, 'tcx> {
|
||||
|
@ -4,3 +4,4 @@ match_block_trailing_comma = true
|
||||
wrap_comments = true
|
||||
edition = "2018"
|
||||
error_on_line_overflow = true
|
||||
version = "Two"
|
||||
|
@ -98,7 +98,9 @@ fn lint_message_convention() {
|
||||
eprintln!("\n\n");
|
||||
});
|
||||
|
||||
eprintln!("\n\n\nLint message should not start with a capital letter and should not have punctuation at the end of the message unless multiple sentences are needed.");
|
||||
eprintln!(
|
||||
"\n\n\nLint message should not start with a capital letter and should not have punctuation at the end of the message unless multiple sentences are needed."
|
||||
);
|
||||
eprintln!("Check out the rustc-dev-guide for more information:");
|
||||
eprintln!("https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure\n\n\n");
|
||||
|
||||
|
@ -16,7 +16,8 @@ enum Flags {
|
||||
FIN,
|
||||
}
|
||||
|
||||
struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
|
||||
// `GccLlvmSomething`
|
||||
// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
|
||||
// `GccLlvmSomething`
|
||||
struct GCCLLVMSomething;
|
||||
|
||||
fn main() {}
|
||||
|
@ -61,9 +61,9 @@ LL | FIN,
|
||||
| ^^^ help: consider making the acronym lowercase, except the initial letter: `Fin`
|
||||
|
||||
error: name `GCCLLVMSomething` contains a capitalized acronym
|
||||
--> $DIR/upper_case_acronyms.rs:19:8
|
||||
--> $DIR/upper_case_acronyms.rs:21:8
|
||||
|
|
||||
LL | struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
|
||||
LL | struct GCCLLVMSomething;
|
||||
| ^^^^^^^^^^^^^^^^ help: consider making the acronym lowercase, except the initial letter: `GccllvmSomething`
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
@ -23,11 +23,7 @@ macro_rules! try_err {
|
||||
pub fn try_err_fn() -> Result<i32, i32> {
|
||||
let err: i32 = 1;
|
||||
// To avoid warnings during rustfix
|
||||
if true {
|
||||
Err(err)?
|
||||
} else {
|
||||
Ok(2)
|
||||
}
|
||||
if true { Err(err)? } else { Ok(2) }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -4,9 +4,7 @@
|
||||
#![warn(clippy::nonminimal_bool)]
|
||||
|
||||
macro_rules! blocky {
|
||||
() => {{
|
||||
true
|
||||
}};
|
||||
() => {{ true }};
|
||||
}
|
||||
|
||||
macro_rules! blocky_too {
|
||||
@ -34,20 +32,12 @@ fn condition_has_block() -> i32 {
|
||||
}
|
||||
|
||||
fn condition_has_block_with_single_expression() -> i32 {
|
||||
if true {
|
||||
6
|
||||
} else {
|
||||
10
|
||||
}
|
||||
if true { 6 } else { 10 }
|
||||
}
|
||||
|
||||
fn condition_is_normal() -> i32 {
|
||||
let x = 3;
|
||||
if x == 3 {
|
||||
6
|
||||
} else {
|
||||
10
|
||||
}
|
||||
if x == 3 { 6 } else { 10 }
|
||||
}
|
||||
|
||||
fn condition_is_unsafe_block() {
|
||||
@ -61,14 +51,15 @@ fn condition_is_unsafe_block() {
|
||||
|
||||
fn block_in_assert() {
|
||||
let opt = Some(42);
|
||||
assert!(opt
|
||||
.as_ref()
|
||||
.map(|val| {
|
||||
let mut v = val * 2;
|
||||
v -= 1;
|
||||
v * 3
|
||||
})
|
||||
.is_some());
|
||||
assert!(
|
||||
opt.as_ref()
|
||||
.map(|val| {
|
||||
let mut v = val * 2;
|
||||
v -= 1;
|
||||
v * 3
|
||||
})
|
||||
.is_some()
|
||||
);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -4,9 +4,7 @@
|
||||
#![warn(clippy::nonminimal_bool)]
|
||||
|
||||
macro_rules! blocky {
|
||||
() => {{
|
||||
true
|
||||
}};
|
||||
() => {{ true }};
|
||||
}
|
||||
|
||||
macro_rules! blocky_too {
|
||||
@ -34,20 +32,12 @@ fn condition_has_block() -> i32 {
|
||||
}
|
||||
|
||||
fn condition_has_block_with_single_expression() -> i32 {
|
||||
if { true } {
|
||||
6
|
||||
} else {
|
||||
10
|
||||
}
|
||||
if { true } { 6 } else { 10 }
|
||||
}
|
||||
|
||||
fn condition_is_normal() -> i32 {
|
||||
let x = 3;
|
||||
if true && x == 3 {
|
||||
6
|
||||
} else {
|
||||
10
|
||||
}
|
||||
if true && x == 3 { 6 } else { 10 }
|
||||
}
|
||||
|
||||
fn condition_is_unsafe_block() {
|
||||
@ -61,14 +51,15 @@ fn condition_is_unsafe_block() {
|
||||
|
||||
fn block_in_assert() {
|
||||
let opt = Some(42);
|
||||
assert!(opt
|
||||
.as_ref()
|
||||
.map(|val| {
|
||||
let mut v = val * 2;
|
||||
v -= 1;
|
||||
v * 3
|
||||
})
|
||||
.is_some());
|
||||
assert!(
|
||||
opt.as_ref()
|
||||
.map(|val| {
|
||||
let mut v = val * 2;
|
||||
v -= 1;
|
||||
v * 3
|
||||
})
|
||||
.is_some()
|
||||
);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
|
||||
--> $DIR/blocks_in_if_conditions.rs:26:5
|
||||
--> $DIR/blocks_in_if_conditions.rs:24:5
|
||||
|
|
||||
LL | / if {
|
||||
LL | | let x = 3;
|
||||
@ -17,15 +17,15 @@ LL | }; if res {
|
||||
|
|
||||
|
||||
error: omit braces around single expression condition
|
||||
--> $DIR/blocks_in_if_conditions.rs:37:8
|
||||
--> $DIR/blocks_in_if_conditions.rs:35:8
|
||||
|
|
||||
LL | if { true } {
|
||||
LL | if { true } { 6 } else { 10 }
|
||||
| ^^^^^^^^ help: try: `true`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/blocks_in_if_conditions.rs:46:8
|
||||
--> $DIR/blocks_in_if_conditions.rs:40:8
|
||||
|
|
||||
LL | if true && x == 3 {
|
||||
LL | if true && x == 3 { 6 } else { 10 }
|
||||
| ^^^^^^^^^^^^^^ help: try: `x == 3`
|
||||
|
|
||||
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
|
||||
|
@ -66,14 +66,16 @@ fn main() {
|
||||
}
|
||||
if x.is_ok() {
|
||||
x = Err(());
|
||||
x.unwrap(); // not unnecessary because of mutation of x
|
||||
// it will always panic but the lint is not smart enough to see this (it only
|
||||
// checks if conditions).
|
||||
// not unnecessary because of mutation of x
|
||||
// it will always panic but the lint is not smart enough to see this (it only
|
||||
// checks if conditions).
|
||||
x.unwrap();
|
||||
} else {
|
||||
x = Ok(());
|
||||
x.unwrap_err(); // not unnecessary because of mutation of x
|
||||
// it will always panic but the lint is not smart enough to see this (it
|
||||
// only checks if conditions).
|
||||
// not unnecessary because of mutation of x
|
||||
// it will always panic but the lint is not smart enough to see this (it
|
||||
// only checks if conditions).
|
||||
x.unwrap_err();
|
||||
}
|
||||
|
||||
assert!(x.is_ok(), "{:?}", x.unwrap_err()); // ok, it's a common test pattern
|
||||
|
@ -8,6 +8,7 @@ impl dyn TT {
|
||||
fn func(&self) {}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn main() {
|
||||
let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
|
||||
//[nll]~^ ERROR: borrowed data escapes outside of closure
|
||||
|
@ -1,13 +1,13 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/ice-6256.rs:12:28
|
||||
--> $DIR/ice-6256.rs:13:28
|
||||
|
|
||||
LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
|
||||
| ^^^^ lifetime mismatch
|
||||
|
|
||||
= note: expected reference `&(dyn TT + 'static)`
|
||||
found reference `&dyn TT`
|
||||
note: the anonymous lifetime #1 defined on the body at 12:13...
|
||||
--> $DIR/ice-6256.rs:12:13
|
||||
note: the anonymous lifetime #1 defined on the body at 13:13...
|
||||
--> $DIR/ice-6256.rs:13:13
|
||||
|
|
||||
LL | let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,11 +1,7 @@
|
||||
#![warn(clippy::dbg_macro)]
|
||||
|
||||
fn foo(n: u32) -> u32 {
|
||||
if let Some(n) = dbg!(n.checked_sub(4)) {
|
||||
n
|
||||
} else {
|
||||
n
|
||||
}
|
||||
if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n }
|
||||
}
|
||||
|
||||
fn factorial(n: u32) -> u32 {
|
||||
|
@ -1,17 +1,17 @@
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:4:22
|
||||
|
|
||||
LL | if let Some(n) = dbg!(n.checked_sub(4)) {
|
||||
LL | if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::dbg-macro` implied by `-D warnings`
|
||||
help: ensure to avoid having uses of it in version control
|
||||
|
|
||||
LL | if let Some(n) = n.checked_sub(4) {
|
||||
LL | if let Some(n) = n.checked_sub(4) { n } else { n }
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:12:8
|
||||
--> $DIR/dbg_macro.rs:8:8
|
||||
|
|
||||
LL | if dbg!(n <= 1) {
|
||||
| ^^^^^^^^^^^^
|
||||
@ -22,7 +22,7 @@ LL | if n <= 1 {
|
||||
| ^^^^^^
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:13:9
|
||||
--> $DIR/dbg_macro.rs:9:9
|
||||
|
|
||||
LL | dbg!(1)
|
||||
| ^^^^^^^
|
||||
@ -33,7 +33,7 @@ LL | 1
|
||||
|
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:15:9
|
||||
--> $DIR/dbg_macro.rs:11:9
|
||||
|
|
||||
LL | dbg!(n * factorial(n - 1))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -44,7 +44,7 @@ LL | n * factorial(n - 1)
|
||||
|
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:20:5
|
||||
--> $DIR/dbg_macro.rs:16:5
|
||||
|
|
||||
LL | dbg!(42);
|
||||
| ^^^^^^^^
|
||||
@ -55,7 +55,7 @@ LL | 42;
|
||||
| ^^
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:21:5
|
||||
--> $DIR/dbg_macro.rs:17:5
|
||||
|
|
||||
LL | dbg!(dbg!(dbg!(42)));
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
@ -66,7 +66,7 @@ LL | dbg!(dbg!(42));
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: `dbg!` macro is intended as a debugging tool
|
||||
--> $DIR/dbg_macro.rs:22:14
|
||||
--> $DIR/dbg_macro.rs:18:14
|
||||
|
|
||||
LL | foo(3) + dbg!(factorial(4));
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
@ -48,25 +48,7 @@ fn main() {
|
||||
|
||||
println!(
|
||||
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]",
|
||||
s1,
|
||||
s2,
|
||||
s3,
|
||||
s4,
|
||||
s5,
|
||||
s6,
|
||||
s7,
|
||||
s8,
|
||||
s9,
|
||||
s10,
|
||||
s11,
|
||||
s12,
|
||||
s13,
|
||||
s14,
|
||||
s15,
|
||||
s16,
|
||||
s17,
|
||||
s18,
|
||||
s19,
|
||||
s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -48,25 +48,7 @@ fn main() {
|
||||
|
||||
println!(
|
||||
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}] [{:?}], [{:?}]",
|
||||
s1,
|
||||
s2,
|
||||
s3,
|
||||
s4,
|
||||
s5,
|
||||
s6,
|
||||
s7,
|
||||
s8,
|
||||
s9,
|
||||
s10,
|
||||
s11,
|
||||
s12,
|
||||
s13,
|
||||
s14,
|
||||
s15,
|
||||
s16,
|
||||
s17,
|
||||
s18,
|
||||
s19,
|
||||
s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,7 @@ pub fn inner_body(opt: Option<u32>) {
|
||||
|
||||
/// This needs to be documented
|
||||
pub fn unreachable_and_panic() {
|
||||
if true {
|
||||
unreachable!()
|
||||
} else {
|
||||
panic!()
|
||||
}
|
||||
if true { unreachable!() } else { panic!() }
|
||||
}
|
||||
|
||||
/// This is documented
|
||||
@ -84,11 +80,7 @@ pub fn todo_documented() {
|
||||
///
|
||||
/// We still need to do this part
|
||||
pub fn unreachable_amd_panic_documented() {
|
||||
if true {
|
||||
unreachable!()
|
||||
} else {
|
||||
panic!()
|
||||
}
|
||||
if true { unreachable!() } else { panic!() }
|
||||
}
|
||||
|
||||
/// This is okay because it is private
|
||||
|
@ -67,19 +67,15 @@ error: docs for function which may panic missing `# Panics` section
|
||||
--> $DIR/doc_panics.rs:32:1
|
||||
|
|
||||
LL | / pub fn unreachable_and_panic() {
|
||||
LL | | if true {
|
||||
LL | | unreachable!()
|
||||
LL | | } else {
|
||||
LL | | panic!()
|
||||
LL | | }
|
||||
LL | | if true { unreachable!() } else { panic!() }
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
note: first possible panic found here
|
||||
--> $DIR/doc_panics.rs:36:9
|
||||
--> $DIR/doc_panics.rs:33:39
|
||||
|
|
||||
LL | panic!()
|
||||
| ^^^^^^^^
|
||||
LL | if true { unreachable!() } else { panic!() }
|
||||
| ^^^^^^^^
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
@ -21,19 +21,11 @@ where
|
||||
}
|
||||
|
||||
fn eq_fl(x: f32, y: f32) -> bool {
|
||||
if x.is_nan() {
|
||||
y.is_nan()
|
||||
} else {
|
||||
x == y
|
||||
} // no error, inside "eq" fn
|
||||
if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn
|
||||
}
|
||||
|
||||
fn fl_eq(x: f32, y: f32) -> bool {
|
||||
if x.is_nan() {
|
||||
y.is_nan()
|
||||
} else {
|
||||
x == y
|
||||
} // no error, inside "eq" fn
|
||||
if x.is_nan() { y.is_nan() } else { x == y } // no error, inside "eq" fn
|
||||
}
|
||||
|
||||
struct X {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:66:5
|
||||
--> $DIR/float_cmp.rs:58:5
|
||||
|
|
||||
LL | ONE as f64 != 2.0;
|
||||
| ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f64 - 2.0).abs() > error_margin`
|
||||
@ -8,7 +8,7 @@ LL | ONE as f64 != 2.0;
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:71:5
|
||||
--> $DIR/float_cmp.rs:63:5
|
||||
|
|
||||
LL | x == 1.0;
|
||||
| ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin`
|
||||
@ -16,7 +16,7 @@ LL | x == 1.0;
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:74:5
|
||||
--> $DIR/float_cmp.rs:66:5
|
||||
|
|
||||
LL | twice(x) != twice(ONE as f64);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin`
|
||||
@ -24,7 +24,7 @@ LL | twice(x) != twice(ONE as f64);
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:94:5
|
||||
--> $DIR/float_cmp.rs:86:5
|
||||
|
|
||||
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin`
|
||||
@ -32,7 +32,7 @@ LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` arrays
|
||||
--> $DIR/float_cmp.rs:99:5
|
||||
--> $DIR/float_cmp.rs:91:5
|
||||
|
|
||||
LL | a1 == a2;
|
||||
| ^^^^^^^^
|
||||
@ -40,7 +40,7 @@ LL | a1 == a2;
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
--> $DIR/float_cmp.rs:100:5
|
||||
--> $DIR/float_cmp.rs:92:5
|
||||
|
|
||||
LL | a1[0] == a2[0];
|
||||
| ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin`
|
||||
|
@ -8,11 +8,7 @@ const ONE: f32 = 1.0;
|
||||
const TWO: f32 = 2.0;
|
||||
|
||||
fn eq_one(x: f32) -> bool {
|
||||
if x.is_nan() {
|
||||
false
|
||||
} else {
|
||||
x == ONE
|
||||
} // no error, inside "eq" fn
|
||||
if x.is_nan() { false } else { x == ONE } // no error, inside "eq" fn
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:20:5
|
||||
--> $DIR/float_cmp_const.rs:16:5
|
||||
|
|
||||
LL | 1f32 == ONE;
|
||||
| ^^^^^^^^^^^ help: consider comparing them within some margin of error: `(1f32 - ONE).abs() < error_margin`
|
||||
@ -8,7 +8,7 @@ LL | 1f32 == ONE;
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:21:5
|
||||
--> $DIR/float_cmp_const.rs:17:5
|
||||
|
|
||||
LL | TWO == ONE;
|
||||
| ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() < error_margin`
|
||||
@ -16,7 +16,7 @@ LL | TWO == ONE;
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:22:5
|
||||
--> $DIR/float_cmp_const.rs:18:5
|
||||
|
|
||||
LL | TWO != ONE;
|
||||
| ^^^^^^^^^^ help: consider comparing them within some margin of error: `(TWO - ONE).abs() > error_margin`
|
||||
@ -24,7 +24,7 @@ LL | TWO != ONE;
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:23:5
|
||||
--> $DIR/float_cmp_const.rs:19:5
|
||||
|
|
||||
LL | ONE + ONE == TWO;
|
||||
| ^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE + ONE - TWO).abs() < error_margin`
|
||||
@ -32,7 +32,7 @@ LL | ONE + ONE == TWO;
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:25:5
|
||||
--> $DIR/float_cmp_const.rs:21:5
|
||||
|
|
||||
LL | x as f32 == ONE;
|
||||
| ^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(x as f32 - ONE).abs() < error_margin`
|
||||
@ -40,7 +40,7 @@ LL | x as f32 == ONE;
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:28:5
|
||||
--> $DIR/float_cmp_const.rs:24:5
|
||||
|
|
||||
LL | v == ONE;
|
||||
| ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() < error_margin`
|
||||
@ -48,7 +48,7 @@ LL | v == ONE;
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
--> $DIR/float_cmp_const.rs:29:5
|
||||
--> $DIR/float_cmp_const.rs:25:5
|
||||
|
|
||||
LL | v != ONE;
|
||||
| ^^^^^^^^ help: consider comparing them within some margin of error: `(v - ONE).abs() > error_margin`
|
||||
@ -56,7 +56,7 @@ LL | v != ONE;
|
||||
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant arrays
|
||||
--> $DIR/float_cmp_const.rs:61:5
|
||||
--> $DIR/float_cmp_const.rs:57:5
|
||||
|
|
||||
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -42,43 +42,23 @@ fn fake_nabs3(a: A) -> A {
|
||||
}
|
||||
|
||||
fn not_fake_abs1(num: f64) -> f64 {
|
||||
if num > 0.0 {
|
||||
num
|
||||
} else {
|
||||
-num - 1f64
|
||||
}
|
||||
if num > 0.0 { num } else { -num - 1f64 }
|
||||
}
|
||||
|
||||
fn not_fake_abs2(num: f64) -> f64 {
|
||||
if num > 0.0 {
|
||||
num + 1.0
|
||||
} else {
|
||||
-(num + 1.0)
|
||||
}
|
||||
if num > 0.0 { num + 1.0 } else { -(num + 1.0) }
|
||||
}
|
||||
|
||||
fn not_fake_abs3(num1: f64, num2: f64) -> f64 {
|
||||
if num1 > 0.0 {
|
||||
num2
|
||||
} else {
|
||||
-num2
|
||||
}
|
||||
if num1 > 0.0 { num2 } else { -num2 }
|
||||
}
|
||||
|
||||
fn not_fake_abs4(a: A) -> f64 {
|
||||
if a.a > 0.0 {
|
||||
a.b
|
||||
} else {
|
||||
-a.b
|
||||
}
|
||||
if a.a > 0.0 { a.b } else { -a.b }
|
||||
}
|
||||
|
||||
fn not_fake_abs5(a: A) -> f64 {
|
||||
if a.a > 0.0 {
|
||||
a.a
|
||||
} else {
|
||||
-a.b
|
||||
}
|
||||
if a.a > 0.0 { a.a } else { -a.b }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -7,59 +7,31 @@ struct A {
|
||||
}
|
||||
|
||||
fn fake_abs1(num: f64) -> f64 {
|
||||
if num >= 0.0 {
|
||||
num
|
||||
} else {
|
||||
-num
|
||||
}
|
||||
if num >= 0.0 { num } else { -num }
|
||||
}
|
||||
|
||||
fn fake_abs2(num: f64) -> f64 {
|
||||
if 0.0 < num {
|
||||
num
|
||||
} else {
|
||||
-num
|
||||
}
|
||||
if 0.0 < num { num } else { -num }
|
||||
}
|
||||
|
||||
fn fake_abs3(a: A) -> f64 {
|
||||
if a.a > 0.0 {
|
||||
a.a
|
||||
} else {
|
||||
-a.a
|
||||
}
|
||||
if a.a > 0.0 { a.a } else { -a.a }
|
||||
}
|
||||
|
||||
fn fake_abs4(num: f64) -> f64 {
|
||||
if 0.0 >= num {
|
||||
-num
|
||||
} else {
|
||||
num
|
||||
}
|
||||
if 0.0 >= num { -num } else { num }
|
||||
}
|
||||
|
||||
fn fake_abs5(a: A) -> f64 {
|
||||
if a.a < 0.0 {
|
||||
-a.a
|
||||
} else {
|
||||
a.a
|
||||
}
|
||||
if a.a < 0.0 { -a.a } else { a.a }
|
||||
}
|
||||
|
||||
fn fake_nabs1(num: f64) -> f64 {
|
||||
if num < 0.0 {
|
||||
num
|
||||
} else {
|
||||
-num
|
||||
}
|
||||
if num < 0.0 { num } else { -num }
|
||||
}
|
||||
|
||||
fn fake_nabs2(num: f64) -> f64 {
|
||||
if 0.0 >= num {
|
||||
num
|
||||
} else {
|
||||
-num
|
||||
}
|
||||
if 0.0 >= num { num } else { -num }
|
||||
}
|
||||
|
||||
fn fake_nabs3(a: A) -> A {
|
||||
@ -70,43 +42,23 @@ fn fake_nabs3(a: A) -> A {
|
||||
}
|
||||
|
||||
fn not_fake_abs1(num: f64) -> f64 {
|
||||
if num > 0.0 {
|
||||
num
|
||||
} else {
|
||||
-num - 1f64
|
||||
}
|
||||
if num > 0.0 { num } else { -num - 1f64 }
|
||||
}
|
||||
|
||||
fn not_fake_abs2(num: f64) -> f64 {
|
||||
if num > 0.0 {
|
||||
num + 1.0
|
||||
} else {
|
||||
-(num + 1.0)
|
||||
}
|
||||
if num > 0.0 { num + 1.0 } else { -(num + 1.0) }
|
||||
}
|
||||
|
||||
fn not_fake_abs3(num1: f64, num2: f64) -> f64 {
|
||||
if num1 > 0.0 {
|
||||
num2
|
||||
} else {
|
||||
-num2
|
||||
}
|
||||
if num1 > 0.0 { num2 } else { -num2 }
|
||||
}
|
||||
|
||||
fn not_fake_abs4(a: A) -> f64 {
|
||||
if a.a > 0.0 {
|
||||
a.b
|
||||
} else {
|
||||
-a.b
|
||||
}
|
||||
if a.a > 0.0 { a.b } else { -a.b }
|
||||
}
|
||||
|
||||
fn not_fake_abs5(a: A) -> f64 {
|
||||
if a.a > 0.0 {
|
||||
a.a
|
||||
} else {
|
||||
-a.b
|
||||
}
|
||||
if a.a > 0.0 { a.a } else { -a.b }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,77 +1,49 @@
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:10:5
|
||||
|
|
||||
LL | / if num >= 0.0 {
|
||||
LL | | num
|
||||
LL | | } else {
|
||||
LL | | -num
|
||||
LL | | }
|
||||
| |_____^ help: try: `num.abs()`
|
||||
LL | if num >= 0.0 { num } else { -num }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
|
||||
|
|
||||
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:14:5
|
||||
|
|
||||
LL | if 0.0 < num { num } else { -num }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:18:5
|
||||
|
|
||||
LL | / if 0.0 < num {
|
||||
LL | | num
|
||||
LL | | } else {
|
||||
LL | | -num
|
||||
LL | | }
|
||||
| |_____^ help: try: `num.abs()`
|
||||
LL | if a.a > 0.0 { a.a } else { -a.a }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:22:5
|
||||
|
|
||||
LL | if 0.0 >= num { -num } else { num }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.abs()`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:26:5
|
||||
|
|
||||
LL | / if a.a > 0.0 {
|
||||
LL | | a.a
|
||||
LL | | } else {
|
||||
LL | | -a.a
|
||||
LL | | }
|
||||
| |_____^ help: try: `a.a.abs()`
|
||||
LL | if a.a < 0.0 { -a.a } else { a.a }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `a.a.abs()`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
error: manual implementation of negation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:30:5
|
||||
|
|
||||
LL | if num < 0.0 { num } else { -num }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()`
|
||||
|
||||
error: manual implementation of negation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:34:5
|
||||
|
|
||||
LL | / if 0.0 >= num {
|
||||
LL | | -num
|
||||
LL | | } else {
|
||||
LL | | num
|
||||
LL | | }
|
||||
| |_____^ help: try: `num.abs()`
|
||||
|
||||
error: manual implementation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:42:5
|
||||
|
|
||||
LL | / if a.a < 0.0 {
|
||||
LL | | -a.a
|
||||
LL | | } else {
|
||||
LL | | a.a
|
||||
LL | | }
|
||||
| |_____^ help: try: `a.a.abs()`
|
||||
LL | if 0.0 >= num { num } else { -num }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-num.abs()`
|
||||
|
||||
error: manual implementation of negation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:50:5
|
||||
|
|
||||
LL | / if num < 0.0 {
|
||||
LL | | num
|
||||
LL | | } else {
|
||||
LL | | -num
|
||||
LL | | }
|
||||
| |_____^ help: try: `-num.abs()`
|
||||
|
||||
error: manual implementation of negation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:58:5
|
||||
|
|
||||
LL | / if 0.0 >= num {
|
||||
LL | | num
|
||||
LL | | } else {
|
||||
LL | | -num
|
||||
LL | | }
|
||||
| |_____^ help: try: `-num.abs()`
|
||||
|
||||
error: manual implementation of negation of `abs` method
|
||||
--> $DIR/floating_point_abs.rs:67:12
|
||||
--> $DIR/floating_point_abs.rs:39:12
|
||||
|
|
||||
LL | a: if a.a >= 0.0 { -a.a } else { a.a },
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-a.a.abs()`
|
||||
|
@ -3,19 +3,11 @@
|
||||
#![warn(clippy::if_let_some_result)]
|
||||
|
||||
fn str_to_int(x: &str) -> i32 {
|
||||
if let Ok(y) = x.parse() {
|
||||
y
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if let Ok(y) = x.parse() { y } else { 0 }
|
||||
}
|
||||
|
||||
fn str_to_int_ok(x: &str) -> i32 {
|
||||
if let Ok(y) = x.parse() {
|
||||
y
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if let Ok(y) = x.parse() { y } else { 0 }
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -3,19 +3,11 @@
|
||||
#![warn(clippy::if_let_some_result)]
|
||||
|
||||
fn str_to_int(x: &str) -> i32 {
|
||||
if let Some(y) = x.parse().ok() {
|
||||
y
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if let Some(y) = x.parse().ok() { y } else { 0 }
|
||||
}
|
||||
|
||||
fn str_to_int_ok(x: &str) -> i32 {
|
||||
if let Ok(y) = x.parse() {
|
||||
y
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if let Ok(y) = x.parse() { y } else { 0 }
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -1,17 +1,17 @@
|
||||
error: matching on `Some` with `ok()` is redundant
|
||||
--> $DIR/if_let_some_result.rs:6:5
|
||||
|
|
||||
LL | if let Some(y) = x.parse().ok() {
|
||||
LL | if let Some(y) = x.parse().ok() { y } else { 0 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::if-let-some-result` implied by `-D warnings`
|
||||
help: consider matching on `Ok(y)` and removing the call to `ok` instead
|
||||
|
|
||||
LL | if let Ok(y) = x.parse() {
|
||||
LL | if let Ok(y) = x.parse() { y } else { 0 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: matching on `Some` with `ok()` is redundant
|
||||
--> $DIR/if_let_some_result.rs:24:9
|
||||
--> $DIR/if_let_some_result.rs:16:9
|
||||
|
|
||||
LL | if let Some(y) = x . parse() . ok () {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -14,11 +14,7 @@ fn test_end_of_fn() -> bool {
|
||||
|
||||
#[allow(clippy::needless_bool)]
|
||||
fn test_if_block() -> bool {
|
||||
if true {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
if true { return true } else { return false }
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -14,11 +14,7 @@ fn test_end_of_fn() -> bool {
|
||||
|
||||
#[allow(clippy::needless_bool)]
|
||||
fn test_if_block() -> bool {
|
||||
if true {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
if true { true } else { false }
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
@ -7,61 +7,61 @@ LL | true
|
||||
= note: `-D clippy::implicit-return` implied by `-D warnings`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:18:9
|
||||
--> $DIR/implicit_return.rs:17:15
|
||||
|
|
||||
LL | true
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
LL | if true { true } else { false }
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:20:9
|
||||
--> $DIR/implicit_return.rs:17:29
|
||||
|
|
||||
LL | false
|
||||
| ^^^^^ help: add `return` as shown: `return false`
|
||||
LL | if true { true } else { false }
|
||||
| ^^^^^ help: add `return` as shown: `return false`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:27:17
|
||||
--> $DIR/implicit_return.rs:23:17
|
||||
|
|
||||
LL | true => false,
|
||||
| ^^^^^ help: add `return` as shown: `return false`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:28:20
|
||||
--> $DIR/implicit_return.rs:24:20
|
||||
|
|
||||
LL | false => { true },
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:43:9
|
||||
--> $DIR/implicit_return.rs:39:9
|
||||
|
|
||||
LL | break true;
|
||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:51:13
|
||||
--> $DIR/implicit_return.rs:47:13
|
||||
|
|
||||
LL | break true;
|
||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:60:13
|
||||
--> $DIR/implicit_return.rs:56:13
|
||||
|
|
||||
LL | break true;
|
||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:78:18
|
||||
--> $DIR/implicit_return.rs:74:18
|
||||
|
|
||||
LL | let _ = || { true };
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:79:16
|
||||
--> $DIR/implicit_return.rs:75:16
|
||||
|
|
||||
LL | let _ = || true;
|
||||
| ^^^^ help: add `return` as shown: `return true`
|
||||
|
||||
error: missing `return` statement
|
||||
--> $DIR/implicit_return.rs:87:5
|
||||
--> $DIR/implicit_return.rs:83:5
|
||||
|
|
||||
LL | format!("test {}", "test")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")`
|
||||
|
@ -105,11 +105,7 @@ fn fn_bound_3_cannot_elide() {
|
||||
|
||||
// No error; multiple input refs.
|
||||
fn fn_bound_4<'a, F: FnOnce() -> &'a ()>(cond: bool, x: &'a (), f: F) -> &'a () {
|
||||
if cond {
|
||||
x
|
||||
} else {
|
||||
f()
|
||||
}
|
||||
if cond { x } else { f() }
|
||||
}
|
||||
|
||||
struct X {
|
||||
|
@ -43,109 +43,109 @@ LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:120:5
|
||||
--> $DIR/needless_lifetimes.rs:116:5
|
||||
|
|
||||
LL | fn self_and_out<'s>(&'s self) -> &'s u8 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:129:5
|
||||
--> $DIR/needless_lifetimes.rs:125:5
|
||||
|
|
||||
LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:148:1
|
||||
--> $DIR/needless_lifetimes.rs:144:1
|
||||
|
|
||||
LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:178:1
|
||||
--> $DIR/needless_lifetimes.rs:174:1
|
||||
|
|
||||
LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:184:1
|
||||
--> $DIR/needless_lifetimes.rs:180:1
|
||||
|
|
||||
LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:203:1
|
||||
--> $DIR/needless_lifetimes.rs:199:1
|
||||
|
|
||||
LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:211:1
|
||||
--> $DIR/needless_lifetimes.rs:207:1
|
||||
|
|
||||
LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:247:1
|
||||
--> $DIR/needless_lifetimes.rs:243:1
|
||||
|
|
||||
LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:254:9
|
||||
--> $DIR/needless_lifetimes.rs:250:9
|
||||
|
|
||||
LL | fn needless_lt<'a>(x: &'a u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:258:9
|
||||
--> $DIR/needless_lifetimes.rs:254:9
|
||||
|
|
||||
LL | fn needless_lt<'a>(_x: &'a u8) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:271:9
|
||||
--> $DIR/needless_lifetimes.rs:267:9
|
||||
|
|
||||
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:300:5
|
||||
--> $DIR/needless_lifetimes.rs:296:5
|
||||
|
|
||||
LL | fn impl_trait_elidable_nested_named_lifetimes<'a>(i: &'a i32, f: impl for<'b> Fn(&'b i32) -> &'b i32) -> &'a i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:303:5
|
||||
--> $DIR/needless_lifetimes.rs:299:5
|
||||
|
|
||||
LL | fn impl_trait_elidable_nested_anonymous_lifetimes<'a>(i: &'a i32, f: impl Fn(&i32) -> &i32) -> &'a i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:312:5
|
||||
--> $DIR/needless_lifetimes.rs:308:5
|
||||
|
|
||||
LL | fn generics_elidable<'a, T: Fn(&i32) -> &i32>(i: &'a i32, f: T) -> &'a i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:324:5
|
||||
--> $DIR/needless_lifetimes.rs:320:5
|
||||
|
|
||||
LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:339:5
|
||||
--> $DIR/needless_lifetimes.rs:335:5
|
||||
|
|
||||
LL | fn pointer_fn_elidable<'a>(i: &'a i32, f: fn(&i32) -> &i32) -> &'a i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:352:5
|
||||
--> $DIR/needless_lifetimes.rs:348:5
|
||||
|
|
||||
LL | fn nested_fn_pointer_3<'a>(_: &'a i32) -> fn(fn(&i32) -> &i32) -> i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
|
||||
--> $DIR/needless_lifetimes.rs:355:5
|
||||
--> $DIR/needless_lifetimes.rs:351:5
|
||||
|
|
||||
LL | fn nested_fn_pointer_4<'a>(_: &'a i32) -> impl Fn(fn(&i32)) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -59,11 +59,7 @@ fn main() {
|
||||
#[derive(Clone)]
|
||||
struct Alpha;
|
||||
fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) {
|
||||
if b {
|
||||
(a.clone(), a)
|
||||
} else {
|
||||
(Alpha, a)
|
||||
}
|
||||
if b { (a.clone(), a) } else { (Alpha, a) }
|
||||
}
|
||||
|
||||
fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) {
|
||||
|
@ -59,11 +59,7 @@ fn main() {
|
||||
#[derive(Clone)]
|
||||
struct Alpha;
|
||||
fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) {
|
||||
if b {
|
||||
(a.clone(), a.clone())
|
||||
} else {
|
||||
(Alpha, a)
|
||||
}
|
||||
if b { (a.clone(), a.clone()) } else { (Alpha, a) }
|
||||
}
|
||||
|
||||
fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) {
|
||||
|
@ -108,61 +108,61 @@ LL | let _t = tup.0.clone();
|
||||
| ^^^^^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:63:22
|
||||
--> $DIR/redundant_clone.rs:62:25
|
||||
|
|
||||
LL | (a.clone(), a.clone())
|
||||
| ^^^^^^^^ help: remove this
|
||||
LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) }
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:63:21
|
||||
--> $DIR/redundant_clone.rs:62:24
|
||||
|
|
||||
LL | (a.clone(), a.clone())
|
||||
| ^
|
||||
LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) }
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:123:15
|
||||
--> $DIR/redundant_clone.rs:119:15
|
||||
|
|
||||
LL | let _s = s.clone();
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:123:14
|
||||
--> $DIR/redundant_clone.rs:119:14
|
||||
|
|
||||
LL | let _s = s.clone();
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:124:15
|
||||
--> $DIR/redundant_clone.rs:120:15
|
||||
|
|
||||
LL | let _t = t.clone();
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:124:14
|
||||
--> $DIR/redundant_clone.rs:120:14
|
||||
|
|
||||
LL | let _t = t.clone();
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:134:19
|
||||
--> $DIR/redundant_clone.rs:130:19
|
||||
|
|
||||
LL | let _f = f.clone();
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: this value is dropped without further use
|
||||
--> $DIR/redundant_clone.rs:134:18
|
||||
--> $DIR/redundant_clone.rs:130:18
|
||||
|
|
||||
LL | let _f = f.clone();
|
||||
| ^
|
||||
|
||||
error: redundant clone
|
||||
--> $DIR/redundant_clone.rs:146:14
|
||||
--> $DIR/redundant_clone.rs:142:14
|
||||
|
|
||||
LL | let y = x.clone().join("matthias");
|
||||
| ^^^^^^^^ help: remove this
|
||||
|
|
||||
note: cloned value is neither consumed nor mutated
|
||||
--> $DIR/redundant_clone.rs:146:13
|
||||
--> $DIR/redundant_clone.rs:142:13
|
||||
|
|
||||
LL | let y = x.clone().join("matthias");
|
||||
| ^^^^^^^^^
|
||||
|
@ -22,29 +22,17 @@ fn func2(a: bool, b: bool) -> Option<i32> {
|
||||
if a && b {
|
||||
return Some(10);
|
||||
}
|
||||
if a {
|
||||
Some(20)
|
||||
} else {
|
||||
Some(30)
|
||||
}
|
||||
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)
|
||||
}
|
||||
if a { Some(1) } else { Some(1) }
|
||||
}
|
||||
|
||||
// should not be linted
|
||||
fn func4(a: bool) -> Option<i32> {
|
||||
if a {
|
||||
Some(1)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if a { Some(1) } else { None }
|
||||
}
|
||||
|
||||
// should be linted
|
||||
@ -64,11 +52,7 @@ fn func7() -> Result<i32, ()> {
|
||||
|
||||
// should not be linted
|
||||
fn func8(a: bool) -> Result<i32, ()> {
|
||||
if a {
|
||||
Ok(1)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
if a { Ok(1) } else { Err(()) }
|
||||
}
|
||||
|
||||
// should not be linted
|
||||
@ -143,20 +127,12 @@ fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
|
||||
|
||||
// should not be linted
|
||||
fn issue_6640_3() -> Option<()> {
|
||||
if true {
|
||||
Some(())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if true { Some(()) } else { None }
|
||||
}
|
||||
|
||||
// should not be linted
|
||||
fn issue_6640_4() -> Result<(), ()> {
|
||||
if true {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
if true { Ok(()) } else { Err(()) }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -32,8 +32,7 @@ LL | / fn func2(a: bool, b: bool) -> Option<i32> {
|
||||
LL | | if a && b {
|
||||
LL | | return Some(10);
|
||||
LL | | }
|
||||
... |
|
||||
LL | | }
|
||||
LL | | if a { Some(20) } else { Some(30) }
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
@ -45,14 +44,11 @@ help: ...and then change returning expressions
|
||||
|
|
||||
LL | return 10;
|
||||
LL | }
|
||||
LL | if a {
|
||||
LL | 20
|
||||
LL | } else {
|
||||
LL | 30
|
||||
LL | if a { 20 } else { 30 }
|
||||
|
|
||||
|
||||
error: this function's return value is unnecessarily wrapped by `Option`
|
||||
--> $DIR/unnecessary_wraps.rs:51:1
|
||||
--> $DIR/unnecessary_wraps.rs:39:1
|
||||
|
|
||||
LL | / fn func5() -> Option<i32> {
|
||||
LL | | Some(1)
|
||||
@ -69,7 +65,7 @@ LL | 1
|
||||
|
|
||||
|
||||
error: this function's return value is unnecessarily wrapped by `Result`
|
||||
--> $DIR/unnecessary_wraps.rs:61:1
|
||||
--> $DIR/unnecessary_wraps.rs:49:1
|
||||
|
|
||||
LL | / fn func7() -> Result<i32, ()> {
|
||||
LL | | Ok(1)
|
||||
@ -86,7 +82,7 @@ LL | 1
|
||||
|
|
||||
|
||||
error: this function's return value is unnecessarily wrapped by `Option`
|
||||
--> $DIR/unnecessary_wraps.rs:93:5
|
||||
--> $DIR/unnecessary_wraps.rs:77:5
|
||||
|
|
||||
LL | / fn func12() -> Option<i32> {
|
||||
LL | | Some(1)
|
||||
@ -103,7 +99,7 @@ LL | 1
|
||||
|
|
||||
|
||||
error: this function's return value is unnecessary
|
||||
--> $DIR/unnecessary_wraps.rs:120:1
|
||||
--> $DIR/unnecessary_wraps.rs:104:1
|
||||
|
|
||||
LL | / fn issue_6640_1(a: bool, b: bool) -> Option<()> {
|
||||
LL | | if a && b {
|
||||
@ -129,7 +125,7 @@ LL | } else {
|
||||
...
|
||||
|
||||
error: this function's return value is unnecessary
|
||||
--> $DIR/unnecessary_wraps.rs:133:1
|
||||
--> $DIR/unnecessary_wraps.rs:117:1
|
||||
|
|
||||
LL | / fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
|
||||
LL | | if a && b {
|
||||
|
@ -16,7 +16,8 @@ enum Flags {
|
||||
FIN,
|
||||
}
|
||||
|
||||
struct GCCLLVMSomething; // linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
|
||||
// `GccLlvmSomething`
|
||||
// linted with cfg option, beware that lint suggests `GccllvmSomething` instead of
|
||||
// `GccLlvmSomething`
|
||||
struct GCCLLVMSomething;
|
||||
|
||||
fn main() {}
|
||||
|
@ -329,11 +329,7 @@ mod issue4140 {
|
||||
type To = Self;
|
||||
|
||||
fn from(value: bool) -> Self {
|
||||
if value {
|
||||
100
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if value { 100 } else { 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -329,11 +329,7 @@ mod issue4140 {
|
||||
type To = Self;
|
||||
|
||||
fn from(value: bool) -> Self {
|
||||
if value {
|
||||
100
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if value { 100 } else { 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ LL | type To = T::To;
|
||||
| ^^^^^ help: use the applicable keyword: `Self`
|
||||
|
||||
error: unnecessary structure name repetition
|
||||
--> $DIR/use_self.rs:457:13
|
||||
--> $DIR/use_self.rs:453:13
|
||||
|
|
||||
LL | A::new::<submod::B>(submod::B {})
|
||||
| ^ help: use the applicable keyword: `Self`
|
||||
|
Loading…
Reference in New Issue
Block a user