Merge associated types with the other alias types

This commit is contained in:
Oli Scherer 2023-07-12 10:18:30 +00:00
parent d5c0f4d139
commit 5c9a74d88b
5 changed files with 24 additions and 35 deletions

View File

@ -210,19 +210,7 @@ where
}
}
}
ty::Alias(ty::Projection, proj) => {
if V::SKIP_ASSOC_TYS {
// Visitors searching for minimal visibility/reachability want to
// conservatively approximate associated types like `<Type as Trait>::Alias`
// as visible/reachable even if both `Type` and `Trait` are private.
// Ideally, associated types should be substituted in the same way as
// free type aliases, but this isn't done yet.
return ControlFlow::Continue(());
}
// This will also visit args if necessary, so we don't need to recurse.
return self.visit_projection_ty(proj);
}
ty::Alias(kind @ (ty::Inherent | ty::Weak), data) => {
ty::Alias(kind @ (ty::Inherent | ty::Weak | ty::Projection), data) => {
if V::SKIP_ASSOC_TYS {
// Visitors searching for minimal visibility/reachability want to
// conservatively approximate associated types like `Type::Alias`
@ -232,13 +220,14 @@ where
return ControlFlow::Continue(());
}
let kind = match kind {
ty::Inherent | ty::Projection => "associated type",
ty::Weak => "type alias",
ty::Opaque => unreachable!(),
};
self.def_id_visitor.visit_def_id(
data.def_id,
match kind {
ty::Inherent => "associated type",
ty::Weak => "type alias",
_ => unreachable!(),
},
kind,
&LazyDefPathStr { def_id: data.def_id, tcx },
)?;

View File

@ -23,7 +23,7 @@ mod priv_trait {
let _: <Pub as PrivTr>::AssocTy;
//~^ ERROR associated type `PrivTr::AssocTy` is private
pub type InSignatureTy = <Pub as PrivTr>::AssocTy;
//~^ ERROR trait `PrivTr` is private
//~^ ERROR associated type `PrivTr::AssocTy` is private
pub trait InSignatureTr: PrivTr {}
//~^ ERROR trait `PrivTr` is private
impl PrivTr for u8 {}

View File

@ -53,11 +53,11 @@ LL | priv_trait::mac!();
|
= note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
error: trait `PrivTr` is private
error: associated type `PrivTr::AssocTy` is private
--> $DIR/associated-item-privacy-trait.rs:25:34
|
LL | pub type InSignatureTy = <Pub as PrivTr>::AssocTy;
| ^^^^^^^^^^^^^^^^^^^^^^^^ private trait
| ^^^^^^^^^^^^^^^^^^^^^^^^ private associated type
...
LL | priv_trait::mac!();
| ------------------ in this macro invocation

View File

@ -104,8 +104,8 @@ mod aliases_pub {
// This should be OK, but associated type aliases are not substituted yet
pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
//~^ WARNING trait `aliases_pub::PrivTr` is more private than the item `aliases_pub::f3`
//~| WARNING type `aliases_pub::Priv` is more private than the item `aliases_pub::f3`
//~^ WARNING type `aliases_pub::Priv` is more private than the item `aliases_pub::f3`
//~| WARNING associated type `aliases_pub::PrivTr::Assoc` is more private than the item `aliases_pub::f3`
impl PrivUseAlias {
pub fn f(arg: Priv) {}
@ -133,8 +133,8 @@ mod aliases_priv {
pub fn f1(arg: PrivUseAlias) {} //~ WARNING type `Priv1` is more private than the item `aliases_priv::f1`
pub fn f2(arg: PrivAlias) {} //~ WARNING type `Priv2` is more private than the item `aliases_priv::f2`
pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
//~^ WARNING trait `aliases_priv::PrivTr` is more private than the item `aliases_priv::f3`
//~| WARNING type `aliases_priv::Priv` is more private than the item `aliases_priv::f3`
//~^ WARNING type `aliases_priv::Priv` is more private than the item `aliases_priv::f3`
//~| WARNING associated type `aliases_priv::PrivTr::Assoc` is more private than the item `aliases_priv::f3`
}
mod aliases_params {

View File

@ -276,17 +276,17 @@ note: but type `impls::Priv` is only usable at visibility `pub(self)`
LL | struct Priv;
| ^^^^^^^^^^^
warning: trait `aliases_pub::PrivTr` is more private than the item `aliases_pub::f3`
warning: associated type `aliases_pub::PrivTr::Assoc` is more private than the item `aliases_pub::f3`
--> $DIR/private-in-public.rs:106:5
|
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_pub::f3` is reachable at visibility `pub(crate)`
|
note: but trait `aliases_pub::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:100:5
note: but associated type `aliases_pub::PrivTr::Assoc` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:101:9
|
LL | trait PrivTr {
| ^^^^^^^^^^^^
LL | type Assoc = m::Pub3;
| ^^^^^^^^^^
warning: type `aliases_pub::Priv` is more private than the item `aliases_pub::f3`
--> $DIR/private-in-public.rs:106:5
@ -324,17 +324,17 @@ note: but type `Priv2` is only usable at visibility `pub(self)`
LL | struct Priv2;
| ^^^^^^^^^^^^
warning: trait `aliases_priv::PrivTr` is more private than the item `aliases_priv::f3`
warning: associated type `aliases_priv::PrivTr::Assoc` is more private than the item `aliases_priv::f3`
--> $DIR/private-in-public.rs:135:5
|
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f3` is reachable at visibility `pub(crate)`
|
note: but trait `aliases_priv::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:128:5
note: but associated type `aliases_priv::PrivTr::Assoc` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:129:9
|
LL | trait PrivTr {
| ^^^^^^^^^^^^
LL | type Assoc = Priv3;
| ^^^^^^^^^^
warning: type `aliases_priv::Priv` is more private than the item `aliases_priv::f3`
--> $DIR/private-in-public.rs:135:5