Skip to content

Using self inside an include! no longer works #15549

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

Closed
chris-morgan opened this issue Jul 9, 2014 · 6 comments
Closed

Using self inside an include! no longer works #15549

chris-morgan opened this issue Jul 9, 2014 · 6 comments

Comments

@chris-morgan
Copy link
Member

I presume this is fallout of #15537.

a.rs:

struct A;

impl A {
    fn a(&self) {
        include!("b.rs");
    }
}

b.rs:

{ self; }

This used to work (rust-http depends on it with its codegen approach). Now:

b.rs:2:5: 2:9 error: `self` is not available in a static method. Maybe a `self` argument is missing?
b.rs:2     self;
           ^~~~
note: in expansion of include!
a.rs:4:9: 4:26 note: expansion site
error: aborting due to previous error
@alexcrichton
Copy link
Member

cc @jbclements, I believe this is "well, that's hygiene"

@chris-morgan
Copy link
Member Author

“Hygiene” is a lofty goal, but something that makes things horrible to use and often useless. I frequently want to be able to turn hygiene off on macros.

With hygiene, include! is fairly much useless.

@chris-morgan
Copy link
Member Author

I’ve worked around this in rust-http in what was probably a better approach anyway: chris-morgan/rust-http@67e1188.

On second thoughts, I think I’ll just close this and contemplate writing an RFC to kill include! entirely, seeing how it’s now fairly useless, not being able to take any inputs.

@jbclements
Copy link
Contributor

Whoa, whoa, not trying to tick anyone off. A hygienic system doesn't preclude capturing macros like include!(), they're just not the default. The hygiene system is designed to pass the current context into macro invocations so that they can "pretend" that they come from the place where they were used. It sounds like an include!() macro is the place where you might want to use this.

On the flip side, it sounds like you did find a better approach.

@PaulS, @dherman

@jbclements
Copy link
Contributor

Re-reading what I wrote, I should apologize for giving the impression that capturing macros are a simple matter of flipping a switch; I think the right thing here would be to define a hygiene_stomp!() macro that rewrites all contexts to be that of the macro use, after it's expanded. This wouldn't solve all such problems, but it would restore include!().

@jbclements
Copy link
Contributor

finally, I would note here that one issue is simply the inability to put macros in method position; if you had this, then the binding of self could just go in the included file, and everything would be fine(*) again

(*) until we get hygiene for items....

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 18, 2023
Add a few more `db.unwind_if_cancelled()` calls

Judging from a profile sent by a friend, the borrowck query took up a significant amount of time in their project which might be the cause for some unresponsiveness as nothing in the mir stack currently unwinds on cancellation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants