-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Diagnostic when trying to use !
or ?
in trait is confusing.
#33418
Comments
The unhelpful answer is "because the same code is used to parse generic type parameters and this part of a trait declaration, so the error isn't detected until we're in too deep"... but it should just give a better message from the beginning. |
Unfortunately, this hasn't improved much since then, though the unexpected
|
Is "negative trait bounds are not supported" too straightforward?
…On Wed, May 3, 2017 at 7:07 PM, Mark Simulacrum ***@***.***> wrote:
Unfortunately, this hasn't improved much since then, though the unexpected
? message is now much better. I'm also not sure what a good message would
be for the first case--does anyone have any suggestions so that we can make
this bug more actionable?
$ rustc first-example.rs
error: expected one of `(`, `?`, `for`, `where`, `{`, lifetime, or path, found `!`
--> test.rs:1:13
|
1 | trait Qqq : !Sized {
| -^ unexpected token
| |
| expected one of 7 possible tokens here
error: aborting due to previous error
$ rustc second-example.rs
error: `?Trait` is not permitted in supertraits
--> test.rs:1:14
|
1 | trait Qqq : ?Sized {
| ^^^^^
|
= note: traits are `?Sized` by default
error: main function not found
error: aborting due to 2 previous errors
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#33418 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n2Cn6pOUJmk4MNh9Ikv6Rrq2EA3Oks5r2QiZgaJpZM4IXqsq>
.
|
That would work. Thanks for the suggestion! |
Hello! I would like to implement this improvement. AIUI, we would like to improve the parse error message for negative supertrait bounds, but negative normal bounds on types are OK. First we add a new parser test as trait Tr: !Sized {} //~ ERROR Negative trait bounds are not supported and for bounds after trait Tr: Send + !Sized {} //~ ERROR Negative trait bounds are not supported Then we have some code to emit a custom error when encountering the unexpected if self.check(&token::Not) {
self.span_err(self.span, "Negative trait bounds are not supported");
} Now I have some trouble finding where to place this check. The closest parsing section is in 5917 │ // Parse optional colon and supertrait bounds.
5918 │ let bounds = if self.eat(&token::Colon) {
5919 │ self.parse_generic_bounds()? However, inserting the check before line 5919 wouldn't catch the second test case (its Next I tried inserting it at the top of each iteration in I have put my work so far into https://github.com/hdhoang/rust/tree/33418_negative_bounds. |
Looking at this, @hdhoang, it seems to me that the "correct" way of dealing with this would be to add a new That being said, if the amount of code being changed to add this were small and the variant were called something along the lines of |
Thank you for your guidance! I will try to work this out. Do you have any suggestion for run-pass tests and similar to avoid unintended breakage? |
I have implemented & pushed your method. It did lead to a better experience with the tests! I have only added a small note to remove the whole negative bound. I will need some more time to target |
Looked at your branch and it already looks quite nice! A couple of nitpicks before you post a PR: You're not actually using the This is already looking great! You can use Other than that, great job! |
I have simplified the Could you elaborate on the
Won't this lead back to the " Furthermore, I would like to be consistent with the terminology to help with |
…tebank Improve parsing diagnostic for negative supertrait bounds closes rust-lang#33418 r? @estebank
…tebank Improve parsing diagnostic for negative supertrait bounds closes rust-lang#33418 r? @estebank
OK, let's try
?
:Why were you expecting
?
then?The text was updated successfully, but these errors were encountered: