Skip to content

Conversation

@dtolnay
Copy link
Owner

@dtolnay dtolnay commented Dec 31, 2017

This is a way to expose the diagnostics API without a large surface area in proc_macro2. Sergio needed this for a demo.

let a = parser.parse::<ExprTuple>()?;
parser.parse::<token::Eq>()?;
let b = parser.parse::<ExprTuple>()?;
parser.eof()?;

let (a_len, b_len) = (a.elems.len(), b.elems.len());
if a_len != b_len {
    return Err(b.span().unstable()
        .error(format!("expected {} element(s), got {}", a_len, b_len))
        .span_note(a.span().unstable(), "because of this"));
}

@dtolnay dtolnay requested a review from alexcrichton December 31, 2017 17:15
@alexcrichton alexcrichton merged commit 31ac177 into master Dec 31, 2017
@alexcrichton
Copy link
Contributor

👍

@antoyo
Copy link

antoyo commented Dec 31, 2017

Thanks for adding this feature.
I wonder where the method span() from the example in the first post comes from, though.
Is it a method that is not yet implemented?

@dtolnay
Copy link
Owner Author

dtolnay commented Dec 31, 2017

It's from Sergio's fork, SergioBenitez/syn@b49a4b4. We are working to get it upstreamed.

@JeanMertz
Copy link

I can across this issue from one of the dyn examples as I was researching how to show accurate errors to the user of my macro.

Am I correct in assuming that this is (one of) the feature(s) that is behind the unstable feature flag as described in the readme?

Is there any roadmap to when this might become stable, or at least behind a regular cargo feature flag instead of requiring every user of a crate that uses this to also set the unstable flag?

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

Successfully merging this pull request may close these issues.

5 participants