diff options
Diffstat (limited to 'tests')
159 files changed, 3481 insertions, 655 deletions
diff --git a/tests/compile-test.rs b/tests/compile-test.rs index af2aa519257..b8e0413e97b 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -8,7 +8,10 @@ use clippy_config::ClippyConfiguration; use clippy_lints::LintInfo; use clippy_lints::declared_lints::LINTS; use clippy_lints::deprecated_lints::{DEPRECATED, DEPRECATED_VERSION, RENAMED}; -use serde::{Deserialize, Serialize}; +use pulldown_cmark::{Options, Parser, html}; +use rinja::Template; +use rinja::filters::Safe; +use serde::Deserialize; use test_utils::IS_RUSTC_TEST_SUITE; use ui_test::custom_flags::Flag; use ui_test::custom_flags::rustfix::RustfixMode; @@ -385,6 +388,23 @@ fn ui_cargo_toml_metadata() { } } +#[derive(Template)] +#[template(path = "index_template.html")] +struct Renderer<'a> { + lints: &'a Vec<LintMetadata>, +} + +impl Renderer<'_> { + fn markdown(input: &str) -> Safe<String> { + let input = clippy_config::sanitize_explanation(input); + let parser = Parser::new_ext(&input, Options::all()); + let mut html_output = String::new(); + html::push_html(&mut html_output, parser); + // Oh deer, what a hack :O + Safe(html_output.replace("<table", "<table class=\"table\"")) + } +} + #[derive(Deserialize)] #[serde(untagged)] enum DiagnosticOrMessage { @@ -445,10 +465,14 @@ impl DiagnosticCollector { .map(|((lint, reason), version)| LintMetadata::new_deprecated(lint, reason, version)), ) .collect(); + metadata.sort_unstable_by(|a, b| a.id.cmp(&b.id)); - let json = serde_json::to_string_pretty(&metadata).unwrap(); - fs::write("util/gh-pages/lints.json", json).unwrap(); + fs::write( + "util/gh-pages/index.html", + Renderer { lints: &metadata }.render().unwrap(), + ) + .unwrap(); }); (Self { sender }, handle) @@ -487,7 +511,7 @@ impl Flag for DiagnosticCollector { } } -#[derive(Debug, Serialize)] +#[derive(Debug)] struct LintMetadata { id: String, id_location: Option<&'static str>, @@ -559,4 +583,14 @@ impl LintMetadata { applicability: Applicability::Unspecified, } } + + fn applicability_str(&self) -> &str { + match self.applicability { + Applicability::MachineApplicable => "MachineApplicable", + Applicability::HasPlaceholders => "HasPlaceholders", + Applicability::MaybeIncorrect => "MaybeIncorrect", + Applicability::Unspecified => "Unspecified", + _ => panic!("needs to update this code"), + } + } } diff --git a/tests/config-metadata.rs b/tests/config-metadata.rs index 628dfc8f758..af9fe064dc7 100644 --- a/tests/config-metadata.rs +++ b/tests/config-metadata.rs @@ -20,7 +20,7 @@ fn book() { let configs = metadata().map(|conf| conf.to_markdown_paragraph()).join("\n"); let expected = format!( - r#"<!-- + r"<!-- This file is generated by `cargo bless --test config-metadata`. Please use that command to update the file and do not edit it by hand. --> @@ -33,7 +33,7 @@ and lints affected. --- {} -"#, +", configs.trim(), ); diff --git a/tests/ui-internal/slow_symbol_comparisons.fixed b/tests/ui-internal/slow_symbol_comparisons.fixed new file mode 100644 index 00000000000..2cbd646a0fd --- /dev/null +++ b/tests/ui-internal/slow_symbol_comparisons.fixed @@ -0,0 +1,24 @@ +#![feature(rustc_private)] +#![warn(clippy::slow_symbol_comparisons)] + +extern crate rustc_span; + +use clippy_utils::sym; +use rustc_span::Symbol; + +fn main() { + let symbol = sym!(example); + let other_symbol = sym!(other_example); + + // Should lint + let slow_comparison = symbol.as_str() == "example"; + //~^ error: comparing `Symbol` via `Symbol::intern` + let slow_comparison_macro = symbol.as_str() == "example"; + //~^ error: comparing `Symbol` via `Symbol::intern` + let slow_comparison_backwards = symbol.as_str() == "example"; + //~^ error: comparing `Symbol` via `Symbol::intern` + + // Should not lint + let faster_comparison = symbol.as_str() == "other_example"; + let preinterned_comparison = symbol == other_symbol; +} diff --git a/tests/ui-internal/slow_symbol_comparisons.rs b/tests/ui-internal/slow_symbol_comparisons.rs new file mode 100644 index 00000000000..0cea3c3fcff --- /dev/null +++ b/tests/ui-internal/slow_symbol_comparisons.rs @@ -0,0 +1,24 @@ +#![feature(rustc_private)] +#![warn(clippy::slow_symbol_comparisons)] + +extern crate rustc_span; + +use clippy_utils::sym; +use rustc_span::Symbol; + +fn main() { + let symbol = sym!(example); + let other_symbol = sym!(other_example); + + // Should lint + let slow_comparison = symbol == Symbol::intern("example"); + //~^ error: comparing `Symbol` via `Symbol::intern` + let slow_comparison_macro = symbol == sym!(example); + //~^ error: comparing `Symbol` via `Symbol::intern` + let slow_comparison_backwards = sym!(example) == symbol; + //~^ error: comparing `Symbol` via `Symbol::intern` + + // Should not lint + let faster_comparison = symbol.as_str() == "other_example"; + let preinterned_comparison = symbol == other_symbol; +} diff --git a/tests/ui-internal/slow_symbol_comparisons.stderr b/tests/ui-internal/slow_symbol_comparisons.stderr new file mode 100644 index 00000000000..72cb20a7fed --- /dev/null +++ b/tests/ui-internal/slow_symbol_comparisons.stderr @@ -0,0 +1,23 @@ +error: comparing `Symbol` via `Symbol::intern` + --> tests/ui-internal/slow_symbol_comparisons.rs:14:27 + | +LL | let slow_comparison = symbol == Symbol::intern("example"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `Symbol::as_str` and check the string instead: `symbol.as_str() == "example"` + | + = note: `-D clippy::slow-symbol-comparisons` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::slow_symbol_comparisons)]` + +error: comparing `Symbol` via `Symbol::intern` + --> tests/ui-internal/slow_symbol_comparisons.rs:16:33 + | +LL | let slow_comparison_macro = symbol == sym!(example); + | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `Symbol::as_str` and check the string instead: `symbol.as_str() == "example"` + +error: comparing `Symbol` via `Symbol::intern` + --> tests/ui-internal/slow_symbol_comparisons.rs:18:37 + | +LL | let slow_comparison_backwards = sym!(example) == symbol; + | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `Symbol::as_str` and check the string instead: `symbol.as_str() == "example"` + +error: aborting due to 3 previous errors + diff --git a/tests/ui-internal/unnecessary_symbol_str.fixed b/tests/ui-internal/unnecessary_symbol_str.fixed index eb79fdbc4b4..8e7f020c1f6 100644 --- a/tests/ui-internal/unnecessary_symbol_str.fixed +++ b/tests/ui-internal/unnecessary_symbol_str.fixed @@ -1,6 +1,7 @@ #![feature(rustc_private)] #![deny(clippy::internal)] #![allow( + clippy::slow_symbol_comparisons, clippy::borrow_deref_ref, clippy::unnecessary_operation, unused_must_use, diff --git a/tests/ui-internal/unnecessary_symbol_str.rs b/tests/ui-internal/unnecessary_symbol_str.rs index bbea13af92a..9aeeb9aaf3a 100644 --- a/tests/ui-internal/unnecessary_symbol_str.rs +++ b/tests/ui-internal/unnecessary_symbol_str.rs @@ -1,6 +1,7 @@ #![feature(rustc_private)] #![deny(clippy::internal)] #![allow( + clippy::slow_symbol_comparisons, clippy::borrow_deref_ref, clippy::unnecessary_operation, unused_must_use, diff --git a/tests/ui-internal/unnecessary_symbol_str.stderr b/tests/ui-internal/unnecessary_symbol_str.stderr index 551167a9ff5..668c11722f9 100644 --- a/tests/ui-internal/unnecessary_symbol_str.stderr +++ b/tests/ui-internal/unnecessary_symbol_str.stderr @@ -1,5 +1,5 @@ error: unnecessary `Symbol` to string conversion - --> tests/ui-internal/unnecessary_symbol_str.rs:15:5 + --> tests/ui-internal/unnecessary_symbol_str.rs:16:5 | LL | Symbol::intern("foo").as_str() == "clippy"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") == rustc_span::sym::clippy` @@ -12,25 +12,25 @@ LL | #![deny(clippy::internal)] = note: `#[deny(clippy::unnecessary_symbol_str)]` implied by `#[deny(clippy::internal)]` error: unnecessary `Symbol` to string conversion - --> tests/ui-internal/unnecessary_symbol_str.rs:16:5 + --> tests/ui-internal/unnecessary_symbol_str.rs:17:5 | LL | Symbol::intern("foo").to_string() == "self"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") == rustc_span::symbol::kw::SelfLower` error: unnecessary `Symbol` to string conversion - --> tests/ui-internal/unnecessary_symbol_str.rs:17:5 + --> tests/ui-internal/unnecessary_symbol_str.rs:18:5 | LL | Symbol::intern("foo").to_ident_string() != "Self"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Symbol::intern("foo") != rustc_span::symbol::kw::SelfUpper` error: unnecessary `Symbol` to string conversion - --> tests/ui-internal/unnecessary_symbol_str.rs:18:5 + --> tests/ui-internal/unnecessary_symbol_str.rs:19:5 | LL | &*Ident::empty().as_str() == "clippy"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::empty().name == rustc_span::sym::clippy` error: unnecessary `Symbol` to string conversion - --> tests/ui-internal/unnecessary_symbol_str.rs:19:5 + --> tests/ui-internal/unnecessary_symbol_str.rs:20:5 | LL | "clippy" == Ident::empty().to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::empty().name` diff --git a/tests/ui-toml/array_size_threshold/array_size_threshold.stderr b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr index 009153bc4a1..41cb85b67df 100644 --- a/tests/ui-toml/array_size_threshold/array_size_threshold.stderr +++ b/tests/ui-toml/array_size_threshold/array_size_threshold.stderr @@ -10,22 +10,14 @@ LL | const ABOVE: [u8; 11] = [0; 11]; = help: to override `-D warnings` add `#[allow(clippy::large_const_arrays)]` error: allocating a local array larger than 10 bytes - --> tests/ui-toml/array_size_threshold/array_size_threshold.rs:4:25 - | -LL | const ABOVE: [u8; 11] = [0; 11]; - | ^^^^^^^ - | - = help: consider allocating on the heap with `vec![0; 11].into_boxed_slice()` - = note: `-D clippy::large-stack-arrays` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]` - -error: allocating a local array larger than 10 bytes --> tests/ui-toml/array_size_threshold/array_size_threshold.rs:8:17 | LL | let above = [0u8; 11]; | ^^^^^^^^^ | = help: consider allocating on the heap with `vec![0u8; 11].into_boxed_slice()` + = note: `-D clippy::large-stack-arrays` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors diff --git a/tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs b/tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs index 4142ced5f6b..2ae673a6def 100644 --- a/tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs +++ b/tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs @@ -1,7 +1,7 @@ #![warn(clippy::module_name_repetitions)] #![allow(dead_code)] -mod foo { +pub mod foo { // #12544 - shouldn't warn if item name consists only of an allowed prefix and a module name. // In this test, allowed prefixes are configured to be ["bar"]. diff --git a/tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs b/tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs index b132305d01c..dbd61992c0d 100644 --- a/tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs +++ b/tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs @@ -1,7 +1,7 @@ #![warn(clippy::module_name_repetitions)] #![allow(dead_code)] -mod foo { +pub mod foo { // #12544 - shouldn't warn if item name consists only of an allowed prefix and a module name. // In this test, allowed prefixes are configured to be all of the default prefixes and ["bar"]. diff --git a/tests/ui-toml/suppress_lint_in_const/test.rs b/tests/ui-toml/suppress_lint_in_const/test.rs index 232bccf6a15..4613a74b85d 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.rs +++ b/tests/ui-toml/suppress_lint_in_const/test.rs @@ -7,7 +7,8 @@ clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, - clippy::out_of_bounds_indexing + clippy::out_of_bounds_indexing, + clippy::needless_lifetimes )] const ARR: [i32; 2] = [1, 2]; diff --git a/tests/ui-toml/suppress_lint_in_const/test.stderr b/tests/ui-toml/suppress_lint_in_const/test.stderr index 5ce2ed2ffae..120f5c35cb0 100644 --- a/tests/ui-toml/suppress_lint_in_const/test.stderr +++ b/tests/ui-toml/suppress_lint_in_const/test.stderr @@ -1,5 +1,5 @@ error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:26:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:27:5 | LL | x[index]; | ^^^^^^^^ @@ -9,7 +9,7 @@ LL | x[index]; = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:41:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:42:5 | LL | v[0]; | ^^^^ @@ -17,7 +17,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:42:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:43:5 | LL | v[10]; | ^^^^^ @@ -25,7 +25,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:43:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:44:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -33,7 +33,7 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:49:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:50:5 | LL | v[N]; | ^^^^ @@ -41,7 +41,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> tests/ui-toml/suppress_lint_in_const/test.rs:50:5 + --> tests/ui-toml/suppress_lint_in_const/test.rs:51:5 | LL | v[M]; | ^^^^ diff --git a/tests/ui-toml/unwrap_used/unwrap_used.fixed b/tests/ui-toml/unwrap_used/unwrap_used.fixed index baf939af24e..cdb8fa0454c 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.fixed +++ b/tests/ui-toml/unwrap_used/unwrap_used.fixed @@ -86,6 +86,7 @@ mod issue9612 { util(); } + #[allow(unconditional_panic)] fn util() { let _a: u8 = 4.try_into().unwrap(); let _a: u8 = 5.try_into().expect(""); diff --git a/tests/ui-toml/unwrap_used/unwrap_used.rs b/tests/ui-toml/unwrap_used/unwrap_used.rs index e300ba18c33..e53d53db5f7 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.rs +++ b/tests/ui-toml/unwrap_used/unwrap_used.rs @@ -86,6 +86,7 @@ mod issue9612 { util(); } + #[allow(unconditional_panic)] fn util() { let _a: u8 = 4.try_into().unwrap(); let _a: u8 = 5.try_into().expect(""); diff --git a/tests/ui-toml/unwrap_used/unwrap_used.stderr b/tests/ui-toml/unwrap_used/unwrap_used.stderr index 320578bfabc..b58ce9b8af3 100644 --- a/tests/ui-toml/unwrap_used/unwrap_used.stderr +++ b/tests/ui-toml/unwrap_used/unwrap_used.stderr @@ -274,7 +274,7 @@ LL | let _ = &boxed_slice[1]; | ~~~~~~~~~~~~~~~ error: called `.get().unwrap()` on a slice - --> tests/ui-toml/unwrap_used/unwrap_used.rs:93:17 + --> tests/ui-toml/unwrap_used/unwrap_used.rs:94:17 | LL | let _ = Box::new([0]).get(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/borrow_box.fixed b/tests/ui/borrow_box.fixed index 5984cc4e930..08ea60583ea 100644 --- a/tests/ui/borrow_box.fixed +++ b/tests/ui/borrow_box.fixed @@ -3,7 +3,8 @@ #![allow( clippy::uninlined_format_args, clippy::disallowed_names, - clippy::needless_pass_by_ref_mut + clippy::needless_pass_by_ref_mut, + clippy::needless_lifetimes )] use std::fmt::Display; diff --git a/tests/ui/borrow_box.rs b/tests/ui/borrow_box.rs index 7f15fc83a1d..b55de1701da 100644 --- a/tests/ui/borrow_box.rs +++ b/tests/ui/borrow_box.rs @@ -3,7 +3,8 @@ #![allow( clippy::uninlined_format_args, clippy::disallowed_names, - clippy::needless_pass_by_ref_mut + clippy::needless_pass_by_ref_mut, + clippy::needless_lifetimes )] use std::fmt::Display; diff --git a/tests/ui/borrow_box.stderr b/tests/ui/borrow_box.stderr index ed4308161bb..6f80f86c3b3 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<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:24:14 + --> tests/ui/borrow_box.rs:25:14 | LL | let foo: &Box<bool>; | ^^^^^^^^^^ help: try: `&bool` @@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)] | ^^^^^^^^^^^^^^^^^^^^ error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:29:10 + --> tests/ui/borrow_box.rs:30:10 | LL | foo: &'a Box<bool>, | ^^^^^^^^^^^^^ help: try: `&'a bool` error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:34:17 + --> tests/ui/borrow_box.rs:35:17 | LL | fn test4(a: &Box<bool>); | ^^^^^^^^^^ help: try: `&bool` error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:95:25 + --> tests/ui/borrow_box.rs:96:25 | LL | pub fn test14(_display: &Box<dyn Display>) {} | ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display` error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:97:25 + --> tests/ui/borrow_box.rs:98:25 | LL | pub fn test15(_display: &Box<dyn Display + Send>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:99:29 + --> tests/ui/borrow_box.rs:100:29 | LL | pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)` error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:102:25 + --> tests/ui/borrow_box.rs:103:25 | LL | pub fn test17(_display: &Box<impl Display>) {} | ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display` error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:104:25 + --> tests/ui/borrow_box.rs:105:25 | LL | pub fn test18(_display: &Box<impl Display + Send>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)` error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:106:29 + --> tests/ui/borrow_box.rs:107:29 | LL | pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)` error: you seem to be trying to use `&Box<T>`. Consider using just `&T` - --> tests/ui/borrow_box.rs:112:25 + --> tests/ui/borrow_box.rs:113:25 | LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)` diff --git a/tests/ui/boxed_local.rs b/tests/ui/boxed_local.rs index fbd9e12fc18..e2c27e585fc 100644 --- a/tests/ui/boxed_local.rs +++ b/tests/ui/boxed_local.rs @@ -3,7 +3,8 @@ clippy::needless_pass_by_value, clippy::unused_unit, clippy::redundant_clone, - clippy::match_single_binding + clippy::match_single_binding, + clippy::needless_lifetimes )] #![warn(clippy::boxed_local)] diff --git a/tests/ui/boxed_local.stderr b/tests/ui/boxed_local.stderr index 7710233fa4d..d3156c820b2 100644 --- a/tests/ui/boxed_local.stderr +++ b/tests/ui/boxed_local.stderr @@ -1,5 +1,5 @@ error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:39:13 + --> tests/ui/boxed_local.rs:40:13 | LL | fn warn_arg(x: Box<A>) { | ^ @@ -8,19 +8,19 @@ LL | fn warn_arg(x: Box<A>) { = help: to override `-D warnings` add `#[allow(clippy::boxed_local)]` error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:122:12 + --> tests/ui/boxed_local.rs:123:12 | LL | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {} | ^^^^^^^^^^^ error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:187:44 + --> tests/ui/boxed_local.rs:188:44 | LL | fn default_impl_x(self: Box<Self>, x: Box<u32>) -> u32 { | ^ error: local variable doesn't need to be boxed here - --> tests/ui/boxed_local.rs:195:16 + --> tests/ui/boxed_local.rs:196:16 | LL | fn foo(x: Box<u32>) {} | ^ diff --git a/tests/ui/crashes/ice-12284.rs b/tests/ui/crashes/ice-12284.rs deleted file mode 100644 index 8d1dbface8e..00000000000 --- a/tests/ui/crashes/ice-12284.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![allow(incomplete_features)] -#![feature(unnamed_fields)] - -#[repr(C)] -struct Foo { - _: struct { - }, -} - -fn main() {} diff --git a/tests/ui/crashes/ice-6251.stderr b/tests/ui/crashes/ice-6251.stderr index 82e7d723586..77c3e6288ce 100644 --- a/tests/ui/crashes/ice-6251.stderr +++ b/tests/ui/crashes/ice-6251.stderr @@ -1,8 +1,8 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> tests/ui/crashes/ice-6251.rs:4:45 + --> tests/ui/crashes/ice-6251.rs:4:48 | LL | fn bug<T>() -> impl Iterator<Item = [(); { |x: [u8]| x }]> { - | ^ doesn't have a size known at compile-time + | ^^^^ doesn't have a size known at compile-time | = help: the trait `std::marker::Sized` is not implemented for `[u8]` = help: unsized fn params are gated as an unstable feature diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed index 8bd9eea75bb..837069cae6d 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.fixed +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.fixed @@ -9,7 +9,7 @@ struct Baz<'a> { bar: &'a Bar, } -impl<'a> Foo for Baz<'a> {} +impl Foo for Baz<'_> {} impl Bar { fn baz(&self) -> impl Foo + '_ { diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr b/tests/ui/crashes/needless_lifetimes_impl_trait.stderr index 3a2d1f4410e..bed6aab25c4 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.stderr +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.stderr @@ -1,8 +1,8 @@ error: the following explicit lifetimes could be elided: 'a - --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:15:12 + --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:12:6 | -LL | fn baz<'a>(&'a self) -> impl Foo + 'a { - | ^^ ^^ ^^ +LL | impl<'a> Foo for Baz<'a> {} + | ^^ ^^ | note: the lint level is defined here --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:1:9 @@ -11,9 +11,21 @@ LL | #![deny(clippy::needless_lifetimes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: elide the lifetimes | +LL - impl<'a> Foo for Baz<'a> {} +LL + impl Foo for Baz<'_> {} + | + +error: the following explicit lifetimes could be elided: 'a + --> tests/ui/crashes/needless_lifetimes_impl_trait.rs:15:12 + | +LL | fn baz<'a>(&'a self) -> impl Foo + 'a { + | ^^ ^^ ^^ + | +help: elide the lifetimes + | LL - fn baz<'a>(&'a self) -> impl Foo + 'a { LL + fn baz(&self) -> impl Foo + '_ { | -error: aborting due to 1 previous error +error: aborting due to 2 previous errors diff --git a/tests/ui/dbg_macro/dbg_macro.fixed b/tests/ui/dbg_macro/dbg_macro.fixed index e3525191423..bda9221a5e1 100644 --- a/tests/ui/dbg_macro/dbg_macro.fixed +++ b/tests/ui/dbg_macro/dbg_macro.fixed @@ -1,5 +1,5 @@ #![warn(clippy::dbg_macro)] -#![allow(clippy::unnecessary_operation, clippy::no_effect)] +#![allow(clippy::unnecessary_operation, clippy::no_effect, clippy::unit_arg)] fn foo(n: u32) -> u32 { if let Some(n) = n.checked_sub(4) { n } else { n } diff --git a/tests/ui/dbg_macro/dbg_macro.rs b/tests/ui/dbg_macro/dbg_macro.rs index 80606c2db05..8244254026b 100644 --- a/tests/ui/dbg_macro/dbg_macro.rs +++ b/tests/ui/dbg_macro/dbg_macro.rs @@ -1,5 +1,5 @@ #![warn(clippy::dbg_macro)] -#![allow(clippy::unnecessary_operation, clippy::no_effect)] +#![allow(clippy::unnecessary_operation, clippy::no_effect, clippy::unit_arg)] fn foo(n: u32) -> u32 { if let Some(n) = dbg!(n.checked_sub(4)) { n } else { n } diff --git a/tests/ui/derive.rs b/tests/ui/derive.rs index 4ac21f2cb4b..3647b242505 100644 --- a/tests/ui/derive.rs +++ b/tests/ui/derive.rs @@ -1,4 +1,9 @@ -#![allow(clippy::non_canonical_clone_impl, clippy::non_canonical_partial_ord_impl, dead_code)] +#![allow( + clippy::non_canonical_clone_impl, + clippy::non_canonical_partial_ord_impl, + clippy::needless_lifetimes, + dead_code +)] #![warn(clippy::expl_impl_clone_on_copy)] #[derive(Copy)] diff --git a/tests/ui/derive.stderr b/tests/ui/derive.stderr index 486e6dc1b6b..c072a9a6277 100644 --- a/tests/ui/derive.stderr +++ b/tests/ui/derive.stderr @@ -1,5 +1,5 @@ error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:7:1 + --> tests/ui/derive.rs:12:1 | LL | / impl Clone for Qux { LL | | @@ -10,7 +10,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> tests/ui/derive.rs:7:1 + --> tests/ui/derive.rs:12:1 | LL | / impl Clone for Qux { LL | | @@ -23,7 +23,7 @@ LL | | } = help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]` error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:32:1 + --> tests/ui/derive.rs:37:1 | LL | / impl<'a> Clone for Lt<'a> { LL | | @@ -34,7 +34,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> tests/ui/derive.rs:32:1 + --> tests/ui/derive.rs:37:1 | LL | / impl<'a> Clone for Lt<'a> { LL | | @@ -45,7 +45,7 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:44:1 + --> tests/ui/derive.rs:49:1 | LL | / impl Clone for BigArray { LL | | @@ -56,7 +56,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> tests/ui/derive.rs:44:1 + --> tests/ui/derive.rs:49:1 | LL | / impl Clone for BigArray { LL | | @@ -67,7 +67,7 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:56:1 + --> tests/ui/derive.rs:61:1 | LL | / impl Clone for FnPtr { LL | | @@ -78,7 +78,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> tests/ui/derive.rs:56:1 + --> tests/ui/derive.rs:61:1 | LL | / impl Clone for FnPtr { LL | | @@ -89,7 +89,7 @@ LL | | } | |_^ error: you are implementing `Clone` explicitly on a `Copy` type - --> tests/ui/derive.rs:77:1 + --> tests/ui/derive.rs:82:1 | LL | / impl<T: Clone> Clone for Generic2<T> { LL | | @@ -100,7 +100,7 @@ LL | | } | |_^ | note: consider deriving `Clone` or removing `Copy` - --> tests/ui/derive.rs:77:1 + --> tests/ui/derive.rs:82:1 | LL | / impl<T: Clone> Clone for Generic2<T> { LL | | diff --git a/tests/ui/doc/doc-fixable.fixed b/tests/ui/doc/doc-fixable.fixed index c2e4a124d2a..8a379330c48 100644 --- a/tests/ui/doc/doc-fixable.fixed +++ b/tests/ui/doc/doc-fixable.fixed @@ -3,7 +3,7 @@ #![allow(dead_code, incomplete_features)] #![warn(clippy::doc_markdown)] -#![feature(custom_inner_attributes, generic_const_exprs, const_option)] +#![feature(custom_inner_attributes, generic_const_exprs)] #![rustfmt::skip] /// The `foo_bar` function does _nothing_. See also `foo::bar`. (note the dot there) diff --git a/tests/ui/doc/doc-fixable.rs b/tests/ui/doc/doc-fixable.rs index de71cf73ffe..35f43d98e79 100644 --- a/tests/ui/doc/doc-fixable.rs +++ b/tests/ui/doc/doc-fixable.rs @@ -3,7 +3,7 @@ #![allow(dead_code, incomplete_features)] #![warn(clippy::doc_markdown)] -#![feature(custom_inner_attributes, generic_const_exprs, const_option)] +#![feature(custom_inner_attributes, generic_const_exprs)] #![rustfmt::skip] /// The foo_bar function does _nothing_. See also foo::bar. (note the dot there) diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed index ca422ee29c1..f1baf28200e 100644 --- a/tests/ui/eta.fixed +++ b/tests/ui/eta.fixed @@ -9,7 +9,8 @@ clippy::redundant_closure_call, clippy::uninlined_format_args, clippy::useless_vec, - clippy::unnecessary_map_on_constructor + clippy::unnecessary_map_on_constructor, + clippy::needless_lifetimes )] use std::path::{Path, PathBuf}; diff --git a/tests/ui/eta.rs b/tests/ui/eta.rs index c0db91c03ef..c52a51880bf 100644 --- a/tests/ui/eta.rs +++ b/tests/ui/eta.rs @@ -9,7 +9,8 @@ clippy::redundant_closure_call, clippy::uninlined_format_args, clippy::useless_vec, - clippy::unnecessary_map_on_constructor + clippy::unnecessary_map_on_constructor, + clippy::needless_lifetimes )] use std::path::{Path, PathBuf}; diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr index 5540261fc57..1731a4377f5 100644 --- a/tests/ui/eta.stderr +++ b/tests/ui/eta.stderr @@ -1,5 +1,5 @@ error: redundant closure - --> tests/ui/eta.rs:30:27 + --> tests/ui/eta.rs:31:27 | LL | let a = Some(1u8).map(|a| foo(a)); | ^^^^^^^^^^ help: replace the closure with the function itself: `foo` @@ -8,31 +8,31 @@ LL | let a = Some(1u8).map(|a| foo(a)); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]` error: redundant closure - --> tests/ui/eta.rs:34:40 + --> tests/ui/eta.rs:35:40 | LL | let _: Option<Vec<u8>> = true.then(|| vec![]); // special case vec! | ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new` error: redundant closure - --> tests/ui/eta.rs:35:35 + --> tests/ui/eta.rs:36:35 | LL | let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted? | ^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo2` error: redundant closure - --> tests/ui/eta.rs:36:26 + --> tests/ui/eta.rs:37:26 | LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted | ^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `below` error: redundant closure - --> tests/ui/eta.rs:43:27 + --> tests/ui/eta.rs:44:27 | LL | let e = Some(1u8).map(|a| generic(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic` error: redundant closure - --> tests/ui/eta.rs:95:51 + --> tests/ui/eta.rs:96:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo` @@ -41,169 +41,169 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo()); = help: to override `-D warnings` add `#[allow(clippy::redundant_closure_for_method_calls)]` error: redundant closure - --> tests/ui/eta.rs:96:51 + --> tests/ui/eta.rs:97:51 | LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo()); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `TestTrait::trait_foo` error: redundant closure - --> tests/ui/eta.rs:98:42 + --> tests/ui/eta.rs:99:42 | LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear()); | ^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::vec::Vec::clear` error: redundant closure - --> tests/ui/eta.rs:102:29 + --> tests/ui/eta.rs:103:29 | LL | let e = Some("str").map(|s| s.to_string()); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string` error: redundant closure - --> tests/ui/eta.rs:103:27 + --> tests/ui/eta.rs:104:27 | LL | let e = Some('a').map(|s| s.to_uppercase()); | ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_uppercase` error: redundant closure - --> tests/ui/eta.rs:105:65 + --> tests/ui/eta.rs:106:65 | LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_ascii_uppercase` error: redundant closure - --> tests/ui/eta.rs:168:22 + --> tests/ui/eta.rs:169:22 | LL | requires_fn_once(|| x()); | ^^^^^^ help: replace the closure with the function itself: `x` error: redundant closure - --> tests/ui/eta.rs:175:27 + --> tests/ui/eta.rs:176:27 | LL | let a = Some(1u8).map(|a| foo_ptr(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr` error: redundant closure - --> tests/ui/eta.rs:180:27 + --> tests/ui/eta.rs:181:27 | LL | let a = Some(1u8).map(|a| closure(a)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure` error: redundant closure - --> tests/ui/eta.rs:212:28 + --> tests/ui/eta.rs:213:28 | LL | x.into_iter().for_each(|x| add_to_res(x)); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res` error: redundant closure - --> tests/ui/eta.rs:213:28 + --> tests/ui/eta.rs:214:28 | LL | y.into_iter().for_each(|x| add_to_res(x)); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res` error: redundant closure - --> tests/ui/eta.rs:214:28 + --> tests/ui/eta.rs:215:28 | LL | z.into_iter().for_each(|x| add_to_res(x)); | ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `add_to_res` error: redundant closure - --> tests/ui/eta.rs:221:21 + --> tests/ui/eta.rs:222:21 | LL | Some(1).map(|n| closure(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure` error: redundant closure - --> tests/ui/eta.rs:225:21 + --> tests/ui/eta.rs:226:21 | LL | Some(1).map(|n| in_loop(n)); | ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop` error: redundant closure - --> tests/ui/eta.rs:318:18 + --> tests/ui/eta.rs:319:18 | LL | takes_fn_mut(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> tests/ui/eta.rs:321:19 + --> tests/ui/eta.rs:322:19 | LL | takes_fn_once(|| f()); | ^^^^^^ help: replace the closure with the function itself: `&mut f` error: redundant closure - --> tests/ui/eta.rs:325:26 + --> tests/ui/eta.rs:326:26 | LL | move || takes_fn_mut(|| f_used_once()) | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once` error: redundant closure - --> tests/ui/eta.rs:337:19 + --> tests/ui/eta.rs:338:19 | LL | array_opt.map(|a| a.as_slice()); | ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice` error: redundant closure - --> tests/ui/eta.rs:340:19 + --> tests/ui/eta.rs:341:19 | LL | slice_opt.map(|s| s.len()); | ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len` error: redundant closure - --> tests/ui/eta.rs:343:17 + --> tests/ui/eta.rs:344:17 | LL | ptr_opt.map(|p| p.is_null()); | ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null` error: redundant closure - --> tests/ui/eta.rs:347:17 + --> tests/ui/eta.rs:348:17 | LL | dyn_opt.map(|d| d.method_on_dyn()); | ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn` error: redundant closure - --> tests/ui/eta.rs:407:19 + --> tests/ui/eta.rs:408:19 | LL | let _ = f(&0, |x, y| f2(x, y)); | ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `f2` error: redundant closure - --> tests/ui/eta.rs:435:22 + --> tests/ui/eta.rs:436:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `Test::method` error: redundant closure - --> tests/ui/eta.rs:439:22 + --> tests/ui/eta.rs:440:22 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `super::Outer::method` error: redundant closure - --> tests/ui/eta.rs:452:18 + --> tests/ui/eta.rs:453:18 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `test_mod::Test::method` error: redundant closure - --> tests/ui/eta.rs:459:30 + --> tests/ui/eta.rs:460:30 | LL | test.map(|t| t.method()) | ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `crate::issue_10854::d::Test::method` error: redundant closure - --> tests/ui/eta.rs:478:38 + --> tests/ui/eta.rs:479:38 | LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `&f` error: redundant closure - --> tests/ui/eta.rs:482:38 + --> tests/ui/eta.rs:483:38 | LL | let x = Box::new(|| None.map(|x| f(x))); | ^^^^^^^^ help: replace the closure with the function itself: `f` error: redundant closure - --> tests/ui/eta.rs:499:35 + --> tests/ui/eta.rs:500:35 | LL | let _field = bind.or_else(|| get_default()).unwrap(); | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `get_default` diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr index bae853ac5c1..050c039f834 100644 --- a/tests/ui/expect_fun_call.stderr +++ b/tests/ui/expect_fun_call.stderr @@ -1,4 +1,4 @@ -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:35:26 | LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code)); @@ -7,85 +7,85 @@ LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code = note: `-D clippy::expect-fun-call` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::expect_fun_call)]` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:38:26 | LL | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:41:37 | LL | with_none_and_format_with_macro.expect(format!("Error {}: fake error", one!()).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("Error {}: fake error", one!()))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:51:25 | LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:54:25 | LL | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:66:17 | LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{} {}", 1, 2))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:87:21 | LL | Some("foo").expect(&get_string()); | ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:88:21 | LL | Some("foo").expect(get_string().as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:89:21 | LL | Some("foo").expect(get_string().as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:91:21 | LL | Some("foo").expect(get_static_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_static_str()) })` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:92:21 | LL | Some("foo").expect(get_non_static_str(&0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:96:16 | LL | Some(true).expect(&format!("key {}, {}", 1, 2)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:102:17 | LL | opt_ref.expect(&format!("{:?}", opt_ref)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{:?}", opt_ref))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:106:20 | LL | format_capture.expect(&format!("{error_code}")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}"))` -error: use of `expect` followed by a function call +error: function call inside of `expect` --> tests/ui/expect_fun_call.rs:109:30 | LL | format_capture_and_value.expect(&format!("{error_code}, {}", 1)); diff --git a/tests/ui/explicit_auto_deref.fixed b/tests/ui/explicit_auto_deref.fixed index 255b2c5a220..9d476259b87 100644 --- a/tests/ui/explicit_auto_deref.fixed +++ b/tests/ui/explicit_auto_deref.fixed @@ -10,7 +10,8 @@ clippy::redundant_field_names, clippy::too_many_arguments, clippy::borrow_deref_ref, - clippy::let_unit_value + clippy::let_unit_value, + clippy::needless_lifetimes )] trait CallableStr { diff --git a/tests/ui/explicit_auto_deref.rs b/tests/ui/explicit_auto_deref.rs index 99906999f01..23307c837f0 100644 --- a/tests/ui/explicit_auto_deref.rs +++ b/tests/ui/explicit_auto_deref.rs @@ -10,7 +10,8 @@ clippy::redundant_field_names, clippy::too_many_arguments, clippy::borrow_deref_ref, - clippy::let_unit_value + clippy::let_unit_value, + clippy::needless_lifetimes )] trait CallableStr { diff --git a/tests/ui/explicit_auto_deref.stderr b/tests/ui/explicit_auto_deref.stderr index 53784934f63..0b05a554eb1 100644 --- a/tests/ui/explicit_auto_deref.stderr +++ b/tests/ui/explicit_auto_deref.stderr @@ -1,5 +1,5 @@ error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:68:19 + --> tests/ui/explicit_auto_deref.rs:69:19 | LL | let _: &str = &*s; | ^^^ help: try: `&s` @@ -8,271 +8,271 @@ LL | let _: &str = &*s; = help: to override `-D warnings` add `#[allow(clippy::explicit_auto_deref)]` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:69:19 + --> tests/ui/explicit_auto_deref.rs:70:19 | LL | let _: &str = &*{ String::new() }; | ^^^^^^^^^^^^^^^^^^^ help: try: `&{ String::new() }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:70:19 + --> tests/ui/explicit_auto_deref.rs:71:19 | LL | let _: &str = &mut *{ String::new() }; | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut { String::new() }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:74:11 + --> tests/ui/explicit_auto_deref.rs:75:11 | LL | f_str(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:78:13 + --> tests/ui/explicit_auto_deref.rs:79:13 | LL | f_str_t(&*s, &*s); // Don't lint second param. | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:81:24 + --> tests/ui/explicit_auto_deref.rs:82:24 | LL | let _: &Box<i32> = &**b; | ^^^^ help: try: `&b` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:87:7 + --> tests/ui/explicit_auto_deref.rs:88:7 | LL | c(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:93:9 + --> tests/ui/explicit_auto_deref.rs:94:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:97:11 + --> tests/ui/explicit_auto_deref.rs:98:11 | LL | { &**x } | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:101:9 + --> tests/ui/explicit_auto_deref.rs:102:9 | LL | &**{ x } | ^^^^^^^^ help: try: `{ x }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:105:9 + --> tests/ui/explicit_auto_deref.rs:106:9 | LL | &***x | ^^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:122:12 + --> tests/ui/explicit_auto_deref.rs:123:12 | LL | f1(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:123:12 + --> tests/ui/explicit_auto_deref.rs:124:12 | LL | f2(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:124:12 + --> tests/ui/explicit_auto_deref.rs:125:12 | LL | f3(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:125:27 + --> tests/ui/explicit_auto_deref.rs:126:27 | LL | f4.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:126:12 + --> tests/ui/explicit_auto_deref.rs:127:12 | LL | f5(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:127:12 + --> tests/ui/explicit_auto_deref.rs:128:12 | LL | f6(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:128:27 + --> tests/ui/explicit_auto_deref.rs:129:27 | LL | f7.callable_str()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:129:25 + --> tests/ui/explicit_auto_deref.rs:130:25 | LL | f8.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:130:12 + --> tests/ui/explicit_auto_deref.rs:131:12 | LL | f9(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:131:13 + --> tests/ui/explicit_auto_deref.rs:132:13 | LL | f10(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:132:26 + --> tests/ui/explicit_auto_deref.rs:133:26 | LL | f11.callable_t()(&*x); | ^^^ help: try: `&x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:136:16 + --> tests/ui/explicit_auto_deref.rs:137:16 | LL | let _ = S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:141:21 + --> tests/ui/explicit_auto_deref.rs:142:21 | LL | let _ = S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:157:30 + --> tests/ui/explicit_auto_deref.rs:158:30 | LL | let _ = Self::S1(&**s); | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:158:35 + --> tests/ui/explicit_auto_deref.rs:159:35 | LL | let _ = Self::S2 { s: &**s }; | ^^^^ help: try: `s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:161:20 + --> tests/ui/explicit_auto_deref.rs:162:20 | LL | let _ = E1::S1(&*s); | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:162:25 + --> tests/ui/explicit_auto_deref.rs:163:25 | LL | let _ = E1::S2 { s: &*s }; | ^^^ help: try: `&s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:180:13 + --> tests/ui/explicit_auto_deref.rs:181:13 | LL | let _ = (*b).foo; | ^^^^ help: try: `b` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:181:13 + --> tests/ui/explicit_auto_deref.rs:182:13 | LL | let _ = (**b).foo; | ^^^^^ help: try: `b` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:196:19 + --> tests/ui/explicit_auto_deref.rs:197:19 | LL | let _ = f_str(*ref_str); | ^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:198:19 + --> tests/ui/explicit_auto_deref.rs:199:19 | LL | let _ = f_str(**ref_ref_str); | ^^^^^^^^^^^^^ help: try: `ref_ref_str` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:208:12 + --> tests/ui/explicit_auto_deref.rs:209:12 | LL | f_str(&&*ref_str); // `needless_borrow` will suggest removing both references | ^^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:209:12 + --> tests/ui/explicit_auto_deref.rs:210:12 | LL | f_str(&&**ref_str); // `needless_borrow` will suggest removing only one reference | ^^^^^^^^^^ help: try: `ref_str` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:218:41 + --> tests/ui/explicit_auto_deref.rs:219:41 | LL | let _ = || -> &'static str { return *s }; | ^^ help: try: `s` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:237:9 + --> tests/ui/explicit_auto_deref.rs:238:9 | LL | &**x | ^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:260:8 + --> tests/ui/explicit_auto_deref.rs:261:8 | LL | c1(*x); | ^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:263:20 + --> tests/ui/explicit_auto_deref.rs:264:20 | LL | return *x; | ^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:265:9 + --> tests/ui/explicit_auto_deref.rs:266:9 | LL | *x | ^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:299:20 + --> tests/ui/explicit_auto_deref.rs:300:20 | LL | Some(x) => &mut *x, | ^^^^^^^ help: try: `x` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:332:22 + --> tests/ui/explicit_auto_deref.rs:333:22 | LL | let _ = &mut (*{ x.u }).x; | ^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:338:22 + --> tests/ui/explicit_auto_deref.rs:339:22 | LL | let _ = &mut (**x.u).x; | ^^^^^^^ help: try: `(*x.u)` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:339:22 + --> tests/ui/explicit_auto_deref.rs:340:22 | LL | let _ = &mut (**{ x.u }).x; | ^^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:343:22 + --> tests/ui/explicit_auto_deref.rs:344:22 | LL | let _ = &mut (*x.u).x; | ^^^^^^ help: try: `x.u` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:344:22 + --> tests/ui/explicit_auto_deref.rs:345:22 | LL | let _ = &mut (*{ x.u }).x; | ^^^^^^^^^^ help: try: `{ x.u }` error: deref which would be done by auto-deref - --> tests/ui/explicit_auto_deref.rs:367:13 + --> tests/ui/explicit_auto_deref.rs:368:13 | LL | foo(&*wrapped_bar); | ^^^^^^^^^^^^^ help: try: `&wrapped_bar` diff --git a/tests/ui/extra_unused_lifetimes.rs b/tests/ui/extra_unused_lifetimes.rs index cdfaf8d3afe..17d2ed9f50c 100644 --- a/tests/ui/extra_unused_lifetimes.rs +++ b/tests/ui/extra_unused_lifetimes.rs @@ -114,9 +114,17 @@ mod second_case { fn hey(); } + // Should lint. The response to the above comment incorrectly called this a false positive. The + // lifetime `'a` can be removed, as demonstrated below. impl<'a, T: Source + ?Sized + 'a> Source for Box<T> { fn hey() {} } + + struct OtherBox<T: ?Sized>(Box<T>); + + impl<T: Source + ?Sized> Source for OtherBox<T> { + fn hey() {} + } } // Should not lint diff --git a/tests/ui/extra_unused_lifetimes.stderr b/tests/ui/extra_unused_lifetimes.stderr index 56292cb5d1a..85fbb7568ff 100644 --- a/tests/ui/extra_unused_lifetimes.stderr +++ b/tests/ui/extra_unused_lifetimes.stderr @@ -37,5 +37,11 @@ error: this lifetime isn't used in the function definition LL | pub fn something<'c>() -> Self { | ^^ -error: aborting due to 6 previous errors +error: this lifetime isn't used in the impl + --> tests/ui/extra_unused_lifetimes.rs:119:10 + | +LL | impl<'a, T: Source + ?Sized + 'a> Source for Box<T> { + | ^^ + +error: aborting due to 7 previous errors diff --git a/tests/ui/get_unwrap.fixed b/tests/ui/get_unwrap.fixed index 62beb195939..2dd3c30a4e2 100644 --- a/tests/ui/get_unwrap.fixed +++ b/tests/ui/get_unwrap.fixed @@ -70,6 +70,7 @@ fn main() { mod issue9909 { #![allow(clippy::identity_op, clippy::unwrap_used, dead_code)] + #[allow(unconditional_panic)] fn reduced() { let f = &[1, 2, 3]; diff --git a/tests/ui/get_unwrap.rs b/tests/ui/get_unwrap.rs index 1e09ff5c67e..94226564cac 100644 --- a/tests/ui/get_unwrap.rs +++ b/tests/ui/get_unwrap.rs @@ -70,6 +70,7 @@ fn main() { mod issue9909 { #![allow(clippy::identity_op, clippy::unwrap_used, dead_code)] + #[allow(unconditional_panic)] fn reduced() { let f = &[1, 2, 3]; diff --git a/tests/ui/get_unwrap.stderr b/tests/ui/get_unwrap.stderr index 0f8b279da1e..8eacb249c60 100644 --- a/tests/ui/get_unwrap.stderr +++ b/tests/ui/get_unwrap.stderr @@ -266,7 +266,7 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec(); = help: consider using `expect()` to provide a better panic message error: called `.get().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:77:24 + --> tests/ui/get_unwrap.rs:78:24 | LL | let _x: &i32 = f.get(1 + 2).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -277,7 +277,7 @@ LL | let _x: &i32 = &f[1 + 2]; | ~~~~~~~~~ error: called `.get().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:80:18 + --> tests/ui/get_unwrap.rs:81:18 | LL | let _x = f.get(1 + 2).unwrap().to_string(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -288,7 +288,7 @@ LL | let _x = f[1 + 2].to_string(); | ~~~~~~~~ error: called `.get().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:83:18 + --> tests/ui/get_unwrap.rs:84:18 | LL | let _x = f.get(1 + 2).unwrap().abs(); | ^^^^^^^^^^^^^^^^^^^^^ @@ -299,7 +299,7 @@ LL | let _x = f[1 + 2].abs(); | ~~~~~~~~ error: called `.get_mut().unwrap()` on a slice - --> tests/ui/get_unwrap.rs:100:33 + --> tests/ui/get_unwrap.rs:101:33 | LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/implicit_saturating_sub.fixed b/tests/ui/implicit_saturating_sub.fixed index 81cc1494914..136238f9eca 100644 --- a/tests/ui/implicit_saturating_sub.fixed +++ b/tests/ui/implicit_saturating_sub.fixed @@ -222,3 +222,9 @@ fn main() { a - b }; } + +fn regression_13524(a: usize, b: usize, c: bool) -> usize { + if c { + 123 + } else { b.saturating_sub(a) } +} diff --git a/tests/ui/implicit_saturating_sub.rs b/tests/ui/implicit_saturating_sub.rs index f73396ebd27..e371e37fb2f 100644 --- a/tests/ui/implicit_saturating_sub.rs +++ b/tests/ui/implicit_saturating_sub.rs @@ -268,3 +268,13 @@ fn main() { a - b }; } + +fn regression_13524(a: usize, b: usize, c: bool) -> usize { + if c { + 123 + } else if a >= b { + 0 + } else { + b - a + } +} diff --git a/tests/ui/implicit_saturating_sub.stderr b/tests/ui/implicit_saturating_sub.stderr index 59a9ddbff2d..61319851228 100644 --- a/tests/ui/implicit_saturating_sub.stderr +++ b/tests/ui/implicit_saturating_sub.stderr @@ -185,5 +185,16 @@ LL | | i_64 -= 1; LL | | } | |_____^ help: try: `i_64 = i_64.saturating_sub(1);` -error: aborting due to 23 previous errors +error: manual arithmetic check found + --> tests/ui/implicit_saturating_sub.rs:275:12 + | +LL | } else if a >= b { + | ____________^ +LL | | 0 +LL | | } else { +LL | | b - a +LL | | } + | |_____^ help: replace it with: `{ b.saturating_sub(a) }` + +error: aborting due to 24 previous errors diff --git a/tests/ui/index_refutable_slice/if_let_slice_binding.rs b/tests/ui/index_refutable_slice/if_let_slice_binding.rs index 5bbdabcaad1..a4cb50bd682 100644 --- a/tests/ui/index_refutable_slice/if_let_slice_binding.rs +++ b/tests/ui/index_refutable_slice/if_let_slice_binding.rs @@ -1,5 +1,5 @@ #![deny(clippy::index_refutable_slice)] -#![allow(clippy::uninlined_format_args)] +#![allow(clippy::uninlined_format_args, clippy::needless_lifetimes)] //@no-rustfix: need to change the suggestion to a multipart suggestion diff --git a/tests/ui/infinite_loops.rs b/tests/ui/infinite_loops.rs index b2d522fa011..b6cb7ff49b0 100644 --- a/tests/ui/infinite_loops.rs +++ b/tests/ui/infinite_loops.rs @@ -390,4 +390,42 @@ fn span_inside_fn() { } } +fn continue_outer() { + // Should not lint (issue #13511) + let mut count = 0; + 'outer: loop { + if count != 0 { + break; + } + + loop { + count += 1; + continue 'outer; + } + } + + // This should lint as we continue the loop itself + 'infinite: loop { + //~^ ERROR: infinite loop detected + loop { + continue 'infinite; + } + } + // This should lint as we continue an inner loop + loop { + //~^ ERROR: infinite loop detected + 'inner: loop { + loop { + continue 'inner; + } + } + } + + // This should lint as we continue the loop itself + loop { + //~^ ERROR: infinite loop detected + continue; + } +} + fn main() {} diff --git a/tests/ui/infinite_loops.stderr b/tests/ui/infinite_loops.stderr index ec6bd81dc17..7635a7442f4 100644 --- a/tests/ui/infinite_loops.stderr +++ b/tests/ui/infinite_loops.stderr @@ -255,5 +255,67 @@ LL | | }) | = help: if this is not intended, try adding a `break` or `return` condition in the loop -error: aborting due to 17 previous errors +error: infinite loop detected + --> tests/ui/infinite_loops.rs:408:5 + | +LL | / 'infinite: loop { +LL | | +LL | | loop { +LL | | continue 'infinite; +LL | | } +LL | | } + | |_____^ + | +help: if this is intentional, consider specifying `!` as function return + | +LL | fn continue_outer() -> ! { + | ++++ + +error: infinite loop detected + --> tests/ui/infinite_loops.rs:415:5 + | +LL | / loop { +LL | | +LL | | 'inner: loop { +LL | | loop { +... | +LL | | } +LL | | } + | |_____^ + | +help: if this is intentional, consider specifying `!` as function return + | +LL | fn continue_outer() -> ! { + | ++++ + +error: infinite loop detected + --> tests/ui/infinite_loops.rs:417:9 + | +LL | / 'inner: loop { +LL | | loop { +LL | | continue 'inner; +LL | | } +LL | | } + | |_________^ + | +help: if this is intentional, consider specifying `!` as function return + | +LL | fn continue_outer() -> ! { + | ++++ + +error: infinite loop detected + --> tests/ui/infinite_loops.rs:425:5 + | +LL | / loop { +LL | | +LL | | continue; +LL | | } + | |_____^ + | +help: if this is intentional, consider specifying `!` as function return + | +LL | fn continue_outer() -> ! { + | ++++ + +error: aborting due to 21 previous errors diff --git a/tests/ui/invalid_null_ptr_usage.fixed b/tests/ui/invalid_null_ptr_usage.fixed index 092e875a255..ba225102c98 100644 --- a/tests/ui/invalid_null_ptr_usage.fixed +++ b/tests/ui/invalid_null_ptr_usage.fixed @@ -1,44 +1,44 @@ fn main() { unsafe { - let _slice: &[usize] = std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); - let _slice: &[usize] = std::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::NonNull::dangling().as_ptr(), 0); + let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::NonNull::dangling().as_ptr(), 0); - let _slice: &[usize] = std::slice::from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0); + let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::NonNull::dangling().as_ptr(), 0); - std::ptr::copy::<usize>(core::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); - std::ptr::copy::<usize>(std::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + std::ptr::copy::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); + std::ptr::copy::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); - std::ptr::copy_nonoverlapping::<usize>(core::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); - std::ptr::copy_nonoverlapping::<usize>(std::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + std::ptr::copy_nonoverlapping::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); + std::ptr::copy_nonoverlapping::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::NonNull::dangling().as_ptr(), 0); struct A; // zero sized struct assert_eq!(std::mem::size_of::<A>(), 0); - let _a: A = std::ptr::read(core::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::read(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read(std::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read(std::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read_unaligned(std::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read_unaligned(std::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read_volatile(std::ptr::NonNull::dangling().as_ptr()); + let _a: A = std::ptr::read_volatile(std::ptr::NonNull::dangling().as_ptr()); - let _a: A = std::ptr::replace(core::ptr::NonNull::dangling().as_ptr(), A); + let _a: A = std::ptr::replace(std::ptr::NonNull::dangling().as_ptr(), A); let _slice: *const [usize] = std::ptr::slice_from_raw_parts(std::ptr::null_mut(), 0); // shouldn't lint let _slice: *const [usize] = std::ptr::slice_from_raw_parts_mut(std::ptr::null_mut(), 0); - std::ptr::swap::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A); - std::ptr::swap::<A>(&mut A, core::ptr::NonNull::dangling().as_ptr()); + std::ptr::swap::<A>(std::ptr::NonNull::dangling().as_ptr(), &mut A); + std::ptr::swap::<A>(&mut A, std::ptr::NonNull::dangling().as_ptr()); - std::ptr::swap_nonoverlapping::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A, 0); - std::ptr::swap_nonoverlapping::<A>(&mut A, core::ptr::NonNull::dangling().as_ptr(), 0); + std::ptr::swap_nonoverlapping::<A>(std::ptr::NonNull::dangling().as_ptr(), &mut A, 0); + std::ptr::swap_nonoverlapping::<A>(&mut A, std::ptr::NonNull::dangling().as_ptr(), 0); - std::ptr::write(core::ptr::NonNull::dangling().as_ptr(), A); + std::ptr::write(std::ptr::NonNull::dangling().as_ptr(), A); - std::ptr::write_unaligned(core::ptr::NonNull::dangling().as_ptr(), A); + std::ptr::write_unaligned(std::ptr::NonNull::dangling().as_ptr(), A); - std::ptr::write_volatile(core::ptr::NonNull::dangling().as_ptr(), A); + std::ptr::write_volatile(std::ptr::NonNull::dangling().as_ptr(), A); - std::ptr::write_bytes::<usize>(core::ptr::NonNull::dangling().as_ptr(), 42, 0); + std::ptr::write_bytes::<usize>(std::ptr::NonNull::dangling().as_ptr(), 42, 0); } } diff --git a/tests/ui/invalid_null_ptr_usage.stderr b/tests/ui/invalid_null_ptr_usage.stderr index a0be2c0ad75..613a2cc3688 100644 --- a/tests/ui/invalid_null_ptr_usage.stderr +++ b/tests/ui/invalid_null_ptr_usage.stderr @@ -2,7 +2,7 @@ error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:3:59 | LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null(), 0); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` | = note: `#[deny(clippy::invalid_null_ptr_usage)]` on by default @@ -10,127 +10,127 @@ error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:4:59 | LL | let _slice: &[usize] = std::slice::from_raw_parts(std::ptr::null_mut(), 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:6:63 | LL | let _slice: &[usize] = std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:8:33 | LL | std::ptr::copy::<usize>(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:9:73 | LL | std::ptr::copy::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:11:48 | LL | std::ptr::copy_nonoverlapping::<usize>(std::ptr::null(), std::ptr::NonNull::dangling().as_ptr(), 0); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:12:88 | LL | std::ptr::copy_nonoverlapping::<usize>(std::ptr::NonNull::dangling().as_ptr(), std::ptr::null_mut(), 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:17:36 | LL | let _a: A = std::ptr::read(std::ptr::null()); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:18:36 | LL | let _a: A = std::ptr::read(std::ptr::null_mut()); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:20:46 | LL | let _a: A = std::ptr::read_unaligned(std::ptr::null()); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:21:46 | LL | let _a: A = std::ptr::read_unaligned(std::ptr::null_mut()); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:23:45 | LL | let _a: A = std::ptr::read_volatile(std::ptr::null()); - | ^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:24:45 | LL | let _a: A = std::ptr::read_volatile(std::ptr::null_mut()); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:26:39 | LL | let _a: A = std::ptr::replace(std::ptr::null_mut(), A); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:30:29 | LL | std::ptr::swap::<A>(std::ptr::null_mut(), &mut A); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:31:37 | LL | std::ptr::swap::<A>(&mut A, std::ptr::null_mut()); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:33:44 | LL | std::ptr::swap_nonoverlapping::<A>(std::ptr::null_mut(), &mut A, 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:34:52 | LL | std::ptr::swap_nonoverlapping::<A>(&mut A, std::ptr::null_mut(), 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:36:25 | LL | std::ptr::write(std::ptr::null_mut(), A); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:38:35 | LL | std::ptr::write_unaligned(std::ptr::null_mut(), A); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:40:34 | LL | std::ptr::write_volatile(std::ptr::null_mut(), A); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: pointer must be non-null --> tests/ui/invalid_null_ptr_usage.rs:42:40 | LL | std::ptr::write_bytes::<usize>(std::ptr::null_mut(), 42, 0); - | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | ^^^^^^^^^^^^^^^^^^^^ help: change this to: `std::ptr::NonNull::dangling().as_ptr()` error: aborting due to 22 previous errors diff --git a/tests/ui/invalid_null_ptr_usage_no_std.fixed b/tests/ui/invalid_null_ptr_usage_no_std.fixed new file mode 100644 index 00000000000..2bbfe727424 --- /dev/null +++ b/tests/ui/invalid_null_ptr_usage_no_std.fixed @@ -0,0 +1,57 @@ +#![no_std] +#![feature(lang_items)] + +use core::panic::PanicInfo; + +#[lang = "eh_personality"] +extern "C" fn eh_personality() {} + +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + loop {} +} + +fn main() { + unsafe { + let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::NonNull::dangling().as_ptr(), 0); + + let _slice: &[usize] = core::slice::from_raw_parts_mut(core::ptr::NonNull::dangling().as_ptr(), 0); + + core::ptr::copy::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + core::ptr::copy::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + + core::ptr::copy_nonoverlapping::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + core::ptr::copy_nonoverlapping::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::NonNull::dangling().as_ptr(), 0); + + struct A; // zero sized struct + assert_eq!(core::mem::size_of::<A>(), 0); + + let _a: A = core::ptr::read(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = core::ptr::read(core::ptr::NonNull::dangling().as_ptr()); + + let _a: A = core::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = core::ptr::read_unaligned(core::ptr::NonNull::dangling().as_ptr()); + + let _a: A = core::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); + let _a: A = core::ptr::read_volatile(core::ptr::NonNull::dangling().as_ptr()); + + let _a: A = core::ptr::replace(core::ptr::NonNull::dangling().as_ptr(), A); + let _slice: *const [usize] = core::ptr::slice_from_raw_parts(core::ptr::null_mut(), 0); // shouldn't lint + let _slice: *const [usize] = core::ptr::slice_from_raw_parts_mut(core::ptr::null_mut(), 0); + + core::ptr::swap::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A); + core::ptr::swap::<A>(&mut A, core::ptr::NonNull::dangling().as_ptr()); + + core::ptr::swap_nonoverlapping::<A>(core::ptr::NonNull::dangling().as_ptr(), &mut A, 0); + core::ptr::swap_nonoverlapping::<A>(&mut A, core::ptr::NonNull::dangling().as_ptr(), 0); + + core::ptr::write(core::ptr::NonNull::dangling().as_ptr(), A); + + core::ptr::write_unaligned(core::ptr::NonNull::dangling().as_ptr(), A); + + core::ptr::write_volatile(core::ptr::NonNull::dangling().as_ptr(), A); + + core::ptr::write_bytes::<usize>(core::ptr::NonNull::dangling().as_ptr(), 42, 0); + } +} diff --git a/tests/ui/invalid_null_ptr_usage_no_std.rs b/tests/ui/invalid_null_ptr_usage_no_std.rs new file mode 100644 index 00000000000..cbce44f7c0d --- /dev/null +++ b/tests/ui/invalid_null_ptr_usage_no_std.rs @@ -0,0 +1,57 @@ +#![no_std] +#![feature(lang_items)] + +use core::panic::PanicInfo; + +#[lang = "eh_personality"] +extern "C" fn eh_personality() {} + +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + loop {} +} + +fn main() { + unsafe { + let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null(), 0); + let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null_mut(), 0); + + let _slice: &[usize] = core::slice::from_raw_parts_mut(core::ptr::null_mut(), 0); + + core::ptr::copy::<usize>(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); + core::ptr::copy::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); + + core::ptr::copy_nonoverlapping::<usize>(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); + core::ptr::copy_nonoverlapping::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); + + struct A; // zero sized struct + assert_eq!(core::mem::size_of::<A>(), 0); + + let _a: A = core::ptr::read(core::ptr::null()); + let _a: A = core::ptr::read(core::ptr::null_mut()); + + let _a: A = core::ptr::read_unaligned(core::ptr::null()); + let _a: A = core::ptr::read_unaligned(core::ptr::null_mut()); + + let _a: A = core::ptr::read_volatile(core::ptr::null()); + let _a: A = core::ptr::read_volatile(core::ptr::null_mut()); + + let _a: A = core::ptr::replace(core::ptr::null_mut(), A); + let _slice: *const [usize] = core::ptr::slice_from_raw_parts(core::ptr::null_mut(), 0); // shouldn't lint + let _slice: *const [usize] = core::ptr::slice_from_raw_parts_mut(core::ptr::null_mut(), 0); + + core::ptr::swap::<A>(core::ptr::null_mut(), &mut A); + core::ptr::swap::<A>(&mut A, core::ptr::null_mut()); + + core::ptr::swap_nonoverlapping::<A>(core::ptr::null_mut(), &mut A, 0); + core::ptr::swap_nonoverlapping::<A>(&mut A, core::ptr::null_mut(), 0); + + core::ptr::write(core::ptr::null_mut(), A); + + core::ptr::write_unaligned(core::ptr::null_mut(), A); + + core::ptr::write_volatile(core::ptr::null_mut(), A); + + core::ptr::write_bytes::<usize>(core::ptr::null_mut(), 42, 0); + } +} diff --git a/tests/ui/invalid_null_ptr_usage_no_std.stderr b/tests/ui/invalid_null_ptr_usage_no_std.stderr new file mode 100644 index 00000000000..df0d40e9e07 --- /dev/null +++ b/tests/ui/invalid_null_ptr_usage_no_std.stderr @@ -0,0 +1,136 @@ +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:16:60 + | +LL | let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null(), 0); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + | + = note: `#[deny(clippy::invalid_null_ptr_usage)]` on by default + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:17:60 + | +LL | let _slice: &[usize] = core::slice::from_raw_parts(core::ptr::null_mut(), 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:19:64 + | +LL | let _slice: &[usize] = core::slice::from_raw_parts_mut(core::ptr::null_mut(), 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:21:34 + | +LL | core::ptr::copy::<usize>(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:22:75 + | +LL | core::ptr::copy::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:24:49 + | +LL | core::ptr::copy_nonoverlapping::<usize>(core::ptr::null(), core::ptr::NonNull::dangling().as_ptr(), 0); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:25:90 + | +LL | core::ptr::copy_nonoverlapping::<usize>(core::ptr::NonNull::dangling().as_ptr(), core::ptr::null_mut(), 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:30:37 + | +LL | let _a: A = core::ptr::read(core::ptr::null()); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:31:37 + | +LL | let _a: A = core::ptr::read(core::ptr::null_mut()); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:33:47 + | +LL | let _a: A = core::ptr::read_unaligned(core::ptr::null()); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:34:47 + | +LL | let _a: A = core::ptr::read_unaligned(core::ptr::null_mut()); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:36:46 + | +LL | let _a: A = core::ptr::read_volatile(core::ptr::null()); + | ^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:37:46 + | +LL | let _a: A = core::ptr::read_volatile(core::ptr::null_mut()); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:39:40 + | +LL | let _a: A = core::ptr::replace(core::ptr::null_mut(), A); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:43:30 + | +LL | core::ptr::swap::<A>(core::ptr::null_mut(), &mut A); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:44:38 + | +LL | core::ptr::swap::<A>(&mut A, core::ptr::null_mut()); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:46:45 + | +LL | core::ptr::swap_nonoverlapping::<A>(core::ptr::null_mut(), &mut A, 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:47:53 + | +LL | core::ptr::swap_nonoverlapping::<A>(&mut A, core::ptr::null_mut(), 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:49:26 + | +LL | core::ptr::write(core::ptr::null_mut(), A); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:51:36 + | +LL | core::ptr::write_unaligned(core::ptr::null_mut(), A); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:53:35 + | +LL | core::ptr::write_volatile(core::ptr::null_mut(), A); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: pointer must be non-null + --> tests/ui/invalid_null_ptr_usage_no_std.rs:55:41 + | +LL | core::ptr::write_bytes::<usize>(core::ptr::null_mut(), 42, 0); + | ^^^^^^^^^^^^^^^^^^^^^ help: change this to: `core::ptr::NonNull::dangling().as_ptr()` + +error: aborting due to 22 previous errors + diff --git a/tests/ui/iter_without_into_iter.rs b/tests/ui/iter_without_into_iter.rs index 3054d848efb..d5b28e45453 100644 --- a/tests/ui/iter_without_into_iter.rs +++ b/tests/ui/iter_without_into_iter.rs @@ -1,6 +1,7 @@ //@no-rustfix //@aux-build:proc_macros.rs #![warn(clippy::iter_without_into_iter)] +#![allow(clippy::needless_lifetimes)] extern crate proc_macros; pub struct S1; diff --git a/tests/ui/iter_without_into_iter.stderr b/tests/ui/iter_without_into_iter.stderr index 382a7606f48..7c42fa1dd89 100644 --- a/tests/ui/iter_without_into_iter.stderr +++ b/tests/ui/iter_without_into_iter.stderr @@ -1,5 +1,5 @@ error: `iter` method without an `IntoIterator` impl for `&S1` - --> tests/ui/iter_without_into_iter.rs:8:5 + --> tests/ui/iter_without_into_iter.rs:9:5 | LL | / pub fn iter(&self) -> std::slice::Iter<'_, u8> { LL | | @@ -22,7 +22,7 @@ LL + } | error: `iter_mut` method without an `IntoIterator` impl for `&mut S1` - --> tests/ui/iter_without_into_iter.rs:12:5 + --> tests/ui/iter_without_into_iter.rs:13:5 | LL | / pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, u8> { LL | | @@ -43,7 +43,7 @@ LL + } | error: `iter` method without an `IntoIterator` impl for `&S3<'a>` - --> tests/ui/iter_without_into_iter.rs:28:5 + --> tests/ui/iter_without_into_iter.rs:29:5 | LL | / pub fn iter(&self) -> std::slice::Iter<'_, u8> { LL | | @@ -64,7 +64,7 @@ LL + } | error: `iter_mut` method without an `IntoIterator` impl for `&mut S3<'a>` - --> tests/ui/iter_without_into_iter.rs:32:5 + --> tests/ui/iter_without_into_iter.rs:33:5 | LL | / pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, u8> { LL | | @@ -85,7 +85,7 @@ LL + } | error: `iter` method without an `IntoIterator` impl for `&S8<T>` - --> tests/ui/iter_without_into_iter.rs:69:5 + --> tests/ui/iter_without_into_iter.rs:70:5 | LL | / pub fn iter(&self) -> std::slice::Iter<'static, T> { LL | | todo!() @@ -105,7 +105,7 @@ LL + } | error: `iter` method without an `IntoIterator` impl for `&S9<T>` - --> tests/ui/iter_without_into_iter.rs:77:5 + --> tests/ui/iter_without_into_iter.rs:78:5 | LL | / pub fn iter(&self) -> std::slice::Iter<'_, T> { LL | | @@ -126,7 +126,7 @@ LL + } | error: `iter_mut` method without an `IntoIterator` impl for `&mut S9<T>` - --> tests/ui/iter_without_into_iter.rs:81:5 + --> tests/ui/iter_without_into_iter.rs:82:5 | LL | / pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> { LL | | @@ -147,7 +147,7 @@ LL + } | error: `iter` method without an `IntoIterator` impl for `&Issue12037` - --> tests/ui/iter_without_into_iter.rs:130:13 + --> tests/ui/iter_without_into_iter.rs:131:13 | LL | / fn iter(&self) -> std::slice::Iter<'_, u8> { LL | | todo!() diff --git a/tests/ui/large_const_arrays.fixed b/tests/ui/large_const_arrays.fixed index 6011bb99dec..543ce460e7b 100644 --- a/tests/ui/large_const_arrays.fixed +++ b/tests/ui/large_const_arrays.fixed @@ -12,9 +12,9 @@ pub static FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; static FOO: [u32; 1_000_000] = [0u32; 1_000_000]; // Good -pub(crate) const G_FOO_PUB_CRATE: [u32; 1_000] = [0u32; 1_000]; -pub const G_FOO_PUB: [u32; 1_000] = [0u32; 1_000]; -const G_FOO: [u32; 1_000] = [0u32; 1_000]; +pub(crate) const G_FOO_PUB_CRATE: [u32; 250] = [0u32; 250]; +pub const G_FOO_PUB: [u32; 250] = [0u32; 250]; +const G_FOO: [u32; 250] = [0u32; 250]; fn main() { // Should lint @@ -26,10 +26,10 @@ fn main() { static BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; // Good - pub const G_BAR_PUB: [u32; 1_000] = [0u32; 1_000]; - const G_BAR: [u32; 1_000] = [0u32; 1_000]; - pub const G_BAR_STRUCT_PUB: [S; 500] = [S { data: [0; 32] }; 500]; - const G_BAR_STRUCT: [S; 500] = [S { data: [0; 32] }; 500]; - pub const G_BAR_S_PUB: [Option<&str>; 200] = [Some("str"); 200]; - const G_BAR_S: [Option<&str>; 200] = [Some("str"); 200]; + pub const G_BAR_PUB: [u32; 250] = [0u32; 250]; + const G_BAR: [u32; 250] = [0u32; 250]; + pub const G_BAR_STRUCT_PUB: [S; 4] = [S { data: [0; 32] }; 4]; + const G_BAR_STRUCT: [S; 4] = [S { data: [0; 32] }; 4]; + pub const G_BAR_S_PUB: [Option<&str>; 50] = [Some("str"); 50]; + const G_BAR_S: [Option<&str>; 50] = [Some("str"); 50]; } diff --git a/tests/ui/large_const_arrays.rs b/tests/ui/large_const_arrays.rs index a78425d7bc6..e23a8081171 100644 --- a/tests/ui/large_const_arrays.rs +++ b/tests/ui/large_const_arrays.rs @@ -12,9 +12,9 @@ pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000]; const FOO: [u32; 1_000_000] = [0u32; 1_000_000]; // Good -pub(crate) const G_FOO_PUB_CRATE: [u32; 1_000] = [0u32; 1_000]; -pub const G_FOO_PUB: [u32; 1_000] = [0u32; 1_000]; -const G_FOO: [u32; 1_000] = [0u32; 1_000]; +pub(crate) const G_FOO_PUB_CRATE: [u32; 250] = [0u32; 250]; +pub const G_FOO_PUB: [u32; 250] = [0u32; 250]; +const G_FOO: [u32; 250] = [0u32; 250]; fn main() { // Should lint @@ -26,10 +26,10 @@ fn main() { const BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000]; // Good - pub const G_BAR_PUB: [u32; 1_000] = [0u32; 1_000]; - const G_BAR: [u32; 1_000] = [0u32; 1_000]; - pub const G_BAR_STRUCT_PUB: [S; 500] = [S { data: [0; 32] }; 500]; - const G_BAR_STRUCT: [S; 500] = [S { data: [0; 32] }; 500]; - pub const G_BAR_S_PUB: [Option<&str>; 200] = [Some("str"); 200]; - const G_BAR_S: [Option<&str>; 200] = [Some("str"); 200]; + pub const G_BAR_PUB: [u32; 250] = [0u32; 250]; + const G_BAR: [u32; 250] = [0u32; 250]; + pub const G_BAR_STRUCT_PUB: [S; 4] = [S { data: [0; 32] }; 4]; + const G_BAR_STRUCT: [S; 4] = [S { data: [0; 32] }; 4]; + pub const G_BAR_S_PUB: [Option<&str>; 50] = [Some("str"); 50]; + const G_BAR_S: [Option<&str>; 50] = [Some("str"); 50]; } diff --git a/tests/ui/large_stack_arrays.rs b/tests/ui/large_stack_arrays.rs index 6bcaf481c9f..cd72b9bfa47 100644 --- a/tests/ui/large_stack_arrays.rs +++ b/tests/ui/large_stack_arrays.rs @@ -15,6 +15,12 @@ enum E { T(u32), } +const STATIC_PROMOTED_LARGE_ARRAY: &[u8; 512001] = &[0; 512001]; +const STATIC_PROMOTED_LARGE_ARRAY_WITH_NESTED: &[u8; 512001] = { + const NESTED: () = (); + &[0; 512001] +}; + pub static DOESNOTLINT: [u8; 512_001] = [0; 512_001]; pub static DOESNOTLINT2: [u8; 512_001] = { let x = 0; @@ -23,38 +29,38 @@ pub static DOESNOTLINT2: [u8; 512_001] = { fn issue_10741() { #[derive(Copy, Clone)] - struct Large([u32; 100_000]); + struct Large([u32; 2048]); fn build() -> Large { - Large([0; 100_000]) + Large([0; 2048]) } let _x = [build(); 3]; - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes let _y = [build(), build(), build()]; - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes } fn main() { let bad = ( [0u32; 20_000_000], - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes [S { data: [0; 32] }; 5000], - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes [Some(""); 20_000_000], - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes [E::T(0); 5000], - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes [0u8; usize::MAX], - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes ); let good = ( - [0u32; 1000], - [S { data: [0; 32] }; 1000], - [Some(""); 1000], - [E::T(0); 1000], + [0u32; 50], + [S { data: [0; 32] }; 4], + [Some(""); 50], + [E::T(0); 2], [(); 20_000_000], ); } @@ -68,7 +74,7 @@ fn issue_12586() { // Weird rule to test help messages. ($a:expr => $b:expr) => { [$a, $b, $a, $b] - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes }; ($id:ident; $n:literal) => { dummy!(::std::vec![$id;$n]) @@ -80,26 +86,26 @@ fn issue_12586() { macro_rules! create_then_move { ($id:ident; $n:literal) => {{ let _x_ = [$id; $n]; - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes _x_ }}; } - let x = [0u32; 50_000]; + let x = [0u32; 4096]; let y = vec![x, x, x, x, x]; let y = vec![dummy![x, x, x, x, x]]; let y = vec![dummy![[x, x, x, x, x]]]; let y = dummy![x, x, x, x, x]; let y = [x, x, dummy!(x), x, x]; - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes let y = dummy![x => x]; let y = dummy![x;5]; let y = dummy!(vec![dummy![x, x, x, x, x]]); let y = dummy![[x, x, x, x, x]]; - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes let y = proc_macros::make_it_big!([x; 1]); - //~^ ERROR: allocating a local array larger than 512000 bytes + //~^ ERROR: allocating a local array larger than 16384 bytes let y = vec![proc_macros::make_it_big!([x; 10])]; let y = vec![create_then_move![x; 5]; 5]; } diff --git a/tests/ui/large_stack_arrays.stderr b/tests/ui/large_stack_arrays.stderr index 06294ee8b8c..f48706415e6 100644 --- a/tests/ui/large_stack_arrays.stderr +++ b/tests/ui/large_stack_arrays.stderr @@ -1,5 +1,5 @@ -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:32:14 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:38:14 | LL | let _x = [build(); 3]; | ^^^^^^^^^^^^ @@ -8,64 +8,64 @@ LL | let _x = [build(); 3]; = note: `-D clippy::large-stack-arrays` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]` -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:35:14 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:41:14 | LL | let _y = [build(), build(), build()]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider allocating on the heap with `vec![build(), build(), build()].into_boxed_slice()` -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:41:9 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:47:9 | LL | [0u32; 20_000_000], | ^^^^^^^^^^^^^^^^^^ | = help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()` -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:43:9 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:49:9 | LL | [S { data: [0; 32] }; 5000], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider allocating on the heap with `vec![S { data: [0; 32] }; 5000].into_boxed_slice()` -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:45:9 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:51:9 | LL | [Some(""); 20_000_000], | ^^^^^^^^^^^^^^^^^^^^^^ | = help: consider allocating on the heap with `vec![Some(""); 20_000_000].into_boxed_slice()` -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:47:9 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:53:9 | LL | [E::T(0); 5000], | ^^^^^^^^^^^^^^^ | = help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()` -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:49:9 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:55:9 | LL | [0u8; usize::MAX], | ^^^^^^^^^^^^^^^^^ | = help: consider allocating on the heap with `vec![0u8; usize::MAX].into_boxed_slice()` -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:93:13 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:99:13 | LL | let y = [x, x, dummy!(x), x, x]; | ^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider allocating on the heap with `vec![x, x, dummy!(x), x, x].into_boxed_slice()` -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:70:13 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:76:13 | LL | [$a, $b, $a, $b] | ^^^^^^^^^^^^^^^^ @@ -75,22 +75,22 @@ LL | let y = dummy![x => x]; | = note: this error originates in the macro `dummy` (in Nightly builds, run with -Z macro-backtrace for more info) -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:98:20 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:104:20 | LL | let y = dummy![[x, x, x, x, x]]; | ^^^^^^^^^^^^^^^ | = help: consider allocating on the heap with `vec![x, x, x, x, x].into_boxed_slice()` -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:101:39 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:107:39 | LL | let y = proc_macros::make_it_big!([x; 1]); | ^^^^^^ -error: allocating a local array larger than 512000 bytes - --> tests/ui/large_stack_arrays.rs:82:23 +error: allocating a local array larger than 16384 bytes + --> tests/ui/large_stack_arrays.rs:88:23 | LL | let _x_ = [$id; $n]; | ^^^^^^^^^ diff --git a/tests/ui/manual_bits.fixed b/tests/ui/manual_bits.fixed index 4de01905e8a..8e5cb7d38b9 100644 --- a/tests/ui/manual_bits.fixed +++ b/tests/ui/manual_bits.fixed @@ -56,3 +56,14 @@ fn main() { let _ = (u128::BITS as usize).pow(5); let _ = &(u128::BITS as usize); } + +fn should_not_lint() { + macro_rules! bits_via_macro { + ($T: ty) => { + size_of::<$T>() * 8; + }; + } + + bits_via_macro!(u8); + bits_via_macro!(String); +} diff --git a/tests/ui/manual_bits.rs b/tests/ui/manual_bits.rs index d4f369fcf87..5e492ed15d2 100644 --- a/tests/ui/manual_bits.rs +++ b/tests/ui/manual_bits.rs @@ -56,3 +56,14 @@ fn main() { let _ = (size_of::<u128>() * 8).pow(5); let _ = &(size_of::<u128>() * 8); } + +fn should_not_lint() { + macro_rules! bits_via_macro { + ($T: ty) => { + size_of::<$T>() * 8; + }; + } + + bits_via_macro!(u8); + bits_via_macro!(String); +} diff --git a/tests/ui/manual_c_str_literals.fixed b/tests/ui/manual_c_str_literals.edition2021.fixed index a24d7088c88..391c63bb4b8 100644 --- a/tests/ui/manual_c_str_literals.fixed +++ b/tests/ui/manual_c_str_literals.edition2021.fixed @@ -1,3 +1,6 @@ +//@revisions: edition2018 edition2021 +//@[edition2018] edition:2018 +//@[edition2021] edition:2021 #![warn(clippy::manual_c_str_literals)] #![allow(clippy::no_effect)] diff --git a/tests/ui/manual_c_str_literals.stderr b/tests/ui/manual_c_str_literals.edition2021.stderr index 9c70bddb81c..beab29ccdda 100644 --- a/tests/ui/manual_c_str_literals.stderr +++ b/tests/ui/manual_c_str_literals.edition2021.stderr @@ -1,5 +1,5 @@ error: calling `CStr::new` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:31:5 + --> tests/ui/manual_c_str_literals.rs:34:5 | LL | CStr::from_bytes_with_nul(b"foo\0"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` @@ -8,73 +8,73 @@ LL | CStr::from_bytes_with_nul(b"foo\0"); = help: to override `-D warnings` add `#[allow(clippy::manual_c_str_literals)]` error: calling `CStr::new` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:35:5 + --> tests/ui/manual_c_str_literals.rs:38:5 | LL | CStr::from_bytes_with_nul(b"foo\0"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::new` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:36:5 + --> tests/ui/manual_c_str_literals.rs:39:5 | LL | CStr::from_bytes_with_nul(b"foo\x00"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::new` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:37:5 + --> tests/ui/manual_c_str_literals.rs:40:5 | LL | CStr::from_bytes_with_nul(b"foo\0").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::new` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:38:5 + --> tests/ui/manual_c_str_literals.rs:41:5 | LL | CStr::from_bytes_with_nul(b"foo\\0sdsd\0").unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo\\0sdsd"` error: calling `CStr::from_ptr` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:43:14 + --> tests/ui/manual_c_str_literals.rs:46:14 | LL | unsafe { CStr::from_ptr(b"foo\0".as_ptr().cast()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: calling `CStr::from_ptr` with a byte string literal - --> tests/ui/manual_c_str_literals.rs:44:14 + --> tests/ui/manual_c_str_literals.rs:47:14 | LL | unsafe { CStr::from_ptr(b"foo\0".as_ptr() as *const _) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:45:23 + --> tests/ui/manual_c_str_literals.rs:48:23 | LL | let _: *const _ = b"foo\0".as_ptr(); | ^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:46:23 + --> tests/ui/manual_c_str_literals.rs:49:23 | LL | let _: *const _ = "foo\0".as_ptr(); | ^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:49:23 + --> tests/ui/manual_c_str_literals.rs:52:23 | LL | let _: *const _ = b"foo\0".as_ptr().cast::<i8>(); | ^^^^^^^^ help: use a `c""` literal: `c"foo"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:52:13 + --> tests/ui/manual_c_str_literals.rs:55:13 | LL | let _ = "电脑\\\0".as_ptr(); | ^^^^^^^^^^ help: use a `c""` literal: `c"电脑\\"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:53:13 + --> tests/ui/manual_c_str_literals.rs:56:13 | LL | let _ = "电脑\0".as_ptr(); | ^^^^^^^^ help: use a `c""` literal: `c"电脑"` error: manually constructing a nul-terminated string - --> tests/ui/manual_c_str_literals.rs:54:13 + --> tests/ui/manual_c_str_literals.rs:57:13 | LL | let _ = "电脑\x00".as_ptr(); | ^^^^^^^^^^ help: use a `c""` literal: `c"电脑"` diff --git a/tests/ui/manual_c_str_literals.rs b/tests/ui/manual_c_str_literals.rs index 0a007786720..39b62258077 100644 --- a/tests/ui/manual_c_str_literals.rs +++ b/tests/ui/manual_c_str_literals.rs @@ -1,3 +1,6 @@ +//@revisions: edition2018 edition2021 +//@[edition2018] edition:2018 +//@[edition2021] edition:2021 #![warn(clippy::manual_c_str_literals)] #![allow(clippy::no_effect)] diff --git a/tests/ui/manual_float_methods.rs b/tests/ui/manual_float_methods.rs index ee3daa12834..66545d180ef 100644 --- a/tests/ui/manual_float_methods.rs +++ b/tests/ui/manual_float_methods.rs @@ -39,8 +39,11 @@ fn main() { if x != f64::INFINITY && x != fn_test() {} // Not -inf if x != f64::INFINITY && x != fn_test_not_inf() {} + const { + let x = 1.0f64; + if x == f64::INFINITY || x == f64::NEG_INFINITY {} + } const X: f64 = 1.0f64; - // Will be linted if `const_float_classify` is enabled if const { X == f64::INFINITY || X == f64::NEG_INFINITY } {} if const { X != f64::INFINITY && X != f64::NEG_INFINITY } {} external! { diff --git a/tests/ui/manual_float_methods.stderr b/tests/ui/manual_float_methods.stderr index 70057620a4a..676a4485ab4 100644 --- a/tests/ui/manual_float_methods.stderr +++ b/tests/ui/manual_float_methods.stderr @@ -78,5 +78,11 @@ help: or, for conciseness LL | if !x.is_infinite() {} | ~~~~~~~~~~~~~~~~ -error: aborting due to 6 previous errors +error: manually checking if a float is infinite + --> tests/ui/manual_float_methods.rs:44:12 + | +LL | if x == f64::INFINITY || x == f64::NEG_INFINITY {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()` + +error: aborting due to 7 previous errors diff --git a/tests/ui/manual_ignore_case_cmp.fixed b/tests/ui/manual_ignore_case_cmp.fixed new file mode 100644 index 00000000000..53a124f59c8 --- /dev/null +++ b/tests/ui/manual_ignore_case_cmp.fixed @@ -0,0 +1,107 @@ +#![allow(clippy::all)] +#![deny(clippy::manual_ignore_case_cmp)] + +use std::ffi::{OsStr, OsString}; + +fn main() {} + +fn variants(a: &str, b: &str) { + if a.eq_ignore_ascii_case(b) { + return; + } + if a.eq_ignore_ascii_case(b) { + return; + } + let r = a.eq_ignore_ascii_case(b); + let r = r || a.eq_ignore_ascii_case(b); + r && a.eq_ignore_ascii_case(&b.to_uppercase()); + // != + if !a.eq_ignore_ascii_case(b) { + return; + } + if !a.eq_ignore_ascii_case(b) { + return; + } + let r = !a.eq_ignore_ascii_case(b); + let r = r || !a.eq_ignore_ascii_case(b); + r && !a.eq_ignore_ascii_case(&b.to_uppercase()); +} + +fn unsupported(a: char, b: char) { + // TODO:: these are rare, and might not be worth supporting + a.to_ascii_lowercase() == char::to_ascii_lowercase(&b); + char::to_ascii_lowercase(&a) == b.to_ascii_lowercase(); + char::to_ascii_lowercase(&a) == char::to_ascii_lowercase(&b); +} + +fn char(a: char, b: char) { + a.eq_ignore_ascii_case(&b); + a.to_ascii_lowercase() == *&b.to_ascii_lowercase(); + *&a.to_ascii_lowercase() == b.to_ascii_lowercase(); + a.eq_ignore_ascii_case(&'a'); + 'a'.eq_ignore_ascii_case(&b); +} +fn u8(a: u8, b: u8) { + a.eq_ignore_ascii_case(&b); + a.eq_ignore_ascii_case(&b'a'); + b'a'.eq_ignore_ascii_case(&b); +} +fn ref_str(a: &str, b: &str) { + a.eq_ignore_ascii_case(b); + a.to_uppercase().eq_ignore_ascii_case(b); + a.eq_ignore_ascii_case("a"); + "a".eq_ignore_ascii_case(b); +} +fn ref_ref_str(a: &&str, b: &&str) { + a.eq_ignore_ascii_case(b); + a.to_uppercase().eq_ignore_ascii_case(b); + a.eq_ignore_ascii_case("a"); + "a".eq_ignore_ascii_case(b); +} +fn string(a: String, b: String) { + a.eq_ignore_ascii_case(&b); + a.eq_ignore_ascii_case("a"); + "a".eq_ignore_ascii_case(&b); + &a.to_ascii_lowercase() == &b.to_ascii_lowercase(); + &&a.to_ascii_lowercase() == &&b.to_ascii_lowercase(); + a.eq_ignore_ascii_case("a"); + "a".eq_ignore_ascii_case(&b); +} +fn ref_string(a: String, b: &String) { + a.eq_ignore_ascii_case(b); + a.eq_ignore_ascii_case("a"); + "a".eq_ignore_ascii_case(b); + + b.eq_ignore_ascii_case(&a); + b.eq_ignore_ascii_case("a"); + "a".eq_ignore_ascii_case(&a); +} +fn string_ref_str(a: String, b: &str) { + a.eq_ignore_ascii_case(b); + a.eq_ignore_ascii_case("a"); + "a".eq_ignore_ascii_case(b); + + b.eq_ignore_ascii_case(&a); + b.eq_ignore_ascii_case("a"); + "a".eq_ignore_ascii_case(&a); +} +fn ref_u8slice(a: &[u8], b: &[u8]) { + a.eq_ignore_ascii_case(b); +} +fn u8vec(a: Vec<u8>, b: Vec<u8>) { + a.eq_ignore_ascii_case(&b); +} +fn ref_u8vec(a: Vec<u8>, b: &Vec<u8>) { + a.eq_ignore_ascii_case(b); + b.eq_ignore_ascii_case(&a); +} +fn ref_osstr(a: &OsStr, b: &OsStr) { + a.eq_ignore_ascii_case(b); +} +fn osstring(a: OsString, b: OsString) { + a.eq_ignore_ascii_case(b); +} +fn ref_osstring(a: OsString, b: &OsString) { + a.eq_ignore_ascii_case(b); + b.eq_ignore_ascii_case(a); +} diff --git a/tests/ui/manual_ignore_case_cmp.rs b/tests/ui/manual_ignore_case_cmp.rs new file mode 100644 index 00000000000..2a4d84b30ac --- /dev/null +++ b/tests/ui/manual_ignore_case_cmp.rs @@ -0,0 +1,107 @@ +#![allow(clippy::all)] +#![deny(clippy::manual_ignore_case_cmp)] + +use std::ffi::{OsStr, OsString}; + +fn main() {} + +fn variants(a: &str, b: &str) { + if a.to_ascii_lowercase() == b.to_ascii_lowercase() { + return; + } + if a.to_ascii_uppercase() == b.to_ascii_uppercase() { + return; + } + let r = a.to_ascii_lowercase() == b.to_ascii_lowercase(); + let r = r || a.to_ascii_uppercase() == b.to_ascii_uppercase(); + r && a.to_ascii_lowercase() == b.to_uppercase().to_ascii_lowercase(); + // != + if a.to_ascii_lowercase() != b.to_ascii_lowercase() { + return; + } + if a.to_ascii_uppercase() != b.to_ascii_uppercase() { + return; + } + let r = a.to_ascii_lowercase() != b.to_ascii_lowercase(); + let r = r || a.to_ascii_uppercase() != b.to_ascii_uppercase(); + r && a.to_ascii_lowercase() != b.to_uppercase().to_ascii_lowercase(); +} + +fn unsupported(a: char, b: char) { + // TODO:: these are rare, and might not be worth supporting + a.to_ascii_lowercase() == char::to_ascii_lowercase(&b); + char::to_ascii_lowercase(&a) == b.to_ascii_lowercase(); + char::to_ascii_lowercase(&a) == char::to_ascii_lowercase(&b); +} + +fn char(a: char, b: char) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); + a.to_ascii_lowercase() == *&b.to_ascii_lowercase(); + *&a.to_ascii_lowercase() == b.to_ascii_lowercase(); + a.to_ascii_lowercase() == 'a'; + 'a' == b.to_ascii_lowercase(); +} +fn u8(a: u8, b: u8) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); + a.to_ascii_lowercase() == b'a'; + b'a' == b.to_ascii_lowercase(); +} +fn ref_str(a: &str, b: &str) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); + a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); + a.to_ascii_lowercase() == "a"; + "a" == b.to_ascii_lowercase(); +} +fn ref_ref_str(a: &&str, b: &&str) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); + a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); + a.to_ascii_lowercase() == "a"; + "a" == b.to_ascii_lowercase(); +} +fn string(a: String, b: String) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); + a.to_ascii_lowercase() == "a"; + "a" == b.to_ascii_lowercase(); + &a.to_ascii_lowercase() == &b.to_ascii_lowercase(); + &&a.to_ascii_lowercase() == &&b.to_ascii_lowercase(); + a.to_ascii_lowercase() == "a"; + "a" == b.to_ascii_lowercase(); +} +fn ref_string(a: String, b: &String) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); + a.to_ascii_lowercase() == "a"; + "a" == b.to_ascii_lowercase(); + + b.to_ascii_lowercase() == a.to_ascii_lowercase(); + b.to_ascii_lowercase() == "a"; + "a" == a.to_ascii_lowercase(); +} +fn string_ref_str(a: String, b: &str) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); + a.to_ascii_lowercase() == "a"; + "a" == b.to_ascii_lowercase(); + + b.to_ascii_lowercase() == a.to_ascii_lowercase(); + b.to_ascii_lowercase() == "a"; + "a" == a.to_ascii_lowercase(); +} +fn ref_u8slice(a: &[u8], b: &[u8]) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); +} +fn u8vec(a: Vec<u8>, b: Vec<u8>) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); +} +fn ref_u8vec(a: Vec<u8>, b: &Vec<u8>) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); + b.to_ascii_lowercase() == a.to_ascii_lowercase(); +} +fn ref_osstr(a: &OsStr, b: &OsStr) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); +} +fn osstring(a: OsString, b: OsString) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); +} +fn ref_osstring(a: OsString, b: &OsString) { + a.to_ascii_lowercase() == b.to_ascii_lowercase(); + b.to_ascii_lowercase() == a.to_ascii_lowercase(); +} diff --git a/tests/ui/manual_ignore_case_cmp.stderr b/tests/ui/manual_ignore_case_cmp.stderr new file mode 100644 index 00000000000..11e8b8aebb5 --- /dev/null +++ b/tests/ui/manual_ignore_case_cmp.stderr @@ -0,0 +1,546 @@ +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:9:8 + | +LL | if a.to_ascii_lowercase() == b.to_ascii_lowercase() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> tests/ui/manual_ignore_case_cmp.rs:2:9 + | +LL | #![deny(clippy::manual_ignore_case_cmp)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | if a.eq_ignore_ascii_case(b) { + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:12:8 + | +LL | if a.to_ascii_uppercase() == b.to_ascii_uppercase() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | if a.eq_ignore_ascii_case(b) { + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:15:13 + | +LL | let r = a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | let r = a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:16:18 + | +LL | let r = r || a.to_ascii_uppercase() == b.to_ascii_uppercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | let r = r || a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:17:10 + | +LL | r && a.to_ascii_lowercase() == b.to_uppercase().to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | r && a.eq_ignore_ascii_case(&b.to_uppercase()); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:19:8 + | +LL | if a.to_ascii_lowercase() != b.to_ascii_lowercase() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | if !a.eq_ignore_ascii_case(b) { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:22:8 + | +LL | if a.to_ascii_uppercase() != b.to_ascii_uppercase() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | if !a.eq_ignore_ascii_case(b) { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:25:13 + | +LL | let r = a.to_ascii_lowercase() != b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | let r = !a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:26:18 + | +LL | let r = r || a.to_ascii_uppercase() != b.to_ascii_uppercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | let r = r || !a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:27:10 + | +LL | r && a.to_ascii_lowercase() != b.to_uppercase().to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | r && !a.eq_ignore_ascii_case(&b.to_uppercase()); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:38:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:41:5 + | +LL | a.to_ascii_lowercase() == 'a'; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(&'a'); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:42:5 + | +LL | 'a' == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | 'a'.eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:45:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:46:5 + | +LL | a.to_ascii_lowercase() == b'a'; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(&b'a'); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:47:5 + | +LL | b'a' == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b'a'.eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:50:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:51:5 + | +LL | a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.to_uppercase().eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:52:5 + | +LL | a.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:53:5 + | +LL | "a" == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:56:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:57:5 + | +LL | a.to_uppercase().to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.to_uppercase().eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:58:5 + | +LL | a.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:59:5 + | +LL | "a" == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:62:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:63:5 + | +LL | a.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:64:5 + | +LL | "a" == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:67:5 + | +LL | a.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:68:5 + | +LL | "a" == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:71:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:72:5 + | +LL | a.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:73:5 + | +LL | "a" == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:75:5 + | +LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b.eq_ignore_ascii_case(&a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:76:5 + | +LL | b.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:77:5 + | +LL | "a" == a.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(&a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:80:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:81:5 + | +LL | a.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:82:5 + | +LL | "a" == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:84:5 + | +LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b.eq_ignore_ascii_case(&a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:85:5 + | +LL | b.to_ascii_lowercase() == "a"; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b.eq_ignore_ascii_case("a"); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:86:5 + | +LL | "a" == a.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | "a".eq_ignore_ascii_case(&a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:89:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:92:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(&b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:95:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:96:5 + | +LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b.eq_ignore_ascii_case(&a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:99:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:102:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:105:5 + | +LL | a.to_ascii_lowercase() == b.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | a.eq_ignore_ascii_case(b); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: manual case-insensitive ASCII comparison + --> tests/ui/manual_ignore_case_cmp.rs:106:5 + | +LL | b.to_ascii_lowercase() == a.to_ascii_lowercase(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider using `.eq_ignore_ascii_case()` instead + | +LL | b.eq_ignore_ascii_case(a); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 49 previous errors + diff --git a/tests/ui/manual_slice_size_calculation.fixed b/tests/ui/manual_slice_size_calculation.fixed index 62b372f4b8d..0603b30e346 100644 --- a/tests/ui/manual_slice_size_calculation.fixed +++ b/tests/ui/manual_slice_size_calculation.fixed @@ -10,11 +10,15 @@ use proc_macros::external; fn main() { let v_i32 = Vec::<i32>::new(); let s_i32 = v_i32.as_slice(); + let s_i32_ref = &s_i32; + let s_i32_ref_ref = &s_i32_ref; // True positives: let _ = std::mem::size_of_val(s_i32); // WARNING let _ = std::mem::size_of_val(s_i32); // WARNING let _ = std::mem::size_of_val(s_i32) * 5; // WARNING + let _ = std::mem::size_of_val(*s_i32_ref); // WARNING + let _ = std::mem::size_of_val(**s_i32_ref_ref); // WARNING let len = s_i32.len(); let size = size_of::<i32>(); diff --git a/tests/ui/manual_slice_size_calculation.rs b/tests/ui/manual_slice_size_calculation.rs index d59f5fd8b94..14093e653c0 100644 --- a/tests/ui/manual_slice_size_calculation.rs +++ b/tests/ui/manual_slice_size_calculation.rs @@ -10,11 +10,15 @@ use proc_macros::external; fn main() { let v_i32 = Vec::<i32>::new(); let s_i32 = v_i32.as_slice(); + let s_i32_ref = &s_i32; + let s_i32_ref_ref = &s_i32_ref; // True positives: let _ = s_i32.len() * size_of::<i32>(); // WARNING let _ = size_of::<i32>() * s_i32.len(); // WARNING let _ = size_of::<i32>() * s_i32.len() * 5; // WARNING + let _ = size_of::<i32>() * s_i32_ref.len(); // WARNING + let _ = size_of::<i32>() * s_i32_ref_ref.len(); // WARNING let len = s_i32.len(); let size = size_of::<i32>(); diff --git a/tests/ui/manual_slice_size_calculation.stderr b/tests/ui/manual_slice_size_calculation.stderr index 4bd8a4fdf17..0397f3a4969 100644 --- a/tests/ui/manual_slice_size_calculation.stderr +++ b/tests/ui/manual_slice_size_calculation.stderr @@ -1,5 +1,5 @@ error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:15:13 + --> tests/ui/manual_slice_size_calculation.rs:17:13 | LL | let _ = s_i32.len() * size_of::<i32>(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` @@ -8,40 +8,52 @@ LL | let _ = s_i32.len() * size_of::<i32>(); // WARNING = help: to override `-D warnings` add `#[allow(clippy::manual_slice_size_calculation)]` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:16:13 + --> tests/ui/manual_slice_size_calculation.rs:18:13 | LL | let _ = size_of::<i32>() * s_i32.len(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:17:13 + --> tests/ui/manual_slice_size_calculation.rs:19:13 | LL | let _ = size_of::<i32>() * s_i32.len() * 5; // WARNING | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation + --> tests/ui/manual_slice_size_calculation.rs:20:13 + | +LL | let _ = size_of::<i32>() * s_i32_ref.len(); // WARNING + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(*s_i32_ref)` + +error: manual slice size calculation --> tests/ui/manual_slice_size_calculation.rs:21:13 | +LL | let _ = size_of::<i32>() * s_i32_ref_ref.len(); // WARNING + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(**s_i32_ref_ref)` + +error: manual slice size calculation + --> tests/ui/manual_slice_size_calculation.rs:25:13 + | LL | let _ = len * size_of::<i32>(); // WARNING | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:22:13 + --> tests/ui/manual_slice_size_calculation.rs:26:13 | LL | let _ = s_i32.len() * size; // WARNING | ^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:23:13 + --> tests/ui/manual_slice_size_calculation.rs:27:13 | LL | let _ = len * size; // WARNING | ^^^^^^^^^^ help: try: `std::mem::size_of_val(s_i32)` error: manual slice size calculation - --> tests/ui/manual_slice_size_calculation.rs:25:13 + --> tests/ui/manual_slice_size_calculation.rs:29:13 | LL | let _ = external!(&[1u64][..]).len() * size_of::<u64>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::mem::size_of_val(external!(&[1u64][..]))` -error: aborting due to 7 previous errors +error: aborting due to 9 previous errors diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed index 78d8b3e9bce..4210dbbe82d 100644 --- a/tests/ui/mem_replace.fixed +++ b/tests/ui/mem_replace.fixed @@ -1,6 +1,5 @@ -#![allow(unused)] +#![allow(unused, clippy::needless_lifetimes)] #![warn( - clippy::all, clippy::style, clippy::mem_replace_option_with_none, clippy::mem_replace_with_default diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index 28915bf6dae..bd7ad78b2af 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -1,6 +1,5 @@ -#![allow(unused)] +#![allow(unused, clippy::needless_lifetimes)] #![warn( - clippy::all, clippy::style, clippy::mem_replace_option_with_none, clippy::mem_replace_with_default diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index 44be2c9b63d..c33f80b01b8 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -1,5 +1,5 @@ error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:14:13 + --> tests/ui/mem_replace.rs:13:13 | LL | let _ = mem::replace(&mut an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` @@ -8,13 +8,13 @@ LL | let _ = mem::replace(&mut an_option, None); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:16:13 + --> tests/ui/mem_replace.rs:15:13 | LL | let _ = mem::replace(an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:21:13 + --> tests/ui/mem_replace.rs:20:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` @@ -23,127 +23,127 @@ LL | let _ = std::mem::replace(&mut s, String::default()); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:24:13 + --> tests/ui/mem_replace.rs:23:13 | LL | let _ = std::mem::replace(s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:25:13 + --> tests/ui/mem_replace.rs:24:13 | LL | let _ = std::mem::replace(s, Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:28:13 + --> tests/ui/mem_replace.rs:27:13 | LL | let _ = std::mem::replace(&mut v, Vec::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:29:13 + --> tests/ui/mem_replace.rs:28:13 | LL | let _ = std::mem::replace(&mut v, Default::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:30:13 + --> tests/ui/mem_replace.rs:29:13 | LL | let _ = std::mem::replace(&mut v, Vec::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:31:13 + --> tests/ui/mem_replace.rs:30:13 | LL | let _ = std::mem::replace(&mut v, vec![]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:34:13 + --> tests/ui/mem_replace.rs:33:13 | LL | let _ = std::mem::replace(&mut hash_map, HashMap::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_map)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:37:13 + --> tests/ui/mem_replace.rs:36:13 | LL | let _ = std::mem::replace(&mut btree_map, BTreeMap::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_map)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:40:13 + --> tests/ui/mem_replace.rs:39:13 | LL | let _ = std::mem::replace(&mut vd, VecDeque::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut vd)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:43:13 + --> tests/ui/mem_replace.rs:42:13 | LL | let _ = std::mem::replace(&mut hash_set, HashSet::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_set)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:46:13 + --> tests/ui/mem_replace.rs:45:13 | LL | let _ = std::mem::replace(&mut btree_set, BTreeSet::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_set)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:49:13 + --> tests/ui/mem_replace.rs:48:13 | LL | let _ = std::mem::replace(&mut list, LinkedList::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut list)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:52:13 + --> tests/ui/mem_replace.rs:51:13 | LL | let _ = std::mem::replace(&mut binary_heap, BinaryHeap::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut binary_heap)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:55:13 + --> tests/ui/mem_replace.rs:54:13 | LL | let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut tuple)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:58:13 + --> tests/ui/mem_replace.rs:57:13 | LL | let _ = std::mem::replace(&mut refstr, ""); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut refstr)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:61:13 + --> tests/ui/mem_replace.rs:60:13 | LL | let _ = std::mem::replace(&mut slice, &[]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut slice)` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:97:13 + --> tests/ui/mem_replace.rs:96:13 | LL | let _ = std::mem::replace(&mut s, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:127:13 + --> tests/ui/mem_replace.rs:126:13 | LL | let _ = std::mem::replace(&mut f.0, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:128:13 + --> tests/ui/mem_replace.rs:127:13 | LL | let _ = std::mem::replace(&mut *f, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()` error: replacing an `Option` with `None` - --> tests/ui/mem_replace.rs:129:13 + --> tests/ui/mem_replace.rs:128:13 | LL | let _ = std::mem::replace(&mut b.opt, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `b.opt.take()` error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take` - --> tests/ui/mem_replace.rs:131:13 + --> tests/ui/mem_replace.rs:130:13 | LL | let _ = std::mem::replace(&mut b.val, String::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut b.val)` diff --git a/tests/ui/mem_replace_no_std.fixed b/tests/ui/mem_replace_no_std.fixed index c970f2ba281..60f523c8ef1 100644 --- a/tests/ui/mem_replace_no_std.fixed +++ b/tests/ui/mem_replace_no_std.fixed @@ -1,6 +1,5 @@ -#![allow(unused)] +#![allow(unused, clippy::needless_lifetimes)] #![warn( - clippy::all, clippy::style, clippy::mem_replace_option_with_none, clippy::mem_replace_with_default diff --git a/tests/ui/mem_replace_no_std.rs b/tests/ui/mem_replace_no_std.rs index 673d5c7b4f4..d1cb9a5817b 100644 --- a/tests/ui/mem_replace_no_std.rs +++ b/tests/ui/mem_replace_no_std.rs @@ -1,6 +1,5 @@ -#![allow(unused)] +#![allow(unused, clippy::needless_lifetimes)] #![warn( - clippy::all, clippy::style, clippy::mem_replace_option_with_none, clippy::mem_replace_with_default diff --git a/tests/ui/mem_replace_no_std.stderr b/tests/ui/mem_replace_no_std.stderr index eea538da427..6ba6d2162a7 100644 --- a/tests/ui/mem_replace_no_std.stderr +++ b/tests/ui/mem_replace_no_std.stderr @@ -1,5 +1,5 @@ error: replacing an `Option` with `None` - --> tests/ui/mem_replace_no_std.rs:24:13 + --> tests/ui/mem_replace_no_std.rs:23:13 | LL | let _ = mem::replace(&mut an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` @@ -8,13 +8,13 @@ LL | let _ = mem::replace(&mut an_option, None); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_option_with_none)]` error: replacing an `Option` with `None` - --> tests/ui/mem_replace_no_std.rs:26:13 + --> tests/ui/mem_replace_no_std.rs:25:13 | LL | let _ = mem::replace(an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` error: replacing a value of type `T` with `T::default()` is better expressed using `core::mem::take` - --> tests/ui/mem_replace_no_std.rs:31:13 + --> tests/ui/mem_replace_no_std.rs:30:13 | LL | let _ = mem::replace(&mut refstr, ""); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut refstr)` @@ -23,25 +23,25 @@ LL | let _ = mem::replace(&mut refstr, ""); = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]` error: replacing a value of type `T` with `T::default()` is better expressed using `core::mem::take` - --> tests/ui/mem_replace_no_std.rs:34:13 + --> tests/ui/mem_replace_no_std.rs:33:13 | LL | let _ = mem::replace(&mut slice, &[]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut slice)` error: replacing an `Option` with `None` - --> tests/ui/mem_replace_no_std.rs:77:13 + --> tests/ui/mem_replace_no_std.rs:76:13 | LL | let _ = mem::replace(&mut f.0, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `f.0.take()` error: replacing an `Option` with `None` - --> tests/ui/mem_replace_no_std.rs:78:13 + --> tests/ui/mem_replace_no_std.rs:77:13 | LL | let _ = mem::replace(&mut *f, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `(*f).take()` error: replacing an `Option` with `None` - --> tests/ui/mem_replace_no_std.rs:79:13 + --> tests/ui/mem_replace_no_std.rs:78:13 | LL | let _ = mem::replace(&mut b.opt, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `b.opt.take()` diff --git a/tests/ui/mismatching_type_param_order.rs b/tests/ui/mismatching_type_param_order.rs index af2882e41fb..a4560f9e9a9 100644 --- a/tests/ui/mismatching_type_param_order.rs +++ b/tests/ui/mismatching_type_param_order.rs @@ -1,5 +1,5 @@ #![warn(clippy::mismatching_type_param_order)] -#![allow(clippy::disallowed_names)] +#![allow(clippy::disallowed_names, clippy::needless_lifetimes)] fn main() { struct Foo<A, B> { diff --git a/tests/ui/module_name_repetitions.rs b/tests/ui/module_name_repetitions.rs index b75ef87ab36..71d8ac7a1f0 100644 --- a/tests/ui/module_name_repetitions.rs +++ b/tests/ui/module_name_repetitions.rs @@ -3,7 +3,7 @@ #![warn(clippy::module_name_repetitions)] #![allow(dead_code)] -mod foo { +pub mod foo { pub fn foo() {} pub fn foo_bar() {} //~^ ERROR: item name starts with its containing module's name @@ -20,6 +20,22 @@ mod foo { // Should not warn pub struct Foobar; + // #8524 - shouldn't warn when item is declared in a private module... + mod error { + pub struct Error; + pub struct FooError; + } + pub use error::Error; + // ... but should still warn when the item is reexported to create a *public* path with repetition. + pub use error::FooError; + //~^ ERROR: item name starts with its containing module's name + + // FIXME: This should also warn because it creates the public path `foo::FooIter`. + mod iter { + pub struct FooIter; + } + pub use iter::*; + // #12544 - shouldn't warn if item name consists only of an allowed prefix and a module name. pub fn to_foo() {} pub fn into_foo() {} diff --git a/tests/ui/module_name_repetitions.stderr b/tests/ui/module_name_repetitions.stderr index bffb08f6f87..8fd8b394875 100644 --- a/tests/ui/module_name_repetitions.stderr +++ b/tests/ui/module_name_repetitions.stderr @@ -31,5 +31,11 @@ error: item name starts with its containing module's name LL | pub struct Foo7Bar; | ^^^^^^^ -error: aborting due to 5 previous errors +error: item name starts with its containing module's name + --> tests/ui/module_name_repetitions.rs:30:20 + | +LL | pub use error::FooError; + | ^^^^^^^^ + +error: aborting due to 6 previous errors diff --git a/tests/ui/mut_key.stderr b/tests/ui/mut_key.stderr index 5ad9aad2d0a..8698ed4fd67 100644 --- a/tests/ui/mut_key.stderr +++ b/tests/ui/mut_key.stderr @@ -4,6 +4,9 @@ error: mutable key type LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> { | ^^^^^^^^^^^^^^^^^^^^^^^^ | + = note: ... because it contains `Key`, which has interior mutability + = note: ... because it contains `AtomicUsize`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability = note: `-D clippy::mutable-key-type` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::mutable_key_type)]` @@ -12,84 +15,141 @@ error: mutable key type | LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> { | ^^^^^^^^^^^^ + | + = note: ... because it contains `Key`, which has interior mutability + = note: ... because it contains `AtomicUsize`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:35:5 | LL | let _other: HashMap<Key, bool> = HashMap::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `Key`, which has interior mutability + = note: ... because it contains `AtomicUsize`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:63:22 | LL | fn tuples_bad<U>(_m: &mut HashMap<(Key, U), bool>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `(Key, U)`, which has interior mutability + = note: ... because it contains `Key`, which has interior mutability + = note: ... because it contains `AtomicUsize`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:76:5 | LL | let _map = HashMap::<Cell<usize>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:78:5 | LL | let _map = HashMap::<&mut Cell<usize>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `&mut Cell<usize>`, which has interior mutability + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:81:5 | LL | let _map = HashMap::<Vec<Cell<usize>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `Vec<Cell<usize>>`, which has interior mutability + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:83:5 | LL | let _map = HashMap::<BTreeMap<Cell<usize>, ()>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `BTreeMap<Cell<usize>, ()>`, which has interior mutability + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:85:5 | LL | let _map = HashMap::<BTreeMap<(), Cell<usize>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `BTreeMap<(), Cell<usize>>`, which has interior mutability + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:87:5 | LL | let _map = HashMap::<BTreeSet<Cell<usize>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `BTreeSet<Cell<usize>>`, which has interior mutability + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:89:5 | LL | let _map = HashMap::<Option<Cell<usize>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `Option<Cell<usize>>`, which has interior mutability + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:91:5 | LL | let _map = HashMap::<Option<Vec<Cell<usize>>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `Option<Vec<Cell<usize>>>`, which has interior mutability + = note: ... because it contains `Vec<Cell<usize>>`, which has interior mutability + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:94:5 | LL | let _map = HashMap::<Box<Cell<usize>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `Box<Cell<usize>>`, which has interior mutability + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:96:5 | LL | let _map = HashMap::<Rc<Cell<usize>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `Rc<Cell<usize>>`, which has interior mutability + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: mutable key type --> tests/ui/mut_key.rs:98:5 | LL | let _map = HashMap::<Arc<Cell<usize>>, usize>::new(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ... because it contains `Arc<Cell<usize>>`, which has interior mutability + = note: ... because it contains `Cell<usize>`, which has interior mutability + = note: ... because it contains `UnsafeCell<usize>`, which has interior mutability error: aborting due to 15 previous errors diff --git a/tests/ui/mut_mutex_lock.fixed b/tests/ui/mut_mutex_lock.fixed index bbedbb2bed2..29c5a27cb62 100644 --- a/tests/ui/mut_mutex_lock.fixed +++ b/tests/ui/mut_mutex_lock.fixed @@ -9,6 +9,11 @@ fn mut_mutex_lock() { let mut value = value_mutex.get_mut().unwrap(); *value += 1; + + let mut value_mutex = Mutex::new(42_u8); + let mut_ref_mut_ref_mutex = &mut &mut value_mutex; + let mut value = mut_ref_mut_ref_mutex.get_mut().unwrap(); + *value += 1; } fn no_owned_mutex_lock() { @@ -24,4 +29,11 @@ fn issue9415() { *guard += 1; } +fn mut_ref_ref_mutex_lock() { + let mutex = Mutex::new(42_u8); + let mut_ref_ref_mutex = &mut &mutex; + let mut guard = mut_ref_ref_mutex.lock().unwrap(); + *guard += 1; +} + fn main() {} diff --git a/tests/ui/mut_mutex_lock.rs b/tests/ui/mut_mutex_lock.rs index 74116100e82..fcdb3ff97db 100644 --- a/tests/ui/mut_mutex_lock.rs +++ b/tests/ui/mut_mutex_lock.rs @@ -9,6 +9,11 @@ fn mut_mutex_lock() { let mut value = value_mutex.lock().unwrap(); *value += 1; + + let mut value_mutex = Mutex::new(42_u8); + let mut_ref_mut_ref_mutex = &mut &mut value_mutex; + let mut value = mut_ref_mut_ref_mutex.lock().unwrap(); + *value += 1; } fn no_owned_mutex_lock() { @@ -24,4 +29,11 @@ fn issue9415() { *guard += 1; } +fn mut_ref_ref_mutex_lock() { + let mutex = Mutex::new(42_u8); + let mut_ref_ref_mutex = &mut &mutex; + let mut guard = mut_ref_ref_mutex.lock().unwrap(); + *guard += 1; +} + fn main() {} diff --git a/tests/ui/mut_mutex_lock.stderr b/tests/ui/mut_mutex_lock.stderr index a3d4905c04c..92601c4c612 100644 --- a/tests/ui/mut_mutex_lock.stderr +++ b/tests/ui/mut_mutex_lock.stderr @@ -7,5 +7,11 @@ LL | let mut value = value_mutex.lock().unwrap(); = note: `-D clippy::mut-mutex-lock` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::mut_mutex_lock)]` -error: aborting due to 1 previous error +error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference + --> tests/ui/mut_mutex_lock.rs:15:43 + | +LL | let mut value = mut_ref_mut_ref_mutex.lock().unwrap(); + | ^^^^ help: change this to: `get_mut` + +error: aborting due to 2 previous errors diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed index cabdc22bda8..2763830e09c 100644 --- a/tests/ui/needless_borrow.fixed +++ b/tests/ui/needless_borrow.fixed @@ -4,7 +4,8 @@ clippy::uninlined_format_args, clippy::unnecessary_mut_passed, clippy::unnecessary_to_owned, - clippy::unnecessary_literal_unwrap + clippy::unnecessary_literal_unwrap, + clippy::needless_lifetimes )] #![warn(clippy::needless_borrow)] diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs index 50062589645..b46f82b18c6 100644 --- a/tests/ui/needless_borrow.rs +++ b/tests/ui/needless_borrow.rs @@ -4,7 +4,8 @@ clippy::uninlined_format_args, clippy::unnecessary_mut_passed, clippy::unnecessary_to_owned, - clippy::unnecessary_literal_unwrap + clippy::unnecessary_literal_unwrap, + clippy::needless_lifetimes )] #![warn(clippy::needless_borrow)] diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr index bf0e265c250..4b2b17e7e57 100644 --- a/tests/ui/needless_borrow.stderr +++ b/tests/ui/needless_borrow.stderr @@ -1,5 +1,5 @@ error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:15:15 + --> tests/ui/needless_borrow.rs:16:15 | LL | let _ = x(&&a); // warn | ^^^ help: change this to: `&a` @@ -8,163 +8,163 @@ LL | let _ = x(&&a); // warn = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:19:13 + --> tests/ui/needless_borrow.rs:20:13 | LL | mut_ref(&mut &mut b); // warn | ^^^^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:31:13 + --> tests/ui/needless_borrow.rs:32:13 | LL | &&a | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:33:15 + --> tests/ui/needless_borrow.rs:34:15 | LL | 46 => &&a, | ^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:39:27 + --> tests/ui/needless_borrow.rs:40:27 | LL | break &ref_a; | ^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:46:15 + --> tests/ui/needless_borrow.rs:47:15 | LL | let _ = x(&&&a); | ^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:47:15 + --> tests/ui/needless_borrow.rs:48:15 | LL | let _ = x(&mut &&a); | ^^^^^^^^ help: change this to: `&a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:48:15 + --> tests/ui/needless_borrow.rs:49:15 | LL | let _ = x(&&&mut b); | ^^^^^^^^ help: change this to: `&mut b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:49:15 + --> tests/ui/needless_borrow.rs:50:15 | LL | let _ = x(&&ref_a); | ^^^^^^^ help: change this to: `ref_a` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:52:11 + --> tests/ui/needless_borrow.rs:53:11 | LL | x(&b); | ^^ help: change this to: `b` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:59:13 + --> tests/ui/needless_borrow.rs:60:13 | LL | mut_ref(&mut x); | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:60:13 + --> tests/ui/needless_borrow.rs:61:13 | LL | mut_ref(&mut &mut x); | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:61:23 + --> tests/ui/needless_borrow.rs:62:23 | LL | let y: &mut i32 = &mut x; | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:62:23 + --> tests/ui/needless_borrow.rs:63:23 | LL | let y: &mut i32 = &mut &mut x; | ^^^^^^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:71:14 + --> tests/ui/needless_borrow.rs:72:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:77:14 + --> tests/ui/needless_borrow.rs:78:14 | LL | 0 => &mut x, | ^^^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:89:13 + --> tests/ui/needless_borrow.rs:90:13 | LL | let _ = (&x).0; | ^^^^ help: change this to: `x` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:91:22 + --> tests/ui/needless_borrow.rs:92:22 | LL | let _ = unsafe { (&*x).0 }; | ^^^^^ help: change this to: `(*x)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:101:5 + --> tests/ui/needless_borrow.rs:102:5 | LL | (&&()).foo(); | ^^^^^^ help: change this to: `(&())` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:110:5 + --> tests/ui/needless_borrow.rs:111:5 | LL | (&&5).foo(); | ^^^^^ help: change this to: `(&5)` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:136:23 + --> tests/ui/needless_borrow.rs:137:23 | LL | let x: (&str,) = (&"",); | ^^^ help: change this to: `""` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:178:13 + --> tests/ui/needless_borrow.rs:179:13 | LL | (&self.f)() | ^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:187:13 + --> tests/ui/needless_borrow.rs:188:13 | LL | (&mut self.f)() | ^^^^^^^^^^^^^ help: change this to: `(self.f)` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:224:22 + --> tests/ui/needless_borrow.rs:225:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:231:22 + --> tests/ui/needless_borrow.rs:232:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:235:22 + --> tests/ui/needless_borrow.rs:236:22 | LL | let _ = &mut (&mut x.u).x; | ^^^^^^^^^^ help: change this to: `x.u` error: this expression borrows a value the compiler would automatically borrow - --> tests/ui/needless_borrow.rs:236:22 + --> tests/ui/needless_borrow.rs:237:22 | LL | let _ = &mut (&mut { x.u }).x; | ^^^^^^^^^^^^^^ help: change this to: `{ x.u }` error: this expression creates a reference which is immediately dereferenced by the compiler - --> tests/ui/needless_borrow.rs:257:23 + --> tests/ui/needless_borrow.rs:258:23 | LL | option.unwrap_or((&x.0,)); | ^^^^ help: change this to: `x.0` diff --git a/tests/ui/needless_lifetimes.fixed b/tests/ui/needless_lifetimes.fixed index d1787b35abd..cfa4cf9da3c 100644 --- a/tests/ui/needless_lifetimes.fixed +++ b/tests/ui/needless_lifetimes.fixed @@ -329,7 +329,7 @@ mod issue2944 { bar: &'a Bar, } - impl<'a> Foo for Baz<'a> {} + impl Foo for Baz<'_> {} impl Bar { fn baz(&self) -> impl Foo + '_ { Baz { bar: self } @@ -384,7 +384,7 @@ mod nested_elision_sites { f() } // lint - fn where_clause_elidadable<T>(i: &i32, f: T) -> &i32 + fn where_clause_elidable<T>(i: &i32, f: T) -> &i32 where T: Fn(&i32) -> &i32, { @@ -543,4 +543,23 @@ mod issue5787 { } } +// https://github.com/rust-lang/rust-clippy/pull/13286#issuecomment-2374245772 +mod rayon { + trait ParallelIterator { + type Item; + } + + struct Copied<I: ParallelIterator> { + base: I, + } + + impl<'a, T, I> ParallelIterator for Copied<I> + where + I: ParallelIterator<Item = &'a T>, + T: 'a + Copy + Send + Sync, + { + type Item = T; + } +} + fn main() {} diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index 03d6f201358..5e9d5116426 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -384,7 +384,7 @@ mod nested_elision_sites { f() } // lint - fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32 + fn where_clause_elidable<'a, T>(i: &'a i32, f: T) -> &'a i32 where T: Fn(&i32) -> &i32, { @@ -543,4 +543,23 @@ mod issue5787 { } } +// https://github.com/rust-lang/rust-clippy/pull/13286#issuecomment-2374245772 +mod rayon { + trait ParallelIterator { + type Item; + } + + struct Copied<I: ParallelIterator> { + base: I, + } + + impl<'a, T, I> ParallelIterator for Copied<I> + where + I: ParallelIterator<Item = &'a T>, + T: 'a + Copy + Send + Sync, + { + type Item = T; + } +} + fn main() {} diff --git a/tests/ui/needless_lifetimes.stderr b/tests/ui/needless_lifetimes.stderr index 50f845e2d92..e56c914cc86 100644 --- a/tests/ui/needless_lifetimes.stderr +++ b/tests/ui/needless_lifetimes.stderr @@ -336,6 +336,18 @@ LL + fn needless_lt(_x: &u8) {} | error: the following explicit lifetimes could be elided: 'a + --> tests/ui/needless_lifetimes.rs:332:10 + | +LL | impl<'a> Foo for Baz<'a> {} + | ^^ ^^ + | +help: elide the lifetimes + | +LL - impl<'a> Foo for Baz<'a> {} +LL + impl Foo for Baz<'_> {} + | + +error: the following explicit lifetimes could be elided: 'a --> tests/ui/needless_lifetimes.rs:334:16 | LL | fn baz<'a>(&'a self) -> impl Foo + 'a { @@ -372,15 +384,15 @@ LL + fn generics_elidable<T: Fn(&i32) -> &i32>(i: &i32, f: T) -> &i32 { | error: the following explicit lifetimes could be elided: 'a - --> tests/ui/needless_lifetimes.rs:387:32 + --> tests/ui/needless_lifetimes.rs:387:30 | -LL | fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32 - | ^^ ^^ ^^ +LL | fn where_clause_elidable<'a, T>(i: &'a i32, f: T) -> &'a i32 + | ^^ ^^ ^^ | help: elide the lifetimes | -LL - fn where_clause_elidadable<'a, T>(i: &'a i32, f: T) -> &'a i32 -LL + fn where_clause_elidadable<T>(i: &i32, f: T) -> &i32 +LL - fn where_clause_elidable<'a, T>(i: &'a i32, f: T) -> &'a i32 +LL + fn where_clause_elidable<T>(i: &i32, f: T) -> &i32 | error: the following explicit lifetimes could be elided: 'a @@ -564,5 +576,5 @@ LL - fn one_input<'a>(x: &'a u8) -> &'a u8 { LL + fn one_input(x: &u8) -> &u8 { | -error: aborting due to 47 previous errors +error: aborting due to 48 previous errors diff --git a/tests/ui/needless_pass_by_value.rs b/tests/ui/needless_pass_by_value.rs index 9408b8c948f..a8d9db95dcc 100644 --- a/tests/ui/needless_pass_by_value.rs +++ b/tests/ui/needless_pass_by_value.rs @@ -5,7 +5,8 @@ clippy::redundant_clone, clippy::redundant_pattern_matching, clippy::single_match, - clippy::uninlined_format_args + clippy::uninlined_format_args, + clippy::needless_lifetimes )] //@no-rustfix use std::borrow::Borrow; diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 46ef8f3e8da..2587d3f8c52 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -1,5 +1,5 @@ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:18:23 + --> tests/ui/needless_pass_by_value.rs:19:23 | LL | fn foo<T: Default>(v: Vec<T>, w: Vec<T>, mut x: Vec<T>, y: Vec<T>) -> Vec<T> { | ^^^^^^ help: consider changing the type to: `&[T]` @@ -8,55 +8,55 @@ LL | fn foo<T: Default>(v: Vec<T>, w: Vec<T>, mut x: Vec<T>, y: Vec<T>) -> Vec<T = help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_value)]` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:34:11 + --> tests/ui/needless_pass_by_value.rs:35:11 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:34:22 + --> tests/ui/needless_pass_by_value.rs:35:22 | LL | fn bar(x: String, y: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:42:71 + --> tests/ui/needless_pass_by_value.rs:43:71 | LL | fn test_borrow_trait<T: Borrow<str>, U: AsRef<str>, V>(t: T, u: U, v: V) { | ^ help: consider taking a reference instead: `&V` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:55:18 + --> tests/ui/needless_pass_by_value.rs:56:18 | LL | fn test_match(x: Option<Option<String>>, y: Option<Option<String>>) { | ^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Option<Option<String>>` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:69:24 + --> tests/ui/needless_pass_by_value.rs:70:24 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:69:36 + --> tests/ui/needless_pass_by_value.rs:70:36 | LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:87:49 + --> tests/ui/needless_pass_by_value.rs:88:49 | LL | fn test_blanket_ref<T: Foo, S: Serialize>(vals: T, serializable: S) {} | ^ help: consider taking a reference instead: `&T` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:90:18 + --> tests/ui/needless_pass_by_value.rs:91:18 | LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) { | ^^^^^^ help: consider taking a reference instead: `&String` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:90:29 + --> tests/ui/needless_pass_by_value.rs:91:29 | LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) { | ^^^^^^ @@ -71,13 +71,13 @@ LL | let _ = t.to_string(); | ~~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:90:40 + --> tests/ui/needless_pass_by_value.rs:91:40 | LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) { | ^^^^^^^^ help: consider taking a reference instead: `&Vec<i32>` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:90:53 + --> tests/ui/needless_pass_by_value.rs:91:53 | LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) { | ^^^^^^^^ @@ -92,85 +92,85 @@ LL | let _ = v.to_owned(); | ~~~~~~~~~~~~ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:107:12 + --> tests/ui/needless_pass_by_value.rs:108:12 | LL | s: String, | ^^^^^^ help: consider changing the type to: `&str` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:109:12 + --> tests/ui/needless_pass_by_value.rs:110:12 | LL | t: String, | ^^^^^^ help: consider taking a reference instead: `&String` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:119:23 + --> tests/ui/needless_pass_by_value.rs:120:23 | LL | fn baz(&self, uu: U, ss: Self) {} | ^ help: consider taking a reference instead: `&U` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:119:30 + --> tests/ui/needless_pass_by_value.rs:120:30 | LL | fn baz(&self, uu: U, ss: Self) {} | ^^^^ help: consider taking a reference instead: `&Self` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:143:24 + --> tests/ui/needless_pass_by_value.rs:144:24 | LL | fn bar_copy(x: u32, y: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:141:1 + --> tests/ui/needless_pass_by_value.rs:142:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:150:29 + --> tests/ui/needless_pass_by_value.rs:151:29 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:141:1 + --> tests/ui/needless_pass_by_value.rs:142:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:150:45 + --> tests/ui/needless_pass_by_value.rs:151:45 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:141:1 + --> tests/ui/needless_pass_by_value.rs:142:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:150:61 + --> tests/ui/needless_pass_by_value.rs:151:61 | LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) { | ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper` | help: or consider marking this type as `Copy` - --> tests/ui/needless_pass_by_value.rs:141:1 + --> tests/ui/needless_pass_by_value.rs:142:1 | LL | struct CopyWrapper(u32); | ^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:165:40 + --> tests/ui/needless_pass_by_value.rs:166:40 | LL | fn some_fun<'b, S: Bar<'b, ()>>(items: S) {} | ^ help: consider taking a reference instead: `&S` error: this argument is passed by value, but not consumed in the function body - --> tests/ui/needless_pass_by_value.rs:171:20 + --> tests/ui/needless_pass_by_value.rs:172:20 | LL | fn more_fun(items: impl Club<'static, i32>) {} | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>` diff --git a/tests/ui/needless_raw_string.fixed b/tests/ui/needless_raw_string.fixed index 1a9c601c462..ab061467488 100644 --- a/tests/ui/needless_raw_string.fixed +++ b/tests/ui/needless_raw_string.fixed @@ -22,3 +22,12 @@ fn main() { b"no hashes"; c"no hashes"; } + +fn issue_13503() { + println!("SELECT * FROM posts"); + println!("SELECT * FROM posts"); + println!(r##"SELECT * FROM "posts""##); + + // Test arguments as well + println!("{}", "foobar".len()); +} diff --git a/tests/ui/needless_raw_string.rs b/tests/ui/needless_raw_string.rs index 1126ea5aa30..5be8bdeb4ad 100644 --- a/tests/ui/needless_raw_string.rs +++ b/tests/ui/needless_raw_string.rs @@ -22,3 +22,12 @@ fn main() { br"no hashes"; cr"no hashes"; } + +fn issue_13503() { + println!(r"SELECT * FROM posts"); + println!(r#"SELECT * FROM posts"#); + println!(r##"SELECT * FROM "posts""##); + + // Test arguments as well + println!("{}", r"foobar".len()); +} diff --git a/tests/ui/needless_raw_string.stderr b/tests/ui/needless_raw_string.stderr index 7d3451a03c7..5169f085573 100644 --- a/tests/ui/needless_raw_string.stderr +++ b/tests/ui/needless_raw_string.stderr @@ -91,5 +91,41 @@ LL - cr"no hashes"; LL + c"no hashes"; | -error: aborting due to 7 previous errors +error: unnecessary raw string literal + --> tests/ui/needless_raw_string.rs:27:14 + | +LL | println!(r"SELECT * FROM posts"); + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: use a plain string literal instead + | +LL - println!(r"SELECT * FROM posts"); +LL + println!("SELECT * FROM posts"); + | + +error: unnecessary raw string literal + --> tests/ui/needless_raw_string.rs:28:14 + | +LL | println!(r#"SELECT * FROM posts"#); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: use a plain string literal instead + | +LL - println!(r#"SELECT * FROM posts"#); +LL + println!("SELECT * FROM posts"); + | + +error: unnecessary raw string literal + --> tests/ui/needless_raw_string.rs:32:20 + | +LL | println!("{}", r"foobar".len()); + | ^^^^^^^^^ + | +help: use a plain string literal instead + | +LL - println!("{}", r"foobar".len()); +LL + println!("{}", "foobar".len()); + | + +error: aborting due to 10 previous errors diff --git a/tests/ui/needless_raw_string_hashes.fixed b/tests/ui/needless_raw_string_hashes.fixed index b2ad657d6b2..4c113709107 100644 --- a/tests/ui/needless_raw_string_hashes.fixed +++ b/tests/ui/needless_raw_string_hashes.fixed @@ -24,3 +24,13 @@ fn main() { r"rust"; r"hello world"; } + +fn issue_13503() { + println!(r"SELECT * FROM posts"); + println!(r"SELECT * FROM posts"); + println!(r#"SELECT * FROM "posts""#); + println!(r#"SELECT * FROM "posts""#); + + // Test arguments as well + println!("{}", r"foobar".len()); +} diff --git a/tests/ui/needless_raw_string_hashes.rs b/tests/ui/needless_raw_string_hashes.rs index 54d8ed76d47..7b6b4e784ee 100644 --- a/tests/ui/needless_raw_string_hashes.rs +++ b/tests/ui/needless_raw_string_hashes.rs @@ -24,3 +24,13 @@ fn main() { r###"rust"###; r#"hello world"#; } + +fn issue_13503() { + println!(r"SELECT * FROM posts"); + println!(r#"SELECT * FROM posts"#); + println!(r##"SELECT * FROM "posts""##); + println!(r##"SELECT * FROM "posts""##); + + // Test arguments as well + println!("{}", r"foobar".len()); +} diff --git a/tests/ui/needless_raw_string_hashes.stderr b/tests/ui/needless_raw_string_hashes.stderr index 96864f612c0..a213ba3e743 100644 --- a/tests/ui/needless_raw_string_hashes.stderr +++ b/tests/ui/needless_raw_string_hashes.stderr @@ -187,5 +187,41 @@ LL - r#"hello world"#; LL + r"hello world"; | -error: aborting due to 15 previous errors +error: unnecessary hashes around raw string literal + --> tests/ui/needless_raw_string_hashes.rs:30:14 + | +LL | println!(r#"SELECT * FROM posts"#); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove all the hashes around the string literal + | +LL - println!(r#"SELECT * FROM posts"#); +LL + println!(r"SELECT * FROM posts"); + | + +error: unnecessary hashes around raw string literal + --> tests/ui/needless_raw_string_hashes.rs:31:14 + | +LL | println!(r##"SELECT * FROM "posts""##); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove one hash from both sides of the string literal + | +LL - println!(r##"SELECT * FROM "posts""##); +LL + println!(r#"SELECT * FROM "posts""#); + | + +error: unnecessary hashes around raw string literal + --> tests/ui/needless_raw_string_hashes.rs:32:14 + | +LL | println!(r##"SELECT * FROM "posts""##); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove one hash from both sides of the string literal + | +LL - println!(r##"SELECT * FROM "posts""##); +LL + println!(r#"SELECT * FROM "posts""#); + | + +error: aborting due to 18 previous errors diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed index ca422e605d6..aa2a274525b 100644 --- a/tests/ui/needless_return.fixed +++ b/tests/ui/needless_return.fixed @@ -1,3 +1,4 @@ +//@aux-build:proc_macros.rs #![feature(yeet_expr)] #![allow(unused)] #![allow( @@ -9,6 +10,9 @@ )] #![warn(clippy::needless_return)] +extern crate proc_macros; +use proc_macros::with_span; + use std::cell::RefCell; macro_rules! the_answer { @@ -359,6 +363,10 @@ fn issue12907() -> String { "".split("").next().unwrap().to_string() } +fn issue13458() { + with_span!(span return); +} + fn main() {} fn a(x: Option<u8>) -> Option<u8> { diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index aad6e13136f..bf67cfd3698 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -1,3 +1,4 @@ +//@aux-build:proc_macros.rs #![feature(yeet_expr)] #![allow(unused)] #![allow( @@ -9,6 +10,9 @@ )] #![warn(clippy::needless_return)] +extern crate proc_macros; +use proc_macros::with_span; + use std::cell::RefCell; macro_rules! the_answer { @@ -369,6 +373,10 @@ fn issue12907() -> String { return "".split("").next().unwrap().to_string(); } +fn issue13458() { + with_span!(span return); +} + fn main() {} fn a(x: Option<u8>) -> Option<u8> { diff --git a/tests/ui/needless_return.stderr b/tests/ui/needless_return.stderr index da0fa220d8c..d3c2a6badc0 100644 --- a/tests/ui/needless_return.stderr +++ b/tests/ui/needless_return.stderr @@ -1,5 +1,5 @@ error: unneeded `return` statement - --> tests/ui/needless_return.rs:25:5 + --> tests/ui/needless_return.rs:29:5 | LL | return true; | ^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:29:5 + --> tests/ui/needless_return.rs:33:5 | LL | return true; | ^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:34:5 + --> tests/ui/needless_return.rs:38:5 | LL | return true;;; | ^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:39:5 + --> tests/ui/needless_return.rs:43:5 | LL | return true;; ; ; | ^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:44:9 + --> tests/ui/needless_return.rs:48:9 | LL | return true; | ^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:46:9 + --> tests/ui/needless_return.rs:50:9 | LL | return false; | ^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + false | error: unneeded `return` statement - --> tests/ui/needless_return.rs:52:17 + --> tests/ui/needless_return.rs:56:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -84,7 +84,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:54:13 + --> tests/ui/needless_return.rs:58:13 | LL | return true; | ^^^^^^^^^^^ @@ -96,7 +96,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:61:9 + --> tests/ui/needless_return.rs:65:9 | LL | return true; | ^^^^^^^^^^^ @@ -108,7 +108,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:63:16 + --> tests/ui/needless_return.rs:67:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -119,7 +119,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:67:5 + --> tests/ui/needless_return.rs:71:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -131,7 +131,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:70:21 + --> tests/ui/needless_return.rs:74:21 | LL | fn test_void_fun() { | _____________________^ @@ -146,7 +146,7 @@ LL + fn test_void_fun() { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:75:11 + --> tests/ui/needless_return.rs:79:11 | LL | if b { | ___________^ @@ -161,7 +161,7 @@ LL + if b { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:77:13 + --> tests/ui/needless_return.rs:81:13 | LL | } else { | _____________^ @@ -176,7 +176,7 @@ LL + } else { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:85:14 + --> tests/ui/needless_return.rs:89:14 | LL | _ => return, | ^^^^^^ @@ -187,7 +187,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:93:24 + --> tests/ui/needless_return.rs:97:24 | LL | let _ = 42; | ________________________^ @@ -202,7 +202,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:96:14 + --> tests/ui/needless_return.rs:100:14 | LL | _ => return, | ^^^^^^ @@ -213,7 +213,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:109:9 + --> tests/ui/needless_return.rs:113:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -225,7 +225,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:111:9 + --> tests/ui/needless_return.rs:115:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -237,7 +237,7 @@ LL + String::new() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:133:32 + --> tests/ui/needless_return.rs:137:32 | LL | bar.unwrap_or_else(|_| return) | ^^^^^^ @@ -248,7 +248,7 @@ LL | bar.unwrap_or_else(|_| {}) | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:137:21 + --> tests/ui/needless_return.rs:141:21 | LL | let _ = || { | _____________________^ @@ -263,7 +263,7 @@ LL + let _ = || { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:140:20 + --> tests/ui/needless_return.rs:144:20 | LL | let _ = || return; | ^^^^^^ @@ -274,7 +274,7 @@ LL | let _ = || {}; | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:146:32 + --> tests/ui/needless_return.rs:150:32 | LL | res.unwrap_or_else(|_| return Foo) | ^^^^^^^^^^ @@ -285,7 +285,7 @@ LL | res.unwrap_or_else(|_| Foo) | ~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:155:5 + --> tests/ui/needless_return.rs:159:5 | LL | return true; | ^^^^^^^^^^^ @@ -297,7 +297,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:159:5 + --> tests/ui/needless_return.rs:163:5 | LL | return true; | ^^^^^^^^^^^ @@ -309,7 +309,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:164:9 + --> tests/ui/needless_return.rs:168:9 | LL | return true; | ^^^^^^^^^^^ @@ -321,7 +321,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:166:9 + --> tests/ui/needless_return.rs:170:9 | LL | return false; | ^^^^^^^^^^^^ @@ -333,7 +333,7 @@ LL + false | error: unneeded `return` statement - --> tests/ui/needless_return.rs:172:17 + --> tests/ui/needless_return.rs:176:17 | LL | true => return false, | ^^^^^^^^^^^^ @@ -344,7 +344,7 @@ LL | true => false, | ~~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:174:13 + --> tests/ui/needless_return.rs:178:13 | LL | return true; | ^^^^^^^^^^^ @@ -356,7 +356,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:181:9 + --> tests/ui/needless_return.rs:185:9 | LL | return true; | ^^^^^^^^^^^ @@ -368,7 +368,7 @@ LL + true | error: unneeded `return` statement - --> tests/ui/needless_return.rs:183:16 + --> tests/ui/needless_return.rs:187:16 | LL | let _ = || return true; | ^^^^^^^^^^^ @@ -379,7 +379,7 @@ LL | let _ = || true; | ~~~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:187:5 + --> tests/ui/needless_return.rs:191:5 | LL | return the_answer!(); | ^^^^^^^^^^^^^^^^^^^^ @@ -391,7 +391,7 @@ LL + the_answer!() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:190:33 + --> tests/ui/needless_return.rs:194:33 | LL | async fn async_test_void_fun() { | _________________________________^ @@ -406,7 +406,7 @@ LL + async fn async_test_void_fun() { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:195:11 + --> tests/ui/needless_return.rs:199:11 | LL | if b { | ___________^ @@ -421,7 +421,7 @@ LL + if b { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:197:13 + --> tests/ui/needless_return.rs:201:13 | LL | } else { | _____________^ @@ -436,7 +436,7 @@ LL + } else { | error: unneeded `return` statement - --> tests/ui/needless_return.rs:205:14 + --> tests/ui/needless_return.rs:209:14 | LL | _ => return, | ^^^^^^ @@ -447,7 +447,7 @@ LL | _ => (), | ~~ error: unneeded `return` statement - --> tests/ui/needless_return.rs:218:9 + --> tests/ui/needless_return.rs:222:9 | LL | return String::from("test"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -459,7 +459,7 @@ LL + String::from("test") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:220:9 + --> tests/ui/needless_return.rs:224:9 | LL | return String::new(); | ^^^^^^^^^^^^^^^^^^^^ @@ -471,7 +471,7 @@ LL + String::new() | error: unneeded `return` statement - --> tests/ui/needless_return.rs:236:5 + --> tests/ui/needless_return.rs:240:5 | LL | return format!("Hello {}", "world!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -483,7 +483,7 @@ LL + format!("Hello {}", "world!") | error: unneeded `return` statement - --> tests/ui/needless_return.rs:277:9 + --> tests/ui/needless_return.rs:281:9 | LL | return true; | ^^^^^^^^^^^ @@ -497,7 +497,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:279:9 + --> tests/ui/needless_return.rs:283:9 | LL | return false; | ^^^^^^^^^^^^ @@ -509,7 +509,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:286:13 + --> tests/ui/needless_return.rs:290:13 | LL | return 10; | ^^^^^^^^^ @@ -524,7 +524,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:289:13 + --> tests/ui/needless_return.rs:293:13 | LL | return 100; | ^^^^^^^^^^ @@ -537,7 +537,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:297:9 + --> tests/ui/needless_return.rs:301:9 | LL | return 0; | ^^^^^^^^ @@ -549,7 +549,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:304:13 + --> tests/ui/needless_return.rs:308:13 | LL | return *(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -564,7 +564,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:306:13 + --> tests/ui/needless_return.rs:310:13 | LL | return !*(x as *const isize); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -577,7 +577,7 @@ LL ~ } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:313:20 + --> tests/ui/needless_return.rs:317:20 | LL | let _ = 42; | ____________________^ @@ -594,7 +594,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:320:20 + --> tests/ui/needless_return.rs:324:20 | LL | let _ = 42; return; | ^^^^^^^ @@ -606,7 +606,7 @@ LL + let _ = 42; | error: unneeded `return` statement - --> tests/ui/needless_return.rs:332:9 + --> tests/ui/needless_return.rs:336:9 | LL | return Ok(format!("ok!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -618,7 +618,7 @@ LL + Ok(format!("ok!")) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:334:9 + --> tests/ui/needless_return.rs:338:9 | LL | return Err(format!("err!")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -630,7 +630,7 @@ LL + Err(format!("err!")) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:340:9 + --> tests/ui/needless_return.rs:344:9 | LL | return if true { 1 } else { 2 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -642,7 +642,7 @@ LL + if true { 1 } else { 2 } | error: unneeded `return` statement - --> tests/ui/needless_return.rs:344:9 + --> tests/ui/needless_return.rs:348:9 | LL | return if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else { 5 }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -654,7 +654,7 @@ LL + (if b1 { 0 } else { 1 } | if b2 { 2 } else { 3 } | if b3 { 4 } else | error: unneeded `return` statement - --> tests/ui/needless_return.rs:365:5 + --> tests/ui/needless_return.rs:369:5 | LL | return { "a".to_string() } + "b" + { "c" }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -666,7 +666,7 @@ LL + ({ "a".to_string() } + "b" + { "c" }) | error: unneeded `return` statement - --> tests/ui/needless_return.rs:369:5 + --> tests/ui/needless_return.rs:373:5 | LL | return "".split("").next().unwrap().to_string(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/new_without_default.fixed b/tests/ui/new_without_default.fixed index 85408c4e17f..5a6a92394a7 100644 --- a/tests/ui/new_without_default.fixed +++ b/tests/ui/new_without_default.fixed @@ -2,7 +2,8 @@ dead_code, clippy::missing_safety_doc, clippy::extra_unused_lifetimes, - clippy::extra_unused_type_parameters + clippy::extra_unused_type_parameters, + clippy::needless_lifetimes )] #![warn(clippy::new_without_default)] diff --git a/tests/ui/new_without_default.rs b/tests/ui/new_without_default.rs index 3ac7292c236..12ea729253a 100644 --- a/tests/ui/new_without_default.rs +++ b/tests/ui/new_without_default.rs @@ -2,7 +2,8 @@ dead_code, clippy::missing_safety_doc, clippy::extra_unused_lifetimes, - clippy::extra_unused_type_parameters + clippy::extra_unused_type_parameters, + clippy::needless_lifetimes )] #![warn(clippy::new_without_default)] diff --git a/tests/ui/new_without_default.stderr b/tests/ui/new_without_default.stderr index a30830ae7b2..57bf4bd847c 100644 --- a/tests/ui/new_without_default.stderr +++ b/tests/ui/new_without_default.stderr @@ -1,5 +1,5 @@ error: you should consider adding a `Default` implementation for `Foo` - --> tests/ui/new_without_default.rs:12:5 + --> tests/ui/new_without_default.rs:13:5 | LL | / pub fn new() -> Foo { LL | | @@ -20,7 +20,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Bar` - --> tests/ui/new_without_default.rs:22:5 + --> tests/ui/new_without_default.rs:23:5 | LL | / pub fn new() -> Self { LL | | @@ -38,7 +38,7 @@ LL + } | error: you should consider adding a `Default` implementation for `LtKo<'c>` - --> tests/ui/new_without_default.rs:87:5 + --> tests/ui/new_without_default.rs:88:5 | LL | / pub fn new() -> LtKo<'c> { LL | | @@ -56,7 +56,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Const` - --> tests/ui/new_without_default.rs:120:5 + --> tests/ui/new_without_default.rs:121:5 | LL | / pub const fn new() -> Const { LL | | Const @@ -73,7 +73,7 @@ LL + } | error: you should consider adding a `Default` implementation for `NewNotEqualToDerive` - --> tests/ui/new_without_default.rs:180:5 + --> tests/ui/new_without_default.rs:181:5 | LL | / pub fn new() -> Self { LL | | @@ -91,7 +91,7 @@ LL + } | error: you should consider adding a `Default` implementation for `FooGenerics<T>` - --> tests/ui/new_without_default.rs:189:5 + --> tests/ui/new_without_default.rs:190:5 | LL | / pub fn new() -> Self { LL | | @@ -109,7 +109,7 @@ LL + } | error: you should consider adding a `Default` implementation for `BarGenerics<T>` - --> tests/ui/new_without_default.rs:197:5 + --> tests/ui/new_without_default.rs:198:5 | LL | / pub fn new() -> Self { LL | | @@ -127,7 +127,7 @@ LL + } | error: you should consider adding a `Default` implementation for `Foo<T>` - --> tests/ui/new_without_default.rs:209:9 + --> tests/ui/new_without_default.rs:210:9 | LL | / pub fn new() -> Self { LL | | @@ -147,7 +147,7 @@ LL ~ impl<T> Foo<T> { | error: you should consider adding a `Default` implementation for `MyStruct<K, V>` - --> tests/ui/new_without_default.rs:255:5 + --> tests/ui/new_without_default.rs:256:5 | LL | / pub fn new() -> Self { LL | | Self { _kv: None } diff --git a/tests/ui/nonminimal_bool_methods.fixed b/tests/ui/nonminimal_bool_methods.fixed index cc91ba6ec66..a23310c1ad9 100644 --- a/tests/ui/nonminimal_bool_methods.fixed +++ b/tests/ui/nonminimal_bool_methods.fixed @@ -115,4 +115,66 @@ fn issue_12625() { if a as u64 > b {} //~ ERROR: this boolean expression can be simplified } +fn issue_13436() { + fn not_zero(x: i32) -> bool { + x != 0 + } + + let opt = Some(500); + _ = opt.is_some_and(|x| x < 1000); + _ = opt.is_some_and(|x| x <= 1000); + _ = opt.is_some_and(|x| x > 1000); + _ = opt.is_some_and(|x| x >= 1000); + _ = opt.is_some_and(|x| x == 1000); + _ = opt.is_some_and(|x| x != 1000); + _ = opt.is_some_and(not_zero); + _ = opt.is_none_or(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified + _ = opt.is_none_or(|x| x > 1000); //~ ERROR: this boolean expression can be simplified + _ = opt.is_none_or(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified + _ = opt.is_none_or(|x| x < 1000); //~ ERROR: this boolean expression can be simplified + _ = opt.is_none_or(|x| x != 1000); //~ ERROR: this boolean expression can be simplified + _ = opt.is_none_or(|x| x == 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_some_and(not_zero); + _ = opt.is_none_or(|x| x < 1000); + _ = opt.is_none_or(|x| x <= 1000); + _ = opt.is_none_or(|x| x > 1000); + _ = opt.is_none_or(|x| x >= 1000); + _ = opt.is_none_or(|x| x == 1000); + _ = opt.is_none_or(|x| x != 1000); + _ = opt.is_none_or(not_zero); + _ = opt.is_some_and(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified + _ = opt.is_some_and(|x| x > 1000); //~ ERROR: this boolean expression can be simplified + _ = opt.is_some_and(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified + _ = opt.is_some_and(|x| x < 1000); //~ ERROR: this boolean expression can be simplified + _ = opt.is_some_and(|x| x != 1000); //~ ERROR: this boolean expression can be simplified + _ = opt.is_some_and(|x| x == 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_none_or(not_zero); + + let opt = Some(true); + _ = opt.is_some_and(|x| x); + _ = opt.is_some_and(|x| !x); + _ = !opt.is_some_and(|x| x); + _ = opt.is_none_or(|x| x); //~ ERROR: this boolean expression can be simplified + _ = opt.is_none_or(|x| x); + _ = opt.is_none_or(|x| !x); + _ = !opt.is_none_or(|x| x); + _ = opt.is_some_and(|x| x); //~ ERROR: this boolean expression can be simplified + + let opt: Option<Result<i32, i32>> = Some(Ok(123)); + _ = opt.is_some_and(|x| x.is_ok()); + _ = opt.is_some_and(|x| x.is_err()); + _ = opt.is_none_or(|x| x.is_ok()); + _ = opt.is_none_or(|x| x.is_err()); + _ = opt.is_none_or(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified + _ = opt.is_none_or(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified + _ = opt.is_some_and(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified + _ = opt.is_some_and(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified + + #[clippy::msrv = "1.81"] + fn before_stabilization() { + let opt = Some(500); + _ = !opt.is_some_and(|x| x < 1000); + } +} + fn main() {} diff --git a/tests/ui/nonminimal_bool_methods.rs b/tests/ui/nonminimal_bool_methods.rs index c812f6f0ca4..6c844373af7 100644 --- a/tests/ui/nonminimal_bool_methods.rs +++ b/tests/ui/nonminimal_bool_methods.rs @@ -115,4 +115,66 @@ fn issue_12625() { if !(a as u64 <= b) {} //~ ERROR: this boolean expression can be simplified } +fn issue_13436() { + fn not_zero(x: i32) -> bool { + x != 0 + } + + let opt = Some(500); + _ = opt.is_some_and(|x| x < 1000); + _ = opt.is_some_and(|x| x <= 1000); + _ = opt.is_some_and(|x| x > 1000); + _ = opt.is_some_and(|x| x >= 1000); + _ = opt.is_some_and(|x| x == 1000); + _ = opt.is_some_and(|x| x != 1000); + _ = opt.is_some_and(not_zero); + _ = !opt.is_some_and(|x| x < 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_some_and(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_some_and(|x| x > 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_some_and(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_some_and(|x| x == 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_some_and(|x| x != 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_some_and(not_zero); + _ = opt.is_none_or(|x| x < 1000); + _ = opt.is_none_or(|x| x <= 1000); + _ = opt.is_none_or(|x| x > 1000); + _ = opt.is_none_or(|x| x >= 1000); + _ = opt.is_none_or(|x| x == 1000); + _ = opt.is_none_or(|x| x != 1000); + _ = opt.is_none_or(not_zero); + _ = !opt.is_none_or(|x| x < 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_none_or(|x| x <= 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_none_or(|x| x > 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_none_or(|x| x >= 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_none_or(|x| x == 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_none_or(|x| x != 1000); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_none_or(not_zero); + + let opt = Some(true); + _ = opt.is_some_and(|x| x); + _ = opt.is_some_and(|x| !x); + _ = !opt.is_some_and(|x| x); + _ = !opt.is_some_and(|x| !x); //~ ERROR: this boolean expression can be simplified + _ = opt.is_none_or(|x| x); + _ = opt.is_none_or(|x| !x); + _ = !opt.is_none_or(|x| x); + _ = !opt.is_none_or(|x| !x); //~ ERROR: this boolean expression can be simplified + + let opt: Option<Result<i32, i32>> = Some(Ok(123)); + _ = opt.is_some_and(|x| x.is_ok()); + _ = opt.is_some_and(|x| x.is_err()); + _ = opt.is_none_or(|x| x.is_ok()); + _ = opt.is_none_or(|x| x.is_err()); + _ = !opt.is_some_and(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_some_and(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_none_or(|x| x.is_ok()); //~ ERROR: this boolean expression can be simplified + _ = !opt.is_none_or(|x| x.is_err()); //~ ERROR: this boolean expression can be simplified + + #[clippy::msrv = "1.81"] + fn before_stabilization() { + let opt = Some(500); + _ = !opt.is_some_and(|x| x < 1000); + } +} + fn main() {} diff --git a/tests/ui/nonminimal_bool_methods.stderr b/tests/ui/nonminimal_bool_methods.stderr index d7adc0638b3..52803e828ae 100644 --- a/tests/ui/nonminimal_bool_methods.stderr +++ b/tests/ui/nonminimal_bool_methods.stderr @@ -97,5 +97,113 @@ error: this boolean expression can be simplified LL | if !(a as u64 <= b) {} | ^^^^^^^^^^^^^^^^ help: try: `a as u64 > b` -error: aborting due to 16 previous errors +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:131:9 + | +LL | _ = !opt.is_some_and(|x| x < 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x >= 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:132:9 + | +LL | _ = !opt.is_some_and(|x| x <= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x > 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:133:9 + | +LL | _ = !opt.is_some_and(|x| x > 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x <= 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:134:9 + | +LL | _ = !opt.is_some_and(|x| x >= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x < 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:135:9 + | +LL | _ = !opt.is_some_and(|x| x == 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x != 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:136:9 + | +LL | _ = !opt.is_some_and(|x| x != 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x == 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:145:9 + | +LL | _ = !opt.is_none_or(|x| x < 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x >= 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:146:9 + | +LL | _ = !opt.is_none_or(|x| x <= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x > 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:147:9 + | +LL | _ = !opt.is_none_or(|x| x > 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x <= 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:148:9 + | +LL | _ = !opt.is_none_or(|x| x >= 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x < 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:149:9 + | +LL | _ = !opt.is_none_or(|x| x == 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x != 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:150:9 + | +LL | _ = !opt.is_none_or(|x| x != 1000); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x == 1000)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:157:9 + | +LL | _ = !opt.is_some_and(|x| !x); + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:161:9 + | +LL | _ = !opt.is_none_or(|x| !x); + | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x)` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:168:9 + | +LL | _ = !opt.is_some_and(|x| x.is_ok()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_err())` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:169:9 + | +LL | _ = !opt.is_some_and(|x| x.is_err()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_none_or(|x| x.is_ok())` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:170:9 + | +LL | _ = !opt.is_none_or(|x| x.is_ok()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_err())` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods.rs:171:9 + | +LL | _ = !opt.is_none_or(|x| x.is_err()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt.is_some_and(|x| x.is_ok())` + +error: aborting due to 34 previous errors diff --git a/tests/ui/nonminimal_bool_methods_unfixable.rs b/tests/ui/nonminimal_bool_methods_unfixable.rs new file mode 100644 index 00000000000..60b8da30a2f --- /dev/null +++ b/tests/ui/nonminimal_bool_methods_unfixable.rs @@ -0,0 +1,9 @@ +#![warn(clippy::nonminimal_bool)] +//@no-rustfix + +fn issue_13436() { + let opt_opt = Some(Some(500)); + _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); //~ ERROR: this boolean expression can be simplified +} + +fn main() {} diff --git a/tests/ui/nonminimal_bool_methods_unfixable.stderr b/tests/ui/nonminimal_bool_methods_unfixable.stderr new file mode 100644 index 00000000000..5a90155844c --- /dev/null +++ b/tests/ui/nonminimal_bool_methods_unfixable.stderr @@ -0,0 +1,17 @@ +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods_unfixable.rs:6:9 + | +LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `opt_opt.is_none_or(|x| x.is_some_and(|y| y != 1000))` + | + = note: `-D clippy::nonminimal-bool` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]` + +error: this boolean expression can be simplified + --> tests/ui/nonminimal_bool_methods_unfixable.rs:6:34 + | +LL | _ = !opt_opt.is_some_and(|x| !x.is_some_and(|y| y != 1000)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_none_or(|y| y == 1000)` + +error: aborting due to 2 previous errors + diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed index 7452eb77688..625d654dd39 100644 --- a/tests/ui/or_fun_call.fixed +++ b/tests/ui/or_fun_call.fixed @@ -341,18 +341,18 @@ fn fn_call_in_nested_expr() { } let opt: Option<i32> = Some(1); - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or_else(f); // suggest `.unwrap_or_else(f)` // - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or_else(|| f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` // - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or_else(|| { let x = f(); x + 1 }); - //~v ERROR: use of `map_or` followed by a function call + //~v ERROR: function call inside of `map_or` let _ = opt.map_or_else(|| f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` // //~v ERROR: use of `unwrap_or` to construct default value @@ -361,7 +361,7 @@ fn fn_call_in_nested_expr() { let opt_foo = Some(Foo { val: String::from("123"), }); - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt_foo.unwrap_or_else(|| Foo { val: String::default() }); } diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs index cd6f7bb2070..5b7d8faec7b 100644 --- a/tests/ui/or_fun_call.rs +++ b/tests/ui/or_fun_call.rs @@ -341,18 +341,18 @@ fn fn_call_in_nested_expr() { } let opt: Option<i32> = Some(1); - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` // - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` // - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt.unwrap_or({ let x = f(); x + 1 }); - //~v ERROR: use of `map_or` followed by a function call + //~v ERROR: function call inside of `map_or` let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` // //~v ERROR: use of `unwrap_or` to construct default value @@ -361,7 +361,7 @@ fn fn_call_in_nested_expr() { let opt_foo = Some(Foo { val: String::from("123"), }); - //~v ERROR: use of `unwrap_or` followed by a function call + //~v ERROR: function call inside of `unwrap_or` let _ = opt_foo.unwrap_or(Foo { val: String::default() }); } diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr index 06f804fb41e..9f90a830a21 100644 --- a/tests/ui/or_fun_call.stderr +++ b/tests/ui/or_fun_call.stderr @@ -1,4 +1,4 @@ -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:52:22 | LL | with_constructor.unwrap_or(make()); @@ -16,19 +16,19 @@ LL | with_new.unwrap_or(Vec::new()); = note: `-D clippy::unwrap-or-default` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unwrap_or_default)]` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:58:21 | LL | with_const_args.unwrap_or(Vec::with_capacity(12)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Vec::with_capacity(12))` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:61:14 | LL | with_err.unwrap_or(make()); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| make())` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:64:19 | LL | with_err_args.unwrap_or(Vec::with_capacity(12)); @@ -46,7 +46,7 @@ error: use of `unwrap_or` to construct default value LL | with_default_type.unwrap_or(u64::default()); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:73:18 | LL | self_default.unwrap_or(<FakeDefault>::default()); @@ -64,7 +64,7 @@ error: use of `unwrap_or` to construct default value LL | with_vec.unwrap_or(vec![]); | ^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:82:21 | LL | without_default.unwrap_or(Foo::new()); @@ -100,55 +100,55 @@ error: use of `unwrap_or` to construct default value LL | let _ = stringy.unwrap_or(String::new()); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `ok_or` followed by a function call +error: function call inside of `ok_or` --> tests/ui/or_fun_call.rs:101:17 | LL | let _ = opt.ok_or(format!("{} world.", hello)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ok_or_else(|| format!("{} world.", hello))` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:105:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:107:21 | LL | let _ = Some(1).unwrap_or(map[&1]); | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| map[&1])` -error: use of `or` followed by a function call +error: function call inside of `or` --> tests/ui/or_fun_call.rs:131:35 | LL | let _ = Some("a".to_string()).or(Some("b".to_string())); | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_else(|| Some("b".to_string()))` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:170:14 | LL | None.unwrap_or(ptr_to_ref(s)); | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| ptr_to_ref(s))` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:176:14 | LL | None.unwrap_or(unsafe { ptr_to_ref(s) }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:178:14 | LL | None.unwrap_or( unsafe { ptr_to_ref(s) } ); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })` -error: use of `map_or` followed by a function call +error: function call inside of `map_or` --> tests/ui/or_fun_call.rs:253:25 | LL | let _ = Some(4).map_or(g(), |v| v); | ^^^^^^^^^^^^^^^^^^ help: try: `map_or_else(g, |v| v)` -error: use of `map_or` followed by a function call +error: function call inside of `map_or` --> tests/ui/or_fun_call.rs:254:25 | LL | let _ = Some(4).map_or(g(), f); @@ -196,19 +196,19 @@ error: use of `unwrap_or_else` to construct default value LL | let _ = stringy.unwrap_or_else(String::new); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:345:17 | LL | let _ = opt.unwrap_or({ f() }); // suggest `.unwrap_or_else(f)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(f)` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:348:17 | LL | let _ = opt.unwrap_or(f() + 1); // suggest `.unwrap_or_else(|| f() + 1)` | ^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| f() + 1)` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:351:17 | LL | let _ = opt.unwrap_or({ @@ -226,7 +226,7 @@ LL + x + 1 LL ~ }); | -error: use of `map_or` followed by a function call +error: function call inside of `map_or` --> tests/ui/or_fun_call.rs:356:17 | LL | let _ = opt.map_or(f() + 1, |v| v); // suggest `.map_or_else(|| f() + 1, |v| v)` @@ -238,7 +238,7 @@ error: use of `unwrap_or` to construct default value LL | let _ = opt.unwrap_or({ i32::default() }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/or_fun_call.rs:365:21 | LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() }); diff --git a/tests/ui/ref_as_ptr.fixed b/tests/ui/ref_as_ptr.fixed index 466a628a002..6048267092f 100644 --- a/tests/ui/ref_as_ptr.fixed +++ b/tests/ui/ref_as_ptr.fixed @@ -1,5 +1,5 @@ #![warn(clippy::ref_as_ptr)] -#![allow(clippy::unnecessary_mut_passed)] +#![allow(clippy::unnecessary_mut_passed, clippy::needless_lifetimes)] fn f<T>(_: T) {} diff --git a/tests/ui/ref_as_ptr.rs b/tests/ui/ref_as_ptr.rs index 0fdc753dc22..7f1d59b856e 100644 --- a/tests/ui/ref_as_ptr.rs +++ b/tests/ui/ref_as_ptr.rs @@ -1,5 +1,5 @@ #![warn(clippy::ref_as_ptr)] -#![allow(clippy::unnecessary_mut_passed)] +#![allow(clippy::unnecessary_mut_passed, clippy::needless_lifetimes)] fn f<T>(_: T) {} diff --git a/tests/ui/ref_option/all/clippy.toml b/tests/ui/ref_option/all/clippy.toml new file mode 100644 index 00000000000..cda8d17eed4 --- /dev/null +++ b/tests/ui/ref_option/all/clippy.toml @@ -0,0 +1 @@ +avoid-breaking-exported-api = false diff --git a/tests/ui/ref_option/private/clippy.toml b/tests/ui/ref_option/private/clippy.toml new file mode 100644 index 00000000000..5f304987aa9 --- /dev/null +++ b/tests/ui/ref_option/private/clippy.toml @@ -0,0 +1 @@ +avoid-breaking-exported-api = true diff --git a/tests/ui/ref_option/ref_option.all.fixed b/tests/ui/ref_option/ref_option.all.fixed new file mode 100644 index 00000000000..47781a97c98 --- /dev/null +++ b/tests/ui/ref_option/ref_option.all.fixed @@ -0,0 +1,62 @@ +//@revisions: private all +//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/private +//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/all + +#![allow(unused, clippy::needless_lifetimes, clippy::borrowed_box)] +#![warn(clippy::ref_option)] + +fn opt_u8(a: Option<&u8>) {} +fn opt_gen<T>(a: Option<&T>) {} +fn opt_string(a: std::option::Option<&String>) {} +fn ret_string<'a>(p: &'a str) -> Option<&'a u8> { + panic!() +} +fn ret_string_static() -> Option<&'static u8> { + panic!() +} +fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {} +fn ret_box<'a>() -> Option<&'a Box<u8>> { + panic!() +} + +pub fn pub_opt_string(a: Option<&String>) {} +pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {} + +pub trait PubTrait { + fn pub_trait_opt(&self, a: Option<&Vec<u8>>); + fn pub_trait_ret(&self) -> Option<&Vec<u8>>; +} + +trait PrivateTrait { + fn trait_opt(&self, a: Option<&String>); + fn trait_ret(&self) -> Option<&String>; +} + +pub struct PubStruct; + +impl PubStruct { + pub fn pub_opt_params(&self, a: Option<&()>) {} + pub fn pub_opt_ret(&self) -> Option<&String> { + panic!() + } + + fn private_opt_params(&self, a: Option<&()>) {} + fn private_opt_ret(&self) -> Option<&String> { + panic!() + } +} + +// valid, don't change +fn mut_u8(a: &mut Option<u8>) {} +pub fn pub_mut_u8(a: &mut Option<String>) {} + +// might be good to catch in the future +fn mut_u8_ref(a: &mut &Option<u8>) {} +pub fn pub_mut_u8_ref(a: &mut &Option<String>) {} +fn lambdas() { + // Not handled for now, not sure if we should + let x = |a: &Option<String>| {}; + let x = |a: &Option<String>| -> &Option<String> { panic!() }; +} + +fn main() {} diff --git a/tests/ui/ref_option/ref_option.all.stderr b/tests/ui/ref_option/ref_option.all.stderr new file mode 100644 index 00000000000..b4c69ac6296 --- /dev/null +++ b/tests/ui/ref_option/ref_option.all.stderr @@ -0,0 +1,162 @@ +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:8:1 + | +LL | fn opt_u8(a: &Option<u8>) {} + | ^^^^^^^^^^^^^-----------^^^^ + | | + | help: change this to: `Option<&u8>` + | + = note: `-D clippy::ref-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ref_option)]` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:9:1 + | +LL | fn opt_gen<T>(a: &Option<T>) {} + | ^^^^^^^^^^^^^^^^^----------^^^^ + | | + | help: change this to: `Option<&T>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:10:1 + | +LL | fn opt_string(a: &std::option::Option<String>) {} + | ^^^^^^^^^^^^^^^^^----------------------------^^^^ + | | + | help: change this to: `std::option::Option<&String>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:11:1 + | +LL | fn ret_string<'a>(p: &'a str) -> &'a Option<u8> { + | ^ -------------- help: change this to: `Option<&'a u8>` + | _| + | | +LL | | panic!() +LL | | } + | |_^ + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:14:1 + | +LL | fn ret_string_static() -> &'static Option<u8> { + | ^ ------------------- help: change this to: `Option<&'static u8>` + | _| + | | +LL | | panic!() +LL | | } + | |_^ + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:17:1 + | +LL | fn mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: change this to + | +LL | fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {} + | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:18:1 + | +LL | fn ret_box<'a>() -> &'a Option<Box<u8>> { + | ^ ------------------- help: change this to: `Option<&'a Box<u8>>` + | _| + | | +LL | | panic!() +LL | | } + | |_^ + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:22:1 + | +LL | pub fn pub_opt_string(a: &Option<String>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^---------------^^^^ + | | + | help: change this to: `Option<&String>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:23:1 + | +LL | pub fn pub_mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: change this to + | +LL | pub fn pub_mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {} + | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:26:5 + | +LL | fn pub_trait_opt(&self, a: &Option<Vec<u8>>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^^ + | | + | help: change this to: `Option<&Vec<u8>>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:27:5 + | +LL | fn pub_trait_ret(&self) -> &Option<Vec<u8>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^ + | | + | help: change this to: `Option<&Vec<u8>>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:31:5 + | +LL | fn trait_opt(&self, a: &Option<String>); + | ^^^^^^^^^^^^^^^^^^^^^^^---------------^^ + | | + | help: change this to: `Option<&String>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:32:5 + | +LL | fn trait_ret(&self) -> &Option<String>; + | ^^^^^^^^^^^^^^^^^^^^^^^---------------^ + | | + | help: change this to: `Option<&String>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:38:5 + | +LL | pub fn pub_opt_params(&self, a: &Option<()>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^ + | | + | help: change this to: `Option<&()>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:39:5 + | +LL | pub fn pub_opt_ret(&self) -> &Option<String> { + | ^ --------------- help: change this to: `Option<&String>` + | _____| + | | +LL | | panic!() +LL | | } + | |_____^ + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:43:5 + | +LL | fn private_opt_params(&self, a: &Option<()>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^ + | | + | help: change this to: `Option<&()>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:44:5 + | +LL | fn private_opt_ret(&self) -> &Option<String> { + | ^ --------------- help: change this to: `Option<&String>` + | _____| + | | +LL | | panic!() +LL | | } + | |_____^ + +error: aborting due to 17 previous errors + diff --git a/tests/ui/ref_option/ref_option.private.fixed b/tests/ui/ref_option/ref_option.private.fixed new file mode 100644 index 00000000000..8c42556e9b0 --- /dev/null +++ b/tests/ui/ref_option/ref_option.private.fixed @@ -0,0 +1,62 @@ +//@revisions: private all +//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/private +//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/all + +#![allow(unused, clippy::needless_lifetimes, clippy::borrowed_box)] +#![warn(clippy::ref_option)] + +fn opt_u8(a: Option<&u8>) {} +fn opt_gen<T>(a: Option<&T>) {} +fn opt_string(a: std::option::Option<&String>) {} +fn ret_string<'a>(p: &'a str) -> Option<&'a u8> { + panic!() +} +fn ret_string_static() -> Option<&'static u8> { + panic!() +} +fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {} +fn ret_box<'a>() -> Option<&'a Box<u8>> { + panic!() +} + +pub fn pub_opt_string(a: &Option<String>) {} +pub fn pub_mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {} + +pub trait PubTrait { + fn pub_trait_opt(&self, a: &Option<Vec<u8>>); + fn pub_trait_ret(&self) -> &Option<Vec<u8>>; +} + +trait PrivateTrait { + fn trait_opt(&self, a: Option<&String>); + fn trait_ret(&self) -> Option<&String>; +} + +pub struct PubStruct; + +impl PubStruct { + pub fn pub_opt_params(&self, a: &Option<()>) {} + pub fn pub_opt_ret(&self) -> &Option<String> { + panic!() + } + + fn private_opt_params(&self, a: Option<&()>) {} + fn private_opt_ret(&self) -> Option<&String> { + panic!() + } +} + +// valid, don't change +fn mut_u8(a: &mut Option<u8>) {} +pub fn pub_mut_u8(a: &mut Option<String>) {} + +// might be good to catch in the future +fn mut_u8_ref(a: &mut &Option<u8>) {} +pub fn pub_mut_u8_ref(a: &mut &Option<String>) {} +fn lambdas() { + // Not handled for now, not sure if we should + let x = |a: &Option<String>| {}; + let x = |a: &Option<String>| -> &Option<String> { panic!() }; +} + +fn main() {} diff --git a/tests/ui/ref_option/ref_option.private.stderr b/tests/ui/ref_option/ref_option.private.stderr new file mode 100644 index 00000000000..17c90536da3 --- /dev/null +++ b/tests/ui/ref_option/ref_option.private.stderr @@ -0,0 +1,108 @@ +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:8:1 + | +LL | fn opt_u8(a: &Option<u8>) {} + | ^^^^^^^^^^^^^-----------^^^^ + | | + | help: change this to: `Option<&u8>` + | + = note: `-D clippy::ref-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ref_option)]` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:9:1 + | +LL | fn opt_gen<T>(a: &Option<T>) {} + | ^^^^^^^^^^^^^^^^^----------^^^^ + | | + | help: change this to: `Option<&T>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:10:1 + | +LL | fn opt_string(a: &std::option::Option<String>) {} + | ^^^^^^^^^^^^^^^^^----------------------------^^^^ + | | + | help: change this to: `std::option::Option<&String>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:11:1 + | +LL | fn ret_string<'a>(p: &'a str) -> &'a Option<u8> { + | ^ -------------- help: change this to: `Option<&'a u8>` + | _| + | | +LL | | panic!() +LL | | } + | |_^ + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:14:1 + | +LL | fn ret_string_static() -> &'static Option<u8> { + | ^ ------------------- help: change this to: `Option<&'static u8>` + | _| + | | +LL | | panic!() +LL | | } + | |_^ + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:17:1 + | +LL | fn mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: change this to + | +LL | fn mult_string(a: Option<&String>, b: Option<&Vec<u8>>) {} + | ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:18:1 + | +LL | fn ret_box<'a>() -> &'a Option<Box<u8>> { + | ^ ------------------- help: change this to: `Option<&'a Box<u8>>` + | _| + | | +LL | | panic!() +LL | | } + | |_^ + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:31:5 + | +LL | fn trait_opt(&self, a: &Option<String>); + | ^^^^^^^^^^^^^^^^^^^^^^^---------------^^ + | | + | help: change this to: `Option<&String>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:32:5 + | +LL | fn trait_ret(&self) -> &Option<String>; + | ^^^^^^^^^^^^^^^^^^^^^^^---------------^ + | | + | help: change this to: `Option<&String>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:43:5 + | +LL | fn private_opt_params(&self, a: &Option<()>) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------^^^^ + | | + | help: change this to: `Option<&()>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option.rs:44:5 + | +LL | fn private_opt_ret(&self) -> &Option<String> { + | ^ --------------- help: change this to: `Option<&String>` + | _____| + | | +LL | | panic!() +LL | | } + | |_____^ + +error: aborting due to 11 previous errors + diff --git a/tests/ui/ref_option/ref_option.rs b/tests/ui/ref_option/ref_option.rs new file mode 100644 index 00000000000..05251bcf12c --- /dev/null +++ b/tests/ui/ref_option/ref_option.rs @@ -0,0 +1,62 @@ +//@revisions: private all +//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/private +//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/all + +#![allow(unused, clippy::needless_lifetimes, clippy::borrowed_box)] +#![warn(clippy::ref_option)] + +fn opt_u8(a: &Option<u8>) {} +fn opt_gen<T>(a: &Option<T>) {} +fn opt_string(a: &std::option::Option<String>) {} +fn ret_string<'a>(p: &'a str) -> &'a Option<u8> { + panic!() +} +fn ret_string_static() -> &'static Option<u8> { + panic!() +} +fn mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {} +fn ret_box<'a>() -> &'a Option<Box<u8>> { + panic!() +} + +pub fn pub_opt_string(a: &Option<String>) {} +pub fn pub_mult_string(a: &Option<String>, b: &Option<Vec<u8>>) {} + +pub trait PubTrait { + fn pub_trait_opt(&self, a: &Option<Vec<u8>>); + fn pub_trait_ret(&self) -> &Option<Vec<u8>>; +} + +trait PrivateTrait { + fn trait_opt(&self, a: &Option<String>); + fn trait_ret(&self) -> &Option<String>; +} + +pub struct PubStruct; + +impl PubStruct { + pub fn pub_opt_params(&self, a: &Option<()>) {} + pub fn pub_opt_ret(&self) -> &Option<String> { + panic!() + } + + fn private_opt_params(&self, a: &Option<()>) {} + fn private_opt_ret(&self) -> &Option<String> { + panic!() + } +} + +// valid, don't change +fn mut_u8(a: &mut Option<u8>) {} +pub fn pub_mut_u8(a: &mut Option<String>) {} + +// might be good to catch in the future +fn mut_u8_ref(a: &mut &Option<u8>) {} +pub fn pub_mut_u8_ref(a: &mut &Option<String>) {} +fn lambdas() { + // Not handled for now, not sure if we should + let x = |a: &Option<String>| {}; + let x = |a: &Option<String>| -> &Option<String> { panic!() }; +} + +fn main() {} diff --git a/tests/ui/ref_option/ref_option_traits.all.stderr b/tests/ui/ref_option/ref_option_traits.all.stderr new file mode 100644 index 00000000000..a9967168c12 --- /dev/null +++ b/tests/ui/ref_option/ref_option_traits.all.stderr @@ -0,0 +1,37 @@ +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option_traits.rs:10:5 + | +LL | fn pub_trait_opt(&self, a: &Option<Vec<u8>>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^^ + | | + | help: change this to: `Option<&Vec<u8>>` + | + = note: `-D clippy::ref-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ref_option)]` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option_traits.rs:11:5 + | +LL | fn pub_trait_ret(&self) -> &Option<Vec<u8>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------^ + | | + | help: change this to: `Option<&Vec<u8>>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option_traits.rs:15:5 + | +LL | fn trait_opt(&self, a: &Option<String>); + | ^^^^^^^^^^^^^^^^^^^^^^^---------------^^ + | | + | help: change this to: `Option<&String>` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option_traits.rs:16:5 + | +LL | fn trait_ret(&self) -> &Option<String>; + | ^^^^^^^^^^^^^^^^^^^^^^^---------------^ + | | + | help: change this to: `Option<&String>` + +error: aborting due to 4 previous errors + diff --git a/tests/ui/ref_option/ref_option_traits.private.stderr b/tests/ui/ref_option/ref_option_traits.private.stderr new file mode 100644 index 00000000000..36d0833af8a --- /dev/null +++ b/tests/ui/ref_option/ref_option_traits.private.stderr @@ -0,0 +1,21 @@ +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option_traits.rs:15:5 + | +LL | fn trait_opt(&self, a: &Option<String>); + | ^^^^^^^^^^^^^^^^^^^^^^^---------------^^ + | | + | help: change this to: `Option<&String>` + | + = note: `-D clippy::ref-option` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::ref_option)]` + +error: it is more idiomatic to use `Option<&T>` instead of `&Option<T>` + --> tests/ui/ref_option/ref_option_traits.rs:16:5 + | +LL | fn trait_ret(&self) -> &Option<String>; + | ^^^^^^^^^^^^^^^^^^^^^^^---------------^ + | | + | help: change this to: `Option<&String>` + +error: aborting due to 2 previous errors + diff --git a/tests/ui/ref_option/ref_option_traits.rs b/tests/ui/ref_option/ref_option_traits.rs new file mode 100644 index 00000000000..5d5f113c83d --- /dev/null +++ b/tests/ui/ref_option/ref_option_traits.rs @@ -0,0 +1,37 @@ +//@no-rustfix: fixes are only done to traits, not the impls +//@revisions: private all +//@[private] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/private +//@[all] rustc-env:CLIPPY_CONF_DIR=tests/ui/ref_option/all + +#![allow(unused, clippy::all)] +#![warn(clippy::ref_option)] + +pub trait PubTrait { + fn pub_trait_opt(&self, a: &Option<Vec<u8>>); + fn pub_trait_ret(&self) -> &Option<Vec<u8>>; +} + +trait PrivateTrait { + fn trait_opt(&self, a: &Option<String>); + fn trait_ret(&self) -> &Option<String>; +} + +pub struct PubStruct; + +impl PubTrait for PubStruct { + fn pub_trait_opt(&self, a: &Option<Vec<u8>>) {} + fn pub_trait_ret(&self) -> &Option<Vec<u8>> { + panic!() + } +} + +struct PrivateStruct; + +impl PrivateTrait for PrivateStruct { + fn trait_opt(&self, a: &Option<String>) {} + fn trait_ret(&self) -> &Option<String> { + panic!() + } +} + +fn main() {} diff --git a/tests/ui/regex.rs b/tests/ui/regex.rs index 4fb6c08bb44..f607a2d50c6 100644 --- a/tests/ui/regex.rs +++ b/tests/ui/regex.rs @@ -5,7 +5,7 @@ clippy::needless_borrow, clippy::needless_borrows_for_generic_args )] -#![warn(clippy::invalid_regex, clippy::trivial_regex)] +#![warn(clippy::invalid_regex, clippy::trivial_regex, clippy::regex_creation_in_loops)] extern crate regex; @@ -118,7 +118,35 @@ fn trivial_regex() { let _ = BRegex::new(r"\b{start}word\b{end}"); } +fn regex_creation_in_loops() { + loop { + static STATIC_REGEX: std::sync::LazyLock<Regex> = std::sync::LazyLock::new(|| Regex::new("a.b").unwrap()); + + let regex = Regex::new("a.b"); + //~^ ERROR: compiling a regex in a loop + let regex = BRegex::new("a.b"); + //~^ ERROR: compiling a regex in a loop + #[allow(clippy::regex_creation_in_loops)] + let allowed_regex = Regex::new("a.b"); + + if true { + let regex = Regex::new("a.b"); + //~^ ERROR: compiling a regex in a loop + } + + for _ in 0..10 { + let nested_regex = Regex::new("a.b"); + //~^ ERROR: compiling a regex in a loop + } + } + + for i in 0..10 { + let dependant_regex = Regex::new(&format!("{i}")); + } +} + fn main() { syntax_error(); trivial_regex(); + regex_creation_in_loops(); } diff --git a/tests/ui/regex.stderr b/tests/ui/regex.stderr index e936208d8d7..18dd538c68b 100644 --- a/tests/ui/regex.stderr +++ b/tests/ui/regex.stderr @@ -195,5 +195,55 @@ LL | let binary_trivial_empty = BRegex::new("^$"); | = help: consider using `str::is_empty` -error: aborting due to 24 previous errors +error: compiling a regex in a loop + --> tests/ui/regex.rs:125:21 + | +LL | let regex = Regex::new("a.b"); + | ^^^^^^^^^^ + | +help: move the regex construction outside this loop + --> tests/ui/regex.rs:122:5 + | +LL | loop { + | ^^^^ + = note: `-D clippy::regex-creation-in-loops` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::regex_creation_in_loops)]` + +error: compiling a regex in a loop + --> tests/ui/regex.rs:127:21 + | +LL | let regex = BRegex::new("a.b"); + | ^^^^^^^^^^^ + | +help: move the regex construction outside this loop + --> tests/ui/regex.rs:122:5 + | +LL | loop { + | ^^^^ + +error: compiling a regex in a loop + --> tests/ui/regex.rs:133:25 + | +LL | let regex = Regex::new("a.b"); + | ^^^^^^^^^^ + | +help: move the regex construction outside this loop + --> tests/ui/regex.rs:122:5 + | +LL | loop { + | ^^^^ + +error: compiling a regex in a loop + --> tests/ui/regex.rs:138:32 + | +LL | let nested_regex = Regex::new("a.b"); + | ^^^^^^^^^^ + | +help: move the regex construction outside this loop + --> tests/ui/regex.rs:137:9 + | +LL | for _ in 0..10 { + | ^^^^^^^^^^^^^^ + +error: aborting due to 28 previous errors diff --git a/tests/ui/semicolon_outside_block.fixed b/tests/ui/semicolon_outside_block.fixed index 148e112e0bc..ac7e86631ca 100644 --- a/tests/ui/semicolon_outside_block.fixed +++ b/tests/ui/semicolon_outside_block.fixed @@ -80,5 +80,13 @@ fn main() { { unit_fn_block(); }; + unsafe { + std::arch::asm!("") + }; + + { + line!() + }; + unit_fn_block() } diff --git a/tests/ui/semicolon_outside_block.rs b/tests/ui/semicolon_outside_block.rs index c767201469a..68f25339e32 100644 --- a/tests/ui/semicolon_outside_block.rs +++ b/tests/ui/semicolon_outside_block.rs @@ -80,5 +80,13 @@ fn main() { { unit_fn_block(); }; + unsafe { + std::arch::asm!(""); + } + + { + line!(); + } + unit_fn_block() } diff --git a/tests/ui/semicolon_outside_block.stderr b/tests/ui/semicolon_outside_block.stderr index 68b44c8f980..ff8c00048f6 100644 --- a/tests/ui/semicolon_outside_block.stderr +++ b/tests/ui/semicolon_outside_block.stderr @@ -51,5 +51,33 @@ LL - { m!(()); } LL + { m!(()) }; | -error: aborting due to 4 previous errors +error: consider moving the `;` outside the block for consistent formatting + --> tests/ui/semicolon_outside_block.rs:83:5 + | +LL | / unsafe { +LL | | std::arch::asm!(""); +LL | | } + | |_____^ + | +help: put the `;` here + | +LL ~ std::arch::asm!("") +LL ~ }; + | + +error: consider moving the `;` outside the block for consistent formatting + --> tests/ui/semicolon_outside_block.rs:87:5 + | +LL | / { +LL | | line!(); +LL | | } + | |_____^ + | +help: put the `;` here + | +LL ~ line!() +LL ~ }; + | + +error: aborting due to 6 previous errors diff --git a/tests/ui/serde.rs b/tests/ui/serde.rs index 610a50020ec..af8b10f3e6a 100644 --- a/tests/ui/serde.rs +++ b/tests/ui/serde.rs @@ -1,5 +1,5 @@ #![warn(clippy::serde_api_misuse)] -#![allow(dead_code)] +#![allow(dead_code, clippy::needless_lifetimes)] extern crate serde; diff --git a/tests/ui/significant_drop_in_scrutinee.rs b/tests/ui/significant_drop_in_scrutinee.rs index 0db6fbfb7be..8468d1d7c7d 100644 --- a/tests/ui/significant_drop_in_scrutinee.rs +++ b/tests/ui/significant_drop_in_scrutinee.rs @@ -2,7 +2,12 @@ //@no-rustfix #![warn(clippy::significant_drop_in_scrutinee)] #![allow(dead_code, unused_assignments)] -#![allow(clippy::match_single_binding, clippy::single_match, clippy::uninlined_format_args)] +#![allow( + clippy::match_single_binding, + clippy::single_match, + clippy::uninlined_format_args, + clippy::needless_lifetimes +)] use std::num::ParseIntError; use std::ops::Deref; diff --git a/tests/ui/significant_drop_in_scrutinee.stderr b/tests/ui/significant_drop_in_scrutinee.stderr index c0c93cd10c0..62030cbe70e 100644 --- a/tests/ui/significant_drop_in_scrutinee.stderr +++ b/tests/ui/significant_drop_in_scrutinee.stderr @@ -1,5 +1,5 @@ error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:55:11 + --> tests/ui/significant_drop_in_scrutinee.rs:60:11 | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:143:11 + --> tests/ui/significant_drop_in_scrutinee.rs:148:11 | LL | match s.lock_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -42,7 +42,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:166:11 + --> tests/ui/significant_drop_in_scrutinee.rs:171:11 | LL | match s.lock_m_m().get_the_value() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:216:11 + --> tests/ui/significant_drop_in_scrutinee.rs:221:11 | LL | match counter.temp_increment().len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:241:16 + --> tests/ui/significant_drop_in_scrutinee.rs:246:16 | LL | match (mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL ~ match (value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:252:22 + --> tests/ui/significant_drop_in_scrutinee.rs:257:22 | LL | match (true, mutex1.lock().unwrap().s.len(), true) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -118,7 +118,7 @@ LL ~ match (true, value, true) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:264:16 + --> tests/ui/significant_drop_in_scrutinee.rs:269:16 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -139,7 +139,7 @@ LL ~ match (value, true, mutex2.lock().unwrap().s.len()) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:264:54 + --> tests/ui/significant_drop_in_scrutinee.rs:269:54 | LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -160,7 +160,7 @@ LL ~ match (mutex1.lock().unwrap().s.len(), true, value) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:319:11 + --> tests/ui/significant_drop_in_scrutinee.rs:324:11 | LL | match mutex.lock().unwrap().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -179,7 +179,7 @@ LL ~ match value > 1 { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:328:15 + --> tests/ui/significant_drop_in_scrutinee.rs:333:15 | LL | match 1 < mutex.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -198,7 +198,7 @@ LL ~ match 1 < value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:348:11 + --> tests/ui/significant_drop_in_scrutinee.rs:353:11 | LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -219,7 +219,7 @@ LL ~ match value < mutex2.lock().unwrap().s.len() { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:348:44 + --> tests/ui/significant_drop_in_scrutinee.rs:353:44 | LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -240,7 +240,7 @@ LL ~ match mutex1.lock().unwrap().s.len() < value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:361:11 + --> tests/ui/significant_drop_in_scrutinee.rs:366:11 | LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -261,7 +261,7 @@ LL ~ match value >= mutex2.lock().unwrap().s.len() { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:361:45 + --> tests/ui/significant_drop_in_scrutinee.rs:366:45 | LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -282,7 +282,7 @@ LL ~ match mutex1.lock().unwrap().s.len() >= value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:398:11 + --> tests/ui/significant_drop_in_scrutinee.rs:403:11 | LL | match get_mutex_guard().s.len() > 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -301,7 +301,7 @@ LL ~ match value > 1 { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:417:11 + --> tests/ui/significant_drop_in_scrutinee.rs:422:11 | LL | match match i { | ___________^ @@ -334,7 +334,7 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:445:11 + --> tests/ui/significant_drop_in_scrutinee.rs:450:11 | LL | match if i > 1 { | ___________^ @@ -368,7 +368,7 @@ LL ~ match value | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:501:11 + --> tests/ui/significant_drop_in_scrutinee.rs:506:11 | LL | match s.lock().deref().deref() { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -386,7 +386,7 @@ LL ~ match (&value) { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:551:11 + --> tests/ui/significant_drop_in_scrutinee.rs:556:11 | LL | match mutex.lock().unwrap().i = i { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -405,7 +405,7 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:559:15 + --> tests/ui/significant_drop_in_scrutinee.rs:564:15 | LL | match i = mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -424,7 +424,7 @@ LL ~ match i = value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:567:11 + --> tests/ui/significant_drop_in_scrutinee.rs:572:11 | LL | match mutex.lock().unwrap().i += 1 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -443,7 +443,7 @@ LL ~ match () { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:575:16 + --> tests/ui/significant_drop_in_scrutinee.rs:580:16 | LL | match i += mutex.lock().unwrap().i { | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -462,7 +462,7 @@ LL ~ match i += value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:640:11 + --> tests/ui/significant_drop_in_scrutinee.rs:645:11 | LL | match rwlock.read().unwrap().to_number() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -478,7 +478,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:668:11 + --> tests/ui/significant_drop_in_scrutinee.rs:673:11 | LL | match mutex.lock().unwrap().foo() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -494,7 +494,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression - --> tests/ui/significant_drop_in_scrutinee.rs:731:11 + --> tests/ui/significant_drop_in_scrutinee.rs:736:11 | LL | match guard.take().len() { | ^^^^^^^^^^^^^^^^^^ @@ -510,7 +510,7 @@ LL ~ match value { | error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression - --> tests/ui/significant_drop_in_scrutinee.rs:757:16 + --> tests/ui/significant_drop_in_scrutinee.rs:762:16 | LL | for val in mutex.lock().unwrap().copy_old_lifetime() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -526,7 +526,7 @@ LL ~ for val in value { | error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression - --> tests/ui/significant_drop_in_scrutinee.rs:797:17 + --> tests/ui/significant_drop_in_scrutinee.rs:802:17 | LL | for val in [mutex.lock().unwrap()[0], 2] { | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -542,7 +542,7 @@ LL ~ for val in [value, 2] { | error: temporary with significant `Drop` in `if let` scrutinee will live until the end of the `if let` expression - --> tests/ui/significant_drop_in_scrutinee.rs:807:24 + --> tests/ui/significant_drop_in_scrutinee.rs:812:24 | LL | if let Some(val) = mutex.lock().unwrap().first().copied() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -558,7 +558,7 @@ LL ~ if let Some(val) = value { | error: temporary with significant `Drop` in `while let` scrutinee will live until the end of the `while let` expression - --> tests/ui/significant_drop_in_scrutinee.rs:823:27 + --> tests/ui/significant_drop_in_scrutinee.rs:828:27 | LL | while let Some(val) = mutex.lock().unwrap().pop() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/str_split.fixed b/tests/ui/str_split.fixed index 4f33241da7a..57a3c315a87 100644 --- a/tests/ui/str_split.fixed +++ b/tests/ui/str_split.fixed @@ -1,4 +1,5 @@ #![warn(clippy::str_split_at_newline)] +#![allow(clippy::needless_lifetimes)] use core::str::Split; use std::ops::Deref; diff --git a/tests/ui/str_split.rs b/tests/ui/str_split.rs index f24caa61c30..fcff036f264 100644 --- a/tests/ui/str_split.rs +++ b/tests/ui/str_split.rs @@ -1,4 +1,5 @@ #![warn(clippy::str_split_at_newline)] +#![allow(clippy::needless_lifetimes)] use core::str::Split; use std::ops::Deref; diff --git a/tests/ui/str_split.stderr b/tests/ui/str_split.stderr index ebe0d4ef4d3..7b560468f12 100644 --- a/tests/ui/str_split.stderr +++ b/tests/ui/str_split.stderr @@ -1,5 +1,5 @@ error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:59:13 + --> tests/ui/str_split.rs:60:13 | LL | let _ = s1.trim().split('\n'); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s1.lines()` @@ -8,55 +8,55 @@ LL | let _ = s1.trim().split('\n'); = help: to override `-D warnings` add `#[allow(clippy::str_split_at_newline)]` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:61:13 + --> tests/ui/str_split.rs:62:13 | LL | let _ = s1.trim().split("\n"); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s1.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:62:13 + --> tests/ui/str_split.rs:63:13 | LL | let _ = s1.trim().split("\r\n"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s1.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:65:13 + --> tests/ui/str_split.rs:66:13 | LL | let _ = s2.trim().split('\n'); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s2.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:67:13 + --> tests/ui/str_split.rs:68:13 | LL | let _ = s2.trim().split("\n"); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s2.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:68:13 + --> tests/ui/str_split.rs:69:13 | LL | let _ = s2.trim().split("\r\n"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s2.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:72:13 + --> tests/ui/str_split.rs:73:13 | LL | let _ = s3.trim().split('\n'); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s3.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:74:13 + --> tests/ui/str_split.rs:75:13 | LL | let _ = s3.trim().split("\n"); | ^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s3.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:75:13 + --> tests/ui/str_split.rs:76:13 | LL | let _ = s3.trim().split("\r\n"); | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `s3.lines()` error: using `str.trim().split()` with hard-coded newlines - --> tests/ui/str_split.rs:78:13 + --> tests/ui/str_split.rs:79:13 | LL | let _ = make_str!(s1).trim().split('\n'); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `str.lines()` instead: `make_str!(s1).lines()` diff --git a/tests/ui/temporary_assignment.rs b/tests/ui/temporary_assignment.rs index e2b982aeaf5..d269f91b9fa 100644 --- a/tests/ui/temporary_assignment.rs +++ b/tests/ui/temporary_assignment.rs @@ -1,4 +1,5 @@ #![warn(clippy::temporary_assignment)] +#![allow(clippy::needless_lifetimes)] use std::ops::{Deref, DerefMut}; diff --git a/tests/ui/temporary_assignment.stderr b/tests/ui/temporary_assignment.stderr index 1b6007f0b98..8c284594075 100644 --- a/tests/ui/temporary_assignment.stderr +++ b/tests/ui/temporary_assignment.stderr @@ -1,5 +1,5 @@ error: assignment to temporary - --> tests/ui/temporary_assignment.rs:47:5 + --> tests/ui/temporary_assignment.rs:48:5 | LL | Struct { field: 0 }.field = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | Struct { field: 0 }.field = 1; = help: to override `-D warnings` add `#[allow(clippy::temporary_assignment)]` error: assignment to temporary - --> tests/ui/temporary_assignment.rs:50:5 + --> tests/ui/temporary_assignment.rs:51:5 | LL | / MultiStruct { LL | | @@ -19,13 +19,13 @@ LL | | .field = 1; | |______________^ error: assignment to temporary - --> tests/ui/temporary_assignment.rs:56:5 + --> tests/ui/temporary_assignment.rs:57:5 | LL | ArrayStruct { array: [0] }.array[0] = 1; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: assignment to temporary - --> tests/ui/temporary_assignment.rs:58:5 + --> tests/ui/temporary_assignment.rs:59:5 | LL | (0, 0).0 = 1; | ^^^^^^^^^^^^ diff --git a/tests/ui/trait_duplication_in_bounds.fixed b/tests/ui/trait_duplication_in_bounds.fixed index 7e2663d734f..779431303ae 100644 --- a/tests/ui/trait_duplication_in_bounds.fixed +++ b/tests/ui/trait_duplication_in_bounds.fixed @@ -1,5 +1,6 @@ #![deny(clippy::trait_duplication_in_bounds)] #![allow(unused)] +#![feature(const_trait_impl)] use std::any::Any; @@ -144,6 +145,36 @@ fn f<P: Proj>(obj: &dyn Derived<P>) { Base::<()>::is_base(obj); } +// #13476 +trait Value<const N: usize> {} +fn const_generic<T: Value<0> + Value<1>>() {} + +// #11067 and #9626 +fn assoc_tys_generics<'a, 'b, T, U>() +where + T: IntoIterator<Item = ()> + IntoIterator<Item = i32>, + U: From<&'a str> + From<&'b [u16]>, +{ +} + +// #13476 +#[const_trait] +trait ConstTrait {} +const fn const_trait_bounds_good<T: ConstTrait + ~const ConstTrait>() {} + +const fn const_trait_bounds_bad<T: ~const ConstTrait>() {} +//~^ trait_duplication_in_bounds + +fn projections<T, U, V>() +where + U: ToOwned, + V: ToOwned, + T: IntoIterator<Item = U::Owned>, + //~^ trait_duplication_in_bounds + V: IntoIterator<Item = U::Owned> + IntoIterator<Item = V::Owned>, +{ +} + fn main() { let _x: fn(_) = f::<()>; let _x: fn(_) = f::<i32>; diff --git a/tests/ui/trait_duplication_in_bounds.rs b/tests/ui/trait_duplication_in_bounds.rs index fede1671a43..3e974dc0a8f 100644 --- a/tests/ui/trait_duplication_in_bounds.rs +++ b/tests/ui/trait_duplication_in_bounds.rs @@ -1,5 +1,6 @@ #![deny(clippy::trait_duplication_in_bounds)] #![allow(unused)] +#![feature(const_trait_impl)] use std::any::Any; @@ -144,6 +145,36 @@ fn f<P: Proj>(obj: &dyn Derived<P>) { Base::<()>::is_base(obj); } +// #13476 +trait Value<const N: usize> {} +fn const_generic<T: Value<0> + Value<1>>() {} + +// #11067 and #9626 +fn assoc_tys_generics<'a, 'b, T, U>() +where + T: IntoIterator<Item = ()> + IntoIterator<Item = i32>, + U: From<&'a str> + From<&'b [u16]>, +{ +} + +// #13476 +#[const_trait] +trait ConstTrait {} +const fn const_trait_bounds_good<T: ConstTrait + ~const ConstTrait>() {} + +const fn const_trait_bounds_bad<T: ~const ConstTrait + ~const ConstTrait>() {} +//~^ trait_duplication_in_bounds + +fn projections<T, U, V>() +where + U: ToOwned, + V: ToOwned, + T: IntoIterator<Item = U::Owned> + IntoIterator<Item = U::Owned>, + //~^ trait_duplication_in_bounds + V: IntoIterator<Item = U::Owned> + IntoIterator<Item = V::Owned>, +{ +} + fn main() { let _x: fn(_) = f::<()>; let _x: fn(_) = f::<i32>; diff --git a/tests/ui/trait_duplication_in_bounds.stderr b/tests/ui/trait_duplication_in_bounds.stderr index 78861fc16e8..0dd508e4745 100644 --- a/tests/ui/trait_duplication_in_bounds.stderr +++ b/tests/ui/trait_duplication_in_bounds.stderr @@ -1,5 +1,5 @@ error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:6:15 + --> tests/ui/trait_duplication_in_bounds.rs:7:15 | LL | fn bad_foo<T: Clone + Clone + Clone + Copy, U: Clone + Copy>(arg0: T, argo1: U) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` @@ -11,52 +11,64 @@ LL | #![deny(clippy::trait_duplication_in_bounds)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:12:8 + --> tests/ui/trait_duplication_in_bounds.rs:13:8 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:40:26 + --> tests/ui/trait_duplication_in_bounds.rs:41:26 | LL | trait BadSelfTraitBound: Clone + Clone + Clone { | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:47:15 + --> tests/ui/trait_duplication_in_bounds.rs:48:15 | LL | Self: Clone + Clone + Clone; | ^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:61:24 + --> tests/ui/trait_duplication_in_bounds.rs:62:24 | LL | trait BadTraitBound<T: Clone + Clone + Clone + Copy, U: Clone + Copy> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:68:12 + --> tests/ui/trait_duplication_in_bounds.rs:69:12 | LL | T: Clone + Clone + Clone + Copy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Clone + Copy` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:101:19 + --> tests/ui/trait_duplication_in_bounds.rs:102:19 | LL | fn bad_generic<T: GenericTrait<u64> + GenericTrait<u32> + GenericTrait<u64>>(arg0: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `GenericTrait<u64> + GenericTrait<u32>` error: these bounds contain repeated elements - --> tests/ui/trait_duplication_in_bounds.rs:109:22 + --> tests/ui/trait_duplication_in_bounds.rs:110:22 | LL | fn qualified_path<T: std::clone::Clone + Clone + foo::Clone>(arg0: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::clone::Clone + foo::Clone` error: this trait bound is already specified in trait declaration - --> tests/ui/trait_duplication_in_bounds.rs:117:33 + --> tests/ui/trait_duplication_in_bounds.rs:118:33 | LL | fn bad_trait_object(arg0: &(dyn Any + Send + Send)) { | ^^^^^^^^^^^^^^^^^ help: try: `Any + Send` -error: aborting due to 9 previous errors +error: these bounds contain repeated elements + --> tests/ui/trait_duplication_in_bounds.rs:165:36 + | +LL | const fn const_trait_bounds_bad<T: ~const ConstTrait + ~const ConstTrait>() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `~const ConstTrait` + +error: these where clauses contain repeated elements + --> tests/ui/trait_duplication_in_bounds.rs:172:8 + | +LL | T: IntoIterator<Item = U::Owned> + IntoIterator<Item = U::Owned>, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `IntoIterator<Item = U::Owned>` + +error: aborting due to 11 previous errors diff --git a/tests/ui/transmute_float_to_int.fixed b/tests/ui/transmute_float_to_int.fixed index 83814ca43b9..075a198918a 100644 --- a/tests/ui/transmute_float_to_int.fixed +++ b/tests/ui/transmute_float_to_int.fixed @@ -1,7 +1,7 @@ #![warn(clippy::transmute_float_to_int)] #![allow(clippy::missing_transmute_annotations)] -#![feature(f128, f128_const)] -#![feature(f16, f16_const)] +#![feature(f128)] +#![feature(f16)] fn float_to_int() { let _: u32 = unsafe { 1f32.to_bits() }; diff --git a/tests/ui/transmute_float_to_int.rs b/tests/ui/transmute_float_to_int.rs index 64d6e917203..12541b2f7cf 100644 --- a/tests/ui/transmute_float_to_int.rs +++ b/tests/ui/transmute_float_to_int.rs @@ -1,7 +1,7 @@ #![warn(clippy::transmute_float_to_int)] #![allow(clippy::missing_transmute_annotations)] -#![feature(f128, f128_const)] -#![feature(f16, f16_const)] +#![feature(f128)] +#![feature(f16)] fn float_to_int() { let _: u32 = unsafe { std::mem::transmute(1f32) }; diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed index e95054a7ccb..a4a3ca82e76 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -84,8 +84,14 @@ fn issue_10449() { } // Pointers cannot be cast to integers in const contexts +#[allow( + ptr_to_integer_transmute_in_consts, + reason = "This is tested in the compiler test suite" +)] const fn issue_12402<P>(ptr: *const P) { - unsafe { transmute::<*const i32, usize>(&42i32) }; - unsafe { transmute::<fn(*const P), usize>(issue_12402) }; - let _ = unsafe { transmute::<_, usize>(ptr) }; + // This test exists even though the compiler lints against it + // to test that clippy's transmute lints do not trigger on this. + unsafe { std::mem::transmute::<*const i32, usize>(&42i32) }; + unsafe { std::mem::transmute::<fn(*const P), usize>(issue_12402) }; + let _ = unsafe { std::mem::transmute::<_, usize>(ptr) }; } diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index e5fcdef7a1c..6aa8e384e26 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -84,8 +84,14 @@ fn issue_10449() { } // Pointers cannot be cast to integers in const contexts +#[allow( + ptr_to_integer_transmute_in_consts, + reason = "This is tested in the compiler test suite" +)] const fn issue_12402<P>(ptr: *const P) { - unsafe { transmute::<*const i32, usize>(&42i32) }; - unsafe { transmute::<fn(*const P), usize>(issue_12402) }; - let _ = unsafe { transmute::<_, usize>(ptr) }; + // This test exists even though the compiler lints against it + // to test that clippy's transmute lints do not trigger on this. + unsafe { std::mem::transmute::<*const i32, usize>(&42i32) }; + unsafe { std::mem::transmute::<fn(*const P), usize>(issue_12402) }; + let _ = unsafe { std::mem::transmute::<_, usize>(ptr) }; } diff --git a/tests/ui/unconditional_recursion.rs b/tests/ui/unconditional_recursion.rs index a51fc567f50..b8476a7088a 100644 --- a/tests/ui/unconditional_recursion.rs +++ b/tests/ui/unconditional_recursion.rs @@ -4,7 +4,8 @@ #![allow( clippy::partialeq_ne_impl, clippy::default_constructed_unit_structs, - clippy::only_used_in_recursion + clippy::only_used_in_recursion, + clippy::needless_lifetimes )] enum Foo { diff --git a/tests/ui/unconditional_recursion.stderr b/tests/ui/unconditional_recursion.stderr index 03c27bd8ed8..6a0078ee090 100644 --- a/tests/ui/unconditional_recursion.stderr +++ b/tests/ui/unconditional_recursion.stderr @@ -1,5 +1,5 @@ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:46:5 + --> tests/ui/unconditional_recursion.rs:47:5 | LL | fn ne(&self, other: &Self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -12,7 +12,7 @@ LL | self.ne(other) = help: to override `-D warnings` add `#[allow(unconditional_recursion)]` error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:50:5 + --> tests/ui/unconditional_recursion.rs:51:5 | LL | fn eq(&self, other: &Self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -23,7 +23,7 @@ LL | self.eq(other) = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:215:5 + --> tests/ui/unconditional_recursion.rs:216:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -34,7 +34,7 @@ LL | self.to_string() = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:225:5 + --> tests/ui/unconditional_recursion.rs:226:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -45,7 +45,7 @@ LL | x.to_string() = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:236:5 + --> tests/ui/unconditional_recursion.rs:237:5 | LL | fn to_string(&self) -> String { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing @@ -56,7 +56,7 @@ LL | (self as &Self).to_string() = help: a `loop` may express intention better if this is on purpose error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:16:5 + --> tests/ui/unconditional_recursion.rs:17:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -65,7 +65,7 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:18:9 + --> tests/ui/unconditional_recursion.rs:19:9 | LL | self != other | ^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL | self != other = help: to override `-D warnings` add `#[allow(clippy::unconditional_recursion)]` error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:20:5 + --> tests/ui/unconditional_recursion.rs:21:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -82,13 +82,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:22:9 + --> tests/ui/unconditional_recursion.rs:23:9 | LL | self == other | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:32:5 + --> tests/ui/unconditional_recursion.rs:33:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | self != &Foo2::B // no error here @@ -96,13 +96,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:33:9 + --> tests/ui/unconditional_recursion.rs:34:9 | LL | self != &Foo2::B // no error here | ^^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:35:5 + --> tests/ui/unconditional_recursion.rs:36:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | self == &Foo2::B // no error here @@ -110,13 +110,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:36:9 + --> tests/ui/unconditional_recursion.rs:37:9 | LL | self == &Foo2::B // no error here | ^^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:46:5 + --> tests/ui/unconditional_recursion.rs:47:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -125,13 +125,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:48:9 + --> tests/ui/unconditional_recursion.rs:49:9 | LL | self.ne(other) | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:50:5 + --> tests/ui/unconditional_recursion.rs:51:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -140,13 +140,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:52:9 + --> tests/ui/unconditional_recursion.rs:53:9 | LL | self.eq(other) | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:94:5 + --> tests/ui/unconditional_recursion.rs:95:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -155,13 +155,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:96:9 + --> tests/ui/unconditional_recursion.rs:97:9 | LL | other != self | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:98:5 + --> tests/ui/unconditional_recursion.rs:99:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -170,13 +170,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:100:9 + --> tests/ui/unconditional_recursion.rs:101:9 | LL | other == self | ^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:108:5 + --> tests/ui/unconditional_recursion.rs:109:5 | LL | / fn ne(&self, other: &Self) -> bool { LL | | @@ -185,13 +185,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:110:9 + --> tests/ui/unconditional_recursion.rs:111:9 | LL | other != other | ^^^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/unconditional_recursion.rs:110:9 + --> tests/ui/unconditional_recursion.rs:111:9 | LL | other != other | ^^^^^^^^^^^^^^ @@ -199,7 +199,7 @@ LL | other != other = note: `#[deny(clippy::eq_op)]` on by default error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:112:5 + --> tests/ui/unconditional_recursion.rs:113:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -208,19 +208,19 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:114:9 + --> tests/ui/unconditional_recursion.rs:115:9 | LL | other == other | ^^^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/unconditional_recursion.rs:114:9 + --> tests/ui/unconditional_recursion.rs:115:9 | LL | other == other | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:121:5 + --> tests/ui/unconditional_recursion.rs:122:5 | LL | / fn ne(&self, _other: &Self) -> bool { LL | | @@ -229,19 +229,19 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:123:9 + --> tests/ui/unconditional_recursion.rs:124:9 | LL | self != self | ^^^^^^^^^^^^ error: equal expressions as operands to `!=` - --> tests/ui/unconditional_recursion.rs:123:9 + --> tests/ui/unconditional_recursion.rs:124:9 | LL | self != self | ^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:125:5 + --> tests/ui/unconditional_recursion.rs:126:5 | LL | / fn eq(&self, _other: &Self) -> bool { LL | | @@ -250,19 +250,19 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:127:9 + --> tests/ui/unconditional_recursion.rs:128:9 | LL | self == self | ^^^^^^^^^^^^ error: equal expressions as operands to `==` - --> tests/ui/unconditional_recursion.rs:127:9 + --> tests/ui/unconditional_recursion.rs:128:9 | LL | self == self | ^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:153:13 + --> tests/ui/unconditional_recursion.rs:154:13 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -274,7 +274,7 @@ LL | impl_partial_eq!(S5); | -------------------- in this macro invocation | note: recursive call site - --> tests/ui/unconditional_recursion.rs:155:17 + --> tests/ui/unconditional_recursion.rs:156:17 | LL | self == other | ^^^^^^^^^^^^^ @@ -284,7 +284,7 @@ LL | impl_partial_eq!(S5); = note: this error originates in the macro `impl_partial_eq` (in Nightly builds, run with -Z macro-backtrace for more info) error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:182:5 + --> tests/ui/unconditional_recursion.rs:183:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -295,13 +295,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:186:9 + --> tests/ui/unconditional_recursion.rs:187:9 | LL | mine == theirs | ^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:251:5 + --> tests/ui/unconditional_recursion.rs:252:5 | LL | / fn new() -> Self { LL | | @@ -310,13 +310,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:253:9 + --> tests/ui/unconditional_recursion.rs:254:9 | LL | Self::default() | ^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:290:5 + --> tests/ui/unconditional_recursion.rs:291:5 | LL | / fn eq(&self, other: &Self) -> bool { LL | | @@ -327,13 +327,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:294:9 + --> tests/ui/unconditional_recursion.rs:295:9 | LL | mine.eq(theirs) | ^^^^^^^^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:361:5 + --> tests/ui/unconditional_recursion.rs:362:5 | LL | / fn from(f: BadFromTy1<'a>) -> Self { LL | | f.into() @@ -341,13 +341,13 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:362:9 + --> tests/ui/unconditional_recursion.rs:363:9 | LL | f.into() | ^^^^^^^^ error: function cannot return without recursing - --> tests/ui/unconditional_recursion.rs:370:5 + --> tests/ui/unconditional_recursion.rs:371:5 | LL | / fn from(f: BadFromTy2<'a>) -> Self { LL | | Into::into(f) @@ -355,7 +355,7 @@ LL | | } | |_____^ | note: recursive call site - --> tests/ui/unconditional_recursion.rs:371:9 + --> tests/ui/unconditional_recursion.rs:372:9 | LL | Into::into(f) | ^^^^^^^^^^^^^ diff --git a/tests/ui/unnecessary_literal_bound.fixed b/tests/ui/unnecessary_literal_bound.fixed new file mode 100644 index 00000000000..107e397466d --- /dev/null +++ b/tests/ui/unnecessary_literal_bound.fixed @@ -0,0 +1,65 @@ +#![warn(clippy::unnecessary_literal_bound)] + +struct Struct<'a> { + not_literal: &'a str, +} + +impl Struct<'_> { + // Should warn + fn returns_lit(&self) -> &'static str { + "Hello" + } + + // Should NOT warn + fn returns_non_lit(&self) -> &str { + self.not_literal + } + + // Should warn, does not currently + fn conditionally_returns_lit(&self, cond: bool) -> &str { + if cond { "Literal" } else { "also a literal" } + } + + // Should NOT warn + fn conditionally_returns_non_lit(&self, cond: bool) -> &str { + if cond { "Literal" } else { self.not_literal } + } + + // Should warn + fn contionally_returns_literals_explicit(&self, cond: bool) -> &'static str { + if cond { + return "Literal"; + } + + "also a literal" + } + + // Should NOT warn + fn conditionally_returns_non_lit_explicit(&self, cond: bool) -> &str { + if cond { + return self.not_literal; + } + + "Literal" + } +} + +trait ReturnsStr { + fn trait_method(&self) -> &str; +} + +impl ReturnsStr for u8 { + // Should warn, even though not useful without trait refinement + fn trait_method(&self) -> &'static str { + "Literal" + } +} + +impl ReturnsStr for Struct<'_> { + // Should NOT warn + fn trait_method(&self) -> &str { + self.not_literal + } +} + +fn main() {} diff --git a/tests/ui/unnecessary_literal_bound.rs b/tests/ui/unnecessary_literal_bound.rs new file mode 100644 index 00000000000..b371ff9d3a2 --- /dev/null +++ b/tests/ui/unnecessary_literal_bound.rs @@ -0,0 +1,65 @@ +#![warn(clippy::unnecessary_literal_bound)] + +struct Struct<'a> { + not_literal: &'a str, +} + +impl Struct<'_> { + // Should warn + fn returns_lit(&self) -> &str { + "Hello" + } + + // Should NOT warn + fn returns_non_lit(&self) -> &str { + self.not_literal + } + + // Should warn, does not currently + fn conditionally_returns_lit(&self, cond: bool) -> &str { + if cond { "Literal" } else { "also a literal" } + } + + // Should NOT warn + fn conditionally_returns_non_lit(&self, cond: bool) -> &str { + if cond { "Literal" } else { self.not_literal } + } + + // Should warn + fn contionally_returns_literals_explicit(&self, cond: bool) -> &str { + if cond { + return "Literal"; + } + + "also a literal" + } + + // Should NOT warn + fn conditionally_returns_non_lit_explicit(&self, cond: bool) -> &str { + if cond { + return self.not_literal; + } + + "Literal" + } +} + +trait ReturnsStr { + fn trait_method(&self) -> &str; +} + +impl ReturnsStr for u8 { + // Should warn, even though not useful without trait refinement + fn trait_method(&self) -> &str { + "Literal" + } +} + +impl ReturnsStr for Struct<'_> { + // Should NOT warn + fn trait_method(&self) -> &str { + self.not_literal + } +} + +fn main() {} diff --git a/tests/ui/unnecessary_literal_bound.stderr b/tests/ui/unnecessary_literal_bound.stderr new file mode 100644 index 00000000000..512b2f9a0af --- /dev/null +++ b/tests/ui/unnecessary_literal_bound.stderr @@ -0,0 +1,23 @@ +error: returning a `str` unnecessarily tied to the lifetime of arguments + --> tests/ui/unnecessary_literal_bound.rs:9:30 + | +LL | fn returns_lit(&self) -> &str { + | ^^^^ help: try: `&'static str` + | + = note: `-D clippy::unnecessary-literal-bound` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::unnecessary_literal_bound)]` + +error: returning a `str` unnecessarily tied to the lifetime of arguments + --> tests/ui/unnecessary_literal_bound.rs:29:68 + | +LL | fn contionally_returns_literals_explicit(&self, cond: bool) -> &str { + | ^^^^ help: try: `&'static str` + +error: returning a `str` unnecessarily tied to the lifetime of arguments + --> tests/ui/unnecessary_literal_bound.rs:53:31 + | +LL | fn trait_method(&self) -> &str { + | ^^^^ help: try: `&'static str` + +error: aborting due to 3 previous errors + diff --git a/tests/ui/unused_async.rs b/tests/ui/unused_async.rs index 7ec8a3adb4c..838d6f0aa97 100644 --- a/tests/ui/unused_async.rs +++ b/tests/ui/unused_async.rs @@ -55,6 +55,22 @@ mod issue9695 { } } +mod issue13466 { + use std::future::Future; + + struct Wrap<F>(F); + impl<F> From<F> for Wrap<F> { + fn from(f: F) -> Self { + Self(f) + } + } + fn takes_fut<F: Fn() -> Fut, Fut: Future>(_: Wrap<F>) {} + async fn unused_async() {} + fn fp() { + takes_fut(unused_async.into()); + } +} + async fn foo() -> i32 { //~^ ERROR: unused `async` for function with no await statements 4 diff --git a/tests/ui/unused_async.stderr b/tests/ui/unused_async.stderr index 337c650e029..4811df63658 100644 --- a/tests/ui/unused_async.stderr +++ b/tests/ui/unused_async.stderr @@ -27,7 +27,7 @@ LL | async fn f3() {} = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:58:1 + --> tests/ui/unused_async.rs:74:1 | LL | / async fn foo() -> i32 { LL | | @@ -38,7 +38,7 @@ LL | | } = help: consider removing the `async` from this function error: unused `async` for function with no await statements - --> tests/ui/unused_async.rs:70:5 + --> tests/ui/unused_async.rs:86:5 | LL | / async fn unused(&self) -> i32 { LL | | diff --git a/tests/ui/unwrap_or.fixed b/tests/ui/unwrap_or.fixed index e1a47fc7bd9..62bc1966da6 100644 --- a/tests/ui/unwrap_or.fixed +++ b/tests/ui/unwrap_or.fixed @@ -3,11 +3,11 @@ fn main() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); - //~^ ERROR: use of `unwrap_or` followed by a function call + //~^ ERROR: function call inside of `unwrap_or` //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` } fn new_lines() { let s = Some(String::from("test string")).unwrap_or_else(|| "Fail".to_string()).len(); - //~^ ERROR: use of `unwrap_or` followed by a function call + //~^ ERROR: function call inside of `unwrap_or` } diff --git a/tests/ui/unwrap_or.rs b/tests/ui/unwrap_or.rs index 914bfb939b8..e8e4b6b7168 100644 --- a/tests/ui/unwrap_or.rs +++ b/tests/ui/unwrap_or.rs @@ -3,11 +3,11 @@ fn main() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); - //~^ ERROR: use of `unwrap_or` followed by a function call + //~^ ERROR: function call inside of `unwrap_or` //~| NOTE: `-D clippy::or-fun-call` implied by `-D warnings` } fn new_lines() { let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); - //~^ ERROR: use of `unwrap_or` followed by a function call + //~^ ERROR: function call inside of `unwrap_or` } diff --git a/tests/ui/unwrap_or.stderr b/tests/ui/unwrap_or.stderr index 6aa0b9df29b..b712f8cf693 100644 --- a/tests/ui/unwrap_or.stderr +++ b/tests/ui/unwrap_or.stderr @@ -1,4 +1,4 @@ -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/unwrap_or.rs:5:47 | LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); @@ -7,7 +7,7 @@ LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()) = note: `-D clippy::or-fun-call` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::or_fun_call)]` -error: use of `unwrap_or` followed by a function call +error: function call inside of `unwrap_or` --> tests/ui/unwrap_or.rs:11:47 | LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len(); diff --git a/tests/ui/useful_asref.rs b/tests/ui/useful_asref.rs index a9f0170a79c..d17db9371ee 100644 --- a/tests/ui/useful_asref.rs +++ b/tests/ui/useful_asref.rs @@ -1,4 +1,5 @@ #![deny(clippy::useless_asref)] +#![allow(clippy::needless_lifetimes)] trait Trait { fn as_ptr(&self); diff --git a/tests/ui/zombie_processes.rs b/tests/ui/zombie_processes.rs index a2abc7fc3a1..b41bcce3f7f 100644 --- a/tests/ui/zombie_processes.rs +++ b/tests/ui/zombie_processes.rs @@ -131,6 +131,13 @@ fn main() { } x.wait().unwrap(); } + + { + let mut x = Command::new("").spawn().unwrap(); + std::thread::spawn(move || { + x.wait().unwrap(); + }); + } } fn process_child(c: Child) { diff --git a/tests/versioncheck.rs b/tests/versioncheck.rs index 68328333937..e29898f068d 100644 --- a/tests/versioncheck.rs +++ b/tests/versioncheck.rs @@ -24,7 +24,6 @@ fn consistent_clippy_crate_versions() { let clippy_version = read_version("Cargo.toml"); let paths = [ - "declare_clippy_lint/Cargo.toml", "clippy_config/Cargo.toml", "clippy_lints/Cargo.toml", "clippy_utils/Cargo.toml", |
