Add some tests for associated type normalization edge cases

This commit is contained in:
Oli Scherer 2024-02-08 12:28:35 +00:00
parent e867886c6a
commit d80d7ea1e3
4 changed files with 194 additions and 0 deletions

View File

@ -0,0 +1,60 @@
mod m {
struct Priv;
pub type Leak = Priv; //~ WARN: `Priv` is more private than the item `Leak`
}
trait Trait {
type A<T>;
}
impl Trait for u8 {
type A<T> = u8;
}
fn check() -> <u8 as Trait>::A<m::Leak> {
//~^ ERROR: `Priv` is private
0
}
trait Trait2 {
type A<T>;
}
impl Trait2 for u8 {
type A<T> = m::Leak;
//~^ ERROR: `Priv` is private
//~| ERROR: private type `Priv` in public interface
}
fn check2() -> <u8 as Trait2>::A<u32> {
//~^ ERROR: `Priv` is private
todo!()
}
trait Trait3 {
type A<T: Trait>;
}
impl Trait3 for u8 {
type A<T: Trait> = T::A<m::Leak>;
//~^ ERROR: `Priv` is private
//~| ERROR: private type `Priv` in public interface
}
fn check3() -> <u8 as Trait3>::A<u8> {
todo!()
}
trait Trait4 {
type A<T: Trait3>;
}
impl Trait4 for u8 {
type A<T: Trait3> = T::A<u8>;
}
fn check4() -> <u8 as Trait4>::A<u8> {
todo!()
}
fn main() {}

View File

@ -0,0 +1,62 @@
warning: type `Priv` is more private than the item `Leak`
--> $DIR/projections.rs:3:5
|
LL | pub type Leak = Priv;
| ^^^^^^^^^^^^^ type alias `Leak` is reachable at visibility `pub(crate)`
|
note: but type `Priv` is only usable at visibility `pub(self)`
--> $DIR/projections.rs:2:5
|
LL | struct Priv;
| ^^^^^^^^^^^
= note: `#[warn(private_interfaces)]` on by default
error[E0446]: private type `Priv` in public interface
--> $DIR/projections.rs:24:5
|
LL | struct Priv;
| ----------- `Priv` declared as private
...
LL | type A<T> = m::Leak;
| ^^^^^^^^^ can't leak private type
error[E0446]: private type `Priv` in public interface
--> $DIR/projections.rs:39:5
|
LL | struct Priv;
| ----------- `Priv` declared as private
...
LL | type A<T: Trait> = T::A<m::Leak>;
| ^^^^^^^^^^^^^^^^ can't leak private type
error: type `Priv` is private
--> $DIR/projections.rs:14:15
|
LL | fn check() -> <u8 as Trait>::A<m::Leak> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ private type
error: type `Priv` is private
--> $DIR/projections.rs:29:39
|
LL | fn check2() -> <u8 as Trait2>::A<u32> {
| _______________________________________^
LL | |
LL | | todo!()
LL | | }
| |_^ private type
error: type `Priv` is private
--> $DIR/projections.rs:24:17
|
LL | type A<T> = m::Leak;
| ^^^^^^^ private type
error: type `Priv` is private
--> $DIR/projections.rs:39:24
|
LL | type A<T: Trait> = T::A<m::Leak>;
| ^^^^^^^^^^^^^ private type
error: aborting due to 6 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0446`.

View File

@ -0,0 +1,38 @@
mod m {
use super::*;
struct Priv;
pub type Leak = Priv; //~ WARN: `Priv` is more private than the item `Leak`
trait Trait3 {
type A<T: Trait>;
}
impl Trait3 for u8 {
type A<T: Trait> = T::A<Leak>;
}
pub trait Trait4 {
type A<T: Trait>;
}
impl Trait4 for u8 {
type A<T: Trait> = <u8 as Trait3>::A<T>;
//~^ ERROR: private associated type `Trait3::A` in public interface
//~| ERROR: private trait `Trait3` in public interface
}
}
pub trait Trait {
type A<T>;
}
impl Trait for u8 {
type A<T> = u8;
}
use m::*;
fn check4() -> <u8 as Trait4>::A<u8> {
todo!()
}
fn main() {}

View File

@ -0,0 +1,34 @@
warning: type `Priv` is more private than the item `Leak`
--> $DIR/projections2.rs:4:5
|
LL | pub type Leak = Priv;
| ^^^^^^^^^^^^^ type alias `Leak` is reachable at visibility `pub(crate)`
|
note: but type `Priv` is only usable at visibility `pub(self)`
--> $DIR/projections2.rs:3:5
|
LL | struct Priv;
| ^^^^^^^^^^^
= note: `#[warn(private_interfaces)]` on by default
error[E0446]: private associated type `Trait3::A` in public interface
--> $DIR/projections2.rs:19:9
|
LL | type A<T: Trait>;
| ---------------- `Trait3::A` declared as private
...
LL | type A<T: Trait> = <u8 as Trait3>::A<T>;
| ^^^^^^^^^^^^^^^^ can't leak private associated type
error[E0446]: private trait `Trait3` in public interface
--> $DIR/projections2.rs:19:9
|
LL | trait Trait3 {
| ------------ `Trait3` declared as private
...
LL | type A<T: Trait> = <u8 as Trait3>::A<T>;
| ^^^^^^^^^^^^^^^^ can't leak private trait
error: aborting due to 2 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0446`.