Closed
Description
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
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
dylni commentedon Jan 25, 2021
@rustbot modify labels: +regression-untriaged
dylni commentedon Jan 25, 2021
This is old, so I-prioritize is likely not relevant. Will this work?
@rustbot modify labels: -I-prioritize
ehuss commentedon Jan 25, 2021
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 writeuse my_derive_macro::Clone;
and it would use a different derive. I believe this started with #63056.dylni commentedon Jan 26, 2021
@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.