From 8dcd26a6df4bb932cd94404a6c941d84a3d1d851 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 23 Sep 2017 20:48:08 +0300 Subject: [PATCH] Add tests for associated item privacy --- .../associated-item-privacy-inherent.rs | 122 ++++++++++++++ .../privacy/associated-item-privacy-trait.rs | 152 ++++++++++++++++++ .../associated-item-privacy-type-binding.rs | 75 +++++++++ 3 files changed, 349 insertions(+) create mode 100644 src/test/compile-fail/privacy/associated-item-privacy-inherent.rs create mode 100644 src/test/compile-fail/privacy/associated-item-privacy-trait.rs create mode 100644 src/test/compile-fail/privacy/associated-item-privacy-type-binding.rs diff --git a/src/test/compile-fail/privacy/associated-item-privacy-inherent.rs b/src/test/compile-fail/privacy/associated-item-privacy-inherent.rs new file mode 100644 index 000000000000..d742a3a19422 --- /dev/null +++ b/src/test/compile-fail/privacy/associated-item-privacy-inherent.rs @@ -0,0 +1,122 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(decl_macro, associated_type_defaults)] +#![allow(unused, private_in_public)] + +mod priv_nominal { + pub struct Pub; + impl Pub { + fn method(&self) {} + const CONST: u8 = 0; + // type AssocTy = u8; + } + + pub macro mac() { + let value = Pub::method; + //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private + value; + //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private + Pub.method(); + //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private + Pub::CONST; + //FIXME ERROR associated constant `CONST` is private + // let _: Pub::AssocTy; + // pub type InSignatureTy = Pub::AssocTy; + } +} +fn priv_nominal() { + priv_nominal::mac!(); +} + +mod priv_signature { + struct Priv; + pub struct Pub; + impl Pub { + pub fn method(&self, arg: Priv) {} + } + + pub macro mac() { + let value = Pub::method; + //~^ ERROR type `priv_signature::Priv` is private + value; + //~^ ERROR type `priv_signature::Priv` is private + Pub.method(loop {}); + //~^ ERROR type `priv_signature::Priv` is private + } +} +fn priv_signature() { + priv_signature::mac!(); +} + +mod priv_substs { + struct Priv; + pub struct Pub; + impl Pub { + pub fn method(&self) {} + } + + pub macro mac() { + let value = Pub::method::; + //~^ ERROR type `priv_substs::Priv` is private + value; + //~^ ERROR type `priv_substs::Priv` is private + Pub.method::(); + //~^ ERROR type `priv_substs::Priv` is private + } +} +fn priv_substs() { + priv_substs::mac!(); +} + +mod priv_parent_substs { + struct Priv; + pub struct Pub(T); + impl Pub { + pub fn method(&self) {} + pub fn static_method() {} + pub const CONST: u8 = 0; + // pub type AssocTy = u8; + } + + pub macro mac() { + let value = ::method; + //~^ ERROR type `priv_parent_substs::Priv` is private + value; + //~^ ERROR type `priv_parent_substs::Priv` is private + let value = Pub::method; + //~^ ERROR type `priv_parent_substs::Priv` is private + value; + //~^ ERROR type `priv_parent_substs::Priv` is private + let value = ::static_method; + //~^ ERROR type `priv_parent_substs::Priv` is private + value; + //~^ ERROR type `priv_parent_substs::Priv` is private + let value = Pub::static_method; + //~^ ERROR type `priv_parent_substs::Priv` is private + value; + //~^ ERROR type `priv_parent_substs::Priv` is private + Pub(Priv).method(); + //~^ ERROR type `priv_parent_substs::Priv` is private + + ::CONST; + //~^ ERROR type `priv_parent_substs::Priv` is private + Pub::CONST; + //~^ ERROR type `priv_parent_substs::Priv` is private + + // let _: Pub::AssocTy; + // pub type InSignatureTy = Pub::AssocTy; + } +} +fn priv_parent_substs() { + priv_parent_substs::mac!(); +} + +fn main() {} diff --git a/src/test/compile-fail/privacy/associated-item-privacy-trait.rs b/src/test/compile-fail/privacy/associated-item-privacy-trait.rs new file mode 100644 index 000000000000..d68c50228490 --- /dev/null +++ b/src/test/compile-fail/privacy/associated-item-privacy-trait.rs @@ -0,0 +1,152 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-tidy-linelength + +#![feature(decl_macro, associated_type_defaults)] +#![allow(unused, private_in_public)] + +mod priv_trait { + trait PrivTr { + fn method(&self) {} + const CONST: u8 = 0; + type AssocTy = u8; + } + pub struct Pub; + impl PrivTr for Pub {} + pub trait PubTr: PrivTr {} + + pub macro mac() { + let value = ::method; + //~^ ERROR type `for<'r> fn(&'r priv_trait::Pub) {::method}` is private + value; + //~^ ERROR type `for<'r> fn(&'r priv_trait::Pub) {::method}` is private + Pub.method(); + //~^ ERROR type `for<'r> fn(&'r Self) {::method}` is private + ::CONST; + //FIXME ERROR associated constant `path(PrivTr::CONST)` is private + let _: ::AssocTy; + //~^ ERROR trait `priv_trait::PrivTr` is private + //~| ERROR trait `priv_trait::PrivTr` is private + pub type InSignatureTy = ::AssocTy; + //~^ ERROR trait `priv_trait::PrivTr` is private + //~| ERROR trait `path(PrivTr)` is private + pub trait InSignatureTr: PrivTr {} + //FIXME ERROR trait `priv_trait::PrivTr` is private + impl PrivTr for u8 {} + //FIXME ERROR trait `priv_trait::PrivTr` is private + } +} +fn priv_trait() { + priv_trait::mac!(); +} + +mod priv_signature { + pub trait PubTr { + fn method(&self, arg: Priv) {} + } + struct Priv; + pub struct Pub; + impl PubTr for Pub {} + + pub macro mac() { + let value = ::method; + //~^ ERROR type `priv_signature::Priv` is private + value; + //~^ ERROR type `priv_signature::Priv` is private + Pub.method(loop {}); + //~^ ERROR type `priv_signature::Priv` is private + } +} +fn priv_signature() { + priv_signature::mac!(); +} + +mod priv_substs { + pub trait PubTr { + fn method(&self) {} + } + struct Priv; + pub struct Pub; + impl PubTr for Pub {} + + pub macro mac() { + let value = ::method::; + //~^ ERROR type `priv_substs::Priv` is private + value; + //~^ ERROR type `priv_substs::Priv` is private + Pub.method::(); + //~^ ERROR type `priv_substs::Priv` is private + } +} +fn priv_substs() { + priv_substs::mac!(); +} + +mod priv_parent_substs { + pub trait PubTr { + fn method(&self) {} + const CONST: u8 = 0; + type AssocTy = u8; + } + struct Priv; + pub struct Pub; + impl PubTr for Pub {} + impl PubTr for Priv {} + + pub macro mac() { + let value = ::method; + //~^ ERROR type `priv_parent_substs::Priv` is private + value; + //~^ ERROR type `priv_parent_substs::Priv` is private + let value = >::method; + //~^ ERROR type `priv_parent_substs::Priv` is private + value; + //~^ ERROR type `priv_parent_substs::Priv` is private + Pub.method(); + //~^ ERROR type `priv_parent_substs::Priv` is private + + let value = >::method; + //~^ ERROR type `priv_parent_substs::Priv` is private + value; + //~^ ERROR type `priv_parent_substs::Priv` is private + Priv.method(); + //~^ ERROR type `priv_parent_substs::Priv` is private + + ::CONST; + //~^ ERROR type `priv_parent_substs::Priv` is private + >::CONST; + //~^ ERROR type `priv_parent_substs::Priv` is private + >::CONST; + //~^ ERROR type `priv_parent_substs::Priv` is private + + let _: ::AssocTy; + //~^ ERROR type `priv_parent_substs::Priv` is private + //~| ERROR type `priv_parent_substs::Priv` is private + let _: >::AssocTy; + //~^ ERROR type `priv_parent_substs::Priv` is private + //~| ERROR type `priv_parent_substs::Priv` is private + let _: >::AssocTy; + //~^ ERROR type `priv_parent_substs::Priv` is private + //~| ERROR type `priv_parent_substs::Priv` is private + + pub type InSignatureTy1 = ::AssocTy; + //~^ ERROR type `priv_parent_substs::Priv` is private + pub type InSignatureTy2 = >::AssocTy; + //~^ ERROR type `priv_parent_substs::Priv` is private + impl PubTr for u8 {} + //FIXME ERROR type `priv_parent_substs::Priv` is private + } +} +fn priv_parent_substs() { + priv_parent_substs::mac!(); +} + +fn main() {} diff --git a/src/test/compile-fail/privacy/associated-item-privacy-type-binding.rs b/src/test/compile-fail/privacy/associated-item-privacy-type-binding.rs new file mode 100644 index 000000000000..f191ff14dce6 --- /dev/null +++ b/src/test/compile-fail/privacy/associated-item-privacy-type-binding.rs @@ -0,0 +1,75 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(decl_macro, associated_type_defaults)] +#![allow(unused, private_in_public)] + +mod priv_trait { + trait PrivTr { + type AssocTy = u8; + } + pub trait PubTr: PrivTr {} + + pub macro mac1() { + let _: Box>; + //~^ ERROR type `priv_trait::PubTr + '` is private + //~| ERROR type `priv_trait::PubTr + '` is private + type InSignatureTy2 = Box>; + //~^ ERROR type `priv_trait::PubTr + 'static` is private + trait InSignatureTr2: PubTr {} + //FIXME ERROR trait `priv_trait::PrivTr` is private + } + pub macro mac2() { + let _: Box>; + //~^ ERROR type `priv_trait::PrivTr + '` is private + //~| ERROR type `priv_trait::PrivTr + '` is private + type InSignatureTy1 = Box>; + //~^ ERROR type `priv_trait::PrivTr + 'static` is private + //~| ERROR trait `path(PrivTr)` is private + trait InSignatureTr1: PrivTr {} + //FIXME ERROR trait `priv_trait::PrivTr` is private + } +} +fn priv_trait1() { + priv_trait::mac1!(); +} +fn priv_trait2() { + priv_trait::mac2!(); +} + +mod priv_parent_substs { + pub trait PubTrWithParam { + type AssocTy = u8; + } + struct Priv; + pub trait PubTr: PubTrWithParam {} + + pub macro mac() { + let _: Box>; + //~^ ERROR type `priv_parent_substs::Priv` is private + //~| ERROR type `priv_parent_substs::Priv` is private + let _: Box>; + //~^ ERROR type `priv_parent_substs::Priv` is private + //~| ERROR type `priv_parent_substs::Priv` is private + pub type InSignatureTy1 = Box>; + //~^ ERROR type `priv_parent_substs::Priv` is private + pub type InSignatureTy2 = Box>; + //~^ ERROR type `priv_parent_substs::Priv` is private + trait InSignatureTr1: PubTrWithParam {} + //FIXME ERROR type `priv_parent_substs::Priv` is private + trait InSignatureTr2: PubTr {} + //FIXME ERROR type `priv_parent_substs::Priv` is private + } +} +fn priv_parent_substs() { + priv_parent_substs::mac!(); +} + +fn main() {}