Skip to content

Commit

Permalink
privacy: Use common DefId visiting infra for all privacy visitors
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Dec 31, 2018
1 parent 6efaef6 commit 8b1c424
Show file tree
Hide file tree
Showing 17 changed files with 565 additions and 533 deletions.
9 changes: 9 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,15 @@ impl VisibilityKind {
VisibilityKind::Restricted { .. } => true,
}
}

pub fn descr(&self) -> &'static str {
match *self {
VisibilityKind::Public => "public",
VisibilityKind::Inherited => "private",
VisibilityKind::Crate(..) => "crate-visible",
VisibilityKind::Restricted { .. } => "restricted",
}
}
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
Expand Down
911 changes: 408 additions & 503 deletions src/librustc_privacy/lib.rs

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/libstd/sys/windows/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ impl RawHandle {
}
}

pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
let mut me = self;
(&mut me).read_to_end(buf)
}

pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
let mut amt = 0;
let len = cmp::min(buf.len(), <c::DWORD>::max_value() as usize) as c::DWORD;
Expand Down
5 changes: 0 additions & 5 deletions src/libstd/sys/windows/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ impl Stdin {
// MemReader shouldn't error here since we just filled it
utf8.read(buf)
}

pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
let mut me = self;
(&mut me).read_to_end(buf)
}
}

