Clippy lints / Restriction
Clippy lint · Restriction · checked with Clippy 0.1.99
clippy::pub_with_shorthand: usage of `pub` without `in`
What it meansChecks for usage of pub(<loc>) with in. It is in the restriction group and off by default.
What you see
warning: usage of `pub` without `in` --> main.rs:3:1 | 3 | pub(super) type OptBox<T> = Option<Box<T>>; | ^^^^^^^^^^ help: add it: `pub(in super)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#pub_with_shorthand = note: requested on the command line with `-W clippy::pub-with-shorthand`
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
Consistency. Use it or don’t, just be consistent about it. Also see the pub_without_shorthand lint for an alternative.
Lints that forbid language features for specific codebases (no unwrap, no indexing...). Off by default; pick them one by one, never the whole group.
How to fix it
Clippy can fix this one for you: run cargo clippy --fix (add --allow-dirty if you have uncommitted changes). Review the diff before you commit.
Flagged
pub(super) type OptBox<T> = Option<Box<T>>;
Write this instead
pub(in super) type OptBox<T> = Option<Box<T>>;
Turn it off, or on
It is off by default. To use it, set it to warn or deny:
Whole crate (Cargo.toml)
[lints.clippy]
pub_with_shorthand = "warn"In code
#![warn(clippy::pub_with_shorthand)]One run
cargo clippy -- -W clippy::pub-with-shorthandThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for usage of pub(<loc>) with in.
Why restrict this?
Consistency. Use it or don’t, just be consistent about it.
Also see the pub_without_shorthand lint for an alternative.
Example
pub(super) type OptBox<T> = Option<Box<T>>;
Use instead:
pub(in super) type OptBox<T> = Option<Box<T>>;
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on Options
- module_name_repetitionsDetects public item names that are prefixed or suffixed by the containing public module’s name
- expect_usedChecks for .expect() or .expect_err() calls on Results and .expect() call on Options
- print_stderruse of `eprintln!`
- print_stdoutuse of `println!`
- pub_useusing `pub use`
- pub_without_shorthandusage of `pub` with `in`
- question_mark_usedChecks for expressions that use the ? operator and rejects them
- rc_bufferChecks for Rc<T> and Arc<T> when T is a mutable buffer type such as String or Vec
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::unwrap_usedChecks for .unwrap() or .unwrap_err() calls on Results and .unwrap() call on OptionsRead it next →Did this answer your question?