From ce5a6622e2933e70b21e3d795f09b38e2fa26165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 27 Jul 2019 19:40:28 +0200 Subject: [PATCH] submodules: update clippy from 164310dd to dc69a5c0 Changes: ```` ci: temporarily disable rustfmt checks/tetss since it's broken for nightly rustup https://github.com/rust-lang/rust/pull/62964 Bump version of clippy_dummy update test stderr, not sure which rustc pull request caused this. rustup https://github.com/rust-lang/rust/pull/62859 Fix tests for edition 2018 compatibility Revert "Revert global fmt config and use `rustfmt::skip`" Fix breakage due to rust-lang/rust#60913 Fix breakage due to rust-lang/rust#62705 Revert global fmt config and use `rustfmt::skip` Fix fmt rustup https://github.com/rust-lang/rust/pull/62679/ Update pulldown-cmark to 0.5.3 rustup https://github.com/rust-lang/rust/pull/62764 Add test Format code Decrease maximum length for stderr files Improved imports Fix "unkown clippy lint" error in UI test. Corrections for PR review. Implement lint for inherent to_string() method. UI Test Cleanup: Extract match_ref_pats tests Update UI tests Allow no_effect lint Remove comment cargo fmt UI Test Cleanup: Split up checked_unwrap tests Removed lintining on never type. UI Test Cleanup: Split out out_of_bounds_indexing false positives fixes of `implicit_return` Ignore generated fresh lifetimes in elision check. ```` --- .travis.yml | 2 +- CHANGELOG.md | 2 + README.md | 2 +- appveyor.yml | 2 +- clippy_dev/src/stderr_length_check.rs | 2 +- clippy_dummy/Cargo.toml | 2 +- clippy_dummy/build.rs | 4 +- clippy_dummy/crates-readme.md | 2 +- clippy_lints/Cargo.toml | 2 +- clippy_lints/src/double_comparison.rs | 1 + clippy_lints/src/implicit_return.rs | 154 +++++++++------- clippy_lints/src/inherent_to_string.rs | 154 ++++++++++++++++ clippy_lints/src/lib.rs | 9 +- clippy_lints/src/lifetimes.rs | 2 + clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/redundant_clone.rs | 45 +++-- clippy_lints/src/utils/internal_lints.rs | 12 +- mini-macro/src/lib.rs | 10 +- rustfmt.toml | 2 +- src/driver.rs | 4 +- src/lintlist/mod.rs | 16 +- tests/fmt.rs | 1 + tests/ui/absurd-extreme-comparisons.stderr | 2 +- tests/ui/bit_masks.stderr | 2 +- .../complex_conditionals.rs} | 40 +---- .../complex_conditionals.stderr} | 166 ++++-------------- .../ui/checked_unwrap/simple_conditionals.rs | 40 +++++ .../checked_unwrap/simple_conditionals.stderr | 118 +++++++++++++ tests/ui/cognitive_complexity.rs | 18 +- tests/ui/cognitive_complexity.stderr | 8 +- tests/ui/cstring.stderr | 2 +- tests/ui/derive.stderr | 2 +- tests/ui/dlist.rs | 2 +- tests/ui/dlist.stderr | 6 +- tests/ui/doc.rs | 4 + tests/ui/drop_bounds.stderr | 2 +- tests/ui/for_loop_over_option_result.stderr | 4 +- tests/ui/if_same_then_else.rs | 4 +- tests/ui/if_same_then_else.stderr | 6 +- tests/ui/implicit_return.rs | 10 ++ tests/ui/implicit_return.stderr | 28 +-- tests/ui/indexing_slicing.rs | 35 +--- tests/ui/indexing_slicing.stderr | 156 ++++------------ tests/ui/infinite_iter.stderr | 2 +- tests/ui/infinite_loop.stderr | 2 +- tests/ui/inherent_to_string.rs | 84 +++++++++ tests/ui/inherent_to_string.stderr | 28 +++ tests/ui/invalid_ref.stderr | 2 +- tests/ui/issue-3145.stderr | 2 +- tests/ui/issue_4266.rs | 38 ++++ tests/ui/issue_4266.stderr | 18 ++ tests/ui/lint_without_lint_pass.stderr | 2 +- tests/ui/match_bool.stderr | 2 +- tests/ui/match_ref_pats.rs | 73 ++++++++ tests/ui/match_ref_pats.stderr | 86 +++++++++ tests/ui/matches.rs | 68 +------ tests/ui/matches.stderr | 146 ++++----------- tests/ui/mistyped_literal_suffix.stderr | 2 +- tests/ui/never_loop.stderr | 2 +- tests/ui/non_copy_const.stderr | 4 +- .../ui/out_of_bounds_indexing/empty_array.rs | 19 ++ .../out_of_bounds_indexing/empty_array.stderr | 54 ++++++ tests/ui/out_of_bounds_indexing/issue-3102.rs | 11 ++ .../out_of_bounds_indexing/issue-3102.stderr | 16 ++ tests/ui/out_of_bounds_indexing/simple.rs | 22 +++ tests/ui/out_of_bounds_indexing/simple.stderr | 40 +++++ tests/ui/outer_expn_info.rs | 2 +- tests/ui/outer_expn_info.stderr | 8 +- tests/ui/proc_macro.stderr | 2 +- tests/ui/suspicious_arithmetic_impl.stderr | 2 +- tests/ui/unnecessary_clone.stderr | 2 +- tests/ui/unused_io_amount.rs | 4 +- tests/ui/unused_io_amount.stderr | 8 +- tests/ui/zero_div_zero.stderr | 2 +- 74 files changed, 1159 insertions(+), 681 deletions(-) create mode 100644 clippy_lints/src/inherent_to_string.rs rename tests/ui/{checked_unwrap.rs => checked_unwrap/complex_conditionals.rs} (62%) rename tests/ui/{checked_unwrap.stderr => checked_unwrap/complex_conditionals.stderr} (60%) create mode 100644 tests/ui/checked_unwrap/simple_conditionals.rs create mode 100644 tests/ui/checked_unwrap/simple_conditionals.stderr create mode 100644 tests/ui/inherent_to_string.rs create mode 100644 tests/ui/inherent_to_string.stderr create mode 100644 tests/ui/issue_4266.rs create mode 100644 tests/ui/issue_4266.stderr create mode 100644 tests/ui/match_ref_pats.rs create mode 100644 tests/ui/match_ref_pats.stderr create mode 100644 tests/ui/out_of_bounds_indexing/empty_array.rs create mode 100644 tests/ui/out_of_bounds_indexing/empty_array.stderr create mode 100644 tests/ui/out_of_bounds_indexing/issue-3102.rs create mode 100644 tests/ui/out_of_bounds_indexing/issue-3102.stderr create mode 100644 tests/ui/out_of_bounds_indexing/simple.rs create mode 100644 tests/ui/out_of_bounds_indexing/simple.stderr diff --git a/.travis.yml b/.travis.yml index 0a1bd0ea2750..0b012139d7a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ env: install: - | if [ -z ${INTEGRATION} ]; then - rustup component add rustfmt || cargo install --git https://github.com/rust-lang/rustfmt/ --force + # rustup component add rustfmt || cargo install --git https://github.com/rust-lang/rustfmt/ --force if [ "$TRAVIS_OS_NAME" == "linux" ]; then . $HOME/.nvm/nvm.sh nvm install stable diff --git a/CHANGELOG.md b/CHANGELOG.md index 461adb729f9b..ff5aebbc892b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -973,6 +973,8 @@ Released 2018-09-13 [`ineffective_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#ineffective_bit_mask [`infallible_destructuring_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#infallible_destructuring_match [`infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#infinite_iter +[`inherent_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string +[`inherent_to_string_shadow_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string_shadow_display [`inline_always`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_always [`inline_fn_without_body`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_fn_without_body [`int_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one diff --git a/README.md b/README.md index 24bda9bbef67..1e649d8982fe 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 306 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 308 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/appveyor.yml b/appveyor.yml index 9f6cc45af81e..4cea8d99ec6d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,7 +22,7 @@ install: - del rust-toolchain - cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed" - rustup-toolchain-install-master %RUSTC_HASH% -f -n master - - rustup component add rustfmt --toolchain nightly + #- rustup component add rustfmt --toolchain nightly - rustup default master - set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin - rustc -V diff --git a/clippy_dev/src/stderr_length_check.rs b/clippy_dev/src/stderr_length_check.rs index ba8e5f83ef4e..3049c45ddc86 100644 --- a/clippy_dev/src/stderr_length_check.rs +++ b/clippy_dev/src/stderr_length_check.rs @@ -7,7 +7,7 @@ use std::io::prelude::*; // The maximum length allowed for stderr files. // // We limit this because small files are easier to deal with than bigger files. -const LIMIT: usize = 320; +const LIMIT: usize = 275; pub fn check() { let stderr_files = stderr_files(); diff --git a/clippy_dummy/Cargo.toml b/clippy_dummy/Cargo.toml index f99a23d93d06..fb426a4ad2d1 100644 --- a/clippy_dummy/Cargo.toml +++ b/clippy_dummy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clippy_dummy" # rename to clippy before publishing -version = "0.0.302" +version = "0.0.303" authors = ["Manish Goregaokar "] edition = "2018" readme = "crates-readme.md" diff --git a/clippy_dummy/build.rs b/clippy_dummy/build.rs index 59d32e5db439..1288250daaa6 100644 --- a/clippy_dummy/build.rs +++ b/clippy_dummy/build.rs @@ -3,7 +3,7 @@ extern crate term; fn main() { if let Err(_) = foo() { eprintln!("error: Clippy is no longer available via crates.io\n"); - eprintln!("help: please run `rustup component add clippy-preview` instead"); + eprintln!("help: please run `rustup component add clippy` instead"); } std::process::exit(1); } @@ -31,7 +31,7 @@ fn foo() -> Result<(), ()> { write!(t, "please run `").map_err(|_| ())?; t.attr(term::Attr::Bold).map_err(|_| ())?; - write!(t, "rustup component add clippy-preview").map_err(|_| ())?; + write!(t, "rustup component add clippy").map_err(|_| ())?; t.reset().map_err(|_| ())?; t.fg(term::color::WHITE).map_err(|_| ())?; diff --git a/clippy_dummy/crates-readme.md b/clippy_dummy/crates-readme.md index 4f4f4991ed45..0decae8b9103 100644 --- a/clippy_dummy/crates-readme.md +++ b/clippy_dummy/crates-readme.md @@ -1,7 +1,7 @@ Installing clippy via crates.io is deprecated. Please use the following: ```terminal -rustup component add clippy-preview +rustup component add clippy ``` on a Rust version 1.29 or later. You may need to run `rustup self update` if it complains about a missing clippy binary. diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index ba67a3ac539c..53d7f317f332 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -27,7 +27,7 @@ semver = "0.9.0" serde = { version = "1.0", features = ["derive"] } toml = "0.5" unicode-normalization = "0.1" -pulldown-cmark = "0.5.2" +pulldown-cmark = "0.5.3" url = "1.7.0" if_chain = "1.0.0" smallvec = { version = "0.6.5", features = ["union"] } diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 228d53ff1130..0c7c81f40bf4 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -63,6 +63,7 @@ impl<'a, 'tcx> DoubleComparisons { ); }}; } + #[rustfmt::skip] match (op, lkind, rkind) { (BinOpKind::Or, BinOpKind::Eq, BinOpKind::Lt) | (BinOpKind::Or, BinOpKind::Lt, BinOpKind::Eq) => { lint_double_comparison!(<=) diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs index e280ce4c80ba..4df9789f39df 100644 --- a/clippy_lints/src/implicit_return.rs +++ b/clippy_lints/src/implicit_return.rs @@ -1,7 +1,14 @@ -use crate::utils::{in_macro_or_desugar, is_expn_of, snippet_opt, span_lint_and_then}; -use rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl, HirId, MatchSource}; -use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::{declare_lint_pass, declare_tool_lint}; +use crate::utils::{ + in_macro_or_desugar, match_def_path, + paths::{BEGIN_PANIC, BEGIN_PANIC_FMT}, + resolve_node, snippet_opt, span_lint_and_then, +}; +use if_chain::if_chain; +use rustc::{ + declare_lint_pass, declare_tool_lint, + hir::{intravisit::FnKind, Body, Expr, ExprKind, FnDecl, HirId, MatchSource, StmtKind}, + lint::{LateContext, LateLintPass, LintArray, LintPass}, +}; use rustc_errors::Applicability; use syntax::source_map::Span; @@ -35,71 +42,92 @@ declare_clippy_lint! { declare_lint_pass!(ImplicitReturn => [IMPLICIT_RETURN]); -impl ImplicitReturn { - fn lint(cx: &LateContext<'_, '_>, outer_span: syntax_pos::Span, inner_span: syntax_pos::Span, msg: &str) { - span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| { - if let Some(snippet) = snippet_opt(cx, inner_span) { - db.span_suggestion( - outer_span, - msg, - format!("return {}", snippet), - Applicability::MachineApplicable, - ); - } - }); +static LINT_BREAK: &str = "change `break` to `return` as shown"; +static LINT_RETURN: &str = "add `return` as shown"; + +fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str) { + let outer_span = span_to_outer_expn(outer_span); + let inner_span = span_to_outer_expn(inner_span); + + span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| { + if let Some(snippet) = snippet_opt(cx, inner_span) { + db.span_suggestion( + outer_span, + msg, + format!("return {}", snippet), + Applicability::MachineApplicable, + ); + } + }); +} + +fn span_to_outer_expn(span: Span) -> Span { + if let Some(expr) = span.ctxt().outer_expn_info() { + span_to_outer_expn(expr.call_site) + } else { + span } +} - fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) { - match &expr.node { - // loops could be using `break` instead of `return` - ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => { - if let Some(expr) = &block.expr { - Self::expr_match(cx, expr); - } - // only needed in the case of `break` with `;` at the end - else if let Some(stmt) = block.stmts.last() { - if let rustc::hir::StmtKind::Semi(expr, ..) = &stmt.node { - // make sure it's a break, otherwise we want to skip - if let ExprKind::Break(.., break_expr) = &expr.node { - if let Some(break_expr) = break_expr { - Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown"); - } - } +fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) { + match &expr.node { + // loops could be using `break` instead of `return` + ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => { + if let Some(expr) = &block.expr { + expr_match(cx, expr); + } + // only needed in the case of `break` with `;` at the end + else if let Some(stmt) = block.stmts.last() { + if_chain! { + if let StmtKind::Semi(expr, ..) = &stmt.node; + // make sure it's a break, otherwise we want to skip + if let ExprKind::Break(.., break_expr) = &expr.node; + if let Some(break_expr) = break_expr; + then { + lint(cx, expr.span, break_expr.span, LINT_BREAK); } } - }, - // use `return` instead of `break` - ExprKind::Break(.., break_expr) => { - if let Some(break_expr) = break_expr { - Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown"); - } - }, - ExprKind::Match(.., arms, source) => { - let check_all_arms = match source { - MatchSource::IfLetDesugar { - contains_else_clause: has_else, - } => *has_else, - _ => true, - }; + } + }, + // use `return` instead of `break` + ExprKind::Break(.., break_expr) => { + if let Some(break_expr) = break_expr { + lint(cx, expr.span, break_expr.span, LINT_BREAK); + } + }, + ExprKind::Match(.., arms, source) => { + let check_all_arms = match source { + MatchSource::IfLetDesugar { + contains_else_clause: has_else, + } => *has_else, + _ => true, + }; - if check_all_arms { - for arm in arms { - Self::expr_match(cx, &arm.body); - } - } else { - Self::expr_match(cx, &arms.first().expect("if let doesn't have a single arm").body); + if check_all_arms { + for arm in arms { + expr_match(cx, &arm.body); } - }, - // skip if it already has a return statement - ExprKind::Ret(..) => (), - // everything else is missing `return` - _ => { - // make sure it's not just an unreachable expression - if is_expn_of(expr.span, "unreachable").is_none() { - Self::lint(cx, expr.span, expr.span, "add `return` as shown") + } else { + expr_match(cx, &arms.first().expect("if let doesn't have a single arm").body); + } + }, + // skip if it already has a return statement + ExprKind::Ret(..) => (), + // make sure it's not a call that panics + ExprKind::Call(expr, ..) => { + if_chain! { + if let ExprKind::Path(qpath) = &expr.node; + if let Some(path_def_id) = resolve_node(cx, qpath, expr.hir_id).opt_def_id(); + if match_def_path(cx, path_def_id, &BEGIN_PANIC) || + match_def_path(cx, path_def_id, &BEGIN_PANIC_FMT); + then { } + else { + lint(cx, expr.span, expr.span, LINT_RETURN) } - }, - } + } + }, + // everything else is missing `return` + _ => lint(cx, expr.span, expr.span, LINT_RETURN), } } @@ -119,7 +147,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitReturn { // checking return type through MIR, HIR is not able to determine inferred closure return types // make sure it's not a macro if !mir.return_ty().is_unit() && !in_macro_or_desugar(span) { - Self::expr_match(cx, &body.value); + expr_match(cx, &body.value); } } } diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs new file mode 100644 index 000000000000..ef0a75438379 --- /dev/null +++ b/clippy_lints/src/inherent_to_string.rs @@ -0,0 +1,154 @@ +use if_chain::if_chain; +use rustc::hir::{ImplItem, ImplItemKind}; +use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; +use rustc::{declare_lint_pass, declare_tool_lint}; + +use crate::utils::{ + get_trait_def_id, implements_trait, in_macro_or_desugar, match_type, paths, return_ty, span_help_and_lint, + trait_ref_of_method, walk_ptrs_ty, +}; + +declare_clippy_lint! { + /// **What id does:** Checks for the definition of inherent methods with a signature of `to_string(&self) -> String`. + /// + /// **Why is this bad?** This method is also implicitly defined if a type implements the `Display` trait. As the functionality of `Display` is much more versatile, it should be preferred. + /// + /// **Known problems:** None + /// + /// ** Example:** + /// + /// ```rust + /// // Bad + /// pub struct A; + /// + /// impl A { + /// pub fn to_string(&self) -> String { + /// "I am A".to_string() + /// } + /// } + /// ``` + /// + /// ```rust + /// // Good + /// use std::fmt; + /// + /// pub struct A; + /// + /// impl fmt::Display for A { + /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + /// write!(f, "I am A") + /// } + /// } + /// ``` + pub INHERENT_TO_STRING, + style, + "type implements inherent method `to_string()`, but should instead implement the `Display` trait" +} + +declare_clippy_lint! { + /// **What id does:** Checks for the definition of inherent methods with a signature of `to_string(&self) -> String` and if the type implementing this method also implements the `Display` trait. + /// + /// **Why is this bad?** This method is also implicitly defined if a type implements the `Display` trait. The less versatile inherent method will then shadow the implementation introduced by `Display`. + /// + /// **Known problems:** None + /// + /// ** Example:** + /// + /// ```rust + /// // Bad + /// use std::fmt; + /// + /// pub struct A; + /// + /// impl A { + /// pub fn to_string(&self) -> String { + /// "I am A".to_string() + /// } + /// } + /// + /// impl fmt::Display for A { + /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + /// write!(f, "I am A, too") + /// } + /// } + /// ``` + /// + /// ```rust + /// // Good + /// use std::fmt; + /// + /// pub struct A; + /// + /// impl fmt::Display for A { + /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + /// write!(f, "I am A") + /// } + /// } + /// ``` + pub INHERENT_TO_STRING_SHADOW_DISPLAY, + correctness, + "type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait " +} + +declare_lint_pass!(InherentToString => [INHERENT_TO_STRING, INHERENT_TO_STRING_SHADOW_DISPLAY]); + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString { + fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem) { + if in_macro_or_desugar(impl_item.span) { + return; + } + + if_chain! { + // Check if item is a method, called to_string and has a parameter 'self' + if let ImplItemKind::Method(ref signature, _) = impl_item.node; + if impl_item.ident.name.as_str() == "to_string"; + let decl = &signature.decl; + if decl.implicit_self.has_implicit_self(); + + // Check if return type is String + if match_type(cx, return_ty(cx, impl_item.hir_id), &paths::STRING); + + // Filters instances of to_string which are required by a trait + if trait_ref_of_method(cx, impl_item.hir_id).is_none(); + + then { + show_lint(cx, impl_item); + } + } + } +} + +fn show_lint(cx: &LateContext<'_, '_>, item: &ImplItem) { + let display_trait_id = + get_trait_def_id(cx, &["core", "fmt", "Display"]).expect("Failed to get trait ID of `Display`!"); + + // Get the real type of 'self' + let fn_def_id = cx.tcx.hir().local_def_id(item.hir_id); + let self_type = cx.tcx.fn_sig(fn_def_id).input(0); + let self_type = walk_ptrs_ty(self_type.skip_binder()); + + // Emit either a warning or an error + if implements_trait(cx, self_type, display_trait_id, &[]) { + span_help_and_lint( + cx, + INHERENT_TO_STRING_SHADOW_DISPLAY, + item.span, + &format!( + "type `{}` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`", + self_type.to_string() + ), + &format!("remove the inherent method from type `{}`", self_type.to_string()) + ); + } else { + span_help_and_lint( + cx, + INHERENT_TO_STRING, + item.span, + &format!( + "implementation of inherent method `to_string(&self) -> String` for type `{}`", + self_type.to_string() + ), + &format!("implement trait `Display` for type `{}` instead", self_type.to_string()), + ); + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 369a736aa644..6d90d315f005 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1,6 +1,7 @@ // error-pattern:cargo-clippy #![feature(box_syntax)] +#![feature(box_patterns)] #![feature(never_type)] #![feature(rustc_private)] #![feature(slice_patterns)] @@ -195,6 +196,7 @@ pub mod indexing_slicing; pub mod infallible_destructuring_match; pub mod infinite_iter; pub mod inherent_impl; +pub mod inherent_to_string; pub mod inline_fn_without_body; pub mod int_plus_one; pub mod integer_division; @@ -585,6 +587,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { reg.register_late_lint_pass(box path_buf_push_overwrite::PathBufPushOverwrite); reg.register_late_lint_pass(box checked_conversions::CheckedConversions); reg.register_late_lint_pass(box integer_division::IntegerDivision); + reg.register_late_lint_pass(box inherent_to_string::InherentToString); reg.register_lint_group("clippy::restriction", Some("clippy_restriction"), vec![ arithmetic::FLOAT_ARITHMETIC, @@ -666,7 +669,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { utils::internal_lints::CLIPPY_LINTS_INTERNAL, utils::internal_lints::COMPILER_LINT_FUNCTIONS, utils::internal_lints::LINT_WITHOUT_LINT_PASS, - utils::internal_lints::OUTER_EXPN_INFO, + utils::internal_lints::OUTER_EXPN_EXPN_INFO, ]); reg.register_lint_group("clippy::all", Some("clippy"), vec![ @@ -725,6 +728,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { indexing_slicing::OUT_OF_BOUNDS_INDEXING, infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH, infinite_iter::INFINITE_ITER, + inherent_to_string::INHERENT_TO_STRING, + inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY, inline_fn_without_body::INLINE_FN_WITHOUT_BODY, int_plus_one::INT_PLUS_ONE, invalid_ref::INVALID_REF, @@ -913,6 +918,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { formatting::SUSPICIOUS_ASSIGNMENT_FORMATTING, formatting::SUSPICIOUS_ELSE_FORMATTING, infallible_destructuring_match::INFALLIBLE_DESTRUCTURING_MATCH, + inherent_to_string::INHERENT_TO_STRING, len_zero::LEN_WITHOUT_IS_EMPTY, len_zero::LEN_ZERO, let_if_seq::USELESS_LET_IF_SEQ, @@ -1075,6 +1081,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { functions::NOT_UNSAFE_PTR_ARG_DEREF, indexing_slicing::OUT_OF_BOUNDS_INDEXING, infinite_iter::INFINITE_ITER, + inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY, inline_fn_without_body::INLINE_FN_WITHOUT_BODY, invalid_ref::INVALID_REF, literal_representation::MISTYPED_LITERAL_SUFFIXES, diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index dbdb3c519627..47cced9d9a42 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -283,6 +283,8 @@ impl<'v, 't> RefVisitor<'v, 't> { if let Some(ref lt) = *lifetime { if lt.name == LifetimeName::Static { self.lts.push(RefLt::Static); + } else if let LifetimeName::Param(ParamName::Fresh(_)) = lt.name { + // Fresh lifetimes generated should be ignored. } else if lt.is_elided() { self.lts.push(RefLt::Unnamed); } else { diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 5098fa2a7365..c5283a432bcb 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -193,7 +193,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { if_chain! { if !is_self(arg); - if !ty.is_mutable_pointer(); + if !ty.is_mutable_ptr(); if !is_copy(cx, ty); if !whitelisted_traits.iter().any(|&t| implements_trait(cx, ty, t, &[])); if !implements_borrow_trait; diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index edcf41f758c0..e85538615973 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -132,7 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone { let pred_arg = if_chain! { if let Some((pred_fn_def_id, pred_arg, pred_arg_ty, Some(res))) = is_call_with_ref_arg(cx, mir, &pred_terminator.kind); - if *res == mir::Place::Base(mir::PlaceBase::Local(cloned)); + if res.base == mir::PlaceBase::Local(cloned); if match_def_path(cx, pred_fn_def_id, &paths::DEREF_TRAIT_METHOD); if match_type(cx, pred_arg_ty, &paths::PATH_BUF) || match_type(cx, pred_arg_ty, &paths::OS_STRING); @@ -218,7 +218,7 @@ fn is_call_with_ref_arg<'tcx>( if_chain! { if let TerminatorKind::Call { func, args, destination, .. } = kind; if args.len() == 1; - if let mir::Operand::Move(mir::Place::Base(mir::PlaceBase::Local(local))) = &args[0]; + if let mir::Operand::Move(mir::Place { base: mir::PlaceBase::Local(local), .. }) = &args[0]; if let ty::FnDef(def_id, _) = func.ty(&*mir, cx.tcx).sty; if let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].ty(&*mir, cx.tcx)); if !is_copy(cx, inner_ty); @@ -244,7 +244,14 @@ fn find_stmt_assigns_to<'a, 'tcx: 'a>( stmts .rev() .find_map(|stmt| { - if let mir::StatementKind::Assign(mir::Place::Base(mir::PlaceBase::Local(local)), v) = &stmt.kind { + if let mir::StatementKind::Assign( + mir::Place { + base: mir::PlaceBase::Local(local), + .. + }, + v, + ) = &stmt.kind + { if *local == to { return Some(v); } @@ -271,28 +278,34 @@ fn find_stmt_assigns_to<'a, 'tcx: 'a>( fn base_local_and_movability<'tcx>( cx: &LateContext<'_, 'tcx>, mir: &mir::Body<'tcx>, - mut place: &mir::Place<'tcx>, + place: &mir::Place<'tcx>, ) -> Option<(mir::Local, CannotMoveOut)> { - use rustc::mir::Place::*; + use rustc::mir::Place; use rustc::mir::PlaceBase; + use rustc::mir::PlaceRef; + use rustc::mir::Projection; // Dereference. You cannot move things out from a borrowed value. let mut deref = false; // Accessing a field of an ADT that has `Drop`. Moving the field out will cause E0509. let mut field = false; - loop { - match place { - Base(PlaceBase::Local(local)) => return Some((*local, deref || field)), - Projection(proj) => { - place = &proj.base; - deref = deref || matches!(proj.elem, mir::ProjectionElem::Deref); - if !field && matches!(proj.elem, mir::ProjectionElem::Field(..)) { - field = has_drop(cx, place.ty(&mir.local_decls, cx.tcx).ty); - } - }, - _ => return None, + let PlaceRef { + base: place_base, + mut projection, + } = place.as_ref(); + if let PlaceBase::Local(local) = place_base { + while let Some(box Projection { base, elem }) = projection { + projection = base; + deref = matches!(elem, mir::ProjectionElem::Deref); + field = !field + && matches!(elem, mir::ProjectionElem::Field(..)) + && has_drop(cx, Place::ty_from(place_base, projection, &mir.local_decls, cx.tcx).ty); } + + Some((*local, deref || field)) + } else { + None } } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index aba2543b13c8..6393bf2add47 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -93,9 +93,9 @@ declare_clippy_lint! { /// ```rust /// expr.span.ctxt().outer_expn_info() /// ``` - pub OUTER_EXPN_INFO, + pub OUTER_EXPN_EXPN_INFO, internal, - "using `cx.outer().expn_info()` instead of `cx.outer_expn_info()`" + "using `cx.outer_expn().expn_info()` instead of `cx.outer_expn_info()`" } declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]); @@ -280,7 +280,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { pub struct OuterExpnInfoPass; -impl_lint_pass!(OuterExpnInfoPass => [OUTER_EXPN_INFO]); +impl_lint_pass!(OuterExpnInfoPass => [OUTER_EXPN_EXPN_INFO]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnInfoPass { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { @@ -288,7 +288,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnInfoPass { let method_names: Vec = method_names.iter().map(|s| s.as_str()).collect(); let method_names: Vec<&str> = method_names.iter().map(std::convert::AsRef::as_ref).collect(); if_chain! { - if let ["expn_info", "outer"] = method_names.as_slice(); + if let ["expn_info", "outer_expn"] = method_names.as_slice(); let args = arg_lists[1]; if args.len() == 1; let self_arg = &args[0]; @@ -297,9 +297,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnInfoPass { then { span_lint_and_sugg( cx, - OUTER_EXPN_INFO, + OUTER_EXPN_EXPN_INFO, expr.span.trim_start(self_arg.span).unwrap_or(expr.span), - "usage of `outer().expn_info()`", + "usage of `outer_expn().expn_info()`", "try", ".outer_expn_info()".to_string(), Applicability::MachineApplicable, diff --git a/mini-macro/src/lib.rs b/mini-macro/src/lib.rs index ec489344a6f1..ddb40dace753 100644 --- a/mini-macro/src/lib.rs +++ b/mini-macro/src/lib.rs @@ -2,13 +2,17 @@ #![deny(rust_2018_idioms)] extern crate proc_macro; -use proc_macro::{TokenStream, quote}; +use proc_macro::{quote, TokenStream}; #[proc_macro_derive(ClippyMiniMacroTest)] pub fn mini_macro(_: TokenStream) -> TokenStream { quote!( - #[allow(unused)] fn needless_take_by_value(s: String) { println!("{}", s.len()); } - #[allow(unused)] fn needless_loop(items: &[u8]) { + #[allow(unused)] + fn needless_take_by_value(s: String) { + println!("{}", s.len()); + } + #[allow(unused)] + fn needless_loop(items: &[u8]) { for i in 0..items.len() { println!("{}", items[i]); } diff --git a/rustfmt.toml b/rustfmt.toml index 797eccdad99e..f1241e74b0a3 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,5 +2,5 @@ max_width = 120 comment_width = 100 match_block_trailing_comma = true wrap_comments = true - +edition = "2018" error_on_line_overflow = true diff --git a/src/driver.rs b/src/driver.rs index 146e3fe2d08f..cec88be7eb1b 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -63,7 +63,7 @@ fn test_arg_value() { struct ClippyCallbacks; impl rustc_driver::Callbacks for ClippyCallbacks { - fn after_parsing(&mut self, compiler: &interface::Compiler) -> bool { + fn after_parsing(&mut self, compiler: &interface::Compiler) -> rustc_driver::Compilation { let sess = compiler.session(); let mut registry = rustc_plugin::registry::Registry::new( sess, @@ -107,7 +107,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks { sess.plugin_attributes.borrow_mut().extend(attributes); // Continue execution - true + rustc_driver::Compilation::Continue } } diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 8c49a3b18380..2d9e800b6e43 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 306] = [ +pub const ALL_LINTS: [Lint; 308] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness", @@ -728,6 +728,20 @@ pub const ALL_LINTS: [Lint; 306] = [ deprecation: None, module: "infinite_iter", }, + Lint { + name: "inherent_to_string", + group: "style", + desc: "type implements inherent method `to_string()`, but should instead implement the `Display` trait", + deprecation: None, + module: "inherent_to_string", + }, + Lint { + name: "inherent_to_string_shadow_display", + group: "correctness", + desc: "type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait ", + deprecation: None, + module: "inherent_to_string", + }, Lint { name: "inline_always", group: "pedantic", diff --git a/tests/fmt.rs b/tests/fmt.rs index 2500132d7ad3..4df93cf5a085 100644 --- a/tests/fmt.rs +++ b/tests/fmt.rs @@ -1,4 +1,5 @@ #[test] +#[ignore] fn fmt() { if option_env!("RUSTC_TEST_SUITE").is_some() { return; diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr index b18a943c557c..c22c7eb75b46 100644 --- a/tests/ui/absurd-extreme-comparisons.stderr +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -141,7 +141,7 @@ error: <-comparison of unit values detected. This will always be false LL | () < {}; | ^^^^^^^ | - = note: #[deny(clippy::unit_cmp)] on by default + = note: `#[deny(clippy::unit_cmp)]` on by default error: aborting due to 18 previous errors diff --git a/tests/ui/bit_masks.stderr b/tests/ui/bit_masks.stderr index 159db0374d29..dc5ad6dfbdff 100644 --- a/tests/ui/bit_masks.stderr +++ b/tests/ui/bit_masks.stderr @@ -12,7 +12,7 @@ error: this operation will always return zero. This is likely not the intended o LL | x & 0 == 0; | ^^^^^ | - = note: #[deny(clippy::erasing_op)] on by default + = note: `#[deny(clippy::erasing_op)]` on by default error: incompatible bit mask: `_ & 2` can never be equal to `1` --> $DIR/bit_masks.rs:17:5 diff --git a/tests/ui/checked_unwrap.rs b/tests/ui/checked_unwrap/complex_conditionals.rs similarity index 62% rename from tests/ui/checked_unwrap.rs rename to tests/ui/checked_unwrap/complex_conditionals.rs index 21f9e33201f1..fbeee1b572a6 100644 --- a/tests/ui/checked_unwrap.rs +++ b/tests/ui/checked_unwrap/complex_conditionals.rs @@ -1,44 +1,6 @@ #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] #![allow(clippy::if_same_then_else)] -fn main() { - let x = Some(()); - if x.is_some() { - x.unwrap(); // unnecessary - } else { - x.unwrap(); // will panic - } - if x.is_none() { - x.unwrap(); // will panic - } else { - x.unwrap(); // unnecessary - } - let mut x: Result<(), ()> = Ok(()); - if x.is_ok() { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic - } else { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary - } - if x.is_err() { - x.unwrap(); // will panic - x.unwrap_err(); // unnecessary - } else { - x.unwrap(); // unnecessary - x.unwrap_err(); // will panic - } - 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). - } 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). - } -} - fn test_complex_conditions() { let x: Result<(), ()> = Ok(()); let y: Result<(), ()> = Ok(()); @@ -99,3 +61,5 @@ fn test_nested() { } } } + +fn main() {} diff --git a/tests/ui/checked_unwrap.stderr b/tests/ui/checked_unwrap/complex_conditionals.stderr similarity index 60% rename from tests/ui/checked_unwrap.stderr rename to tests/ui/checked_unwrap/complex_conditionals.stderr index 514814b0ee02..a2207314aeec 100644 --- a/tests/ui/checked_unwrap.stderr +++ b/tests/ui/checked_unwrap/complex_conditionals.stderr @@ -1,138 +1,34 @@ 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:7:9 + --> $DIR/complex_conditionals.rs:8:9 | -LL | if x.is_some() { - | ----------- the check is happening here +LL | if x.is_ok() && y.is_err() { + | --------- the check is happening here LL | x.unwrap(); // unnecessary | ^^^^^^^^^^ | note: lint level defined here - --> $DIR/checked_unwrap.rs:1:35 + --> $DIR/complex_conditionals.rs:1:35 | LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:9:9 - | -LL | if x.is_some() { - | ----------- because of this check -... -LL | x.unwrap(); // will panic - | ^^^^^^^^^^ - | -note: lint level defined here - --> $DIR/checked_unwrap.rs:1:9 - | -LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:12:9 - | -LL | if x.is_none() { - | ----------- because of this check -LL | 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:14:9 - | -LL | if x.is_none() { - | ----------- the check is happening here -... -LL | 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:18:9 - | -LL | if x.is_ok() { - | --------- the check is happening here -LL | x.unwrap(); // unnecessary - | ^^^^^^^^^^ - error: This call to `unwrap_err()` will always panic. - --> $DIR/checked_unwrap.rs:19:9 + --> $DIR/complex_conditionals.rs:9:9 | -LL | if x.is_ok() { - | --------- because of this check -LL | x.unwrap(); // unnecessary -LL | x.unwrap_err(); // will panic - | ^^^^^^^^^^^^^^ - -error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:21:9 - | -LL | if x.is_ok() { +LL | if x.is_ok() && y.is_err() { | --------- because of this check -... -LL | 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:22:9 - | -LL | if x.is_ok() { - | --------- the check is happening here -... -LL | x.unwrap_err(); // unnecessary - | ^^^^^^^^^^^^^^ - -error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:25:9 - | -LL | if x.is_err() { - | ---------- because of this check -LL | 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:26:9 - | -LL | if x.is_err() { - | ---------- the check is happening here -LL | x.unwrap(); // will panic -LL | 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:28:9 - | -LL | if x.is_err() { - | ---------- the check is happening here -... LL | x.unwrap(); // unnecessary - | ^^^^^^^^^^ - -error: This call to `unwrap_err()` will always panic. - --> $DIR/checked_unwrap.rs:29:9 - | -LL | if x.is_err() { - | ---------- because of this check -... LL | 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:46:9 | -LL | if x.is_ok() && y.is_err() { - | --------- the check is happening here -LL | x.unwrap(); // unnecessary - | ^^^^^^^^^^ - -error: This call to `unwrap_err()` will always panic. - --> $DIR/checked_unwrap.rs:47:9 +note: lint level defined here + --> $DIR/complex_conditionals.rs:1:9 | -LL | if x.is_ok() && y.is_err() { - | --------- because of this check -LL | x.unwrap(); // unnecessary -LL | x.unwrap_err(); // will panic - | ^^^^^^^^^^^^^^ +LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:48:9 + --> $DIR/complex_conditionals.rs:10:9 | LL | if x.is_ok() && y.is_err() { | ---------- because of this check @@ -141,7 +37,7 @@ LL | 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:49:9 + --> $DIR/complex_conditionals.rs:11:9 | LL | if x.is_ok() && y.is_err() { | ---------- the check is happening here @@ -150,7 +46,7 @@ LL | y.unwrap_err(); // unnecessary | ^^^^^^^^^^^^^^ error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:63:9 + --> $DIR/complex_conditionals.rs:25:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check @@ -159,7 +55,7 @@ LL | 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:64:9 + --> $DIR/complex_conditionals.rs:26:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here @@ -168,7 +64,7 @@ LL | x.unwrap_err(); // unnecessary | ^^^^^^^^^^^^^^ error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:65:9 + --> $DIR/complex_conditionals.rs:27:9 | LL | if x.is_ok() || y.is_ok() { | --------- because of this check @@ -177,7 +73,7 @@ LL | 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:66:9 + --> $DIR/complex_conditionals.rs:28:9 | LL | if x.is_ok() || y.is_ok() { | --------- the check is happening here @@ -186,7 +82,7 @@ LL | 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:70:9 + --> $DIR/complex_conditionals.rs:32:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here @@ -194,7 +90,7 @@ LL | x.unwrap(); // unnecessary | ^^^^^^^^^^ error: This call to `unwrap_err()` will always panic. - --> $DIR/checked_unwrap.rs:71:9 + --> $DIR/complex_conditionals.rs:33:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check @@ -203,7 +99,7 @@ LL | x.unwrap_err(); // will panic | ^^^^^^^^^^^^^^ error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:72:9 + --> $DIR/complex_conditionals.rs:34:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- because of this check @@ -212,7 +108,7 @@ LL | 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:73:9 + --> $DIR/complex_conditionals.rs:35:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | --------- the check is happening here @@ -221,7 +117,7 @@ LL | 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:74:9 + --> $DIR/complex_conditionals.rs:36:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- the check is happening here @@ -230,7 +126,7 @@ LL | z.unwrap(); // unnecessary | ^^^^^^^^^^ error: This call to `unwrap_err()` will always panic. - --> $DIR/checked_unwrap.rs:75:9 + --> $DIR/complex_conditionals.rs:37:9 | LL | if x.is_ok() && !(y.is_ok() || z.is_err()) { | ---------- because of this check @@ -239,7 +135,7 @@ LL | z.unwrap_err(); // will panic | ^^^^^^^^^^^^^^ error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:83:9 + --> $DIR/complex_conditionals.rs:45:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check @@ -248,7 +144,7 @@ LL | 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:84:9 + --> $DIR/complex_conditionals.rs:46:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here @@ -257,7 +153,7 @@ LL | 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:85:9 + --> $DIR/complex_conditionals.rs:47:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- the check is happening here @@ -266,7 +162,7 @@ LL | y.unwrap(); // unnecessary | ^^^^^^^^^^ error: This call to `unwrap_err()` will always panic. - --> $DIR/checked_unwrap.rs:86:9 + --> $DIR/complex_conditionals.rs:48:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | --------- because of this check @@ -275,7 +171,7 @@ LL | y.unwrap_err(); // will panic | ^^^^^^^^^^^^^^ error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:87:9 + --> $DIR/complex_conditionals.rs:49:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- because of this check @@ -284,7 +180,7 @@ LL | 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:88:9 + --> $DIR/complex_conditionals.rs:50:9 | LL | if x.is_ok() || !(y.is_ok() && z.is_err()) { | ---------- the check is happening here @@ -293,7 +189,7 @@ LL | 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:96:13 + --> $DIR/complex_conditionals.rs:58:13 | LL | if x.is_some() { | ----------- the check is happening here @@ -301,7 +197,7 @@ LL | x.unwrap(); // unnecessary | ^^^^^^^^^^ error: This call to `unwrap()` will always panic. - --> $DIR/checked_unwrap.rs:98:13 + --> $DIR/complex_conditionals.rs:60:13 | LL | if x.is_some() { | ----------- because of this check @@ -309,5 +205,5 @@ LL | if x.is_some() { LL | x.unwrap(); // will panic | ^^^^^^^^^^ -error: aborting due to 34 previous errors +error: aborting due to 22 previous errors diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs new file mode 100644 index 000000000000..c20c4a7a7009 --- /dev/null +++ b/tests/ui/checked_unwrap/simple_conditionals.rs @@ -0,0 +1,40 @@ +#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] +#![allow(clippy::if_same_then_else)] + +fn main() { + let x = Some(()); + if x.is_some() { + x.unwrap(); // unnecessary + } else { + x.unwrap(); // will panic + } + if x.is_none() { + x.unwrap(); // will panic + } else { + x.unwrap(); // unnecessary + } + let mut x: Result<(), ()> = Ok(()); + if x.is_ok() { + x.unwrap(); // unnecessary + x.unwrap_err(); // will panic + } else { + x.unwrap(); // will panic + x.unwrap_err(); // unnecessary + } + if x.is_err() { + x.unwrap(); // will panic + x.unwrap_err(); // unnecessary + } else { + x.unwrap(); // unnecessary + x.unwrap_err(); // will panic + } + 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). + } 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). + } +} diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr new file mode 100644 index 000000000000..58a38cd8209c --- /dev/null +++ b/tests/ui/checked_unwrap/simple_conditionals.stderr @@ -0,0 +1,118 @@ +error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`. + --> $DIR/simple_conditionals.rs:7:9 + | +LL | if x.is_some() { + | ----------- the check is happening here +LL | x.unwrap(); // unnecessary + | ^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/simple_conditionals.rs:1:35 + | +LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: This call to `unwrap()` will always panic. + --> $DIR/simple_conditionals.rs:9:9 + | +LL | if x.is_some() { + | ----------- because of this check +... +LL | x.unwrap(); // will panic + | ^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/simple_conditionals.rs:1:9 + | +LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: This call to `unwrap()` will always panic. + --> $DIR/simple_conditionals.rs:12:9 + | +LL | if x.is_none() { + | ----------- because of this check +LL | 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/simple_conditionals.rs:14:9 + | +LL | if x.is_none() { + | ----------- the check is happening here +... +LL | 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/simple_conditionals.rs:18:9 + | +LL | if x.is_ok() { + | --------- the check is happening here +LL | x.unwrap(); // unnecessary + | ^^^^^^^^^^ + +error: This call to `unwrap_err()` will always panic. + --> $DIR/simple_conditionals.rs:19:9 + | +LL | if x.is_ok() { + | --------- because of this check +LL | x.unwrap(); // unnecessary +LL | x.unwrap_err(); // will panic + | ^^^^^^^^^^^^^^ + +error: This call to `unwrap()` will always panic. + --> $DIR/simple_conditionals.rs:21:9 + | +LL | if x.is_ok() { + | --------- because of this check +... +LL | 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/simple_conditionals.rs:22:9 + | +LL | if x.is_ok() { + | --------- the check is happening here +... +LL | x.unwrap_err(); // unnecessary + | ^^^^^^^^^^^^^^ + +error: This call to `unwrap()` will always panic. + --> $DIR/simple_conditionals.rs:25:9 + | +LL | if x.is_err() { + | ---------- because of this check +LL | 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/simple_conditionals.rs:26:9 + | +LL | if x.is_err() { + | ---------- the check is happening here +LL | x.unwrap(); // will panic +LL | 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/simple_conditionals.rs:28:9 + | +LL | if x.is_err() { + | ---------- the check is happening here +... +LL | x.unwrap(); // unnecessary + | ^^^^^^^^^^ + +error: This call to `unwrap_err()` will always panic. + --> $DIR/simple_conditionals.rs:29:9 + | +LL | if x.is_err() { + | ---------- because of this check +... +LL | x.unwrap_err(); // will panic + | ^^^^^^^^^^^^^^ + +error: aborting due to 12 previous errors + diff --git a/tests/ui/cognitive_complexity.rs b/tests/ui/cognitive_complexity.rs index 4e4016e78c2a..a1f1c586eb0b 100644 --- a/tests/ui/cognitive_complexity.rs +++ b/tests/ui/cognitive_complexity.rs @@ -313,7 +313,7 @@ fn mcarton_sees_all() { } #[clippy::cognitive_complexity = "0"] -fn try() -> Result { +fn try_() -> Result { match 5 { 5 => Ok(5), _ => return Err("bla"), @@ -322,14 +322,14 @@ fn try() -> Result { #[clippy::cognitive_complexity = "0"] fn try_again() -> Result { - let _ = try!(Ok(42)); - let _ = try!(Ok(43)); - let _ = try!(Ok(44)); - let _ = try!(Ok(45)); - let _ = try!(Ok(46)); - let _ = try!(Ok(47)); - let _ = try!(Ok(48)); - let _ = try!(Ok(49)); + let _ = r#try!(Ok(42)); + let _ = r#try!(Ok(43)); + let _ = r#try!(Ok(44)); + let _ = r#try!(Ok(45)); + let _ = r#try!(Ok(46)); + let _ = r#try!(Ok(47)); + let _ = r#try!(Ok(48)); + let _ = r#try!(Ok(49)); match 5 { 5 => Ok(5), _ => return Err("bla"), diff --git a/tests/ui/cognitive_complexity.stderr b/tests/ui/cognitive_complexity.stderr index 168653b97116..e1c5863f4942 100644 --- a/tests/ui/cognitive_complexity.stderr +++ b/tests/ui/cognitive_complexity.stderr @@ -216,7 +216,7 @@ LL | | } error: the function has a cognitive complexity of 1 --> $DIR/cognitive_complexity.rs:316:1 | -LL | / fn try() -> Result { +LL | / fn try_() -> Result { LL | | match 5 { LL | | 5 => Ok(5), LL | | _ => return Err("bla"), @@ -230,9 +230,9 @@ error: the function has a cognitive complexity of 1 --> $DIR/cognitive_complexity.rs:324:1 | LL | / fn try_again() -> Result { -LL | | let _ = try!(Ok(42)); -LL | | let _ = try!(Ok(43)); -LL | | let _ = try!(Ok(44)); +LL | | let _ = r#try!(Ok(42)); +LL | | let _ = r#try!(Ok(43)); +LL | | let _ = r#try!(Ok(44)); ... | LL | | } LL | | } diff --git a/tests/ui/cstring.stderr b/tests/ui/cstring.stderr index a2fc07d4af0d..8c86249dc845 100644 --- a/tests/ui/cstring.stderr +++ b/tests/ui/cstring.stderr @@ -4,7 +4,7 @@ error: you are getting the inner pointer of a temporary `CString` LL | CString::new("foo").unwrap().as_ptr(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: #[deny(clippy::temporary_cstring_as_ptr)] on by default + = note: `#[deny(clippy::temporary_cstring_as_ptr)]` on by default = note: that pointer will be invalid outside this expression help: assign the `CString` to a variable to extend its lifetime --> $DIR/cstring.rs:7:5 diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr index fc87c7d15960..875018961090 100644 --- a/tests/ui/derive.stderr +++ b/tests/ui/derive.stderr @@ -4,7 +4,7 @@ error: you are deriving `Hash` but have implemented `PartialEq` explicitly LL | #[derive(Hash)] | ^^^^ | - = note: #[deny(clippy::derive_hash_xor_eq)] on by default + = note: `#[deny(clippy::derive_hash_xor_eq)]` on by default note: `PartialEq` implemented here --> $DIR/derive.rs:19:1 | diff --git a/tests/ui/dlist.rs b/tests/ui/dlist.rs index 5af79f9c58ed..2940d2d29011 100644 --- a/tests/ui/dlist.rs +++ b/tests/ui/dlist.rs @@ -7,7 +7,7 @@ use alloc::collections::linked_list::LinkedList; trait Foo { type Baz = LinkedList; - fn foo(LinkedList); + fn foo(_: LinkedList); const BAR: Option>; } diff --git a/tests/ui/dlist.stderr b/tests/ui/dlist.stderr index e4712e5d07f8..1f6646ec9ade 100644 --- a/tests/ui/dlist.stderr +++ b/tests/ui/dlist.stderr @@ -8,10 +8,10 @@ LL | type Baz = LinkedList; = help: a VecDeque might work error: I see you're using a LinkedList! Perhaps you meant some other data structure? - --> $DIR/dlist.rs:10:12 + --> $DIR/dlist.rs:10:15 | -LL | fn foo(LinkedList); - | ^^^^^^^^^^^^^^ +LL | fn foo(_: LinkedList); + | ^^^^^^^^^^^^^^ | = help: a VecDeque might work diff --git a/tests/ui/doc.rs b/tests/ui/doc.rs index 039ce5d9c423..77620c857e66 100644 --- a/tests/ui/doc.rs +++ b/tests/ui/doc.rs @@ -178,3 +178,7 @@ fn issue_2210() {} /// This should not cause the lint to trigger: /// #REQ-data-family.lint_partof_exists fn issue_2343() {} + +/// This should not cause an ICE: +/// __|_ _|__||_| +fn pulldown_cmark_crash() {} diff --git a/tests/ui/drop_bounds.stderr b/tests/ui/drop_bounds.stderr index cc87913ecb1a..5d360ef30a1d 100644 --- a/tests/ui/drop_bounds.stderr +++ b/tests/ui/drop_bounds.stderr @@ -4,7 +4,7 @@ error: Bounds of the form `T: Drop` are useless. Use `std::mem::needs_drop` to d LL | fn foo() {} | ^^^^ | - = note: #[deny(clippy::drop_bounds)] on by default + = note: `#[deny(clippy::drop_bounds)]` on by default error: Bounds of the form `T: Drop` are useless. Use `std::mem::needs_drop` to detect if a type has drop glue. --> $DIR/drop_bounds.rs:5:8 diff --git a/tests/ui/for_loop_over_option_result.stderr b/tests/ui/for_loop_over_option_result.stderr index 5414bfcf9de5..194a0bfec5b3 100644 --- a/tests/ui/for_loop_over_option_result.stderr +++ b/tests/ui/for_loop_over_option_result.stderr @@ -30,7 +30,7 @@ error: you are iterating over `Iterator::next()` which is an Option; this will c LL | for x in v.iter().next() { | ^^^^^^^^^^^^^^^ | - = note: #[deny(clippy::iter_next_loop)] on by default + = note: `#[deny(clippy::iter_next_loop)]` on by default error: for loop over `v.iter().next().and(Some(0))`, which is an `Option`. This is more readably written as an `if let` statement. --> $DIR/for_loop_over_option_result.rs:31:14 @@ -57,7 +57,7 @@ LL | | break; LL | | } | |_____^ | - = note: #[deny(clippy::never_loop)] on by default + = note: `#[deny(clippy::never_loop)]` on by default error: this loop never actually loops --> $DIR/for_loop_over_option_result.rs:53:5 diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs index d1213e5e5fda..f9923c9bb480 100644 --- a/tests/ui/if_same_then_else.rs +++ b/tests/ui/if_same_then_else.rs @@ -215,10 +215,10 @@ fn if_same_then_else() -> Result<&'static str, ()> { }; if true { - try!(Ok("foo")); + r#try!(Ok("foo")); } else { //~ ERROR same body as `if` block - try!(Ok("foo")); + r#try!(Ok("foo")); } if true { diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr index fa42afff0be0..9649c2232932 100644 --- a/tests/ui/if_same_then_else.stderr +++ b/tests/ui/if_same_then_else.stderr @@ -197,7 +197,7 @@ error: this `if` has identical blocks LL | } else { | ____________^ LL | | //~ ERROR same body as `if` block -LL | | try!(Ok("foo")); +LL | | r#try!(Ok("foo")); LL | | } | |_____^ | @@ -206,7 +206,7 @@ note: same as this | LL | if true { | _____________^ -LL | | try!(Ok("foo")); +LL | | r#try!(Ok("foo")); LL | | } else { | |_____^ @@ -236,7 +236,7 @@ error: this `if` has the same condition as a previous if LL | } else if true { | ^^^^ | - = note: #[deny(clippy::ifs_same_cond)] on by default + = note: `#[deny(clippy::ifs_same_cond)]` on by default note: same as this --> $DIR/if_same_then_else.rs:235:8 | diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs index d1c63ca1697c..47e0679c430d 100644 --- a/tests/ui/implicit_return.rs +++ b/tests/ui/implicit_return.rs @@ -5,6 +5,7 @@ fn test_end_of_fn() -> bool { // no error! return true; } + true } @@ -76,6 +77,14 @@ fn test_closure() { let _ = || true; } +fn test_panic() -> bool { + panic!() +} + +fn test_return_macro() -> String { + format!("test {}", "test") +} + fn main() { let _ = test_end_of_fn(); let _ = test_if_block(); @@ -86,4 +95,5 @@ fn main() { let _ = test_loop_with_nests(); let _ = test_loop_with_if_let(); test_closure(); + let _ = test_return_macro(); } diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 98b588f1a74a..41b0873317e8 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -1,5 +1,5 @@ error: missing return statement - --> $DIR/implicit_return.rs:8:5 + --> $DIR/implicit_return.rs:9:5 | LL | true | ^^^^ help: add `return` as shown: `return true` @@ -7,58 +7,64 @@ LL | true = note: `-D clippy::implicit-return` implied by `-D warnings` error: missing return statement - --> $DIR/implicit_return.rs:14:9 + --> $DIR/implicit_return.rs:15:9 | LL | true | ^^^^ help: add `return` as shown: `return true` error: missing return statement - --> $DIR/implicit_return.rs:16:9 + --> $DIR/implicit_return.rs:17:9 | LL | false | ^^^^^ help: add `return` as shown: `return false` error: missing return statement - --> $DIR/implicit_return.rs:24:17 + --> $DIR/implicit_return.rs:25:17 | LL | true => false, | ^^^^^ help: add `return` as shown: `return false` error: missing return statement - --> $DIR/implicit_return.rs:25:20 + --> $DIR/implicit_return.rs:26:20 | LL | false => { true }, | ^^^^ help: add `return` as shown: `return true` error: missing return statement - --> $DIR/implicit_return.rs:40:9 + --> $DIR/implicit_return.rs:41:9 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing return statement - --> $DIR/implicit_return.rs:48:13 + --> $DIR/implicit_return.rs:49:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing return statement - --> $DIR/implicit_return.rs:57:13 + --> $DIR/implicit_return.rs:58:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing return statement - --> $DIR/implicit_return.rs:75:18 + --> $DIR/implicit_return.rs:76:18 | LL | let _ = || { true }; | ^^^^ help: add `return` as shown: `return true` error: missing return statement - --> $DIR/implicit_return.rs:76:16 + --> $DIR/implicit_return.rs:77:16 | LL | let _ = || true; | ^^^^ help: add `return` as shown: `return true` -error: aborting due to 10 previous errors +error: missing return statement + --> $DIR/implicit_return.rs:85:5 + | +LL | format!("test {}", "test") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")` + +error: aborting due to 11 previous errors diff --git a/tests/ui/indexing_slicing.rs b/tests/ui/indexing_slicing.rs index f0bd39c02542..8dd6ae146251 100644 --- a/tests/ui/indexing_slicing.rs +++ b/tests/ui/indexing_slicing.rs @@ -1,5 +1,7 @@ #![feature(plugin)] #![warn(clippy::indexing_slicing)] +// We also check the out_of_bounds_indexing lint here, because it lints similar things and +// we want to avoid false positives. #![warn(clippy::out_of_bounds_indexing)] #![allow(clippy::no_effect, clippy::unnecessary_operation)] @@ -15,21 +17,10 @@ fn main() { &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - &x[..=4]; - &x[1..5]; - &x[5..][..10]; // Two lint reports, one for [5..] and another for [..10]. - &x[5..]; - &x[..5]; - &x[5..].iter().map(|x| 2 * x).collect::>(); - &x[0..=4]; + &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. &x[0..][..3]; &x[1..][..5]; - &x[4..]; // Ok, should not produce stderr. - &x[..4]; // Ok, should not produce stderr. - &x[..]; // Ok, should not produce stderr. - &x[1..]; // Ok, should not produce stderr. - &x[2..].iter().map(|x| 2 * x).collect::>(); // Ok, should not produce stderr. &x[0..].get(..3); // Ok, should not produce stderr. x[0]; // Ok, should not produce stderr. x[3]; // Ok, should not produce stderr. @@ -43,21 +34,6 @@ fn main() { &y[..]; // Ok, should not produce stderr. - let empty: [i8; 0] = []; - empty[0]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - &empty[1..5]; - &empty[0..=4]; - &empty[..=4]; - &empty[1..]; - &empty[..4]; - &empty[0..=0]; - &empty[..=0]; - - &empty[0..]; // Ok, should not produce stderr. - &empty[0..0]; // Ok, should not produce stderr. - &empty[..0]; // Ok, should not produce stderr. - &empty[..]; // Ok, should not produce stderr. - let v = vec![0; 5]; v[0]; v[10]; @@ -79,9 +55,4 @@ fn main() { x[M]; // Ok, should not produce stderr. v[N]; v[M]; - - // issue 3102 - let num = 1; - &x[num..10]; // should trigger out of bounds error - &x[10..num]; // should trigger out of bounds error } diff --git a/tests/ui/indexing_slicing.stderr b/tests/ui/indexing_slicing.stderr index 129fec0e97c1..b2840f7b5ccc 100644 --- a/tests/ui/indexing_slicing.stderr +++ b/tests/ui/indexing_slicing.stderr @@ -1,31 +1,25 @@ error: index out of bounds: the len is 4 but the index is 4 - --> $DIR/indexing_slicing.rs:16:5 + --> $DIR/indexing_slicing.rs:18:5 | LL | x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. | ^^^^ | - = note: #[deny(const_err)] on by default + = note: `#[deny(const_err)]` on by default error: index out of bounds: the len is 4 but the index is 8 - --> $DIR/indexing_slicing.rs:17:5 + --> $DIR/indexing_slicing.rs:19:5 | LL | x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. | ^^^^^^^^^ -error: index out of bounds: the len is 0 but the index is 0 - --> $DIR/indexing_slicing.rs:47:5 - | -LL | empty[0]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - | ^^^^^^^^ - error: index out of bounds: the len is 4 but the index is 15 - --> $DIR/indexing_slicing.rs:78:5 + --> $DIR/indexing_slicing.rs:54:5 | LL | x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. | ^^^^ error: indexing may panic. - --> $DIR/indexing_slicing.rs:11:5 + --> $DIR/indexing_slicing.rs:13:5 | LL | x[index]; | ^^^^^^^^ @@ -34,7 +28,7 @@ LL | x[index]; = help: Consider using `.get(n)` or `.get_mut(n)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:12:6 + --> $DIR/indexing_slicing.rs:14:6 | LL | &x[index..]; | ^^^^^^^^^^ @@ -42,7 +36,7 @@ LL | &x[index..]; = help: Consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:13:6 + --> $DIR/indexing_slicing.rs:15:6 | LL | &x[..index]; | ^^^^^^^^^^ @@ -50,7 +44,7 @@ LL | &x[..index]; = help: Consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:14:6 + --> $DIR/indexing_slicing.rs:16:6 | LL | &x[index_from..index_to]; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -58,7 +52,7 @@ LL | &x[index_from..index_to]; = help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:15:6 + --> $DIR/indexing_slicing.rs:17:6 | LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -66,31 +60,17 @@ LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from. = help: Consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:15:6 + --> $DIR/indexing_slicing.rs:17:6 | LL | &x[index_from..][..index_to]; // Two lint reports, one for [index_from..] and another for [..index_to]. | ^^^^^^^^^^^^^^^ | = help: Consider using `.get(n..)` or .get_mut(n..)` instead -error: range is out of bounds - --> $DIR/indexing_slicing.rs:18:11 - | -LL | &x[..=4]; - | ^ - | - = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:19:11 - | -LL | &x[1..5]; - | ^ - error: slicing may panic. --> $DIR/indexing_slicing.rs:20:6 | -LL | &x[5..][..10]; // Two lint reports, one for [5..] and another for [..10]. +LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. | ^^^^^^^^^^^^ | = help: Consider using `.get(..n)`or `.get_mut(..n)` instead @@ -98,35 +78,13 @@ LL | &x[5..][..10]; // Two lint reports, one for [5..] and another for [..10 error: range is out of bounds --> $DIR/indexing_slicing.rs:20:8 | -LL | &x[5..][..10]; // Two lint reports, one for [5..] and another for [..10]. +LL | &x[5..][..10]; // Two lint reports, one for out of bounds [5..] and another for slicing [..10]. | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:21:8 - | -LL | &x[5..]; - | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:22:10 - | -LL | &x[..5]; - | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:23:8 - | -LL | &x[5..].iter().map(|x| 2 * x).collect::>(); - | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:24:12 | -LL | &x[0..=4]; - | ^ + = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` error: slicing may panic. - --> $DIR/indexing_slicing.rs:25:6 + --> $DIR/indexing_slicing.rs:21:6 | LL | &x[0..][..3]; | ^^^^^^^^^^^ @@ -134,7 +92,7 @@ LL | &x[0..][..3]; = help: Consider using `.get(..n)`or `.get_mut(..n)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:26:6 + --> $DIR/indexing_slicing.rs:22:6 | LL | &x[1..][..5]; | ^^^^^^^^^^^ @@ -142,7 +100,7 @@ LL | &x[1..][..5]; = help: Consider using `.get(..n)`or `.get_mut(..n)` instead error: indexing may panic. - --> $DIR/indexing_slicing.rs:39:5 + --> $DIR/indexing_slicing.rs:30:5 | LL | y[0]; | ^^^^ @@ -150,7 +108,7 @@ LL | y[0]; = help: Consider using `.get(n)` or `.get_mut(n)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:40:6 + --> $DIR/indexing_slicing.rs:31:6 | LL | &y[1..2]; | ^^^^^^^ @@ -158,7 +116,7 @@ LL | &y[1..2]; = help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:41:6 + --> $DIR/indexing_slicing.rs:32:6 | LL | &y[0..=4]; | ^^^^^^^^ @@ -166,57 +124,15 @@ LL | &y[0..=4]; = help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:42:6 + --> $DIR/indexing_slicing.rs:33:6 | LL | &y[..=4]; | ^^^^^^^ | = help: Consider using `.get(..n)`or `.get_mut(..n)` instead -error: range is out of bounds - --> $DIR/indexing_slicing.rs:48:12 - | -LL | &empty[1..5]; - | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:49:16 - | -LL | &empty[0..=4]; - | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:50:15 - | -LL | &empty[..=4]; - | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:51:12 - | -LL | &empty[1..]; - | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:52:14 - | -LL | &empty[..4]; - | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:53:16 - | -LL | &empty[0..=0]; - | ^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:54:15 - | -LL | &empty[..=0]; - | ^ - error: indexing may panic. - --> $DIR/indexing_slicing.rs:62:5 + --> $DIR/indexing_slicing.rs:38:5 | LL | v[0]; | ^^^^ @@ -224,7 +140,7 @@ LL | v[0]; = help: Consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic. - --> $DIR/indexing_slicing.rs:63:5 + --> $DIR/indexing_slicing.rs:39:5 | LL | v[10]; | ^^^^^ @@ -232,7 +148,7 @@ LL | v[10]; = help: Consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic. - --> $DIR/indexing_slicing.rs:64:5 + --> $DIR/indexing_slicing.rs:40:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -240,7 +156,7 @@ LL | v[1 << 3]; = help: Consider using `.get(n)` or `.get_mut(n)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:65:6 + --> $DIR/indexing_slicing.rs:41:6 | LL | &v[10..100]; | ^^^^^^^^^^ @@ -248,7 +164,7 @@ LL | &v[10..100]; = help: Consider using `.get(n..m)` or `.get_mut(n..m)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:66:6 + --> $DIR/indexing_slicing.rs:42:6 | LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. | ^^^^^^^^^^^^^^ @@ -256,13 +172,13 @@ LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [. = help: Consider using `.get(..n)`or `.get_mut(..n)` instead error: range is out of bounds - --> $DIR/indexing_slicing.rs:66:8 + --> $DIR/indexing_slicing.rs:42:8 | LL | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100]. | ^^ error: slicing may panic. - --> $DIR/indexing_slicing.rs:67:6 + --> $DIR/indexing_slicing.rs:43:6 | LL | &v[10..]; | ^^^^^^^ @@ -270,7 +186,7 @@ LL | &v[10..]; = help: Consider using `.get(n..)` or .get_mut(n..)` instead error: slicing may panic. - --> $DIR/indexing_slicing.rs:68:6 + --> $DIR/indexing_slicing.rs:44:6 | LL | &v[..100]; | ^^^^^^^^ @@ -278,7 +194,7 @@ LL | &v[..100]; = help: Consider using `.get(..n)`or `.get_mut(..n)` instead error: indexing may panic. - --> $DIR/indexing_slicing.rs:80:5 + --> $DIR/indexing_slicing.rs:56:5 | LL | v[N]; | ^^^^ @@ -286,24 +202,12 @@ LL | v[N]; = help: Consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic. - --> $DIR/indexing_slicing.rs:81:5 + --> $DIR/indexing_slicing.rs:57:5 | LL | v[M]; | ^^^^ | = help: Consider using `.get(n)` or `.get_mut(n)` instead -error: range is out of bounds - --> $DIR/indexing_slicing.rs:85:13 - | -LL | &x[num..10]; // should trigger out of bounds error - | ^^ - -error: range is out of bounds - --> $DIR/indexing_slicing.rs:86:8 - | -LL | &x[10..num]; // should trigger out of bounds error - | ^^ - -error: aborting due to 43 previous errors +error: aborting due to 27 previous errors diff --git a/tests/ui/infinite_iter.stderr b/tests/ui/infinite_iter.stderr index 564c2b43778b..ec30a54d3817 100644 --- a/tests/ui/infinite_iter.stderr +++ b/tests/ui/infinite_iter.stderr @@ -111,7 +111,7 @@ error: infinite iteration detected LL | let _: HashSet = (0..).collect(); // Infinite iter | ^^^^^^^^^^^^^^^ | - = note: #[deny(clippy::infinite_iter)] on by default + = note: `#[deny(clippy::infinite_iter)]` on by default error: aborting due to 15 previous errors diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index a3fc591c1b16..6f0332fa8c4a 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -4,7 +4,7 @@ error: Variable in the condition are not mutated in the loop body. This either l LL | while y < 10 { | ^^^^^^ | - = note: #[deny(clippy::while_immutable_condition)] on by default + = note: `#[deny(clippy::while_immutable_condition)]` on by default error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop. --> $DIR/infinite_loop.rs:28:11 diff --git a/tests/ui/inherent_to_string.rs b/tests/ui/inherent_to_string.rs new file mode 100644 index 000000000000..fc21b5cbc3f1 --- /dev/null +++ b/tests/ui/inherent_to_string.rs @@ -0,0 +1,84 @@ +#![warn(clippy::inherent_to_string)] +#![deny(clippy::inherent_to_string_shadow_display)] + +use std::fmt; + +trait FalsePositive { + fn to_string(&self) -> String; +} + +struct A; +struct B; +struct C; +struct D; +struct E; + +impl A { + // Should be detected; emit warning + fn to_string(&self) -> String { + "A.to_string()".to_string() + } + + // Should not be detected as it does not match the function signature + fn to_str(&self) -> String { + "A.to_str()".to_string() + } +} + +// Should not be detected as it is a free function +fn to_string() -> String { + "free to_string()".to_string() +} + +impl B { + // Should not be detected, wrong return type + fn to_string(&self) -> i32 { + 42 + } +} + +impl C { + // Should be detected and emit error as C also implements Display + fn to_string(&self) -> String { + "C.to_string()".to_string() + } +} + +impl fmt::Display for C { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "impl Display for C") + } +} + +impl FalsePositive for D { + // Should not be detected, as it is a trait function + fn to_string(&self) -> String { + "impl FalsePositive for D".to_string() + } +} + +impl E { + // Should not be detected, as it is not bound to an instance + fn to_string() -> String { + "E::to_string()".to_string() + } +} + +fn main() { + let a = A; + a.to_string(); + a.to_str(); + + to_string(); + + let b = B; + b.to_string(); + + let c = C; + C.to_string(); + + let d = D; + d.to_string(); + + E::to_string(); +} diff --git a/tests/ui/inherent_to_string.stderr b/tests/ui/inherent_to_string.stderr new file mode 100644 index 000000000000..5252a168830a --- /dev/null +++ b/tests/ui/inherent_to_string.stderr @@ -0,0 +1,28 @@ +error: implementation of inherent method `to_string(&self) -> String` for type `A` + --> $DIR/inherent_to_string.rs:18:5 + | +LL | / fn to_string(&self) -> String { +LL | | "A.to_string()".to_string() +LL | | } + | |_____^ + | + = note: `-D clippy::inherent-to-string` implied by `-D warnings` + = help: implement trait `Display` for type `A` instead + +error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display` + --> $DIR/inherent_to_string.rs:42:5 + | +LL | / fn to_string(&self) -> String { +LL | | "C.to_string()".to_string() +LL | | } + | |_____^ + | +note: lint level defined here + --> $DIR/inherent_to_string.rs:2:9 + | +LL | #![deny(clippy::inherent_to_string_shadow_display)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: remove the inherent method from type `C` + +error: aborting due to 2 previous errors + diff --git a/tests/ui/invalid_ref.stderr b/tests/ui/invalid_ref.stderr index 42a11fe7e5d2..aeef3892dbe7 100644 --- a/tests/ui/invalid_ref.stderr +++ b/tests/ui/invalid_ref.stderr @@ -4,7 +4,7 @@ error: reference to zeroed memory LL | let ref_zero: &T = std::mem::zeroed(); // warning | ^^^^^^^^^^^^^^^^^^ | - = note: #[deny(clippy::invalid_ref)] on by default + = note: `#[deny(clippy::invalid_ref)]` on by default = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html error: reference to zeroed memory diff --git a/tests/ui/issue-3145.stderr b/tests/ui/issue-3145.stderr index f3984f991a45..cb0d95f5e264 100644 --- a/tests/ui/issue-3145.stderr +++ b/tests/ui/issue-3145.stderr @@ -2,7 +2,7 @@ error: expected token: `,` --> $DIR/issue-3145.rs:2:19 | LL | println!("{}" a); //~ERROR expected token: `,` - | ^ + | ^ expected `,` error: aborting due to previous error diff --git a/tests/ui/issue_4266.rs b/tests/ui/issue_4266.rs new file mode 100644 index 000000000000..953879f7bed0 --- /dev/null +++ b/tests/ui/issue_4266.rs @@ -0,0 +1,38 @@ +// compile-flags: --edition 2018 +#![feature(async_await)] +#![allow(dead_code)] + +async fn sink1<'a>(_: &'a str) {} // lint +async fn sink1_elided(_: &str) {} // ok + +// lint +async fn one_to_one<'a>(s: &'a str) -> &'a str { + s +} + +// ok +async fn one_to_one_elided(s: &str) -> &str { + s +} + +// ok +async fn all_to_one<'a>(a: &'a str, _b: &'a str) -> &'a str { + a +} + +// async fn unrelated(_: &str, _: &str) {} // Not allowed in async fn + +// #3988 +struct Foo; +impl Foo { + // ok + pub async fn foo(&mut self) {} +} + +// rust-lang/rust#61115 +// ok +async fn print(s: &str) { + println!("{}", s); +} + +fn main() {} diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr new file mode 100644 index 000000000000..8b4e70eb9c22 --- /dev/null +++ b/tests/ui/issue_4266.stderr @@ -0,0 +1,18 @@ +error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) + --> $DIR/issue_4266.rs:5:1 + | +LL | async fn sink1<'a>(_: &'a str) {} // lint + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::needless-lifetimes` implied by `-D warnings` + +error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) + --> $DIR/issue_4266.rs:9:1 + | +LL | / async fn one_to_one<'a>(s: &'a str) -> &'a str { +LL | | s +LL | | } + | |_^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lint_without_lint_pass.stderr b/tests/ui/lint_without_lint_pass.stderr index 9d0b0d627898..0559cee70efb 100644 --- a/tests/ui/lint_without_lint_pass.stderr +++ b/tests/ui/lint_without_lint_pass.stderr @@ -13,7 +13,7 @@ note: lint level defined here | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ - = note: #[deny(clippy::lint_without_lint_pass)] implied by #[deny(clippy::internal)] + = note: `#[deny(clippy::lint_without_lint_pass)]` implied by `#[deny(clippy::internal)]` = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to previous error diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index 193e6c17238b..5c65d2fed3da 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -83,7 +83,7 @@ error: equal expressions as operands to `&&` LL | match test && test { | ^^^^^^^^^^^^ | - = note: #[deny(clippy::eq_op)] on by default + = note: `#[deny(clippy::eq_op)]` on by default error: you seem to be trying to match on a boolean expression --> $DIR/match_bool.rs:36:5 diff --git a/tests/ui/match_ref_pats.rs b/tests/ui/match_ref_pats.rs new file mode 100644 index 000000000000..d26b59db91bc --- /dev/null +++ b/tests/ui/match_ref_pats.rs @@ -0,0 +1,73 @@ +#![warn(clippy::match_ref_pats)] + +fn ref_pats() { + { + let v = &Some(0); + match v { + &Some(v) => println!("{:?}", v), + &None => println!("none"), + } + match v { + // This doesn't trigger; we have a different pattern. + &Some(v) => println!("some"), + other => println!("other"), + } + } + let tup = &(1, 2); + match tup { + &(v, 1) => println!("{}", v), + _ => println!("none"), + } + // Special case: using `&` both in expr and pats. + let w = Some(0); + match &w { + &Some(v) => println!("{:?}", v), + &None => println!("none"), + } + // False positive: only wildcard pattern. + let w = Some(0); + match w { + _ => println!("none"), + } + + let a = &Some(0); + if let &None = a { + println!("none"); + } + + let b = Some(0); + if let &None = &b { + println!("none"); + } +} + +mod ice_3719 { + macro_rules! foo_variant( + ($idx:expr) => (Foo::get($idx).unwrap()) + ); + + enum Foo { + A, + B, + } + + impl Foo { + fn get(idx: u8) -> Option<&'static Self> { + match idx { + 0 => Some(&Foo::A), + 1 => Some(&Foo::B), + _ => None, + } + } + } + + fn ice_3719() { + // ICE #3719 + match foo_variant!(0) { + &Foo::A => println!("A"), + _ => println!("Wild"), + } + } +} + +fn main() {} diff --git a/tests/ui/match_ref_pats.stderr b/tests/ui/match_ref_pats.stderr new file mode 100644 index 000000000000..80e862c8ea9e --- /dev/null +++ b/tests/ui/match_ref_pats.stderr @@ -0,0 +1,86 @@ +error: you don't need to add `&` to all patterns + --> $DIR/match_ref_pats.rs:6:9 + | +LL | / match v { +LL | | &Some(v) => println!("{:?}", v), +LL | | &None => println!("none"), +LL | | } + | |_________^ + | + = note: `-D clippy::match-ref-pats` implied by `-D warnings` +help: instead of prefixing all patterns with `&`, you can dereference the expression + | +LL | match *v { +LL | Some(v) => println!("{:?}", v), +LL | None => println!("none"), + | + +error: you don't need to add `&` to all patterns + --> $DIR/match_ref_pats.rs:17:5 + | +LL | / match tup { +LL | | &(v, 1) => println!("{}", v), +LL | | _ => println!("none"), +LL | | } + | |_____^ +help: instead of prefixing all patterns with `&`, you can dereference the expression + | +LL | match *tup { +LL | (v, 1) => println!("{}", v), + | + +error: you don't need to add `&` to both the expression and the patterns + --> $DIR/match_ref_pats.rs:23:5 + | +LL | / match &w { +LL | | &Some(v) => println!("{:?}", v), +LL | | &None => println!("none"), +LL | | } + | |_____^ +help: try + | +LL | match w { +LL | Some(v) => println!("{:?}", v), +LL | None => println!("none"), + | + +error: you don't need to add `&` to all patterns + --> $DIR/match_ref_pats.rs:34:5 + | +LL | / if let &None = a { +LL | | println!("none"); +LL | | } + | |_____^ +help: instead of prefixing all patterns with `&`, you can dereference the expression + | +LL | if let None = *a { + | ^^^^ ^^ + +error: you don't need to add `&` to both the expression and the patterns + --> $DIR/match_ref_pats.rs:39:5 + | +LL | / if let &None = &b { +LL | | println!("none"); +LL | | } + | |_____^ +help: try + | +LL | if let None = b { + | ^^^^ ^ + +error: you don't need to add `&` to all patterns + --> $DIR/match_ref_pats.rs:66:9 + | +LL | / match foo_variant!(0) { +LL | | &Foo::A => println!("A"), +LL | | _ => println!("Wild"), +LL | | } + | |_________^ +help: instead of prefixing all patterns with `&`, you can dereference the expression + | +LL | match *foo_variant!(0) { +LL | Foo::A => println!("A"), + | + +error: aborting due to 6 previous errors + diff --git a/tests/ui/matches.rs b/tests/ui/matches.rs index 0360cc739c81..44725db97f7f 100644 --- a/tests/ui/matches.rs +++ b/tests/ui/matches.rs @@ -5,47 +5,6 @@ fn dummy() {} -fn ref_pats() { - { - let v = &Some(0); - match v { - &Some(v) => println!("{:?}", v), - &None => println!("none"), - } - match v { - // This doesn't trigger; we have a different pattern. - &Some(v) => println!("some"), - other => println!("other"), - } - } - let tup = &(1, 2); - match tup { - &(v, 1) => println!("{}", v), - _ => println!("none"), - } - // Special case: using `&` both in expr and pats. - let w = Some(0); - match &w { - &Some(v) => println!("{:?}", v), - &None => println!("none"), - } - // False positive: only wildcard pattern. - let w = Some(0); - match w { - _ => println!("none"), - } - - let a = &Some(0); - if let &None = a { - println!("none"); - } - - let b = Some(0); - if let &None = &b { - println!("none"); - } -} - fn match_wild_err_arm() { let x: Result = Ok(3); @@ -136,29 +95,4 @@ fn match_wild_err_arm() { } } -macro_rules! foo_variant( - ($idx:expr) => (Foo::get($idx).unwrap()) -); - -enum Foo { - A, - B, -} - -impl Foo { - fn get(idx: u8) -> Option<&'static Self> { - match idx { - 0 => Some(&Foo::A), - 1 => Some(&Foo::B), - _ => None, - } - } -} - -fn main() { - // ICE #3719 - match foo_variant!(0) { - &Foo::A => println!("A"), - _ => println!("Wild"), - } -} +fn main() {} diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr index 232ae28009b6..f47e976e8cc4 100644 --- a/tests/ui/matches.stderr +++ b/tests/ui/matches.stderr @@ -1,75 +1,5 @@ -error: you don't need to add `&` to all patterns - --> $DIR/matches.rs:11:9 - | -LL | / match v { -LL | | &Some(v) => println!("{:?}", v), -LL | | &None => println!("none"), -LL | | } - | |_________^ - | - = note: `-D clippy::match-ref-pats` implied by `-D warnings` -help: instead of prefixing all patterns with `&`, you can dereference the expression - | -LL | match *v { -LL | Some(v) => println!("{:?}", v), -LL | None => println!("none"), - | - -error: you don't need to add `&` to all patterns - --> $DIR/matches.rs:22:5 - | -LL | / match tup { -LL | | &(v, 1) => println!("{}", v), -LL | | _ => println!("none"), -LL | | } - | |_____^ -help: instead of prefixing all patterns with `&`, you can dereference the expression - | -LL | match *tup { -LL | (v, 1) => println!("{}", v), - | - -error: you don't need to add `&` to both the expression and the patterns - --> $DIR/matches.rs:28:5 - | -LL | / match &w { -LL | | &Some(v) => println!("{:?}", v), -LL | | &None => println!("none"), -LL | | } - | |_____^ -help: try - | -LL | match w { -LL | Some(v) => println!("{:?}", v), -LL | None => println!("none"), - | - -error: you don't need to add `&` to all patterns - --> $DIR/matches.rs:39:5 - | -LL | / if let &None = a { -LL | | println!("none"); -LL | | } - | |_____^ -help: instead of prefixing all patterns with `&`, you can dereference the expression - | -LL | if let None = *a { - | ^^^^ ^^ - -error: you don't need to add `&` to both the expression and the patterns - --> $DIR/matches.rs:44:5 - | -LL | / if let &None = &b { -LL | | println!("none"); -LL | | } - | |_____^ -help: try - | -LL | if let None = b { - | ^^^^ ^ - error: Err(_) will match all errors, maybe not a good idea - --> $DIR/matches.rs:55:9 + --> $DIR/matches.rs:14:9 | LL | Err(_) => panic!("err"), | ^^^^^^ @@ -78,26 +8,26 @@ LL | Err(_) => panic!("err"), = note: to remove this warning, match each error separately or use unreachable macro error: this `match` has identical arm bodies - --> $DIR/matches.rs:54:18 + --> $DIR/matches.rs:13:18 | LL | Ok(_) => println!("ok"), | ^^^^^^^^^^^^^^ | = note: `-D clippy::match-same-arms` implied by `-D warnings` note: same as this - --> $DIR/matches.rs:53:18 + --> $DIR/matches.rs:12:18 | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ help: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:53:9 + --> $DIR/matches.rs:12:9 | LL | Ok(3) => println!("ok"), | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: Err(_) will match all errors, maybe not a good idea - --> $DIR/matches.rs:61:9 + --> $DIR/matches.rs:20:9 | LL | Err(_) => panic!(), | ^^^^^^ @@ -105,25 +35,25 @@ LL | Err(_) => panic!(), = note: to remove this warning, match each error separately or use unreachable macro error: this `match` has identical arm bodies - --> $DIR/matches.rs:60:18 + --> $DIR/matches.rs:19:18 | LL | Ok(_) => println!("ok"), | ^^^^^^^^^^^^^^ | note: same as this - --> $DIR/matches.rs:59:18 + --> $DIR/matches.rs:18:18 | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ help: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:59:9 + --> $DIR/matches.rs:18:9 | LL | Ok(3) => println!("ok"), | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: Err(_) will match all errors, maybe not a good idea - --> $DIR/matches.rs:67:9 + --> $DIR/matches.rs:26:9 | LL | Err(_) => { | ^^^^^^ @@ -131,144 +61,130 @@ LL | Err(_) => { = note: to remove this warning, match each error separately or use unreachable macro error: this `match` has identical arm bodies - --> $DIR/matches.rs:66:18 + --> $DIR/matches.rs:25:18 | LL | Ok(_) => println!("ok"), | ^^^^^^^^^^^^^^ | note: same as this - --> $DIR/matches.rs:65:18 + --> $DIR/matches.rs:24:18 | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ help: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:65:9 + --> $DIR/matches.rs:24:9 | LL | Ok(3) => println!("ok"), | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies - --> $DIR/matches.rs:75:18 + --> $DIR/matches.rs:34:18 | LL | Ok(_) => println!("ok"), | ^^^^^^^^^^^^^^ | note: same as this - --> $DIR/matches.rs:74:18 + --> $DIR/matches.rs:33:18 | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ help: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:74:9 + --> $DIR/matches.rs:33:9 | LL | Ok(3) => println!("ok"), | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies - --> $DIR/matches.rs:82:18 + --> $DIR/matches.rs:41:18 | LL | Ok(_) => println!("ok"), | ^^^^^^^^^^^^^^ | note: same as this - --> $DIR/matches.rs:81:18 + --> $DIR/matches.rs:40:18 | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ help: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:81:9 + --> $DIR/matches.rs:40:9 | LL | Ok(3) => println!("ok"), | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies - --> $DIR/matches.rs:88:18 + --> $DIR/matches.rs:47:18 | LL | Ok(_) => println!("ok"), | ^^^^^^^^^^^^^^ | note: same as this - --> $DIR/matches.rs:87:18 + --> $DIR/matches.rs:46:18 | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ help: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:87:9 + --> $DIR/matches.rs:46:9 | LL | Ok(3) => println!("ok"), | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies - --> $DIR/matches.rs:94:18 + --> $DIR/matches.rs:53:18 | LL | Ok(_) => println!("ok"), | ^^^^^^^^^^^^^^ | note: same as this - --> $DIR/matches.rs:93:18 + --> $DIR/matches.rs:52:18 | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ help: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:93:9 + --> $DIR/matches.rs:52:9 | LL | Ok(3) => println!("ok"), | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies - --> $DIR/matches.rs:117:29 + --> $DIR/matches.rs:76:29 | LL | (Ok(_), Some(x)) => println!("ok {}", x), | ^^^^^^^^^^^^^^^^^^^^ | note: same as this - --> $DIR/matches.rs:116:29 + --> $DIR/matches.rs:75:29 | LL | (Ok(x), Some(_)) => println!("ok {}", x), | ^^^^^^^^^^^^^^^^^^^^ help: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))` - --> $DIR/matches.rs:116:9 + --> $DIR/matches.rs:75:9 | LL | (Ok(x), Some(_)) => println!("ok {}", x), | ^^^^^^^^^^^^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: this `match` has identical arm bodies - --> $DIR/matches.rs:132:18 + --> $DIR/matches.rs:91:18 | LL | Ok(_) => println!("ok"), | ^^^^^^^^^^^^^^ | note: same as this - --> $DIR/matches.rs:131:18 + --> $DIR/matches.rs:90:18 | LL | Ok(3) => println!("ok"), | ^^^^^^^^^^^^^^ help: consider refactoring into `Ok(3) | Ok(_)` - --> $DIR/matches.rs:131:9 + --> $DIR/matches.rs:90:9 | LL | Ok(3) => println!("ok"), | ^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) -error: you don't need to add `&` to all patterns - --> $DIR/matches.rs:160:5 - | -LL | / match foo_variant!(0) { -LL | | &Foo::A => println!("A"), -LL | | _ => println!("Wild"), -LL | | } - | |_____^ -help: instead of prefixing all patterns with `&`, you can dereference the expression - | -LL | match *foo_variant!(0) { -LL | Foo::A => println!("A"), - | - -error: aborting due to 18 previous errors +error: aborting due to 12 previous errors diff --git a/tests/ui/mistyped_literal_suffix.stderr b/tests/ui/mistyped_literal_suffix.stderr index c3fed6ae8fdc..17c8b3230273 100644 --- a/tests/ui/mistyped_literal_suffix.stderr +++ b/tests/ui/mistyped_literal_suffix.stderr @@ -4,7 +4,7 @@ error: mistyped literal suffix LL | let fail14 = 2_32; | ^^^^ help: did you mean to write: `2_i32` | - = note: #[deny(clippy::mistyped_literal_suffixes)] on by default + = note: `#[deny(clippy::mistyped_literal_suffixes)]` on by default error: mistyped literal suffix --> $DIR/mistyped_literal_suffix.rs:7:18 diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr index 416e14d676e7..c00b4c78cf28 100644 --- a/tests/ui/never_loop.stderr +++ b/tests/ui/never_loop.stderr @@ -10,7 +10,7 @@ LL | | break; LL | | } | |_____^ | - = note: #[deny(clippy::never_loop)] on by default + = note: `#[deny(clippy::never_loop)]` on by default error: this loop never actually loops --> $DIR/never_loop.rs:32:5 diff --git a/tests/ui/non_copy_const.stderr b/tests/ui/non_copy_const.stderr index 1276491127ad..634933eac618 100644 --- a/tests/ui/non_copy_const.stderr +++ b/tests/ui/non_copy_const.stderr @@ -6,7 +6,7 @@ LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable | | | help: make this a static item: `static` | - = note: #[deny(clippy::declare_interior_mutable_const)] on by default + = note: `#[deny(clippy::declare_interior_mutable_const)]` on by default error: a const item should never be interior mutable --> $DIR/non_copy_const.rs:11:1 @@ -132,7 +132,7 @@ error: a const item with interior mutability should not be borrowed LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability | ^^^^^^ | - = note: #[deny(clippy::borrow_interior_mutable_const)] on by default + = note: `#[deny(clippy::borrow_interior_mutable_const)]` on by default = help: assign this const to a local or static variable, and use the variable here error: a const item with interior mutability should not be borrowed diff --git a/tests/ui/out_of_bounds_indexing/empty_array.rs b/tests/ui/out_of_bounds_indexing/empty_array.rs new file mode 100644 index 000000000000..884e46eb4ee1 --- /dev/null +++ b/tests/ui/out_of_bounds_indexing/empty_array.rs @@ -0,0 +1,19 @@ +#![warn(clippy::out_of_bounds_indexing)] +#![allow(clippy::no_effect, clippy::unnecessary_operation)] + +fn main() { + let empty: [i8; 0] = []; + empty[0]; + &empty[1..5]; + &empty[0..=4]; + &empty[..=4]; + &empty[1..]; + &empty[..4]; + &empty[0..=0]; + &empty[..=0]; + + &empty[0..]; // Ok, should not produce stderr. + &empty[0..0]; // Ok, should not produce stderr. + &empty[..0]; // Ok, should not produce stderr. + &empty[..]; // Ok, should not produce stderr. +} diff --git a/tests/ui/out_of_bounds_indexing/empty_array.stderr b/tests/ui/out_of_bounds_indexing/empty_array.stderr new file mode 100644 index 000000000000..cda78a47ec73 --- /dev/null +++ b/tests/ui/out_of_bounds_indexing/empty_array.stderr @@ -0,0 +1,54 @@ +error: index out of bounds: the len is 0 but the index is 0 + --> $DIR/empty_array.rs:6:5 + | +LL | empty[0]; + | ^^^^^^^^ + | + = note: `#[deny(const_err)]` on by default + +error: range is out of bounds + --> $DIR/empty_array.rs:7:12 + | +LL | &empty[1..5]; + | ^ + | + = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + +error: range is out of bounds + --> $DIR/empty_array.rs:8:16 + | +LL | &empty[0..=4]; + | ^ + +error: range is out of bounds + --> $DIR/empty_array.rs:9:15 + | +LL | &empty[..=4]; + | ^ + +error: range is out of bounds + --> $DIR/empty_array.rs:10:12 + | +LL | &empty[1..]; + | ^ + +error: range is out of bounds + --> $DIR/empty_array.rs:11:14 + | +LL | &empty[..4]; + | ^ + +error: range is out of bounds + --> $DIR/empty_array.rs:12:16 + | +LL | &empty[0..=0]; + | ^ + +error: range is out of bounds + --> $DIR/empty_array.rs:13:15 + | +LL | &empty[..=0]; + | ^ + +error: aborting due to 8 previous errors + diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.rs b/tests/ui/out_of_bounds_indexing/issue-3102.rs new file mode 100644 index 000000000000..edd2123d48a5 --- /dev/null +++ b/tests/ui/out_of_bounds_indexing/issue-3102.rs @@ -0,0 +1,11 @@ +#![warn(clippy::out_of_bounds_indexing)] +#![allow(clippy::no_effect)] + +fn main() { + let x = [1, 2, 3, 4]; + + // issue 3102 + let num = 1; + &x[num..10]; // should trigger out of bounds error + &x[10..num]; // should trigger out of bounds error +} diff --git a/tests/ui/out_of_bounds_indexing/issue-3102.stderr b/tests/ui/out_of_bounds_indexing/issue-3102.stderr new file mode 100644 index 000000000000..516c1df40be0 --- /dev/null +++ b/tests/ui/out_of_bounds_indexing/issue-3102.stderr @@ -0,0 +1,16 @@ +error: range is out of bounds + --> $DIR/issue-3102.rs:9:13 + | +LL | &x[num..10]; // should trigger out of bounds error + | ^^ + | + = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + +error: range is out of bounds + --> $DIR/issue-3102.rs:10:8 + | +LL | &x[10..num]; // should trigger out of bounds error + | ^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/out_of_bounds_indexing/simple.rs b/tests/ui/out_of_bounds_indexing/simple.rs new file mode 100644 index 000000000000..4c541c23f5f4 --- /dev/null +++ b/tests/ui/out_of_bounds_indexing/simple.rs @@ -0,0 +1,22 @@ +#![warn(clippy::out_of_bounds_indexing)] +#![allow(clippy::no_effect, clippy::unnecessary_operation)] + +fn main() { + let x = [1, 2, 3, 4]; + + &x[..=4]; + &x[1..5]; + &x[5..]; + &x[..5]; + &x[5..].iter().map(|x| 2 * x).collect::>(); + &x[0..=4]; + + &x[4..]; // Ok, should not produce stderr. + &x[..4]; // Ok, should not produce stderr. + &x[..]; // Ok, should not produce stderr. + &x[1..]; // Ok, should not produce stderr. + &x[2..].iter().map(|x| 2 * x).collect::>(); // Ok, should not produce stderr. + + &x[0..].get(..3); // Ok, should not produce stderr. + &x[0..3]; // Ok, should not produce stderr. +} diff --git a/tests/ui/out_of_bounds_indexing/simple.stderr b/tests/ui/out_of_bounds_indexing/simple.stderr new file mode 100644 index 000000000000..3d95afcdab23 --- /dev/null +++ b/tests/ui/out_of_bounds_indexing/simple.stderr @@ -0,0 +1,40 @@ +error: range is out of bounds + --> $DIR/simple.rs:7:11 + | +LL | &x[..=4]; + | ^ + | + = note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings` + +error: range is out of bounds + --> $DIR/simple.rs:8:11 + | +LL | &x[1..5]; + | ^ + +error: range is out of bounds + --> $DIR/simple.rs:9:8 + | +LL | &x[5..]; + | ^ + +error: range is out of bounds + --> $DIR/simple.rs:10:10 + | +LL | &x[..5]; + | ^ + +error: range is out of bounds + --> $DIR/simple.rs:11:8 + | +LL | &x[5..].iter().map(|x| 2 * x).collect::>(); + | ^ + +error: range is out of bounds + --> $DIR/simple.rs:12:12 + | +LL | &x[0..=4]; + | ^ + +error: aborting due to 6 previous errors + diff --git a/tests/ui/outer_expn_info.rs b/tests/ui/outer_expn_info.rs index 1bc6f6888054..ed0542c9298b 100644 --- a/tests/ui/outer_expn_info.rs +++ b/tests/ui/outer_expn_info.rs @@ -16,7 +16,7 @@ declare_lint_pass!(Pass => [TEST_LINT]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { fn check_expr(&mut self, _cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { - let _ = expr.span.ctxt().outer().expn_info(); + let _ = expr.span.ctxt().outer_expn().expn_info(); } } diff --git a/tests/ui/outer_expn_info.stderr b/tests/ui/outer_expn_info.stderr index 2bd3a9835457..4bbd1493dc4f 100644 --- a/tests/ui/outer_expn_info.stderr +++ b/tests/ui/outer_expn_info.stderr @@ -1,15 +1,15 @@ -error: usage of `outer().expn_info()` +error: usage of `outer_expn().expn_info()` --> $DIR/outer_expn_info.rs:19:33 | -LL | let _ = expr.span.ctxt().outer().expn_info(); - | ^^^^^^^^^^^^^^^^^^^^ help: try: `.outer_expn_info()` +LL | let _ = expr.span.ctxt().outer_expn().expn_info(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.outer_expn_info()` | note: lint level defined here --> $DIR/outer_expn_info.rs:1:9 | LL | #![deny(clippy::internal)] | ^^^^^^^^^^^^^^^^ - = note: #[deny(clippy::outer_expn_info)] implied by #[deny(clippy::internal)] + = note: `#[deny(clippy::outer_expn_expn_info)]` implied by `#[deny(clippy::internal)]` error: aborting due to previous error diff --git a/tests/ui/proc_macro.stderr b/tests/ui/proc_macro.stderr index ec19cd8fc5fb..78c3880db499 100644 --- a/tests/ui/proc_macro.stderr +++ b/tests/ui/proc_macro.stderr @@ -4,7 +4,7 @@ error: approximate value of `f{32, 64}::consts::PI` found. Consider using it dir LL | let _x = 3.14; | ^^^^ | - = note: #[deny(clippy::approx_constant)] on by default + = note: `#[deny(clippy::approx_constant)]` on by default error: aborting due to previous error diff --git a/tests/ui/suspicious_arithmetic_impl.stderr b/tests/ui/suspicious_arithmetic_impl.stderr index f818f7b3d956..e8a6efc4c4d2 100644 --- a/tests/ui/suspicious_arithmetic_impl.stderr +++ b/tests/ui/suspicious_arithmetic_impl.stderr @@ -12,7 +12,7 @@ error: Suspicious use of binary operator in `AddAssign` impl LL | *self = *self - other; | ^ | - = note: #[deny(clippy::suspicious_op_assign_impl)] on by default + = note: `#[deny(clippy::suspicious_op_assign_impl)]` on by default error: aborting due to 2 previous errors diff --git a/tests/ui/unnecessary_clone.stderr b/tests/ui/unnecessary_clone.stderr index 8d5d54e7de67..79b99ff1d1d2 100644 --- a/tests/ui/unnecessary_clone.stderr +++ b/tests/ui/unnecessary_clone.stderr @@ -68,7 +68,7 @@ error: using `clone` on a double-reference; this will copy the reference instead LL | let z: &Vec<_> = y.clone(); | ^^^^^^^^^ | - = note: #[deny(clippy::clone_double_ref)] on by default + = note: `#[deny(clippy::clone_double_ref)]` on by default help: try dereferencing it | LL | let z: &Vec<_> = &(*y).clone(); diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index c8a38f9fe57a..40968822493f 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -4,9 +4,9 @@ use std::io; fn try_macro(s: &mut T) -> io::Result<()> { - try!(s.write(b"test")); + r#try!(s.write(b"test")); let mut buf = [0u8; 4]; - try!(s.read(&mut buf)); + r#try!(s.read(&mut buf)); Ok(()) } diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr index 2d00338193c4..dbf701e06f9a 100644 --- a/tests/ui/unused_io_amount.stderr +++ b/tests/ui/unused_io_amount.stderr @@ -1,8 +1,8 @@ error: handle written amount returned or use `Write::write_all` instead --> $DIR/unused_io_amount.rs:7:5 | -LL | try!(s.write(b"test")); - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | r#try!(s.write(b"test")); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::unused-io-amount` implied by `-D warnings` = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) @@ -10,8 +10,8 @@ LL | try!(s.write(b"test")); error: handle read amount returned or use `Read::read_exact` instead --> $DIR/unused_io_amount.rs:9:5 | -LL | try!(s.read(&mut buf)); - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | r#try!(s.read(&mut buf)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) diff --git a/tests/ui/zero_div_zero.stderr b/tests/ui/zero_div_zero.stderr index 763859f54fb2..c599da8baf9b 100644 --- a/tests/ui/zero_div_zero.stderr +++ b/tests/ui/zero_div_zero.stderr @@ -4,7 +4,7 @@ error: equal expressions as operands to `/` LL | let nan = 0.0 / 0.0; | ^^^^^^^^^ | - = note: #[deny(clippy::eq_op)] on by default + = note: `#[deny(clippy::eq_op)]` on by default error: constant division of 0.0 with 0.0 will always result in NaN --> $DIR/zero_div_zero.rs:4:15