Skip to content

Contradictory unused imports on traits #43970

Closed
@WiSaGaN

Description

@WiSaGaN

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions