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

Parse error with unsafe expression #202

Closed
eqrion opened this issue Oct 4, 2017 · 2 comments
Closed

Parse error with unsafe expression #202

eqrion opened this issue Oct 4, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@eqrion
Copy link

eqrion commented Oct 4, 2017

Tested with syn 0.11.11.

// test.rs
pub fn test() {
    for i in 1 .. unsafe { 100 } {
        println!("{:?}", i);
    }
}
// main.rs
extern crate syn;

fn main() {
    syn::parse_crate(include_str!("test.rs")).unwrap();
}

Output:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "failed to parse crate: \"pub fn test() {\\n    for i in 1 .. unsafe { 100 } {\\n        println!(\\\"{:?}\\\", i);\\n    }\\n}\\n\""', /checkout/src/libcore/result.rs:906:4

Changing unsafe { 100 } to be just 100 fixes the issue.

The attached rust (test.rs) compiles fine (with rustc 1.22 nightly), so I think it should be able to be parsed by syn.

Thanks for the great library!

@mystor
Copy link
Collaborator

mystor commented Nov 18, 2017

The problem here is that we parse unsafe {} in the same parser as we parse {}, and in that position a normal, non-unsafe, block would not be allowed to be parsed, but an unsafe block would.

We'll need to split up the parsers for unsafe {} and {} so that we don't have to guard both.

@eqrion
Copy link
Author

eqrion commented Dec 5, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants