Skip to content

Commit 6541f80

Browse files
committed
Document -Ztreat-pub-as-pub-crate
1 parent 5885285 commit 6541f80

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# `treat-pub-as-pub-crate`
2+
3+
The tracking issue for this feature is: [#00000](https://github.com/rust-lang/rust/issues/00000)
4+
5+
------------------------
6+
7+
The `-Ztreat-pub-as-pub-crate` flag causes the compiler to treat all `pub` items in the crate as if they were `pub(crate)`. This is useful for finding dead code in binary crates where public items are not intended to be exported to other crates.
8+
9+
When this flag is enabled, the dead code lint will warn about public items that are not used within the crate (unless they are the entry point, like `main`).
10+
11+
## Example
12+
13+
Consider the following code in a binary crate:
14+
15+
```rust
16+
pub fn unused_pub_fn() {}
17+
18+
fn main() {
19+
println!("Hello, world!");
20+
}
21+
```
22+
23+
By default, `rustc` assumes that `unused_pub_fn` might be used by other crates linking to this binary, so it does not warn about it being unused.
24+
25+
With `-Ztreat-pub-as-pub-crate`, `rustc` will emit a warning:
26+
27+
```text
28+
warning: function `unused_pub_fn` is never used
29+
--> src/main.rs:1:8
30+
|
31+
1 | pub fn unused_pub_fn() {}
32+
| ^^^^^^^^^^^^^
33+
|
34+
= note: `#[warn(dead_code)]` on by default
35+
```

0 commit comments

Comments
 (0)