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

Does not preserve invisible delimiters from declarative macros #85

Closed
Kyuuhachi opened this issue Aug 22, 2022 · 1 comment
Closed

Does not preserve invisible delimiters from declarative macros #85

Kyuuhachi opened this issue Aug 22, 2022 · 1 comment

Comments

@Kyuuhachi
Copy link

The below example requires parentheses around the $val to compile, which it doesn't without paste.

macro_rules! clone {
  ($val:expr) => {
    paste::paste! {
      $val.clone()
    }
  }
}

#[derive(Clone)]
struct A;

impl A {
  fn consume_self(self) {}
}

fn main() {
  clone!(&A).consume_self();
}

The correct resulting token tree would be ⟦⟦&A⟧.clone()⟧.consume_self(), but with paste, it appears to be flattened to ⟦&A.clone()⟧.consume_self().

The docs do say null delimiters might not survive roundtripping, but I think it should be possible to avoid here.

@dtolnay
Copy link
Owner

dtolnay commented Aug 22, 2022

This is a rustc bug — paste! expands this input correctly (preserving the None-delimited group) but rustc's parser that is used for parsing the tokens returned by a proc macro just totally ignores None-delimited groups as if they were not grouped at all. See rust-lang/rust#67062.

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

2 participants