Skip to content

Commit 5c9a74d

Browse files
committed
Merge associated types with the other alias types
1 parent d5c0f4d commit 5c9a74d

File tree

5 files changed

+24
-35
lines changed

5 files changed

+24
-35
lines changed

compiler/rustc_privacy/src/lib.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,7 @@ where
210210
}
211211
}
212212
}
213-
ty::Alias(ty::Projection, proj) => {
214-
if V::SKIP_ASSOC_TYS {
215-
// Visitors searching for minimal visibility/reachability want to
216-
// conservatively approximate associated types like `<Type as Trait>::Alias`
217-
// as visible/reachable even if both `Type` and `Trait` are private.
218-
// Ideally, associated types should be substituted in the same way as
219-
// free type aliases, but this isn't done yet.
220-
return ControlFlow::Continue(());
221-
}
222-
// This will also visit args if necessary, so we don't need to recurse.
223-
return self.visit_projection_ty(proj);
224-
}
225-
ty::Alias(kind @ (ty::Inherent | ty::Weak), data) => {
213+
ty::Alias(kind @ (ty::Inherent | ty::Weak | ty::Projection), data) => {
226214
if V::SKIP_ASSOC_TYS {
227215
// Visitors searching for minimal visibility/reachability want to
228216
// conservatively approximate associated types like `Type::Alias`
@@ -232,13 +220,14 @@ where
232220
return ControlFlow::Continue(());
233221
}
234222

223+
let kind = match kind {
224+
ty::Inherent | ty::Projection => "associated type",
225+
ty::Weak => "type alias",
226+
ty::Opaque => unreachable!(),
227+
};
235228
self.def_id_visitor.visit_def_id(
236229
data.def_id,
237-
match kind {
238-
ty::Inherent => "associated type",
239-
ty::Weak => "type alias",
240-
_ => unreachable!(),
241-
},
230+
kind,
242231
&LazyDefPathStr { def_id: data.def_id, tcx },
243232
)?;
244233

tests/ui/privacy/associated-item-privacy-trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mod priv_trait {
2323
let _: <Pub as PrivTr>::AssocTy;
2424
//~^ ERROR associated type `PrivTr::AssocTy` is private
2525
pub type InSignatureTy = <Pub as PrivTr>::AssocTy;
26-
//~^ ERROR trait `PrivTr` is private
26+
//~^ ERROR associated type `PrivTr::AssocTy` is private
2727
pub trait InSignatureTr: PrivTr {}
2828
//~^ ERROR trait `PrivTr` is private
2929
impl PrivTr for u8 {}

tests/ui/privacy/associated-item-privacy-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ LL | priv_trait::mac!();
5353
|
5454
= note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
5555

56-
error: trait `PrivTr` is private
56+
error: associated type `PrivTr::AssocTy` is private
5757
--> $DIR/associated-item-privacy-trait.rs:25:34
5858
|
5959
LL | pub type InSignatureTy = <Pub as PrivTr>::AssocTy;
60-
| ^^^^^^^^^^^^^^^^^^^^^^^^ private trait
60+
| ^^^^^^^^^^^^^^^^^^^^^^^^ private associated type
6161
...
6262
LL | priv_trait::mac!();
6363
| ------------------ in this macro invocation

tests/ui/privacy/private-in-public.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ mod aliases_pub {
104104

105105
// This should be OK, but associated type aliases are not substituted yet
106106
pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
107-
//~^ WARNING trait `aliases_pub::PrivTr` is more private than the item `aliases_pub::f3`
108-
//~| WARNING type `aliases_pub::Priv` is more private than the item `aliases_pub::f3`
107+
//~^ WARNING type `aliases_pub::Priv` is more private than the item `aliases_pub::f3`
108+
//~| WARNING associated type `aliases_pub::PrivTr::Assoc` is more private than the item `aliases_pub::f3`
109109

110110
impl PrivUseAlias {
111111
pub fn f(arg: Priv) {}
@@ -133,8 +133,8 @@ mod aliases_priv {
133133
pub fn f1(arg: PrivUseAlias) {} //~ WARNING type `Priv1` is more private than the item `aliases_priv::f1`
134134
pub fn f2(arg: PrivAlias) {} //~ WARNING type `Priv2` is more private than the item `aliases_priv::f2`
135135
pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
136-
//~^ WARNING trait `aliases_priv::PrivTr` is more private than the item `aliases_priv::f3`
137-
//~| WARNING type `aliases_priv::Priv` is more private than the item `aliases_priv::f3`
136+
//~^ WARNING type `aliases_priv::Priv` is more private than the item `aliases_priv::f3`
137+
//~| WARNING associated type `aliases_priv::PrivTr::Assoc` is more private than the item `aliases_priv::f3`
138138
}
139139

140140
mod aliases_params {

tests/ui/privacy/private-in-public.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,17 @@ note: but type `impls::Priv` is only usable at visibility `pub(self)`
276276
LL | struct Priv;
277277
| ^^^^^^^^^^^
278278

279-
warning: trait `aliases_pub::PrivTr` is more private than the item `aliases_pub::f3`
279+
warning: associated type `aliases_pub::PrivTr::Assoc` is more private than the item `aliases_pub::f3`
280280
--> $DIR/private-in-public.rs:106:5
281281
|
282282
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
283283
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_pub::f3` is reachable at visibility `pub(crate)`
284284
|
285-
note: but trait `aliases_pub::PrivTr` is only usable at visibility `pub(self)`
286-
--> $DIR/private-in-public.rs:100:5
285+
note: but associated type `aliases_pub::PrivTr::Assoc` is only usable at visibility `pub(self)`
286+
--> $DIR/private-in-public.rs:101:9
287287
|
288-
LL | trait PrivTr {
289-
| ^^^^^^^^^^^^
288+
LL | type Assoc = m::Pub3;
289+
| ^^^^^^^^^^
290290

291291
warning: type `aliases_pub::Priv` is more private than the item `aliases_pub::f3`
292292
--> $DIR/private-in-public.rs:106:5
@@ -324,17 +324,17 @@ note: but type `Priv2` is only usable at visibility `pub(self)`
324324
LL | struct Priv2;
325325
| ^^^^^^^^^^^^
326326

327-
warning: trait `aliases_priv::PrivTr` is more private than the item `aliases_priv::f3`
327+
warning: associated type `aliases_priv::PrivTr::Assoc` is more private than the item `aliases_priv::f3`
328328
--> $DIR/private-in-public.rs:135:5
329329
|
330330
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
331331
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f3` is reachable at visibility `pub(crate)`
332332
|
333-
note: but trait `aliases_priv::PrivTr` is only usable at visibility `pub(self)`
334-
--> $DIR/private-in-public.rs:128:5
333+
note: but associated type `aliases_priv::PrivTr::Assoc` is only usable at visibility `pub(self)`
334+
--> $DIR/private-in-public.rs:129:9
335335
|
336-
LL | trait PrivTr {
337-
| ^^^^^^^^^^^^
336+
LL | type Assoc = Priv3;
337+
| ^^^^^^^^^^
338338

339339
warning: type `aliases_priv::Priv` is more private than the item `aliases_priv::f3`
340340
--> $DIR/private-in-public.rs:135:5

0 commit comments

Comments
 (0)