From 14f596cb7425e2a12a6e034880683e976179d1cd Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 21 Apr 2020 22:53:18 +0200 Subject: [PATCH 1/9] Only run cargo lints, when they are warn/deny/forbid --- clippy_lints/src/cargo_common_metadata.rs | 18 +++++++++++------- clippy_lints/src/lib.rs | 6 +++--- clippy_lints/src/multiple_crate_versions.rs | 14 +++++++++----- clippy_lints/src/utils/mod.rs | 9 +++++++++ clippy_lints/src/wildcard_dependencies.rs | 14 +++++++++----- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index 06e866dd72a01..782da249808d0 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -2,9 +2,9 @@ use std::path::PathBuf; -use crate::utils::span_lint; -use rustc_ast::ast::Crate; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use crate::utils::{run_lints, span_lint}; +use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::DUMMY_SP; @@ -35,11 +35,11 @@ declare_clippy_lint! { "common metadata is defined in `Cargo.toml`" } -fn warning(cx: &EarlyContext<'_>, message: &str) { +fn warning(cx: &LateContext<'_, '_>, message: &str) { span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, message); } -fn missing_warning(cx: &EarlyContext<'_>, package: &cargo_metadata::Package, field: &str) { +fn missing_warning(cx: &LateContext<'_, '_>, package: &cargo_metadata::Package, field: &str) { let message = format!("package `{}` is missing `{}` metadata", package.name, field); warning(cx, &message); } @@ -59,8 +59,12 @@ fn is_empty_vec(value: &[String]) -> bool { declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]); -impl EarlyLintPass for CargoCommonMetadata { - fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) { +impl LateLintPass<'_, '_> for CargoCommonMetadata { + fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) { + if !run_lints(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) { + return; + } + let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() { metadata } else { diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index dee4188b75f38..9cd78945eecb6 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1024,9 +1024,9 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_early_pass(|| box precedence::Precedence); store.register_early_pass(|| box needless_continue::NeedlessContinue); store.register_early_pass(|| box redundant_static_lifetimes::RedundantStaticLifetimes); - store.register_early_pass(|| box cargo_common_metadata::CargoCommonMetadata); - store.register_early_pass(|| box multiple_crate_versions::MultipleCrateVersions); - store.register_early_pass(|| box wildcard_dependencies::WildcardDependencies); + store.register_late_pass(|| box cargo_common_metadata::CargoCommonMetadata); + store.register_late_pass(|| box multiple_crate_versions::MultipleCrateVersions); + store.register_late_pass(|| box wildcard_dependencies::WildcardDependencies); store.register_early_pass(|| box literal_representation::LiteralDigitGrouping); let literal_representation_threshold = conf.literal_representation_threshold; store.register_early_pass(move || box literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold)); diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index 88605c52f2e2b..ed85d0315bd25 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -1,8 +1,8 @@ //! lint on multiple versions of a crate being used -use crate::utils::span_lint; -use rustc_ast::ast::Crate; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use crate::utils::{run_lints, span_lint}; +use rustc_hir::{Crate, CRATE_HIR_ID}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::DUMMY_SP; @@ -33,8 +33,12 @@ declare_clippy_lint! { declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]); -impl EarlyLintPass for MultipleCrateVersions { - fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) { +impl LateLintPass<'_, '_> for MultipleCrateVersions { + fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) { + if !run_lints(cx, &[MULTIPLE_CRATE_VERSIONS], CRATE_HIR_ID) { + return; + } + let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().exec() { metadata } else { diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index a0543a8dcf985..0d37932ddab53 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1399,6 +1399,15 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_, '_>, did: DefId) -> bool ) } +pub fn run_lints(cx: &LateContext<'_, '_>, lints: &[&'static Lint], id: HirId) -> bool { + lints.iter().any(|lint| { + matches!( + cx.tcx.lint_level_at_node(lint, id), + (Level::Forbid | Level::Deny | Level::Warn, _) + ) + }) +} + #[cfg(test)] mod test { use super::{trim_multiline, without_block_comments}; diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index 035a10b1a2478..d8d48eb15358d 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -1,6 +1,6 @@ -use crate::utils::span_lint; -use rustc_ast::ast::Crate; -use rustc_lint::{EarlyContext, EarlyLintPass}; +use crate::utils::{run_lints, span_lint}; +use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; +use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::DUMMY_SP; @@ -28,8 +28,12 @@ declare_clippy_lint! { declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]); -impl EarlyLintPass for WildcardDependencies { - fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) { +impl LateLintPass<'_, '_> for WildcardDependencies { + fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) { + if !run_lints(cx, &[WILDCARD_DEPENDENCIES], CRATE_HIR_ID) { + return; + } + let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() { metadata } else { From f31502f4bb22262cd1d05e59aa7af4879ae1b2ed Mon Sep 17 00:00:00 2001 From: flip1995 Date: Wed, 22 Apr 2020 20:51:58 +0200 Subject: [PATCH 2/9] Only run (late) internal lints, when they are warn/deny/forbid --- clippy_lints/src/utils/internal_lints.rs | 32 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 6eb6c2d98e917..5bf9acdc5f7ce 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -1,7 +1,7 @@ use crate::utils::SpanlessEq; use crate::utils::{ - is_expn_of, match_def_path, match_qpath, match_type, method_calls, paths, snippet, span_lint, span_lint_and_help, - span_lint_and_sugg, walk_ptrs_ty, + is_expn_of, match_def_path, match_qpath, match_type, method_calls, paths, run_lints, snippet, span_lint, + span_lint_and_help, span_lint_and_sugg, walk_ptrs_ty, }; use if_chain::if_chain; use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, Name, NodeId}; @@ -10,7 +10,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc_hir::hir_id::CRATE_HIR_ID; +use rustc_hir::intravisit::{NestedVisitorMap, Visitor}; use rustc_hir::{Crate, Expr, ExprKind, HirId, Item, MutTy, Mutability, Path, StmtKind, Ty, TyKind}; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; use rustc_middle::hir::map::Map; @@ -252,6 +253,10 @@ impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) { + if !run_lints(cx, &[DEFAULT_LINT], item.hir_id) { + return; + } + if let hir::ItemKind::Static(ref ty, Mutability::Not, body_id) = item.kind { if is_lint_ref_type(cx, ty) { let expr = &cx.tcx.hir().body(body_id).value; @@ -306,6 +311,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass { } fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, _: &'tcx Crate<'_>) { + if !run_lints(cx, &[LINT_WITHOUT_LINT_PASS], CRATE_HIR_ID) { + return; + } + for (lint_name, &lint_span) in &self.declared_lints { // When using the `declare_tool_lint!` macro, the original `lint_span`'s // file points to "". @@ -355,15 +364,12 @@ struct LintCollector<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> { type Map = Map<'tcx>; - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - walk_expr(self, expr); - } - fn visit_path(&mut self, path: &'tcx Path<'_>, _: HirId) { if path.segments.len() == 1 { self.output.insert(path.segments[0].ident.name); } } + fn nested_visit_map(&mut self) -> NestedVisitorMap { NestedVisitorMap::All(self.cx.tcx.hir()) } @@ -391,6 +397,10 @@ impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { + if !run_lints(cx, &[COMPILER_LINT_FUNCTIONS], expr.hir_id) { + return; + } + if_chain! { if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind; let fn_name = path.ident; @@ -416,6 +426,10 @@ declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { + if !run_lints(cx, &[OUTER_EXPN_EXPN_DATA], expr.hir_id) { + return; + } + let (method_names, arg_lists, spans) = method_calls(expr, 2); let method_names: Vec = method_names.iter().map(|s| s.as_str()).collect(); let method_names: Vec<&str> = method_names.iter().map(|s| &**s).collect(); @@ -462,6 +476,10 @@ declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CollapsibleCalls { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) { + if !run_lints(cx, &[COLLAPSIBLE_SPAN_LINT_CALLS], expr.hir_id) { + return; + } + if_chain! { if let ExprKind::Call(ref func, ref and_then_args) = expr.kind; if let ExprKind::Path(ref path) = func.kind; From 35ef280b5586264a1c9f6cdaec836d2e9945d60f Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 23 Apr 2020 20:44:18 +0200 Subject: [PATCH 3/9] Always use the deploy script and templates of the master branch --- .github/workflows/deploy.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 10033daf0aedb..f542f9b02c17b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -38,6 +38,12 @@ jobs: - name: Set beta to true if: github.ref == 'refs/heads/beta' run: echo "::set-env name=BETA::true" + + - name: Use scripts and templates from master branch + run: | + git fetch --no-tags --prune --depth=1 origin master + git checkout origin/master -- .github/deploy.sh util/gh-pages/ util/*.py + - name: Deploy run: | eval "$(ssh-agent -s)" From 0476e8b48380f0376ff040f07edfe74372ae2101 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 23 Apr 2020 20:45:39 +0200 Subject: [PATCH 4/9] Remove apt-get upgrade again --- .github/workflows/clippy_bors.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/clippy_bors.yml b/.github/workflows/clippy_bors.yml index 4429a7c1e5c53..6675a1029bbc8 100644 --- a/.github/workflows/clippy_bors.yml +++ b/.github/workflows/clippy_bors.yml @@ -77,8 +77,6 @@ jobs: run: | sudo dpkg --add-architecture i386 sudo apt-get update - # perform system upgrade to work around https://github.com/rust-lang/rust-clippy/issues/5477 , revert as soon as that is fixed - sudo apt-get -y upgrade sudo apt-get install gcc-multilib libssl-dev:i386 libgit2-dev:i386 if: matrix.host == 'i686-unknown-linux-gnu' From 4619bb243db71309f1c0a619347995560d3dd20b Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 23 Apr 2020 20:14:06 +0200 Subject: [PATCH 5/9] Add a note to the beta sections of release.md --- doc/release.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/release.md b/doc/release.md index 25ddff4c48ca0..f16ddb375da31 100644 --- a/doc/release.md +++ b/doc/release.md @@ -63,6 +63,9 @@ to the beta Rust release. The remerge is then necessary, to make sure that the Clippy commit, that was used by the now stable Rust release, persists in the tree of the Clippy repository. +To find out if this step is necessary run `git branch master --contains beta`. +If this command outputs `master`, this step is **not** necessary. + ```bash # Assuming `HEAD` is the current `master` branch of rust-lang/rust-clippy $ git checkout -b backport_remerge From c19ca0e8a8d6b8e04d635af617a80cf63aed1abc Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 23 Apr 2020 20:34:30 +0200 Subject: [PATCH 6/9] The beta branch update should not require a force push --- doc/release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/release.md b/doc/release.md index f16ddb375da31..12bfe5a1487e8 100644 --- a/doc/release.md +++ b/doc/release.md @@ -100,5 +100,5 @@ be updated. # Assuming the current directory corresponds to the Clippy repository $ git checkout beta $ git rebase $BETA_SHA -$ git push upstream beta [-f] # This requires a force push, if a remerge was done +$ git push upstream beta ``` From 451badeddf0c7ea13353bdd3f3fa3cf690bc22d9 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 23 Apr 2020 23:24:58 +0200 Subject: [PATCH 7/9] Run fetch before testing if master contains beta --- doc/release.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/release.md b/doc/release.md index 12bfe5a1487e8..9d69fa8a7f69a 100644 --- a/doc/release.md +++ b/doc/release.md @@ -63,7 +63,14 @@ to the beta Rust release. The remerge is then necessary, to make sure that the Clippy commit, that was used by the now stable Rust release, persists in the tree of the Clippy repository. -To find out if this step is necessary run `git branch master --contains beta`. +To find out if this step is necessary run + +```bash +# Assumes that the local master branch is up-to-date +$ git fetch upstream +$ git branch master --contains upstream/beta +``` + If this command outputs `master`, this step is **not** necessary. ```bash From ef28361293b39b63f313aa756fce1b9c74f9eb28 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 2 Apr 2020 17:36:49 -0700 Subject: [PATCH 8/9] Downgrade match_bool to pedantic --- clippy_lints/src/lib.rs | 3 +-- clippy_lints/src/matches.rs | 2 +- src/lintlist/mod.rs | 2 +- tests/ui/implicit_return.fixed | 3 +-- tests/ui/implicit_return.rs | 3 +-- tests/ui/implicit_return.stderr | 16 ++++++++-------- tests/ui/match_bool.rs | 2 ++ tests/ui/match_bool.stderr | 22 +++++++++++++--------- tests/ui/needless_return.fixed | 2 +- tests/ui/needless_return.rs | 2 +- 10 files changed, 30 insertions(+), 27 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index dee4188b75f38..f9d1ddf049cd8 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1134,6 +1134,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&loops::EXPLICIT_INTO_ITER_LOOP), LintId::of(&loops::EXPLICIT_ITER_LOOP), LintId::of(¯o_use::MACRO_USE_IMPORTS), + LintId::of(&matches::MATCH_BOOL), LintId::of(&matches::SINGLE_MATCH_ELSE), LintId::of(&methods::FILTER_MAP), LintId::of(&methods::FILTER_MAP_NEXT), @@ -1279,7 +1280,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN), LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH), LintId::of(&matches::MATCH_AS_REF), - LintId::of(&matches::MATCH_BOOL), LintId::of(&matches::MATCH_OVERLAPPING_ARM), LintId::of(&matches::MATCH_REF_PATS), LintId::of(&matches::MATCH_SINGLE_BINDING), @@ -1470,7 +1470,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&main_recursion::MAIN_RECURSION), LintId::of(&map_clone::MAP_CLONE), LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH), - LintId::of(&matches::MATCH_BOOL), LintId::of(&matches::MATCH_OVERLAPPING_ARM), LintId::of(&matches::MATCH_REF_PATS), LintId::of(&matches::MATCH_WILD_ERR_ARM), diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 270e306e15f7a..8f86535ef1e0f 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -138,7 +138,7 @@ declare_clippy_lint! { /// } /// ``` pub MATCH_BOOL, - style, + pedantic, "a `match` on a boolean expression instead of an `if..else` block" } diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 2c466aa20c675..9b67bacc35d72 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -1139,7 +1139,7 @@ pub static ref ALL_LINTS: Vec = vec![ }, Lint { name: "match_bool", - group: "style", + group: "pedantic", desc: "a `match` on a boolean expression instead of an `if..else` block", deprecation: None, module: "matches", diff --git a/tests/ui/implicit_return.fixed b/tests/ui/implicit_return.fixed index dd42f06664e15..9066dc3fedfd6 100644 --- a/tests/ui/implicit_return.fixed +++ b/tests/ui/implicit_return.fixed @@ -21,7 +21,6 @@ fn test_if_block() -> bool { } } -#[allow(clippy::match_bool)] #[rustfmt::skip] fn test_match(x: bool) -> bool { match x { @@ -30,7 +29,7 @@ fn test_match(x: bool) -> bool { } } -#[allow(clippy::match_bool, clippy::needless_return)] +#[allow(clippy::needless_return)] fn test_match_with_unreachable(x: bool) -> bool { match x { true => return false, diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs index 5abbf6a5583ea..c0d70ecf502ed 100644 --- a/tests/ui/implicit_return.rs +++ b/tests/ui/implicit_return.rs @@ -21,7 +21,6 @@ fn test_if_block() -> bool { } } -#[allow(clippy::match_bool)] #[rustfmt::skip] fn test_match(x: bool) -> bool { match x { @@ -30,7 +29,7 @@ fn test_match(x: bool) -> bool { } } -#[allow(clippy::match_bool, clippy::needless_return)] +#[allow(clippy::needless_return)] fn test_match_with_unreachable(x: bool) -> bool { match x { true => return false, diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr index 411b98067d0ef..fb2ec90276454 100644 --- a/tests/ui/implicit_return.stderr +++ b/tests/ui/implicit_return.stderr @@ -19,49 +19,49 @@ LL | false | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:28:17 + --> $DIR/implicit_return.rs:27:17 | LL | true => false, | ^^^^^ help: add `return` as shown: `return false` error: missing `return` statement - --> $DIR/implicit_return.rs:29:20 + --> $DIR/implicit_return.rs:28:20 | LL | false => { true }, | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:44:9 + --> $DIR/implicit_return.rs:43:9 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:52:13 + --> $DIR/implicit_return.rs:51:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:61:13 + --> $DIR/implicit_return.rs:60:13 | LL | break true; | ^^^^^^^^^^ help: change `break` to `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:79:18 + --> $DIR/implicit_return.rs:78:18 | LL | let _ = || { true }; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:80:16 + --> $DIR/implicit_return.rs:79:16 | LL | let _ = || true; | ^^^^ help: add `return` as shown: `return true` error: missing `return` statement - --> $DIR/implicit_return.rs:88:5 + --> $DIR/implicit_return.rs:87:5 | LL | format!("test {}", "test") | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")` diff --git a/tests/ui/match_bool.rs b/tests/ui/match_bool.rs index 811aff2a8d404..9ed55ca7ae7f9 100644 --- a/tests/ui/match_bool.rs +++ b/tests/ui/match_bool.rs @@ -1,3 +1,5 @@ +#![deny(clippy::match_bool)] + fn match_bool() { let test: bool = true; diff --git a/tests/ui/match_bool.stderr b/tests/ui/match_bool.stderr index d0c20eb2696b9..1ad78c740c68b 100644 --- a/tests/ui/match_bool.stderr +++ b/tests/ui/match_bool.stderr @@ -1,5 +1,5 @@ error: this boolean expression can be simplified - --> $DIR/match_bool.rs:29:11 + --> $DIR/match_bool.rs:31:11 | LL | match test && test { | ^^^^^^^^^^^^ help: try: `test` @@ -7,7 +7,7 @@ LL | match test && test { = note: `-D clippy::nonminimal-bool` implied by `-D warnings` error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:4:5 + --> $DIR/match_bool.rs:6:5 | LL | / match test { LL | | true => 0, @@ -15,10 +15,14 @@ LL | | false => 42, LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if test { 0 } else { 42 }` | - = note: `-D clippy::match-bool` implied by `-D warnings` +note: the lint level is defined here + --> $DIR/match_bool.rs:1:9 + | +LL | #![deny(clippy::match_bool)] + | ^^^^^^^^^^^^^^^^^^ error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:10:5 + --> $DIR/match_bool.rs:12:5 | LL | / match option == 1 { LL | | true => 1, @@ -27,7 +31,7 @@ LL | | }; | |_____^ help: consider using an `if`/`else` expression: `if option == 1 { 1 } else { 0 }` error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:15:5 + --> $DIR/match_bool.rs:17:5 | LL | / match test { LL | | true => (), @@ -45,7 +49,7 @@ LL | }; | error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:22:5 + --> $DIR/match_bool.rs:24:5 | LL | / match test { LL | | false => { @@ -63,7 +67,7 @@ LL | }; | error: you seem to be trying to match on a boolean expression - --> $DIR/match_bool.rs:29:5 + --> $DIR/match_bool.rs:31:5 | LL | / match test && test { LL | | false => { @@ -81,7 +85,7 @@ LL | }; | error: equal expressions as operands to `&&` - --> $DIR/match_bool.rs:29:11 + --> $DIR/match_bool.rs:31:11 | LL | match test && test { | ^^^^^^^^^^^^ @@ -89,7 +93,7 @@ LL | match test && test { = 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 + --> $DIR/match_bool.rs:38:5 | LL | / match test { LL | | false => { diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed index 70af5c1961410..ad20e2381073a 100644 --- a/tests/ui/needless_return.fixed +++ b/tests/ui/needless_return.fixed @@ -1,6 +1,6 @@ // run-rustfix -#![allow(unused, clippy::needless_bool, clippy::match_bool)] +#![allow(unused, clippy::needless_bool)] #![allow(clippy::if_same_then_else, clippy::single_match)] #![warn(clippy::needless_return)] diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index a1f8321ac6e7e..af0cdfb207ff5 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -1,6 +1,6 @@ // run-rustfix -#![allow(unused, clippy::needless_bool, clippy::match_bool)] +#![allow(unused, clippy::needless_bool)] #![allow(clippy::if_same_then_else, clippy::single_match)] #![warn(clippy::needless_return)] From bf73d519597dcc8bcf2ac05b106afbd89deb846d Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Sat, 25 Apr 2020 10:43:41 +0200 Subject: [PATCH 9/9] Add lifetime test case for `new_ret_no_self` --- tests/ui/new_ret_no_self.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index 35aaecc9ac423..2c2d1e275893f 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -199,3 +199,14 @@ impl NestedReturnerOk3 { unimplemented!(); } } + +struct WithLifetime<'a> { + cat: &'a str, +} + +impl<'a> WithLifetime<'a> { + // should not trigger the lint, because the lifetimes are different + pub fn new<'b: 'a>(s: &'b str) -> WithLifetime<'b> { + unimplemented!(); + } +}