diff --git a/src/test/compile-fail/issue-22912.rs b/src/test/compile-fail/issue-22912.rs deleted file mode 100644 index c619f771fda..00000000000 --- a/src/test/compile-fail/issue-22912.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2015 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. - -pub struct PublicType; -struct PrivateType; - -pub trait PublicTrait { - type Item; -} - -trait PrivateTrait { - type Item; -} - -impl PublicTrait for PublicType { - type Item = PrivateType; //~ ERROR private type in public interface -} - -// OK -impl PublicTrait for PrivateType { - type Item = PrivateType; -} - -// OK -impl PrivateTrait for PublicType { - type Item = PrivateType; -} - -// OK -impl PrivateTrait for PrivateType { - type Item = PrivateType; -} - -fn main() {} diff --git a/src/test/compile-fail/issue-28325.rs b/src/test/compile-fail/issue-28325.rs deleted file mode 100644 index 34a62384693..00000000000 --- a/src/test/compile-fail/issue-28325.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015 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. - -// Checks for private types in public interfaces - -#![feature(rustc_attrs)] -#![allow(dead_code, unused_variables)] - -mod y { - pub struct Foo { x: u32 } - - struct Bar { x: u32 } - - impl Foo { - pub fn foo(&self, x: Self, y: Bar) { } //~ WARN private type in public interface - } -} - -mod x { - pub struct Foo { pub x: u32 } - - struct Bar { _x: u32 } - - impl Foo { - pub fn foo(&self, _x: Self, _y: Bar) { } //~ WARN private type in public interface - pub fn bar(&self) -> Bar { Bar { _x: self.x } } - //~^ WARN private type in public interface - } -} - -#[rustc_error] -pub fn main() { //~ ERROR compilation successful - let f = x::Foo { x: 4 }; - let b = f.bar(); - f.foo(x::Foo { x: 5 }, b); -} diff --git a/src/test/compile-fail/issue-28450.rs b/src/test/compile-fail/issue-28450.rs deleted file mode 100644 index 65c5978103a..00000000000 --- a/src/test/compile-fail/issue-28450.rs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2015 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. - -// Checks for private types in public interfaces - -#![feature(rustc_attrs)] - -struct Priv; - -pub use self::private::public; - -mod private { - pub type Priv = super::Priv; //~ WARN private type in public interface - - pub fn public(_x: Priv) { - } -} - -struct __CFArray; -pub type CFArrayRef = *const __CFArray; //~ WARN private type in public interface -trait Pointer { type Pointee; } -impl Pointer for *const T { type Pointee = T; } -pub type __CFArrayRevealed = ::Pointee; -//~^ WARN private type in public interface - -pub trait Exporter { - type Output; -} -pub struct Helper; - -pub fn block() -> ::Output { - struct Inner; - impl Inner { - fn poke(&self) { println!("Hello!"); } - } - - impl Exporter for Helper { - type Output = Inner; //~ WARN private type in public interface - } - - Inner -} - -#[rustc_error] -fn main() { //~ ERROR compilation successful - block().poke(); -} diff --git a/src/test/compile-fail/lint-visible-private-types-1.rs b/src/test/compile-fail/lint-visible-private-types-1.rs deleted file mode 100644 index 939f2400d1b..00000000000 --- a/src/test/compile-fail/lint-visible-private-types-1.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2014 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(rustc_attrs)] -#![allow(dead_code)] - -use std::marker; - -struct Private(marker::PhantomData); -pub struct Public(marker::PhantomData); - -pub trait PubTrait { - type Output; -} - -type PrivAlias = Public; - -trait PrivTrait2 { - type Alias; -} -impl PrivTrait2 for Private { - type Alias = Public; -} - -impl PubTrait for PrivAlias { - type Output = Private; //~ WARN private type in public interface -} - -impl PubTrait for as PrivTrait2>::Alias { - type Output = Private; //~ WARN private type in public interface -} - -type PrivAliasPubType = u8; -pub fn f1(_: PrivAliasPubType) {} // Ok, not an error - -type PrivAliasGeneric> = T; -pub fn f2(_: PrivAliasGeneric) {} // Ok, not an error - -#[rustc_error] -fn main() {} //~ ERROR compilation successful diff --git a/src/test/compile-fail/lint-visible-private-types.rs b/src/test/compile-fail/lint-visible-private-types.rs deleted file mode 100644 index e9890dc32b7..00000000000 --- a/src/test/compile-fail/lint-visible-private-types.rs +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2014 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. - -#![allow(dead_code)] -#![crate_type="lib"] - -use std::marker; - -struct Private(marker::PhantomData); -pub struct Public(marker::PhantomData); - -impl Private> { - pub fn a(&self) -> Private { panic!() } - fn b(&self) -> Private { panic!() } - - pub fn c() -> Private { panic!() } - fn d() -> Private { panic!() } -} -impl Private { - pub fn e(&self) -> Private { panic!() } - fn f(&self) -> Private { panic!() } -} - -impl Public> { - pub fn a(&self) -> Private { panic!() } - fn b(&self) -> Private { panic!() } - - pub fn c() -> Private { panic!() } - fn d() -> Private { panic!() } -} -impl Public { - pub fn e(&self) -> Private { panic!() } //~ ERROR private type in public interface - fn f(&self) -> Private { panic!() } -} - -pub fn x(_: Private) {} //~ ERROR private type in public interface - -fn y(_: Private) {} - - -pub struct Foo { - pub x: Private, //~ ERROR private type in public interface - y: Private -} - -struct Bar { - x: Private, -} - -pub enum Baz { - Baz1(Private), //~ ERROR private type in public interface - Baz2 { - y: Private //~ ERROR private type in public interface - }, -} - -enum Qux { - Qux1(Private), - Qux2 { - x: Private, - } -} - -pub trait PubTrait { - fn foo(&self) -> Private { panic!( )} //~ ERROR private type in public interface - fn bar(&self) -> Private; //~ ERROR private type in public interface - fn baz() -> Private; //~ ERROR private type in public interface -} - -impl PubTrait for Public { - fn bar(&self) -> Private { panic!() } // Warns in lint checking phase - fn baz() -> Private { panic!() } // Warns in lint checking phase -} -impl PubTrait for Public> { - fn bar(&self) -> Private { panic!() } - fn baz() -> Private { panic!() } -} - -impl PubTrait for Private { - fn bar(&self) -> Private { panic!() } - fn baz() -> Private { panic!() } -} -impl PubTrait for (Private,) { - fn bar(&self) -> Private { panic!() } - fn baz() -> Private { panic!() } -} - - -trait PrivTrait { - fn foo(&self) -> Private { panic!( )} - fn bar(&self) -> Private; -} -impl PrivTrait for Private { - fn bar(&self) -> Private { panic!() } -} -impl PrivTrait for (Private,) { - fn bar(&self) -> Private { panic!() } -} - -pub trait ParamTrait { - fn foo() -> T; -} - -impl ParamTrait> - for Public { - fn foo() -> Private { panic!() } -} - -impl ParamTrait> for Private { - fn foo() -> Private { panic!( )} -} - -impl>> //~ ERROR private type in public interface - ParamTrait for Public { - fn foo() -> T { panic!() } -} - -type PrivAliasPrivType = Private; -pub fn f1(_: PrivAliasPrivType) {} //~ ERROR private type in public interface - -type PrivAliasGeneric> = T; -pub fn f2(_: PrivAliasGeneric) {} //~ ERROR private type in public interface - -type Result = std::result::Result>; -pub fn f3(_: Result) {} //~ ERROR private type in public interface diff --git a/src/test/compile-fail/priv_in_pub_sig_priv_mod.rs b/src/test/compile-fail/priv_in_pub_sig_priv_mod.rs deleted file mode 100644 index cca6143ed40..00000000000 --- a/src/test/compile-fail/priv_in_pub_sig_priv_mod.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2015 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. - -// Test that we properly check for private types in public signatures, even -// inside a private module (#22261). - -mod a { - struct Priv; - - pub fn expose_a() -> Priv { //~Error: private type in public interface - panic!(); - } - - mod b { - pub fn expose_b() -> super::Priv { //~Error: private type in public interface - panic!(); - } - } -} - -pub fn main() {} diff --git a/src/test/compile-fail/lint-private-in-public.rs b/src/test/compile-fail/private-in-public-lint.rs similarity index 100% rename from src/test/compile-fail/lint-private-in-public.rs rename to src/test/compile-fail/private-in-public-lint.rs diff --git a/src/test/compile-fail/private-in-public-warn.rs b/src/test/compile-fail/private-in-public-warn.rs new file mode 100644 index 00000000000..8128fde4de5 --- /dev/null +++ b/src/test/compile-fail/private-in-public-warn.rs @@ -0,0 +1,254 @@ +// Copyright 2015 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. + +// Private types and traits are not allowed in public interfaces. +// This test also ensures that the checks are performed even inside private modules. + +#![feature(rustc_attrs)] +#![feature(associated_consts)] +#![feature(associated_type_defaults)] +#![allow(dead_code)] +#![allow(unused_variables)] +#![allow(improper_ctypes)] + +mod types { + struct Priv; + pub struct Pub; + pub trait PubTr { + type Alias; + } + + pub type Alias = Priv; //~ WARN private type in public interface + pub enum E { + V1(Priv), //~ WARN private type in public interface + V2 { field: Priv }, //~ WARN private type in public interface + } + pub trait Tr { + const C: Priv = Priv; //~ WARN private type in public interface + type Alias = Priv; //~ WARN private type in public interface + fn f1(arg: Priv) {} //~ WARN private type in public interface + fn f2() -> Priv { panic!() } //~ WARN private type in public interface + } + extern { + pub static ES: Priv; //~ WARN private type in public interface + pub fn ef1(arg: Priv); //~ WARN private type in public interface + pub fn ef2() -> Priv; //~ WARN private type in public interface + } + impl PubTr for Pub { + type Alias = Priv; //~ WARN private type in public interface + } +} + +mod traits { + trait PrivTr {} + pub struct Pub(T); + pub trait PubTr {} + + pub type Alias = T; //~ WARN private trait in public interface + //~^ WARN trait bounds are not (yet) enforced in type definitions + pub trait Tr1: PrivTr {} //~ WARN private trait in public interface + pub trait Tr2 {} //~ WARN private trait in public interface + pub trait Tr3 { + type Alias: PrivTr; //~ WARN private trait in public interface + fn f(arg: T) {} //~ WARN private trait in public interface + } + impl Pub {} //~ WARN private trait in public interface + impl PubTr for Pub {} //~ WARN private trait in public interface +} + +mod traits_where { + trait PrivTr {} + pub struct Pub(T); + pub trait PubTr {} + + pub type Alias where T: PrivTr = T; //~ WARN private trait in public interface + pub trait Tr2 where T: PrivTr {} //~ WARN private trait in public interface + pub trait Tr3 { + fn f(arg: T) where T: PrivTr {} //~ WARN private trait in public interface + } + impl Pub where T: PrivTr {} //~ WARN private trait in public interface + impl PubTr for Pub where T: PrivTr {} //~ WARN private trait in public interface +} + +mod generics { + struct Priv(T); + pub struct Pub(T); + trait PrivTr {} + pub trait PubTr {} + + pub trait Tr1: PrivTr {} //~ WARN private trait in public interface + pub trait Tr2: PubTr {} //~ WARN private type in public interface + pub trait Tr3: PubTr<[Priv; 1]> {} //~ WARN private type in public interface + pub trait Tr4: PubTr> {} //~ WARN private type in public interface +} + +mod impls { + struct Priv; + pub struct Pub; + trait PrivTr { + type Alias; + } + pub trait PubTr { + type Alias; + } + + impl Priv { + pub fn f(arg: Priv) {} // OK + } + impl PrivTr for Priv { + type Alias = Priv; // OK + } + impl PubTr for Priv { + type Alias = Priv; // OK + } + impl PrivTr for Pub { + type Alias = Priv; // OK + } + impl PubTr for Pub { + type Alias = Priv; //~ WARN private type in public interface + } +} + +mod impls_generics { + struct Priv(T); + pub struct Pub(T); + trait PrivTr { + type Alias; + } + pub trait PubTr { + type Alias; + } + + impl Priv { + pub fn f(arg: Priv) {} // OK + } + impl Pub { + pub fn f(arg: Priv) {} // OK + } + impl PrivTr for Priv { + type Alias = Priv; // OK + } + impl PubTr for Priv { + type Alias = Priv; // OK + } + impl PubTr for Priv { + type Alias = Priv; // OK + } + impl PubTr for [Priv; 1] { + type Alias = Priv; // OK + } + impl PubTr for Pub { + type Alias = Priv; // OK + } + impl PrivTr for Pub { + type Alias = Priv; // OK + } + impl PubTr for Pub { + type Alias = Priv; // OK + } +} + +mod aliases_pub { + struct Priv; + mod m { + pub struct Pub1; + pub struct Pub2; + pub struct Pub3; + pub trait PubTr { + type Check = u8; + } + } + + use self::m::Pub1 as PrivUseAlias; + use self::m::PubTr as PrivUseAliasTr; + type PrivAlias = m::Pub2; + trait PrivTr { + type AssocAlias = m::Pub3; + } + impl PrivTr for Priv {} + + pub fn f1(arg: PrivUseAlias) {} // OK + pub fn f2(arg: PrivAlias) {} // OK + + pub trait Tr1: PrivUseAliasTr {} // OK + pub trait Tr2: PrivUseAliasTr {} // OK + + impl PrivAlias { + pub fn f(arg: Priv) {} //~ WARN private type in public interface + } + // This doesn't even parse + // impl ::AssocAlias { + // pub fn f(arg: Priv) {} // WARN private type in public interface + // } + impl PrivUseAliasTr for PrivUseAlias { + type Check = Priv; //~ WARN private type in public interface + } + impl PrivUseAliasTr for PrivAlias { + type Check = Priv; //~ WARN private type in public interface + } + impl PrivUseAliasTr for ::AssocAlias { + type Check = Priv; //~ WARN private type in public interface + } +} + +mod aliases_priv { + struct Priv; + + struct Priv1; + struct Priv2; + struct Priv3; + trait PrivTr1 { + type Check = u8; + } + + use self::Priv1 as PrivUseAlias; + use self::PrivTr1 as PrivUseAliasTr; + type PrivAlias = Priv2; + //~^ WARN private type in public interface + trait PrivTr { + type AssocAlias = Priv3; + } + impl PrivTr for Priv {} + + pub trait Tr1: PrivUseAliasTr {} //~ WARN private trait in public interface + pub trait Tr2: PrivUseAliasTr {} //~ WARN private trait in public interface + //~^ WARN private type in public interface + + impl PrivUseAlias { + pub fn f(arg: Priv) {} // OK + } + impl PrivAlias { + pub fn f(arg: Priv) {} // OK + } + // This doesn't even parse + // impl ::AssocAlias { + // pub fn f(arg: Priv) {} // OK + // } + impl PrivUseAliasTr for PrivUseAlias { + type Check = Priv; // OK + } + impl PrivUseAliasTr for PrivAlias { + type Check = Priv; // OK + } + impl PrivUseAliasTr for ::AssocAlias { + type Check = Priv; // OK + } +} + +mod aliases_params { + struct Priv; + type PrivAliasGeneric = T; + type Result = ::std::result::Result; + + pub fn f1(arg: PrivAliasGeneric) {} // OK, not an error +} + +#[rustc_error] +fn main() {} //~ ERROR compilation successful diff --git a/src/test/compile-fail/private-in-public.rs b/src/test/compile-fail/private-in-public.rs new file mode 100644 index 00000000000..7d4dcfd3145 --- /dev/null +++ b/src/test/compile-fail/private-in-public.rs @@ -0,0 +1,148 @@ +// Copyright 2015 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. + +// Private types and traits are not allowed in public interfaces. +// This test also ensures that the checks are performed even inside private modules. + +#![feature(associated_consts)] +#![feature(associated_type_defaults)] + +mod types { + struct Priv; + pub struct Pub; + pub trait PubTr { + type Alias; + } + + pub const C: Priv = Priv; //~ ERROR private type in public interface + pub static S: Priv = Priv; //~ ERROR private type in public interface + pub fn f1(arg: Priv) {} //~ ERROR private type in public interface + pub fn f2() -> Priv { panic!() } //~ ERROR private type in public interface + pub struct S1(pub Priv); //~ ERROR private type in public interface + pub struct S2 { pub field: Priv } //~ ERROR private type in public interface + impl Pub { + pub const C: Priv = Priv; //~ ERROR private type in public interface + pub fn f1(arg: Priv) {} //~ ERROR private type in public interface + pub fn f2() -> Priv { panic!() } //~ ERROR private type in public interface + } +} + +mod traits { + trait PrivTr {} + pub struct Pub(T); + pub trait PubTr {} + + pub enum E { V(T) } //~ ERROR private trait in public interface + pub fn f(arg: T) {} //~ ERROR private trait in public interface + pub struct S1(T); //~ ERROR private trait in public interface + impl Pub { + pub fn f(arg: U) {} //~ ERROR private trait in public interface + } +} + +mod traits_where { + trait PrivTr {} + pub struct Pub(T); + pub trait PubTr {} + + pub enum E where T: PrivTr { V(T) } //~ ERROR private trait in public interface + pub fn f(arg: T) where T: PrivTr {} //~ ERROR private trait in public interface + pub struct S1(T) where T: PrivTr; //~ ERROR private trait in public interface + impl Pub where T: PrivTr { + pub fn f(arg: U) where U: PrivTr {} //~ ERROR private trait in public interface + } +} + +mod generics { + struct Priv(T); + pub struct Pub(T); + trait PrivTr {} + pub trait PubTr {} + + pub fn f1(arg: [Priv; 1]) {} //~ ERROR private type in public interface + pub fn f2(arg: Pub) {} //~ ERROR private type in public interface + pub fn f3(arg: Priv) {} //~ ERROR private type in public interface +} + +mod impls { + struct Priv; + pub struct Pub; + trait PrivTr { + type Alias; + } + pub trait PubTr { + type Alias; + } + + impl Pub { + pub fn f(arg: Priv) {} //~ ERROR private type in public interface + } +} + +mod aliases_pub { + struct Priv; + mod m { + pub struct Pub1; + pub struct Pub2; + pub struct Pub3; + pub trait PubTr { + type Check = u8; + } + } + + use self::m::Pub1 as PrivUseAlias; + use self::m::PubTr as PrivUseAliasTr; + type PrivAlias = m::Pub2; + trait PrivTr { + type AssocAlias = m::Pub3; + } + impl PrivTr for Priv {} + + // This should be OK, but associated type aliases are not substituted yet + pub fn f3(arg: ::AssocAlias) {} //~ ERROR private type in public interface + + impl PrivUseAlias { + pub fn f(arg: Priv) {} //~ ERROR private type in public interface + } +} + +mod aliases_priv { + struct Priv; + + struct Priv1; + struct Priv2; + struct Priv3; + trait PrivTr1 { + type Check = u8; + } + + use self::Priv1 as PrivUseAlias; + use self::PrivTr1 as PrivUseAliasTr; + type PrivAlias = Priv2; + trait PrivTr { + type AssocAlias = Priv3; + } + impl PrivTr for Priv {} + + pub fn f1(arg: PrivUseAlias) {} //~ ERROR private type in public interface + pub fn f2(arg: PrivAlias) {} //~ ERROR private type in public interface + pub fn f3(arg: ::AssocAlias) {} //~ ERROR private type in public interface +} + +mod aliases_params { + struct Priv; + type PrivAliasGeneric = T; + type Result = ::std::result::Result; + + pub fn f2(arg: PrivAliasGeneric) {} //~ ERROR private type in public interface + pub fn f3(arg: Result) {} //~ ERROR private type in public interface +} + +fn main() {} diff --git a/src/test/compile-fail/visible-private-types-generics.rs b/src/test/compile-fail/visible-private-types-generics.rs deleted file mode 100644 index 23e05479228..00000000000 --- a/src/test/compile-fail/visible-private-types-generics.rs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2014 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. - -trait Foo { - fn dummy(&self) { } -} - -pub fn f< - T - : Foo //~ ERROR private trait in public interface ->() {} - -pub fn g() where - T - : Foo //~ ERROR private trait in public interface -{} - -pub struct S; - -impl S { - pub fn f< - T - : Foo //~ ERROR private trait in public interface - >() {} - - pub fn g() where - T - : Foo //~ ERROR private trait in public interface - {} -} - -pub struct S1< - T - : Foo //~ ERROR private trait in public interface -> { - x: T -} - -pub struct S2 where - T - : Foo //~ ERROR private trait in public interface -{ - x: T -} - -pub enum E1< - T - : Foo //~ ERROR private trait in public interface -> { - V1(T) -} - -pub enum E2 where - T - : Foo //~ ERROR private trait in public interface -{ - V2(T) -} - -fn main() {} diff --git a/src/test/compile-fail/visible-private-types-supertrait.rs b/src/test/compile-fail/visible-private-types-supertrait.rs deleted file mode 100644 index 6de627a698a..00000000000 --- a/src/test/compile-fail/visible-private-types-supertrait.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2014 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. - -trait Foo { - fn dummy(&self) { } -} - -pub trait Bar : Foo {} //~ ERROR private trait in public interface - -fn main() {}