You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot use Self to construct a tuple struct in a macro #57523
Reproduced on both on beta and nightly (not tested on stable since #51994 wasn't stabilized in 1.31).
#![warn(clippy::use_self)]pubstructS(pubu16);implFrom<u8>forS{fnfrom(a:u8) -> Self{Self(a.into())// <-- this is fine}}macro_rules! a {() => {implFrom<u16> forS{fn from(a:u16) -> Self{// S(a) // <-- this is fine but triggers the `clippy::use_self` warningSelf(a)// <-- ERROR E0423// Self { 0: a } // <-- this is fine but ugly}}}}a!();fnmain(){}
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.
That FIXME is unrelated to the issue.
The issue is that Self in value namespace accidentally uses "let variable hygiene" rather than "item hygiene", so macro_rules "hides" it from the outside world like it would do for a let variable.
Regarding type aliases, B defined by type B = T; doesn't exist in value namespace, so B() doesn't resolve (with or without macros).
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
Selfin value namespace accidentally uses "letvariable hygiene" rather than "item hygiene", somacro_rules"hides" it from the outside world like it would do for aletvariable.Regarding type aliases,
Bdefined 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.
petrochenkov 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.