Skip to content

Commit

Permalink
Only inspect user-written predicates for privacy concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 2, 2024
1 parent 79021b0 commit aede7a9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
11 changes: 6 additions & 5 deletions compiler/rustc_ty_utils/src/sig_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub trait SpannedTypeVisitor<'tcx> {
fn visit(&mut self, span: Span, value: impl TypeVisitable<TyCtxt<'tcx>>) -> Self::Result;
}

#[instrument(level = "trace", skip(tcx, visitor))]
pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
tcx: TyCtxt<'tcx>,
item: LocalDefId,
Expand All @@ -36,7 +37,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
for (hir, ty) in hir_sig.inputs.iter().zip(ty_sig.inputs().iter()) {
try_visit!(visitor.visit(hir.span, ty.map_bound(|x| *x)));
}
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) {
try_visit!(visitor.visit(span, pred));
}
}
Expand All @@ -54,7 +55,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
// Associated types in traits don't necessarily have a type that we can visit
try_visit!(visitor.visit(ty.span, tcx.type_of(item).instantiate_identity()));
}
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) {
try_visit!(visitor.visit(span, pred));
}
}
Expand All @@ -76,7 +77,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
let ty = field.ty(tcx, args);
try_visit!(visitor.visit(span, ty));
}
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) {
try_visit!(visitor.visit(span, pred));
}
}
Expand All @@ -95,12 +96,12 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
_ => tcx.def_span(item),
};
try_visit!(visitor.visit(span, tcx.type_of(item).instantiate_identity()));
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) {
try_visit!(visitor.visit(span, pred));
}
}
DefKind::TraitAlias | DefKind::Trait => {
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) {
try_visit!(visitor.visit(span, pred));
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/privacy/generic_struct_field_projection.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ check-pass

mod baz {
struct Foo;

Expand All @@ -11,7 +13,6 @@ mod baz {

pub struct Bar<'a, T: Trait> {
source: &'a T::Assoc,
//~^ ERROR: type `Foo` is private
}

pub struct Baz<'a> {
Expand Down
8 changes: 0 additions & 8 deletions tests/ui/privacy/generic_struct_field_projection.stderr

This file was deleted.

0 comments on commit aede7a9

Please sign in to comment.