fix existing clippy tests

This commit is contained in:
Max Baumann 2022-03-27 14:41:09 +02:00
parent 528ada958b
commit 9be3945be7
50 changed files with 109 additions and 107 deletions

View file

@ -34,7 +34,7 @@ declare_clippy_lint! {
///
/// ### Example
/// ```rust
/// struct Foo {}
/// struct Foo;
/// impl Foo {
/// fn new() -> Foo {
/// Foo {}
@ -43,7 +43,7 @@ declare_clippy_lint! {
/// ```
/// could be
/// ```rust
/// struct Foo {}
/// struct Foo;
/// impl Foo {
/// fn new() -> Self {
/// Self {}

View file

@ -4,6 +4,6 @@ struct S {
a: bool,
}
struct Foo {}
struct Foo;
fn main() {}

View file

@ -2,7 +2,7 @@
use std::string::String;
struct TestStruct {}
struct TestStruct;
impl TestStruct {
fn ends_with(self, arg: &str) {}

View file

@ -8,7 +8,7 @@ pub struct Bar {
}
#[derive(Eq, PartialEq, Debug, Hash)]
pub struct Foo {}
pub struct Foo;
#[allow(clippy::implicit_hasher)]
// This should not cause a "cannot relate bound region" ICE.

View file

@ -4,7 +4,7 @@
#![warn(clippy::use_self)]
#![allow(dead_code)]
struct Foo {}
struct Foo;
impl Foo {
fn new() -> Self {

View file

@ -7,7 +7,7 @@ trait Trait {
fn broken() -> Self::Ty;
}
struct Foo {}
struct Foo;
impl Trait for Foo {
type Ty = Foo;

View file

@ -3,7 +3,7 @@
trait Foo {}
struct Bar {}
struct Bar;
struct Baz<'a> {
bar: &'a Bar,

View file

@ -6,6 +6,6 @@ pub fn foo(bar: *const u8) {
// Regression test for https://github.com/rust-lang/rust-clippy/issues/4917
/// <foo
struct A {}
struct A;
fn main() {}

View file

@ -134,7 +134,7 @@ mod enum_ctor {
}
mod method_calls {
struct StructForMethodCallTest {}
struct StructForMethodCallTest;
impl StructForMethodCallTest {
fn concrete_arg(&self, f: f64) {}

View file

@ -134,7 +134,7 @@ mod enum_ctor {
}
mod method_calls {
struct StructForMethodCallTest {}
struct StructForMethodCallTest;
impl StructForMethodCallTest {
fn concrete_arg(&self, f: f64) {}

View file

@ -133,7 +133,7 @@ mod enum_ctor {
}
mod method_calls {
struct StructForMethodCallTest {}
struct StructForMethodCallTest;
impl StructForMethodCallTest {
fn concrete_arg(&self, x: i32) {}

View file

@ -133,7 +133,7 @@ mod enum_ctor {
}
mod method_calls {
struct StructForMethodCallTest {}
struct StructForMethodCallTest;
impl StructForMethodCallTest {
fn concrete_arg(&self, x: i32) {}

View file

@ -5,7 +5,7 @@ use std::mem::{drop, forget};
use std::vec::Vec;
#[derive(Copy, Clone)]
struct SomeStruct {}
struct SomeStruct;
struct AnotherStruct {
x: u8,

View file

@ -20,7 +20,7 @@ fn h(_: bool, _: bool, _: bool) {}
fn e(_: S, _: S, _: Box<S>, _: Vec<u32>) {}
fn t(_: S, _: S, _: Box<S>, _: Vec<u32>, _: bool, _: bool, _: bool, _: bool) {}
struct S {}
struct S;
trait Trait {
fn f(_: bool, _: bool, _: bool, _: bool);
fn g(_: bool, _: bool, _: bool, _: Vec<u32>);

View file

@ -30,7 +30,7 @@ where
}
#[derive(Copy, Clone)]
struct Kitten {}
struct Kitten;
impl Kitten {
// badly named method
fn to_vec(self) -> Kitten {
@ -44,7 +44,7 @@ impl Borrow<BorrowedKitten> for Kitten {
}
}
struct BorrowedKitten {}
struct BorrowedKitten;
impl ToOwned for BorrowedKitten {
type Owned = Kitten;
fn to_owned(&self) -> Kitten {

View file

@ -3,7 +3,7 @@
#![warn(clippy::iter_nth_zero)]
use std::collections::HashSet;
struct Foo {}
struct Foo;
impl Foo {
fn nth(&self, index: usize) -> usize {

View file

@ -3,7 +3,7 @@
#![warn(clippy::iter_nth_zero)]
use std::collections::HashSet;
struct Foo {}
struct Foo;
impl Foo {
fn nth(&self, index: usize) -> usize {

View file

@ -37,7 +37,7 @@ pub trait PubLargeTypeDevourer {
fn devoure_array_in_public(&self, array: [u8; 6666]);
}
struct S {}
struct S;
impl LargeTypeDevourer for S {
fn devoure_array(&self, array: [u8; 6666]) {
todo!();

View file

@ -88,7 +88,7 @@ mod no_lint_if_stmt_borrows {
ret
}
struct Bar {}
struct Bar;
impl Bar {
fn new() -> Self {

View file

@ -26,7 +26,7 @@ fn h() -> u32 {
0
}
struct S {}
struct S;
impl S {
#[must_use]

View file

@ -38,7 +38,7 @@ async fn already_async() -> impl Future<Output = i32> {
async { 42 }
}
struct S {}
struct S;
impl S {
async fn inh_fut() -> i32 {
// NOTE: this code is here just to check that the indentation is correct in the suggested fix

View file

@ -52,7 +52,7 @@ async fn already_async() -> impl Future<Output = i32> {
async { 42 }
}
struct S {}
struct S;
impl S {
fn inh_fut() -> impl Future<Output = i32> {
async {

View file

@ -78,7 +78,7 @@ fn result_unwrap_or() {
(Ok(1) as Result<i32, &str>).unwrap_or(42);
// method call case, suggestion must not surround Result expr `s.method()` with parentheses
struct S {}
struct S;
impl S {
fn method(self) -> Option<i32> {
Some(42)

View file

@ -102,7 +102,7 @@ fn result_unwrap_or() {
};
// method call case, suggestion must not surround Result expr `s.method()` with parentheses
struct S {}
struct S;
impl S {
fn method(self) -> Option<i32> {
Some(42)

View file

@ -1,5 +1,5 @@
#![allow(unused)]
struct Mappable {}
struct Mappable;
impl Mappable {
pub fn map(&self) {}

View file

@ -99,7 +99,7 @@ pub fn manual_range_contains() {
}
pub fn use_self() {
struct Foo {}
struct Foo;
impl Foo {
fn new() -> Foo {

View file

@ -7,8 +7,8 @@
type Typedef = String;
pub type PubTypedef = String;
struct Foo {} // ok
pub struct PubFoo {} // ok
struct Foo; // ok
pub struct PubFoo; // ok
enum FooE {} // ok
pub enum PubFooE {} // ok
@ -63,4 +63,4 @@ impl PubFoo {
// do not lint this since users cannot control the external code
#[derive(Debug)]
pub struct S {}
pub struct S;

View file

@ -7,7 +7,7 @@ mod foo {
pub fn foo() {}
pub fn foo_bar() {}
pub fn bar_foo() {}
pub struct FooCake {}
pub struct FooCake;
pub enum CakeFoo {}
pub struct Foo7Bar;

View file

@ -14,7 +14,7 @@ mod issue_6089 {
fn test(self: &Self);
}
struct S1 {}
struct S1;
impl T1 for S1 {
fn test(self: &Self) {}
@ -32,7 +32,7 @@ mod issue_6089 {
fn call_with_mut_self(&mut self);
}
struct S2 {}
struct S2;
// The method's signature will be expanded to:
// fn call_with_mut_self<'life0>(self: &'life0 mut Self) {}

View file

@ -268,7 +268,7 @@ mod issue4291 {
mod issue2944 {
trait Foo {}
struct Bar {}
struct Bar;
struct Baz<'a> {
bar: &'a Bar,
}

View file

@ -68,7 +68,7 @@ impl FnOnce<(&str,)> for GreetStruct1 {
}
}
struct GreetStruct2();
struct GreetStruct2;
impl FnOnce<(&str,)> for GreetStruct2 {
type Output = ();
@ -78,7 +78,7 @@ impl FnOnce<(&str,)> for GreetStruct2 {
}
}
struct GreetStruct3 {}
struct GreetStruct3;
impl FnOnce<(&str,)> for GreetStruct3 {
type Output = ();

View file

@ -3,7 +3,7 @@
#![warn(clippy::or_then_unwrap)]
#![allow(clippy::map_identity)]
struct SomeStruct {}
struct SomeStruct;
impl SomeStruct {
fn or(self, _: Option<Self>) -> Self {
self
@ -11,7 +11,7 @@ impl SomeStruct {
fn unwrap(&self) {}
}
struct SomeOtherStruct {}
struct SomeOtherStruct;
impl SomeOtherStruct {
fn or(self) -> Self {
self

View file

@ -3,7 +3,7 @@
#![warn(clippy::or_then_unwrap)]
#![allow(clippy::map_identity)]
struct SomeStruct {}
struct SomeStruct;
impl SomeStruct {
fn or(self, _: Option<Self>) -> Self {
self
@ -11,7 +11,7 @@ impl SomeStruct {
fn unwrap(&self) {}
}
struct SomeOtherStruct {}
struct SomeOtherStruct;
impl SomeOtherStruct {
fn or(self) -> Self {
self

View file

@ -112,7 +112,7 @@ mod issue_5644 {
) {
}
struct S {}
struct S;
impl S {
fn allowed(
#[allow(clippy::ptr_arg)] _v: &Vec<u32>,

View file

@ -66,7 +66,7 @@ impl std::fmt::Display for D {
// Check for use of self as Display, in Display impl
// Triggers on direct use of self
struct G {}
struct G;
impl std::fmt::Display for G {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@ -75,7 +75,7 @@ impl std::fmt::Display for G {
}
// Triggers on reference to self
struct H {}
struct H;
impl std::fmt::Display for H {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@ -90,7 +90,7 @@ impl std::fmt::Debug for H {
}
// Triggers on multiple reference to self
struct H2 {}
struct H2;
impl std::fmt::Display for H2 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@ -99,7 +99,7 @@ impl std::fmt::Display for H2 {
}
// Doesn't trigger on correct deref
struct I {}
struct I;
impl std::ops::Deref for I {
type Target = str;
@ -122,7 +122,7 @@ impl std::fmt::Debug for I {
}
// Doesn't trigger on multiple correct deref
struct I2 {}
struct I2;
impl std::ops::Deref for I2 {
type Target = str;
@ -139,7 +139,7 @@ impl std::fmt::Display for I2 {
}
// Doesn't trigger on multiple correct deref
struct I3 {}
struct I3;
impl std::ops::Deref for I3 {
type Target = str;
@ -156,7 +156,7 @@ impl std::fmt::Display for I3 {
}
// Does trigger when deref resolves to self
struct J {}
struct J;
impl std::ops::Deref for J {
type Target = str;
@ -178,7 +178,7 @@ impl std::fmt::Debug for J {
}
}
struct J2 {}
struct J2;
impl std::ops::Deref for J2 {
type Target = str;
@ -194,7 +194,7 @@ impl std::fmt::Display for J2 {
}
}
struct J3 {}
struct J3;
impl std::ops::Deref for J3 {
type Target = str;
@ -210,7 +210,7 @@ impl std::fmt::Display for J3 {
}
}
struct J4 {}
struct J4;
impl std::ops::Deref for J4 {
type Target = str;
@ -227,7 +227,7 @@ impl std::fmt::Display for J4 {
}
// Doesn't trigger on Debug from Display
struct K {}
struct K;
impl std::fmt::Debug for K {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
@ -242,7 +242,7 @@ impl std::fmt::Display for K {
}
// Doesn't trigger on Display from Debug
struct K2 {}
struct K2;
impl std::fmt::Debug for K2 {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {

View file

@ -3,7 +3,7 @@
#![allow(clippy::blacklisted_name, unused_variables, dead_code)]
#![allow(unused_imports)]
pub struct MyStruct {}
pub struct MyStruct;
pub struct SubT<T> {
foo: T,

View file

@ -4,7 +4,7 @@
#![allow(clippy::blacklisted_name, unused_variables, dead_code)]
#![allow(unused_imports)]
pub struct MyStruct {}
pub struct MyStruct;
pub struct SubT<T> {
foo: T,

View file

@ -3,7 +3,7 @@
#![allow(unused)]
#[derive(Debug)]
struct Foo {}
struct Foo;
const VAR_ONE: &str = "Test constant #1"; // ERROR Consider removing 'static.

View file

@ -3,7 +3,7 @@
#![allow(unused)]
#[derive(Debug)]
struct Foo {}
struct Foo;
const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.

View file

@ -120,7 +120,7 @@ fn main() {
}
// Fix #5979
#[derive(Clone)]
struct S {}
struct S;
trait T {}
impl T for S {}

View file

@ -62,7 +62,7 @@ trait BadTrait: Default + Clone {
}
#[derive(Default, Clone)]
struct Life {}
struct Life;
impl T for Life {
// this should not warn
@ -85,7 +85,7 @@ trait Iter: Iterator {
}
}
struct Foo {}
struct Foo;
trait FooIter: Iterator<Item = Foo> {
fn bar()

View file

@ -2,12 +2,13 @@
#![warn(clippy::unit_like_struct_brackets)]
#![allow(dead_code)]
pub struct MyEmptyStruct; // should trigger lint
struct MyEmptyTupleStruct; // should trigger lint
pub struct MyEmptyStruct; // should trigger lint
struct MyEmptyTupleStruct; // should trigger lint
struct MyStruct { // should not trigger lint
struct MyStruct {
// should not trigger lint
field: u8,
}
struct MyTupleStruct(usize, String); // should not trigger lint
struct MyTupleStruct(usize, String); // should not trigger lint
fn main() {}

View file

@ -2,12 +2,13 @@
#![warn(clippy::unit_like_struct_brackets)]
#![allow(dead_code)]
pub struct MyEmptyStruct {} // should trigger lint
struct MyEmptyTupleStruct(); // should trigger lint
pub struct MyEmptyStruct {} // should trigger lint
struct MyEmptyTupleStruct(); // should trigger lint
struct MyStruct { // should not trigger lint
struct MyStruct {
// should not trigger lint
field: u8,
}
struct MyTupleStruct(usize, String); // should not trigger lint
struct MyTupleStruct(usize, String); // should not trigger lint
fn main() {}

View file

@ -6,7 +6,7 @@ extern crate serde;
use serde::Deserialize;
#[derive(Deserialize)]
pub struct A {}
pub struct A;
impl A {
pub unsafe fn new(_a: i32, _b: i32) -> Self {
Self {}
@ -14,13 +14,13 @@ impl A {
}
#[derive(Deserialize)]
pub struct B {}
pub struct B;
impl B {
pub unsafe fn unsafe_method(&self) {}
}
#[derive(Deserialize)]
pub struct C {}
pub struct C;
impl C {
pub fn unsafe_block(&self) {
unsafe {}
@ -28,7 +28,7 @@ impl C {
}
#[derive(Deserialize)]
pub struct D {}
pub struct D;
impl D {
pub fn inner_unsafe_fn(&self) {
unsafe fn inner() {}
@ -36,7 +36,7 @@ impl D {
}
// Does not derive `Deserialize`, should be ignored
pub struct E {}
pub struct E;
impl E {
pub unsafe fn new(_a: i32, _b: i32) -> Self {
Self {}
@ -55,12 +55,12 @@ impl E {
// Does not have methods using `unsafe`, should be ignored
#[derive(Deserialize)]
pub struct F {}
pub struct F;
// Check that we honor the `allow` attribute on the ADT
#[allow(clippy::unsafe_derive_deserialize)]
#[derive(Deserialize)]
pub struct G {}
pub struct G;
impl G {
pub fn unsafe_block(&self) {
unsafe {}

View file

@ -14,8 +14,8 @@ use std::cell::UnsafeCell as Dangerunsafe;
use std::cell::UnsafeCell as Bombsawayunsafe;
mod mod_with_some_unsafe_things {
pub struct Safe {}
pub struct Unsafe {}
pub struct Safe;
pub struct Unsafe;
}
use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety;

View file

@ -5,7 +5,7 @@ mod unused_self {
use std::pin::Pin;
use std::sync::{Arc, Mutex};
struct A {}
struct A;
impl A {
fn unused_self_move(self) {}
@ -27,7 +27,7 @@ mod unused_self {
}
mod unused_self_allow {
struct A {}
struct A;
impl A {
// shouldn't trigger
@ -35,7 +35,7 @@ mod unused_self_allow {
fn unused_self_move(self) {}
}
struct B {}
struct B;
// shouldn't trigger
#[allow(clippy::unused_self)]
@ -43,7 +43,7 @@ mod unused_self_allow {
fn unused_self_move(self) {}
}
struct C {}
struct C;
#[allow(clippy::unused_self)]
impl C {
@ -120,7 +120,7 @@ mod used_self {
mod not_applicable {
use std::fmt;
struct A {}
struct A;
impl fmt::Debug for A {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

View file

@ -16,7 +16,7 @@ extern crate proc_macro_derive;
fn main() {}
mod use_self {
struct Foo {}
struct Foo;
impl Foo {
fn new() -> Self {
@ -35,7 +35,7 @@ mod use_self {
}
mod better {
struct Foo {}
struct Foo;
impl Foo {
fn new() -> Self {
@ -123,7 +123,7 @@ mod macros {
};
}
struct Foo {}
struct Foo;
impl Foo {
use_self_expand!(); // Should not lint in local macros
@ -134,7 +134,7 @@ mod macros {
}
mod nesting {
struct Foo {}
struct Foo;
impl Foo {
fn foo() {
#[allow(unused_imports)]
@ -209,7 +209,7 @@ mod issue3410 {
#[allow(clippy::no_effect, path_statements)]
mod rustfix {
mod nested {
pub struct A {}
pub struct A;
}
impl nested::A {
@ -227,7 +227,7 @@ mod rustfix {
}
mod issue3567 {
struct TestStruct {}
struct TestStruct;
impl TestStruct {
fn from_something() -> Self {
Self {}
@ -248,7 +248,7 @@ mod issue3567 {
mod paths_created_by_lowering {
use std::ops::Range;
struct S {}
struct S;
impl S {
const A: usize = 0;
@ -382,7 +382,7 @@ mod issue4305 {
}
mod lint_at_item_level {
struct Foo {}
struct Foo;
#[allow(clippy::use_self)]
impl Foo {
@ -400,7 +400,7 @@ mod lint_at_item_level {
}
mod lint_at_impl_item_level {
struct Foo {}
struct Foo;
impl Foo {
#[allow(clippy::use_self)]
@ -433,8 +433,8 @@ mod issue4734 {
mod nested_paths {
use std::convert::Into;
mod submod {
pub struct B {}
pub struct C {}
pub struct B;
pub struct C;
impl Into<C> for B {
fn into(self) -> C {

View file

@ -16,7 +16,7 @@ extern crate proc_macro_derive;
fn main() {}
mod use_self {
struct Foo {}
struct Foo;
impl Foo {
fn new() -> Foo {
@ -35,7 +35,7 @@ mod use_self {
}
mod better {
struct Foo {}
struct Foo;
impl Foo {
fn new() -> Self {
@ -123,7 +123,7 @@ mod macros {
};
}
struct Foo {}
struct Foo;
impl Foo {
use_self_expand!(); // Should not lint in local macros
@ -134,7 +134,7 @@ mod macros {
}
mod nesting {
struct Foo {}
struct Foo;
impl Foo {
fn foo() {
#[allow(unused_imports)]
@ -209,7 +209,7 @@ mod issue3410 {
#[allow(clippy::no_effect, path_statements)]
mod rustfix {
mod nested {
pub struct A {}
pub struct A;
}
impl nested::A {
@ -227,7 +227,7 @@ mod rustfix {
}
mod issue3567 {
struct TestStruct {}
struct TestStruct;
impl TestStruct {
fn from_something() -> Self {
Self {}
@ -248,7 +248,7 @@ mod issue3567 {
mod paths_created_by_lowering {
use std::ops::Range;
struct S {}
struct S;
impl S {
const A: usize = 0;
@ -382,7 +382,7 @@ mod issue4305 {
}
mod lint_at_item_level {
struct Foo {}
struct Foo;
#[allow(clippy::use_self)]
impl Foo {
@ -400,7 +400,7 @@ mod lint_at_item_level {
}
mod lint_at_impl_item_level {
struct Foo {}
struct Foo;
impl Foo {
#[allow(clippy::use_self)]
@ -433,8 +433,8 @@ mod issue4734 {
mod nested_paths {
use std::convert::Into;
mod submod {
pub struct B {}
pub struct C {}
pub struct B;
pub struct C;
impl Into<C> for B {
fn into(self) -> C {

View file

@ -42,7 +42,7 @@ mod a {
mod b {
#[allow(dead_code)]
#[allow(unreachable_pub)]
pub struct C {}
pub struct C;
}
#[allow(unreachable_pub)]

View file

@ -42,7 +42,7 @@ mod a {
mod b {
#[allow(dead_code)]
#[allow(unreachable_pub)]
pub struct C {}
pub struct C;
}
#[allow(unreachable_pub)]