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

"Expected operator, found /" when passing operator to macro #27660

Closed
jonas-schievink opened this issue Aug 11, 2015 · 4 comments
Closed

"Expected operator, found /" when passing operator to macro #27660

jonas-schievink opened this issue Aug 11, 2015 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@jonas-schievink
Copy link
Contributor

macro_rules! apply_op {
    ( $op:tt ) => {{ 4 $op 5 }};
}

fn main() {
    let _ = apply_op!(/);
}

gives:

<anon>:2:24: 2:27 error: expected one of `.`, `;`, `}`, or an operator, found `/`
<anon>:2     ( $op:tt ) => {{ 4 $op 5 }};
                                ^~~

The same thing happens for other operators as well as . and ;.

@Stebalien
Copy link
Contributor

That's because rust currently needs to be told how to interpret the token:

macro_rules! expr_identity {
    ($e:expr) => { $e }
}
macro_rules! apply_op {
    ( $op:tt ) => { expr_identity!(4 $op 5)};
}

fn main() {
    let _ = apply_op!(/);
}

dup of #27231

@jonas-schievink
Copy link
Contributor Author

Ah, so these are caused by the same issue. The error message has definitely confused me there.

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Aug 13, 2015
@steveklabnik
Copy link
Member

tagging as 'diagnostics' since it's not actually incorrect code

@huonw
Copy link
Member

huonw commented Oct 27, 2015

Dupe of #27231 and #5846. Thanks for filing!

@huonw huonw closed this as completed Oct 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

4 participants