privacy: Use common DefId visiting infra for all privacy visitors

This commit is contained in:
Vadim Petrochenkov 2018-12-16 16:18:45 +03:00
parent 6efaef6189
commit 8b1c424b6d
17 changed files with 571 additions and 539 deletions

View File

@ -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)]

File diff suppressed because it is too large Load Diff

View File

@ -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;

View File

@ -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")]

View File

@ -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() {}

View File

@ -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

View File

@ -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 {}
}

View File

@ -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,

View File

@ -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() {}

View File

@ -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
}

View File

@ -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

View File

@ -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() {}

View File

@ -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

View File

@ -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 {

View File

@ -297,8 +297,17 @@ 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 {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -306,17 +315,8 @@ 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
|
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
--> $DIR/private-in-public-warn.rs:250:5
|
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -324,6 +324,15 @@ 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: 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 36 previous errors
For more information about this error, try `rustc --explain E0446`.

View File

@ -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 {
@ -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
}

View File

@ -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 | | }
@ -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 {}
@ -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
@ -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
@ -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