-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
self and hygiene interact in unfortunate ways #39922
Comments
Slightly different error on nightly:
Previous discussions: #33485 #15682 rust-lang/rfcs#1606 #34317 |
@petrochenkov thanks for the pointers to previous conversation. It feels like the current behavior rules out some useful constructs :/ but I can see it's a complicated question. |
I agree with @nikomatsakis that because |
@dherman Instead, I think we should make it more ergonomic to "opt out" of hygiene; @sergio has proposed macro m() {
#self
}
impl S {
fn f(&self) {
m!(); // this resolves, but wouldn't without the `#`
}
}
macro n($e:expr) {
impl S {
fn f(&#self) {
$e
}
}
}
n!(self /* this resolves, but wouldn't with the `#` */); |
@jseyfried can you give an example of something where the behavior would be surprising? Sorry if you've already given one =) |
@nikomatsakis sure -- I think the following would be surprising: struct S;
impl S {
fn f(&self) {
m!(); // If `self` were unhygienic, this would resolve
}
}
macro m() {
self // the resolution of `self` here would depend on where the macro is used (i.e. not hygienic)
} Here, |
@jseyfried I see. That could indeed be surprising. My example of course is somewhat different, in that the user supplies the binding. There is definitely something special about How would you phrase the macro I wrote above to make it "unhygenic"? I guess that the |
@nikomatsakis I feel like discussion here leads me to believe that we don't actually want this -- should we close? |
@nikomatsakis @Mark-Simulacrum I think so. |
In this example, the code is attempting to use a macro to match generically over
&self
,&mut self
, etc. In so doing, theself
in the function signature is produced by a token-tree fragment. Unfortunately, if you do this, thenself
in the macro itself is considered a different self. Given thatself
is a keyword and not a normal variable, this seems a bit odd:Error:
Also, the friendly error here is quite confusing.
cc @jseyfried @nrc @pnkfelix @wycats @dherman
The text was updated successfully, but these errors were encountered: