Skip to content

warning: pub extern crate does not work as expected and should not be used #189

Closed

Description

@briansmith

Instead of, e.g. pub extern crate num_traits, the code should use extern crate num_traits; pub use num_traits;

Otherwise, rustc causes warnings to be output for any crate that uses num.

Activity

  1. cuviper commented on Apr 29, 2016

    @cuviper
    Member

    Ideally, I wouldn't want these public at all, rather just the renamed pub use num_traits as traits. But IIRC nightly then complains about a public export of something private. So we're left living with a warning on stable.

  2. briansmith commented on Apr 29, 2016

    @briansmith
    ContributorAuthor

    Are people supposed to use the new crates directly instead of using num? I did make a patch to modify ring to do that but it was quite cumbersome to use num_bigint since the traits I needed were split into two other crates, e.g.:

    use num_bigint;
    use num_integer::Integer as Integral;
    use num_traits::{FromPrimitive, Num, One, Signed, ToPrimitive, Zero};

    And then three crate references in Cargo.toml. Maybe I'm doing something silly, though?

    In any case, if the warnings are intended to be ignored then maybe you can use #[allow] to suppress them?

  3. cuviper commented on Apr 29, 2016

    @cuviper
    Member

    Your exact suggestion doesn't work:

    error: an extern crate named `num_traits` has already been imported in this module
    

    If I just drop the pub from the crate, leaving pub use num_traits as traits below, it says:

    warning: extern crate `num_traits` is private, and cannot be reexported (error E0364), consider declaring with `pub`, #[warn(private_in_public)] on by default
    warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    

    Both 1.8.0 and nightly say that right now, and they're perfectly happy when pub extern crate is used. Only 1.4 through 1.7 complain about pub extern crate, but seem to work AFAICT.

    As for how to use all this, please feel free to continue using num as before. I don't plan to remove this supercrate any time soon. I'm fine with adding #[allow], although the message doesn't say what the lint name is.

  4. bluss commented on Apr 29, 2016

    @bluss
    Contributor

    another reexporting technique that's sometimes used is:

    extern crate num_traits;
    
    pub mod traits {
        pub use num_traits::*;
    }

    but I actually don't know what caveats or bugs might apply to this form.

  5. cuviper commented on Apr 29, 2016

    @cuviper
    Member

    Hmm, I could have sworn I tried that, but it does appear to work.

  6. added a commit that references this issue on Apr 29, 2016
    865c491
  7. cuviper commented on May 3, 2016

    @cuviper
    Member

    In case you missed it, I opened #190 removing pub extern crate. Please let me know if you find any issues with this, or else I'll merge it soon.

  8. added a commit that references this issue on May 12, 2016
    4bbc34b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions