Skip to content
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

Lifetimes are not hygenic #55744

Closed
RalfJung opened this issue Nov 7, 2018 · 6 comments
Closed

Lifetimes are not hygenic #55744

RalfJung opened this issue Nov 7, 2018 · 6 comments
Labels
A-lifetimes Area: Lifetimes / regions A-macros-1.2 Area: Declarative macros 1.2

Comments

@RalfJung
Copy link
Member

RalfJung commented Nov 7, 2018

I would expect the following to not compile (Playground):

trait Trait {}

macro_rules! impl_trait_for {
    ($name:path) => { impl<'tcx> Trait for $name {} }
}

impl_trait_for!(Option<i32>);
impl_trait_for!(Option<&'tcx i32>);

The lifetime 'tcx is bound in the macro, and used in a macro argument. This violates hygiene.

I am sure this has already been reported but I cannot find an issue that matches...

@RalfJung
Copy link
Member Author

RalfJung commented Nov 7, 2018

Type parameters have the same issue. This compiles as well:

trait Trait {}

macro_rules! impl_trait_for {
    ($name:path) => { impl<T> Trait for $name {} }
}

impl_trait_for!(Result<T, T>);

@petrochenkov
Copy link
Contributor

This is by design in macro_rules!, but fixed in macro.

@pnkfelix
Copy link
Member

pnkfelix commented Nov 7, 2018

There's some truly ancient history here, see e.g. #7743, #12451 and meeting from 2014-06-10

@eddyb
Copy link
Member

eddyb commented Nov 7, 2018

I thought we had to pass lifetimes to macros to make things work, are they hygienic sometimes?

@petrochenkov
Copy link
Contributor

Only labels are hygienic (if those can be counted as lifetimes).

@jonas-schievink jonas-schievink added A-lifetimes Area: Lifetimes / regions A-macros-1.2 Area: Declarative macros 1.2 labels Jan 27, 2019
@petrochenkov
Copy link
Contributor

(Closing as not an issue.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-macros-1.2 Area: Declarative macros 1.2
Projects
None yet
Development

No branches or pull requests

5 participants