diff options
| author | bors <bors@rust-lang.org> | 2023-06-11 22:18:23 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-11 22:18:23 +0000 |
| commit | 77dba225c1048e5585b2cdefb7f8588bd2d2741b (patch) | |
| tree | 89b81f60a07b914d6d38b5c12c176695b6175bf2 /compiler/rustc_lint_defs | |
| parent | 37998ab508d5d9fa0d465d7b535dc673087dda8f (diff) | |
| parent | 6d46382f6f0688df0fc5c67386f86ccd6fdb975f (diff) | |
| download | rust-77dba225c1048e5585b2cdefb7f8588bd2d2741b.tar.gz rust-77dba225c1048e5585b2cdefb7f8588bd2d2741b.zip | |
Auto merge of #111801 - Bryanskiy:lints1, r=petrochenkov
Private-in-public lints implementation Next part of RFC https://github.com/rust-lang/rust/issues/48054. r? `@petrochenkov`
Diffstat (limited to 'compiler/rustc_lint_defs')
| -rw-r--r-- | compiler/rustc_lint_defs/src/builtin.rs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index eb246c3f93e..53ece08ac3d 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -3372,7 +3372,9 @@ declare_lint_pass! { OVERLAPPING_RANGE_ENDPOINTS, PATTERNS_IN_FNS_WITHOUT_BODY, POINTER_STRUCTURAL_MATCH, + PRIVATE_BOUNDS, PRIVATE_IN_PUBLIC, + PRIVATE_INTERFACES, PROC_MACRO_BACK_COMPAT, PROC_MACRO_DERIVE_RESOLUTION_FALLBACK, PUB_USE_OF_PRIVATE_EXTERN_CRATE, @@ -3399,6 +3401,7 @@ declare_lint_pass! { UNINHABITED_STATIC, UNKNOWN_CRATE_TYPES, UNKNOWN_LINTS, + UNNAMEABLE_TYPES, UNREACHABLE_CODE, UNREACHABLE_PATTERNS, UNSAFE_OP_IN_UNSAFE_FN, @@ -4251,3 +4254,95 @@ declare_lint! { Warn, "\"invalid_parameter\" isn't a valid argument for `#[macro_export]`", } + +declare_lint! { + /// The `private_interfaces` lint detects types in a primary interface of an item, + /// that are more private than the item itself. Primary interface of an item is all + /// its interface except for bounds on generic parameters and where clauses. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// # #![allow(unused)] + /// # #![allow(private_in_public)] + /// #![deny(private_interfaces)] + /// struct SemiPriv; + /// + /// mod m1 { + /// struct Priv; + /// impl crate::SemiPriv { + /// pub fn f(_: Priv) {} + /// } + /// } + /// + /// # fn main() {} + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Having something private in primary interface guarantees that + /// the item will be unusable from outer modules due to type privacy. + pub PRIVATE_INTERFACES, + Allow, + "private type in primary interface of an item", +} + +declare_lint! { + /// The `private_bounds` lint detects types in a secondary interface of an item, + /// that are more private than the item itself. Secondary interface of an item consists of + /// bounds on generic parameters and where clauses, including supertraits for trait items. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// # #![allow(private_in_public)] + /// # #![allow(unused)] + /// #![deny(private_bounds)] + /// + /// struct PrivTy; + /// pub struct S + /// where PrivTy: + /// {} + /// # fn main() {} + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Having private types or traits in item bounds makes it less clear what interface + /// the item actually provides. + pub PRIVATE_BOUNDS, + Allow, + "private type in secondary interface of an item" +} + +declare_lint! { + /// The `unnameable_types` lint detects types for which you can get objects of that type, + /// but cannot name the type itself. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// # #![allow(unused)] + /// #![deny(unnameable_types)] + /// mod m { + /// pub struct S; + /// } + /// + /// pub fn get_voldemort() -> m::S { m::S } + /// # fn main() {} + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// 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. + pub UNNAMEABLE_TYPES, + Allow, + "effective visibility of a type is larger than the area in which it can be named" +} |
