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

Unexpected interpolate tokens in quote_item! macro #24914

Closed
ptal opened this issue Apr 28, 2015 · 5 comments
Closed

Unexpected interpolate tokens in quote_item! macro #24914

ptal opened this issue Apr 28, 2015 · 5 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@ptal
Copy link

ptal commented Apr 28, 2015

Recent changes (I guess #23085) make interpolated items unexpected when quoting items. The error is:expected one of const, extern, fn, pub, type, unsafe, or }, found an interpolated item``. The full failing code is available ptal/oak@20ddd3d and a snippet is below:

pub struct PegCompiler<'cx>
{
  cx: &'cx ExtCtxt<'cx>,
  top_level_items: Vec<rust::P<rust::Item>>
}

impl<'cx> PegCompiler<'cx>
{
  fn compile_peg(&mut self) {
    let items = &self.top_level_items;
    parser.push(quote_item!(self.cx,
        impl Parser
        {
          pub fn new() -> Parser
          {
            Parser
          }
          $items // <== Remove this, and the error dissapears.
        }).unwrap());
  }
}

On rustc 1.1.0-dev (441b3f0c2 2015-04-28) (built 2015-04-28)

@sunng87
Copy link

sunng87 commented Apr 29, 2015

I confirm the same issue with my little Derive macro tojson_macros

Edit, my error is:

expected one of `;` or `}`, found `an interpolated statement`

@steveklabnik steveklabnik added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Apr 30, 2015
@ptal
Copy link
Author

ptal commented May 4, 2015

As of rustc 1.1.0-dev (a979efc2f 2015-05-04) (built 2015-05-04) the error message changed: error: expected ident, found an interpolated item.

@ptal
Copy link
Author

ptal commented Jun 2, 2015

This bug persists but the interpolated item seems now "expanded", the new error is:

src/test/ntcc.rs:15:1: 138:2 error: expected one of `const`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `fn lt(input: &str, pos: usize) -> Result<usize, String> {
    match peg::runtime::match_literal(input, pos, "<", 1usize) {
        Ok(pos) => { Parser::spacing(input, pos) }
        x => x,
    }
}`

@ptal
Copy link
Author

ptal commented Jun 29, 2015

After investigations, it is normal that the code does not compile. This is due to the introduction of ImplItem. We tried to add free functions of type Item as method of an implementation (that should be of type ImplItem).

So the only problem is the bad error message.

@steveklabnik
Copy link
Member

Triage: compiler plugin stuff is changing wildly; it will not be using this interface publicly. And given that is about a diagnostic, and nobody has commented in a while, I'm going to give this a close. If someone else sees a bad diagnostic like this with stable code, please let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

No branches or pull requests

3 participants