Skip to content

Commit d296294

Browse files
authored
Auto merge of #34206 - petrochenkov:pipdeny, r=nikomatsakis
Make `private_in_public` compatibility lint deny-by-default In accordance with the [plan](https://internals.rust-lang.org/t/fcp-for-various-future-compatibility-warnings/3590/5?u=petrochenkov). r? @nikomatsakis
2 parents 1deb02e + b052dd6 commit d296294

File tree

11 files changed

+101
-65
lines changed

11 files changed

+101
-65
lines changed

src/librustc/lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ declare_lint! {
114114

115115
declare_lint! {
116116
pub PRIVATE_IN_PUBLIC,
117-
Warn,
117+
Deny,
118118
"detect private items in public interfaces not caught by the old implementation"
119119
}
120120

src/librustc_lint/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
157157
store.register_future_incompatible(sess, vec![
158158
FutureIncompatibleInfo {
159159
id: LintId::of(PRIVATE_IN_PUBLIC),
160-
reference: "the explanation for E0446 (`--explain E0446`)",
160+
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
161161
},
162162
FutureIncompatibleInfo {
163163
id: LintId::of(INACCESSIBLE_EXTERN_CRATE),

src/librustc_privacy/diagnostics.rs

-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ A private trait was used on a public type parameter bound. Erroneous code
1717
examples:
1818
1919
```compile_fail,E0445
20-
#![deny(private_in_public)]
21-
2220
trait Foo {
2321
fn dummy(&self) { }
2422
}
@@ -47,8 +45,6 @@ E0446: r##"
4745
A private type was used in a public type signature. Erroneous code example:
4846
4947
```compile_fail,E0446
50-
#![deny(private_in_public)]
51-
5248
mod Foo {
5349
struct Bar(u32);
5450

src/librustc_privacy/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,8 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
938938
self.tcx.sess.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
939939
node_id,
940940
ty.span,
941-
format!("private type in public interface"));
941+
format!("private type in public \
942+
interface (error E0446)"));
942943
}
943944
}
944945
}

src/test/compile-fail/issue-28514.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2016 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+
pub use inner::C;
12+
13+
mod inner {
14+
trait A {
15+
fn a(&self) { }
16+
}
17+
18+
pub trait B {
19+
fn b(&self) { }
20+
}
21+
22+
pub trait C: A + B { //~ ERROR private trait in public interface
23+
//~^ WARN will become a hard error
24+
fn c(&self) { }
25+
}
26+
27+
impl A for i32 {}
28+
impl B for i32 {}
29+
impl C for i32 {}
30+
31+
}
32+
33+
fn main() {
34+
// A is private
35+
// B is pub, not reexported
36+
// C : A + B is pub, reexported
37+
38+
// 0.a(); // can't call
39+
// 0.b(); // can't call
40+
0.c(); // ok
41+
42+
C::a(&0); // can call
43+
C::b(&0); // can call
44+
C::c(&0); // ok
45+
}

src/test/compile-fail/issue-30079.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(rustc_attrs)]
1211
#![allow(unused)]
1312

1413
struct SemiPriv;
1514

1615
mod m1 {
1716
struct Priv;
1817
impl ::SemiPriv {
19-
pub fn f(_: Priv) {} //~ WARN private type in public interface
18+
pub fn f(_: Priv) {} //~ ERROR private type in public interface
2019
//~^ WARNING hard error
2120
}
2221

@@ -28,7 +27,7 @@ mod m1 {
2827
mod m2 {
2928
struct Priv;
3029
impl ::std::ops::Deref for ::SemiPriv {
31-
type Target = Priv; //~ WARN private type in public interface
30+
type Target = Priv; //~ ERROR private type in public interface
3231
//~^ WARNING hard error
3332
fn deref(&self) -> &Self::Target { unimplemented!() }
3433
}
@@ -46,10 +45,9 @@ trait SemiPrivTrait {
4645
mod m3 {
4746
struct Priv;
4847
impl ::SemiPrivTrait for () {
49-
type Assoc = Priv; //~ WARN private type in public interface
48+
type Assoc = Priv; //~ ERROR private type in public interface
5049
//~^ WARNING hard error
5150
}
5251
}
5352

54-
#[rustc_error]
55-
fn main() {} //~ ERROR compilation successful
53+
fn main() {}

src/test/compile-fail/private-in-public-lint.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// except according to those terms.
1010

1111
mod m1 {
12-
#![deny(private_in_public)]
13-
1412
pub struct Pub;
1513
struct Priv;
1614

src/test/compile-fail/private-in-public-warn.rs

+37-39
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// Private types and traits are not allowed in public interfaces.
1212
// This test also ensures that the checks are performed even inside private modules.
1313

14-
#![feature(rustc_attrs)]
1514
#![feature(associated_consts)]
1615
#![feature(associated_type_defaults)]
1716
#![allow(dead_code)]
@@ -25,34 +24,34 @@ mod types {
2524
type Alias;
2625
}
2726

28-
pub type Alias = Priv; //~ WARN private type in public interface
27+
pub type Alias = Priv; //~ ERROR private type in public interface
2928
//~^ WARNING hard error
3029
pub enum E {
31-
V1(Priv), //~ WARN private type in public interface
30+
V1(Priv), //~ ERROR private type in public interface
3231
//~^ WARNING hard error
33-
V2 { field: Priv }, //~ WARN private type in public interface
32+
V2 { field: Priv }, //~ ERROR private type in public interface
3433
//~^ WARNING hard error
3534
}
3635
pub trait Tr {
37-
const C: Priv = Priv; //~ WARN private type in public interface
36+
const C: Priv = Priv; //~ ERROR private type in public interface
3837
//~^ WARNING hard error
39-
type Alias = Priv; //~ WARN private type in public interface
38+
type Alias = Priv; //~ ERROR private type in public interface
4039
//~^ WARNING hard error
41-
fn f1(arg: Priv) {} //~ WARN private type in public interface
40+
fn f1(arg: Priv) {} //~ ERROR private type in public interface
4241
//~^ WARNING hard error
43-
fn f2() -> Priv { panic!() } //~ WARN private type in public interface
42+
fn f2() -> Priv { panic!() } //~ ERROR private type in public interface
4443
//~^ WARNING hard error
4544
}
4645
extern {
47-
pub static ES: Priv; //~ WARN private type in public interface
46+
pub static ES: Priv; //~ ERROR private type in public interface
4847
//~^ WARNING hard error
49-
pub fn ef1(arg: Priv); //~ WARN private type in public interface
48+
pub fn ef1(arg: Priv); //~ ERROR private type in public interface
5049
//~^ WARNING hard error
51-
pub fn ef2() -> Priv; //~ WARN private type in public interface
50+
pub fn ef2() -> Priv; //~ ERROR private type in public interface
5251
//~^ WARNING hard error
5352
}
5453
impl PubTr for Pub {
55-
type Alias = Priv; //~ WARN private type in public interface
54+
type Alias = Priv; //~ ERROR private type in public interface
5655
//~^ WARNING hard error
5756
}
5857
}
@@ -62,22 +61,22 @@ mod traits {
6261
pub struct Pub<T>(T);
6362
pub trait PubTr {}
6463

65-
pub type Alias<T: PrivTr> = T; //~ WARN private trait in public interface
64+
pub type Alias<T: PrivTr> = T; //~ ERROR private trait in public interface
6665
//~^ WARN trait bounds are not (yet) enforced in type definitions
6766
//~| WARNING hard error
68-
pub trait Tr1: PrivTr {} //~ WARN private trait in public interface
67+
pub trait Tr1: PrivTr {} //~ ERROR private trait in public interface
6968
//~^ WARNING hard error
70-
pub trait Tr2<T: PrivTr> {} //~ WARN private trait in public interface
69+
pub trait Tr2<T: PrivTr> {} //~ ERROR private trait in public interface
7170
//~^ WARNING hard error
7271
pub trait Tr3 {
73-
type Alias: PrivTr; //~ WARN private trait in public interface
72+
type Alias: PrivTr; //~ ERROR private trait in public interface
7473
//~^ WARNING hard error
75-
fn f<T: PrivTr>(arg: T) {} //~ WARN private trait in public interface
74+
fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait in public interface
7675
//~^ WARNING hard error
7776
}
78-
impl<T: PrivTr> Pub<T> {} //~ WARN private trait in public interface
77+
impl<T: PrivTr> Pub<T> {} //~ ERROR private trait in public interface
7978
//~^ WARNING hard error
80-
impl<T: PrivTr> PubTr for Pub<T> {} //~ WARN private trait in public interface
79+
impl<T: PrivTr> PubTr for Pub<T> {} //~ ERROR private trait in public interface
8180
//~^ WARNING hard error
8281
}
8382

@@ -86,17 +85,17 @@ mod traits_where {
8685
pub struct Pub<T>(T);
8786
pub trait PubTr {}
8887

89-
pub type Alias<T> where T: PrivTr = T; //~ WARN private trait in public interface
88+
pub type Alias<T> where T: PrivTr = T; //~ ERROR private trait in public interface
9089
//~^ WARNING hard error
91-
pub trait Tr2<T> where T: PrivTr {} //~ WARN private trait in public interface
90+
pub trait Tr2<T> where T: PrivTr {} //~ ERROR private trait in public interface
9291
//~^ WARNING hard error
9392
pub trait Tr3 {
94-
fn f<T>(arg: T) where T: PrivTr {} //~ WARN private trait in public interface
93+
fn f<T>(arg: T) where T: PrivTr {} //~ ERROR private trait in public interface
9594
//~^ WARNING hard error
9695
}
97-
impl<T> Pub<T> where T: PrivTr {} //~ WARN private trait in public interface
96+
impl<T> Pub<T> where T: PrivTr {} //~ ERROR private trait in public interface
9897
//~^ WARNING hard error
99-
impl<T> PubTr for Pub<T> where T: PrivTr {} //~ WARN private trait in public interface
98+
impl<T> PubTr for Pub<T> where T: PrivTr {} //~ ERROR private trait in public interface
10099
//~^ WARNING hard error
101100
}
102101

@@ -106,13 +105,13 @@ mod generics {
106105
trait PrivTr<T> {}
107106
pub trait PubTr<T> {}
108107

109-
pub trait Tr1: PrivTr<Pub> {} //~ WARN private trait in public interface
108+
pub trait Tr1: PrivTr<Pub> {} //~ ERROR private trait in public interface
110109
//~^ WARNING hard error
111-
pub trait Tr2: PubTr<Priv> {} //~ WARN private type in public interface
110+
pub trait Tr2: PubTr<Priv> {} //~ ERROR private type in public interface
112111
//~^ WARNING hard error
113-
pub trait Tr3: PubTr<[Priv; 1]> {} //~ WARN private type in public interface
112+
pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type in public interface
114113
//~^ WARNING hard error
115-
pub trait Tr4: PubTr<Pub<Priv>> {} //~ WARN private type in public interface
114+
pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type in public interface
116115
//~^ WARNING hard error
117116
}
118117

@@ -139,7 +138,7 @@ mod impls {
139138
type Alias = Priv; // OK
140139
}
141140
impl PubTr for Pub {
142-
type Alias = Priv; //~ WARN private type in public interface
141+
type Alias = Priv; //~ ERROR private type in public interface
143142
//~^ WARNING hard error
144143
}
145144
}
@@ -211,23 +210,23 @@ mod aliases_pub {
211210
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK
212211

213212
impl PrivAlias {
214-
pub fn f(arg: Priv) {} //~ WARN private type in public interface
213+
pub fn f(arg: Priv) {} //~ ERROR private type in public interface
215214
//~^ WARNING hard error
216215
}
217216
// This doesn't even parse
218217
// impl <Priv as PrivTr>::AssocAlias {
219-
// pub fn f(arg: Priv) {} // WARN private type in public interface
218+
// pub fn f(arg: Priv) {} // ERROR private type in public interface
220219
// }
221220
impl PrivUseAliasTr for PrivUseAlias {
222-
type Check = Priv; //~ WARN private type in public interface
221+
type Check = Priv; //~ ERROR private type in public interface
223222
//~^ WARNING hard error
224223
}
225224
impl PrivUseAliasTr for PrivAlias {
226-
type Check = Priv; //~ WARN private type in public interface
225+
type Check = Priv; //~ ERROR private type in public interface
227226
//~^ WARNING hard error
228227
}
229228
impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
230-
type Check = Priv; //~ WARN private type in public interface
229+
type Check = Priv; //~ ERROR private type in public interface
231230
//~^ WARNING hard error
232231
}
233232
}
@@ -252,10 +251,10 @@ mod aliases_priv {
252251
type AssocAlias = Priv3;
253252
}
254253

255-
pub trait Tr1: PrivUseAliasTr {} //~ WARN private trait in public interface
254+
pub trait Tr1: PrivUseAliasTr {} //~ ERROR private trait in public interface
256255
//~^ WARNING hard error
257-
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} //~ WARN private trait in public interface
258-
//~^ WARN private type in public interface
256+
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} //~ ERROR private trait in public interface
257+
//~^ ERROR private type in public interface
259258
//~| WARNING hard error
260259
//~| WARNING hard error
261260

@@ -288,5 +287,4 @@ mod aliases_params {
288287
pub fn f1(arg: PrivAliasGeneric<u8>) {} // OK, not an error
289288
}
290289

291-
#[rustc_error]
292-
fn main() {} //~ ERROR compilation successful
290+
fn main() {}

src/test/compile-fail/private-variant-and-crate-reexport.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,32 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(rustc_attrs)]
1211
#![allow(dead_code)]
1312

1413
extern crate core;
15-
pub use core as reexported_core; //~ WARN extern crate `core` is private, and cannot be reexported
14+
pub use core as reexported_core; //~ ERROR extern crate `core` is private, and cannot be reexported
1615
//~^ WARNING hard error
1716

1817
mod m1 {
19-
pub use ::E::V; //~ WARN variant `V` is private, and cannot be reexported
18+
pub use ::E::V; //~ ERROR variant `V` is private, and cannot be reexported
2019
//~^ WARNING hard error
2120
}
2221

2322
mod m2 {
24-
pub use ::E::{V}; //~ WARN variant `V` is private, and cannot be reexported
23+
pub use ::E::{V}; //~ ERROR variant `V` is private, and cannot be reexported
2524
//~^ WARNING hard error
2625
}
2726

2827
mod m3 {
29-
pub use ::E::V::{self}; //~ WARN variant `V` is private, and cannot be reexported
28+
pub use ::E::V::{self}; //~ ERROR variant `V` is private, and cannot be reexported
3029
//~^ WARNING hard error
3130
}
3231

3332
mod m4 {
34-
pub use ::E::*; //~ WARN variant `V` is private, and cannot be reexported
33+
pub use ::E::*; //~ ERROR variant `V` is private, and cannot be reexported
3534
//~^ WARNING hard error
3635
}
3736

3837
enum E { V }
3938

40-
#[rustc_error]
41-
fn main() {} //~ ERROR compilation successful
39+
fn main() {}

src/test/run-pass/issue-31776.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct S2;
4545

4646
mod m1 {
4747
fn f() {
48-
struct Z {
48+
pub struct Z {
4949
pub field: u8
5050
}
5151

src/test/rustdoc/auxiliary/issue-28927-1.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern crate issue_28927_2 as inner2;
12-
pub use inner2 as bar;
11+
mod detail {
12+
pub extern crate issue_28927_2 as inner2;
13+
}
14+
pub use detail::inner2 as bar;

0 commit comments

Comments
 (0)