Skip to content

Spurious unused import warning with trait used transitively via use super::* #41358

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
khuey opened this issue Apr 18, 2017 · 4 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@khuey
Copy link
Contributor

khuey commented Apr 18, 2017

use std::rc::Rc;
use std::ops::Deref;

mod foo {
    use super::*;

    pub struct Bar {
        pub thing: Rc<u32>,
    }
    
    impl Bar {
        pub fn baz(&self) -> &u32 {
            self.thing.deref()
        }
    }
}

fn main() {
    let use_bar = foo::Bar {
        thing: Rc::new(42),
    };
    println!("value {}", use_bar.baz());
}

triggers

warning: unused import: `std::ops::Deref`, #[warn(unused_imports)] on by default
 --> <anon>:2:5
  |
2 | use std::ops::Deref;
  |     ^^^^^^^^^^^^^^^

This happens on both stable and nightly. The warning goes away if use super::* is replaced by use super::{Rc, Deref}. And the sample of course fails to compile if you remove the use std::ops::Deref.

I ran into this while trying to take advantage of serde-rs/serde#765 by defining a bunch of modules with a common set of imports and a use super::* in each module for simplicity.

@Mark-Simulacrum Mark-Simulacrum added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-diagnostics Area: Messages for errors, warnings, and lints labels Jun 20, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@Wolvereness
Copy link

I also ran across this with the write trait if another example is needed, https://play.rust-lang.org/?gist=296cf1f7d10dbc7a31509e531ac4760f&version=stable

@tjpalmer
Copy link

tjpalmer commented Nov 25, 2017

I also ran across this problem while trying out this code: https://github.com/KeepCalmAndLearnRust/pratt-parser

Specifically, the line complained about is here: https://github.com/KeepCalmAndLearnRust/pratt-parser/blob/d0fdf4c408f6626484fbd0da24f7bcd041952747/src/parser.rs#L3

A compiler that cries wolf can break trust.

@ExpHP
Copy link
Contributor

ExpHP commented Jun 19, 2018

Same as #45268. I'm building a list of linkbacks there for whoever wants to add half a dozen bug reports to their trophy case.

(too bad I chose that issue, this one has a much more accurate title!)

@sanxiyn
Copy link
Member

sanxiyn commented Jan 13, 2019

Yes, this is a much better title, so I retitled the merged issue. 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
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

6 participants