Skip to content

[1.38] Regression: missing unused import warning #81368

Closed
@dylni

Description

@dylni
Contributor

Code

I tried this code:

use std::clone::Clone;

#[derive(Clone)]
struct S;

fn main() {}

I expected to see this happen: The code compiles with a warning about the import being unused.

Instead, this happened: The code compiles with no warnings.

Version it worked on

It most recently worked on: Rust 1.37

Version with regression

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-unknown-linux-gnu
release: 1.49.0

Activity

dylni

dylni commented on Jan 25, 2021

@dylni
ContributorAuthor

@rustbot modify labels: +regression-untriaged

added
regression-untriagedUntriaged performance or correctness regression.
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jan 25, 2021
dylni

dylni commented on Jan 25, 2021

@dylni
ContributorAuthor

This is old, so I-prioritize is likely not relevant. Will this work?

@rustbot modify labels: -I-prioritize

removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jan 25, 2021
ehuss

ehuss commented on Jan 25, 2021

@ehuss
Contributor

I believe this is working as intended. use std::clone::Clone; imports both the trait and the derive macro (which lives in different namespaces). Thus the #[derive(Clone)] is using the derive that you imported, not the one in the standard library prelude (it is shadowed by the import). They are one in the same, but you could also write use my_derive_macro::Clone; and it would use a different derive. I believe this started with #63056.

dylni

dylni commented on Jan 26, 2021

@dylni
ContributorAuthor

@ehuss Thanks for the explanation. I didn't consider that the prelude Clone is a re-export, so they're not the same. The prelude could be considered special for detecting unused imports, but I don't think that's necessary.

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

    regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@dylni@rustbot

        Issue actions

          [1.38] Regression: missing unused import warning · Issue #81368 · rust-lang/rust