Skip to content

Contradictory unused imports on traits #43970

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

Closed
WiSaGaN opened this issue Aug 18, 2017 · 4 comments
Closed

Contradictory unused imports on traits #43970

WiSaGaN opened this issue Aug 18, 2017 · 4 comments
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@WiSaGaN
Copy link
Contributor

WiSaGaN commented Aug 18, 2017

Below generates an unused warning:

extern crate num;

use num::Zero;

pub mod foo {
    use super::*;

    pub fn foo_zero() -> u64 {
        u64::zero()
    }
}
warning: unused import: `num::Zero`
 --> src/lib.rs:3:5
  |
3 | use num::Zero;
  |     ^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

While removing the suggested offended line generates error:

error: no associated item named `zero` found for type `u64` in the current scope
 --> src/lib.rs:7:9
  |
7 |         u64::zero()
  |         ^^^^^^^^^
  |
  = help: items from traits can only be used if the trait is in scope; the following traits are implemented but not in scope, perhaps add a `use` for one of them:
  = help: candidate #1: `use core::fmt::num::Int;`
  = help: candidate #2: `use num::Zero;`

Tested on rustc 1.18.0 (03fc9d622 2017-06-06) and rustc 1.21.0-nightly (59ccba995 2017-08-17) with slightly different error message.

Seems similar to symptom of #30159

@oli-obk
Copy link
Contributor

oli-obk commented Aug 18, 2017

Why are private use addressable by inner modules at all?

The warning disappears if foo contains type Foo = Zero;

@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 20, 2017
@Marwes
Copy link
Contributor

Marwes commented Jan 19, 2018

Reproduction without any dependency

mod test {
    pub trait A {
        fn a();
    }

    impl A for () {
        fn a() { }
    }
}

use test::A;

mod test2 {
    use super::*;
    pub fn b() {
        let _ = <()>::a();
    }
}

fn main() {
    test2::b();
}

nicokosi added a commit to nicokosi/pullpito that referenced this issue May 8, 2018
  warning: unused import: `super::*`
     --> src/github_events/mod.rs:121:9
      |
  121 |     use super::*;
      |         ^^^^^^^^
      |
      = note: #[warn(unused_imports)] on by default

  warning: unused imports: `TimeZone`, `Utc`
     --> src/github_events/mod.rs:122:18
      |
  122 |     use chrono::{TimeZone, Utc};
      |                  ^^^^^^^^  ^^^

Seems an open issue: rust-lang/rust#43970
nicokosi added a commit to nicokosi/pullpito that referenced this issue May 8, 2018
  warning: unused import: `super::*`
     --> src/github_events/mod.rs:121:9
      |
  121 |     use super::*;
      |         ^^^^^^^^
      |
      = note: #[warn(unused_imports)] on by default

  warning: unused imports: `TimeZone`, `Utc`
     --> src/github_events/mod.rs:122:18
      |
  122 |     use chrono::{TimeZone, Utc};
      |                  ^^^^^^^^  ^^^

Seems an open issue: rust-lang/rust#43970
@ExpHP
Copy link
Contributor

ExpHP commented Jun 19, 2018

Same as #45268. (this issue is older, but I'm building a list of "linkbacks" there)

@sanxiyn
Copy link
Member

sanxiyn commented Jan 13, 2019

Closing as a duplicate.

@sanxiyn sanxiyn closed this as completed Jan 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. 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

6 participants