Skip to content

Commit 19d700d

Browse files
authored
Unrolled build for rust-lang#120144
Rollup merge of rust-lang#120144 - petrochenkov:unty, r=davidtwco privacy: Stabilize lint `unnameable_types` This is the last piece of ["RFC rust-lang#2145: Type privacy and private-in-public lints"](rust-lang#48054). Having unstable lints is not very useful because you cannot even dogfood them in the compiler/stdlib in this case (rust-lang#113284). The worst thing that may happen when a lint is removed are some `removed_lints` warnings, but I haven't heard anyone suggesting removing this specific lint. This lint is allow-by-default and is supposed to be enabled explicitly. Some false positives are expected, because sometimes unnameable types are a legitimate pattern. This lint also have some unnecessary false positives, that can be fixed - see rust-lang#120146 and rust-lang#120149. Closes rust-lang#48054.
2 parents 75fd074 + 95ec17a commit 19d700d

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
@@ -355,6 +355,8 @@ declare_features! (
355355
(accepted, type_alias_enum_variants, "1.37.0", Some(49683)),
356356
/// Allows macros to appear in the type position.
357357
(accepted, type_macros, "1.13.0", Some(27245)),
358+
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
359+
(accepted, type_privacy_lints, "CURRENT_RUSTC_VERSION", Some(48054)),
358360
/// Allows `const _: TYPE = VALUE`.
359361
(accepted, underscore_const_names, "1.37.0", Some(54912)),
360362
/// Allows `use path as _;` and `extern crate c as _;`.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,6 @@ declare_features! (
615615
/// Allows creation of instances of a struct by moving fields that have
616616
/// not changed from prior instances of the same struct (RFC #2528)
617617
(unstable, type_changing_struct_update, "1.58.0", Some(86555)),
618-
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
619-
(unstable, type_privacy_lints, "1.72.0", Some(48054)),
620618
/// Enables rustc to generate code that instructs libstd to NOT ignore SIGPIPE.
621619
(unstable, unix_sigpipe, "1.65.0", Some(97889)),
622620
/// 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
@@ -4311,7 +4311,6 @@ declare_lint! {
43114311
/// ### Example
43124312
///
43134313
/// ```rust,compile_fail
4314-
/// # #![feature(type_privacy_lints)]
43154314
/// # #![allow(unused)]
43164315
/// #![deny(unnameable_types)]
43174316
/// mod m {
@@ -4328,10 +4327,14 @@ declare_lint! {
43284327
///
43294328
/// It is often expected that if you can obtain an object of type `T`, then
43304329
/// you can name the type `T` as well, this lint attempts to enforce this rule.
4330+
/// The recommended action is to either reexport the type properly to make it nameable,
4331+
/// or document that users are not supposed to be able to name it for one reason or another.
4332+
///
4333+
/// Besides types, this lint applies to traits because traits can also leak through signatures,
4334+
/// and you may obtain objects of their `dyn Trait` or `impl Trait` types.
43314335
pub UNNAMEABLE_TYPES,
43324336
Allow,
43334337
"effective visibility of a type is larger than the area in which it can be named",
4334-
@feature_gate = sym::type_privacy_lints;
43354338
}
43364339

43374340
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)