Skip to content

Commit 95ec17a

Browse files
committed
privacy: Stabilize lint unnameable_types
1 parent 9ce37dc commit 95ec17a

File tree

8 files changed

+14
-29
lines changed

8 files changed

+14
-29
lines changed

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ declare_features! (
351351
(accepted, type_alias_enum_variants, "1.37.0", Some(49683)),
352352
/// Allows macros to appear in the type position.
353353
(accepted, type_macros, "1.13.0", Some(27245)),
354+
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
355+
(accepted, type_privacy_lints, "CURRENT_RUSTC_VERSION", Some(48054)),
354356
/// Allows `const _: TYPE = VALUE`.
355357
(accepted, underscore_const_names, "1.37.0", Some(54912)),
356358
/// Allows `use path as _;` and `extern crate c as _;`.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,6 @@ declare_features! (
605605
/// Allows creation of instances of a struct by moving fields that have
606606
/// not changed from prior instances of the same struct (RFC #2528)
607607
(unstable, type_changing_struct_update, "1.58.0", Some(86555)),
608-
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
609-
(unstable, type_privacy_lints, "1.72.0", Some(48054)),
610608
/// Enables rustc to generate code that instructs libstd to NOT ignore SIGPIPE.
611609
(unstable, unix_sigpipe, "1.65.0", Some(97889)),
612610
/// Allows unnamed fields of struct and union type

compiler/rustc_lint/src/builtin.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1337,8 +1337,9 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
13371337
}
13381338

13391339
declare_lint! {
1340-
/// The `unreachable_pub` lint triggers for `pub` items not reachable from
1341-
/// the crate root.
1340+
/// The `unreachable_pub` lint triggers for `pub` items not reachable from other crates - that
1341+
/// means neither directly accessible, nor reexported, nor leaked through things like return
1342+
/// types.
13421343
///
13431344
/// ### Example
13441345
///

compiler/rustc_lint_defs/src/builtin.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4248,7 +4248,6 @@ declare_lint! {
42484248
/// ### Example
42494249
///
42504250
/// ```rust,compile_fail
4251-
/// # #![feature(type_privacy_lints)]
42524251
/// # #![allow(unused)]
42534252
/// #![deny(unnameable_types)]
42544253
/// mod m {
@@ -4265,10 +4264,14 @@ declare_lint! {
42654264
///
42664265
/// It is often expected that if you can obtain an object of type `T`, then
42674266
/// you can name the type `T` as well, this lint attempts to enforce this rule.
4267+
/// The recommended action is to either reexport the type properly to make it nameable,
4268+
/// or document that users are not supposed to be able to name it for one reason or another.
4269+
///
4270+
/// Besides types, this lint applies to traits because traits can also leak through signatures,
4271+
/// and you may obtain objects of their `dyn Trait` or `impl Trait` types.
42684272
pub UNNAMEABLE_TYPES,
42694273
Allow,
42704274
"effective visibility of a type is larger than the area in which it can be named",
4271-
@feature_gate = sym::type_privacy_lints;
42724275
}
42734276

42744277
declare_lint! {

tests/ui/feature-gates/feature-gate-type_privacy_lints.rs

-4
This file was deleted.

tests/ui/feature-gates/feature-gate-type_privacy_lints.stderr

-14
This file was deleted.

tests/ui/privacy/unnameable_types.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(type_privacy_lints)]
21
#![deny(unnameable_types)]
32

43
mod m {

tests/ui/privacy/unnameable_types.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: struct `PubStruct` is reachable but cannot be named
2-
--> $DIR/unnameable_types.rs:5:5
2+
--> $DIR/unnameable_types.rs:4:5
33
|
44
LL | pub struct PubStruct(pub i32);
55
| ^^^^^^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
66
|
77
note: the lint level is defined here
8-
--> $DIR/unnameable_types.rs:2:9
8+
--> $DIR/unnameable_types.rs:1:9
99
|
1010
LL | #![deny(unnameable_types)]
1111
| ^^^^^^^^^^^^^^^^
1212

1313
error: enum `PubE` is reachable but cannot be named
14-
--> $DIR/unnameable_types.rs:7:5
14+
--> $DIR/unnameable_types.rs:6:5
1515
|
1616
LL | pub enum PubE {
1717
| ^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
1818

1919
error: trait `PubTr` is reachable but cannot be named
20-
--> $DIR/unnameable_types.rs:11:5
20+
--> $DIR/unnameable_types.rs:10:5
2121
|
2222
LL | pub trait PubTr {
2323
| ^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`

0 commit comments

Comments
 (0)