#[unstable(reason = "not public", issue = "0", feature = "fd_read")]
Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/error-codes/E0445.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ trait Foo {

pub trait Bar : Foo {}
//~^ ERROR private trait `Foo` in public interface [E0445]
//~| NOTE can't leak private trait
pub struct Bar2<T: Foo>(pub T);
//~^ ERROR private trait `Foo` in public interface [E0445]
//~| NOTE can't leak private trait
pub fn foo<T: Foo> (t: T) {}
//~^ ERROR private trait `Foo` in public interface [E0445]
//~| NOTE can't leak private trait

fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0445.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ LL | pub trait Bar : Foo {}
| ^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0445]: private trait `Foo` in public interface
--> $DIR/E0445.rs:8:1
--> $DIR/E0445.rs:7:1
|
LL | pub struct Bar2<T: Foo>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0445]: private trait `Foo` in public interface
--> $DIR/E0445.rs:11:1
--> $DIR/E0445.rs:9:1
|
LL | pub fn foo<T: Foo> (t: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/impl-trait/issue-49376.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ fn gen() -> impl PartialOrd + PartialEq + Debug { }

struct Bar {}
trait Foo<T = Self> {}
trait FooNested<T = Option<Self>> {}
impl Foo for Bar {}
impl FooNested for Bar {}

fn foo() -> impl Foo {
fn foo() -> impl Foo + FooNested {
Bar {}
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/issues/issue-18389.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
error[E0445]: private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface
--> $DIR/issue-18389.rs:7:1
|
LL | trait Private<P, R> {
| - `Private<<Self as Public>::P, <Self as Public>::R>` declared as private
...
LL | / pub trait Public: Private<
LL | | //~^ ERROR private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface
LL | | <Self as Public>::P,
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/privacy/private-in-public-expr-pat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Patterns and expressions are not interface parts and don't produce private-in-public errors.

// compile-pass

struct Priv1(usize);
struct Priv2;

pub struct Pub(Priv2);

pub fn public_expr(_: [u8; Priv1(0).0]) {} // OK
pub fn public_pat(Pub(Priv2): Pub) {} // OK

fn main() {}
13 changes: 13 additions & 0 deletions src/test/ui/privacy/private-in-public-non-principal-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(optin_builtin_traits)]

#[allow(private_in_public)]
mod m {
pub trait PubPrincipal {}
auto trait PrivNonPrincipal {}
pub fn leak_dyn_nonprincipal() -> Box<PubPrincipal + PrivNonPrincipal> { loop {} }
}

fn main() {
m::leak_dyn_nonprincipal();
//~^ ERROR type `(dyn m::PubPrincipal + m::PrivNonPrincipal + 'static)` is private
}
8 changes: 8 additions & 0 deletions src/test/ui/privacy/private-in-public-non-principal-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: type `(dyn m::PubPrincipal + m::PrivNonPrincipal + 'static)` is private
--> $DIR/private-in-public-non-principal-2.rs:11:5
|
LL | m::leak_dyn_nonprincipal();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

20 changes: 20 additions & 0 deletions src/test/ui/privacy/private-in-public-non-principal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![feature(optin_builtin_traits)]

pub trait PubPrincipal {}
auto trait PrivNonPrincipal {}

pub fn leak_dyn_nonprincipal() -> Box<PubPrincipal + PrivNonPrincipal> { loop {} }
//~^ WARN private type `(dyn PubPrincipal + PrivNonPrincipal + 'static)` in public interface
//~| WARN this was previously accepted

#[deny(missing_docs)]
fn container() {
impl dyn PubPrincipal {
pub fn check_doc_lint() {} //~ ERROR missing documentation for a method
}
impl dyn PubPrincipal + PrivNonPrincipal {
pub fn check_doc_lint() {} // OK, no missing doc lint
}
}

fn main() {}
24 changes: 24 additions & 0 deletions src/test/ui/privacy/private-in-public-non-principal.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
warning: private type `(dyn PubPrincipal + PrivNonPrincipal + 'static)` in public interface (error E0446)
--> $DIR/private-in-public-non-principal.rs:6:1
|
LL | pub fn leak_dyn_nonprincipal() -> Box<PubPrincipal + PrivNonPrincipal> { loop {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(private_in_public)] on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>

error: missing documentation for a method
--> $DIR/private-in-public-non-principal.rs:13:9
|
LL | pub fn check_doc_lint() {} //~ ERROR missing documentation for a method
| ^^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/private-in-public-non-principal.rs:10:8
|
LL | #[deny(missing_docs)]
| ^^^^^^^^^^^^

error: aborting due to previous error

9 changes: 9 additions & 0 deletions src/test/ui/privacy/private-in-public-warn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ mod aliases_pub {
impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
}
impl PrivUseAliasTr for Option<<Priv as PrivTr>::AssocAlias> {
type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
}
impl PrivUseAliasTr for (<Priv as PrivTr>::AssocAlias, Priv) {
type Check = Priv; // OK
}
impl PrivUseAliasTr for Option<(<Priv as PrivTr>::AssocAlias, Priv)> {
type Check = Priv; // OK
}
}

mod aliases_priv {
Expand Down
21 changes: 15 additions & 6 deletions src/test/ui/privacy/private-in-public-warn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -297,33 +297,42 @@ LL | struct Priv;
LL | type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
| ^^^^^^^^^^^^^^^^^^ can't leak private type

error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:217:9
|
LL | struct Priv;
| - `aliases_pub::Priv` declared as private
...
LL | type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
| ^^^^^^^^^^^^^^^^^^ can't leak private type

error: private trait `aliases_priv::PrivTr1` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:238:5
--> $DIR/private-in-public-warn.rs:247:5
|
LL | pub trait Tr1: PrivUseAliasTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>

error: private type `aliases_priv::Priv2` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:241:5
error: private trait `aliases_priv::PrivTr1<aliases_priv::Priv2>` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:250:5
|
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>

error: private trait `aliases_priv::PrivTr1<aliases_priv::Priv2>` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:241:5
error: private type `aliases_priv::Priv2` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:250:5
|
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>

error: aborting due to 35 previous errors
error: aborting due to 36 previous errors

For more information about this error, try `rustc --explain E0446`.
4 changes: 2 additions & 2 deletions src/test/ui/privacy/private-in-public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod aliases_pub {

// This should be OK, but associated type aliases are not substituted yet
pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
//~^ ERROR private type `<aliases_pub::Priv as aliases_pub::PrivTr>::Assoc` in public interface
//~^ ERROR private trait `aliases_pub::PrivTr` in public interface
//~| ERROR private type `aliases_pub::Priv` in public interface

impl PrivUseAlias {
Expand Down Expand Up @@ -131,7 +131,7 @@ mod aliases_priv {
pub fn f1(arg: PrivUseAlias) {} //~ ERROR private type `aliases_priv::Priv1` in public interface
pub fn f2(arg: PrivAlias) {} //~ ERROR private type `aliases_priv::Priv2` in public interface
pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
//~^ ERROR private type `<aliases_priv::Priv as aliases_priv::PrivTr>::Assoc` in public
//~^ ERROR private trait `aliases_priv::PrivTr` in public interface
//~| ERROR private type `aliases_priv::Priv` in public interface
}

Expand Down
42 changes: 36 additions & 6 deletions src/test/ui/privacy/private-in-public.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,36 @@ LL | pub fn f2() -> Priv { panic!() } //~ ERROR private type `types::Pri
error[E0445]: private trait `traits::PrivTr` in public interface
--> $DIR/private-in-public.rs:31:5
|
LL | trait PrivTr {}
| - `traits::PrivTr` declared as private
...
LL | pub enum E<T: PrivTr> { V(T) } //~ ERROR private trait `traits::PrivTr` in public interface
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0445]: private trait `traits::PrivTr` in public interface
--> $DIR/private-in-public.rs:32:5
|
LL | trait PrivTr {}
| - `traits::PrivTr` declared as private
...
LL | pub fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0445]: private trait `traits::PrivTr` in public interface
--> $DIR/private-in-public.rs:33:5
|
LL | trait PrivTr {}
| - `traits::PrivTr` declared as private
...
LL | pub struct S1<T: PrivTr>(T); //~ ERROR private trait `traits::PrivTr` in public interface
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0445]: private trait `traits::PrivTr` in public interface
--> $DIR/private-in-public.rs:34:5
|
LL | trait PrivTr {}
| - `traits::PrivTr` declared as private
...
LL | / impl<T: PrivTr> Pub<T> { //~ ERROR private trait `traits::PrivTr` in public interface
LL | | pub fn f<U: PrivTr>(arg: U) {} //~ ERROR private trait `traits::PrivTr` in public interface
LL | | }
Expand All @@ -108,30 +120,45 @@ LL | | }
error[E0445]: private trait `traits::PrivTr` in public interface
--> $DIR/private-in-public.rs:35:9
|
LL | trait PrivTr {}
| - `traits::PrivTr` declared as private
...
LL | pub fn f<U: PrivTr>(arg: U) {} //~ ERROR private trait `traits::PrivTr` in public interface
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0445]: private trait `traits_where::PrivTr` in public interface
--> $DIR/private-in-public.rs:44:5
|
LL | trait PrivTr {}
| - `traits_where::PrivTr` declared as private
...
LL | pub enum E<T> where T: PrivTr { V(T) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0445]: private trait `traits_where::PrivTr` in public interface
--> $DIR/private-in-public.rs:46:5
|
LL | trait PrivTr {}
| - `traits_where::PrivTr` declared as private
...
LL | pub fn f<T>(arg: T) where T: PrivTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0445]: private trait `traits_where::PrivTr` in public interface
--> $DIR/private-in-public.rs:48:5
|
LL | trait PrivTr {}
| - `traits_where::PrivTr` declared as private
...
LL | pub struct S1<T>(T) where T: PrivTr;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0445]: private trait `traits_where::PrivTr` in public interface
--> $DIR/private-in-public.rs:50:5
|
LL | trait PrivTr {}
| - `traits_where::PrivTr` declared as private
...
LL | / impl<T> Pub<T> where T: PrivTr {
LL | | //~^ ERROR private trait `traits_where::PrivTr` in public interface
LL | | pub fn f<U>(arg: U) where U: PrivTr {}
Expand All @@ -142,6 +169,9 @@ LL | | }
error[E0445]: private trait `traits_where::PrivTr` in public interface
--> $DIR/private-in-public.rs:52:9
|
LL | trait PrivTr {}
| - `traits_where::PrivTr` declared as private
...
LL | pub fn f<U>(arg: U) where U: PrivTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

