about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-02 17:27:35 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-04 14:43:44 +0000
commit83bd12c70fd34dece71bcc632ee3df64036ca1d8 (patch)
tree6aab69bd8ce3105639279ea8bfbfd480ead2ac1a
parent769ab55558488d1ff786fa13e8ba1fb071a9791b (diff)
downloadrust-83bd12c70fd34dece71bcc632ee3df64036ca1d8.tar.gz
rust-83bd12c70fd34dece71bcc632ee3df64036ca1d8.zip
Only inspect user-written predicates for privacy concerns
-rw-r--r--compiler/rustc_ty_utils/src/sig_types.rs11
-rw-r--r--tests/ui/privacy/generic_struct_field_projection.rs9
-rw-r--r--tests/ui/privacy/generic_struct_field_projection.stderr8
3 files changed, 12 insertions, 16 deletions
diff --git a/compiler/rustc_ty_utils/src/sig_types.rs b/compiler/rustc_ty_utils/src/sig_types.rs
index 63654a453dd..19c092c5ddf 100644
--- a/compiler/rustc_ty_utils/src/sig_types.rs
+++ b/compiler/rustc_ty_utils/src/sig_types.rs
@@ -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,
@@ -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));
             }
         }
@@ -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));
             }
         }
@@ -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));
             }
         }
@@ -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));
             }
         }
diff --git a/tests/ui/privacy/generic_struct_field_projection.rs b/tests/ui/privacy/generic_struct_field_projection.rs
index 1931b9bf5c9..c5bb1233c27 100644
--- a/tests/ui/privacy/generic_struct_field_projection.rs
+++ b/tests/ui/privacy/generic_struct_field_projection.rs
@@ -1,11 +1,15 @@
 //! To determine all the types that need to be private when looking at `Struct`, we
-//! invoke `predicates_of` to also look at types in `where` bounds.
+//! used to invoke `predicates_of` to also look at types in `where` bounds.
 //! Unfortunately this also computes the inferred outlives bounds, which means for
 //! every field we check that if it is of type `&'a T` then `T: 'a` and if it is of
 //! struct type, we check that the struct satisfies its lifetime parameters by looking
 //! at its inferred outlives bounds. This means we end up with a `<Foo as Trait>::Assoc: 'a`
 //! in the outlives bounds of `Struct`. While this is trivially provable, privacy
-//! only sees `Foo` and `Trait` and determins that `Foo` is private and then errors.
+//! only sees `Foo` and `Trait` and determines that `Foo` is private and then errors.
+//! So now we invoke `explicit_predicates_of` to make sure we only care about user-written
+//! predicates.
+
+//@ check-pass
 
 mod baz {
     struct Foo;
@@ -20,7 +24,6 @@ mod baz {
 
     pub struct Bar<'a, T: Trait> {
         source: &'a T::Assoc,
-        //~^ ERROR: type `Foo` is private
     }
 
     pub struct Baz<'a> {
diff --git a/tests/ui/privacy/generic_struct_field_projection.stderr b/tests/ui/privacy/generic_struct_field_projection.stderr
deleted file mode 100644
index c51b573d76d..00000000000
--- a/tests/ui/privacy/generic_struct_field_projection.stderr
+++ /dev/null
@@ -1,8 +0,0 @@
-error: type `Foo` is private
-  --> $DIR/generic_struct_field_projection.rs:22:9
-   |
-LL |         source: &'a T::Assoc,
-   |         ^^^^^^^^^^^^^^^^^^^^ private type
-
-error: aborting due to 1 previous error
-