[implied_bounds_in_impls]: move to nursery and fix ICEs

This commit is contained in:
y21 2023-08-30 22:08:05 +02:00
parent b97eaab558
commit 563abf9651
7 changed files with 203 additions and 41 deletions

View file

@ -0,0 +1,25 @@
#![warn(clippy::implied_bounds_in_impls)]
use std::fmt::Debug;
use std::ops::*;
fn gen() -> impl PartialOrd + Debug {}
struct Bar {}
trait Foo<T = Self> {}
trait FooNested<T = Option<Self>> {}
impl Foo for Bar {}
impl FooNested for Bar {}
fn foo() -> impl Foo + FooNested {
Bar {}
}
fn test_impl_ops() -> impl Add + Sub + Mul + Div {
1
}
fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign {
1
}
fn main() {}

View file

@ -0,0 +1,25 @@
#![warn(clippy::implied_bounds_in_impls)]
use std::fmt::Debug;
use std::ops::*;
fn gen() -> impl PartialOrd + PartialEq + Debug {}
struct Bar {}
trait Foo<T = Self> {}
trait FooNested<T = Option<Self>> {}
impl Foo for Bar {}
impl FooNested for Bar {}
fn foo() -> impl Foo + FooNested {
Bar {}
}
fn test_impl_ops() -> impl Add + Sub + Mul + Div {
1
}
fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign {
1
}
fn main() {}

View file

@ -0,0 +1,15 @@
error: this bound is already specified as the supertrait of `PartialOrd`
--> $DIR/ice-11422.rs:6:31
|
LL | fn gen() -> impl PartialOrd + PartialEq + Debug {}
| ^^^^^^^^^
|
= note: `-D clippy::implied-bounds-in-impls` implied by `-D warnings`
help: try removing this bound
|
LL - fn gen() -> impl PartialOrd + PartialEq + Debug {}
LL + fn gen() -> impl PartialOrd + Debug {}
|
error: aborting due to previous error

View file

@ -65,4 +65,22 @@ impl SomeTrait for SomeStruct {
}
}
mod issue11422 {
use core::fmt::Debug;
// Some additional tests that would cause ICEs:
// `PartialOrd` has a default generic parameter and does not need to be explicitly specified.
// This needs special handling.
fn default_generic_param1() -> impl PartialOrd + Debug {}
fn default_generic_param2() -> impl PartialOrd + Debug {}
// Referring to `Self` in the supertrait clause needs special handling.
trait Trait1<X: ?Sized> {}
trait Trait2: Trait1<Self> {}
impl Trait1<()> for () {}
impl Trait2 for () {}
fn f() -> impl Trait1<()> + Trait2 {}
}
fn main() {}

View file

@ -65,4 +65,22 @@ impl SomeTrait for SomeStruct {
}
}
mod issue11422 {
use core::fmt::Debug;
// Some additional tests that would cause ICEs:
// `PartialOrd` has a default generic parameter and does not need to be explicitly specified.
// This needs special handling.
fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {}
fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {}
// Referring to `Self` in the supertrait clause needs special handling.
trait Trait1<X: ?Sized> {}
trait Trait2: Trait1<Self> {}
impl Trait1<()> for () {}
impl Trait2 for () {}
fn f() -> impl Trait1<()> + Trait2 {}
}
fn main() {}

View file

@ -119,5 +119,29 @@ LL - fn f() -> impl Deref + DerefMut<Target = u8> {
LL + fn f() -> impl DerefMut<Target = u8> {
|
error: aborting due to 10 previous errors
error: this bound is already specified as the supertrait of `PartialOrd`
--> $DIR/implied_bounds_in_impls.rs:74:41
|
LL | fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {}
| ^^^^^^^^^
|
help: try removing this bound
|
LL - fn default_generic_param1() -> impl PartialEq + PartialOrd + Debug {}
LL + fn default_generic_param1() -> impl PartialOrd + Debug {}
|
error: this bound is already specified as the supertrait of `PartialOrd`
--> $DIR/implied_bounds_in_impls.rs:75:54
|
LL | fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {}
| ^^^^^^^^^
|
help: try removing this bound
|
LL - fn default_generic_param2() -> impl PartialOrd + PartialEq + Debug {}
LL + fn default_generic_param2() -> impl PartialOrd + Debug {}
|
error: aborting due to 12 previous errors