Rollup merge of #120144 - petrochenkov:unty, r=davidtwco
privacy: Stabilize lint `unnameable_types` This is the last piece of ["RFC #2145: Type privacy and private-in-public lints"](https://github.com/rust-lang/rust/issues/48054). Having unstable lints is not very useful because you cannot even dogfood them in the compiler/stdlib in this case (https://github.com/rust-lang/rust/pull/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 https://github.com/rust-lang/rust/issues/120146 and https://github.com/rust-lang/rust/issues/120149. Closes https://github.com/rust-lang/rust/issues/48054.
This commit is contained in:
commit
337be99bb6
@ -355,6 +355,8 @@ macro_rules! declare_features {
|
|||||||
(accepted, type_alias_enum_variants, "1.37.0", Some(49683)),
|
(accepted, type_alias_enum_variants, "1.37.0", Some(49683)),
|
||||||
/// Allows macros to appear in the type position.
|
/// Allows macros to appear in the type position.
|
||||||
(accepted, type_macros, "1.13.0", Some(27245)),
|
(accepted, type_macros, "1.13.0", Some(27245)),
|
||||||
|
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
|
||||||
|
(accepted, type_privacy_lints, "CURRENT_RUSTC_VERSION", Some(48054)),
|
||||||
/// Allows `const _: TYPE = VALUE`.
|
/// Allows `const _: TYPE = VALUE`.
|
||||||
(accepted, underscore_const_names, "1.37.0", Some(54912)),
|
(accepted, underscore_const_names, "1.37.0", Some(54912)),
|
||||||
/// Allows `use path as _;` and `extern crate c as _;`.
|
/// Allows `use path as _;` and `extern crate c as _;`.
|
||||||
|
@ -615,8 +615,6 @@ pub fn internal(&self, feature: Symbol) -> bool {
|
|||||||
/// Allows creation of instances of a struct by moving fields that have
|
/// Allows creation of instances of a struct by moving fields that have
|
||||||
/// not changed from prior instances of the same struct (RFC #2528)
|
/// not changed from prior instances of the same struct (RFC #2528)
|
||||||
(unstable, type_changing_struct_update, "1.58.0", Some(86555)),
|
(unstable, type_changing_struct_update, "1.58.0", Some(86555)),
|
||||||
/// Allows using type privacy lints (`private_interfaces`, `private_bounds`, `unnameable_types`).
|
|
||||||
(unstable, type_privacy_lints, "1.72.0", Some(48054)),
|
|
||||||
/// Enables rustc to generate code that instructs libstd to NOT ignore SIGPIPE.
|
/// Enables rustc to generate code that instructs libstd to NOT ignore SIGPIPE.
|
||||||
(unstable, unix_sigpipe, "1.65.0", Some(97889)),
|
(unstable, unix_sigpipe, "1.65.0", Some(97889)),
|
||||||
/// Allows unnamed fields of struct and union type
|
/// Allows unnamed fields of struct and union type
|
||||||
|
@ -1337,8 +1337,9 @@ fn check_fn(
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
/// The `unreachable_pub` lint triggers for `pub` items not reachable from
|
/// The `unreachable_pub` lint triggers for `pub` items not reachable from other crates - that
|
||||||
/// the crate root.
|
/// means neither directly accessible, nor reexported, nor leaked through things like return
|
||||||
|
/// types.
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
///
|
///
|
||||||
|
@ -4311,7 +4311,6 @@
|
|||||||
/// ### Example
|
/// ### Example
|
||||||
///
|
///
|
||||||
/// ```rust,compile_fail
|
/// ```rust,compile_fail
|
||||||
/// # #![feature(type_privacy_lints)]
|
|
||||||
/// # #![allow(unused)]
|
/// # #![allow(unused)]
|
||||||
/// #![deny(unnameable_types)]
|
/// #![deny(unnameable_types)]
|
||||||
/// mod m {
|
/// mod m {
|
||||||
@ -4328,10 +4327,14 @@
|
|||||||
///
|
///
|
||||||
/// It is often expected that if you can obtain an object of type `T`, then
|
/// It is often expected that if you can obtain an object of type `T`, then
|
||||||
/// you can name the type `T` as well, this lint attempts to enforce this rule.
|
/// you can name the type `T` as well, this lint attempts to enforce this rule.
|
||||||
|
/// The recommended action is to either reexport the type properly to make it nameable,
|
||||||
|
/// or document that users are not supposed to be able to name it for one reason or another.
|
||||||
|
///
|
||||||
|
/// Besides types, this lint applies to traits because traits can also leak through signatures,
|
||||||
|
/// and you may obtain objects of their `dyn Trait` or `impl Trait` types.
|
||||||
pub UNNAMEABLE_TYPES,
|
pub UNNAMEABLE_TYPES,
|
||||||
Allow,
|
Allow,
|
||||||
"effective visibility of a type is larger than the area in which it can be named",
|
"effective visibility of a type is larger than the area in which it can be named",
|
||||||
@feature_gate = sym::type_privacy_lints;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
//@ check-pass
|
|
||||||
|
|
||||||
#![warn(unnameable_types)] //~ WARN unknown lint
|
|
||||||
fn main() {}
|
|
@ -1,14 +0,0 @@
|
|||||||
warning: unknown lint: `unnameable_types`
|
|
||||||
--> $DIR/feature-gate-type_privacy_lints.rs:3:1
|
|
||||||
|
|
|
||||||
LL | #![warn(unnameable_types)]
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: the `unnameable_types` lint is unstable
|
|
||||||
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
|
|
||||||
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
|
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
|
||||||
= note: `#[warn(unknown_lints)]` on by default
|
|
||||||
|
|
||||||
warning: 1 warning emitted
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
|||||||
#![feature(type_privacy_lints)]
|
|
||||||
#![deny(unnameable_types)]
|
#![deny(unnameable_types)]
|
||||||
|
|
||||||
mod m {
|
mod m {
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
error: struct `PubStruct` is reachable but cannot be named
|
error: struct `PubStruct` is reachable but cannot be named
|
||||||
--> $DIR/unnameable_types.rs:5:5
|
--> $DIR/unnameable_types.rs:4:5
|
||||||
|
|
|
|
||||||
LL | pub struct PubStruct(pub i32);
|
LL | pub struct PubStruct(pub i32);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
|
| ^^^^^^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/unnameable_types.rs:2:9
|
--> $DIR/unnameable_types.rs:1:9
|
||||||
|
|
|
|
||||||
LL | #![deny(unnameable_types)]
|
LL | #![deny(unnameable_types)]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: enum `PubE` is reachable but cannot be named
|
error: enum `PubE` is reachable but cannot be named
|
||||||
--> $DIR/unnameable_types.rs:7:5
|
--> $DIR/unnameable_types.rs:6:5
|
||||||
|
|
|
|
||||||
LL | pub enum PubE {
|
LL | pub enum PubE {
|
||||||
| ^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
|
| ^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
|
||||||
|
|
||||||
error: trait `PubTr` is reachable but cannot be named
|
error: trait `PubTr` is reachable but cannot be named
|
||||||
--> $DIR/unnameable_types.rs:11:5
|
--> $DIR/unnameable_types.rs:10:5
|
||||||
|
|
|
|
||||||
LL | pub trait PubTr {
|
LL | pub trait PubTr {
|
||||||
| ^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
|
| ^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
|
||||||
|
Loading…
Reference in New Issue
Block a user