Skip to content

Commit

Permalink
Fixup clippy tests
Browse files Browse the repository at this point in the history
- Don't depend on the fact that `!` falls back to `()` and so panic-ish things
  can be used in `-> impl ImplementedForUnit` functions
- Remove `;` after `unimplemented!()` calls (not necessarily an issue, but there
  are plans to restrict this in future editions)
  • Loading branch information
WaffleLapkin committed May 21, 2024
1 parent 7c91091 commit cedada8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
61 changes: 29 additions & 32 deletions src/tools/clippy/tests/ui/new_ret_no_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct T;
impl T {
// should not trigger lint
pub fn new() -> Self {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -83,7 +83,7 @@ impl U {
// should trigger lint
pub fn new() -> u32 {
//~^ ERROR: methods called `new` usually return `Self`
unimplemented!();
unimplemented!()
}
}

Expand All @@ -93,7 +93,7 @@ impl V {
// should trigger lint
pub fn new(_: String) -> u32 {
//~^ ERROR: methods called `new` usually return `Self`
unimplemented!();
unimplemented!()
}
}

Expand All @@ -102,7 +102,7 @@ struct TupleReturnerOk;
impl TupleReturnerOk {
// should not trigger lint
pub fn new() -> (Self, u32) {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -111,7 +111,7 @@ struct TupleReturnerOk2;
impl TupleReturnerOk2 {
// should not trigger lint (it doesn't matter which element in the tuple is Self)
pub fn new() -> (u32, Self) {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -120,7 +120,7 @@ struct TupleReturnerOk3;
impl TupleReturnerOk3 {
// should not trigger lint (tuple can contain multiple Self)
pub fn new() -> (Self, Self) {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -130,7 +130,7 @@ impl TupleReturnerBad {
// should trigger lint
pub fn new() -> (u32, u32) {
//~^ ERROR: methods called `new` usually return `Self`
unimplemented!();
unimplemented!()
}
}

Expand All @@ -139,7 +139,7 @@ struct MutPointerReturnerOk;
impl MutPointerReturnerOk {
// should not trigger lint
pub fn new() -> *mut Self {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -148,7 +148,7 @@ struct ConstPointerReturnerOk2;
impl ConstPointerReturnerOk2 {
// should not trigger lint
pub fn new() -> *const Self {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -158,7 +158,7 @@ impl MutPointerReturnerBad {
// should trigger lint
pub fn new() -> *mut V {
//~^ ERROR: methods called `new` usually return `Self`
unimplemented!();
unimplemented!()
}
}

Expand All @@ -167,7 +167,7 @@ struct GenericReturnerOk;
impl GenericReturnerOk {
// should not trigger lint
pub fn new() -> Option<Self> {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -177,7 +177,7 @@ impl GenericReturnerBad {
// should trigger lint
pub fn new() -> Option<u32> {
//~^ ERROR: methods called `new` usually return `Self`
unimplemented!();
unimplemented!()
}
}

Expand All @@ -186,7 +186,7 @@ struct NestedReturnerOk;
impl NestedReturnerOk {
// should not trigger lint
pub fn new() -> (Option<Self>, u32) {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -195,7 +195,7 @@ struct NestedReturnerOk2;
impl NestedReturnerOk2 {
// should not trigger lint
pub fn new() -> ((Self, u32), u32) {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -204,7 +204,7 @@ struct NestedReturnerOk3;
impl NestedReturnerOk3 {
// should not trigger lint
pub fn new() -> Option<(Self, u32)> {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -215,7 +215,7 @@ struct WithLifetime<'a> {
impl<'a> WithLifetime<'a> {
// should not trigger the lint, because the lifetimes are different
pub fn new<'b: 'a>(s: &'b str) -> WithLifetime<'b> {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -236,7 +236,7 @@ mod issue5435 {
impl TraitRet for StructRet {
// should not trigger lint as we are in the impl block
fn new() -> String {
unimplemented!();
unimplemented!()
}
}

Expand All @@ -252,7 +252,7 @@ mod issue5435 {
where
Self: Sized,
{
unimplemented!();
unimplemented!()
}
}

Expand All @@ -262,7 +262,7 @@ mod issue5435 {
where
Self: Sized,
{
unimplemented!();
unimplemented!()
}
}

Expand All @@ -272,15 +272,15 @@ mod issue5435 {
where
Self: Sized,
{
unimplemented!();
unimplemented!()
}
}

trait TupleReturnerBad {
// should trigger lint
fn new() -> (u32, u32) {
//~^ ERROR: methods called `new` usually return `Self`
unimplemented!();
unimplemented!()
}
}

Expand All @@ -290,7 +290,7 @@ mod issue5435 {
where
Self: Sized,
{
unimplemented!();
unimplemented!()
}
}

Expand All @@ -300,15 +300,15 @@ mod issue5435 {
where
Self: Sized,
{
unimplemented!();
unimplemented!()
}
}

trait MutPointerReturnerBad {
// should trigger lint
fn new() -> *mut V {
//~^ ERROR: methods called `new` usually return `Self`
unimplemented!();
unimplemented!()
}
}

Expand All @@ -318,7 +318,7 @@ mod issue5435 {
where
Self: Sized,
{
unimplemented!();
unimplemented!()
}
}

Expand All @@ -328,7 +328,7 @@ mod issue5435 {
where
Self: Sized,
{
unimplemented!();
unimplemented!()
}
}

Expand All @@ -338,7 +338,7 @@ mod issue5435 {
where
Self: Sized,
{
unimplemented!();
unimplemented!()
}
}

Expand All @@ -348,7 +348,7 @@ mod issue5435 {
where
Self: Sized,
{
unimplemented!();
unimplemented!()
}
}
}
Expand Down Expand Up @@ -390,9 +390,7 @@ mod issue7344 {

impl<T> RetImplTraitSelf2<T> {
// should not trigger lint
fn new(t: T) -> impl Trait2<(), Self> {
unimplemented!()
}
fn new(t: T) -> impl Trait2<(), Self> {}
}

struct RetImplTraitNoSelf2<T>(T);
Expand All @@ -401,7 +399,6 @@ mod issue7344 {
// should trigger lint
fn new(t: T) -> impl Trait2<(), i32> {
//~^ ERROR: methods called `new` usually return `Self`
unimplemented!()
}
}

Expand Down
17 changes: 8 additions & 9 deletions src/tools/clippy/tests/ui/new_ret_no_self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error: methods called `new` usually return `Self`
|
LL | / pub fn new() -> u32 {
LL | |
LL | | unimplemented!();
LL | | unimplemented!()
LL | | }
| |_____^

Expand All @@ -25,7 +25,7 @@ error: methods called `new` usually return `Self`
|
LL | / pub fn new(_: String) -> u32 {
LL | |
LL | | unimplemented!();
LL | | unimplemented!()
LL | | }
| |_____^

Expand All @@ -34,7 +34,7 @@ error: methods called `new` usually return `Self`
|
LL | / pub fn new() -> (u32, u32) {
LL | |
LL | | unimplemented!();
LL | | unimplemented!()
LL | | }
| |_____^

Expand All @@ -43,7 +43,7 @@ error: methods called `new` usually return `Self`
|
LL | / pub fn new() -> *mut V {
LL | |
LL | | unimplemented!();
LL | | unimplemented!()
LL | | }
| |_____^

Expand All @@ -52,7 +52,7 @@ error: methods called `new` usually return `Self`
|
LL | / pub fn new() -> Option<u32> {
LL | |
LL | | unimplemented!();
LL | | unimplemented!()
LL | | }
| |_____^

Expand All @@ -73,7 +73,7 @@ error: methods called `new` usually return `Self`
|
LL | / fn new() -> (u32, u32) {
LL | |
LL | | unimplemented!();
LL | | unimplemented!()
LL | | }
| |_________^

Expand All @@ -82,7 +82,7 @@ error: methods called `new` usually return `Self`
|
LL | / fn new() -> *mut V {
LL | |
LL | | unimplemented!();
LL | | unimplemented!()
LL | | }
| |_________^

Expand All @@ -96,11 +96,10 @@ LL | | }
| |_________^

error: methods called `new` usually return `Self`
--> tests/ui/new_ret_no_self.rs:402:9
--> tests/ui/new_ret_no_self.rs:400:9
|
LL | / fn new(t: T) -> impl Trait2<(), i32> {
LL | |
LL | | unimplemented!()
LL | | }
| |_________^

Expand Down

0 comments on commit cedada8

Please sign in to comment.