-
Notifications
You must be signed in to change notification settings - Fork 13.3k
libsyntax: note that let a = (let b = something)
is invalid
#30765
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (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. |
r? @Manishearth |
Now, we should update the existing test |
Alternatively, add a new parse-fail test. |
Well, at the moment I still have the issue with the following code: fn main() {
let let = 3;
println!(let);
} which of course fails:
However, the note that |
in parse_bottom_expr (parser.rs)
run-fail-fulldeps/qquote.rs fails. Might want to run |
@dsprenkels I'm not sure why you want to address that case, because the compiler already points it out quite correctly (that it expects an identifier and not a keyword). I think your previous version was good (since it addresses the actual issue) For building & testing, run |
No, the previous fix does complain about
|
Oh, fine. Then, carry on :) |
… let error, by moving unexpected let check into the proper if-else clause
Currently, the
It is, however, unclear to me how to resolve this, as I do not know this plugin works. |
} else if self.token.is_keyword(keywords::Let) { | ||
// Catch this syntax error here, instead of in `check_strict_keywords`, so | ||
// that we can explicitly mention that let is not to be used as an expression | ||
let msg = "`let` is not an expression, so it cannot be used in this way"; |
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.
This error message needs some work: why single let
out here? Rather than other keywords, it seems oddly specific. You probably mean that "a let
statement is not an expression", not that let
it self is not. It is not clear what "this way" means.
Maybe better, something like: expected expression, found statement; variable declaration using
letis a statement
. Perhaps the bit after the semicolon should be a note.
Note that neither then before or after message fit the let let x = ...
case, where we expect an identifier, not a keyword, so the original error is better, and the new one (either as well as or instead of) is wrong.
This error is probably only signalled because of the first panic. Would be good to get a stack trace for the first panic. Try running the test with RUST_BACKTRACE=1, then post the stack trace here. The first error is probably because you're making an error which includes the span, but the span for quasi-quoted code is not a valid one. Not sure how we handle this usually. |
Full traceback:
Furthermore: I agree that the error message is not very informative at the moment. The original plan was (still is?) to add a note to the error thrown in |
Hmm, this is puzzling. It is clear what is going on - when quasi-quoting we are getting an error causing us to panic. However, it is not clear why the error is not |
The new error is indeed fatal, whereas the error that would originally occur was not. |
As I see it, the issue here is this: The parser maintains a I noticed that The relevant backtrace is:
@nrc any idea what's going on here? |
That sounds like a reasonable analysis. We have access to the error before it is emitted in quote::parse_expr_panic, so we could strip out the span from the error there. Alternatively, we could check that the span is valid in EmitterWriter::emit and don't try and use it if not. The second is more robust and probably better. |
I fixed the error in https://github.com/rust-lang/rust/compare/master...Manishearth:pr-30765?expand=1, and additionally used the improved error message. Should I make a new PR? Otherwise cherry-picking the last two commits should work. |
Superseded by #31211. |
@Manishearth Thank you! Shall I close this PR in favor of #31211? |
Sure. I opened a new PR in case you didn't want to cherry pick. It's also acceptable to cherry pick commits here and we'll close that PR 😄 |
Closed in favor of #31211. |
This merged (#31211). Thanks for all the effort, @dsprenkels, and apologies for the holdups! 😃 |
This PR is in response to #30440.
Mention: @Manishearth, @wafflespeanut