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

mock! gives " error: unexpected end of input, Unsupported in this context" #143

Closed
arnabcs17b006 opened this issue Jun 8, 2020 · 6 comments

Comments

@arnabcs17b006
Copy link

Here are attached screenshots for reference.
1
2

@asomers
Copy link
Owner

asomers commented Jun 8, 2020

Please enable the "nightly" feature of Mockall and try building again. You'll get a much better error message.

@arnabcs17b006
Copy link
Author

1
I get the above message

@asomers
Copy link
Owner

asomers commented Jun 8, 2020

That doesn't look like the full error message. Are you sure you enabled the nightly feature? Would you mind showing your Cargo.toml?Nevermind, I see why the error message is not more detailed. Not your fault.

@asomers
Copy link
Owner

asomers commented Jun 8, 2020

Would you mind posting your code someplace where I can copy/paste it? Either push your branch to GH, or just copy/paste the mock! block into this issue.

@asomers
Copy link
Owner

asomers commented Jun 8, 2020

You need to remove the visibility specifiers from your mock!. Methods in mock! are always written like trait methods, so they can't have visibility specifiers. Instead, they inherit the visibility specifier of the struct. Change pub fn to merely fn.

@asomers asomers closed this as completed Jun 8, 2020
asomers added a commit that referenced this issue Jun 8, 2020
When mock! fails due to unsupported items in the struct section, print a
better error message, including the span.

Issue #143
@asomers
Copy link
Owner

asomers commented Jun 8, 2020

BTW, using pub fn in that location actually used to be accepted, so you may see it in old code some places. A change to the syn crate released in version 1.0.15 is why it isn't accepted any longer.
dtolnay/syn@09f2f5c

asomers added a commit that referenced this issue Jun 8, 2020
When mock! fails due to unsupported items in the struct section, print a
better error message, including the span.

Also, raise syn dependency to 1.0.15.

Older versions of syn allowed a visibility specifier on trait items.

Issue #143
asomers added a commit that referenced this issue Jun 8, 2020
When mock! fails due to unsupported items in the struct section, print a
better error message, including the span.

Also, raise syn dependency to 1.0.15.

Older versions of syn allowed a visibility specifier on trait items.

Issue #143
asomers added a commit that referenced this issue Sep 7, 2020
Previously, it forbade them, and treated the inherent method as having
the same visibility as the struct itself.  That was occasionally
problematic, for example when the mock struct was pub but one of its
methods' arguments was not.

Relates to issue #143
asomers added a commit that referenced this issue Sep 7, 2020
Previously, it forbade them, and treated the inherent method as having
the same visibility as the struct itself.  That was occasionally
problematic, for example when the mock struct was pub but one of its
methods' arguments was not.

Relates to issue #143
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

No branches or pull requests

2 participants