-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add expected closing delimiter to diagnostic #51099
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
I'm working on making/testing some code that might provide an even better descriptor of where the closing bracket should go (basically concluding that it should in fact be a closing bracket and not something else). Not sure if anything will come of that though. |
This comment has been minimized.
This comment has been minimized.
Two orders of business.
In other words, way too many options. What I'm trying to add is something like: match f(self) {
Ok(t) => {
v.push(t);
continue;
},
Err(mut e) => {
//If f errored, it should be because we're missing a bracket (and thus shouldn't have parsed f).
e.cancel();
self.expect_one_of(&[], unref_kets)?;
//The double cloned() is ugly but is necessary due to kets being a slice of references.
break;
}
} At line 1133 in parser.rs, as well as something similar at the other invocation of let before_span = self.span.clone();
let maybe_err = f(self);
match maybe_err {
Ok(t) => {
v.push(t);
}
Err(e) => {
if before_span == self.span {
//If no input was consumed, assume we wanted a sequence ender.
self.expect_one_of(&[], unref_kets)?;
//The double cloned() is ugly but is necessary due to kets being a slice of references.
//If there was in fact a sequence ender, return the error the function gave us.
}
else {
debug!("parse_seq_to_before_tokens: No equality. Propogating error.");
}
return Err(e.into());
}
} I know the error is caused by |
This comment has been minimized.
This comment has been minimized.
src/libsyntax/parse/parser.rs
Outdated
@@ -651,7 +650,7 @@ impl<'a> Parser<'a> { | |||
Err(err) | |||
} | |||
} else { | |||
self.expect_one_of(unsafe { slice::from_raw_parts(t, 1) }, &[]) | |||
self.expect_one_of(&[t.clone()], &[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use slice::from_ref
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this currently breaks compilation as it is still an unstable feature on my rustc -- should I go through with the change anyway, despite not being able to build it locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add a feature-gate to lib.rs
I guess - actually, wait, cc @Manishearth @dtolnay - what does syntex
need from libsyntax
? Is this one of those things where it must work on stable? If so, can we at least leave a comment above this unsafe
code saying it should use slice::from_ref
but syntex
must work on stable Rust?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my knowledge, syntex no longer has any bearing on what we can write in libsyntax. Use slice::from_ref
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, this isn't directly relevant to the issue being fixed, but I thought it'd be worth addressing an unsafe block.
--> $DIR/token-error-correct-3.rs:24:35 | ||
| | ||
LL | callback(path.as_ref(); //~ ERROR expected one of | ||
| ^ expected one of `,`, `.`, `?`, or an operator here | ||
| ^ expected one of `(`, `,`, `.`, `?`, or an operator here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused, why is this the opposite of the error message above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opposite? I changed the error message because that's the purpose of the issue being solved.
Edit: OH! I see what you mean. Yes, that's just my mistake. I'll swap it.
This comment has been minimized.
This comment has been minimized.
The error is
Now, I think that this also falls under an expected error message as per the issue? Though I'm not so familiar with this syntax so I could be wrong, but the compiler says that |
This comment has been minimized.
This comment has been minimized.
The merge commit actually resulted from me trying to squash two commits! That's my mistake; I haven't had to worry about things like that before. I'll fix it when I'm able. What I did was make and push commit 07620b3, but then made the next commit locally, then squashed the two together. But I couldn't push that before pulling and, yeah... Anyway, not able to fix it at the moment but I should soon. |
Yeah, I think that's where you need to use |
My suggestion for cleaning up the history in this kind of thing is just to git reset and recreate the commit:
Anyway, please do fix the history. Code seems fine to me. That said, I'm going to delegate to someone else because I'm drowning in reviews and I don't actually know this part of the parser particularly well (so e.g. I'm not sure what's on with that r? @petrochenkov (cc @estebank — you might be another good choice here) |
81ef025
to
c1df62a
Compare
All right, I've fixed the history, as well as modified the other failing test cases. I'm still a bit wary about the token-error-correct-3 test case, as that's meant to continue parsing to the end due to a similar token, so I'd like to hear someone more experienced's opinion on what the error should be like. Interestingly, but somewhat unrelatedly, if the token is NOT similar we end up with two error messages. (This is using rustc before this change in this PR but it shouldn't change the number of error messages)
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Okay addressing these discrepancies one-by-one:
Offending code: fn foo(a: [0; 1]) {} //~ ERROR expected type, found `0`
//~| ERROR expected one of `->`, `where`, or `{`, found `]`
// FIXME(jseyfried): avoid emitting the second error (preexisting) I believe this to be caused by attempted recovery from the parsing of the [0; 1]. That is, it fails upon 0, so it discards the current tree, then errors upon reaching
Offending code: struct S2(pub((foo)) ());
//~^ ERROR expected `,`, found `(` The second Tests 2 and 3 are basically the same as the above scenario. Should I change the expected error messages? I think an argument for the first one could be made. Also, it seems more useful, but context sensitive error messages (as suggested in the issue) would be difficult due to the need to parse the callback (and thus generate the error) BEFORE looking ahead to see if the next token is a |
@Crazycolorz5 change the tests, and if you can, move them to |
I've changed the tests and their folders as suggested above. I'm not familiar with the process of opening tickets so, ... |
This comment has been minimized.
This comment has been minimized.
My bad, I didn't quite previously understand the testing infrastructure. I'll add stderr files when I'm able to run the built compiler locally. |
You can use the --bless flag for x.py to create the stderr files for you. |
@bors r+ rollup |
📌 Commit df0c6a9 has been approved by |
…estebank Fix Issue 38777 When looking through for a closing bracket in the loop condition, adds them to expecteds. rust-lang#38777
Rollup of 13 pull requests Successful merges: - #50143 (Add deprecation lint for duplicated `macro_export`s) - #51099 (Fix Issue 38777) - #51276 (Dedup auto traits in trait objects.) - #51298 (Stabilize unit tests with non-`()` return type) - #51360 (Suggest parentheses when a struct literal needs them) - #51391 (Use spans pointing at the inside of a rustdoc attribute) - #51394 (Use scope tree depths to speed up `nearest_common_ancestor`.) - #51396 (Make the size of Option<NonZero*> a documented guarantee.) - #51401 (Warn on `repr` without hints) - #51412 (Avoid useless Vec clones in pending_obligations().) - #51427 (compiletest: autoremove duplicate .nll.* files (#51204)) - #51436 (Do not require stage 2 compiler for rustdoc) - #51437 (rustbuild: generate full list of dependencies for metadata) Failed merges:
When looking through for a closing bracket in the loop condition, adds them to expecteds.
Fix #38777.