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.
This commit is contained in:
Oli Scherer 2023-03-07 12:03:11 +00:00
parent a35c78fa70
commit 5777494f99
9 changed files with 51 additions and 76 deletions

View file

@ -1424,6 +1424,7 @@ fn ty_auto_deref_stability<'tcx>(
continue; continue;
}, },
ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty), ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty),
ty::Alias(ty::Weak, _) => unreachable!("should have been normalized away above"),
ty::Alias(ty::Inherent, _) => unreachable!("inherent projection should have been normalized away above"), ty::Alias(ty::Inherent, _) => unreachable!("inherent projection should have been normalized away above"),
ty::Alias(ty::Projection, _) if ty.has_non_region_param() => { ty::Alias(ty::Projection, _) if ty.has_non_region_param() => {
TyPosition::new_deref_stable_for_result(precedence, ty) TyPosition::new_deref_stable_for_result(precedence, ty)

View file

@ -82,10 +82,4 @@ fn msrv_1_41() {
} }
} }
type Opaque = impl Sized;
struct IntoOpaque;
impl Into<Opaque> for IntoOpaque {
fn into(self) -> Opaque {}
}
fn main() {} fn main() {}

View file

@ -82,10 +82,4 @@ fn msrv_1_41() {
} }
} }
type Opaque = impl Sized;
struct IntoOpaque;
impl Into<Opaque> for IntoOpaque {
fn into(self) -> Opaque {}
}
fn main() {} fn main() {}

View file

@ -32,4 +32,10 @@ impl Into<u8> for ContainsVal {
} }
} }
type Opaque = impl Sized;
struct IntoOpaque;
impl Into<Opaque> for IntoOpaque {
fn into(self) -> Opaque {}
}
fn main() {} fn main() {}

View file

@ -1,29 +1,12 @@
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true error[E0658]: `impl Trait` in type aliases is unstable
--> $DIR/from_over_into_unfixable.rs:11:1 --> $DIR/from_over_into_unfixable.rs:35:15
| |
LL | impl Into<InMacro> for String { LL | type Opaque = impl Sized;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^
| |
= help: replace the `Into` implementation with `From<std::string::String>` = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= note: `-D clippy::from-over-into` implied by `-D warnings` = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true error: aborting due to previous error
--> $DIR/from_over_into_unfixable.rs:19:1
|
LL | impl Into<WeirdUpperSelf> for &'static [u8] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: replace the `Into` implementation with `From<&'static [u8]>`
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
--> $DIR/from_over_into_unfixable.rs:28:1
|
LL | impl Into<u8> for ContainsVal {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
= help: replace the `Into` implementation with `From<ContainsVal>`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0658`.

View file

@ -401,25 +401,3 @@ mod issue7344 {
} }
} }
} }
mod issue10041 {
struct Bomb;
impl Bomb {
// Hidden <Rhs = Self> default generic parameter.
pub fn new() -> impl PartialOrd {
0i32
}
}
// TAIT with self-referencing bounds
type X = impl std::ops::Add<Output = X>;
struct Bomb2;
impl Bomb2 {
pub fn new() -> X {
0i32
}
}
}

View file

@ -92,21 +92,5 @@ LL | | unimplemented!()
LL | | } LL | | }
| |_________^ | |_________^
error: methods called `new` usually return `Self` error: aborting due to 12 previous errors
--> $DIR/new_ret_no_self.rs:410:9
|
LL | / pub fn new() -> impl PartialOrd {
LL | | 0i32
LL | | }
| |_________^
error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:421:9
|
LL | / pub fn new() -> X {
LL | | 0i32
LL | | }
| |_________^
error: aborting due to 14 previous errors

View file

@ -0,0 +1,26 @@
#![feature(type_alias_impl_trait)]
#![warn(clippy::new_ret_no_self)]
mod issue10041 {
struct Bomb;
impl Bomb {
// Hidden <Rhs = Self> default generic parameter.
pub fn new() -> impl PartialOrd {
0i32
}
}
// TAIT with self-referencing bounds
type X = impl std::ops::Add<Output = X>;
struct Bomb2;
impl Bomb2 {
pub fn new() -> X {
0i32
}
}
}
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0275]: overflow evaluating the requirement `<i32 as std::ops::Add>::Output == issue10041::X`
--> $DIR/new_ret_no_self_overflow.rs:20:25
|
LL | pub fn new() -> X {
| ^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0275`.