Skip to content

Suggestion for pub(crate) not always valid on multiple imports #50455

@alexcrichton

Description

@alexcrichton

Given code that looks like:

mod foo { pub struct Bar; pub struct Baz; } mod bar { pub use foo::{Bar, Baz}; }

you get:

$ rustc +nightly src/lib.rs --crate-type lib -W rust_2018_idioms warning: struct is never used: `Bar` --> src/lib.rs:2:5 | 2 | pub struct Bar; | ^^^^^^^^^^^^^^^ | = note: #[warn(dead_code)] on by default warning: struct is never used: `Baz` --> src/lib.rs:3:5 | 3 | pub struct Baz; | ^^^^^^^^^^^^^^^ warning: unreachable `pub` item --> src/lib.rs:2:5 | 2 | pub struct Bar; | ---^^^^^^^^^^^^ | | | help: consider restricting its visibility: `pub(crate)` | = note: `-W unreachable-pub` implied by `-W rust-2018-idioms` = help: or consider exporting it for use by other crates warning: unreachable `pub` item --> src/lib.rs:3:5 | 3 | pub struct Baz; | ---^^^^^^^^^^^^ | | | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` item --> src/lib.rs:7:19 | 7 | pub use foo::{Bar, Baz}; | ^^^ help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` item --> src/lib.rs:7:24 | 7 | pub use foo::{Bar, Baz}; | ^^^ help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates 

which when auto-fixed by cargo fix will produce:

mod foo { pub(crate) struct Bar; pub(crate) struct Baz; } mod bar { pub use foo::{pub(crate), pub(crate)}; }

which fails to compile!

cc @Manishearth

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2018Area: The 2018 editionF-rust_2018_preview`#![feature(rust_2018_preview)]`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions