Closed
Description
Reproduced on both on beta and nightly (not tested on stable since #51994 wasn't stabilized in 1.31).
#![warn(clippy::use_self)]
pub struct S(pub u16);
impl From<u8> for S {
fn from(a: u8) -> Self {
Self(a.into()) // <-- this is fine
}
}
macro_rules! a {
() => {
impl From<u16> for S {
fn from(a: u16) -> Self {
// S(a) // <-- this is fine but triggers the `clippy::use_self` warning
Self(a) // <-- ERROR E0423
// Self { 0: a } // <-- this is fine but ugly
}
}
}
}
a!();
fn main() {}
This is particularly troublesome on nightly since clippy::use_self
is recently upgraded to emit the lint in a local macro thanks to rust-lang/rust-clippy#3627, but the suggestion failed to compile.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
varkor commentedon Jan 11, 2019
This also applies to type aliases.
I suspect this is to do with
rust/src/librustc_resolve/lib.rs
Lines 3557 to 3558 in b439861
cc @alexreg
alexreg commentedon Jan 11, 2019
Yes, I think @varkor is right.
@petrochenkov Maybe you could elaborate on this FIXME? What's stopping us from resolving paths in the macro NS here?
petrochenkov commentedon Jan 12, 2019
That FIXME is unrelated to the issue.
The issue is that
Self
in value namespace accidentally uses "let
variable hygiene" rather than "item hygiene", somacro_rules
"hides" it from the outside world like it would do for alet
variable.Regarding type aliases,
B
defined bytype B = T;
doesn't exist in value namespace, soB()
doesn't resolve (with or without macros).petrochenkov commentedon Jan 12, 2019
@varkor
Looks like const generic parameters in #53645 have the same issue.
Self
ctor as a local variable #57560petrochenkov commentedon Jan 12, 2019
Fixed in #57560
alexreg commentedon Jan 12, 2019
@petrochenkov Ahh, that makes perfect sense. Feel free (but not obliged) to r? me for that PR.
1 remaining item