From 87ba8d24d608276a54a7fcbf00627353e64a5813 Mon Sep 17 00:00:00 2001 From: asquared31415 <34665709+asquared31415@users.noreply.github.com> Date: Fri, 10 Sep 2021 09:33:06 -0400 Subject: [PATCH 01/55] update test --- tests/ui/def_id_nocore.rs | 5 +++-- tests/ui/def_id_nocore.stderr | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/ui/def_id_nocore.rs b/tests/ui/def_id_nocore.rs index cba7666c2d8..1ed78547a60 100644 --- a/tests/ui/def_id_nocore.rs +++ b/tests/ui/def_id_nocore.rs @@ -15,11 +15,12 @@ pub trait Copy {} pub unsafe trait Freeze {} #[lang = "start"] -#[start] -fn start(_argc: isize, _argv: *const *const u8) -> isize { +fn start(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize { 0 } +fn main() {} + struct A; impl A { diff --git a/tests/ui/def_id_nocore.stderr b/tests/ui/def_id_nocore.stderr index 702684f6b43..6210d7c6cfd 100644 --- a/tests/ui/def_id_nocore.stderr +++ b/tests/ui/def_id_nocore.stderr @@ -1,5 +1,5 @@ error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/def_id_nocore.rs:26:19 + --> $DIR/def_id_nocore.rs:27:19 | LL | pub fn as_ref(self) -> &'static str { | ^^^^ From 3e5f80f009453143447bc1cf6bc17801e0586297 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 15 Sep 2021 10:03:03 +0000 Subject: [PATCH 02/55] Move is_const_fn to under TyCtxt --- clippy_utils/src/lib.rs | 1 - clippy_utils/src/qualify_min_const_fn.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 3a94f472983..beddc6f09be 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -18,7 +18,6 @@ extern crate rustc_ast; extern crate rustc_ast_pretty; extern crate rustc_attr; -extern crate rustc_const_eval; extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_hir; diff --git a/clippy_utils/src/qualify_min_const_fn.rs b/clippy_utils/src/qualify_min_const_fn.rs index e9a9895cb74..67dda33e9da 100644 --- a/clippy_utils/src/qualify_min_const_fn.rs +++ b/clippy_utils/src/qualify_min_const_fn.rs @@ -364,7 +364,7 @@ fn check_terminator( } fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> bool { - rustc_const_eval::const_eval::is_const_fn(tcx, def_id) + tcx.is_const_fn(def_id) && tcx.lookup_const_stability(def_id).map_or(true, |const_stab| { if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level { // Checking MSRV is manually necessary because `rustc` has no such concept. This entire From f6c5d580b88c209db4076916b44687df527fd4fd Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 23 Sep 2021 13:14:46 -0500 Subject: [PATCH 03/55] Improve depinfo error --- tests/compile-test.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index d7596f6ff0c..e8b1640c869 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -92,7 +92,9 @@ fn extern_flags() -> String { .collect(); assert!( not_found.is_empty(), - "dependencies not found in depinfo: {:?}", + "dependencies not found in depinfo: {:?}\n\ + help: Make sure the `-Z binary-dep-depinfo` rust flag is enabled\n\ + help: Try adding to dev-dependencies in Cargo.toml", not_found ); crates From 25850fc264ff71fcdbfd3594e8d5a299d7dbe2c0 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 28 Sep 2021 08:33:58 -0700 Subject: [PATCH 04/55] Make doc_unsafe lint on unsafe traits as well --- clippy_lints/src/doc.rs | 12 +++++++++++- tests/ui/def_id_nocore.rs | 1 + tests/ui/def_id_nocore.stderr | 2 +- tests/ui/doc_unsafe.rs | 21 +++++++++++++++++++-- tests/ui/doc_unsafe.stderr | 14 +++++++++++--- 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index cb2b7f5be70..0a9edfd7334 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -236,7 +236,17 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { hir::ItemKind::Impl(ref impl_) => { self.in_trait_impl = impl_.of_trait.is_some(); }, - _ => {}, + hir::ItemKind::Trait(_, unsafety, ..) => { + if !headers.safety && unsafety == hir::Unsafety::Unsafe { + span_lint( + cx, + MISSING_SAFETY_DOC, + item.span, + "unsafe trait's docs miss `# Safety` section", + ); + } + }, + _ => (), } } diff --git a/tests/ui/def_id_nocore.rs b/tests/ui/def_id_nocore.rs index cba7666c2d8..9ff3b5e5ef5 100644 --- a/tests/ui/def_id_nocore.rs +++ b/tests/ui/def_id_nocore.rs @@ -3,6 +3,7 @@ #![feature(no_core, lang_items, start)] #![no_core] +#![allow(clippy::missing_safety_doc)] #[link(name = "c")] extern "C" {} diff --git a/tests/ui/def_id_nocore.stderr b/tests/ui/def_id_nocore.stderr index 702684f6b43..6210d7c6cfd 100644 --- a/tests/ui/def_id_nocore.stderr +++ b/tests/ui/def_id_nocore.stderr @@ -1,5 +1,5 @@ error: methods called `as_*` usually take `self` by reference or `self` by mutable reference - --> $DIR/def_id_nocore.rs:26:19 + --> $DIR/def_id_nocore.rs:27:19 | LL | pub fn as_ref(self) -> &'static str { | ^^^^ diff --git a/tests/ui/doc_unsafe.rs b/tests/ui/doc_unsafe.rs index 484aa72d59a..8f823f1672b 100644 --- a/tests/ui/doc_unsafe.rs +++ b/tests/ui/doc_unsafe.rs @@ -34,16 +34,25 @@ pub unsafe fn republished() { pub use private_mod::republished; -pub trait UnsafeTrait { +pub trait SafeTraitUnsafeMethods { unsafe fn woefully_underdocumented(self); /// # Safety unsafe fn at_least_somewhat_documented(self); } +pub unsafe trait UnsafeTrait { + fn method(); +} + +/// # Safety +pub unsafe trait DocumentedUnsafeTrait { + fn method2(); +} + pub struct Struct; -impl UnsafeTrait for Struct { +impl SafeTraitUnsafeMethods for Struct { unsafe fn woefully_underdocumented(self) { // all is well } @@ -53,6 +62,14 @@ unsafe fn at_least_somewhat_documented(self) { } } +unsafe impl UnsafeTrait for Struct { + fn method() {} +} + +unsafe impl DocumentedUnsafeTrait for Struct { + fn method2() {} +} + impl Struct { pub unsafe fn more_undocumented_unsafe() -> Self { unimplemented!(); diff --git a/tests/ui/doc_unsafe.stderr b/tests/ui/doc_unsafe.stderr index 73b53f3431e..d540abd1262 100644 --- a/tests/ui/doc_unsafe.stderr +++ b/tests/ui/doc_unsafe.stderr @@ -22,8 +22,16 @@ error: unsafe function's docs miss `# Safety` section LL | unsafe fn woefully_underdocumented(self); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: unsafe trait's docs miss `# Safety` section + --> $DIR/doc_unsafe.rs:44:1 + | +LL | / pub unsafe trait UnsafeTrait { +LL | | fn method(); +LL | | } + | |_^ + error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:57:5 + --> $DIR/doc_unsafe.rs:74:5 | LL | / pub unsafe fn more_undocumented_unsafe() -> Self { LL | | unimplemented!(); @@ -31,7 +39,7 @@ LL | | } | |_____^ error: unsafe function's docs miss `# Safety` section - --> $DIR/doc_unsafe.rs:73:9 + --> $DIR/doc_unsafe.rs:90:9 | LL | / pub unsafe fn whee() { LL | | unimplemented!() @@ -43,5 +51,5 @@ LL | very_unsafe!(); | = note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors From 53c534d11b289c8587128929306ad50cd3fe02f9 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 28 Sep 2021 09:37:11 -0700 Subject: [PATCH 05/55] Update clippy_lints/src/doc.rs Co-authored-by: Cameron Steffen --- clippy_lints/src/doc.rs | 2 +- tests/ui/doc_unsafe.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 0a9edfd7334..ce540c38478 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -242,7 +242,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { cx, MISSING_SAFETY_DOC, item.span, - "unsafe trait's docs miss `# Safety` section", + "docs for unsafe trait missing `# Safety` section", ); } }, diff --git a/tests/ui/doc_unsafe.stderr b/tests/ui/doc_unsafe.stderr index d540abd1262..34ca37a6efd 100644 --- a/tests/ui/doc_unsafe.stderr +++ b/tests/ui/doc_unsafe.stderr @@ -22,7 +22,7 @@ error: unsafe function's docs miss `# Safety` section LL | unsafe fn woefully_underdocumented(self); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: unsafe trait's docs miss `# Safety` section +error: docs for unsafe trait missing `# Safety` section --> $DIR/doc_unsafe.rs:44:1 | LL | / pub unsafe trait UnsafeTrait { From 23d5457e6d8d4d1d943d8368af680545fb6222b2 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 28 Sep 2021 18:03:12 +0100 Subject: [PATCH 06/55] Merge commit 'cb7915b00c235e9b5861564f3be78dba330980ee' into clippyup --- .cargo/config | 5 +- .github/ISSUE_TEMPLATE/blank_issue.md | 2 +- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/false_positive.md | 2 +- CHANGELOG.md | 99 +++++-- Cargo.toml | 2 +- README.md | 2 +- clippy_dev/Cargo.toml | 2 +- clippy_dev/src/bless.rs | 20 +- clippy_lints/Cargo.toml | 2 +- clippy_lints/src/derivable_impls.rs | 17 +- clippy_lints/src/disallowed_method.rs | 84 +++--- clippy_lints/src/disallowed_type.rs | 2 +- clippy_lints/src/escape.rs | 7 +- clippy_lints/src/eta_reduction.rs | 242 +++++++----------- clippy_lints/src/float_literal.rs | 2 +- clippy_lints/src/format.rs | 4 +- clippy_lints/src/formatting.rs | 57 +++-- clippy_lints/src/if_then_panic.rs | 97 +++++++ .../src/iter_not_returning_iterator.rs | 64 +++++ clippy_lints/src/lib.rs | 43 ++-- clippy_lints/src/loops/for_kv_map.rs | 7 +- clippy_lints/src/loops/while_let_loop.rs | 2 +- .../src/loops/while_let_on_iterator.rs | 17 +- clippy_lints/src/macro_use.rs | 27 +- ..._let_some_result.rs => match_result_ok.rs} | 55 ++-- clippy_lints/src/matches.rs | 4 +- clippy_lints/src/methods/manual_split_once.rs | 70 +++-- clippy_lints/src/methods/mod.rs | 2 + clippy_lints/src/misc.rs | 2 +- clippy_lints/src/mut_key.rs | 81 ++++-- clippy_lints/src/needless_borrow.rs | 12 +- clippy_lints/src/non_expressive_names.rs | 2 +- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/regex.rs | 7 +- clippy_lints/src/returns.rs | 5 +- clippy_lints/src/same_name_method.rs | 160 ++++++++++++ clippy_lints/src/types/box_collection.rs | 50 ++++ clippy_lints/src/types/box_vec.rs | 25 -- clippy_lints/src/types/mod.rs | 14 +- clippy_lints/src/utils/conf.rs | 12 +- clippy_lints/src/utils/internal_lints.rs | 13 +- .../internal_lints/metadata_collector.rs | 1 + clippy_utils/Cargo.toml | 2 +- clippy_utils/src/ast_utils.rs | 85 +++--- clippy_utils/src/eager_or_lazy.rs | 7 +- clippy_utils/src/higher.rs | 30 +++ clippy_utils/src/hir_utils.rs | 2 +- clippy_utils/src/paths.rs | 1 + clippy_utils/src/qualify_min_const_fn.rs | 3 +- lintcheck/src/main.rs | 20 +- rust-toolchain | 2 +- src/main.rs | 20 +- tests/cargo/mod.rs | 22 -- tests/compile-test.rs | 39 +-- tests/dogfood.rs | 12 +- tests/integration.rs | 7 +- tests/ui-internal/invalid_paths.stderr | 2 +- .../toml_disallowed_method/clippy.toml | 7 +- .../conf_disallowed_method.stderr | 8 +- tests/ui-toml/toml_trivially_copy/test.rs | 1 - tests/ui-toml/toml_trivially_copy/test.stderr | 4 +- .../proc_macro_suspicious_else_formatting.rs | 75 ++++++ tests/ui/{box_vec.rs => box_collection.rs} | 8 + tests/ui/box_collection.stderr | 27 ++ tests/ui/box_vec.stderr | 11 - tests/ui/default_trait_access.fixed | 2 +- tests/ui/default_trait_access.rs | 2 +- tests/ui/deref_addrof.fixed | 2 +- tests/ui/deref_addrof.rs | 2 +- tests/ui/derivable_impls.rs | 40 +++ tests/ui/eq_op.rs | 2 +- tests/ui/eta.fixed | 64 +++-- tests/ui/eta.rs | 56 ++-- tests/ui/eta.stderr | 70 +++-- tests/ui/eval_order_dependence.rs | 1 - tests/ui/eval_order_dependence.stderr | 16 +- tests/ui/excessive_precision.fixed | 10 +- tests/ui/excessive_precision.stderr | 32 +-- tests/ui/explicit_deref_methods.fixed | 2 +- tests/ui/explicit_deref_methods.rs | 2 +- tests/ui/fallible_impl_from.rs | 1 + tests/ui/fallible_impl_from.stderr | 16 +- tests/ui/float_cmp.rs | 3 +- tests/ui/float_cmp.stderr | 12 +- tests/ui/for_loop_fixable.fixed | 2 +- tests/ui/for_loop_fixable.rs | 2 +- tests/ui/if_let_some_result.fixed | 28 -- tests/ui/if_let_some_result.rs | 28 -- tests/ui/if_then_panic.fixed | 34 +++ tests/ui/if_then_panic.rs | 38 +++ tests/ui/if_then_panic.stderr | 20 ++ tests/ui/infinite_loop.rs | 1 - tests/ui/infinite_loop.stderr | 22 +- tests/ui/inherent_to_string.rs | 1 - tests/ui/inherent_to_string.stderr | 4 +- tests/ui/iter_not_returning_iterator.rs | 47 ++++ tests/ui/iter_not_returning_iterator.stderr | 16 ++ tests/ui/logic_bug.rs | 2 +- tests/ui/manual_split_once.fixed | 6 + tests/ui/manual_split_once.rs | 6 + tests/ui/manual_split_once.stderr | 28 +- tests/ui/many_single_char_names.rs | 2 +- tests/ui/map_flatten.fixed | 1 + tests/ui/map_flatten.rs | 1 + tests/ui/map_flatten.stderr | 14 +- tests/ui/match_result_ok.fixed | 63 +++++ tests/ui/match_result_ok.rs | 63 +++++ ...e_result.stderr => match_result_ok.stderr} | 19 +- tests/ui/match_single_binding.fixed | 2 +- tests/ui/match_single_binding.rs | 2 +- tests/ui/mut_key.rs | 34 ++- tests/ui/mut_key.stderr | 88 ++++++- tests/ui/needless_borrow.fixed | 24 +- tests/ui/needless_borrow.rs | 24 +- tests/ui/needless_borrow.stderr | 14 +- tests/ui/needless_pass_by_value.rs | 1 - tests/ui/needless_pass_by_value.stderr | 52 ++-- tests/ui/needless_return.fixed | 12 +- tests/ui/needless_return.rs | 12 +- tests/ui/needless_return.stderr | 72 +++--- tests/ui/nonminimal_bool.rs | 2 +- tests/ui/nonminimal_bool_methods.rs | 2 +- tests/ui/op_ref.rs | 1 - tests/ui/op_ref.stderr | 4 +- tests/ui/overflow_check_conditional.rs | 1 - tests/ui/overflow_check_conditional.stderr | 16 +- tests/ui/ptr_arg.rs | 7 +- tests/ui/ptr_arg.stderr | 24 +- tests/ui/repeat_once.fixed | 2 +- tests/ui/repeat_once.rs | 2 +- tests/ui/same_name_method.rs | 111 ++++++++ tests/ui/same_name_method.stderr | 64 +++++ tests/ui/semicolon_if_nothing_returned.rs | 5 +- tests/ui/semicolon_if_nothing_returned.stderr | 12 +- tests/ui/suspicious_else_formatting.rs | 9 + tests/ui/suspicious_else_formatting.stderr | 18 +- tests/ui/trivially_copy_pass_by_ref.rs | 6 +- tests/ui/trivially_copy_pass_by_ref.stderr | 34 +-- tests/ui/while_let_on_iterator.fixed | 18 +- tests/ui/while_let_on_iterator.stderr | 18 +- tests/ui/wrong_self_convention2.rs | 37 +++ 142 files changed, 2227 insertions(+), 1008 deletions(-) create mode 100644 clippy_lints/src/if_then_panic.rs create mode 100644 clippy_lints/src/iter_not_returning_iterator.rs rename clippy_lints/src/{if_let_some_result.rs => match_result_ok.rs} (66%) create mode 100644 clippy_lints/src/same_name_method.rs create mode 100644 clippy_lints/src/types/box_collection.rs delete mode 100644 clippy_lints/src/types/box_vec.rs create mode 100644 tests/ui/auxiliary/proc_macro_suspicious_else_formatting.rs rename tests/ui/{box_vec.rs => box_collection.rs} (86%) create mode 100644 tests/ui/box_collection.stderr delete mode 100644 tests/ui/box_vec.stderr delete mode 100644 tests/ui/if_let_some_result.fixed delete mode 100644 tests/ui/if_let_some_result.rs create mode 100644 tests/ui/if_then_panic.fixed create mode 100644 tests/ui/if_then_panic.rs create mode 100644 tests/ui/if_then_panic.stderr create mode 100644 tests/ui/iter_not_returning_iterator.rs create mode 100644 tests/ui/iter_not_returning_iterator.stderr create mode 100644 tests/ui/match_result_ok.fixed create mode 100644 tests/ui/match_result_ok.rs rename tests/ui/{if_let_some_result.stderr => match_result_ok.stderr} (56%) create mode 100644 tests/ui/same_name_method.rs create mode 100644 tests/ui/same_name_method.stderr diff --git a/.cargo/config b/.cargo/config index 84ae36a46d7..688473f2f9b 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,9 +1,10 @@ [alias] uitest = "test --test compile-test" -dev = "run --target-dir clippy_dev/target --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --" -lintcheck = "run --target-dir lintcheck/target --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- " +dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --" +lintcheck = "run --package lintcheck --bin lintcheck --manifest-path lintcheck/Cargo.toml -- " collect-metadata = "test --test dogfood --features metadata-collector-lint -- run_metadata_collection_lint --ignored" [build] # -Zbinary-dep-depinfo allows us to track which rlib files to use for compiling UI tests rustflags = ["-Zunstable-options", "-Zbinary-dep-depinfo"] +target-dir = "target" diff --git a/.github/ISSUE_TEMPLATE/blank_issue.md b/.github/ISSUE_TEMPLATE/blank_issue.md index 2891d5e5da1..866303a1f9f 100644 --- a/.github/ISSUE_TEMPLATE/blank_issue.md +++ b/.github/ISSUE_TEMPLATE/blank_issue.md @@ -8,7 +8,7 @@ about: Create a blank issue. Additional labels can be added to this issue by including the following command (without the space after the @ symbol): -`@rustbot label +