Expand Down Expand Up @@ -181,14 +211,14 @@ LL | struct Priv;
LL | pub fn f(arg: Priv) {} //~ ERROR private type `impls::Priv` in public interface
| ^^^^^^^^^^^^^^^^^^^^^^ can't leak private type

error[E0446]: private type `<aliases_pub::Priv as aliases_pub::PrivTr>::Assoc` in public interface
error[E0445]: private trait `aliases_pub::PrivTr` in public interface
--> $DIR/private-in-public.rs:104:5
|
LL | trait PrivTr {
| - `<aliases_pub::Priv as aliases_pub::PrivTr>::Assoc` declared as private
| - `aliases_pub::PrivTr` declared as private
...
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public.rs:104:5
Expand Down Expand Up @@ -226,14 +256,14 @@ LL | struct Priv2;
LL | pub fn f2(arg: PrivAlias) {} //~ ERROR private type `aliases_priv::Priv2` in public interface
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type

error[E0446]: private type `<aliases_priv::Priv as aliases_priv::PrivTr>::Assoc` in public interface
error[E0445]: private trait `aliases_priv::PrivTr` in public interface
--> $DIR/private-in-public.rs:133:5
|
LL | trait PrivTr {
| - `<aliases_priv::Priv as aliases_priv::PrivTr>::Assoc` declared as private
| - `aliases_priv::PrivTr` declared as private
...
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait

error[E0446]: private type `aliases_priv::Priv` in public interface
--> $DIR/private-in-public.rs:133:5
Expand Down

0 comments on commit 8b1c424

Please sign in to comment.