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

cargo fix fails to apply all -Wunreachable-pub hints #6465

Closed
matthiaskrgr opened this issue Dec 20, 2018 · 2 comments
Closed

cargo fix fails to apply all -Wunreachable-pub hints #6465

matthiaskrgr opened this issue Dec 20, 2018 · 2 comments
Labels
C-bug Category: bug

Comments

@matthiaskrgr
Copy link
Member

git clone https://github.com/rust-lang/cargo/
cd cargo
git checkout 0d1f1bbeabd5b43a7f3ecfa16540af8e76d5efb4
RUSTFLAGS="-Wunreachable-pub" cargo fix
   Compiling cargo v0.34.0 (/home/matthias/vcs/github/cargo)
warning: failed to automatically apply fixes suggested by rustc to crate `cargo`

after fixes were automatically applied the compiler reported errors within these files:

  * src/cargo/core/compiler/context/mod.rs
  * src/cargo/core/compiler/mod.rs
  * src/cargo/core/resolver/context.rs
  * src/cargo/util/mod.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/cargo/issues
quoting the full output of this command we'd be very appreciative!

warning: unreachable `pub` item
  --> src/cargo/macros.rs:43:1
   |
43 | pub struct DisplayAsDebug<T>(pub T);
   | ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   | |
   | help: consider restricting its visibility: `pub(crate)`
   |
   = note: requested on the command line with `-W unreachable-pub`
   = help: or consider exporting it for use by other crates

(followed my a lot more warnings).

cargo 1.33.0-nightly (2cf1f5dda 2018-12-11)
release: 1.33.0
commit-hash: 2cf1f5dda2f7ed84e94c4d32f643e0f1f15352f0
commit-date: 2018-12-11
@matthiaskrgr matthiaskrgr added the C-bug Category: bug label Dec 20, 2018
@ehuss
Copy link
Contributor

ehuss commented Dec 20, 2018

It looks like the unreachable_pub lint is a little flaky. It looks like there were some attempts to improve it (rust-lang/rust#51866), but there are still some bad suggestions. I think it is mostly having problems with re-exports.

Here's one problem

#![warn(unreachable_pub)]

pub use self::m::f;

mod m {
    pub use self::imp::f;  // Recommends pub(crate), but that causes an error above.
    mod imp {
        pub fn f() {}
    }
}

And another one where it interacts poorly with unused_imports, which is harder to reduce:

#![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;
    }
}

@alexcrichton
Copy link
Member

I've opened rust-lang/rust#57410 and rust-lang/rust#57411 for this, so closing in favor of those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants