mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Merge branch 'master' into fix-3514
This commit is contained in:
commit
df73348354
470 changed files with 7560 additions and 7269 deletions
|
@ -18,15 +18,6 @@ env:
|
|||
global:
|
||||
- RUST_BACKTRACE=1
|
||||
|
||||
before_install:
|
||||
- |
|
||||
# work-around for issue https://github.com/travis-ci/travis-ci/issues/6307
|
||||
# might not be necessary in the future
|
||||
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
|
||||
command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
|
||||
rvm get stable
|
||||
fi
|
||||
|
||||
install:
|
||||
- |
|
||||
if [ -z ${INTEGRATION} ]; then
|
||||
|
|
|
@ -19,7 +19,6 @@ All contributors are expected to follow the [Rust Code of Conduct](http://www.ru
|
|||
* [Running test suite](#running-test-suite)
|
||||
* [Running rustfmt](#running-rustfmt)
|
||||
* [Testing manually](#testing-manually)
|
||||
* [Linting Clippy with your local changes](#linting-clippy-with-your-local-changes)
|
||||
* [How Clippy works](#how-clippy-works)
|
||||
* [Fixing nightly build failures](#fixing-build-failures-caused-by-rust)
|
||||
* [Issue and PR Triage](#issue-and-pr-triage)
|
||||
|
|
20
README.md
20
README.md
|
@ -106,8 +106,8 @@ script:
|
|||
# etc.
|
||||
```
|
||||
|
||||
It might happen that clippy is not available for a certain nightly release.
|
||||
In this case you can try to conditionally install clippy from the git repo.
|
||||
It might happen that Clippy is not available for a certain nightly release.
|
||||
In this case you can try to conditionally install Clippy from the git repo.
|
||||
|
||||
```yaml
|
||||
language: rust
|
||||
|
@ -149,21 +149,7 @@ You can add options to your code to `allow`/`warn`/`deny` Clippy lints:
|
|||
|
||||
Note: `deny` produces errors instead of warnings.
|
||||
|
||||
Note: To use the new `clippy::lint_name` syntax, a recent compiler has to be used
|
||||
currently. If you want to compile your code with the stable toolchain you can use a `cfg_attr` to
|
||||
activate the `tool_lints` feature:
|
||||
```rust
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(clippy::lint_name))]
|
||||
```
|
||||
|
||||
For this to work you have to use Clippy on the nightly toolchain: `cargo +nightly clippy`. If you
|
||||
want to use Clippy with the stable toolchain, you can stick to the old unscoped method to
|
||||
enable/disable Clippy lints until `tool_lints` are stable:
|
||||
```rust
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(clippy_lint))]
|
||||
```
|
||||
|
||||
If you do not want to include your lint levels in your code, you can globally enable/disable lints by passing extra flags to clippy during the run: `cargo clippy -- -A lint_name` will run clippy with `lint_name` disabled and `cargo clippy -- -W lint_name` will run it with that enabled. On newer compilers you may need to use `clippy::lint_name` instead.
|
||||
If you do not want to include your lint levels in your code, you can globally enable/disable lints by passing extra flags to Clippy during the run: `cargo clippy -- -A clippy::lint_name` will run Clippy with `lint_name` disabled and `cargo clippy -- -W clippy::lint_name` will run it with that enabled. This also works with lint groups. For example you can run Clippy with warnings for all lints enabled: `cargo clippy -- -W clippy::pedantic`
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
@ -29,3 +29,20 @@ cd clippy_dev && cargo test && cd ..
|
|||
# Perform various checks for lint registration
|
||||
./util/dev update_lints --check
|
||||
cargo +nightly fmt --all -- --check
|
||||
|
||||
|
||||
#avoid loop spam
|
||||
set +x
|
||||
# make sure tests are formatted
|
||||
|
||||
# some lints are sensitive to formatting, exclude some files
|
||||
needs_formatting=false
|
||||
for file in `find tests -not -path "tests/ui/methods.rs" -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
|
||||
rustfmt ${file} --check || echo "${file} needs reformatting!" ; needs_formatting=true
|
||||
done
|
||||
|
||||
if [ "${needs_reformatting}" = true ] ; then
|
||||
echo "Tests need reformatting!"
|
||||
exit 2
|
||||
fi
|
||||
set -x
|
||||
|
|
|
@ -238,7 +238,7 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
|
|||
}
|
||||
|
||||
fn check_text(cx: &EarlyContext<'_>, valid_idents: &[String], text: &str, span: Span) {
|
||||
for word in text.split_whitespace() {
|
||||
for word in text.split(|c: char| c.is_whitespace() || c == '\'') {
|
||||
// Trim punctuation as in `some comment (see foo::bar).`
|
||||
// ^^
|
||||
// Or even as in `_foo bar_` which is emphasized.
|
||||
|
@ -281,6 +281,10 @@ fn check_word(cx: &EarlyContext<'_>, word: &str, span: Span) {
|
|||
s != "_" && !s.contains("\\_") && s.contains('_')
|
||||
}
|
||||
|
||||
fn has_hyphen(s: &str) -> bool {
|
||||
s != "-" && s.contains('-')
|
||||
}
|
||||
|
||||
if let Ok(url) = Url::parse(word) {
|
||||
// try to get around the fact that `foo::bar` parses as a valid URL
|
||||
if !url.cannot_be_a_base() {
|
||||
|
@ -295,6 +299,11 @@ fn check_word(cx: &EarlyContext<'_>, word: &str, span: Span) {
|
|||
}
|
||||
}
|
||||
|
||||
// We assume that mixed-case words are not meant to be put inside bacticks. (Issue #2343)
|
||||
if has_underscore(word) && has_hyphen(word) {
|
||||
return;
|
||||
}
|
||||
|
||||
if has_underscore(word) || word.contains("::") || is_camel_case(word) {
|
||||
span_lint(
|
||||
cx,
|
||||
|
|
|
@ -10,8 +10,9 @@
|
|||
use crate::rustc::hir::*;
|
||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use crate::rustc::{declare_tool_lint, lint_array};
|
||||
use crate::utils::opt_def_id;
|
||||
use crate::utils::{is_expn_of, match_def_path, resolve_node, span_lint};
|
||||
use crate::rustc_errors::Applicability;
|
||||
use crate::syntax::ast::LitKind;
|
||||
use crate::utils::{is_expn_of, match_def_path, opt_def_id, resolve_node, span_lint, span_lint_and_sugg};
|
||||
use if_chain::if_chain;
|
||||
|
||||
/// **What it does:** Checks for usage of `write!()` / `writeln()!` which can be
|
||||
|
@ -81,32 +82,85 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
} else {
|
||||
""
|
||||
};
|
||||
if let Some(macro_name) = calling_macro {
|
||||
span_lint(
|
||||
cx,
|
||||
EXPLICIT_WRITE,
|
||||
expr.span,
|
||||
&format!(
|
||||
"use of `{}!({}(), ...).unwrap()`. Consider using `{}{}!` instead",
|
||||
macro_name,
|
||||
dest_name,
|
||||
prefix,
|
||||
macro_name.replace("write", "print")
|
||||
)
|
||||
);
|
||||
|
||||
// We need to remove the last trailing newline from the string because the
|
||||
// underlying `fmt::write` function doesn't know whether `println!` or `print!` was
|
||||
// used.
|
||||
if let Some(mut write_output) = write_output_string(write_args) {
|
||||
if write_output.ends_with('\n') {
|
||||
write_output.pop();
|
||||
}
|
||||
|
||||
if let Some(macro_name) = calling_macro {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
EXPLICIT_WRITE,
|
||||
expr.span,
|
||||
&format!(
|
||||
"use of `{}!({}(), ...).unwrap()`",
|
||||
macro_name,
|
||||
dest_name
|
||||
),
|
||||
"try this",
|
||||
format!("{}{}!(\"{}\")", prefix, macro_name.replace("write", "print"), write_output.escape_default()),
|
||||
Applicability::MachineApplicable
|
||||
);
|
||||
} else {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
EXPLICIT_WRITE,
|
||||
expr.span,
|
||||
&format!("use of `{}().write_fmt(...).unwrap()`", dest_name),
|
||||
"try this",
|
||||
format!("{}print!(\"{}\")", prefix, write_output.escape_default()),
|
||||
Applicability::MachineApplicable
|
||||
);
|
||||
}
|
||||
} else {
|
||||
span_lint(
|
||||
cx,
|
||||
EXPLICIT_WRITE,
|
||||
expr.span,
|
||||
&format!(
|
||||
"use of `{}().write_fmt(...).unwrap()`. Consider using `{}print!` instead",
|
||||
dest_name,
|
||||
prefix,
|
||||
)
|
||||
);
|
||||
// We don't have a proper suggestion
|
||||
if let Some(macro_name) = calling_macro {
|
||||
span_lint(
|
||||
cx,
|
||||
EXPLICIT_WRITE,
|
||||
expr.span,
|
||||
&format!(
|
||||
"use of `{}!({}(), ...).unwrap()`. Consider using `{}{}!` instead",
|
||||
macro_name,
|
||||
dest_name,
|
||||
prefix,
|
||||
macro_name.replace("write", "print")
|
||||
)
|
||||
);
|
||||
} else {
|
||||
span_lint(
|
||||
cx,
|
||||
EXPLICIT_WRITE,
|
||||
expr.span,
|
||||
&format!("use of `{}().write_fmt(...).unwrap()`. Consider using `{}print!` instead", dest_name, prefix),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extract the output string from the given `write_args`.
|
||||
fn write_output_string(write_args: &HirVec<Expr>) -> Option<String> {
|
||||
if_chain! {
|
||||
// Obtain the string that should be printed
|
||||
if write_args.len() > 1;
|
||||
if let ExprKind::Call(_, ref output_args) = write_args[1].node;
|
||||
if output_args.len() > 0;
|
||||
if let ExprKind::AddrOf(_, ref output_string_expr) = output_args[0].node;
|
||||
if let ExprKind::Array(ref string_exprs) = output_string_expr.node;
|
||||
if string_exprs.len() > 0;
|
||||
if let ExprKind::Lit(ref lit) = string_exprs[0].node;
|
||||
if let LitKind::Str(ref write_output, _) = lit.node;
|
||||
then {
|
||||
return Some(write_output.to_string())
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#![feature(slice_patterns)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(range_contains)]
|
||||
#![feature(str_escape)]
|
||||
#![allow(clippy::missing_docs_in_private_items)]
|
||||
#![recursion_limit = "256"]
|
||||
#![warn(rust_2018_idioms, trivial_casts, trivial_numeric_casts)]
|
||||
|
|
|
@ -17,7 +17,7 @@ use crate::rustc_errors::Applicability;
|
|||
use crate::syntax::source_map::Span;
|
||||
use crate::utils::paths;
|
||||
use crate::utils::sugg::DiagnosticBuilderExt;
|
||||
use crate::utils::{get_trait_def_id, implements_trait, return_ty, same_tys, span_lint_and_then};
|
||||
use crate::utils::{get_trait_def_id, implements_trait, return_ty, same_tys, span_lint_node_and_then};
|
||||
use if_chain::if_chain;
|
||||
|
||||
/// **What it does:** Checks for types with a `fn new() -> Self` method and no
|
||||
|
@ -165,9 +165,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
|
|||
}
|
||||
|
||||
if let Some(sp) = can_derive_default(self_ty, cx, default_trait_id) {
|
||||
span_lint_and_then(
|
||||
span_lint_node_and_then(
|
||||
cx,
|
||||
NEW_WITHOUT_DEFAULT_DERIVE,
|
||||
id,
|
||||
impl_item.span,
|
||||
&format!(
|
||||
"you should consider deriving a `Default` implementation for `{}`",
|
||||
|
@ -183,9 +184,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
|
|||
);
|
||||
});
|
||||
} else {
|
||||
span_lint_and_then(
|
||||
span_lint_node_and_then(
|
||||
cx,
|
||||
NEW_WITHOUT_DEFAULT,
|
||||
id,
|
||||
impl_item.span,
|
||||
&format!(
|
||||
"you should consider adding a `Default` implementation for `{}`",
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
use crate::rustc::hir::*;
|
||||
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use crate::rustc::{declare_tool_lint, lint_array};
|
||||
use crate::utils::{is_automatically_derived, span_lint};
|
||||
use crate::utils::{is_automatically_derived, span_lint_node};
|
||||
use if_chain::if_chain;
|
||||
|
||||
/// **What it does:** Checks for manual re-implementations of `PartialEq::ne`.
|
||||
|
@ -56,10 +56,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
then {
|
||||
for impl_item in impl_items {
|
||||
if impl_item.ident.name == "ne" {
|
||||
span_lint(cx,
|
||||
PARTIALEQ_NE_IMPL,
|
||||
impl_item.span,
|
||||
"re-implementing `PartialEq::ne` is unnecessary")
|
||||
span_lint_node(
|
||||
cx,
|
||||
PARTIALEQ_NE_IMPL,
|
||||
impl_item.id.node_id,
|
||||
impl_item.span,
|
||||
"re-implementing `PartialEq::ne` is unnecessary",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use if_chain::if_chain;
|
|||
|
||||
use crate::rustc_errors::Applicability;
|
||||
use crate::utils::paths::*;
|
||||
use crate::utils::{match_def_path, match_type, span_lint_and_then};
|
||||
use crate::utils::{match_def_path, match_type, span_lint_and_then, SpanlessEq};
|
||||
|
||||
/// **What it does:** Checks for expressions that could be replaced by the question mark operator
|
||||
///
|
||||
|
@ -64,14 +64,40 @@ impl Pass {
|
|||
/// If it matches, it will suggest to use the question mark operator instead
|
||||
fn check_is_none_and_early_return_none(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::If(ref if_expr, ref body, _) = expr.node;
|
||||
if let ExprKind::MethodCall(ref segment, _, ref args) = if_expr.node;
|
||||
if let ExprKind::If(if_expr, body, else_) = &expr.node;
|
||||
if let ExprKind::MethodCall(segment, _, args) = &if_expr.node;
|
||||
if segment.ident.name == "is_none";
|
||||
if Self::expression_returns_none(cx, body);
|
||||
if let Some(subject) = args.get(0);
|
||||
if Self::is_option(cx, subject);
|
||||
|
||||
then {
|
||||
if let Some(else_) = else_ {
|
||||
if_chain! {
|
||||
if let ExprKind::Block(block, None) = &else_.node;
|
||||
if block.stmts.len() == 0;
|
||||
if let Some(block_expr) = &block.expr;
|
||||
if SpanlessEq::new(cx).ignore_fn().eq_expr(subject, block_expr);
|
||||
then {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
QUESTION_MARK,
|
||||
expr.span,
|
||||
"this block may be rewritten with the `?` operator",
|
||||
|db| {
|
||||
db.span_suggestion_with_applicability(
|
||||
expr.span,
|
||||
"replace_it_with",
|
||||
format!("Some({}?)", Sugg::hir(cx, subject, "..")),
|
||||
Applicability::MaybeIncorrect, // snippet
|
||||
);
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
QUESTION_MARK,
|
||||
|
@ -84,7 +110,7 @@ impl Pass {
|
|||
expr.span,
|
||||
"replace_it_with",
|
||||
format!("{}?;", receiver_str),
|
||||
Applicability::MachineApplicable, // snippet
|
||||
Applicability::MaybeIncorrect, // snippet
|
||||
);
|
||||
}
|
||||
)
|
||||
|
@ -133,9 +159,13 @@ impl Pass {
|
|||
}
|
||||
}
|
||||
|
||||
// Check if the block has an implicit return expression
|
||||
if let Some(ref ret_expr) = block.expr {
|
||||
return Some(ret_expr.clone());
|
||||
// Check for `return` without a semicolon.
|
||||
if_chain! {
|
||||
if block.stmts.len() == 0;
|
||||
if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.node);
|
||||
then {
|
||||
return Some(ret_expr.clone());
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
|
|
|
@ -57,7 +57,10 @@ impl EarlyLintPass for RedundantFieldNames {
|
|||
continue;
|
||||
}
|
||||
if let ExprKind::Path(None, path) = &field.expr.node {
|
||||
if path.segments.len() == 1 && path.segments[0].ident == field.ident {
|
||||
if path.segments.len() == 1
|
||||
&& path.segments[0].ident == field.ident
|
||||
&& path.segments[0].args.is_none()
|
||||
{
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
REDUNDANT_FIELD_NAMES,
|
||||
|
|
|
@ -137,6 +137,7 @@ define_Conf! {
|
|||
"iOS", "macOS",
|
||||
"TeX", "LaTeX", "BibTeX", "BibLaTeX",
|
||||
"MinGW",
|
||||
"CamelCase",
|
||||
] => Vec<String>),
|
||||
/// Lint: TOO_MANY_ARGUMENTS. The maximum number of argument a function or method can have
|
||||
(too_many_arguments_threshold, "too_many_arguments_threshold", 7 => u64),
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
pub trait A {}
|
||||
|
||||
macro_rules! __implicit_hasher_test_macro {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
pub trait Trait {
|
||||
const CONSTANT: u8;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#[allow(dead_code)]
|
||||
enum Baz {
|
||||
One,
|
||||
|
@ -19,7 +18,7 @@ struct Test {
|
|||
b: Baz,
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
fn main() {}
|
||||
|
||||
pub fn foo() {
|
||||
use Baz::*;
|
||||
|
@ -27,10 +26,7 @@ pub fn foo() {
|
|||
|
||||
match x {
|
||||
Test { t: Some(_), b: One } => unreachable!(),
|
||||
Test {
|
||||
t: Some(42),
|
||||
b: Two,
|
||||
} => unreachable!(),
|
||||
Test { t: Some(42), b: Two } => unreachable!(),
|
||||
Test { t: None, .. } => unreachable!(),
|
||||
Test { .. } => unreachable!(),
|
||||
}
|
||||
|
|
|
@ -7,12 +7,9 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![deny(clippy::all)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::*;
|
||||
|
||||
fn main() { }
|
||||
fn main() {}
|
||||
|
|
|
@ -7,17 +7,14 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![allow(clippy::all)]
|
||||
|
||||
fn main() {
|
||||
match 1 {
|
||||
1 => {}
|
||||
1 => {},
|
||||
2 => {
|
||||
[0; 1];
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,20 +7,28 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![allow(dead_code, unused_variables)]
|
||||
|
||||
/// Should not trigger an ICE in `SpanlessEq` / `consts::constant`
|
||||
///
|
||||
/// Issue: https://github.com/rust-lang/rust-clippy/issues/1782
|
||||
|
||||
use std::{mem, ptr};
|
||||
|
||||
fn spanless_eq_ice() {
|
||||
let txt = "something";
|
||||
match txt {
|
||||
"something" => unsafe { ptr::write(ptr::null_mut() as *mut u32, mem::transmute::<[u8; 4], _>([0, 0, 0, 255])) },
|
||||
_ => unsafe { ptr::write(ptr::null_mut() as *mut u32, mem::transmute::<[u8; 4], _>([13, 246, 24, 255])) },
|
||||
"something" => unsafe {
|
||||
ptr::write(
|
||||
ptr::null_mut() as *mut u32,
|
||||
mem::transmute::<[u8; 4], _>([0, 0, 0, 255]),
|
||||
)
|
||||
},
|
||||
_ => unsafe {
|
||||
ptr::write(
|
||||
ptr::null_mut() as *mut u32,
|
||||
mem::transmute::<[u8; 4], _>([13, 246, 24, 255]),
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,9 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![allow(clippy::all)]
|
||||
|
||||
fn main() { }
|
||||
fn main() {}
|
||||
|
||||
pub trait Convert {
|
||||
type Action: From<*const f64>;
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![allow(dead_code, clippy::char_lit_as_u8, clippy::needless_bool)]
|
||||
|
||||
/// Should not trigger an ICE in `SpanlessHash` / `consts::constant`
|
||||
|
@ -20,15 +17,17 @@ fn f(s: &[u8]) -> bool {
|
|||
let t = s[0] as char;
|
||||
|
||||
match t {
|
||||
'E' | 'W' => {}
|
||||
'T' => if s[0..4] != ['0' as u8; 4] {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
'E' | 'W' => {},
|
||||
'T' => {
|
||||
if s[0..4] != ['0' as u8; 4] {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![allow(dead_code, unused_variables)]
|
||||
|
||||
/// Should not trigger an ICE in `SpanlessHash` / `consts::constant`
|
||||
|
@ -21,7 +20,7 @@ fn spanless_hash_ice() {
|
|||
match txt {
|
||||
"something" => {
|
||||
let mut headers = [empty_header; 1];
|
||||
}
|
||||
},
|
||||
"" => (),
|
||||
_ => (),
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
pub fn f(new: fn()) {
|
||||
new();
|
||||
}
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![allow(unused_variables, clippy::blacklisted_name,
|
||||
clippy::needless_pass_by_value, dead_code)]
|
||||
#![allow(
|
||||
unused_variables,
|
||||
clippy::blacklisted_name,
|
||||
clippy::needless_pass_by_value,
|
||||
dead_code
|
||||
)]
|
||||
|
||||
// This should not compile-fail with:
|
||||
//
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
// See https://github.com/rust-lang/rust-clippy/issues/2774
|
||||
|
@ -26,18 +23,14 @@ pub struct Foo {}
|
|||
// This should not cause a 'cannot relate bound region' ICE
|
||||
pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) {
|
||||
let mut foos = HashSet::new();
|
||||
foos.extend(
|
||||
bars.iter().map(|b| &b.foo)
|
||||
);
|
||||
foos.extend(bars.iter().map(|b| &b.foo));
|
||||
}
|
||||
|
||||
#[allow(clippy::implicit_hasher)]
|
||||
// Also this should not cause a 'cannot relate bound region' ICE
|
||||
pub fn add_barfoos_to_foos2(bars: &HashSet<&Bar>) {
|
||||
let mut foos = HashSet::new();
|
||||
foos.extend(
|
||||
bars.iter().map(|b| &b.foo)
|
||||
);
|
||||
foos.extend(bars.iter().map(|b| &b.foo));
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct Ice {
|
||||
size: String
|
||||
size: String,
|
||||
}
|
||||
|
||||
impl<'a> From<String> for Ice {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HashMap<V, S> {
|
||||
hash_builder: S,
|
||||
|
@ -17,7 +16,7 @@ pub struct HashMap<V, S> {
|
|||
#[derive(Clone)]
|
||||
pub struct RawTable<V> {
|
||||
size: usize,
|
||||
val: V
|
||||
val: V,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
fn main() {}
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![deny(clippy::all)]
|
||||
|
||||
fn core() {}
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![deny(clippy::all)]
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![deny(clippy::if_same_then_else)]
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
pub trait FooMap {
|
||||
fn map<B, F: Fn() -> B>(&self, f: F) -> B;
|
||||
}
|
||||
|
|
|
@ -7,14 +7,23 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![allow(warnings)]
|
||||
|
||||
// this should compile in a reasonable amount of time
|
||||
fn rust_type_id(name: &str) {
|
||||
if "bool" == &name[..] || "uint" == &name[..] || "u8" == &name[..] || "u16" == &name[..] || "u32" == &name[..]
|
||||
|| "f32" == &name[..] || "f64" == &name[..] || "i8" == &name[..] || "i16" == &name[..]
|
||||
|| "i32" == &name[..] || "i64" == &name[..] || "Self" == &name[..] || "str" == &name[..]
|
||||
if "bool" == &name[..]
|
||||
|| "uint" == &name[..]
|
||||
|| "u8" == &name[..]
|
||||
|| "u16" == &name[..]
|
||||
|| "u32" == &name[..]
|
||||
|| "f32" == &name[..]
|
||||
|| "f64" == &name[..]
|
||||
|| "i8" == &name[..]
|
||||
|| "i16" == &name[..]
|
||||
|| "i32" == &name[..]
|
||||
|| "i64" == &name[..]
|
||||
|| "Self" == &name[..]
|
||||
|| "str" == &name[..]
|
||||
{
|
||||
unreachable!();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
/// Issue: https://github.com/rust-lang/rust-clippy/issues/2596
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![deny(clippy::match_same_arms)]
|
||||
|
||||
const PRICE_OF_SWEETS: u32 = 5;
|
||||
|
@ -21,7 +18,7 @@ pub fn price(thing: &str) -> u32 {
|
|||
"rolo" => PRICE_OF_SWEETS,
|
||||
"advice" => PRICE_OF_KINDNESS,
|
||||
"juice" => PRICE_OF_DRINKS,
|
||||
_ => panic!()
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![deny(clippy::mut_mut, clippy::zero_ptr, clippy::cmp_nan)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
|
|
|
@ -7,16 +7,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#[deny(clippy::all)]
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Type(
|
||||
&'static str,
|
||||
),
|
||||
Type(&'static str),
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![deny(clippy::needless_lifetimes)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#[macro_use]
|
||||
extern crate clippy_mini_macro_test;
|
||||
|
||||
|
@ -17,6 +16,5 @@ fn main() {
|
|||
println!("{:?}", x);
|
||||
}
|
||||
|
||||
|
||||
#[derive(ClippyMiniMacroTest, Debug)]
|
||||
struct Foo;
|
||||
struct Foo;
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![allow(clippy::blacklisted_name)]
|
||||
|
||||
pub fn foo(bar: *const u8) {
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#[deny(warnings)]
|
||||
fn cfg_return() -> i32 {
|
||||
#[cfg(unix)] return 1;
|
||||
#[cfg(not(unix))] return 2;
|
||||
#[cfg(unix)]
|
||||
return 1;
|
||||
#[cfg(not(unix))]
|
||||
return 2;
|
||||
}
|
||||
|
||||
#[deny(warnings)]
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![warn(clippy::single_match_else)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![allow(clippy::useless_attribute)] //issue #2910
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -7,5 +7,4 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
// error-pattern: error reading Clippy's configuration file
|
||||
|
||||
|
||||
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -7,10 +7,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
// error-pattern: error reading Clippy's configuration file: `blacklisted-names` is expected to be a `Vec < String >` but is a `integer`
|
||||
|
||||
|
||||
|
||||
// error-pattern: error reading Clippy's configuration file: `blacklisted-names` is expected to be a
|
||||
// `Vec < String >` but is a `integer`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![allow(clippy::single_match)]
|
||||
#![allow(unused_variables)]
|
||||
|
|
|
@ -1,45 +1,45 @@
|
|||
error: use of a blacklisted/placeholder name `toto`
|
||||
--> $DIR/conf_french_blacklisted_name.rs:19:9
|
||||
--> $DIR/conf_french_blacklisted_name.rs:15:9
|
||||
|
|
||||
19 | fn test(toto: ()) {}
|
||||
15 | fn test(toto: ()) {}
|
||||
| ^^^^
|
||||
|
|
||||
= note: `-D clippy::blacklisted-name` implied by `-D warnings`
|
||||
|
||||
error: use of a blacklisted/placeholder name `toto`
|
||||
--> $DIR/conf_french_blacklisted_name.rs:22:9
|
||||
--> $DIR/conf_french_blacklisted_name.rs:18:9
|
||||
|
|
||||
22 | let toto = 42;
|
||||
18 | let toto = 42;
|
||||
| ^^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `tata`
|
||||
--> $DIR/conf_french_blacklisted_name.rs:23:9
|
||||
--> $DIR/conf_french_blacklisted_name.rs:19:9
|
||||
|
|
||||
23 | let tata = 42;
|
||||
19 | let tata = 42;
|
||||
| ^^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `titi`
|
||||
--> $DIR/conf_french_blacklisted_name.rs:24:9
|
||||
--> $DIR/conf_french_blacklisted_name.rs:20:9
|
||||
|
|
||||
24 | let titi = 42;
|
||||
20 | let titi = 42;
|
||||
| ^^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `toto`
|
||||
--> $DIR/conf_french_blacklisted_name.rs:30:10
|
||||
--> $DIR/conf_french_blacklisted_name.rs:26:10
|
||||
|
|
||||
30 | (toto, Some(tata), titi @ Some(_)) => (),
|
||||
26 | (toto, Some(tata), titi @ Some(_)) => (),
|
||||
| ^^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `tata`
|
||||
--> $DIR/conf_french_blacklisted_name.rs:30:21
|
||||
--> $DIR/conf_french_blacklisted_name.rs:26:21
|
||||
|
|
||||
30 | (toto, Some(tata), titi @ Some(_)) => (),
|
||||
26 | (toto, Some(tata), titi @ Some(_)) => (),
|
||||
| ^^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `titi`
|
||||
--> $DIR/conf_french_blacklisted_name.rs:30:28
|
||||
--> $DIR/conf_french_blacklisted_name.rs:26:28
|
||||
|
|
||||
30 | (toto, Some(tata), titi @ Some(_)) => (),
|
||||
26 | (toto, Some(tata), titi @ Some(_)) => (),
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
#![allow(clippy::many_single_char_names)]
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
|
@ -17,11 +15,9 @@ struct Foo(u8);
|
|||
#[derive(Copy, Clone)]
|
||||
struct Bar(u32);
|
||||
|
||||
fn good(a: &mut u32, b: u32, c: &Bar, d: &u32) {
|
||||
}
|
||||
fn good(a: &mut u32, b: u32, c: &Bar, d: &u32) {}
|
||||
|
||||
fn bad(x: &u16, y: &Foo) {
|
||||
}
|
||||
fn bad(x: &u16, y: &Foo) {}
|
||||
|
||||
fn main() {
|
||||
let (mut a, b, c, d, x, y) = (0, 0, Bar(0), 0, 0, Foo(0));
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
error: this argument is passed by reference, but would be more efficient if passed by value
|
||||
--> $DIR/test.rs:23:11
|
||||
--> $DIR/test.rs:20:11
|
||||
|
|
||||
23 | fn bad(x: &u16, y: &Foo) {
|
||||
20 | fn bad(x: &u16, y: &Foo) {}
|
||||
| ^^^^ help: consider passing by value instead: `u16`
|
||||
|
|
||||
= note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings`
|
||||
|
||||
error: this argument is passed by reference, but would be more efficient if passed by value
|
||||
--> $DIR/test.rs:23:20
|
||||
--> $DIR/test.rs:20:20
|
||||
|
|
||||
23 | fn bad(x: &u16, y: &Foo) {
|
||||
20 | fn bad(x: &u16, y: &Foo) {}
|
||||
| ^^^^ help: consider passing by value instead: `Foo`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
// error-pattern: error reading Clippy's configuration file: unknown key `foobar`
|
||||
|
||||
|
||||
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -8,7 +8,13 @@
|
|||
// except according to those terms.
|
||||
|
||||
#![warn(clippy::absurd_extreme_comparisons)]
|
||||
#![allow(unused, clippy::eq_op, clippy::no_effect, clippy::unnecessary_operation, clippy::needless_pass_by_value)]
|
||||
#![allow(
|
||||
unused,
|
||||
clippy::eq_op,
|
||||
clippy::no_effect,
|
||||
clippy::unnecessary_operation,
|
||||
clippy::needless_pass_by_value
|
||||
)]
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn main() {
|
||||
|
|
|
@ -1,144 +1,144 @@
|
|||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:17:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:23:5
|
||||
|
|
||||
17 | u <= 0;
|
||||
23 | u <= 0;
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings`
|
||||
= help: because 0 is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == 0 instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:18:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:24:5
|
||||
|
|
||||
18 | u <= Z;
|
||||
24 | u <= Z;
|
||||
| ^^^^^^
|
||||
|
|
||||
= help: because Z is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == Z instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:19:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:25:5
|
||||
|
|
||||
19 | u < Z;
|
||||
25 | u < Z;
|
||||
| ^^^^^
|
||||
|
|
||||
= help: because Z is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:20:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:26:5
|
||||
|
|
||||
20 | Z >= u;
|
||||
26 | Z >= u;
|
||||
| ^^^^^^
|
||||
|
|
||||
= help: because Z is the minimum value for this type, the case where the two sides are not equal never occurs, consider using Z == u instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:21:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:27:5
|
||||
|
|
||||
21 | Z > u;
|
||||
27 | Z > u;
|
||||
| ^^^^^
|
||||
|
|
||||
= help: because Z is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:22:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:28:5
|
||||
|
|
||||
22 | u > std::u32::MAX;
|
||||
28 | u > std::u32::MAX;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: because std::u32::MAX is the maximum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:23:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:29:5
|
||||
|
|
||||
23 | u >= std::u32::MAX;
|
||||
29 | u >= std::u32::MAX;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: because std::u32::MAX is the maximum value for this type, the case where the two sides are not equal never occurs, consider using u == std::u32::MAX instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:24:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:30:5
|
||||
|
|
||||
24 | std::u32::MAX < u;
|
||||
30 | std::u32::MAX < u;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: because std::u32::MAX is the maximum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:25:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:31:5
|
||||
|
|
||||
25 | std::u32::MAX <= u;
|
||||
31 | std::u32::MAX <= u;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: because std::u32::MAX is the maximum value for this type, the case where the two sides are not equal never occurs, consider using std::u32::MAX == u instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:26:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:32:5
|
||||
|
|
||||
26 | 1-1 > u;
|
||||
32 | 1-1 > u;
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: because 1-1 is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:27:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:33:5
|
||||
|
|
||||
27 | u >= !0;
|
||||
33 | u >= !0;
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: because !0 is the maximum value for this type, the case where the two sides are not equal never occurs, consider using u == !0 instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:28:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:34:5
|
||||
|
|
||||
28 | u <= 12 - 2*6;
|
||||
34 | u <= 12 - 2*6;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= help: because 12 - 2*6 is the minimum value for this type, the case where the two sides are not equal never occurs, consider using u == 12 - 2*6 instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:30:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:36:5
|
||||
|
|
||||
30 | i < -127 - 1;
|
||||
36 | i < -127 - 1;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= help: because -127 - 1 is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:31:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:37:5
|
||||
|
|
||||
31 | std::i8::MAX >= i;
|
||||
37 | std::i8::MAX >= i;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: because std::i8::MAX is the maximum value for this type, this comparison is always true
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:32:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:38:5
|
||||
|
|
||||
32 | 3-7 < std::i32::MIN;
|
||||
38 | 3-7 < std::i32::MIN;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: because std::i32::MIN is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:34:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:40:5
|
||||
|
|
||||
34 | b >= true;
|
||||
40 | b >= true;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: because true is the maximum value for this type, the case where the two sides are not equal never occurs, consider using b == true instead
|
||||
|
||||
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:35:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:41:5
|
||||
|
|
||||
35 | false > b;
|
||||
41 | false > b;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: because false is the minimum value for this type, this comparison is always false
|
||||
|
||||
error: <-comparison of unit values detected. This will always be false
|
||||
--> $DIR/absurd-extreme-comparisons.rs:38:5
|
||||
--> $DIR/absurd-extreme-comparisons.rs:44:5
|
||||
|
|
||||
38 | () < {};
|
||||
44 | () < {};
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: #[deny(clippy::unit_cmp)] on by default
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#[warn(clippy::approx_constant)]
|
||||
#[allow(unused, clippy::shadow_unrelated, clippy::similar_names, clippy::unreadable_literal)]
|
||||
fn main() {
|
||||
|
|
|
@ -1,117 +1,117 @@
|
|||
error: approximate value of `f{32, 64}::consts::E` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:17:16
|
||||
--> $DIR/approx_const.rs:13:16
|
||||
|
|
||||
17 | let my_e = 2.7182;
|
||||
13 | let my_e = 2.7182;
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: `-D clippy::approx-constant` implied by `-D warnings`
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::E` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:18:20
|
||||
--> $DIR/approx_const.rs:14:20
|
||||
|
|
||||
18 | let almost_e = 2.718;
|
||||
14 | let almost_e = 2.718;
|
||||
| ^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_1_PI` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:21:24
|
||||
--> $DIR/approx_const.rs:17:24
|
||||
|
|
||||
21 | let my_1_frac_pi = 0.3183;
|
||||
17 | let my_1_frac_pi = 0.3183;
|
||||
| ^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:24:28
|
||||
--> $DIR/approx_const.rs:20:28
|
||||
|
|
||||
24 | let my_frac_1_sqrt_2 = 0.70710678;
|
||||
20 | let my_frac_1_sqrt_2 = 0.70710678;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_1_SQRT_2` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:25:32
|
||||
--> $DIR/approx_const.rs:21:32
|
||||
|
|
||||
25 | let almost_frac_1_sqrt_2 = 0.70711;
|
||||
21 | let almost_frac_1_sqrt_2 = 0.70711;
|
||||
| ^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_2_PI` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:28:24
|
||||
--> $DIR/approx_const.rs:24:24
|
||||
|
|
||||
28 | let my_frac_2_pi = 0.63661977;
|
||||
24 | let my_frac_2_pi = 0.63661977;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_2_SQRT_PI` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:31:27
|
||||
--> $DIR/approx_const.rs:27:27
|
||||
|
|
||||
31 | let my_frac_2_sq_pi = 1.128379;
|
||||
27 | let my_frac_2_sq_pi = 1.128379;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_PI_2` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:34:24
|
||||
--> $DIR/approx_const.rs:30:24
|
||||
|
|
||||
34 | let my_frac_pi_2 = 1.57079632679;
|
||||
30 | let my_frac_pi_2 = 1.57079632679;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_PI_3` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:37:24
|
||||
--> $DIR/approx_const.rs:33:24
|
||||
|
|
||||
37 | let my_frac_pi_3 = 1.04719755119;
|
||||
33 | let my_frac_pi_3 = 1.04719755119;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_PI_4` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:40:24
|
||||
--> $DIR/approx_const.rs:36:24
|
||||
|
|
||||
40 | let my_frac_pi_4 = 0.785398163397;
|
||||
36 | let my_frac_pi_4 = 0.785398163397;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_PI_6` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:43:24
|
||||
--> $DIR/approx_const.rs:39:24
|
||||
|
|
||||
43 | let my_frac_pi_6 = 0.523598775598;
|
||||
39 | let my_frac_pi_6 = 0.523598775598;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::FRAC_PI_8` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:46:24
|
||||
--> $DIR/approx_const.rs:42:24
|
||||
|
|
||||
46 | let my_frac_pi_8 = 0.3926990816987;
|
||||
42 | let my_frac_pi_8 = 0.3926990816987;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::LN_10` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:49:20
|
||||
--> $DIR/approx_const.rs:45:20
|
||||
|
|
||||
49 | let my_ln_10 = 2.302585092994046;
|
||||
45 | let my_ln_10 = 2.302585092994046;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::LN_2` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:52:19
|
||||
--> $DIR/approx_const.rs:48:19
|
||||
|
|
||||
52 | let my_ln_2 = 0.6931471805599453;
|
||||
48 | let my_ln_2 = 0.6931471805599453;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::LOG10_E` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:55:22
|
||||
--> $DIR/approx_const.rs:51:22
|
||||
|
|
||||
55 | let my_log10_e = 0.4342944819032518;
|
||||
51 | let my_log10_e = 0.4342944819032518;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::LOG2_E` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:58:21
|
||||
--> $DIR/approx_const.rs:54:21
|
||||
|
|
||||
58 | let my_log2_e = 1.4426950408889634;
|
||||
54 | let my_log2_e = 1.4426950408889634;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:61:17
|
||||
--> $DIR/approx_const.rs:57:17
|
||||
|
|
||||
61 | let my_pi = 3.1415;
|
||||
57 | let my_pi = 3.1415;
|
||||
| ^^^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:62:21
|
||||
--> $DIR/approx_const.rs:58:21
|
||||
|
|
||||
62 | let almost_pi = 3.14;
|
||||
58 | let almost_pi = 3.14;
|
||||
| ^^^^
|
||||
|
||||
error: approximate value of `f{32, 64}::consts::SQRT_2` found. Consider using it directly
|
||||
--> $DIR/approx_const.rs:65:18
|
||||
--> $DIR/approx_const.rs:61:18
|
||||
|
|
||||
65 | let my_sq2 = 1.4142;
|
||||
61 | let my_sq2 = 1.4142;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 19 previous errors
|
||||
|
|
|
@ -7,9 +7,14 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![warn(clippy::integer_arithmetic, clippy::float_arithmetic)]
|
||||
#![allow(unused, clippy::shadow_reuse, clippy::shadow_unrelated, clippy::no_effect, clippy::unnecessary_operation)]
|
||||
#![allow(
|
||||
unused,
|
||||
clippy::shadow_reuse,
|
||||
clippy::shadow_unrelated,
|
||||
clippy::no_effect,
|
||||
clippy::unnecessary_operation
|
||||
)]
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn main() {
|
||||
|
|
|
@ -1,72 +1,72 @@
|
|||
error: integer arithmetic detected
|
||||
--> $DIR/arithmetic.rs:17:5
|
||||
--> $DIR/arithmetic.rs:22:5
|
||||
|
|
||||
17 | 1 + i;
|
||||
22 | 1 + i;
|
||||
| ^^^^^
|
||||
|
|
||||
= note: `-D clippy::integer-arithmetic` implied by `-D warnings`
|
||||
|
||||
error: integer arithmetic detected
|
||||
--> $DIR/arithmetic.rs:18:5
|
||||
--> $DIR/arithmetic.rs:23:5
|
||||
|
|
||||
18 | i * 2;
|
||||
23 | i * 2;
|
||||
| ^^^^^
|
||||
|
||||
error: integer arithmetic detected
|
||||
--> $DIR/arithmetic.rs:19:5
|
||||
--> $DIR/arithmetic.rs:24:5
|
||||
|
|
||||
19 | / 1 %
|
||||
20 | | i / 2; // no error, this is part of the expression in the preceding line
|
||||
24 | / 1 %
|
||||
25 | | i / 2; // no error, this is part of the expression in the preceding line
|
||||
| |_________^
|
||||
|
||||
error: integer arithmetic detected
|
||||
--> $DIR/arithmetic.rs:21:5
|
||||
--> $DIR/arithmetic.rs:26:5
|
||||
|
|
||||
21 | i - 2 + 2 - i;
|
||||
26 | i - 2 + 2 - i;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: integer arithmetic detected
|
||||
--> $DIR/arithmetic.rs:22:5
|
||||
--> $DIR/arithmetic.rs:27:5
|
||||
|
|
||||
22 | -i;
|
||||
27 | -i;
|
||||
| ^^
|
||||
|
||||
error: floating-point arithmetic detected
|
||||
--> $DIR/arithmetic.rs:32:5
|
||||
--> $DIR/arithmetic.rs:37:5
|
||||
|
|
||||
32 | f * 2.0;
|
||||
37 | f * 2.0;
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::float-arithmetic` implied by `-D warnings`
|
||||
|
||||
error: floating-point arithmetic detected
|
||||
--> $DIR/arithmetic.rs:34:5
|
||||
--> $DIR/arithmetic.rs:39:5
|
||||
|
|
||||
34 | 1.0 + f;
|
||||
39 | 1.0 + f;
|
||||
| ^^^^^^^
|
||||
|
||||
error: floating-point arithmetic detected
|
||||
--> $DIR/arithmetic.rs:35:5
|
||||
--> $DIR/arithmetic.rs:40:5
|
||||
|
|
||||
35 | f * 2.0;
|
||||
40 | f * 2.0;
|
||||
| ^^^^^^^
|
||||
|
||||
error: floating-point arithmetic detected
|
||||
--> $DIR/arithmetic.rs:36:5
|
||||
--> $DIR/arithmetic.rs:41:5
|
||||
|
|
||||
36 | f / 2.0;
|
||||
41 | f / 2.0;
|
||||
| ^^^^^^^
|
||||
|
||||
error: floating-point arithmetic detected
|
||||
--> $DIR/arithmetic.rs:37:5
|
||||
--> $DIR/arithmetic.rs:42:5
|
||||
|
|
||||
37 | f - 2.0 * 4.2;
|
||||
42 | f - 2.0 * 4.2;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: floating-point arithmetic detected
|
||||
--> $DIR/arithmetic.rs:38:5
|
||||
--> $DIR/arithmetic.rs:43:5
|
||||
|
|
||||
38 | -f;
|
||||
43 | -f;
|
||||
| ^^
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#[allow(dead_code, unused_assignments)]
|
||||
#[warn(clippy::assign_op_pattern)]
|
||||
fn main() {
|
||||
|
|
|
@ -1,57 +1,57 @@
|
|||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:17:5
|
||||
--> $DIR/assign_ops.rs:14:5
|
||||
|
|
||||
17 | a = a + 1;
|
||||
14 | a = a + 1;
|
||||
| ^^^^^^^^^ help: replace it with: `a += 1`
|
||||
|
|
||||
= note: `-D clippy::assign-op-pattern` implied by `-D warnings`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:15:5
|
||||
|
|
||||
15 | a = 1 + a;
|
||||
| ^^^^^^^^^ help: replace it with: `a += 1`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:16:5
|
||||
|
|
||||
16 | a = a - 1;
|
||||
| ^^^^^^^^^ help: replace it with: `a -= 1`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:17:5
|
||||
|
|
||||
17 | a = a * 99;
|
||||
| ^^^^^^^^^^ help: replace it with: `a *= 99`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:18:5
|
||||
|
|
||||
18 | a = 1 + a;
|
||||
| ^^^^^^^^^ help: replace it with: `a += 1`
|
||||
18 | a = 42 * a;
|
||||
| ^^^^^^^^^^ help: replace it with: `a *= 42`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:19:5
|
||||
|
|
||||
19 | a = a - 1;
|
||||
| ^^^^^^^^^ help: replace it with: `a -= 1`
|
||||
19 | a = a / 2;
|
||||
| ^^^^^^^^^ help: replace it with: `a /= 2`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:20:5
|
||||
|
|
||||
20 | a = a * 99;
|
||||
| ^^^^^^^^^^ help: replace it with: `a *= 99`
|
||||
20 | a = a % 5;
|
||||
| ^^^^^^^^^ help: replace it with: `a %= 5`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:21:5
|
||||
|
|
||||
21 | a = 42 * a;
|
||||
| ^^^^^^^^^^ help: replace it with: `a *= 42`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:22:5
|
||||
|
|
||||
22 | a = a / 2;
|
||||
| ^^^^^^^^^ help: replace it with: `a /= 2`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:23:5
|
||||
|
|
||||
23 | a = a % 5;
|
||||
| ^^^^^^^^^ help: replace it with: `a %= 5`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:24:5
|
||||
|
|
||||
24 | a = a & 1;
|
||||
21 | a = a & 1;
|
||||
| ^^^^^^^^^ help: replace it with: `a &= 1`
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops.rs:30:5
|
||||
--> $DIR/assign_ops.rs:27:5
|
||||
|
|
||||
30 | s = s + "bla";
|
||||
27 | s = s + "bla";
|
||||
| ^^^^^^^^^^^^^ help: replace it with: `s += "bla"`
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#[allow(unused_assignments)]
|
||||
#[warn(clippy::misrefactored_assign_op, clippy::assign_op_pattern)]
|
||||
fn main() {
|
||||
|
@ -65,6 +61,4 @@ fn cow_add_assign() {
|
|||
// this should not as cow<str> Add is not commutative
|
||||
buf = cows + buf;
|
||||
println!("{}", buf);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,135 +1,135 @@
|
|||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:18:5
|
||||
--> $DIR/assign_ops2.rs:14:5
|
||||
|
|
||||
18 | a += a + 1;
|
||||
14 | a += a + 1;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::misrefactored-assign-op` implied by `-D warnings`
|
||||
help: Did you mean a = a + 1 or a = a + a + 1? Consider replacing it with
|
||||
|
|
||||
18 | a += 1;
|
||||
14 | a += 1;
|
||||
| ^^^^^^
|
||||
help: or
|
||||
|
|
||||
18 | a = a + a + 1;
|
||||
14 | a = a + a + 1;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:15:5
|
||||
|
|
||||
15 | a += 1 + a;
|
||||
| ^^^^^^^^^^
|
||||
help: Did you mean a = a + 1 or a = a + 1 + a? Consider replacing it with
|
||||
|
|
||||
15 | a += 1;
|
||||
| ^^^^^^
|
||||
help: or
|
||||
|
|
||||
15 | a = a + 1 + a;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:16:5
|
||||
|
|
||||
16 | a -= a - 1;
|
||||
| ^^^^^^^^^^
|
||||
help: Did you mean a = a - 1 or a = a - (a - 1)? Consider replacing it with
|
||||
|
|
||||
16 | a -= 1;
|
||||
| ^^^^^^
|
||||
help: or
|
||||
|
|
||||
16 | a = a - (a - 1);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:17:5
|
||||
|
|
||||
17 | a *= a * 99;
|
||||
| ^^^^^^^^^^^
|
||||
help: Did you mean a = a * 99 or a = a * a * 99? Consider replacing it with
|
||||
|
|
||||
17 | a *= 99;
|
||||
| ^^^^^^^
|
||||
help: or
|
||||
|
|
||||
17 | a = a * a * 99;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:18:5
|
||||
|
|
||||
18 | a *= 42 * a;
|
||||
| ^^^^^^^^^^^
|
||||
help: Did you mean a = a * 42 or a = a * 42 * a? Consider replacing it with
|
||||
|
|
||||
18 | a *= 42;
|
||||
| ^^^^^^^
|
||||
help: or
|
||||
|
|
||||
18 | a = a * 42 * a;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:19:5
|
||||
|
|
||||
19 | a += 1 + a;
|
||||
19 | a /= a / 2;
|
||||
| ^^^^^^^^^^
|
||||
help: Did you mean a = a + 1 or a = a + 1 + a? Consider replacing it with
|
||||
help: Did you mean a = a / 2 or a = a / (a / 2)? Consider replacing it with
|
||||
|
|
||||
19 | a += 1;
|
||||
19 | a /= 2;
|
||||
| ^^^^^^
|
||||
help: or
|
||||
|
|
||||
19 | a = a + 1 + a;
|
||||
| ^^^^^^^^^^^^^
|
||||
19 | a = a / (a / 2);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:20:5
|
||||
|
|
||||
20 | a -= a - 1;
|
||||
20 | a %= a % 5;
|
||||
| ^^^^^^^^^^
|
||||
help: Did you mean a = a - 1 or a = a - (a - 1)? Consider replacing it with
|
||||
help: Did you mean a = a % 5 or a = a % (a % 5)? Consider replacing it with
|
||||
|
|
||||
20 | a -= 1;
|
||||
20 | a %= 5;
|
||||
| ^^^^^^
|
||||
help: or
|
||||
|
|
||||
20 | a = a - (a - 1);
|
||||
20 | a = a % (a % 5);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:21:5
|
||||
|
|
||||
21 | a *= a * 99;
|
||||
| ^^^^^^^^^^^
|
||||
help: Did you mean a = a * 99 or a = a * a * 99? Consider replacing it with
|
||||
21 | a &= a & 1;
|
||||
| ^^^^^^^^^^
|
||||
help: Did you mean a = a & 1 or a = a & a & 1? Consider replacing it with
|
||||
|
|
||||
21 | a *= 99;
|
||||
| ^^^^^^^
|
||||
21 | a &= 1;
|
||||
| ^^^^^^
|
||||
help: or
|
||||
|
|
||||
21 | a = a * a * 99;
|
||||
| ^^^^^^^^^^^^^^
|
||||
21 | a = a & a & 1;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:22:5
|
||||
|
|
||||
22 | a *= 42 * a;
|
||||
| ^^^^^^^^^^^
|
||||
help: Did you mean a = a * 42 or a = a * 42 * a? Consider replacing it with
|
||||
|
|
||||
22 | a *= 42;
|
||||
| ^^^^^^^
|
||||
help: or
|
||||
|
|
||||
22 | a = a * 42 * a;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:23:5
|
||||
|
|
||||
23 | a /= a / 2;
|
||||
| ^^^^^^^^^^
|
||||
help: Did you mean a = a / 2 or a = a / (a / 2)? Consider replacing it with
|
||||
|
|
||||
23 | a /= 2;
|
||||
| ^^^^^^
|
||||
help: or
|
||||
|
|
||||
23 | a = a / (a / 2);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:24:5
|
||||
|
|
||||
24 | a %= a % 5;
|
||||
| ^^^^^^^^^^
|
||||
help: Did you mean a = a % 5 or a = a % (a % 5)? Consider replacing it with
|
||||
|
|
||||
24 | a %= 5;
|
||||
| ^^^^^^
|
||||
help: or
|
||||
|
|
||||
24 | a = a % (a % 5);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:25:5
|
||||
|
|
||||
25 | a &= a & 1;
|
||||
| ^^^^^^^^^^
|
||||
help: Did you mean a = a & 1 or a = a & a & 1? Consider replacing it with
|
||||
|
|
||||
25 | a &= 1;
|
||||
| ^^^^^^
|
||||
help: or
|
||||
|
|
||||
25 | a = a & a & 1;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: variable appears on both sides of an assignment operation
|
||||
--> $DIR/assign_ops2.rs:26:5
|
||||
|
|
||||
26 | a *= a * a;
|
||||
22 | a *= a * a;
|
||||
| ^^^^^^^^^^
|
||||
help: Did you mean a = a * a or a = a * a * a? Consider replacing it with
|
||||
|
|
||||
26 | a *= a;
|
||||
22 | a *= a;
|
||||
| ^^^^^^
|
||||
help: or
|
||||
|
|
||||
26 | a = a * a * a;
|
||||
22 | a = a * a * a;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: manual implementation of an assign operation
|
||||
--> $DIR/assign_ops2.rs:63:5
|
||||
--> $DIR/assign_ops2.rs:59:5
|
||||
|
|
||||
63 | buf = buf + cows.clone();
|
||||
59 | buf = buf + cows.clone();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()`
|
||||
|
|
||||
= note: `-D clippy::assign-op-pattern` implied by `-D warnings`
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#![warn(clippy::inline_always, clippy::deprecated_semver)]
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -30,22 +26,27 @@ fn false_positive_stmt() {
|
|||
|
||||
#[inline(always)]
|
||||
fn empty_and_false_positive_stmt() {
|
||||
;
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
#[deprecated(since = "forever")]
|
||||
pub const SOME_CONST : u8 = 42;
|
||||
pub const SOME_CONST: u8 = 42;
|
||||
|
||||
#[deprecated(since = "1")]
|
||||
pub const ANOTHER_CONST : u8 = 23;
|
||||
pub const ANOTHER_CONST: u8 = 23;
|
||||
|
||||
#[deprecated(since = "0.1.1")]
|
||||
pub const YET_ANOTHER_CONST : u8 = 0;
|
||||
pub const YET_ANOTHER_CONST: u8 = 0;
|
||||
|
||||
fn main() {
|
||||
test_attr_lint();
|
||||
if false { false_positive_expr() }
|
||||
if false { false_positive_stmt() }
|
||||
if false { empty_and_false_positive_stmt() }
|
||||
if false {
|
||||
false_positive_expr()
|
||||
}
|
||||
if false {
|
||||
false_positive_stmt()
|
||||
}
|
||||
if false {
|
||||
empty_and_false_positive_stmt()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
error: you have declared `#[inline(always)]` on `test_attr_lint`. This is usually a bad idea
|
||||
--> $DIR/attrs.rs:16:1
|
||||
--> $DIR/attrs.rs:12:1
|
||||
|
|
||||
16 | #[inline(always)]
|
||||
12 | #[inline(always)]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::inline-always` implied by `-D warnings`
|
||||
|
||||
error: the since field must contain a semver-compliant version
|
||||
--> $DIR/attrs.rs:37:14
|
||||
--> $DIR/attrs.rs:32:14
|
||||
|
|
||||
37 | #[deprecated(since = "forever")]
|
||||
32 | #[deprecated(since = "forever")]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::deprecated-semver` implied by `-D warnings`
|
||||
|
||||
error: the since field must contain a semver-compliant version
|
||||
--> $DIR/attrs.rs:40:14
|
||||
--> $DIR/attrs.rs:35:14
|
||||
|
|
||||
40 | #[deprecated(since = "1")]
|
||||
35 | #[deprecated(since = "1")]
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
|
|
@ -7,11 +7,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
fn main() {
|
||||
|
||||
#[clippy::author]
|
||||
let x: char = 0x45 as char;
|
||||
}
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
fn main() {
|
||||
#[clippy::author]
|
||||
let _ = ::std::cmp::min(3, 4);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(tool_attributes)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
error: returning the result of a let binding from a block. Consider returning the expression directly.
|
||||
--> $DIR/matches.rs:19:13
|
||||
--> $DIR/matches.rs:18:13
|
||||
|
|
||||
19 | x
|
||||
18 | x
|
||||
| ^
|
||||
|
|
||||
= note: `-D clippy::let-and-return` implied by `-D warnings`
|
||||
note: this expression can be directly returned
|
||||
--> $DIR/matches.rs:18:21
|
||||
--> $DIR/matches.rs:17:21
|
||||
|
|
||||
18 | let x = 3;
|
||||
17 | let x = 3;
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
|
@ -7,15 +7,16 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const THREE_BITS : i64 = 7;
|
||||
const EVEN_MORE_REDIRECTION : i64 = THREE_BITS;
|
||||
const THREE_BITS: i64 = 7;
|
||||
const EVEN_MORE_REDIRECTION: i64 = THREE_BITS;
|
||||
|
||||
#[warn(clippy::bad_bit_mask)]
|
||||
#[allow(clippy::ineffective_bit_mask, clippy::identity_op, clippy::no_effect, clippy::unnecessary_operation)]
|
||||
#[allow(
|
||||
clippy::ineffective_bit_mask,
|
||||
clippy::identity_op,
|
||||
clippy::no_effect,
|
||||
clippy::unnecessary_operation
|
||||
)]
|
||||
fn main() {
|
||||
let x = 5;
|
||||
|
||||
|
|
|
@ -1,109 +1,109 @@
|
|||
error: &-masking with zero
|
||||
--> $DIR/bit_masks.rs:22:5
|
||||
--> $DIR/bit_masks.rs:23:5
|
||||
|
|
||||
22 | x & 0 == 0;
|
||||
23 | x & 0 == 0;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::bad-bit-mask` implied by `-D warnings`
|
||||
|
||||
error: this operation will always return zero. This is likely not the intended outcome
|
||||
--> $DIR/bit_masks.rs:22:5
|
||||
--> $DIR/bit_masks.rs:23:5
|
||||
|
|
||||
22 | x & 0 == 0;
|
||||
23 | x & 0 == 0;
|
||||
| ^^^^^
|
||||
|
|
||||
= note: #[deny(clippy::erasing_op)] on by default
|
||||
|
||||
error: incompatible bit mask: `_ & 2` can never be equal to `1`
|
||||
--> $DIR/bit_masks.rs:25:5
|
||||
--> $DIR/bit_masks.rs:26:5
|
||||
|
|
||||
25 | x & 2 == 1;
|
||||
26 | x & 2 == 1;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 3` can never be equal to `2`
|
||||
--> $DIR/bit_masks.rs:29:5
|
||||
--> $DIR/bit_masks.rs:30:5
|
||||
|
|
||||
29 | x | 3 == 2;
|
||||
30 | x | 3 == 2;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ & 1` will never be higher than `1`
|
||||
--> $DIR/bit_masks.rs:31:5
|
||||
--> $DIR/bit_masks.rs:32:5
|
||||
|
|
||||
31 | x & 1 > 1;
|
||||
32 | x & 1 > 1;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 2` will always be higher than `1`
|
||||
--> $DIR/bit_masks.rs:35:5
|
||||
--> $DIR/bit_masks.rs:36:5
|
||||
|
|
||||
35 | x | 2 > 1;
|
||||
36 | x | 2 > 1;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ & 7` can never be equal to `8`
|
||||
--> $DIR/bit_masks.rs:42:5
|
||||
--> $DIR/bit_masks.rs:43:5
|
||||
|
|
||||
42 | x & THREE_BITS == 8;
|
||||
43 | x & THREE_BITS == 8;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 7` will never be lower than `7`
|
||||
--> $DIR/bit_masks.rs:43:5
|
||||
--> $DIR/bit_masks.rs:44:5
|
||||
|
|
||||
43 | x | EVEN_MORE_REDIRECTION < 7;
|
||||
44 | x | EVEN_MORE_REDIRECTION < 7;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: &-masking with zero
|
||||
--> $DIR/bit_masks.rs:45:5
|
||||
--> $DIR/bit_masks.rs:46:5
|
||||
|
|
||||
45 | 0 & x == 0;
|
||||
46 | 0 & x == 0;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: this operation will always return zero. This is likely not the intended outcome
|
||||
--> $DIR/bit_masks.rs:45:5
|
||||
--> $DIR/bit_masks.rs:46:5
|
||||
|
|
||||
45 | 0 & x == 0;
|
||||
46 | 0 & x == 0;
|
||||
| ^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 2` will always be higher than `1`
|
||||
--> $DIR/bit_masks.rs:49:5
|
||||
--> $DIR/bit_masks.rs:50:5
|
||||
|
|
||||
49 | 1 < 2 | x;
|
||||
50 | 1 < 2 | x;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ | 3` can never be equal to `2`
|
||||
--> $DIR/bit_masks.rs:50:5
|
||||
--> $DIR/bit_masks.rs:51:5
|
||||
|
|
||||
50 | 2 == 3 | x;
|
||||
51 | 2 == 3 | x;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: incompatible bit mask: `_ & 2` can never be equal to `1`
|
||||
--> $DIR/bit_masks.rs:51:5
|
||||
--> $DIR/bit_masks.rs:52:5
|
||||
|
|
||||
51 | 1 == x & 2;
|
||||
52 | 1 == x & 2;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly
|
||||
--> $DIR/bit_masks.rs:62:5
|
||||
--> $DIR/bit_masks.rs:63:5
|
||||
|
|
||||
62 | x | 1 > 3;
|
||||
63 | x | 1 > 3;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::ineffective-bit-mask` implied by `-D warnings`
|
||||
|
||||
error: ineffective bit mask: `x | 1` compared to `4`, is the same as x compared directly
|
||||
--> $DIR/bit_masks.rs:63:5
|
||||
--> $DIR/bit_masks.rs:64:5
|
||||
|
|
||||
63 | x | 1 < 4;
|
||||
64 | x | 1 < 4;
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: ineffective bit mask: `x | 1` compared to `3`, is the same as x compared directly
|
||||
--> $DIR/bit_masks.rs:64:5
|
||||
--> $DIR/bit_masks.rs:65:5
|
||||
|
|
||||
64 | x | 1 <= 3;
|
||||
65 | x | 1 <= 3;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: ineffective bit mask: `x | 1` compared to `8`, is the same as x compared directly
|
||||
--> $DIR/bit_masks.rs:65:5
|
||||
--> $DIR/bit_masks.rs:66:5
|
||||
|
|
||||
65 | x | 1 >= 8;
|
||||
66 | x | 1 >= 8;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
|
|
@ -7,11 +7,14 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#![allow(dead_code, clippy::similar_names, clippy::single_match, clippy::toplevel_ref_arg, unused_mut, unused_variables)]
|
||||
#![allow(
|
||||
dead_code,
|
||||
clippy::similar_names,
|
||||
clippy::single_match,
|
||||
clippy::toplevel_ref_arg,
|
||||
unused_mut,
|
||||
unused_variables
|
||||
)]
|
||||
#![warn(clippy::blacklisted_name)]
|
||||
|
||||
fn test(foo: ()) {}
|
||||
|
|
|
@ -1,87 +1,87 @@
|
|||
error: use of a blacklisted/placeholder name `foo`
|
||||
--> $DIR/blacklisted_name.rs:17:9
|
||||
--> $DIR/blacklisted_name.rs:20:9
|
||||
|
|
||||
17 | fn test(foo: ()) {}
|
||||
20 | fn test(foo: ()) {}
|
||||
| ^^^
|
||||
|
|
||||
= note: `-D clippy::blacklisted-name` implied by `-D warnings`
|
||||
|
||||
error: use of a blacklisted/placeholder name `foo`
|
||||
--> $DIR/blacklisted_name.rs:20:9
|
||||
--> $DIR/blacklisted_name.rs:23:9
|
||||
|
|
||||
20 | let foo = 42;
|
||||
23 | let foo = 42;
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `bar`
|
||||
--> $DIR/blacklisted_name.rs:21:9
|
||||
--> $DIR/blacklisted_name.rs:24:9
|
||||
|
|
||||
21 | let bar = 42;
|
||||
24 | let bar = 42;
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `baz`
|
||||
--> $DIR/blacklisted_name.rs:22:9
|
||||
--> $DIR/blacklisted_name.rs:25:9
|
||||
|
|
||||
22 | let baz = 42;
|
||||
25 | let baz = 42;
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `foo`
|
||||
--> $DIR/blacklisted_name.rs:28:10
|
||||
--> $DIR/blacklisted_name.rs:31:10
|
||||
|
|
||||
28 | (foo, Some(bar), baz @ Some(_)) => (),
|
||||
31 | (foo, Some(bar), baz @ Some(_)) => (),
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `bar`
|
||||
--> $DIR/blacklisted_name.rs:28:20
|
||||
--> $DIR/blacklisted_name.rs:31:20
|
||||
|
|
||||
28 | (foo, Some(bar), baz @ Some(_)) => (),
|
||||
31 | (foo, Some(bar), baz @ Some(_)) => (),
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `baz`
|
||||
--> $DIR/blacklisted_name.rs:28:26
|
||||
--> $DIR/blacklisted_name.rs:31:26
|
||||
|
|
||||
28 | (foo, Some(bar), baz @ Some(_)) => (),
|
||||
31 | (foo, Some(bar), baz @ Some(_)) => (),
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `foo`
|
||||
--> $DIR/blacklisted_name.rs:33:19
|
||||
--> $DIR/blacklisted_name.rs:36:19
|
||||
|
|
||||
33 | fn issue_1647(mut foo: u8) {
|
||||
36 | fn issue_1647(mut foo: u8) {
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `bar`
|
||||
--> $DIR/blacklisted_name.rs:34:13
|
||||
--> $DIR/blacklisted_name.rs:37:13
|
||||
|
|
||||
34 | let mut bar = 0;
|
||||
37 | let mut bar = 0;
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `baz`
|
||||
--> $DIR/blacklisted_name.rs:35:21
|
||||
--> $DIR/blacklisted_name.rs:38:21
|
||||
|
|
||||
35 | if let Some(mut baz) = Some(42) {}
|
||||
38 | if let Some(mut baz) = Some(42) {}
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `bar`
|
||||
--> $DIR/blacklisted_name.rs:39:13
|
||||
--> $DIR/blacklisted_name.rs:42:13
|
||||
|
|
||||
39 | let ref bar = 0;
|
||||
42 | let ref bar = 0;
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `baz`
|
||||
--> $DIR/blacklisted_name.rs:40:21
|
||||
--> $DIR/blacklisted_name.rs:43:21
|
||||
|
|
||||
40 | if let Some(ref baz) = Some(42) {}
|
||||
43 | if let Some(ref baz) = Some(42) {}
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `bar`
|
||||
--> $DIR/blacklisted_name.rs:44:17
|
||||
--> $DIR/blacklisted_name.rs:47:17
|
||||
|
|
||||
44 | let ref mut bar = 0;
|
||||
47 | let ref mut bar = 0;
|
||||
| ^^^
|
||||
|
||||
error: use of a blacklisted/placeholder name `baz`
|
||||
--> $DIR/blacklisted_name.rs:45:25
|
||||
--> $DIR/blacklisted_name.rs:48:25
|
||||
|
|
||||
45 | if let Some(ref mut baz) = Some(42) {}
|
||||
48 | if let Some(ref mut baz) = Some(42) {}
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
|
|
|
@ -7,33 +7,28 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#![warn(clippy::block_in_if_condition_expr)]
|
||||
#![warn(clippy::block_in_if_condition_stmt)]
|
||||
#![allow(unused, clippy::let_and_return)]
|
||||
#![warn(clippy::nonminimal_bool)]
|
||||
|
||||
|
||||
macro_rules! blocky {
|
||||
() => {{true}}
|
||||
() => {{
|
||||
true
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! blocky_too {
|
||||
() => {{
|
||||
let r = true;
|
||||
r
|
||||
}}
|
||||
}};
|
||||
}
|
||||
|
||||
fn macro_if() {
|
||||
if blocky!() {
|
||||
}
|
||||
if blocky!() {}
|
||||
|
||||
if blocky_too!() {
|
||||
}
|
||||
if blocky_too!() {}
|
||||
}
|
||||
|
||||
fn condition_has_block() -> i32 {
|
||||
|
@ -55,7 +50,7 @@ fn condition_has_block_with_single_expression() -> i32 {
|
|||
}
|
||||
}
|
||||
|
||||
fn predicate<F: FnOnce(T) -> bool, T>(pfn: F, val:T) -> bool {
|
||||
fn predicate<F: FnOnce(T) -> bool, T>(pfn: F, val: T) -> bool {
|
||||
pfn(val)
|
||||
}
|
||||
|
||||
|
@ -65,11 +60,24 @@ fn pred_test() {
|
|||
// this is a sneaky case, where the block isn't directly in the condition, but is actually
|
||||
// inside a closure that the condition is using. same principle applies. add some extra
|
||||
// expressions to make sure linter isn't confused by them.
|
||||
if v == 3 && sky == "blue" && predicate(|x| { let target = 3; x == target }, v) {
|
||||
}
|
||||
if v == 3
|
||||
&& sky == "blue"
|
||||
&& predicate(
|
||||
|x| {
|
||||
let target = 3;
|
||||
x == target
|
||||
},
|
||||
v,
|
||||
)
|
||||
{}
|
||||
|
||||
if predicate(|x| { let target = 3; x == target }, v) {
|
||||
}
|
||||
if predicate(
|
||||
|x| {
|
||||
let target = 3;
|
||||
x == target
|
||||
},
|
||||
v,
|
||||
) {}
|
||||
}
|
||||
|
||||
fn condition_is_normal() -> i32 {
|
||||
|
@ -82,9 +90,7 @@ fn condition_is_normal() -> i32 {
|
|||
}
|
||||
|
||||
fn closure_without_block() {
|
||||
if predicate(|x| x == 3, 6) {
|
||||
|
||||
}
|
||||
if predicate(|x| x == 3, 6) {}
|
||||
}
|
||||
|
||||
fn condition_is_unsafe_block() {
|
||||
|
@ -96,8 +102,7 @@ fn condition_is_unsafe_block() {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
fn main() {}
|
||||
|
||||
fn macro_in_closure() {
|
||||
let option = Some(true);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
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/block_in_if_condition.rs:40:8
|
||||
--> $DIR/block_in_if_condition.rs:35:8
|
||||
|
|
||||
40 | if {
|
||||
35 | if {
|
||||
| ________^
|
||||
41 | | let x = 3;
|
||||
42 | | x == 3
|
||||
43 | | } {
|
||||
36 | | let x = 3;
|
||||
37 | | x == 3
|
||||
38 | | } {
|
||||
| |_____^
|
||||
|
|
||||
= note: `-D clippy::block-in-if-condition-stmt` implied by `-D warnings`
|
||||
|
@ -19,9 +19,9 @@ error: in an 'if' condition, avoid complex blocks or closures with blocks; inste
|
|||
} ...
|
||||
|
||||
error: omit braces around single expression condition
|
||||
--> $DIR/block_in_if_condition.rs:51:8
|
||||
--> $DIR/block_in_if_condition.rs:46:8
|
||||
|
|
||||
51 | if { true } {
|
||||
46 | if { true } {
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::block-in-if-condition-expr` implied by `-D warnings`
|
||||
|
@ -31,21 +31,29 @@ error: omit braces around single expression condition
|
|||
} ...
|
||||
|
||||
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/block_in_if_condition.rs:68:49
|
||||
--> $DIR/block_in_if_condition.rs:66:17
|
||||
|
|
||||
68 | if v == 3 && sky == "blue" && predicate(|x| { let target = 3; x == target }, v) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
66 | |x| {
|
||||
| _________________^
|
||||
67 | | let target = 3;
|
||||
68 | | x == target
|
||||
69 | | },
|
||||
| |_____________^
|
||||
|
||||
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/block_in_if_condition.rs:71:22
|
||||
--> $DIR/block_in_if_condition.rs:75:13
|
||||
|
|
||||
71 | if predicate(|x| { let target = 3; x == target }, v) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
75 | |x| {
|
||||
| _____________^
|
||||
76 | | let target = 3;
|
||||
77 | | x == target
|
||||
78 | | },
|
||||
| |_________^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/block_in_if_condition.rs:77:8
|
||||
--> $DIR/block_in_if_condition.rs:85:8
|
||||
|
|
||||
77 | if true && x == 3 {
|
||||
85 | if true && x == 3 {
|
||||
| ^^^^^^^^^^^^^^ help: try: `x == 3`
|
||||
|
|
||||
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
|
||||
|
|
|
@ -7,19 +7,47 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#[warn(clippy::bool_comparison)]
|
||||
fn main() {
|
||||
let x = true;
|
||||
if x == true { "yes" } else { "no" };
|
||||
if x == false { "yes" } else { "no" };
|
||||
if true == x { "yes" } else { "no" };
|
||||
if false == x { "yes" } else { "no" };
|
||||
if x != true { "yes" } else { "no" };
|
||||
if x != false { "yes" } else { "no" };
|
||||
if true != x { "yes" } else { "no" };
|
||||
if false != x { "yes" } else { "no" };
|
||||
if x == true {
|
||||
"yes"
|
||||
} else {
|
||||
"no"
|
||||
};
|
||||
if x == false {
|
||||
"yes"
|
||||
} else {
|
||||
"no"
|
||||
};
|
||||
if true == x {
|
||||
"yes"
|
||||
} else {
|
||||
"no"
|
||||
};
|
||||
if false == x {
|
||||
"yes"
|
||||
} else {
|
||||
"no"
|
||||
};
|
||||
if x != true {
|
||||
"yes"
|
||||
} else {
|
||||
"no"
|
||||
};
|
||||
if x != false {
|
||||
"yes"
|
||||
} else {
|
||||
"no"
|
||||
};
|
||||
if true != x {
|
||||
"yes"
|
||||
} else {
|
||||
"no"
|
||||
};
|
||||
if false != x {
|
||||
"yes"
|
||||
} else {
|
||||
"no"
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error: equality checks against true are unnecessary
|
||||
--> $DIR/bool_comparison.rs:17:8
|
||||
--> $DIR/bool_comparison.rs:13:8
|
||||
|
|
||||
17 | if x == true { "yes" } else { "no" };
|
||||
13 | if x == true {
|
||||
| ^^^^^^^^^ help: try simplifying it as shown: `x`
|
||||
|
|
||||
= note: `-D clippy::bool-comparison` implied by `-D warnings`
|
||||
|
@ -9,43 +9,43 @@ error: equality checks against true are unnecessary
|
|||
error: equality checks against false can be replaced by a negation
|
||||
--> $DIR/bool_comparison.rs:18:8
|
||||
|
|
||||
18 | if x == false { "yes" } else { "no" };
|
||||
18 | if x == false {
|
||||
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
|
||||
|
||||
error: equality checks against true are unnecessary
|
||||
--> $DIR/bool_comparison.rs:19:8
|
||||
--> $DIR/bool_comparison.rs:23:8
|
||||
|
|
||||
19 | if true == x { "yes" } else { "no" };
|
||||
23 | if true == x {
|
||||
| ^^^^^^^^^ help: try simplifying it as shown: `x`
|
||||
|
||||
error: equality checks against false can be replaced by a negation
|
||||
--> $DIR/bool_comparison.rs:20:8
|
||||
--> $DIR/bool_comparison.rs:28:8
|
||||
|
|
||||
20 | if false == x { "yes" } else { "no" };
|
||||
28 | if false == x {
|
||||
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`
|
||||
|
||||
error: inequality checks against true can be replaced by a negation
|
||||
--> $DIR/bool_comparison.rs:21:8
|
||||
--> $DIR/bool_comparison.rs:33:8
|
||||
|
|
||||
21 | if x != true { "yes" } else { "no" };
|
||||
33 | if x != true {
|
||||
| ^^^^^^^^^ help: try simplifying it as shown: `!x`
|
||||
|
||||
error: inequality checks against false are unnecessary
|
||||
--> $DIR/bool_comparison.rs:22:8
|
||||
--> $DIR/bool_comparison.rs:38:8
|
||||
|
|
||||
22 | if x != false { "yes" } else { "no" };
|
||||
38 | if x != false {
|
||||
| ^^^^^^^^^^ help: try simplifying it as shown: `x`
|
||||
|
||||
error: inequality checks against true can be replaced by a negation
|
||||
--> $DIR/bool_comparison.rs:23:8
|
||||
--> $DIR/bool_comparison.rs:43:8
|
||||
|
|
||||
23 | if true != x { "yes" } else { "no" };
|
||||
43 | if true != x {
|
||||
| ^^^^^^^^^ help: try simplifying it as shown: `!x`
|
||||
|
||||
error: inequality checks against false are unnecessary
|
||||
--> $DIR/bool_comparison.rs:24:8
|
||||
--> $DIR/bool_comparison.rs:48:8
|
||||
|
|
||||
24 | if false != x { "yes" } else { "no" };
|
||||
48 | if false != x {
|
||||
| ^^^^^^^^^^ help: try simplifying it as shown: `x`
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![warn(clippy::nonminimal_bool, clippy::logic_bug)]
|
||||
|
||||
#[allow(unused, clippy::many_single_char_names)]
|
||||
|
@ -71,58 +68,78 @@ fn methods_with_negation() {
|
|||
// Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638
|
||||
// clippy::nonminimal_bool should only check the built-in Result and Some type, not
|
||||
// any other types like the following.
|
||||
enum CustomResultOk<E> { Ok, Err(E) }
|
||||
enum CustomResultErr<E> { Ok, Err(E) }
|
||||
enum CustomSomeSome<T> { Some(T), None }
|
||||
enum CustomSomeNone<T> { Some(T), None }
|
||||
enum CustomResultOk<E> {
|
||||
Ok,
|
||||
Err(E),
|
||||
}
|
||||
enum CustomResultErr<E> {
|
||||
Ok,
|
||||
Err(E),
|
||||
}
|
||||
enum CustomSomeSome<T> {
|
||||
Some(T),
|
||||
None,
|
||||
}
|
||||
enum CustomSomeNone<T> {
|
||||
Some(T),
|
||||
None,
|
||||
}
|
||||
|
||||
impl<E> CustomResultOk<E> {
|
||||
pub fn is_ok(&self) -> bool { true }
|
||||
pub fn is_ok(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> CustomResultErr<E> {
|
||||
pub fn is_err(&self) -> bool { true }
|
||||
pub fn is_err(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> CustomSomeSome<T> {
|
||||
pub fn is_some(&self) -> bool { true }
|
||||
pub fn is_some(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> CustomSomeNone<T> {
|
||||
pub fn is_none(&self) -> bool { true }
|
||||
pub fn is_none(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fn dont_warn_for_custom_methods_with_negation() {
|
||||
let res = CustomResultOk::Err("Error");
|
||||
// Should not warn and suggest 'is_err()' because the type does not
|
||||
// implement is_err().
|
||||
if !res.is_ok() { }
|
||||
if !res.is_ok() {}
|
||||
|
||||
let res = CustomResultErr::Err("Error");
|
||||
// Should not warn and suggest 'is_ok()' because the type does not
|
||||
// implement is_ok().
|
||||
if !res.is_err() { }
|
||||
if !res.is_err() {}
|
||||
|
||||
let res = CustomSomeSome::Some("thing");
|
||||
// Should not warn and suggest 'is_none()' because the type does not
|
||||
// implement is_none().
|
||||
if !res.is_some() { }
|
||||
if !res.is_some() {}
|
||||
|
||||
let res = CustomSomeNone::Some("thing");
|
||||
// Should not warn and suggest 'is_some()' because the type does not
|
||||
// implement is_some().
|
||||
if !res.is_none() { }
|
||||
if !res.is_none() {}
|
||||
}
|
||||
|
||||
// Only Built-in Result and Some types should suggest the negated alternative
|
||||
fn warn_for_built_in_methods_with_negation() {
|
||||
let res: Result<usize, usize> = Ok(1);
|
||||
if !res.is_ok() { }
|
||||
if !res.is_err() { }
|
||||
if !res.is_ok() {}
|
||||
if !res.is_err() {}
|
||||
|
||||
let res = Some(1);
|
||||
if !res.is_some() { }
|
||||
if !res.is_none() { }
|
||||
if !res.is_some() {}
|
||||
if !res.is_none() {}
|
||||
}
|
||||
|
||||
#[allow(clippy::neg_cmp_op_on_partial_ord)]
|
||||
|
|
|
@ -1,202 +1,202 @@
|
|||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:22:13
|
||||
--> $DIR/booleans.rs:19:13
|
||||
|
|
||||
22 | let _ = a && b || a;
|
||||
19 | let _ = a && b || a;
|
||||
| ^^^^^^^^^^^ help: it would look like the following: `a`
|
||||
|
|
||||
= note: `-D clippy::logic-bug` implied by `-D warnings`
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:22:18
|
||||
--> $DIR/booleans.rs:19:18
|
||||
|
|
||||
22 | let _ = a && b || a;
|
||||
19 | let _ = a && b || a;
|
||||
| ^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:24:13
|
||||
--> $DIR/booleans.rs:21:13
|
||||
|
|
||||
24 | let _ = !true;
|
||||
21 | let _ = !true;
|
||||
| ^^^^^ help: try: `false`
|
||||
|
|
||||
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:25:13
|
||||
--> $DIR/booleans.rs:22:13
|
||||
|
|
||||
25 | let _ = !false;
|
||||
22 | let _ = !false;
|
||||
| ^^^^^^ help: try: `true`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:26:13
|
||||
--> $DIR/booleans.rs:23:13
|
||||
|
|
||||
26 | let _ = !!a;
|
||||
23 | let _ = !!a;
|
||||
| ^^^ help: try: `a`
|
||||
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:27:13
|
||||
--> $DIR/booleans.rs:24:13
|
||||
|
|
||||
27 | let _ = false && a;
|
||||
24 | let _ = false && a;
|
||||
| ^^^^^^^^^^ help: it would look like the following: `false`
|
||||
|
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:27:22
|
||||
--> $DIR/booleans.rs:24:22
|
||||
|
|
||||
27 | let _ = false && a;
|
||||
24 | let _ = false && a;
|
||||
| ^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:28:13
|
||||
--> $DIR/booleans.rs:25:13
|
||||
|
|
||||
28 | let _ = false || a;
|
||||
25 | let _ = false || a;
|
||||
| ^^^^^^^^^^ help: try: `a`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:33:13
|
||||
--> $DIR/booleans.rs:30:13
|
||||
|
|
||||
33 | let _ = !(!a && b);
|
||||
30 | let _ = !(!a && b);
|
||||
| ^^^^^^^^^^ help: try: `!b || a`
|
||||
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:43:13
|
||||
--> $DIR/booleans.rs:40:13
|
||||
|
|
||||
43 | let _ = a == b && a != b;
|
||||
40 | let _ = a == b && a != b;
|
||||
| ^^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
||||
|
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:43:13
|
||||
--> $DIR/booleans.rs:40:13
|
||||
|
|
||||
43 | let _ = a == b && a != b;
|
||||
40 | let _ = a == b && a != b;
|
||||
| ^^^^^^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:41:13
|
||||
|
|
||||
41 | let _ = a == b && c == 5 && a == b;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: try
|
||||
|
|
||||
41 | let _ = a == b && c == 5;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
41 | let _ = !(c != 5 || a != b);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:42:13
|
||||
|
|
||||
42 | let _ = a == b && c == 5 && b == a;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: try
|
||||
|
|
||||
42 | let _ = a == b && c == 5;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
42 | let _ = !(c != 5 || a != b);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:43:13
|
||||
|
|
||||
43 | let _ = a < b && a >= b;
|
||||
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
||||
|
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:43:13
|
||||
|
|
||||
43 | let _ = a < b && a >= b;
|
||||
| ^^^^^
|
||||
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:44:13
|
||||
|
|
||||
44 | let _ = a == b && c == 5 && a == b;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: try
|
||||
|
|
||||
44 | let _ = a == b && c == 5;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
44 | let _ = !(c != 5 || a != b);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:45:13
|
||||
|
|
||||
45 | let _ = a == b && c == 5 && b == a;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: try
|
||||
|
|
||||
45 | let _ = a == b && c == 5;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
45 | let _ = !(c != 5 || a != b);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:46:13
|
||||
|
|
||||
46 | let _ = a < b && a >= b;
|
||||
44 | let _ = a > b && a <= b;
|
||||
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
||||
|
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:46:13
|
||||
--> $DIR/booleans.rs:44:13
|
||||
|
|
||||
46 | let _ = a < b && a >= b;
|
||||
| ^^^^^
|
||||
|
||||
error: this boolean expression contains a logic bug
|
||||
--> $DIR/booleans.rs:47:13
|
||||
|
|
||||
47 | let _ = a > b && a <= b;
|
||||
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
||||
|
|
||||
help: this expression can be optimized out by applying boolean operations to the outer expression
|
||||
--> $DIR/booleans.rs:47:13
|
||||
|
|
||||
47 | let _ = a > b && a <= b;
|
||||
44 | let _ = a > b && a <= b;
|
||||
| ^^^^^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:49:13
|
||||
--> $DIR/booleans.rs:46:13
|
||||
|
|
||||
49 | let _ = a != b || !(a != b || c == d);
|
||||
46 | let _ = a != b || !(a != b || c == d);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: try
|
||||
|
|
||||
49 | let _ = c != d || a != b;
|
||||
46 | let _ = c != d || a != b;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
49 | let _ = !(a == b && c == d);
|
||||
46 | let _ = !(a == b && c == d);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:57:13
|
||||
--> $DIR/booleans.rs:54:13
|
||||
|
|
||||
57 | let _ = !a.is_some();
|
||||
54 | let _ = !a.is_some();
|
||||
| ^^^^^^^^^^^^ help: try: `a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:59:13
|
||||
--> $DIR/booleans.rs:56:13
|
||||
|
|
||||
59 | let _ = !a.is_none();
|
||||
56 | let _ = !a.is_none();
|
||||
| ^^^^^^^^^^^^ help: try: `a.is_some()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:61:13
|
||||
--> $DIR/booleans.rs:58:13
|
||||
|
|
||||
61 | let _ = !b.is_err();
|
||||
58 | let _ = !b.is_err();
|
||||
| ^^^^^^^^^^^ help: try: `b.is_ok()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:60:13
|
||||
|
|
||||
60 | let _ = !b.is_ok();
|
||||
| ^^^^^^^^^^ help: try: `b.is_err()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:62:13
|
||||
|
|
||||
62 | let _ = !(a.is_some() && !c);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `c || a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:63:13
|
||||
|
|
||||
63 | let _ = !b.is_ok();
|
||||
| ^^^^^^^^^^ help: try: `b.is_err()`
|
||||
63 | let _ = !(!c ^ c) || !a.is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!(!c ^ c) || a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:64:13
|
||||
|
|
||||
64 | let _ = (!c ^ c) || !a.is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(!c ^ c) || a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:65:13
|
||||
|
|
||||
65 | let _ = !(a.is_some() && !c);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `c || a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:66:13
|
||||
|
|
||||
66 | let _ = !(!c ^ c) || !a.is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!(!c ^ c) || a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:67:13
|
||||
|
|
||||
67 | let _ = (!c ^ c) || !a.is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(!c ^ c) || a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:68:13
|
||||
|
|
||||
68 | let _ = !c ^ c || !a.is_some();
|
||||
65 | let _ = !c ^ c || !a.is_some();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `!c ^ c || a.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:120:8
|
||||
--> $DIR/booleans.rs:137:8
|
||||
|
|
||||
120 | if !res.is_ok() { }
|
||||
137 | if !res.is_ok() {}
|
||||
| ^^^^^^^^^^^^ help: try: `res.is_err()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:121:8
|
||||
--> $DIR/booleans.rs:138:8
|
||||
|
|
||||
121 | if !res.is_err() { }
|
||||
138 | if !res.is_err() {}
|
||||
| ^^^^^^^^^^^^^ help: try: `res.is_ok()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:124:8
|
||||
--> $DIR/booleans.rs:141:8
|
||||
|
|
||||
124 | if !res.is_some() { }
|
||||
141 | if !res.is_some() {}
|
||||
| ^^^^^^^^^^^^^^ help: try: `res.is_none()`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/booleans.rs:125:8
|
||||
--> $DIR/booleans.rs:142:8
|
||||
|
|
||||
125 | if !res.is_none() { }
|
||||
142 | if !res.is_none() {}
|
||||
| ^^^^^^^^^^^^^^ help: try: `res.is_some()`
|
||||
|
||||
error: aborting due to 25 previous errors
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#![deny(clippy::borrowed_box)]
|
||||
#![allow(clippy::blacklisted_name)]
|
||||
#![allow(unused_variables)]
|
||||
|
@ -25,7 +21,7 @@ pub fn test2() {
|
|||
}
|
||||
|
||||
struct Test3<'a> {
|
||||
foo: &'a Box<bool>
|
||||
foo: &'a Box<bool>,
|
||||
}
|
||||
|
||||
trait Test4 {
|
||||
|
@ -49,7 +45,7 @@ pub fn test6() {
|
|||
}
|
||||
|
||||
struct Test7<'a> {
|
||||
foo: &'a Box<Any>
|
||||
foo: &'a Box<Any>,
|
||||
}
|
||||
|
||||
trait Test8 {
|
||||
|
@ -71,7 +67,7 @@ pub fn test10() {
|
|||
}
|
||||
|
||||
struct Test11<'a> {
|
||||
foo: &'a Box<Any + Send>
|
||||
foo: &'a Box<Any + Send>,
|
||||
}
|
||||
|
||||
trait Test12 {
|
||||
|
@ -84,7 +80,7 @@ impl<'a> Test12 for Test11<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn main(){
|
||||
fn main() {
|
||||
test1(&mut Box::new(false));
|
||||
test2();
|
||||
test5(&mut (Box::new(false) as Box<Any>));
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:19:19
|
||||
--> $DIR/borrow_box.rs:15:19
|
||||
|
|
||||
19 | pub fn test1(foo: &mut Box<bool>) {
|
||||
15 | pub fn test1(foo: &mut Box<bool>) {
|
||||
| ^^^^^^^^^^^^^^ help: try: `&mut bool`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/borrow_box.rs:14:9
|
||||
--> $DIR/borrow_box.rs:10:9
|
||||
|
|
||||
14 | #![deny(clippy::borrowed_box)]
|
||||
10 | #![deny(clippy::borrowed_box)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:24:14
|
||||
--> $DIR/borrow_box.rs:20:14
|
||||
|
|
||||
24 | let foo: &Box<bool>;
|
||||
20 | let foo: &Box<bool>;
|
||||
| ^^^^^^^^^^ help: try: `&bool`
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:28:10
|
||||
--> $DIR/borrow_box.rs:24:10
|
||||
|
|
||||
28 | foo: &'a Box<bool>
|
||||
24 | foo: &'a Box<bool>,
|
||||
| ^^^^^^^^^^^^^ help: try: `&'a bool`
|
||||
|
||||
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
|
||||
--> $DIR/borrow_box.rs:32:17
|
||||
--> $DIR/borrow_box.rs:28:17
|
||||
|
|
||||
32 | fn test4(a: &Box<bool>);
|
||||
28 | fn test4(a: &Box<bool>);
|
||||
| ^^^^^^^^^^ help: try: `&bool`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#![warn(clippy::all)]
|
||||
#![allow(clippy::boxed_local, clippy::needless_pass_by_value)]
|
||||
#![allow(clippy::blacklisted_name)]
|
||||
|
@ -18,7 +14,7 @@
|
|||
macro_rules! boxit {
|
||||
($init:expr, $x:ty) => {
|
||||
let _: Box<$x> = Box::new($init);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn test_macro() {
|
||||
|
@ -28,7 +24,8 @@ pub fn test(foo: Box<Vec<bool>>) {
|
|||
println!("{:?}", foo.get(0))
|
||||
}
|
||||
|
||||
pub fn test2(foo: Box<Fn(Vec<u32>)>) { // pass if #31 is fixed
|
||||
pub fn test2(foo: Box<Fn(Vec<u32>)>) {
|
||||
// pass if #31 is fixed
|
||||
foo(vec![1, 2, 3])
|
||||
}
|
||||
|
||||
|
@ -36,7 +33,7 @@ pub fn test_local_not_linted() {
|
|||
let _: Box<Vec<bool>>;
|
||||
}
|
||||
|
||||
fn main(){
|
||||
fn main() {
|
||||
test(Box::new(Vec::new()));
|
||||
test2(Box::new(|v| println!("{:?}", v)));
|
||||
test_macro();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error: you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`
|
||||
--> $DIR/box_vec.rs:27:18
|
||||
--> $DIR/box_vec.rs:23:18
|
||||
|
|
||||
27 | pub fn test(foo: Box<Vec<bool>>) {
|
||||
23 | pub fn test(foo: Box<Vec<bool>>) {
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::box-vec` implied by `-D warnings`
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![warn(clippy::builtin_type_shadow)]
|
||||
|
||||
fn foo<u32>(a: u32) -> u32 {
|
||||
|
@ -17,5 +14,4 @@ fn foo<u32>(a: u32) -> u32 {
|
|||
// ^ rustc's type error
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
fn main() {}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
error: This generic shadows the built-in type `u32`
|
||||
--> $DIR/builtin-type-shadow.rs:15:8
|
||||
--> $DIR/builtin-type-shadow.rs:12:8
|
||||
|
|
||||
15 | fn foo<u32>(a: u32) -> u32 {
|
||||
12 | fn foo<u32>(a: u32) -> u32 {
|
||||
| ^^^
|
||||
|
|
||||
= note: `-D clippy::builtin-type-shadow` implied by `-D warnings`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/builtin-type-shadow.rs:16:5
|
||||
--> $DIR/builtin-type-shadow.rs:13:5
|
||||
|
|
||||
15 | fn foo<u32>(a: u32) -> u32 {
|
||||
12 | fn foo<u32>(a: u32) -> u32 {
|
||||
| --- expected `u32` because of return type
|
||||
16 | 42
|
||||
13 | 42
|
||||
| ^^ expected type parameter, found integral variable
|
||||
|
|
||||
= note: expected type `u32`
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#[deny(clippy::naive_bytecount)]
|
||||
fn main() {
|
||||
let x = vec![0_u8; 16];
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
error: You appear to be counting bytes the naive way
|
||||
--> $DIR/bytecount.rs:18:13
|
||||
--> $DIR/bytecount.rs:14:13
|
||||
|
|
||||
18 | let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count
|
||||
14 | let _ = x.iter().filter(|&&a| a == 0).count(); // naive byte count
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider using the bytecount crate: `bytecount::count(x, 0)`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/bytecount.rs:14:8
|
||||
--> $DIR/bytecount.rs:10:8
|
||||
|
|
||||
14 | #[deny(clippy::naive_bytecount)]
|
||||
10 | #[deny(clippy::naive_bytecount)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: You appear to be counting bytes the naive way
|
||||
--> $DIR/bytecount.rs:20:13
|
||||
--> $DIR/bytecount.rs:16:13
|
||||
|
|
||||
20 | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count
|
||||
16 | let _ = (&x[..]).iter().filter(|&a| *a == 0).count(); // naive byte count
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider using the bytecount crate: `bytecount::count((&x[..]), 0)`
|
||||
|
||||
error: You appear to be counting bytes the naive way
|
||||
--> $DIR/bytecount.rs:32:13
|
||||
--> $DIR/bytecount.rs:28:13
|
||||
|
|
||||
32 | let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count
|
||||
28 | let _ = x.iter().filter(|a| b + 1 == **a).count(); // naive byte count
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider using the bytecount crate: `bytecount::count(x, b + 1)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
|
|
@ -7,11 +7,13 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#[warn(clippy::cast_precision_loss, clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::cast_possible_wrap, clippy::cast_lossless)]
|
||||
#[warn(
|
||||
clippy::cast_precision_loss,
|
||||
clippy::cast_possible_truncation,
|
||||
clippy::cast_sign_loss,
|
||||
clippy::cast_possible_wrap,
|
||||
clippy::cast_lossless
|
||||
)]
|
||||
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
|
||||
fn main() {
|
||||
// Test clippy::cast_precision_loss
|
||||
|
@ -49,6 +51,7 @@ fn main() {
|
|||
false as bool;
|
||||
&1i32 as &i32;
|
||||
// Should not trigger
|
||||
#[rustfmt::skip]
|
||||
let v = vec!(1);
|
||||
&v as &[i32];
|
||||
1.0 as f64;
|
||||
|
|
|
@ -1,181 +1,181 @@
|
|||
error: casting i32 to f32 causes a loss of precision (i32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
|
||||
--> $DIR/cast.rs:18:5
|
||||
--> $DIR/cast.rs:20:5
|
||||
|
|
||||
18 | 1i32 as f32;
|
||||
20 | 1i32 as f32;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
|
||||
error: casting i64 to f32 causes a loss of precision (i64 is 64 bits wide, but f32's mantissa is only 23 bits wide)
|
||||
--> $DIR/cast.rs:19:5
|
||||
--> $DIR/cast.rs:21:5
|
||||
|
|
||||
19 | 1i64 as f32;
|
||||
21 | 1i64 as f32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting i64 to f64 causes a loss of precision (i64 is 64 bits wide, but f64's mantissa is only 52 bits wide)
|
||||
--> $DIR/cast.rs:20:5
|
||||
--> $DIR/cast.rs:22:5
|
||||
|
|
||||
20 | 1i64 as f64;
|
||||
22 | 1i64 as f64;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting u32 to f32 causes a loss of precision (u32 is 32 bits wide, but f32's mantissa is only 23 bits wide)
|
||||
--> $DIR/cast.rs:21:5
|
||||
--> $DIR/cast.rs:23:5
|
||||
|
|
||||
21 | 1u32 as f32;
|
||||
23 | 1u32 as f32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting u64 to f32 causes a loss of precision (u64 is 64 bits wide, but f32's mantissa is only 23 bits wide)
|
||||
--> $DIR/cast.rs:22:5
|
||||
--> $DIR/cast.rs:24:5
|
||||
|
|
||||
22 | 1u64 as f32;
|
||||
24 | 1u64 as f32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting u64 to f64 causes a loss of precision (u64 is 64 bits wide, but f64's mantissa is only 52 bits wide)
|
||||
--> $DIR/cast.rs:23:5
|
||||
--> $DIR/cast.rs:25:5
|
||||
|
|
||||
23 | 1u64 as f64;
|
||||
25 | 1u64 as f64;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting f32 to i32 may truncate the value
|
||||
--> $DIR/cast.rs:25:5
|
||||
--> $DIR/cast.rs:27:5
|
||||
|
|
||||
25 | 1f32 as i32;
|
||||
27 | 1f32 as i32;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
|
||||
|
||||
error: casting f32 to u32 may truncate the value
|
||||
--> $DIR/cast.rs:26:5
|
||||
--> $DIR/cast.rs:28:5
|
||||
|
|
||||
26 | 1f32 as u32;
|
||||
28 | 1f32 as u32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting f32 to u32 may lose the sign of the value
|
||||
--> $DIR/cast.rs:26:5
|
||||
--> $DIR/cast.rs:28:5
|
||||
|
|
||||
26 | 1f32 as u32;
|
||||
28 | 1f32 as u32;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-sign-loss` implied by `-D warnings`
|
||||
|
||||
error: casting f64 to f32 may truncate the value
|
||||
--> $DIR/cast.rs:27:5
|
||||
--> $DIR/cast.rs:29:5
|
||||
|
|
||||
27 | 1f64 as f32;
|
||||
29 | 1f64 as f32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting i32 to i8 may truncate the value
|
||||
--> $DIR/cast.rs:28:5
|
||||
--> $DIR/cast.rs:30:5
|
||||
|
|
||||
28 | 1i32 as i8;
|
||||
30 | 1i32 as i8;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: casting i32 to u8 may lose the sign of the value
|
||||
--> $DIR/cast.rs:29:5
|
||||
--> $DIR/cast.rs:31:5
|
||||
|
|
||||
29 | 1i32 as u8;
|
||||
31 | 1i32 as u8;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: casting i32 to u8 may truncate the value
|
||||
--> $DIR/cast.rs:29:5
|
||||
--> $DIR/cast.rs:31:5
|
||||
|
|
||||
29 | 1i32 as u8;
|
||||
31 | 1i32 as u8;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: casting f64 to isize may truncate the value
|
||||
--> $DIR/cast.rs:30:5
|
||||
--> $DIR/cast.rs:32:5
|
||||
|
|
||||
30 | 1f64 as isize;
|
||||
32 | 1f64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting f64 to usize may truncate the value
|
||||
--> $DIR/cast.rs:31:5
|
||||
--> $DIR/cast.rs:33:5
|
||||
|
|
||||
31 | 1f64 as usize;
|
||||
33 | 1f64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting f64 to usize may lose the sign of the value
|
||||
--> $DIR/cast.rs:31:5
|
||||
--> $DIR/cast.rs:33:5
|
||||
|
|
||||
31 | 1f64 as usize;
|
||||
33 | 1f64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u8 to i8 may wrap around the value
|
||||
--> $DIR/cast.rs:33:5
|
||||
--> $DIR/cast.rs:35:5
|
||||
|
|
||||
33 | 1u8 as i8;
|
||||
35 | 1u8 as i8;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
|
||||
error: casting u16 to i16 may wrap around the value
|
||||
--> $DIR/cast.rs:34:5
|
||||
--> $DIR/cast.rs:36:5
|
||||
|
|
||||
34 | 1u16 as i16;
|
||||
36 | 1u16 as i16;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting u32 to i32 may wrap around the value
|
||||
--> $DIR/cast.rs:35:5
|
||||
--> $DIR/cast.rs:37:5
|
||||
|
|
||||
35 | 1u32 as i32;
|
||||
37 | 1u32 as i32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting u64 to i64 may wrap around the value
|
||||
--> $DIR/cast.rs:36:5
|
||||
--> $DIR/cast.rs:38:5
|
||||
|
|
||||
36 | 1u64 as i64;
|
||||
38 | 1u64 as i64;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting usize to isize may wrap around the value
|
||||
--> $DIR/cast.rs:37:5
|
||||
--> $DIR/cast.rs:39:5
|
||||
|
|
||||
37 | 1usize as isize;
|
||||
39 | 1usize as isize;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: casting f32 to f64 may become silently lossy if types change
|
||||
--> $DIR/cast.rs:39:5
|
||||
--> $DIR/cast.rs:41:5
|
||||
|
|
||||
39 | 1.0f32 as f64;
|
||||
41 | 1.0f32 as f64;
|
||||
| ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)`
|
||||
|
|
||||
= note: `-D clippy::cast-lossless` implied by `-D warnings`
|
||||
|
||||
error: casting u8 to u16 may become silently lossy if types change
|
||||
--> $DIR/cast.rs:41:5
|
||||
--> $DIR/cast.rs:43:5
|
||||
|
|
||||
41 | (1u8 + 1u8) as u16;
|
||||
43 | (1u8 + 1u8) as u16;
|
||||
| ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)`
|
||||
|
||||
error: casting i32 to u32 may lose the sign of the value
|
||||
--> $DIR/cast.rs:43:5
|
||||
--> $DIR/cast.rs:45:5
|
||||
|
|
||||
43 | 1i32 as u32;
|
||||
45 | 1i32 as u32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting isize to usize may lose the sign of the value
|
||||
--> $DIR/cast.rs:44:5
|
||||
--> $DIR/cast.rs:46:5
|
||||
|
|
||||
44 | 1isize as usize;
|
||||
46 | 1isize as usize;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: casting to the same type is unnecessary (`i32` -> `i32`)
|
||||
--> $DIR/cast.rs:47:5
|
||||
--> $DIR/cast.rs:49:5
|
||||
|
|
||||
47 | 1i32 as i32;
|
||||
49 | 1i32 as i32;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
|
||||
|
||||
error: casting to the same type is unnecessary (`f32` -> `f32`)
|
||||
--> $DIR/cast.rs:48:5
|
||||
--> $DIR/cast.rs:50:5
|
||||
|
|
||||
48 | 1f32 as f32;
|
||||
50 | 1f32 as f32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: casting to the same type is unnecessary (`bool` -> `bool`)
|
||||
--> $DIR/cast.rs:49:5
|
||||
--> $DIR/cast.rs:51:5
|
||||
|
|
||||
49 | false as bool;
|
||||
51 | false as bool;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 28 previous errors
|
||||
|
|
|
@ -7,13 +7,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
//! Test casts for alignment issues
|
||||
|
||||
#![feature(libc)]
|
||||
|
||||
#![feature(rustc_private)]
|
||||
extern crate libc;
|
||||
|
||||
#[warn(clippy::cast_ptr_alignment)]
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
error: casting from `*const u8` to a more-strictly-aligned pointer (`*const u16`)
|
||||
--> $DIR/cast_alignment.rs:25:5
|
||||
--> $DIR/cast_alignment.rs:22:5
|
||||
|
|
||||
25 | (&1u8 as *const u8) as *const u16;
|
||||
22 | (&1u8 as *const u8) as *const u16;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-ptr-alignment` implied by `-D warnings`
|
||||
|
||||
error: casting from `*mut u8` to a more-strictly-aligned pointer (`*mut u16`)
|
||||
--> $DIR/cast_alignment.rs:26:5
|
||||
--> $DIR/cast_alignment.rs:23:5
|
||||
|
|
||||
26 | (&mut 1u8 as *mut u8) as *mut u16;
|
||||
23 | (&mut 1u8 as *mut u8) as *mut u16;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#[warn(clippy::cast_lossless)]
|
||||
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
|
||||
fn main() {
|
||||
|
|
|
@ -1,63 +1,63 @@
|
|||
error: casting i8 to f32 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_float.rs:17:5
|
||||
--> $DIR/cast_lossless_float.rs:14:5
|
||||
|
|
||||
17 | 1i8 as f32;
|
||||
14 | 1i8 as f32;
|
||||
| ^^^^^^^^^^ help: try: `f32::from(1i8)`
|
||||
|
|
||||
= note: `-D clippy::cast-lossless` implied by `-D warnings`
|
||||
|
||||
error: casting i8 to f64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_float.rs:18:5
|
||||
--> $DIR/cast_lossless_float.rs:15:5
|
||||
|
|
||||
18 | 1i8 as f64;
|
||||
15 | 1i8 as f64;
|
||||
| ^^^^^^^^^^ help: try: `f64::from(1i8)`
|
||||
|
||||
error: casting u8 to f32 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_float.rs:19:5
|
||||
--> $DIR/cast_lossless_float.rs:16:5
|
||||
|
|
||||
19 | 1u8 as f32;
|
||||
16 | 1u8 as f32;
|
||||
| ^^^^^^^^^^ help: try: `f32::from(1u8)`
|
||||
|
||||
error: casting u8 to f64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_float.rs:20:5
|
||||
--> $DIR/cast_lossless_float.rs:17:5
|
||||
|
|
||||
20 | 1u8 as f64;
|
||||
17 | 1u8 as f64;
|
||||
| ^^^^^^^^^^ help: try: `f64::from(1u8)`
|
||||
|
||||
error: casting i16 to f32 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_float.rs:21:5
|
||||
--> $DIR/cast_lossless_float.rs:18:5
|
||||
|
|
||||
21 | 1i16 as f32;
|
||||
18 | 1i16 as f32;
|
||||
| ^^^^^^^^^^^ help: try: `f32::from(1i16)`
|
||||
|
||||
error: casting i16 to f64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_float.rs:22:5
|
||||
--> $DIR/cast_lossless_float.rs:19:5
|
||||
|
|
||||
22 | 1i16 as f64;
|
||||
19 | 1i16 as f64;
|
||||
| ^^^^^^^^^^^ help: try: `f64::from(1i16)`
|
||||
|
||||
error: casting u16 to f32 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_float.rs:23:5
|
||||
--> $DIR/cast_lossless_float.rs:20:5
|
||||
|
|
||||
23 | 1u16 as f32;
|
||||
20 | 1u16 as f32;
|
||||
| ^^^^^^^^^^^ help: try: `f32::from(1u16)`
|
||||
|
||||
error: casting u16 to f64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_float.rs:24:5
|
||||
--> $DIR/cast_lossless_float.rs:21:5
|
||||
|
|
||||
24 | 1u16 as f64;
|
||||
21 | 1u16 as f64;
|
||||
| ^^^^^^^^^^^ help: try: `f64::from(1u16)`
|
||||
|
||||
error: casting i32 to f64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_float.rs:25:5
|
||||
--> $DIR/cast_lossless_float.rs:22:5
|
||||
|
|
||||
25 | 1i32 as f64;
|
||||
22 | 1i32 as f64;
|
||||
| ^^^^^^^^^^^ help: try: `f64::from(1i32)`
|
||||
|
||||
error: casting u32 to f64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_float.rs:26:5
|
||||
--> $DIR/cast_lossless_float.rs:23:5
|
||||
|
|
||||
26 | 1u32 as f64;
|
||||
23 | 1u32 as f64;
|
||||
| ^^^^^^^^^^^ help: try: `f64::from(1u32)`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
#[warn(clippy::cast_lossless)]
|
||||
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
|
||||
fn main() {
|
||||
|
|
|
@ -1,111 +1,111 @@
|
|||
error: casting i8 to i16 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:16:5
|
||||
--> $DIR/cast_lossless_integer.rs:14:5
|
||||
|
|
||||
16 | 1i8 as i16;
|
||||
14 | 1i8 as i16;
|
||||
| ^^^^^^^^^^ help: try: `i16::from(1i8)`
|
||||
|
|
||||
= note: `-D clippy::cast-lossless` implied by `-D warnings`
|
||||
|
||||
error: casting i8 to i32 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:17:5
|
||||
--> $DIR/cast_lossless_integer.rs:15:5
|
||||
|
|
||||
17 | 1i8 as i32;
|
||||
15 | 1i8 as i32;
|
||||
| ^^^^^^^^^^ help: try: `i32::from(1i8)`
|
||||
|
||||
error: casting i8 to i64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:18:5
|
||||
--> $DIR/cast_lossless_integer.rs:16:5
|
||||
|
|
||||
18 | 1i8 as i64;
|
||||
16 | 1i8 as i64;
|
||||
| ^^^^^^^^^^ help: try: `i64::from(1i8)`
|
||||
|
||||
error: casting u8 to i16 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:19:5
|
||||
--> $DIR/cast_lossless_integer.rs:17:5
|
||||
|
|
||||
19 | 1u8 as i16;
|
||||
17 | 1u8 as i16;
|
||||
| ^^^^^^^^^^ help: try: `i16::from(1u8)`
|
||||
|
||||
error: casting u8 to i32 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:20:5
|
||||
--> $DIR/cast_lossless_integer.rs:18:5
|
||||
|
|
||||
20 | 1u8 as i32;
|
||||
18 | 1u8 as i32;
|
||||
| ^^^^^^^^^^ help: try: `i32::from(1u8)`
|
||||
|
||||
error: casting u8 to i64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:21:5
|
||||
--> $DIR/cast_lossless_integer.rs:19:5
|
||||
|
|
||||
21 | 1u8 as i64;
|
||||
19 | 1u8 as i64;
|
||||
| ^^^^^^^^^^ help: try: `i64::from(1u8)`
|
||||
|
||||
error: casting u8 to u16 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:22:5
|
||||
--> $DIR/cast_lossless_integer.rs:20:5
|
||||
|
|
||||
22 | 1u8 as u16;
|
||||
20 | 1u8 as u16;
|
||||
| ^^^^^^^^^^ help: try: `u16::from(1u8)`
|
||||
|
||||
error: casting u8 to u32 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:23:5
|
||||
--> $DIR/cast_lossless_integer.rs:21:5
|
||||
|
|
||||
23 | 1u8 as u32;
|
||||
21 | 1u8 as u32;
|
||||
| ^^^^^^^^^^ help: try: `u32::from(1u8)`
|
||||
|
||||
error: casting u8 to u64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:24:5
|
||||
--> $DIR/cast_lossless_integer.rs:22:5
|
||||
|
|
||||
24 | 1u8 as u64;
|
||||
22 | 1u8 as u64;
|
||||
| ^^^^^^^^^^ help: try: `u64::from(1u8)`
|
||||
|
||||
error: casting i16 to i32 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:25:5
|
||||
--> $DIR/cast_lossless_integer.rs:23:5
|
||||
|
|
||||
25 | 1i16 as i32;
|
||||
23 | 1i16 as i32;
|
||||
| ^^^^^^^^^^^ help: try: `i32::from(1i16)`
|
||||
|
||||
error: casting i16 to i64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:26:5
|
||||
--> $DIR/cast_lossless_integer.rs:24:5
|
||||
|
|
||||
26 | 1i16 as i64;
|
||||
24 | 1i16 as i64;
|
||||
| ^^^^^^^^^^^ help: try: `i64::from(1i16)`
|
||||
|
||||
error: casting u16 to i32 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:27:5
|
||||
--> $DIR/cast_lossless_integer.rs:25:5
|
||||
|
|
||||
27 | 1u16 as i32;
|
||||
25 | 1u16 as i32;
|
||||
| ^^^^^^^^^^^ help: try: `i32::from(1u16)`
|
||||
|
||||
error: casting u16 to i64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:28:5
|
||||
--> $DIR/cast_lossless_integer.rs:26:5
|
||||
|
|
||||
28 | 1u16 as i64;
|
||||
26 | 1u16 as i64;
|
||||
| ^^^^^^^^^^^ help: try: `i64::from(1u16)`
|
||||
|
||||
error: casting u16 to u32 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:29:5
|
||||
--> $DIR/cast_lossless_integer.rs:27:5
|
||||
|
|
||||
29 | 1u16 as u32;
|
||||
27 | 1u16 as u32;
|
||||
| ^^^^^^^^^^^ help: try: `u32::from(1u16)`
|
||||
|
||||
error: casting u16 to u64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:30:5
|
||||
--> $DIR/cast_lossless_integer.rs:28:5
|
||||
|
|
||||
30 | 1u16 as u64;
|
||||
28 | 1u16 as u64;
|
||||
| ^^^^^^^^^^^ help: try: `u64::from(1u16)`
|
||||
|
||||
error: casting i32 to i64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:31:5
|
||||
--> $DIR/cast_lossless_integer.rs:29:5
|
||||
|
|
||||
31 | 1i32 as i64;
|
||||
29 | 1i32 as i64;
|
||||
| ^^^^^^^^^^^ help: try: `i64::from(1i32)`
|
||||
|
||||
error: casting u32 to i64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:32:5
|
||||
--> $DIR/cast_lossless_integer.rs:30:5
|
||||
|
|
||||
32 | 1u32 as i64;
|
||||
30 | 1u32 as i64;
|
||||
| ^^^^^^^^^^^ help: try: `i64::from(1u32)`
|
||||
|
||||
error: casting u32 to u64 may become silently lossy if types change
|
||||
--> $DIR/cast_lossless_integer.rs:33:5
|
||||
--> $DIR/cast_lossless_integer.rs:31:5
|
||||
|
|
||||
33 | 1u32 as u64;
|
||||
31 | 1u32 as u64;
|
||||
| ^^^^^^^^^^^ help: try: `u64::from(1u32)`
|
||||
|
||||
error: aborting due to 18 previous errors
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#[warn(clippy::cast_precision_loss, clippy::cast_possible_truncation, clippy::cast_sign_loss, clippy::cast_possible_wrap, clippy::cast_lossless)]
|
||||
#[warn(
|
||||
clippy::cast_precision_loss,
|
||||
clippy::cast_possible_truncation,
|
||||
clippy::cast_sign_loss,
|
||||
clippy::cast_possible_wrap,
|
||||
clippy::cast_lossless
|
||||
)]
|
||||
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
|
||||
fn main() {
|
||||
// Casting from *size
|
||||
|
|
|
@ -1,123 +1,123 @@
|
|||
error: casting isize to i8 may truncate the value
|
||||
--> $DIR/cast_size.rs:17:5
|
||||
--> $DIR/cast_size.rs:20:5
|
||||
|
|
||||
17 | 1isize as i8;
|
||||
20 | 1isize as i8;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-possible-truncation` implied by `-D warnings`
|
||||
|
||||
error: casting isize to f64 causes a loss of precision on targets with 64-bit wide pointers (isize is 64 bits wide, but f64's mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size.rs:18:5
|
||||
--> $DIR/cast_size.rs:21:5
|
||||
|
|
||||
18 | 1isize as f64;
|
||||
21 | 1isize as f64;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-precision-loss` implied by `-D warnings`
|
||||
|
||||
error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide)
|
||||
--> $DIR/cast_size.rs:19:5
|
||||
--> $DIR/cast_size.rs:22:5
|
||||
|
|
||||
19 | 1usize as f64;
|
||||
22 | 1usize as f64;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting isize to f32 causes a loss of precision (isize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size.rs:20:5
|
||||
--> $DIR/cast_size.rs:23:5
|
||||
|
|
||||
20 | 1isize as f32;
|
||||
23 | 1isize as f32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting usize to f32 causes a loss of precision (usize is 32 or 64 bits wide, but f32's mantissa is only 23 bits wide)
|
||||
--> $DIR/cast_size.rs:21:5
|
||||
--> $DIR/cast_size.rs:24:5
|
||||
|
|
||||
21 | 1usize as f32;
|
||||
24 | 1usize as f32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting isize to i32 may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:22:5
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
|
|
||||
22 | 1isize as i32;
|
||||
25 | 1isize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting isize to u32 may lose the sign of the value
|
||||
--> $DIR/cast_size.rs:23:5
|
||||
--> $DIR/cast_size.rs:26:5
|
||||
|
|
||||
23 | 1isize as u32;
|
||||
26 | 1isize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-sign-loss` implied by `-D warnings`
|
||||
|
||||
error: casting isize to u32 may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:23:5
|
||||
--> $DIR/cast_size.rs:26:5
|
||||
|
|
||||
23 | 1isize as u32;
|
||||
26 | 1isize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting usize to u32 may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:24:5
|
||||
--> $DIR/cast_size.rs:27:5
|
||||
|
|
||||
24 | 1usize as u32;
|
||||
27 | 1usize as u32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting usize to i32 may truncate the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
--> $DIR/cast_size.rs:28:5
|
||||
|
|
||||
25 | 1usize as i32;
|
||||
28 | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting usize to i32 may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:25:5
|
||||
--> $DIR/cast_size.rs:28:5
|
||||
|
|
||||
25 | 1usize as i32;
|
||||
28 | 1usize as i32;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cast-possible-wrap` implied by `-D warnings`
|
||||
|
||||
error: casting i64 to isize may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:27:5
|
||||
--> $DIR/cast_size.rs:30:5
|
||||
|
|
||||
27 | 1i64 as isize;
|
||||
30 | 1i64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting i64 to usize may lose the sign of the value
|
||||
--> $DIR/cast_size.rs:28:5
|
||||
--> $DIR/cast_size.rs:31:5
|
||||
|
|
||||
28 | 1i64 as usize;
|
||||
31 | 1i64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting i64 to usize may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:28:5
|
||||
--> $DIR/cast_size.rs:31:5
|
||||
|
|
||||
28 | 1i64 as usize;
|
||||
31 | 1i64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u64 to isize may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:29:5
|
||||
--> $DIR/cast_size.rs:32:5
|
||||
|
|
||||
29 | 1u64 as isize;
|
||||
32 | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u64 to isize may wrap around the value on targets with 64-bit wide pointers
|
||||
--> $DIR/cast_size.rs:29:5
|
||||
--> $DIR/cast_size.rs:32:5
|
||||
|
|
||||
29 | 1u64 as isize;
|
||||
32 | 1u64 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u64 to usize may truncate the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:30:5
|
||||
--> $DIR/cast_size.rs:33:5
|
||||
|
|
||||
30 | 1u64 as usize;
|
||||
33 | 1u64 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting u32 to isize may wrap around the value on targets with 32-bit wide pointers
|
||||
--> $DIR/cast_size.rs:31:5
|
||||
--> $DIR/cast_size.rs:34:5
|
||||
|
|
||||
31 | 1u32 as isize;
|
||||
34 | 1u32 as isize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: casting i32 to usize may lose the sign of the value
|
||||
--> $DIR/cast_size.rs:34:5
|
||||
--> $DIR/cast_size.rs:37:5
|
||||
|
|
||||
34 | 1i32 as usize;
|
||||
37 | 1i32 as usize;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 19 previous errors
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#![warn(clippy::char_lit_as_u8)]
|
||||
#![allow(unused_variables)]
|
||||
fn main() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error: casting character literal to u8. `char`s are 4 bytes wide in rust, so casting to u8 truncates them
|
||||
--> $DIR/char_lit_as_u8.rs:17:13
|
||||
--> $DIR/char_lit_as_u8.rs:13:13
|
||||
|
|
||||
17 | let c = 'a' as u8;
|
||||
13 | let c = 'a' as u8;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::char-lit-as-u8` implied by `-D warnings`
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
||||
#![allow(clippy::if_same_then_else)]
|
||||
|
||||
|
@ -43,11 +40,11 @@ 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).
|
||||
// it will always panic but the lint is not smart enough to see this (it only checks if conditions).
|
||||
} 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).
|
||||
// it will always panic but the lint is not smart enough to see this (it only checks if conditions).
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,312 +1,312 @@
|
|||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:19:9
|
||||
--> $DIR/checked_unwrap.rs:16:9
|
||||
|
|
||||
18 | if x.is_some() {
|
||||
15 | if x.is_some() {
|
||||
| ----------- the check is happening here
|
||||
19 | x.unwrap(); // unnecessary
|
||||
16 | x.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/checked_unwrap.rs:13:35
|
||||
--> $DIR/checked_unwrap.rs:10:35
|
||||
|
|
||||
13 | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
||||
10 | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:18:9
|
||||
|
|
||||
15 | if x.is_some() {
|
||||
| ----------- because of this check
|
||||
...
|
||||
18 | x.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/checked_unwrap.rs:10:9
|
||||
|
|
||||
10 | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:21:9
|
||||
|
|
||||
18 | if x.is_some() {
|
||||
20 | if x.is_none() {
|
||||
| ----------- because of this check
|
||||
...
|
||||
21 | x.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/checked_unwrap.rs:13:9
|
||||
|
|
||||
13 | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:24:9
|
||||
|
|
||||
23 | if x.is_none() {
|
||||
| ----------- because of this check
|
||||
24 | x.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:26:9
|
||||
--> $DIR/checked_unwrap.rs:23:9
|
||||
|
|
||||
23 | if x.is_none() {
|
||||
20 | if x.is_none() {
|
||||
| ----------- the check is happening here
|
||||
...
|
||||
26 | x.unwrap(); // unnecessary
|
||||
23 | x.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:27:9
|
||||
|
|
||||
26 | if x.is_ok() {
|
||||
| --------- the check is happening here
|
||||
27 | x.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap_err()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:28:9
|
||||
|
|
||||
26 | if x.is_ok() {
|
||||
| --------- because of this check
|
||||
27 | x.unwrap(); // unnecessary
|
||||
28 | x.unwrap_err(); // will panic
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:30:9
|
||||
|
|
||||
29 | if x.is_ok() {
|
||||
| --------- the check is happening here
|
||||
30 | x.unwrap(); // unnecessary
|
||||
26 | if x.is_ok() {
|
||||
| --------- because of this check
|
||||
...
|
||||
30 | x.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap_err()` will always panic.
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:31:9
|
||||
|
|
||||
29 | if x.is_ok() {
|
||||
| --------- because of this check
|
||||
30 | x.unwrap(); // unnecessary
|
||||
31 | x.unwrap_err(); // will panic
|
||||
26 | if x.is_ok() {
|
||||
| --------- the check is happening here
|
||||
...
|
||||
31 | x.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:33:9
|
||||
|
|
||||
29 | if x.is_ok() {
|
||||
| --------- because of this check
|
||||
...
|
||||
33 | x.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:34:9
|
||||
|
|
||||
29 | if x.is_ok() {
|
||||
| --------- the check is happening here
|
||||
...
|
||||
34 | x.unwrap_err(); // unnecessary
|
||||
33 | if x.is_err() {
|
||||
| ---------- because of this check
|
||||
34 | x.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:35:9
|
||||
|
|
||||
33 | if x.is_err() {
|
||||
| ---------- the check is happening here
|
||||
34 | x.unwrap(); // will panic
|
||||
35 | x.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:37:9
|
||||
|
|
||||
36 | if x.is_err() {
|
||||
| ---------- because of this check
|
||||
37 | x.unwrap(); // will panic
|
||||
33 | if x.is_err() {
|
||||
| ---------- the check is happening here
|
||||
...
|
||||
37 | x.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
error: This call to `unwrap_err()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:38:9
|
||||
|
|
||||
36 | if x.is_err() {
|
||||
| ---------- the check is happening here
|
||||
37 | x.unwrap(); // will panic
|
||||
38 | x.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:40:9
|
||||
|
|
||||
36 | if x.is_err() {
|
||||
| ---------- the check is happening here
|
||||
...
|
||||
40 | x.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap_err()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:41:9
|
||||
|
|
||||
36 | if x.is_err() {
|
||||
33 | if x.is_err() {
|
||||
| ---------- because of this check
|
||||
...
|
||||
41 | x.unwrap_err(); // will panic
|
||||
38 | x.unwrap_err(); // will panic
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:58:9
|
||||
--> $DIR/checked_unwrap.rs:55:9
|
||||
|
|
||||
57 | if x.is_ok() && y.is_err() {
|
||||
54 | if x.is_ok() && y.is_err() {
|
||||
| --------- the check is happening here
|
||||
58 | x.unwrap(); // unnecessary
|
||||
55 | x.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap_err()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:59:9
|
||||
--> $DIR/checked_unwrap.rs:56:9
|
||||
|
|
||||
57 | if x.is_ok() && y.is_err() {
|
||||
54 | if x.is_ok() && y.is_err() {
|
||||
| --------- because of this check
|
||||
58 | x.unwrap(); // unnecessary
|
||||
59 | x.unwrap_err(); // will panic
|
||||
55 | x.unwrap(); // unnecessary
|
||||
56 | x.unwrap_err(); // will panic
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:60:9
|
||||
--> $DIR/checked_unwrap.rs:57:9
|
||||
|
|
||||
57 | if x.is_ok() && y.is_err() {
|
||||
54 | if x.is_ok() && y.is_err() {
|
||||
| ---------- because of this check
|
||||
...
|
||||
60 | y.unwrap(); // will panic
|
||||
57 | y.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:61:9
|
||||
--> $DIR/checked_unwrap.rs:58:9
|
||||
|
|
||||
57 | if x.is_ok() && y.is_err() {
|
||||
54 | if x.is_ok() && y.is_err() {
|
||||
| ---------- the check is happening here
|
||||
...
|
||||
61 | y.unwrap_err(); // unnecessary
|
||||
58 | y.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:75:9
|
||||
--> $DIR/checked_unwrap.rs:72:9
|
||||
|
|
||||
70 | if x.is_ok() || y.is_ok() {
|
||||
67 | if x.is_ok() || y.is_ok() {
|
||||
| --------- because of this check
|
||||
...
|
||||
75 | x.unwrap(); // will panic
|
||||
72 | x.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:76:9
|
||||
--> $DIR/checked_unwrap.rs:73:9
|
||||
|
|
||||
70 | if x.is_ok() || y.is_ok() {
|
||||
67 | if x.is_ok() || y.is_ok() {
|
||||
| --------- the check is happening here
|
||||
...
|
||||
76 | x.unwrap_err(); // unnecessary
|
||||
73 | x.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:77:9
|
||||
--> $DIR/checked_unwrap.rs:74:9
|
||||
|
|
||||
70 | if x.is_ok() || y.is_ok() {
|
||||
67 | if x.is_ok() || y.is_ok() {
|
||||
| --------- because of this check
|
||||
...
|
||||
77 | y.unwrap(); // will panic
|
||||
74 | y.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:78:9
|
||||
--> $DIR/checked_unwrap.rs:75:9
|
||||
|
|
||||
70 | if x.is_ok() || y.is_ok() {
|
||||
67 | if x.is_ok() || y.is_ok() {
|
||||
| --------- the check is happening here
|
||||
...
|
||||
78 | y.unwrap_err(); // unnecessary
|
||||
75 | y.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:79:9
|
||||
|
|
||||
78 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- the check is happening here
|
||||
79 | x.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap_err()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:80:9
|
||||
|
|
||||
78 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- because of this check
|
||||
79 | x.unwrap(); // unnecessary
|
||||
80 | x.unwrap_err(); // will panic
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:81:9
|
||||
|
|
||||
78 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- because of this check
|
||||
...
|
||||
81 | y.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:82:9
|
||||
|
|
||||
81 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- the check is happening here
|
||||
82 | x.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
78 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- the check is happening here
|
||||
...
|
||||
82 | y.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap_err()` will always panic.
|
||||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:83:9
|
||||
|
|
||||
81 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- because of this check
|
||||
82 | x.unwrap(); // unnecessary
|
||||
83 | x.unwrap_err(); // will panic
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:84:9
|
||||
|
|
||||
81 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- because of this check
|
||||
...
|
||||
84 | y.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:85:9
|
||||
|
|
||||
81 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| --------- the check is happening here
|
||||
...
|
||||
85 | y.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:86:9
|
||||
|
|
||||
81 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
78 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| ---------- the check is happening here
|
||||
...
|
||||
86 | z.unwrap(); // unnecessary
|
||||
83 | z.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap_err()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:87:9
|
||||
--> $DIR/checked_unwrap.rs:84:9
|
||||
|
|
||||
81 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
78 | if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
||||
| ---------- because of this check
|
||||
...
|
||||
87 | z.unwrap_err(); // will panic
|
||||
84 | z.unwrap_err(); // will panic
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:95:9
|
||||
--> $DIR/checked_unwrap.rs:92:9
|
||||
|
|
||||
89 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
86 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| --------- because of this check
|
||||
...
|
||||
95 | x.unwrap(); // will panic
|
||||
92 | x.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:96:9
|
||||
--> $DIR/checked_unwrap.rs:93:9
|
||||
|
|
||||
89 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
86 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| --------- the check is happening here
|
||||
...
|
||||
96 | x.unwrap_err(); // unnecessary
|
||||
93 | x.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:97:9
|
||||
--> $DIR/checked_unwrap.rs:94:9
|
||||
|
|
||||
89 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
86 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| --------- the check is happening here
|
||||
...
|
||||
97 | y.unwrap(); // unnecessary
|
||||
94 | y.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap_err()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:98:9
|
||||
--> $DIR/checked_unwrap.rs:95:9
|
||||
|
|
||||
89 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
86 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| --------- because of this check
|
||||
...
|
||||
98 | y.unwrap_err(); // will panic
|
||||
95 | y.unwrap_err(); // will panic
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:99:9
|
||||
--> $DIR/checked_unwrap.rs:96:9
|
||||
|
|
||||
89 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
86 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| ---------- because of this check
|
||||
...
|
||||
99 | z.unwrap(); // will panic
|
||||
96 | z.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:100:9
|
||||
|
|
||||
89 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| ---------- the check is happening here
|
||||
--> $DIR/checked_unwrap.rs:97:9
|
||||
|
|
||||
86 | if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
||||
| ---------- the check is happening here
|
||||
...
|
||||
100 | z.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
97 | z.unwrap_err(); // unnecessary
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
|
||||
--> $DIR/checked_unwrap.rs:108:13
|
||||
--> $DIR/checked_unwrap.rs:105:13
|
||||
|
|
||||
107 | if x.is_some() {
|
||||
104 | if x.is_some() {
|
||||
| ----------- the check is happening here
|
||||
108 | x.unwrap(); // unnecessary
|
||||
105 | x.unwrap(); // unnecessary
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: This call to `unwrap()` will always panic.
|
||||
--> $DIR/checked_unwrap.rs:110:13
|
||||
--> $DIR/checked_unwrap.rs:107:13
|
||||
|
|
||||
107 | if x.is_some() {
|
||||
104 | if x.is_some() {
|
||||
| ----------- because of this check
|
||||
...
|
||||
110 | x.unwrap(); // will panic
|
||||
107 | x.unwrap(); // will panic
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 34 previous errors
|
||||
|
|
|
@ -7,9 +7,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct Key<T> {
|
||||
#[doc(hidden)]
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
|
||||
pub fn dec_read_dec(i: &mut i32) -> i32 {
|
||||
*i -= 1;
|
||||
let ret = *i;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue