Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for pub(crate) and reexports are tricked #57411

Open
alexcrichton opened this issue Jan 7, 2019 · 2 comments
Open

Suggestion for pub(crate) and reexports are tricked #57411

alexcrichton opened this issue Jan 7, 2019 · 2 comments
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-unreachable_pub Lint: unreachable_pub T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

First reported upstream, this code:

#![warn(unreachable_pub)]
#![deny(unused_imports)]

pub mod core {
    pub mod compiler {
        mod context {
            mod compilation_files {
                pub struct Metadata;
                pub struct CompilationFiles;
                impl CompilationFiles {
                    pub fn metadata() -> Metadata { Metadata }
                }
            }
            use self::compilation_files::CompilationFiles;
            pub use self::compilation_files::Metadata;  // Suggests pub(crate)
                                // but that causes unused_imports to complain.

            pub struct Context;
            impl Context {
                pub fn files() -> CompilationFiles { CompilationFiles }
            }
        }
        pub use self::context::Context;
    }
}

generates the warning

warning: unreachable `pub` item
  --> src/lib.rs:15:13
   |
15 |             pub use self::compilation_files::Metadata;  // Suggests pub(crate)
   |             ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |             |
   |             help: consider restricting its visibility: `pub(crate)`
   |
note: lint level defined here
  --> src/lib.rs:1:9
   |
1  | #![warn(unreachable_pub)]
   |         ^^^^^^^^^^^^^^^
   = help: or consider exporting it for use by other crates

warning: unreachable `pub` item
  --> src/lib.rs:15:21
   |
15 |             pub use self::compilation_files::Metadata;  // Suggests pub(crate)
   |             ---     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |             |
   |             help: consider restricting its visibility: `pub(crate)`
   |
   = help: or consider exporting it for use by other crates

but the suggested fix doesn't compile!

@alexcrichton alexcrichton added the A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` label Jan 7, 2019
@jhpratt
Copy link
Member

jhpratt commented Nov 13, 2019

Related? #64762

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 31, 2020
@JoshMcguigan
Copy link

JoshMcguigan commented Mar 16, 2021

I believe rust-lang/rust-analyzer#8056 is another occurrence of this.

@jieyouxu jieyouxu added the L-unreachable_pub Lint: unreachable_pub label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-unreachable_pub Lint: unreachable_pub T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants