Skip to content

Commit d83d03c

Browse files
committed
privacy: visit trait def id of projections
A refactoring in rust-lang#117076 changed the `DefIdVisitorSkeleton` to avoid calling `visit_projection_ty` for `ty::Projection` aliases, and instead just iterate over the args - this makes sense, as `visit_projection_ty` will indirectly visit all of the same args, but in doing so, will also create a `TraitRef` containing the trait's `DefId`, which also gets visited. The trait's `DefId` isn't visited when we only visit the arguments without separating them into `TraitRef` and own args first. Signed-off-by: David Wood <[email protected]>
1 parent 7df0c21 commit d83d03c

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

compiler/rustc_privacy/src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,21 @@ where
218218
return ControlFlow::Continue(());
219219
}
220220

221-
let kind = match kind {
222-
ty::Inherent | ty::Projection => "associated type",
223-
ty::Weak => "type alias",
224-
ty::Opaque => unreachable!(),
225-
};
226221
self.def_id_visitor.visit_def_id(
227222
data.def_id,
228-
kind,
223+
match kind {
224+
ty::Inherent | ty::Projection => "associated type",
225+
ty::Weak => "type alias",
226+
ty::Opaque => unreachable!(),
227+
},
229228
&LazyDefPathStr { def_id: data.def_id, tcx },
230229
)?;
231230

232231
// This will also visit args if necessary, so we don't need to recurse.
233232
return if V::SHALLOW {
234233
ControlFlow::Continue(())
234+
} else if kind == ty::Projection {
235+
self.visit_projection_ty(data)
235236
} else {
236237
data.args.iter().try_for_each(|subst| subst.visit_with(self))
237238
};
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// no-prefer-dynamic
2+
// compile-flags: --crate-type=rlib
3+
4+
pub use impl_mod::TraitImplementer as Implementer;
5+
6+
pub use trait_mod::get_assoc;
7+
8+
mod impl_mod {
9+
use crate::trait_mod::TraitWithAssocType;
10+
11+
pub struct TraitImplementer {}
12+
pub struct AssociatedType {}
13+
14+
impl AssociatedType {
15+
pub fn method_on_assoc(&self) -> i32 {
16+
todo!()
17+
}
18+
}
19+
20+
impl TraitWithAssocType for TraitImplementer {
21+
type AssocType = AssociatedType;
22+
}
23+
}
24+
25+
mod trait_mod {
26+
use crate::Implementer;
27+
28+
pub fn get_assoc() -> <Implementer as TraitWithAssocType>::AssocType {
29+
todo!()
30+
}
31+
32+
pub trait TraitWithAssocType {
33+
type AssocType;
34+
}
35+
}

tests/ui/privacy/issue-117997.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// aux-build:issue-117997.rs
2+
// build-pass
3+
4+
extern crate issue_117997;
5+
6+
pub fn main() {
7+
issue_117997::get_assoc().method_on_assoc();
8+
}

0 commit comments

Comments
 (0)