Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5777494

Browse files
committed
Add AliasKind::Weak for type aliases.
Only use it when the type alias contains an opaque type. Also does wf-checking on such type aliases.
1 parent a35c78f commit 5777494

9 files changed

+51
-76
lines changed

clippy_lints/src/dereference.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,7 @@ fn ty_auto_deref_stability<'tcx>(
14241424
continue;
14251425
},
14261426
ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty),
1427+
ty::Alias(ty::Weak, _) => unreachable!("should have been normalized away above"),
14271428
ty::Alias(ty::Inherent, _) => unreachable!("inherent projection should have been normalized away above"),
14281429
ty::Alias(ty::Projection, _) if ty.has_non_region_param() => {
14291430
TyPosition::new_deref_stable_for_result(precedence, ty)

tests/ui/from_over_into.fixed

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,4 @@ fn msrv_1_41() {
8282
}
8383
}
8484

85-
type Opaque = impl Sized;
86-
struct IntoOpaque;
87-
impl Into<Opaque> for IntoOpaque {
88-
fn into(self) -> Opaque {}
89-
}
90-
9185
fn main() {}

tests/ui/from_over_into.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,4 @@ fn msrv_1_41() {
8282
}
8383
}
8484

85-
type Opaque = impl Sized;
86-
struct IntoOpaque;
87-
impl Into<Opaque> for IntoOpaque {
88-
fn into(self) -> Opaque {}
89-
}
90-
9185
fn main() {}

tests/ui/from_over_into_unfixable.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@ impl Into<u8> for ContainsVal {
3232
}
3333
}
3434

35+
type Opaque = impl Sized;
36+
struct IntoOpaque;
37+
impl Into<Opaque> for IntoOpaque {
38+
fn into(self) -> Opaque {}
39+
}
40+
3541
fn main() {}
Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
1-
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
2-
--> $DIR/from_over_into_unfixable.rs:11:1
1+
error[E0658]: `impl Trait` in type aliases is unstable
2+
--> $DIR/from_over_into_unfixable.rs:35:15
33
|
4-
LL | impl Into<InMacro> for String {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | type Opaque = impl Sized;
5+
| ^^^^^^^^^^
66
|
7-
= help: replace the `Into` implementation with `From<std::string::String>`
8-
= note: `-D clippy::from-over-into` implied by `-D warnings`
7+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
8+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
99

10-
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
11-
--> $DIR/from_over_into_unfixable.rs:19:1
12-
|
13-
LL | impl Into<WeirdUpperSelf> for &'static [u8] {
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= help: replace the `Into` implementation with `From<&'static [u8]>`
17-
18-
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
19-
--> $DIR/from_over_into_unfixable.rs:28:1
20-
|
21-
LL | impl Into<u8> for ContainsVal {
22-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23-
|
24-
= help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
25-
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
26-
= help: replace the `Into` implementation with `From<ContainsVal>`
27-
28-
error: aborting due to 3 previous errors
10+
error: aborting due to previous error
2911

12+
For more information about this error, try `rustc --explain E0658`.

tests/ui/new_ret_no_self.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -401,25 +401,3 @@ mod issue7344 {
401401
}
402402
}
403403
}
404-
405-
mod issue10041 {
406-
struct Bomb;
407-
408-
impl Bomb {
409-
// Hidden <Rhs = Self> default generic parameter.
410-
pub fn new() -> impl PartialOrd {
411-
0i32
412-
}
413-
}
414-
415-
// TAIT with self-referencing bounds
416-
type X = impl std::ops::Add<Output = X>;
417-
418-
struct Bomb2;
419-
420-
impl Bomb2 {
421-
pub fn new() -> X {
422-
0i32
423-
}
424-
}
425-
}

tests/ui/new_ret_no_self.stderr

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,5 @@ LL | | unimplemented!()
9292
LL | | }
9393
| |_________^
9494

95-
error: methods called `new` usually return `Self`
96-
--> $DIR/new_ret_no_self.rs:410:9
97-
|
98-
LL | / pub fn new() -> impl PartialOrd {
99-
LL | | 0i32
100-
LL | | }
101-
| |_________^
102-
103-
error: methods called `new` usually return `Self`
104-
--> $DIR/new_ret_no_self.rs:421:9
105-
|
106-
LL | / pub fn new() -> X {
107-
LL | | 0i32
108-
LL | | }
109-
| |_________^
110-
111-
error: aborting due to 14 previous errors
95+
error: aborting due to 12 previous errors
11296

tests/ui/new_ret_no_self_overflow.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![feature(type_alias_impl_trait)]
2+
#![warn(clippy::new_ret_no_self)]
3+
4+
mod issue10041 {
5+
struct Bomb;
6+
7+
impl Bomb {
8+
// Hidden <Rhs = Self> default generic parameter.
9+
pub fn new() -> impl PartialOrd {
10+
0i32
11+
}
12+
}
13+
14+
// TAIT with self-referencing bounds
15+
type X = impl std::ops::Add<Output = X>;
16+
17+
struct Bomb2;
18+
19+
impl Bomb2 {
20+
pub fn new() -> X {
21+
0i32
22+
}
23+
}
24+
}
25+
26+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0275]: overflow evaluating the requirement `<i32 as std::ops::Add>::Output == issue10041::X`
2+
--> $DIR/new_ret_no_self_overflow.rs:20:25
3+
|
4+
LL | pub fn new() -> X {
5+
| ^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)