Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 4, 2024
1 parent e2cf2cb commit 769ab55
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/ui/privacy/generic_struct_field_projection.rs
Original file line number Diff line number Diff line change
@@ -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() {}
8 changes: 8 additions & 0 deletions tests/ui/privacy/generic_struct_field_projection.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 769ab55

Please sign in to comment.