Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants