Skip to content

Commit 8dcd26a

Browse files
committed
Add tests for associated item privacy
1 parent 7eb64b8 commit 8dcd26a

File tree

3 files changed

+349
-0
lines changed

3 files changed

+349
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(decl_macro, associated_type_defaults)]
12+
#![allow(unused, private_in_public)]
13+
14+
mod priv_nominal {
15+
pub struct Pub;
16+
impl Pub {
17+
fn method(&self) {}
18+
const CONST: u8 = 0;
19+
// type AssocTy = u8;
20+
}
21+
22+
pub macro mac() {
23+
let value = Pub::method;
24+
//~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
25+
value;
26+
//~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
27+
Pub.method();
28+
//~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
29+
Pub::CONST;
30+
//FIXME ERROR associated constant `CONST` is private
31+
// let _: Pub::AssocTy;
32+
// pub type InSignatureTy = Pub::AssocTy;
33+
}
34+
}
35+
fn priv_nominal() {
36+
priv_nominal::mac!();
37+
}
38+
39+
mod priv_signature {
40+
struct Priv;
41+
pub struct Pub;
42+
impl Pub {
43+
pub fn method(&self, arg: Priv) {}
44+
}
45+
46+
pub macro mac() {
47+
let value = Pub::method;
48+
//~^ ERROR type `priv_signature::Priv` is private
49+
value;
50+
//~^ ERROR type `priv_signature::Priv` is private
51+
Pub.method(loop {});
52+
//~^ ERROR type `priv_signature::Priv` is private
53+
}
54+
}
55+
fn priv_signature() {
56+
priv_signature::mac!();
57+
}
58+
59+
mod priv_substs {
60+
struct Priv;
61+
pub struct Pub;
62+
impl Pub {
63+
pub fn method<T>(&self) {}
64+
}
65+
66+
pub macro mac() {
67+
let value = Pub::method::<Priv>;
68+
//~^ ERROR type `priv_substs::Priv` is private
69+
value;
70+
//~^ ERROR type `priv_substs::Priv` is private
71+
Pub.method::<Priv>();
72+
//~^ ERROR type `priv_substs::Priv` is private
73+
}
74+
}
75+
fn priv_substs() {
76+
priv_substs::mac!();
77+
}
78+
79+
mod priv_parent_substs {
80+
struct Priv;
81+
pub struct Pub<T = Priv>(T);
82+
impl Pub<Priv> {
83+
pub fn method(&self) {}
84+
pub fn static_method() {}
85+
pub const CONST: u8 = 0;
86+
// pub type AssocTy = u8;
87+
}
88+
89+
pub macro mac() {
90+
let value = <Pub>::method;
91+
//~^ ERROR type `priv_parent_substs::Priv` is private
92+
value;
93+
//~^ ERROR type `priv_parent_substs::Priv` is private
94+
let value = Pub::method;
95+
//~^ ERROR type `priv_parent_substs::Priv` is private
96+
value;
97+
//~^ ERROR type `priv_parent_substs::Priv` is private
98+
let value = <Pub>::static_method;
99+
//~^ ERROR type `priv_parent_substs::Priv` is private
100+
value;
101+
//~^ ERROR type `priv_parent_substs::Priv` is private
102+
let value = Pub::static_method;
103+
//~^ ERROR type `priv_parent_substs::Priv` is private
104+
value;
105+
//~^ ERROR type `priv_parent_substs::Priv` is private
106+
Pub(Priv).method();
107+
//~^ ERROR type `priv_parent_substs::Priv` is private
108+
109+
<Pub>::CONST;
110+
//~^ ERROR type `priv_parent_substs::Priv` is private
111+
Pub::CONST;
112+
//~^ ERROR type `priv_parent_substs::Priv` is private
113+
114+
// let _: Pub::AssocTy;
115+
// pub type InSignatureTy = Pub::AssocTy;
116+
}
117+
}
118+
fn priv_parent_substs() {
119+
priv_parent_substs::mac!();
120+
}
121+
122+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-tidy-linelength
12+
13+
#![feature(decl_macro, associated_type_defaults)]
14+
#![allow(unused, private_in_public)]
15+
16+
mod priv_trait {
17+
trait PrivTr {
18+
fn method(&self) {}
19+
const CONST: u8 = 0;
20+
type AssocTy = u8;
21+
}
22+
pub struct Pub;
23+
impl PrivTr for Pub {}
24+
pub trait PubTr: PrivTr {}
25+
26+
pub macro mac() {
27+
let value = <Pub as PrivTr>::method;
28+
//~^ ERROR type `for<'r> fn(&'r priv_trait::Pub) {<priv_trait::Pub as priv_trait::PrivTr>::method}` is private
29+
value;
30+
//~^ ERROR type `for<'r> fn(&'r priv_trait::Pub) {<priv_trait::Pub as priv_trait::PrivTr>::method}` is private
31+
Pub.method();
32+
//~^ ERROR type `for<'r> fn(&'r Self) {<Self as priv_trait::PrivTr>::method}` is private
33+
<Pub as PrivTr>::CONST;
34+
//FIXME ERROR associated constant `path(PrivTr::CONST)` is private
35+
let _: <Pub as PrivTr>::AssocTy;
36+
//~^ ERROR trait `priv_trait::PrivTr` is private
37+
//~| ERROR trait `priv_trait::PrivTr` is private
38+
pub type InSignatureTy = <Pub as PrivTr>::AssocTy;
39+
//~^ ERROR trait `priv_trait::PrivTr` is private
40+
//~| ERROR trait `path(PrivTr)` is private
41+
pub trait InSignatureTr: PrivTr {}
42+
//FIXME ERROR trait `priv_trait::PrivTr` is private
43+
impl PrivTr for u8 {}
44+
//FIXME ERROR trait `priv_trait::PrivTr` is private
45+
}
46+
}
47+
fn priv_trait() {
48+
priv_trait::mac!();
49+
}
50+
51+
mod priv_signature {
52+
pub trait PubTr {
53+
fn method(&self, arg: Priv) {}
54+
}
55+
struct Priv;
56+
pub struct Pub;
57+
impl PubTr for Pub {}
58+
59+
pub macro mac() {
60+
let value = <Pub as PubTr>::method;
61+
//~^ ERROR type `priv_signature::Priv` is private
62+
value;
63+
//~^ ERROR type `priv_signature::Priv` is private
64+
Pub.method(loop {});
65+
//~^ ERROR type `priv_signature::Priv` is private
66+
}
67+
}
68+
fn priv_signature() {
69+
priv_signature::mac!();
70+
}
71+
72+
mod priv_substs {
73+
pub trait PubTr {
74+
fn method<T>(&self) {}
75+
}
76+
struct Priv;
77+
pub struct Pub;
78+
impl PubTr for Pub {}
79+
80+
pub macro mac() {
81+
let value = <Pub as PubTr>::method::<Priv>;
82+
//~^ ERROR type `priv_substs::Priv` is private
83+
value;
84+
//~^ ERROR type `priv_substs::Priv` is private
85+
Pub.method::<Priv>();
86+
//~^ ERROR type `priv_substs::Priv` is private
87+
}
88+
}
89+
fn priv_substs() {
90+
priv_substs::mac!();
91+
}
92+
93+
mod priv_parent_substs {
94+
pub trait PubTr<T = Priv> {
95+
fn method(&self) {}
96+
const CONST: u8 = 0;
97+
type AssocTy = u8;
98+
}
99+
struct Priv;
100+
pub struct Pub;
101+
impl PubTr<Priv> for Pub {}
102+
impl PubTr<Pub> for Priv {}
103+
104+
pub macro mac() {
105+
let value = <Pub as PubTr>::method;
106+
//~^ ERROR type `priv_parent_substs::Priv` is private
107+
value;
108+
//~^ ERROR type `priv_parent_substs::Priv` is private
109+
let value = <Pub as PubTr<_>>::method;
110+
//~^ ERROR type `priv_parent_substs::Priv` is private
111+
value;
112+
//~^ ERROR type `priv_parent_substs::Priv` is private
113+
Pub.method();
114+
//~^ ERROR type `priv_parent_substs::Priv` is private
115+
116+
let value = <Priv as PubTr<_>>::method;
117+
//~^ ERROR type `priv_parent_substs::Priv` is private
118+
value;
119+
//~^ ERROR type `priv_parent_substs::Priv` is private
120+
Priv.method();
121+
//~^ ERROR type `priv_parent_substs::Priv` is private
122+
123+
<Pub as PubTr>::CONST;
124+
//~^ ERROR type `priv_parent_substs::Priv` is private
125+
<Pub as PubTr<_>>::CONST;
126+
//~^ ERROR type `priv_parent_substs::Priv` is private
127+
<Priv as PubTr<_>>::CONST;
128+
//~^ ERROR type `priv_parent_substs::Priv` is private
129+
130+
let _: <Pub as PubTr>::AssocTy;
131+
//~^ ERROR type `priv_parent_substs::Priv` is private
132+
//~| ERROR type `priv_parent_substs::Priv` is private
133+
let _: <Pub as PubTr<_>>::AssocTy;
134+
//~^ ERROR type `priv_parent_substs::Priv` is private
135+
//~| ERROR type `priv_parent_substs::Priv` is private
136+
let _: <Priv as PubTr<_>>::AssocTy;
137+
//~^ ERROR type `priv_parent_substs::Priv` is private
138+
//~| ERROR type `priv_parent_substs::Priv` is private
139+
140+
pub type InSignatureTy1 = <Pub as PubTr>::AssocTy;
141+
//~^ ERROR type `priv_parent_substs::Priv` is private
142+
pub type InSignatureTy2 = <Priv as PubTr<Pub>>::AssocTy;
143+
//~^ ERROR type `priv_parent_substs::Priv` is private
144+
impl PubTr for u8 {}
145+
//FIXME ERROR type `priv_parent_substs::Priv` is private
146+
}
147+
}
148+
fn priv_parent_substs() {
149+
priv_parent_substs::mac!();
150+
}
151+
152+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(decl_macro, associated_type_defaults)]
12+
#![allow(unused, private_in_public)]
13+
14+
mod priv_trait {
15+
trait PrivTr {
16+
type AssocTy = u8;
17+
}
18+
pub trait PubTr: PrivTr {}
19+
20+
pub macro mac1() {
21+
let _: Box<PubTr<AssocTy = u8>>;
22+
//~^ ERROR type `priv_trait::PubTr<AssocTy=u8> + '<empty>` is private
23+
//~| ERROR type `priv_trait::PubTr<AssocTy=u8> + '<empty>` is private
24+
type InSignatureTy2 = Box<PubTr<AssocTy = u8>>;
25+
//~^ ERROR type `priv_trait::PubTr<AssocTy=u8> + 'static` is private
26+
trait InSignatureTr2: PubTr<AssocTy = u8> {}
27+
//FIXME ERROR trait `priv_trait::PrivTr` is private
28+
}
29+
pub macro mac2() {
30+
let _: Box<PrivTr<AssocTy = u8>>;
31+
//~^ ERROR type `priv_trait::PrivTr<AssocTy=u8> + '<empty>` is private
32+
//~| ERROR type `priv_trait::PrivTr<AssocTy=u8> + '<empty>` is private
33+
type InSignatureTy1 = Box<PrivTr<AssocTy = u8>>;
34+
//~^ ERROR type `priv_trait::PrivTr<AssocTy=u8> + 'static` is private
35+
//~| ERROR trait `path(PrivTr<AssocTy = u8>)` is private
36+
trait InSignatureTr1: PrivTr<AssocTy = u8> {}
37+
//FIXME ERROR trait `priv_trait::PrivTr` is private
38+
}
39+
}
40+
fn priv_trait1() {
41+
priv_trait::mac1!();
42+
}
43+
fn priv_trait2() {
44+
priv_trait::mac2!();
45+
}
46+
47+
mod priv_parent_substs {
48+
pub trait PubTrWithParam<T = Priv> {
49+
type AssocTy = u8;
50+
}
51+
struct Priv;
52+
pub trait PubTr: PubTrWithParam<Priv> {}
53+
54+
pub macro mac() {
55+
let _: Box<PubTrWithParam<AssocTy = u8>>;
56+
//~^ ERROR type `priv_parent_substs::Priv` is private
57+
//~| ERROR type `priv_parent_substs::Priv` is private
58+
let _: Box<PubTr<AssocTy = u8>>;
59+
//~^ ERROR type `priv_parent_substs::Priv` is private
60+
//~| ERROR type `priv_parent_substs::Priv` is private
61+
pub type InSignatureTy1 = Box<PubTrWithParam<AssocTy = u8>>;
62+
//~^ ERROR type `priv_parent_substs::Priv` is private
63+
pub type InSignatureTy2 = Box<PubTr<AssocTy = u8>>;
64+
//~^ ERROR type `priv_parent_substs::Priv` is private
65+
trait InSignatureTr1: PubTrWithParam<AssocTy = u8> {}
66+
//FIXME ERROR type `priv_parent_substs::Priv` is private
67+
trait InSignatureTr2: PubTr<AssocTy = u8> {}
68+
//FIXME ERROR type `priv_parent_substs::Priv` is private
69+
}
70+
}
71+
fn priv_parent_substs() {
72+
priv_parent_substs::mac!();
73+
}
74+
75+
fn main() {}

0 commit comments

Comments
 (0)