diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cfe89ad3787..81bcfa21e02c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5895,6 +5895,7 @@ Released 2018-09-13 [`is_digit_ascii_radix`]: https://rust-lang.github.io/rust-clippy/master/index.html#is_digit_ascii_radix [`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements [`items_after_test_module`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module +[`items_before_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_before_use [`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect [`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count [`iter_filter_is_ok`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_filter_is_ok @@ -6555,6 +6556,7 @@ Released 2018-09-13 [`source-item-ordering`]: https://doc.rust-lang.org/clippy/lint_configuration.html#source-item-ordering [`stack-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#stack-size-threshold [`standard-macro-braces`]: https://doc.rust-lang.org/clippy/lint_configuration.html#standard-macro-braces +[`strict-order-of-use`]: https://doc.rust-lang.org/clippy/lint_configuration.html#strict-order-of-use [`struct-field-name-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#struct-field-name-threshold [`suppress-restriction-lint-in-const`]: https://doc.rust-lang.org/clippy/lint_configuration.html#suppress-restriction-lint-in-const [`too-large-for-stack`]: https://doc.rust-lang.org/clippy/lint_configuration.html#too-large-for-stack diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index 7c850b4b023a..5b739fb10b1d 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -957,6 +957,16 @@ could be used with a full path two `MacroMatcher`s have to be added one with the * [`nonstandard_macro_braces`](https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces) +## `strict-order-of-use` +Makes the lint strict, use statements must precede mod and extern crate statements too. (Stylistic Choice) + +**Default Value:** `false` + +--- +**Affected lints:** +* [`items_before_use`](https://rust-lang.github.io/rust-clippy/master/index.html#items_before_use) + + ## `struct-field-name-threshold` The minimum number of struct fields for the lints about field names to trigger diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 87158cec42b2..c9a178ad8a14 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -804,6 +804,9 @@ define_Conf! { /// `crate_name::macro_name` and one with just the macro name. #[lints(nonstandard_macro_braces)] standard_macro_braces: Vec = Vec::new(), + /// Makes the lint strict, use statements must precede mod and extern crate statements too. (Stylistic Choice) + #[lints(items_before_use)] + strict_order_of_use: bool = false, /// The minimum number of struct fields for the lints about field names to trigger #[lints(struct_field_names)] struct_field_name_threshold: u64 = 3, diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index bf43234ff50f..fa349c4dc1a5 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -1,3 +1,4 @@ +#![allow(clippy::items_before_use)] use clippy_config::Conf; use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then}; use clippy_utils::msrvs::{self, Msrv}; diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index 1e3907d9ede0..2a7269ea8e35 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -233,6 +233,7 @@ pub static LINTS: &[&crate::LintInfo] = &[ crate::item_name_repetitions::STRUCT_FIELD_NAMES_INFO, crate::items_after_statements::ITEMS_AFTER_STATEMENTS_INFO, crate::items_after_test_module::ITEMS_AFTER_TEST_MODULE_INFO, + crate::items_before_use::ITEMS_BEFORE_USE_INFO, crate::iter_not_returning_iterator::ITER_NOT_RETURNING_ITERATOR_INFO, crate::iter_over_hash_type::ITER_OVER_HASH_TYPE_INFO, crate::iter_without_into_iter::INTO_ITER_WITHOUT_ITER_INFO, diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index bf3eafe09b3d..7837dd248640 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -1,3 +1,4 @@ +#![allow(clippy::items_before_use)] use clippy_utils::diagnostics::span_lint; use clippy_utils::ty::{get_type_diagnostic_name, implements_trait}; use clippy_utils::{higher, sym}; diff --git a/clippy_lints/src/items_before_use.rs b/clippy_lints/src/items_before_use.rs new file mode 100644 index 000000000000..24e43143e75d --- /dev/null +++ b/clippy_lints/src/items_before_use.rs @@ -0,0 +1,153 @@ +use clippy_config::Conf; +use clippy_utils::diagnostics::span_lint_and_note; +use clippy_utils::sym; +use rustc_hir::{HirId, Item, ItemKind, Mod}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_session::impl_lint_pass; + +declare_clippy_lint! { + /// ### What it does + /// Checks that `use` statements come before all other items (functions, structs, constants, etc.) + /// at the module level, exceptions beinng `mod` and `extern crate` statements before `use` (confgiurable). + /// Ignores all use statements in cfg blocks as it's a common pattern. + /// + /// ### Why is this bad? + /// Having `use` statements scattered throughout a module makes it harder to see all imports + /// at a glance. Keeping imports grouped near the top (with `mod` and `extern crate`) + /// improves code organization and readability. + /// + /// ### Example + /// ```no_run + /// mod my_module { + /// fn rand() {} + /// }; + /// + /// fn foo() {} + /// use std::collections::HashMap; + /// + /// const VALUE: i32 = 32; + /// use std::vec::Vec; + /// ``` + /// Use instead: + /// ```no_run + /// mod my_module { + /// fn rand2() {} + /// }; + /// use std::collections::HashMap; + /// use std::vec::Vec; + /// + /// fn foo() {} + /// const VALUE: i32 = 32; + /// ``` + #[clippy::version = "1.89.0"] + pub ITEMS_BEFORE_USE, + style, + "checks if module level `use` statements precede all other items" +} + +// check function to ignore cfg blocks (allowed in both stylistic and pedantic levels) +fn is_cfg(cx: &LateContext<'_>, item: &Item<'_>) -> bool { + let mut def = item.owner_id.def_id; + + loop { + let attrs = cx.tcx.hir_attrs(item.hir_id()); + if attrs.iter().any(|attr| { + attr.has_any_name(&[ + sym::cfg, + sym::cfg_attr, + sym::cfg_eval, + sym::cfg_hide, + sym::cfg_panic, + sym::cfg_trace, + sym::cfg_doctest, + sym::cfg_version, + sym::cfg_sanitize, + sym::cfg_fmt_debug, + sym::cfg_ub_checks, + sym::cfg_accessible, + sym::cfg_attr_multi, + sym::cfg_attr_trace, + sym::cfg_target_abi, + sym::cfg_sanitizer_cfi, + sym::cfg_target_vendor, + sym::cfg_target_compact, + sym::cfg_target_feature, + sym::cfg_contract_checks, + sym::cfg_overflow_checks, + sym::cfg_boolean_literals, + sym::cfg_relocation_model, + sym::cfg_target_has_atomic, + sym::cfg_emscripten_wasm_eh, + sym::cfg_target_thread_local, + sym::cfg_target_has_reliable_f16_f128, + sym::cfg_target_has_atomic_equal_alignment, + sym::doc_cfg, + sym::doc_cfg_hide, + sym::doc_auto_cfg, + sym::link_cfg, + ]) + }) { + return true; + } + match cx.tcx.opt_parent(def.to_def_id()) { + Some(parent) => def = parent.expect_local(), + None => break false, + } + } +} + +pub struct ItemsBeforeUse { + pub strict_order_of_use: bool, +} + +impl ItemsBeforeUse { + pub fn new(conf: &'static Conf) -> Self { + Self { + strict_order_of_use: conf.strict_order_of_use, + } + } +} + +impl_lint_pass!(ItemsBeforeUse => [ITEMS_BEFORE_USE]); + +impl<'tcx> LateLintPass<'tcx> for ItemsBeforeUse { + fn check_mod(&mut self, cx: &LateContext<'tcx>, module: &'tcx Mod<'tcx>, _hir_id: HirId) { + let mut saw_non_use = false; + let mut saw_mod_or_extern = false; + for item_ids in module.item_ids { + let item = cx.tcx.hir_item(*item_ids); + + if is_cfg(cx, item) { + continue; + } + + match item.kind { + ItemKind::Use(..) => { + // strict mode (pedantic) will lint for mod and extern crare too + if (saw_mod_or_extern || saw_non_use) && self.strict_order_of_use { + span_lint_and_note( + cx, + ITEMS_BEFORE_USE, + item.span, + "strict_order_of_use enabled: use statements should precede all other items including mod and extern crate statements", + None, + "Move this statement to the top of the module", + ); + } else if saw_non_use { + // stylistic (on by default) will only lint for non-mod/extern items + span_lint_and_note( + cx, + ITEMS_BEFORE_USE, + item.span, + "module level use statements should precede all other items", + None, + "consider moving this statement to the top of the module", + ); + } + }, + ItemKind::Mod(..) | ItemKind::ExternCrate(..) => saw_mod_or_extern = true, + _ => saw_non_use = true, + } + } + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index d8bd9dc8d2a6..a48df4f19e4e 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -17,7 +17,8 @@ clippy::must_use_candidate, rustc::diagnostic_outside_of_impl, rustc::untranslatable_diagnostic, - clippy::literal_string_with_formatting_args + clippy::literal_string_with_formatting_args, + clippy::items_before_use )] #![warn( trivial_casts, @@ -184,6 +185,7 @@ mod invalid_upcast_comparisons; mod item_name_repetitions; mod items_after_statements; mod items_after_test_module; +mod items_before_use; mod iter_not_returning_iterator; mod iter_over_hash_type; mod iter_without_into_iter; @@ -951,5 +953,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(|_| Box::new(cloned_ref_to_slice_refs::ClonedRefToSliceRefs::new(conf))); store.register_late_pass(|_| Box::new(infallible_try_from::InfallibleTryFrom)); store.register_late_pass(|_| Box::new(coerce_container_to_any::CoerceContainerToAny)); + store.register_late_pass(move |_| Box::new(items_before_use::ItemsBeforeUse::new(conf))); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/tests/ui-internal/check_clippy_version_attribute.rs b/tests/ui-internal/check_clippy_version_attribute.rs index 897002949e67..ea682a2bd520 100644 --- a/tests/ui-internal/check_clippy_version_attribute.rs +++ b/tests/ui-internal/check_clippy_version_attribute.rs @@ -1,5 +1,6 @@ #![feature(rustc_private)] #![deny(clippy::invalid_clippy_version_attribute, clippy::missing_clippy_version_attribute)] +#![allow(clippy::items_before_use)] #[macro_use] extern crate rustc_middle; diff --git a/tests/ui-internal/check_clippy_version_attribute.stderr b/tests/ui-internal/check_clippy_version_attribute.stderr index 952bc9440303..8929bb2b33a0 100644 --- a/tests/ui-internal/check_clippy_version_attribute.stderr +++ b/tests/ui-internal/check_clippy_version_attribute.stderr @@ -1,5 +1,5 @@ error: this item has an invalid `clippy::version` attribute - --> tests/ui-internal/check_clippy_version_attribute.rs:40:1 + --> tests/ui-internal/check_clippy_version_attribute.rs:41:1 | LL | / declare_tool_lint! { LL | | @@ -19,7 +19,7 @@ LL | #![deny(clippy::invalid_clippy_version_attribute, clippy::missing_clippy_ve = note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info) error: this item has an invalid `clippy::version` attribute - --> tests/ui-internal/check_clippy_version_attribute.rs:49:1 + --> tests/ui-internal/check_clippy_version_attribute.rs:50:1 | LL | / declare_tool_lint! { LL | | @@ -34,7 +34,7 @@ LL | | } = note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info) error: this lint is missing the `clippy::version` attribute or version value - --> tests/ui-internal/check_clippy_version_attribute.rs:61:1 + --> tests/ui-internal/check_clippy_version_attribute.rs:62:1 | LL | / declare_tool_lint! { LL | | @@ -54,7 +54,7 @@ LL | #![deny(clippy::invalid_clippy_version_attribute, clippy::missing_clippy_ve = note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info) error: this lint is missing the `clippy::version` attribute or version value - --> tests/ui-internal/check_clippy_version_attribute.rs:70:1 + --> tests/ui-internal/check_clippy_version_attribute.rs:71:1 | LL | / declare_tool_lint! { LL | | diff --git a/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr b/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr index d24b0cd61629..fbfc69f4c307 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr +++ b/tests/ui-toml/absolute_paths/absolute_paths.allow_crates.stderr @@ -1,5 +1,5 @@ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:14:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:15:13 | LL | let _ = std::path::is_separator(' '); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,31 +11,31 @@ LL | #![deny(clippy::absolute_paths)] | ^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:20:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:21:13 | LL | let _ = ::std::path::MAIN_SEPARATOR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:25:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:26:13 | LL | let _ = std::collections::hash_map::HashMap::::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:28:31 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:29:31 | LL | let _: &std::path::Path = std::path::Path::new(""); | ^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:28:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:29:13 | LL | let _: &std::path::Path = std::path::Path::new(""); | ^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:43:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:44:13 | LL | let _ = std::option::Option::None::; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/absolute_paths/absolute_paths.allow_long.stderr b/tests/ui-toml/absolute_paths/absolute_paths.allow_long.stderr index 0cc6566af3a9..dd492f129488 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths.allow_long.stderr +++ b/tests/ui-toml/absolute_paths/absolute_paths.allow_long.stderr @@ -1,5 +1,5 @@ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:25:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:26:13 | LL | let _ = std::collections::hash_map::HashMap::::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui-toml/absolute_paths/absolute_paths.default.stderr b/tests/ui-toml/absolute_paths/absolute_paths.default.stderr index 53aa9030e0dd..1ee9ada35a05 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths.default.stderr +++ b/tests/ui-toml/absolute_paths/absolute_paths.default.stderr @@ -1,5 +1,5 @@ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:14:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:15:13 | LL | let _ = std::path::is_separator(' '); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,67 +11,67 @@ LL | #![deny(clippy::absolute_paths)] | ^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:20:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:21:13 | LL | let _ = ::std::path::MAIN_SEPARATOR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:25:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:26:13 | LL | let _ = std::collections::hash_map::HashMap::::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:28:31 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:29:31 | LL | let _: &std::path::Path = std::path::Path::new(""); | ^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:28:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:29:13 | LL | let _: &std::path::Path = std::path::Path::new(""); | ^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:37:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:38:13 | LL | let _ = ::core::clone::Clone::clone(&0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:40:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:41:13 | LL | let _ = ::clone(&0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:43:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:44:13 | LL | let _ = std::option::Option::None::; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:65:17 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:66:17 | LL | impl core::fmt::Display for X | ^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:70:18 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:71:18 | LL | where T: core::clone::Clone | ^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:65:32 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:66:32 | LL | impl core::fmt::Display for X | ^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:116:5 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:117:5 | LL | crate::m1::S | ^^^^^^^^^^^^ diff --git a/tests/ui-toml/absolute_paths/absolute_paths.no_short.stderr b/tests/ui-toml/absolute_paths/absolute_paths.no_short.stderr index 70d71f6c4ea1..7cd95a973dcb 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths.no_short.stderr +++ b/tests/ui-toml/absolute_paths/absolute_paths.no_short.stderr @@ -1,5 +1,5 @@ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:14:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:15:13 | LL | let _ = std::path::is_separator(' '); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,85 +11,85 @@ LL | #![deny(clippy::absolute_paths)] | ^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:20:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:21:13 | LL | let _ = ::std::path::MAIN_SEPARATOR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:25:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:26:13 | LL | let _ = std::collections::hash_map::HashMap::::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:28:31 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:29:31 | LL | let _: &std::path::Path = std::path::Path::new(""); | ^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:28:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:29:13 | LL | let _: &std::path::Path = std::path::Path::new(""); | ^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:37:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:38:13 | LL | let _ = ::core::clone::Clone::clone(&0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:40:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:41:13 | LL | let _ = ::clone(&0i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:43:13 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:44:13 | LL | let _ = std::option::Option::None::; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:65:17 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:66:17 | LL | impl core::fmt::Display for X | ^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:70:18 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:71:18 | LL | where T: core::clone::Clone | ^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:65:32 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:66:32 | LL | impl core::fmt::Display for X | ^^^^^^^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:113:14 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:114:14 | LL | pub const _: crate::S = { | ^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:114:9 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:115:9 | LL | let crate::S = m1::S; | ^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:116:5 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:117:5 | LL | crate::m1::S | ^^^^^^^^^^^^ error: consider bringing this path into scope with the `use` keyword - --> tests/ui-toml/absolute_paths/absolute_paths.rs:122:14 + --> tests/ui-toml/absolute_paths/absolute_paths.rs:123:14 | LL | let _ = ::clone(&m1::S); | ^^^^^^^^ diff --git a/tests/ui-toml/absolute_paths/absolute_paths.rs b/tests/ui-toml/absolute_paths/absolute_paths.rs index c024f2f513ce..f2556002409f 100644 --- a/tests/ui-toml/absolute_paths/absolute_paths.rs +++ b/tests/ui-toml/absolute_paths/absolute_paths.rs @@ -5,6 +5,7 @@ //@[allow_long] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/allow_long //@[no_short] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/absolute_paths/no_short #![deny(clippy::absolute_paths)] +#![allow(clippy::items_before_use)] extern crate proc_macros; use proc_macros::{external, inline_macros, with_span}; diff --git a/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs b/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs index 1cfed9790c12..95ca384c5430 100644 --- a/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs +++ b/tests/ui-toml/arbitrary_source_item_ordering/ordering_mixed.rs @@ -4,7 +4,7 @@ //@[default_exp] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/default_exp //@[ord_within] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/arbitrary_source_item_ordering/ord_within -#![allow(dead_code)] +#![allow(dead_code, clippy::items_before_use)] #![warn(clippy::arbitrary_source_item_ordering)] /// This module gets linted before clippy gives up. diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.rs b/tests/ui-toml/excessive_nesting/excessive_nesting.rs index 205cd8ba4ee8..f89597227cce 100644 --- a/tests/ui-toml/excessive_nesting/excessive_nesting.rs +++ b/tests/ui-toml/excessive_nesting/excessive_nesting.rs @@ -13,6 +13,7 @@ clippy::collapsible_if, clippy::blocks_in_conditions, clippy::single_match, + clippy::items_before_use )] #[macro_use] diff --git a/tests/ui-toml/excessive_nesting/excessive_nesting.stderr b/tests/ui-toml/excessive_nesting/excessive_nesting.stderr index bc2c4b8612ec..0f33a690f9cf 100644 --- a/tests/ui-toml/excessive_nesting/excessive_nesting.stderr +++ b/tests/ui-toml/excessive_nesting/excessive_nesting.stderr @@ -1,5 +1,5 @@ error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:25:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:26:25 | LL | let w = { 3 }; | ^^^^^ @@ -9,7 +9,7 @@ LL | let w = { 3 }; = help: to override `-D warnings` add `#[allow(clippy::excessive_nesting)]` error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:72:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:73:17 | LL | / impl C { LL | | @@ -20,7 +20,7 @@ LL | | } = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:87:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:88:25 | LL | let x = { 1 }; // not a warning, but cc is | ^^^^^ @@ -28,7 +28,7 @@ LL | let x = { 1 }; // not a warning, but cc is = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:105:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:106:17 | LL | / pub mod e { LL | | @@ -39,7 +39,7 @@ LL | | } // not here = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:119:18 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:120:18 | LL | a_but_not({{{{{{{{0}}}}}}}}); | ^^^^^^^^^^^ @@ -47,7 +47,7 @@ LL | a_but_not({{{{{{{{0}}}}}}}}); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:121:12 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:122:12 | LL | a.a({{{{{{{{{0}}}}}}}}}); | ^^^^^^^^^^^^^ @@ -55,7 +55,7 @@ LL | a.a({{{{{{{{{0}}}}}}}}}); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:123:12 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:124:12 | LL | (0, {{{{{{{1}}}}}}}); | ^^^^^^^^^ @@ -63,7 +63,7 @@ LL | (0, {{{{{{{1}}}}}}}); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:129:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:130:25 | LL | if true { | _________________________^ @@ -76,7 +76,7 @@ LL | | } = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:142:29 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:143:29 | LL | let z = (|| { | _____________________________^ @@ -89,7 +89,7 @@ LL | | })(); = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:162:13 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:163:13 | LL | y += {{{{{5}}}}}; | ^^^^^ @@ -97,7 +97,7 @@ LL | y += {{{{{5}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:164:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:165:20 | LL | let z = y + {{{{{{{{{5}}}}}}}}}; | ^^^^^^^^^^^^^ @@ -105,7 +105,7 @@ LL | let z = y + {{{{{{{{{5}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:166:12 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:167:12 | LL | [0, {{{{{{{{{{0}}}}}}}}}}]; | ^^^^^^^^^^^^^^^ @@ -113,7 +113,7 @@ LL | [0, {{{{{{{{{{0}}}}}}}}}}]; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:168:25 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:169:25 | LL | let mut xx = [0; {{{{{{{{100}}}}}}}}]; | ^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | let mut xx = [0; {{{{{{{{100}}}}}}}}]; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:170:11 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:171:11 | LL | xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -129,7 +129,7 @@ LL | xx[{{{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}}}]; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:172:13 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:173:13 | LL | &mut {{{{{{{{{{y}}}}}}}}}}; | ^^^^^^^^^^^^^^^ @@ -137,7 +137,7 @@ LL | &mut {{{{{{{{{{y}}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:175:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:176:17 | LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} | ^^^^ @@ -145,7 +145,7 @@ LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:175:28 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:176:28 | LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} | ^^^^^^^^^^ @@ -153,7 +153,7 @@ LL | for i in {{{{xx}}}} {{{{{{{{}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:179:28 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:180:28 | LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} | ^^^^^^^^^^^^^ @@ -161,7 +161,7 @@ LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:179:48 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:180:48 | LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} | ^^^^^^^^ @@ -169,7 +169,7 @@ LL | while let Some(i) = {{{{{{Some(1)}}}}}} {{{{{{{}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:183:14 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:184:14 | LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} | ^^^^^^^^^^^^^^ @@ -177,7 +177,7 @@ LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:183:35 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:184:35 | LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} | ^^^^^^^^^^^^ @@ -185,7 +185,7 @@ LL | while {{{{{{{{true}}}}}}}} {{{{{{{{{}}}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:187:23 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:188:23 | LL | let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL | let d = D { d: {{{{{{{{{{{{{{{{{{{{{{{3}}}}}}}}}}}}}}}}}}}}}}} }; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:190:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:191:8 | LL | {{{{1;}}}}..{{{{{{3}}}}}}; | ^^^^ @@ -201,7 +201,7 @@ LL | {{{{1;}}}}..{{{{{{3}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:190:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:191:20 | LL | {{{{1;}}}}..{{{{{{3}}}}}}; | ^^^^^^^ @@ -209,7 +209,7 @@ LL | {{{{1;}}}}..{{{{{{3}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:193:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:194:8 | LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; | ^^^^ @@ -217,7 +217,7 @@ LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:193:21 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:194:21 | LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL | {{{{1;}}}}..={{{{{{{{{{{{{{{{{{{{{{{{{{6}}}}}}}}}}}}}}}}}}}}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:196:10 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:197:10 | LL | ..{{{{{{{5}}}}}}}; | ^^^^^^^^^ @@ -233,7 +233,7 @@ LL | ..{{{{{{{5}}}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:198:11 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:199:11 | LL | ..={{{{{3}}}}}; | ^^^^^ @@ -241,7 +241,7 @@ LL | ..={{{{{3}}}}}; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:200:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:201:8 | LL | {{{{{1;}}}}}..; | ^^^^^^ @@ -249,7 +249,7 @@ LL | {{{{{1;}}}}}..; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:203:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:204:20 | LL | loop { break {{{{1}}}} }; | ^^^^^ @@ -257,7 +257,7 @@ LL | loop { break {{{{1}}}} }; = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:205:13 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:206:13 | LL | loop {{{{{{}}}}}} | ^^^^^^ @@ -265,7 +265,7 @@ LL | loop {{{{{{}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:208:14 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:209:14 | LL | match {{{{{{true}}}}}} { | ^^^^^^^^^^ @@ -273,7 +273,7 @@ LL | match {{{{{{true}}}}}} { = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:210:20 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:211:20 | LL | true => {{{{}}}}, | ^^ @@ -281,7 +281,7 @@ LL | true => {{{{}}}}, = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:212:21 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:213:21 | LL | false => {{{{}}}}, | ^^ @@ -289,7 +289,7 @@ LL | false => {{{{}}}}, = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:219:17 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:220:17 | LL | / { LL | | @@ -300,7 +300,7 @@ LL | | } = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:229:28 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:230:28 | LL | async fn c() -> u32 {{{{{{{0}}}}}}} | ^^^^^^^^^ @@ -308,7 +308,7 @@ LL | async fn c() -> u32 {{{{{{{0}}}}}}} = help: try refactoring your code to minimize nesting error: this block is too nested - --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:236:8 + --> tests/ui-toml/excessive_nesting/excessive_nesting.rs:237:8 | LL | {{{{b().await}}}}; | ^^^^^^^^^^^ diff --git a/tests/ui-toml/strict_order_of_use/clippy.toml b/tests/ui-toml/strict_order_of_use/clippy.toml new file mode 100644 index 000000000000..75731955bb35 --- /dev/null +++ b/tests/ui-toml/strict_order_of_use/clippy.toml @@ -0,0 +1 @@ +strict-order-of-use = true diff --git a/tests/ui-toml/strict_order_of_use/items_before_use.rs b/tests/ui-toml/strict_order_of_use/items_before_use.rs new file mode 100644 index 000000000000..a255e4e3eeeb --- /dev/null +++ b/tests/ui-toml/strict_order_of_use/items_before_use.rs @@ -0,0 +1,28 @@ +#![warn(clippy::items_before_use)] + +mod demo { + use std::fmt; // OK: at the top + + extern crate core; + use std::io; //~ items_before_use + + mod submodule {} + use std::fs; //~ items_before_use + + fn f() {} + use std::str; //~ items_before_use + + #[cfg(test)] + mod test_mod { + use std::collections::HashMap; // ignored (inside cfg block) + fn test_fn() {} + } + + #[cfg(feature = "magic")] + use std::vec::Vec; // ignored (inside cfg block) + + struct Data; + use std::borrow::Cow; //~ items_before_use +} + +fn main() {} diff --git a/tests/ui-toml/strict_order_of_use/items_before_use.stderr b/tests/ui-toml/strict_order_of_use/items_before_use.stderr new file mode 100644 index 000000000000..4039d75ab13d --- /dev/null +++ b/tests/ui-toml/strict_order_of_use/items_before_use.stderr @@ -0,0 +1,36 @@ +error: strict_order_of_use enabled: use statements should precede all other items including mod and extern crate statements + --> tests/ui-toml/strict_order_of_use/items_before_use.rs:7:5 + | +LL | use std::io; + | ^^^^^^^^^^^^ + | + = note: Move this statement to the top of the module + = note: `-D clippy::items-before-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::items_before_use)]` + +error: strict_order_of_use enabled: use statements should precede all other items including mod and extern crate statements + --> tests/ui-toml/strict_order_of_use/items_before_use.rs:10:5 + | +LL | use std::fs; + | ^^^^^^^^^^^^ + | + = note: Move this statement to the top of the module + +error: strict_order_of_use enabled: use statements should precede all other items including mod and extern crate statements + --> tests/ui-toml/strict_order_of_use/items_before_use.rs:13:5 + | +LL | use std::str; + | ^^^^^^^^^^^^^ + | + = note: Move this statement to the top of the module + +error: strict_order_of_use enabled: use statements should precede all other items including mod and extern crate statements + --> tests/ui-toml/strict_order_of_use/items_before_use.rs:25:5 + | +LL | use std::borrow::Cow; + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: Move this statement to the top of the module + +error: aborting due to 4 previous errors + diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index 6ee77ebd8ece..9b51022c7870 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -71,6 +71,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect source-item-ordering stack-size-threshold standard-macro-braces + strict-order-of-use struct-field-name-threshold suppress-restriction-lint-in-const third-party @@ -165,6 +166,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect source-item-ordering stack-size-threshold standard-macro-braces + strict-order-of-use struct-field-name-threshold suppress-restriction-lint-in-const third-party @@ -259,6 +261,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni source-item-ordering stack-size-threshold standard-macro-braces + strict-order-of-use struct-field-name-threshold suppress-restriction-lint-in-const third-party diff --git a/tests/ui/absurd-extreme-comparisons.rs b/tests/ui/absurd-extreme-comparisons.rs index 793961d30f0d..264b6739bef4 100644 --- a/tests/ui/absurd-extreme-comparisons.rs +++ b/tests/ui/absurd-extreme-comparisons.rs @@ -4,7 +4,8 @@ clippy::eq_op, clippy::no_effect, clippy::unnecessary_operation, - clippy::needless_pass_by_value + clippy::needless_pass_by_value, + clippy::items_before_use )] #[rustfmt::skip] diff --git a/tests/ui/absurd-extreme-comparisons.stderr b/tests/ui/absurd-extreme-comparisons.stderr index 6df50c15e8cd..a7acf76c94bd 100644 --- a/tests/ui/absurd-extreme-comparisons.stderr +++ b/tests/ui/absurd-extreme-comparisons.stderr @@ -1,5 +1,5 @@ error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:14:5 + --> tests/ui/absurd-extreme-comparisons.rs:15:5 | LL | u <= 0; | ^^^^^^ @@ -9,7 +9,7 @@ LL | u <= 0; = help: to override `-D warnings` add `#[allow(clippy::absurd_extreme_comparisons)]` error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:17:5 + --> tests/ui/absurd-extreme-comparisons.rs:18:5 | LL | u <= Z; | ^^^^^^ @@ -17,7 +17,7 @@ LL | u <= Z; = help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == Z` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:20:5 + --> tests/ui/absurd-extreme-comparisons.rs:21:5 | LL | u < Z; | ^^^^^ @@ -25,7 +25,7 @@ LL | u < Z; = help: because `Z` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:23:5 + --> tests/ui/absurd-extreme-comparisons.rs:24:5 | LL | Z >= u; | ^^^^^^ @@ -33,7 +33,7 @@ LL | Z >= u; = help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `Z == u` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:26:5 + --> tests/ui/absurd-extreme-comparisons.rs:27:5 | LL | Z > u; | ^^^^^ @@ -41,7 +41,7 @@ LL | Z > u; = help: because `Z` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:29:5 + --> tests/ui/absurd-extreme-comparisons.rs:30:5 | LL | u > u32::MAX; | ^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | u > u32::MAX; = help: because `u32::MAX` is the maximum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:32:5 + --> tests/ui/absurd-extreme-comparisons.rs:33:5 | LL | u >= u32::MAX; | ^^^^^^^^^^^^^ @@ -57,7 +57,7 @@ LL | u >= u32::MAX; = help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == u32::MAX` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:35:5 + --> tests/ui/absurd-extreme-comparisons.rs:36:5 | LL | u32::MAX < u; | ^^^^^^^^^^^^ @@ -65,7 +65,7 @@ LL | u32::MAX < u; = help: because `u32::MAX` is the maximum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:38:5 + --> tests/ui/absurd-extreme-comparisons.rs:39:5 | LL | u32::MAX <= u; | ^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | u32::MAX <= u; = help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u32::MAX == u` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:41:5 + --> tests/ui/absurd-extreme-comparisons.rs:42:5 | LL | 1-1 > u; | ^^^^^^^ @@ -81,7 +81,7 @@ LL | 1-1 > u; = help: because `1-1` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:44:5 + --> tests/ui/absurd-extreme-comparisons.rs:45:5 | LL | u >= !0; | ^^^^^^^ @@ -89,7 +89,7 @@ LL | u >= !0; = help: because `!0` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == !0` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:47:5 + --> tests/ui/absurd-extreme-comparisons.rs:48:5 | LL | u <= 12 - 2*6; | ^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL | u <= 12 - 2*6; = help: because `12 - 2*6` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 12 - 2*6` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:51:5 + --> tests/ui/absurd-extreme-comparisons.rs:52:5 | LL | i < -127 - 1; | ^^^^^^^^^^^^ @@ -105,7 +105,7 @@ LL | i < -127 - 1; = help: because `-127 - 1` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:54:5 + --> tests/ui/absurd-extreme-comparisons.rs:55:5 | LL | i8::MAX >= i; | ^^^^^^^^^^^^ @@ -113,7 +113,7 @@ LL | i8::MAX >= i; = help: because `i8::MAX` is the maximum value for this type, this comparison is always true error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:57:5 + --> tests/ui/absurd-extreme-comparisons.rs:58:5 | LL | 3-7 < i32::MIN; | ^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | 3-7 < i32::MIN; = help: because `i32::MIN` is the minimum value for this type, this comparison is always false error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:61:5 + --> tests/ui/absurd-extreme-comparisons.rs:62:5 | LL | b >= true; | ^^^^^^^^^ @@ -129,7 +129,7 @@ LL | b >= true; = help: because `true` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `b == true` instead error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false - --> tests/ui/absurd-extreme-comparisons.rs:64:5 + --> tests/ui/absurd-extreme-comparisons.rs:65:5 | LL | false > b; | ^^^^^^^^^ @@ -137,7 +137,7 @@ LL | false > b; = help: because `false` is the minimum value for this type, this comparison is always false error: <-comparison of unit values detected. This will always be false - --> tests/ui/absurd-extreme-comparisons.rs:69:5 + --> tests/ui/absurd-extreme-comparisons.rs:70:5 | LL | () < {}; | ^^^^^^^ diff --git a/tests/ui/borrow_box.fixed b/tests/ui/borrow_box.fixed index e6e7f74af7cf..ce9873e8f34e 100644 --- a/tests/ui/borrow_box.fixed +++ b/tests/ui/borrow_box.fixed @@ -4,7 +4,8 @@ clippy::uninlined_format_args, clippy::disallowed_names, clippy::needless_pass_by_ref_mut, - clippy::needless_lifetimes + clippy::needless_lifetimes, + clippy::items_before_use )] use std::fmt::Display; diff --git a/tests/ui/borrow_box.rs b/tests/ui/borrow_box.rs index 43cf809306b3..cef64aefa513 100644 --- a/tests/ui/borrow_box.rs +++ b/tests/ui/borrow_box.rs @@ -4,7 +4,8 @@ clippy::uninlined_format_args, clippy::disallowed_names, clippy::needless_pass_by_ref_mut, - clippy::needless_lifetimes + clippy::needless_lifetimes, + clippy::items_before_use )] use std::fmt::Display; diff --git a/tests/ui/borrow_box.stderr b/tests/ui/borrow_box.stderr index dbe3757dd435..0c2c7c0586f7 100644 --- a/tests/ui/borrow_box.stderr +++ b/tests/ui/borrow_box.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:25:14 + --> tests/ui/borrow_box.rs:26:14 | LL | let foo: &Box; | ^^^^^^^^^^ help: try: `&bool` @@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)] | ^^^^^^^^^^^^^^^^^^^^ error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:30:10 + --> tests/ui/borrow_box.rs:31:10 | LL | foo: &'a Box, | ^^^^^^^^^^^^^ help: try: `&'a bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:35:17 + --> tests/ui/borrow_box.rs:36:17 | LL | fn test4(a: &Box); | ^^^^^^^^^^ help: try: `&bool` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:96:25 + --> tests/ui/borrow_box.rs:97:25 | LL | pub fn test14(_display: &Box) {} | ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:99:25 + --> tests/ui/borrow_box.rs:100:25 | LL | pub fn test15(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:102:29 + --> tests/ui/borrow_box.rs:103:29 | LL | pub fn test16<'a>(_display: &'a Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:105:25 + --> tests/ui/borrow_box.rs:106:25 | LL | pub fn test17(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:108:25 + --> tests/ui/borrow_box.rs:109:25 | LL | pub fn test18(_display: &Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:111:29 + --> tests/ui/borrow_box.rs:112:29 | LL | pub fn test19<'a>(_display: &'a Box) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)` error: you seem to be trying to use `&Box`. Consider using just `&T` - --> tests/ui/borrow_box.rs:117:25 + --> tests/ui/borrow_box.rs:118:25 | LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` diff --git a/tests/ui/box_default.fixed b/tests/ui/box_default.fixed index 80000f5de4fd..ec5c3b74b299 100644 --- a/tests/ui/box_default.fixed +++ b/tests/ui/box_default.fixed @@ -1,5 +1,9 @@ #![warn(clippy::box_default)] -#![allow(clippy::boxed_local, clippy::default_constructed_unit_structs)] +#![allow( + clippy::boxed_local, + clippy::default_constructed_unit_structs, + clippy::items_before_use +)] #[derive(Default)] struct ImplementsDefault; diff --git a/tests/ui/box_default.rs b/tests/ui/box_default.rs index 4681016d7cd3..d1a6f47cd011 100644 --- a/tests/ui/box_default.rs +++ b/tests/ui/box_default.rs @@ -1,5 +1,9 @@ #![warn(clippy::box_default)] -#![allow(clippy::boxed_local, clippy::default_constructed_unit_structs)] +#![allow( + clippy::boxed_local, + clippy::default_constructed_unit_structs, + clippy::items_before_use +)] #[derive(Default)] struct ImplementsDefault; diff --git a/tests/ui/box_default.stderr b/tests/ui/box_default.stderr index f63d97665b34..e2e8c4097e57 100644 --- a/tests/ui/box_default.stderr +++ b/tests/ui/box_default.stderr @@ -1,5 +1,5 @@ error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:34:32 + --> tests/ui/box_default.rs:38:32 | LL | let string1: Box = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` @@ -8,55 +8,55 @@ LL | let string1: Box = Box::new(Default::default()); = help: to override `-D warnings` add `#[allow(clippy::box_default)]` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:36:32 + --> tests/ui/box_default.rs:40:32 | LL | let string2: Box = Box::new(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:38:41 + --> tests/ui/box_default.rs:42:41 | LL | let impl1: Box = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:40:29 + --> tests/ui/box_default.rs:44:29 | LL | let vec: Box> = Box::new(Vec::new()); | ^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:42:25 + --> tests/ui/box_default.rs:46:25 | LL | let byte: Box = Box::new(u8::default()); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:44:45 + --> tests/ui/box_default.rs:48:45 | LL | let vec2: Box> = Box::new(vec![]); | ^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:46:32 + --> tests/ui/box_default.rs:50:32 | LL | let vec3: Box> = Box::new(Vec::from([])); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:49:25 + --> tests/ui/box_default.rs:53:25 | LL | let plain_default = Box::new(Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:67:16 + --> tests/ui/box_default.rs:71:16 | LL | call_ty_fn(Box::new(u8::default())); | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` error: `Box::new(_)` of default value - --> tests/ui/box_default.rs:95:17 + --> tests/ui/box_default.rs:99:17 | LL | Self::x(Box::new(T::default())); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()` diff --git a/tests/ui/crashes/ice-4968.rs b/tests/ui/crashes/ice-4968.rs index 542cb63516da..112e8fb6e1b8 100644 --- a/tests/ui/crashes/ice-4968.rs +++ b/tests/ui/crashes/ice-4968.rs @@ -2,7 +2,7 @@ // Test for https://github.com/rust-lang/rust-clippy/issues/4968 #![warn(clippy::unsound_collection_transmute)] -#![allow(clippy::transmute_undefined_repr)] +#![allow(clippy::transmute_undefined_repr, clippy::items_before_use)] trait Trait { type Assoc; diff --git a/tests/ui/derive_partial_eq_without_eq.fixed b/tests/ui/derive_partial_eq_without_eq.fixed index 00f51d6acb94..449f8f9dc617 100644 --- a/tests/ui/derive_partial_eq_without_eq.fixed +++ b/tests/ui/derive_partial_eq_without_eq.fixed @@ -1,4 +1,4 @@ -#![allow(unused)] +#![allow(unused, clippy::items_before_use)] #![warn(clippy::derive_partial_eq_without_eq)] // Don't warn on structs that aren't PartialEq diff --git a/tests/ui/derive_partial_eq_without_eq.rs b/tests/ui/derive_partial_eq_without_eq.rs index 073330468d31..b8e49c762736 100644 --- a/tests/ui/derive_partial_eq_without_eq.rs +++ b/tests/ui/derive_partial_eq_without_eq.rs @@ -1,4 +1,4 @@ -#![allow(unused)] +#![allow(unused, clippy::items_before_use)] #![warn(clippy::derive_partial_eq_without_eq)] // Don't warn on structs that aren't PartialEq diff --git a/tests/ui/doc_suspicious_footnotes.fixed b/tests/ui/doc_suspicious_footnotes.fixed index 9ed3fd4ef31c..2cce4b575ffa 100644 --- a/tests/ui/doc_suspicious_footnotes.fixed +++ b/tests/ui/doc_suspicious_footnotes.fixed @@ -1,5 +1,5 @@ #![warn(clippy::doc_suspicious_footnotes)] -#![allow(clippy::needless_raw_string_hashes)] +#![allow(clippy::needless_raw_string_hashes, clippy::items_before_use)] //! This is not a footnote[^1]. //! //! [^1]: diff --git a/tests/ui/doc_suspicious_footnotes.rs b/tests/ui/doc_suspicious_footnotes.rs index 9a8d0dcf4754..7f578dab2e38 100644 --- a/tests/ui/doc_suspicious_footnotes.rs +++ b/tests/ui/doc_suspicious_footnotes.rs @@ -1,5 +1,5 @@ #![warn(clippy::doc_suspicious_footnotes)] -#![allow(clippy::needless_raw_string_hashes)] +#![allow(clippy::needless_raw_string_hashes, clippy::items_before_use)] //! This is not a footnote[^1]. //~^ doc_suspicious_footnotes //! diff --git a/tests/ui/doc_unsafe.rs b/tests/ui/doc_unsafe.rs index 7146fd7941ab..461a03442c23 100644 --- a/tests/ui/doc_unsafe.rs +++ b/tests/ui/doc_unsafe.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(clippy::let_unit_value, clippy::needless_pass_by_ref_mut)] +#![allow(clippy::let_unit_value, clippy::needless_pass_by_ref_mut, clippy::items_before_use)] extern crate proc_macros; use proc_macros::external; diff --git a/tests/ui/enum_glob_use.fixed b/tests/ui/enum_glob_use.fixed index 881493f3d5ff..6aa602e8a1d6 100644 --- a/tests/ui/enum_glob_use.fixed +++ b/tests/ui/enum_glob_use.fixed @@ -1,5 +1,5 @@ #![warn(clippy::enum_glob_use)] -#![allow(unused)] +#![allow(unused, clippy::items_before_use)] #![warn(unused_imports)] use std::cmp::Ordering::Less; diff --git a/tests/ui/enum_glob_use.rs b/tests/ui/enum_glob_use.rs index a510462ecb2f..b8f8e56f0d66 100644 --- a/tests/ui/enum_glob_use.rs +++ b/tests/ui/enum_glob_use.rs @@ -1,5 +1,5 @@ #![warn(clippy::enum_glob_use)] -#![allow(unused)] +#![allow(unused, clippy::items_before_use)] #![warn(unused_imports)] use std::cmp::Ordering::*; diff --git a/tests/ui/filter_map_identity.fixed b/tests/ui/filter_map_identity.fixed index c9e2c5f5049f..9cb370176085 100644 --- a/tests/ui/filter_map_identity.fixed +++ b/tests/ui/filter_map_identity.fixed @@ -1,4 +1,9 @@ -#![allow(unused_imports, clippy::needless_return, clippy::useless_vec)] +#![allow( + unused_imports, + clippy::needless_return, + clippy::useless_vec, + clippy::items_before_use +)] #![warn(clippy::filter_map_identity)] #![feature(stmt_expr_attributes)] diff --git a/tests/ui/filter_map_identity.rs b/tests/ui/filter_map_identity.rs index 4c8d48f5221f..d17a4a48193c 100644 --- a/tests/ui/filter_map_identity.rs +++ b/tests/ui/filter_map_identity.rs @@ -1,4 +1,9 @@ -#![allow(unused_imports, clippy::needless_return, clippy::useless_vec)] +#![allow( + unused_imports, + clippy::needless_return, + clippy::useless_vec, + clippy::items_before_use +)] #![warn(clippy::filter_map_identity)] #![feature(stmt_expr_attributes)] diff --git a/tests/ui/filter_map_identity.stderr b/tests/ui/filter_map_identity.stderr index 26b6e0bc7b34..287dedb0f2c4 100644 --- a/tests/ui/filter_map_identity.stderr +++ b/tests/ui/filter_map_identity.stderr @@ -1,5 +1,5 @@ error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:28:45 + --> tests/ui/filter_map_identity.rs:33:45 | LL | copy_vec_non_inferred().into_iter().filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` @@ -8,127 +8,127 @@ LL | copy_vec_non_inferred().into_iter().filter_map(|x| x); = help: to override `-D warnings` add `#[allow(clippy::filter_map_identity)]` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:31:45 + --> tests/ui/filter_map_identity.rs:36:45 | LL | copy_vec_non_inferred().into_iter().filter_map(std::convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:34:45 + --> tests/ui/filter_map_identity.rs:39:45 | LL | copy_vec_non_inferred().into_iter().filter_map(identity); | ^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:37:45 + --> tests/ui/filter_map_identity.rs:42:45 | LL | copy_vec_non_inferred().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:40:45 + --> tests/ui/filter_map_identity.rs:45:45 | LL | copy_vec_non_inferred().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:43:36 + --> tests/ui/filter_map_identity.rs:48:36 | LL | non_copy_vec().into_iter().filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:46:36 + --> tests/ui/filter_map_identity.rs:51:36 | LL | non_copy_vec().into_iter().filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:49:36 + --> tests/ui/filter_map_identity.rs:54:36 | LL | non_copy_vec().into_iter().filter_map(std::convert::identity); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:52:36 + --> tests/ui/filter_map_identity.rs:57:36 | LL | non_copy_vec().into_iter().filter_map(identity); | ^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:55:36 + --> tests/ui/filter_map_identity.rs:60:36 | LL | non_copy_vec().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:58:36 + --> tests/ui/filter_map_identity.rs:63:36 | LL | non_copy_vec().into_iter().filter_map(|x| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:61:39 + --> tests/ui/filter_map_identity.rs:66:39 | LL | copy_vec::().into_iter().filter_map(|x: Option<_>| x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:64:39 + --> tests/ui/filter_map_identity.rs:69:39 | LL | copy_vec::().into_iter().filter_map(|x: Option<_>| x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:67:39 + --> tests/ui/filter_map_identity.rs:72:39 | LL | copy_vec::().into_iter().filter_map(|x: Option<_>| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:70:39 + --> tests/ui/filter_map_identity.rs:75:39 | LL | copy_vec::().into_iter().filter_map(|x: Option<_>| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:74:39 + --> tests/ui/filter_map_identity.rs:79:39 | LL | copy_vec::().into_iter().filter_map(|x: Option| x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:77:39 + --> tests/ui/filter_map_identity.rs:82:39 | LL | copy_vec::().into_iter().filter_map(|x: Option| x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:80:39 + --> tests/ui/filter_map_identity.rs:85:39 | LL | copy_vec::().into_iter().filter_map(|x: Option| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:83:39 + --> tests/ui/filter_map_identity.rs:88:39 | LL | copy_vec::().into_iter().filter_map(|x: Option| return x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:87:43 + --> tests/ui/filter_map_identity.rs:92:43 | LL | copy_vec::().into_iter().filter_map(|x: Option| -> Option {{ x }}); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:91:43 + --> tests/ui/filter_map_identity.rs:96:43 | LL | copy_vec::().into_iter().filter_map(|x: Option| -> Option {{ return x }}); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `flatten()` error: use of `filter_map` with an identity function - --> tests/ui/filter_map_identity.rs:96:37 + --> tests/ui/filter_map_identity.rs:101:37 | LL | opaque::().into_iter().filter_map(|x| x); | ^^^^^^^^^^^^^^^^^ help: try: `flatten()` diff --git a/tests/ui/impl.rs b/tests/ui/impl.rs index 1b9e4a5cdee1..96cf1e13aea7 100644 --- a/tests/ui/impl.rs +++ b/tests/ui/impl.rs @@ -1,4 +1,4 @@ -#![allow(dead_code, clippy::extra_unused_lifetimes)] +#![allow(dead_code, clippy::extra_unused_lifetimes, clippy::items_before_use)] #![warn(clippy::multiple_inherent_impl)] struct MyStruct; diff --git a/tests/ui/infinite_iter.rs b/tests/ui/infinite_iter.rs index 002a791a6579..b6cc99215c3c 100644 --- a/tests/ui/infinite_iter.rs +++ b/tests/ui/infinite_iter.rs @@ -1,4 +1,8 @@ -#![allow(clippy::uninlined_format_args, clippy::double_ended_iterator_last)] +#![allow( + clippy::uninlined_format_args, + clippy::double_ended_iterator_last, + clippy::items_before_use +)] use std::iter::repeat; fn square_is_lower_64(x: &u32) -> bool { diff --git a/tests/ui/infinite_iter.stderr b/tests/ui/infinite_iter.stderr index 47133a2ea62e..453a8f0eb351 100644 --- a/tests/ui/infinite_iter.stderr +++ b/tests/ui/infinite_iter.stderr @@ -1,29 +1,29 @@ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:11:5 + --> tests/ui/infinite_iter.rs:15:5 | LL | repeat(0_u8).collect::>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> tests/ui/infinite_iter.rs:9:8 + --> tests/ui/infinite_iter.rs:13:8 | LL | #[deny(clippy::infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:15:5 + --> tests/ui/infinite_iter.rs:19:5 | LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:19:5 + --> tests/ui/infinite_iter.rs:23:5 | LL | (0..8_u64).chain(0..).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:28:5 + --> tests/ui/infinite_iter.rs:32:5 | LL | / (0..8_u32) LL | | @@ -34,37 +34,37 @@ LL | | .for_each(|x| println!("{}", x)); | |________________________________________^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:37:5 + --> tests/ui/infinite_iter.rs:41:5 | LL | (0_usize..).flat_map(|x| 0..x).product::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:41:5 + --> tests/ui/infinite_iter.rs:45:5 | LL | (0_u64..).filter(|x| x % 2 == 0).last(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:53:5 + --> tests/ui/infinite_iter.rs:57:5 | LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> tests/ui/infinite_iter.rs:50:8 + --> tests/ui/infinite_iter.rs:54:8 | LL | #[deny(clippy::maybe_infinite_iter)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:57:5 + --> tests/ui/infinite_iter.rs:61:5 | LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:61:5 + --> tests/ui/infinite_iter.rs:65:5 | LL | / (1..) LL | | @@ -76,31 +76,31 @@ LL | | .min(); | |______________^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:69:5 + --> tests/ui/infinite_iter.rs:73:5 | LL | (0..).find(|x| *x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:73:5 + --> tests/ui/infinite_iter.rs:77:5 | LL | (0..).position(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:77:5 + --> tests/ui/infinite_iter.rs:81:5 | LL | (0..).any(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: possible infinite iteration detected - --> tests/ui/infinite_iter.rs:81:5 + --> tests/ui/infinite_iter.rs:85:5 | LL | (0..).all(|x| x == 24); | ^^^^^^^^^^^^^^^^^^^^^^ error: infinite iteration detected - --> tests/ui/infinite_iter.rs:107:31 + --> tests/ui/infinite_iter.rs:111:31 | LL | let _: HashSet = (0..).collect(); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/infinite_loop.rs b/tests/ui/infinite_loop.rs index 8ff7f3b0c18d..c9b457412a06 100644 --- a/tests/ui/infinite_loop.rs +++ b/tests/ui/infinite_loop.rs @@ -1,3 +1,5 @@ +#![allow(clippy::items_before_use)] + fn fn_val(i: i32) -> i32 { unimplemented!() } diff --git a/tests/ui/infinite_loop.stderr b/tests/ui/infinite_loop.stderr index 04da9776c302..7ba1374d64f4 100644 --- a/tests/ui/infinite_loop.stderr +++ b/tests/ui/infinite_loop.stderr @@ -1,5 +1,5 @@ error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:20:11 + --> tests/ui/infinite_loop.rs:22:11 | LL | while y < 10 { | ^^^^^^ @@ -8,7 +8,7 @@ LL | while y < 10 { = note: `#[deny(clippy::while_immutable_condition)]` on by default error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:27:11 + --> tests/ui/infinite_loop.rs:29:11 | LL | while y < 10 && x < 3 { | ^^^^^^^^^^^^^^^ @@ -16,7 +16,7 @@ LL | while y < 10 && x < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:36:11 + --> tests/ui/infinite_loop.rs:38:11 | LL | while !cond { | ^^^^^ @@ -24,7 +24,7 @@ LL | while !cond { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:82:11 + --> tests/ui/infinite_loop.rs:84:11 | LL | while i < 3 { | ^^^^^ @@ -32,7 +32,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:89:11 + --> tests/ui/infinite_loop.rs:91:11 | LL | while i < 3 && j > 0 { | ^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | while i < 3 && j > 0 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:95:11 + --> tests/ui/infinite_loop.rs:97:11 | LL | while i < 3 { | ^^^^^ @@ -48,7 +48,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:112:11 + --> tests/ui/infinite_loop.rs:114:11 | LL | while i < 3 { | ^^^^^ @@ -56,7 +56,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:119:11 + --> tests/ui/infinite_loop.rs:121:11 | LL | while i < 3 { | ^^^^^ @@ -64,7 +64,7 @@ LL | while i < 3 { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:187:15 + --> tests/ui/infinite_loop.rs:189:15 | LL | while self.count < n { | ^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | while self.count < n { = note: this may lead to an infinite or to a never running loop error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:197:11 + --> tests/ui/infinite_loop.rs:199:11 | LL | while y < 10 { | ^^^^^^ @@ -82,7 +82,7 @@ LL | while y < 10 { = help: rewrite it as `if cond { loop { } }` error: variables in the condition are not mutated in the loop body - --> tests/ui/infinite_loop.rs:206:11 + --> tests/ui/infinite_loop.rs:208:11 | LL | while y < 10 { | ^^^^^^ diff --git a/tests/ui/into_iter_on_ref.fixed b/tests/ui/into_iter_on_ref.fixed index 7626569fd422..a60362ace14d 100644 --- a/tests/ui/into_iter_on_ref.fixed +++ b/tests/ui/into_iter_on_ref.fixed @@ -1,4 +1,4 @@ -#![allow(clippy::useless_vec, clippy::needless_borrow)] +#![allow(clippy::useless_vec, clippy::needless_borrow, clippy::items_before_use)] #![warn(clippy::into_iter_on_ref)] struct X; diff --git a/tests/ui/into_iter_on_ref.rs b/tests/ui/into_iter_on_ref.rs index 286a62c69ce5..5036304d49e3 100644 --- a/tests/ui/into_iter_on_ref.rs +++ b/tests/ui/into_iter_on_ref.rs @@ -1,4 +1,4 @@ -#![allow(clippy::useless_vec, clippy::needless_borrow)] +#![allow(clippy::useless_vec, clippy::needless_borrow, clippy::items_before_use)] #![warn(clippy::into_iter_on_ref)] struct X; diff --git a/tests/ui/items_before_use.rs b/tests/ui/items_before_use.rs new file mode 100644 index 000000000000..a9bb2833c79b --- /dev/null +++ b/tests/ui/items_before_use.rs @@ -0,0 +1,28 @@ +#![warn(clippy::items_before_use)] + +mod demo { + use std::fmt; // OK: at the top + + extern crate core; + use std::io; // OK: after extern crate (only linted for strict) + + mod submodule {} + use std::fs; // OK: after mod (only linted for strict) + + fn f() {} + use std::str; //~ items_before_use + + #[cfg(test)] + mod test_mod { + use std::collections::HashMap; // ignored (inside cfg block) + fn test_fn() {} + } + + #[cfg(feature = "magic")] + use std::vec::Vec; // ignored + + struct Data; + use std::borrow::Cow; //~ items_before_use +} + +fn main() {} diff --git a/tests/ui/items_before_use.stderr b/tests/ui/items_before_use.stderr new file mode 100644 index 000000000000..cfe1f36f117d --- /dev/null +++ b/tests/ui/items_before_use.stderr @@ -0,0 +1,20 @@ +error: module level use statements should precede all other items + --> tests/ui/items_before_use.rs:13:5 + | +LL | use std::str; + | ^^^^^^^^^^^^^ + | + = note: consider moving this statement to the top of the module + = note: `-D clippy::items-before-use` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::items_before_use)]` + +error: module level use statements should precede all other items + --> tests/ui/items_before_use.rs:25:5 + | +LL | use std::borrow::Cow; + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: consider moving this statement to the top of the module + +error: aborting due to 2 previous errors + diff --git a/tests/ui/iter_on_empty_collections.fixed b/tests/ui/iter_on_empty_collections.fixed index 0c2100034e18..8909be336460 100644 --- a/tests/ui/iter_on_empty_collections.fixed +++ b/tests/ui/iter_on_empty_collections.fixed @@ -1,5 +1,5 @@ #![warn(clippy::iter_on_empty_collections)] -#![allow(clippy::iter_next_slice, clippy::redundant_clone)] +#![allow(clippy::iter_next_slice, clippy::redundant_clone, clippy::items_before_use)] fn array() { assert_eq!(std::iter::empty().next(), Option::::None); diff --git a/tests/ui/iter_on_empty_collections.rs b/tests/ui/iter_on_empty_collections.rs index 0fb7a32d3691..410a358f2332 100644 --- a/tests/ui/iter_on_empty_collections.rs +++ b/tests/ui/iter_on_empty_collections.rs @@ -1,5 +1,5 @@ #![warn(clippy::iter_on_empty_collections)] -#![allow(clippy::iter_next_slice, clippy::redundant_clone)] +#![allow(clippy::iter_next_slice, clippy::redundant_clone, clippy::items_before_use)] fn array() { assert_eq!([].into_iter().next(), Option::::None); diff --git a/tests/ui/iter_on_single_items.fixed b/tests/ui/iter_on_single_items.fixed index b43fad6449c1..ccda6a00e150 100644 --- a/tests/ui/iter_on_single_items.fixed +++ b/tests/ui/iter_on_single_items.fixed @@ -1,5 +1,5 @@ #![warn(clippy::iter_on_single_items)] -#![allow(clippy::iter_next_slice, clippy::redundant_clone)] +#![allow(clippy::iter_next_slice, clippy::redundant_clone, clippy::items_before_use)] fn array() { assert_eq!(std::iter::once(123).next(), Some(123)); diff --git a/tests/ui/iter_on_single_items.rs b/tests/ui/iter_on_single_items.rs index 625c96d3ef1f..dcbe925c0412 100644 --- a/tests/ui/iter_on_single_items.rs +++ b/tests/ui/iter_on_single_items.rs @@ -1,5 +1,5 @@ #![warn(clippy::iter_on_single_items)] -#![allow(clippy::iter_next_slice, clippy::redundant_clone)] +#![allow(clippy::iter_next_slice, clippy::redundant_clone, clippy::items_before_use)] fn array() { assert_eq!([123].into_iter().next(), Some(123)); diff --git a/tests/ui/legacy_numeric_constants.fixed b/tests/ui/legacy_numeric_constants.fixed index 30bb549a9d65..6cabff1da204 100644 --- a/tests/ui/legacy_numeric_constants.fixed +++ b/tests/ui/legacy_numeric_constants.fixed @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs //@require-annotations-for-level: WARN -#![allow(clippy::no_effect, deprecated, unused)] +#![allow(clippy::no_effect, deprecated, unused, clippy::items_before_use)] #![allow(clippy::legacy_numeric_constants)] // For imports. #[macro_use] diff --git a/tests/ui/legacy_numeric_constants.rs b/tests/ui/legacy_numeric_constants.rs index d3878199055f..d02949e62628 100644 --- a/tests/ui/legacy_numeric_constants.rs +++ b/tests/ui/legacy_numeric_constants.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs //@require-annotations-for-level: WARN -#![allow(clippy::no_effect, deprecated, unused)] +#![allow(clippy::no_effect, deprecated, unused, clippy::items_before_use)] #![allow(clippy::legacy_numeric_constants)] // For imports. #[macro_use] diff --git a/tests/ui/manual_unwrap_or.fixed b/tests/ui/manual_unwrap_or.fixed index e12287a70939..b21cb7bbacb6 100644 --- a/tests/ui/manual_unwrap_or.fixed +++ b/tests/ui/manual_unwrap_or.fixed @@ -3,7 +3,8 @@ unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap, - clippy::manual_unwrap_or_default + clippy::manual_unwrap_or_default, + clippy::items_before_use )] fn option_unwrap_or() { diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs index 53cffcab5b56..2ff7ad48d8a5 100644 --- a/tests/ui/manual_unwrap_or.rs +++ b/tests/ui/manual_unwrap_or.rs @@ -3,7 +3,8 @@ unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap, - clippy::manual_unwrap_or_default + clippy::manual_unwrap_or_default, + clippy::items_before_use )] fn option_unwrap_or() { diff --git a/tests/ui/manual_unwrap_or.stderr b/tests/ui/manual_unwrap_or.stderr index 320e895fb823..853c9652d6aa 100644 --- a/tests/ui/manual_unwrap_or.stderr +++ b/tests/ui/manual_unwrap_or.stderr @@ -1,5 +1,5 @@ error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:11:5 + --> tests/ui/manual_unwrap_or.rs:12:5 | LL | / match Some(1) { LL | | @@ -12,7 +12,7 @@ LL | | }; = help: to override `-D warnings` add `#[allow(clippy::manual_unwrap_or)]` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:18:5 + --> tests/ui/manual_unwrap_or.rs:19:5 | LL | / match Some(1) { LL | | @@ -22,7 +22,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:25:5 + --> tests/ui/manual_unwrap_or.rs:26:5 | LL | / match Some(1) { LL | | @@ -32,7 +32,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(1 + 42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:33:5 + --> tests/ui/manual_unwrap_or.rs:34:5 | LL | / match Some(1) { LL | | @@ -50,7 +50,7 @@ LL ~ + 42 + 42 + 42); | error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:44:5 + --> tests/ui/manual_unwrap_or.rs:45:5 | LL | / match Some("Bob") { LL | | @@ -60,7 +60,7 @@ LL | | }; | |_____^ help: replace with: `Some("Bob").unwrap_or("Alice")` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:92:5 + --> tests/ui/manual_unwrap_or.rs:93:5 | LL | / if let Some(x) = Some(1) { LL | | @@ -71,7 +71,7 @@ LL | | }; | |_____^ help: replace with: `Some(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:126:5 + --> tests/ui/manual_unwrap_or.rs:127:5 | LL | / match Ok::(1) { LL | | @@ -81,7 +81,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:134:5 + --> tests/ui/manual_unwrap_or.rs:135:5 | LL | / match a { LL | | @@ -91,7 +91,7 @@ LL | | }; | |_____^ help: replace with: `a.unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:141:5 + --> tests/ui/manual_unwrap_or.rs:142:5 | LL | / match Ok(1) as Result { LL | | @@ -101,7 +101,7 @@ LL | | }; | |_____^ help: replace with: `(Ok(1) as Result).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:155:5 + --> tests/ui/manual_unwrap_or.rs:156:5 | LL | / match s.method() { LL | | @@ -111,7 +111,7 @@ LL | | }; | |_____^ help: replace with: `s.method().unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:162:5 + --> tests/ui/manual_unwrap_or.rs:163:5 | LL | / match Ok::(1) { LL | | @@ -121,7 +121,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:169:5 + --> tests/ui/manual_unwrap_or.rs:170:5 | LL | / match Ok::(1) { LL | | @@ -131,7 +131,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(1 + 42)` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:177:5 + --> tests/ui/manual_unwrap_or.rs:178:5 | LL | / match Ok::(1) { LL | | @@ -149,7 +149,7 @@ LL ~ + 42 + 42 + 42); | error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:188:5 + --> tests/ui/manual_unwrap_or.rs:189:5 | LL | / match Ok::<&str, &str>("Bob") { LL | | @@ -159,7 +159,7 @@ LL | | }; | |_____^ help: replace with: `Ok::<&str, &str>("Bob").unwrap_or("Alice")` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:219:5 + --> tests/ui/manual_unwrap_or.rs:220:5 | LL | / match Ok::<&str, &str>("Alice") { LL | | @@ -169,7 +169,7 @@ LL | | }; | |_____^ help: replace with: `Ok::<&str, &str>("Alice").unwrap_or("Bob")` error: this pattern reimplements `Result::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:225:5 + --> tests/ui/manual_unwrap_or.rs:226:5 | LL | / if let Ok(x) = Ok::(1) { LL | | @@ -180,7 +180,7 @@ LL | | }; | |_____^ help: replace with: `Ok::(1).unwrap_or(42)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:280:17 + --> tests/ui/manual_unwrap_or.rs:281:17 | LL | let _ = match some_macro!() { | _________________^ @@ -191,7 +191,7 @@ LL | | }; | |_________^ help: replace with: `some_macro!().unwrap_or(0)` error: this pattern reimplements `Option::unwrap_or` - --> tests/ui/manual_unwrap_or.rs:324:5 + --> tests/ui/manual_unwrap_or.rs:325:5 | LL | / if let Some(x) = Some(42) { LL | | diff --git a/tests/ui/missing_const_for_fn/cant_be_const.rs b/tests/ui/missing_const_for_fn/cant_be_const.rs index 40e7a5d745cc..9e4878359057 100644 --- a/tests/ui/missing_const_for_fn/cant_be_const.rs +++ b/tests/ui/missing_const_for_fn/cant_be_const.rs @@ -6,6 +6,7 @@ //@aux-build:helper.rs //@aux-build:../auxiliary/proc_macros.rs +#![allow(clippy::items_before_use)] #![warn(clippy::missing_const_for_fn)] #![feature(type_alias_impl_trait)] diff --git a/tests/ui/module_name_repetitions.rs b/tests/ui/module_name_repetitions.rs index 2fde98d7927c..6db1f4146dd9 100644 --- a/tests/ui/module_name_repetitions.rs +++ b/tests/ui/module_name_repetitions.rs @@ -1,7 +1,7 @@ //@compile-flags: --test #![warn(clippy::module_name_repetitions)] -#![allow(dead_code)] +#![allow(dead_code, clippy::items_before_use)] pub mod foo { pub fn foo() {} diff --git a/tests/ui/non_std_lazy_static/non_std_lazy_static_other_once_cell.rs b/tests/ui/non_std_lazy_static/non_std_lazy_static_other_once_cell.rs index f6d4f7250915..ca8675b7efa9 100644 --- a/tests/ui/non_std_lazy_static/non_std_lazy_static_other_once_cell.rs +++ b/tests/ui/non_std_lazy_static/non_std_lazy_static_other_once_cell.rs @@ -1,6 +1,7 @@ //@ check-pass //@aux-build:once_cell.rs +#![allow(clippy::items_before_use)] #![warn(clippy::non_std_lazy_statics)] // Should not error, since we used a type besides `sync::Lazy` diff --git a/tests/ui/redundant_pub_crate.fixed b/tests/ui/redundant_pub_crate.fixed index 8a30fedede4a..cad65956bcb7 100644 --- a/tests/ui/redundant_pub_crate.fixed +++ b/tests/ui/redundant_pub_crate.fixed @@ -1,5 +1,5 @@ //@aux-build:proc_macros.rs -#![allow(dead_code)] +#![allow(dead_code, clippy::items_before_use)] #![warn(clippy::redundant_pub_crate)] mod m1 { diff --git a/tests/ui/redundant_pub_crate.rs b/tests/ui/redundant_pub_crate.rs index 45ba13a63b2e..7cc544d03924 100644 --- a/tests/ui/redundant_pub_crate.rs +++ b/tests/ui/redundant_pub_crate.rs @@ -1,5 +1,5 @@ //@aux-build:proc_macros.rs -#![allow(dead_code)] +#![allow(dead_code, clippy::items_before_use)] #![warn(clippy::redundant_pub_crate)] mod m1 { diff --git a/tests/ui/single_component_path_imports_macro.rs b/tests/ui/single_component_path_imports_macro.rs index f655ea482d1c..63c8d6b63fc8 100644 --- a/tests/ui/single_component_path_imports_macro.rs +++ b/tests/ui/single_component_path_imports_macro.rs @@ -1,7 +1,7 @@ //@ check-pass #![warn(clippy::single_component_path_imports)] -#![allow(unused_imports)] +#![allow(unused_imports, clippy::items_before_use)] // #7106: use statements exporting a macro within a crate should not trigger lint // #7923: normal `use` statements of macros should also not trigger the lint diff --git a/tests/ui/single_match.fixed b/tests/ui/single_match.fixed index db5107600ee6..2c5ef4b310e4 100644 --- a/tests/ui/single_match.fixed +++ b/tests/ui/single_match.fixed @@ -6,7 +6,8 @@ clippy::needless_if, clippy::redundant_guards, clippy::redundant_pattern_matching, - clippy::manual_unwrap_or_default + clippy::manual_unwrap_or_default, + clippy::items_before_use )] fn dummy() {} diff --git a/tests/ui/single_match.rs b/tests/ui/single_match.rs index a367b94c4ca6..b23a37b78534 100644 --- a/tests/ui/single_match.rs +++ b/tests/ui/single_match.rs @@ -6,7 +6,8 @@ clippy::needless_if, clippy::redundant_guards, clippy::redundant_pattern_matching, - clippy::manual_unwrap_or_default + clippy::manual_unwrap_or_default, + clippy::items_before_use )] fn dummy() {} diff --git a/tests/ui/single_match.stderr b/tests/ui/single_match.stderr index 1a4edc45c928..8636e2d97019 100644 --- a/tests/ui/single_match.stderr +++ b/tests/ui/single_match.stderr @@ -1,5 +1,5 @@ error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:16:5 + --> tests/ui/single_match.rs:17:5 | LL | / match x { LL | | Some(y) => { @@ -19,7 +19,7 @@ LL ~ }; | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:25:5 + --> tests/ui/single_match.rs:26:5 | LL | / match x { ... | @@ -30,7 +30,7 @@ LL | | } = note: you might want to preserve the comments from inside the `match` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:36:5 + --> tests/ui/single_match.rs:37:5 | LL | / match z { LL | | (2..=3, 7..=9) => dummy(), @@ -39,7 +39,7 @@ LL | | }; | |_____^ help: try: `if let (2..=3, 7..=9) = z { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:66:5 + --> tests/ui/single_match.rs:67:5 | LL | / match x { LL | | Some(y) => dummy(), @@ -48,7 +48,7 @@ LL | | }; | |_____^ help: try: `if let Some(y) = x { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:72:5 + --> tests/ui/single_match.rs:73:5 | LL | / match y { LL | | Ok(y) => dummy(), @@ -57,7 +57,7 @@ LL | | }; | |_____^ help: try: `if let Ok(y) = y { dummy() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:80:5 + --> tests/ui/single_match.rs:81:5 | LL | / match c { LL | | Cow::Borrowed(..) => dummy(), @@ -66,7 +66,7 @@ LL | | }; | |_____^ help: try: `if let Cow::Borrowed(..) = c { dummy() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:102:5 + --> tests/ui/single_match.rs:103:5 | LL | / match x { LL | | "test" => println!(), @@ -75,7 +75,7 @@ LL | | } | |_____^ help: try: `if x == "test" { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:116:5 + --> tests/ui/single_match.rs:117:5 | LL | / match x { LL | | Foo::A => println!(), @@ -84,7 +84,7 @@ LL | | } | |_____^ help: try: `if x == Foo::A { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:123:5 + --> tests/ui/single_match.rs:124:5 | LL | / match x { LL | | FOO_C => println!(), @@ -93,7 +93,7 @@ LL | | } | |_____^ help: try: `if x == FOO_C { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:129:5 + --> tests/ui/single_match.rs:130:5 | LL | / match &&x { LL | | Foo::A => println!(), @@ -102,7 +102,7 @@ LL | | } | |_____^ help: try: `if x == Foo::A { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:136:5 + --> tests/ui/single_match.rs:137:5 | LL | / match &x { LL | | Foo::A => println!(), @@ -111,7 +111,7 @@ LL | | } | |_____^ help: try: `if x == &Foo::A { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:154:5 + --> tests/ui/single_match.rs:155:5 | LL | / match x { LL | | Bar::A => println!(), @@ -120,7 +120,7 @@ LL | | } | |_____^ help: try: `if let Bar::A = x { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:163:5 + --> tests/ui/single_match.rs:164:5 | LL | / match x { LL | | None => println!(), @@ -129,7 +129,7 @@ LL | | }; | |_____^ help: try: `if let None = x { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:186:5 + --> tests/ui/single_match.rs:187:5 | LL | / match x { LL | | (Some(_), _) => {}, @@ -138,7 +138,7 @@ LL | | } | |_____^ help: try: `if let (Some(_), _) = x {}` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:193:5 + --> tests/ui/single_match.rs:194:5 | LL | / match x { LL | | (Some(E::V), _) => todo!(), @@ -147,7 +147,7 @@ LL | | } | |_____^ help: try: `if let (Some(E::V), _) = x { todo!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:200:5 + --> tests/ui/single_match.rs:201:5 | LL | / match (Some(42), Some(E::V), Some(42)) { LL | | (.., Some(E::V), _) => {}, @@ -156,7 +156,7 @@ LL | | } | |_____^ help: try: `if let (.., Some(E::V), _) = (Some(42), Some(E::V), Some(42)) {}` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:273:5 + --> tests/ui/single_match.rs:274:5 | LL | / match bar { LL | | Some(v) => unsafe { @@ -176,7 +176,7 @@ LL + } } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:282:5 + --> tests/ui/single_match.rs:283:5 | LL | / match bar { LL | | #[rustfmt::skip] @@ -198,7 +198,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:363:5 + --> tests/ui/single_match.rs:364:5 | LL | / match Ok::<_, u32>(Some(A)) { LL | | Ok(Some(A)) => println!(), @@ -207,7 +207,7 @@ LL | | } | |_____^ help: try: `if let Ok(Some(A)) = Ok::<_, u32>(Some(A)) { println!() }` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:379:5 + --> tests/ui/single_match.rs:380:5 | LL | / match &Some(A) { LL | | Some(A | B) => println!(), @@ -216,7 +216,7 @@ LL | | } | |_____^ help: try: `if let Some(A | B) = &Some(A) { println!() }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:387:5 + --> tests/ui/single_match.rs:388:5 | LL | / match &s[0..3] { LL | | b"foo" => println!(), @@ -225,7 +225,7 @@ LL | | } | |_____^ help: try: `if &s[0..3] == b"foo" { println!() }` error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:401:5 + --> tests/ui/single_match.rs:402:5 | LL | / match DATA { LL | | DATA => println!(), @@ -234,7 +234,7 @@ LL | | } | |_____^ help: try: `println!();` error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:407:5 + --> tests/ui/single_match.rs:408:5 | LL | / match CONST_I32 { LL | | CONST_I32 => println!(), @@ -243,7 +243,7 @@ LL | | } | |_____^ help: try: `println!();` error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:414:5 + --> tests/ui/single_match.rs:415:5 | LL | / match i { LL | | i => { @@ -263,7 +263,7 @@ LL + } | error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:423:5 + --> tests/ui/single_match.rs:424:5 | LL | / match i { LL | | i => {}, @@ -272,7 +272,7 @@ LL | | } | |_____^ help: `match` expression can be removed error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:429:5 + --> tests/ui/single_match.rs:430:5 | LL | / match i { LL | | i => (), @@ -281,7 +281,7 @@ LL | | } | |_____^ help: `match` expression can be removed error: this pattern is irrefutable, `match` is useless - --> tests/ui/single_match.rs:435:5 + --> tests/ui/single_match.rs:436:5 | LL | / match CONST_I32 { LL | | CONST_I32 => println!(), @@ -290,7 +290,7 @@ LL | | } | |_____^ help: try: `println!();` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:443:5 + --> tests/ui/single_match.rs:444:5 | LL | / match x.pop() { LL | | // bla @@ -302,7 +302,7 @@ LL | | } = note: you might want to preserve the comments from inside the `match` error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:452:5 + --> tests/ui/single_match.rs:453:5 | LL | / match x.pop() { LL | | // bla @@ -322,7 +322,7 @@ LL + } | error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` - --> tests/ui/single_match.rs:478:5 + --> tests/ui/single_match.rs:479:5 | LL | / match mac!(some) { LL | | Some(u) => println!("{u}"), @@ -331,7 +331,7 @@ LL | | } | |_____^ help: try: `if let Some(u) = mac!(some) { println!("{u}") }` error: you seem to be trying to use `match` for an equality check. Consider using `if` - --> tests/ui/single_match.rs:486:5 + --> tests/ui/single_match.rs:487:5 | LL | / match mac!(str) { LL | | "foo" => println!("eq"), diff --git a/tests/ui/suspicious_doc_comments_unfixable.rs b/tests/ui/suspicious_doc_comments_unfixable.rs index 17c7cc15b170..7b3d779bc97b 100644 --- a/tests/ui/suspicious_doc_comments_unfixable.rs +++ b/tests/ui/suspicious_doc_comments_unfixable.rs @@ -1,4 +1,4 @@ -#![allow(unused, clippy::empty_line_after_doc_comments)] +#![allow(unused, clippy::empty_line_after_doc_comments, clippy::items_before_use)] #![warn(clippy::suspicious_doc_comments)] //@no-rustfix ///! a diff --git a/tests/ui/unnecessary_cast.fixed b/tests/ui/unnecessary_cast.fixed index 91ff4b9ee771..e8f58125eef1 100644 --- a/tests/ui/unnecessary_cast.fixed +++ b/tests/ui/unnecessary_cast.fixed @@ -6,6 +6,7 @@ clippy::no_effect, clippy::nonstandard_macro_braces, clippy::unnecessary_operation, + clippy::items_before_use, nonstandard_style, unused )] diff --git a/tests/ui/unnecessary_cast.rs b/tests/ui/unnecessary_cast.rs index 5444a914db16..5ed5b02dac82 100644 --- a/tests/ui/unnecessary_cast.rs +++ b/tests/ui/unnecessary_cast.rs @@ -6,6 +6,7 @@ clippy::no_effect, clippy::nonstandard_macro_braces, clippy::unnecessary_operation, + clippy::items_before_use, nonstandard_style, unused )] diff --git a/tests/ui/unnecessary_cast.stderr b/tests/ui/unnecessary_cast.stderr index 3e3c5eb81c10..1e58ce320301 100644 --- a/tests/ui/unnecessary_cast.stderr +++ b/tests/ui/unnecessary_cast.stderr @@ -1,5 +1,5 @@ error: casting raw pointers to the same type and constness is unnecessary (`*const T` -> `*const T`) - --> tests/ui/unnecessary_cast.rs:19:5 + --> tests/ui/unnecessary_cast.rs:20:5 | LL | ptr as *const T | ^^^^^^^^^^^^^^^ help: try: `ptr` @@ -8,259 +8,259 @@ LL | ptr as *const T = help: to override `-D warnings` add `#[allow(clippy::unnecessary_cast)]` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:55:5 + --> tests/ui/unnecessary_cast.rs:56:5 | LL | 1i32 as i32; | ^^^^^^^^^^^ help: try: `1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:57:5 + --> tests/ui/unnecessary_cast.rs:58:5 | LL | 1f32 as f32; | ^^^^^^^^^^^ help: try: `1_f32` error: casting to the same type is unnecessary (`bool` -> `bool`) - --> tests/ui/unnecessary_cast.rs:59:5 + --> tests/ui/unnecessary_cast.rs:60:5 | LL | false as bool; | ^^^^^^^^^^^^^ help: try: `false` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:63:5 + --> tests/ui/unnecessary_cast.rs:64:5 | LL | -1_i32 as i32; | ^^^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:65:5 + --> tests/ui/unnecessary_cast.rs:66:5 | LL | - 1_i32 as i32; | ^^^^^^^^^^^^^^ help: try: `- 1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:67:5 + --> tests/ui/unnecessary_cast.rs:68:5 | LL | -1f32 as f32; | ^^^^^^^^^^^^ help: try: `-1_f32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:69:5 + --> tests/ui/unnecessary_cast.rs:70:5 | LL | 1_i32 as i32; | ^^^^^^^^^^^^ help: try: `1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:71:5 + --> tests/ui/unnecessary_cast.rs:72:5 | LL | 1_f32 as f32; | ^^^^^^^^^^^^ help: try: `1_f32` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> tests/ui/unnecessary_cast.rs:74:22 + --> tests/ui/unnecessary_cast.rs:75:22 | LL | let _: *mut u8 = [1u8, 2].as_ptr() as *const u8 as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> tests/ui/unnecessary_cast.rs:77:5 + --> tests/ui/unnecessary_cast.rs:78:5 | LL | [1u8, 2].as_ptr() as *const u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*mut u8` -> `*mut u8`) - --> tests/ui/unnecessary_cast.rs:80:5 + --> tests/ui/unnecessary_cast.rs:81:5 | LL | [1u8, 2].as_mut_ptr() as *mut u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[1u8, 2].as_mut_ptr()` error: casting raw pointers to the same type and constness is unnecessary (`*const u32` -> `*const u32`) - --> tests/ui/unnecessary_cast.rs:92:5 + --> tests/ui/unnecessary_cast.rs:93:5 | LL | owo::([1u32].as_ptr()) as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `owo::([1u32].as_ptr())` error: casting raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) - --> tests/ui/unnecessary_cast.rs:94:5 + --> tests/ui/unnecessary_cast.rs:95:5 | LL | uwu::([1u32].as_ptr()) as *const u8; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::([1u32].as_ptr())` error: casting raw pointers to the same type and constness is unnecessary (`*const u32` -> `*const u32`) - --> tests/ui/unnecessary_cast.rs:97:5 + --> tests/ui/unnecessary_cast.rs:98:5 | LL | uwu::([1u32].as_ptr()) as *const u32; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `uwu::([1u32].as_ptr())` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> tests/ui/unnecessary_cast.rs:133:5 + --> tests/ui/unnecessary_cast.rs:134:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting to the same type is unnecessary (`u32` -> `u32`) - --> tests/ui/unnecessary_cast.rs:136:5 + --> tests/ui/unnecessary_cast.rs:137:5 | LL | aaa() as u32; | ^^^^^^^^^^^^ help: try: `aaa()` error: casting integer literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:173:9 + --> tests/ui/unnecessary_cast.rs:174:9 | LL | 100 as f32; | ^^^^^^^^^^ help: try: `100_f32` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:175:9 + --> tests/ui/unnecessary_cast.rs:176:9 | LL | 100 as f64; | ^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:177:9 + --> tests/ui/unnecessary_cast.rs:178:9 | LL | 100_i32 as f64; | ^^^^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:179:17 + --> tests/ui/unnecessary_cast.rs:180:17 | LL | let _ = -100 as f32; | ^^^^^^^^^^^ help: try: `-100_f32` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:181:17 + --> tests/ui/unnecessary_cast.rs:182:17 | LL | let _ = -100 as f64; | ^^^^^^^^^^^ help: try: `-100_f64` error: casting integer literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:183:17 + --> tests/ui/unnecessary_cast.rs:184:17 | LL | let _ = -100_i32 as f64; | ^^^^^^^^^^^^^^^ help: try: `-100_f64` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:185:9 + --> tests/ui/unnecessary_cast.rs:186:9 | LL | 100. as f32; | ^^^^^^^^^^^ help: try: `100_f32` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:187:9 + --> tests/ui/unnecessary_cast.rs:188:9 | LL | 100. as f64; | ^^^^^^^^^^^ help: try: `100_f64` error: casting integer literal to `u32` is unnecessary - --> tests/ui/unnecessary_cast.rs:200:9 + --> tests/ui/unnecessary_cast.rs:201:9 | LL | 1 as u32; | ^^^^^^^^ help: try: `1_u32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:202:9 + --> tests/ui/unnecessary_cast.rs:203:9 | LL | 0x10 as i32; | ^^^^^^^^^^^ help: try: `0x10_i32` error: casting integer literal to `usize` is unnecessary - --> tests/ui/unnecessary_cast.rs:204:9 + --> tests/ui/unnecessary_cast.rs:205:9 | LL | 0b10 as usize; | ^^^^^^^^^^^^^ help: try: `0b10_usize` error: casting integer literal to `u16` is unnecessary - --> tests/ui/unnecessary_cast.rs:206:9 + --> tests/ui/unnecessary_cast.rs:207:9 | LL | 0o73 as u16; | ^^^^^^^^^^^ help: try: `0o73_u16` error: casting integer literal to `u32` is unnecessary - --> tests/ui/unnecessary_cast.rs:208:9 + --> tests/ui/unnecessary_cast.rs:209:9 | LL | 1_000_000_000 as u32; | ^^^^^^^^^^^^^^^^^^^^ help: try: `1_000_000_000_u32` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:211:9 + --> tests/ui/unnecessary_cast.rs:212:9 | LL | 1.0 as f64; | ^^^^^^^^^^ help: try: `1.0_f64` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:213:9 + --> tests/ui/unnecessary_cast.rs:214:9 | LL | 0.5 as f32; | ^^^^^^^^^^ help: try: `0.5_f32` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:218:17 + --> tests/ui/unnecessary_cast.rs:219:17 | LL | let _ = -1 as i32; | ^^^^^^^^^ help: try: `-1_i32` error: casting float literal to `f32` is unnecessary - --> tests/ui/unnecessary_cast.rs:220:17 + --> tests/ui/unnecessary_cast.rs:221:17 | LL | let _ = -1.0 as f32; | ^^^^^^^^^^^ help: try: `-1.0_f32` error: casting to the same type is unnecessary (`i32` -> `i32`) - --> tests/ui/unnecessary_cast.rs:227:18 + --> tests/ui/unnecessary_cast.rs:228:18 | LL | let _ = &(x as i32); | ^^^^^^^^^^ help: try: `{ x }` error: casting integer literal to `i32` is unnecessary - --> tests/ui/unnecessary_cast.rs:234:22 + --> tests/ui/unnecessary_cast.rs:235:22 | LL | let _: i32 = -(1) as i32; | ^^^^^^^^^^^ help: try: `-1_i32` error: casting integer literal to `i64` is unnecessary - --> tests/ui/unnecessary_cast.rs:237:22 + --> tests/ui/unnecessary_cast.rs:238:22 | LL | let _: i64 = -(1) as i64; | ^^^^^^^^^^^ help: try: `-1_i64` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:245:22 + --> tests/ui/unnecessary_cast.rs:246:22 | LL | let _: f64 = (-8.0 as f64).exp(); | ^^^^^^^^^^^^^ help: try: `(-8.0_f64)` error: casting float literal to `f64` is unnecessary - --> tests/ui/unnecessary_cast.rs:248:23 + --> tests/ui/unnecessary_cast.rs:249:23 | LL | let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior | ^^^^^^^^^^^^ help: try: `8.0_f64` error: casting to the same type is unnecessary (`f32` -> `f32`) - --> tests/ui/unnecessary_cast.rs:258:20 + --> tests/ui/unnecessary_cast.rs:259:20 | LL | let _num = foo() as f32; | ^^^^^^^^^^^^ help: try: `foo()` error: casting to the same type is unnecessary (`usize` -> `usize`) - --> tests/ui/unnecessary_cast.rs:269:9 + --> tests/ui/unnecessary_cast.rs:270:9 | LL | (*x as usize).pow(2) | ^^^^^^^^^^^^^ help: try: `(*x)` error: casting to the same type is unnecessary (`usize` -> `usize`) - --> tests/ui/unnecessary_cast.rs:277:31 + --> tests/ui/unnecessary_cast.rs:278:31 | LL | assert_eq!(vec.len(), x as usize); | ^^^^^^^^^^ help: try: `x` error: casting to the same type is unnecessary (`i64` -> `i64`) - --> tests/ui/unnecessary_cast.rs:280:17 + --> tests/ui/unnecessary_cast.rs:281:17 | LL | let _ = (5i32 as i64 as i64).abs(); | ^^^^^^^^^^^^^^^^^^^^ help: try: `(5i32 as i64)` error: casting to the same type is unnecessary (`i64` -> `i64`) - --> tests/ui/unnecessary_cast.rs:283:17 + --> tests/ui/unnecessary_cast.rs:284:17 | LL | let _ = 5i32 as i64 as i64; | ^^^^^^^^^^^^^^^^^^ help: try: `5i32 as i64` diff --git a/tests/ui/unnecessary_unsafety_doc.rs b/tests/ui/unnecessary_unsafety_doc.rs index 7a847d2e3b50..8acec9247f91 100644 --- a/tests/ui/unnecessary_unsafety_doc.rs +++ b/tests/ui/unnecessary_unsafety_doc.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(clippy::let_unit_value, clippy::needless_pass_by_ref_mut)] +#![allow(clippy::let_unit_value, clippy::needless_pass_by_ref_mut, clippy::items_before_use)] #![warn(clippy::unnecessary_safety_doc)] extern crate proc_macros; diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index 32a50375806a..628af77be9e9 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -1,4 +1,4 @@ -#![allow(dead_code, clippy::needless_pass_by_ref_mut)] +#![allow(dead_code, clippy::needless_pass_by_ref_mut, clippy::items_before_use)] #![allow(clippy::redundant_pattern_matching)] #![warn(clippy::unused_io_amount)] diff --git a/tests/ui/unused_trait_names.fixed b/tests/ui/unused_trait_names.fixed index 17e32ddfd9d9..fa4984c73c1c 100644 --- a/tests/ui/unused_trait_names.fixed +++ b/tests/ui/unused_trait_names.fixed @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(unused)] +#![allow(unused, clippy::items_before_use)] #![warn(clippy::unused_trait_names)] #![feature(decl_macro)] diff --git a/tests/ui/unused_trait_names.rs b/tests/ui/unused_trait_names.rs index 3cf8597e5351..3959003a8e24 100644 --- a/tests/ui/unused_trait_names.rs +++ b/tests/ui/unused_trait_names.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs -#![allow(unused)] +#![allow(unused, clippy::items_before_use)] #![warn(clippy::unused_trait_names)] #![feature(decl_macro)] diff --git a/tests/ui/useless_attribute.fixed b/tests/ui/useless_attribute.fixed index a96c8f46f551..66aaf1cac6df 100644 --- a/tests/ui/useless_attribute.fixed +++ b/tests/ui/useless_attribute.fixed @@ -1,6 +1,6 @@ //@aux-build:proc_macro_derive.rs -#![allow(unused, clippy::duplicated_attributes)] +#![allow(unused, clippy::duplicated_attributes, clippy::items_before_use)] #![warn(clippy::useless_attribute)] #![warn(unreachable_pub)] #![feature(rustc_private)] diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index b26410134bbb..71a1ac731229 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -1,6 +1,6 @@ //@aux-build:proc_macro_derive.rs -#![allow(unused, clippy::duplicated_attributes)] +#![allow(unused, clippy::duplicated_attributes, clippy::items_before_use)] #![warn(clippy::useless_attribute)] #![warn(unreachable_pub)] #![feature(rustc_private)]