about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-02 16:20:04 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-04 09:37:25 +0000
commit769ab55558488d1ff786fa13e8ba1fb071a9791b (patch)
treee33cb49c1c98a4d2e0d63619445c77d937d273e3
parente2cf2cb30388385f0fe6b406a31a3f9841a72a62 (diff)
Add regression test
-rw-r--r--tests/ui/privacy/generic_struct_field_projection.rs35
-rw-r--r--tests/ui/privacy/generic_struct_field_projection.stderr8
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/ui/privacy/generic_struct_field_projection.rs b/tests/ui/privacy/generic_struct_field_projection.rs
new file mode 100644
index 00000000000..1931b9bf5c9
--- /dev/null
+++ b/tests/ui/privacy/generic_struct_field_projection.rs
@@ -0,0 +1,35 @@
+//! 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.
+//! 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.
+
+mod baz {
+    struct Foo;
+
+    pub trait Trait {
+        type Assoc;
+    }
+
+    impl Trait for Foo {
+        type Assoc = ();
+    }
+
+    pub struct Bar<'a, T: Trait> {
+        source: &'a T::Assoc,
+        //~^ ERROR: type `Foo` is private
+    }
+
+    pub struct Baz<'a> {
+        mode: Bar<'a, Foo>,
+    }
+}
+
+pub struct Struct<'a> {
+    lexer: baz::Baz<'a>,
+}
+
+fn main() {}
diff --git a/tests/ui/privacy/generic_struct_field_projection.stderr b/tests/ui/privacy/generic_struct_field_projection.stderr
new file mode 100644
index 00000000000..c51b573d76d
--- /dev/null
+++ b/tests/ui/privacy/generic_struct_field_projection.stderr
@@ -0,0 +1,8 @@
+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
+