about summary refs log tree commit diff
path: root/compiler/rustc_parse
AgeCommit message (Collapse)AuthorLines
2022-05-05Overhaul `MacArgs::Eq`.Nicholas Nethercote-17/+35
The value in `MacArgs::Eq` is currently represented as a `Token`. Because of `TokenKind::Interpolated`, `Token` can be either a token or an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a literal or macro call AST fragment, and then is later lowered to a literal token. But this is very non-obvious. `Token` is a much more general type than what is needed. This commit restricts things, by introducing a new type `MacArgsEqKind` that is either an AST expression (pre-lowering) or an AST literal (post-lowering). The downside is that the code is a bit more verbose in a few places. The benefit is that makes it much clearer what the possibilities are (though also shorter in some other places). Also, it removes one use of `TokenKind::Interpolated`, taking us a step closer to removing that variant, which will let us make `Token` impl `Copy` and remove many "handle Interpolated" code paths in the parser. Things to note: - Error messages have improved. Messages like this: ``` unexpected token: `"bug" + "found"` ``` now say "unexpected expression", which makes more sense. Although arbitrary expressions can exist within tokens thanks to `TokenKind::Interpolated`, that's not obvious to anyone who doesn't know compiler internals. - In `parse_mac_args_common`, we no longer need to collect tokens for the value expression.
2022-05-02fix most compiler/ doctestsElliot Roberts-19/+20
2022-05-02Fix invalid keyword order for function declarationsKen Matsui-2/+2
2022-04-30Add `do yeet` expressions to allow experimentation in nightlyScott McMurray-0/+21
Using an obviously-placeholder syntax. An RFC would still be needed before this could have any chance at stabilization, and it might be removed at any point. But I'd really like to have it in nightly at least to ensure it works well with try_trait_v2, especially as we refactor the traits.
2022-04-30Save colon span to suggest bounds.Camille GILLOT-4/+9
2022-04-29Remove hacks in `make_token_stream`.Nicholas Nethercote-38/+0
`make_tokenstream` has three commented hacks, and a comment at the top referring to #67062. These hacks have no observable effect, at least as judged by running the test suite. The hacks were added in #82608, with an explanation [here](https://github.com/rust-lang/rust/pull/82608#issuecomment-812877329). It appears that one of the following is true: (a) they never did anything useful, (b) they do something useful but we have no test coverage for them, or (c) something has changed in the meantime that means they are no longer necessary. This commit removes the hacks and the comments, in the hope that (b) is not true.
2022-04-29errors: `span_suggestion` takes `impl ToString`David Wood-13/+13
Change `span_suggestion` (and variants) to take `impl ToString` rather than `String` for the suggested code, as this simplifies the requirements on the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-28Rollup merge of #96433 - petrochenkov:delim, r=nnethercoteDylan DPC-240/+245
rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter` Compiler cannot reuse `proc_macro::Delimiter` directly due to extra impls, but can at least use the same naming. After this PR the only difference between these two enums is that `proc_macro::Delimiter::None` is turned into `token::Delimiter::Invisible`. It's my mistake that the invisible delimiter is called `None` on stable, during the stabilization I audited the naming and wrote the docs, but missed the fact that the `None` naming gives a wrong and confusing impression about what this thing is. cc https://github.com/rust-lang/rust/pull/96421 r? ``@nnethercote``
2022-04-28Rollup merge of #96405 - pvdrz:ambiguous-plus-diagnostic, r=davidtwcoDylan DPC-9/+13
Migrate ambiguous plus diagnostic to the new derive macro r? ````@davidtwco```` ````@jyn514````
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-240/+245
2022-04-28Rollup merge of #96471 - BoxyUwU:let_else_considered_harmful, r=lcnrDylan DPC-3/+1
replace let else with `?` r? `@oli-obk`
2022-04-28Rollup merge of #96421 - nnethercote:less-NoDelim, r=petrochenkovDylan DPC-50/+50
Less `NoDelim` Currently there are several places where `NoDelim` (which really means "implicit delimiter" or "invisible delimiter") is used to mean "no delimiter". The name `NoDelim` is a bit misleading, and may be a cause. This PR changes these places, e.g. by changing a `DelimToken` to `Option<DelimToken>` and then using `None` to mean "no delimiter". As a result, the *only* place where `NoDelim` values are now produced is within: - `Delimiter::to_internal()`, when converting from `Delimiter::None`. - `FlattenNonterminals::process_token()`, when converting `TokenKind::Interpolated`. r? ````@petrochenkov````
2022-04-27rename `sum_with_parens`Christian Poveda-6/+3
2022-04-27tut tut tutEllen-3/+1
2022-04-27Avoid producing `NoDelim` values in `FrameData`.Nicholas Nethercote-12/+15
2022-04-27Avoid producing `NoDelim` values in `MacArgs::delim()`.Nicholas Nethercote-16/+20
2022-04-27Avoid producing `NoDelim` values in `TokenCursorFrame`.Nicholas Nethercote-22/+15
2022-04-26move `AmbigousPlus` outsideChristian Poveda-9/+10
2022-04-26avoid `format!`Christian Poveda-2/+2
2022-04-25remove old codeChristian Poveda-9/+0
2022-04-25migrate ambiguous plus diagnosticChristian Poveda-9/+24
2022-04-23Better handle too many `#` recovery in raw strEsteban Küber-9/+34
Point at all the unnecessary trailing `#`. Better handle interaction with outer attributes when `;` is missing. Fix #95030.
2022-04-21Introduced `Cursor::next_with_spacing_ref`.Nicholas Nethercote-5/+5
This lets us clone just the parts within a `TokenTree` that need cloning, rather than the entire thing. This is a surprisingly large performance win, up to 4% on `async-std-1.10.0`.
2022-04-21Produce `CloseDelim` and pop the stack at the same time.Nicholas Nethercote-27/+34
This makes `CloseDelim` handling more like `OpenDelim` handling, which produces `OpenDelim` and pushes the stack at the same time. It requires some adjustment to `parse_token_tree` now that we don't remain within the frame after getting the `CloseDelim`.
2022-04-21Avoid some tuple destructuring.Nicholas Nethercote-5/+7
Surprisingly, this is a non-trivial performance win.
2022-04-20Remove `Eof` sanity check in `Parser::inlined_bump_with`.Nicholas Nethercote-6/+0
A Google search of the error message fails to return any relevant resuts, suggesting this has never occurred in practice. And removeing it reduces instruction counts by up to 2% on some benchmarks.
2022-04-20Inline `Parser::nonterminal_may_begin_with`.Nicholas Nethercote-2/+4
2022-04-20Inline `Parser::parse_nonterminal`.Nicholas Nethercote-1/+3
2022-04-20Only record `fallback_span` when necessary.Nicholas Nethercote-1/+1
2022-04-20Remove the loop from `Parser::bump()`.Nicholas Nethercote-29/+34
The loop is there to handle a `NoDelim` open/close token. This commit changes `TokenCursor::inlined_next` so it never returns such a token. This is a performance win because the conditional test in `bump()` is removed. If the parser needs changing in the future to handle `NoDelim` tokens, then `inlined_next()` can easily be changed to return them.
2022-04-20Remove `TokenCursorFrame::open_delim`.Nicholas Nethercote-20/+5
Because it's now always true.
2022-04-20Use `true` for `open_delim`/`close_delim` in one spot.Nicholas Nethercote-2/+2
The `DelimToken` here is `NoDelim`, which means the returned delim tokens will just be ignored by `Parser::bump()`. This commit changes things so the delim tokens won't be returned.
2022-04-20Add a size assertion for `Parser`.Nicholas Nethercote-0/+5
2022-04-20Move desugaring code into its own function.Nicholas Nethercote-67/+60
It's not hot, so shouldn't be within the always inlined part.
2022-04-19Handle `Delimited` opening immediately.Nicholas Nethercote-1/+3
Instead of letting the next iteration of the loop handle it.
2022-04-19Add {open,close}_delim arguments to `TokenCursorFrame::new()`.Nicholas Nethercote-12/+13
This will facilitate the change in the next commit. `boolean` arguments aren't great, but the function is only used in three places within this one file.
2022-04-19Rearrange `TokenCursor::inlined_next()`.Nicholas Nethercote-17/+20
In particular, avoid wrapping a token within `TokenTree::Token` and then immediately matching it and returning the token within. Just return the token immediately.
2022-04-19Merge `TokenCursor::{next,next_desugared}`.Nicholas Nethercote-85/+71
And likewise for the inlined variants. I did this for simplicity, but interesting it was a performance win as well.
2022-04-19Inline and remove `Parser::next_tok()`.Nicholas Nethercote-32/+26
It has a single call site.
2022-04-19Inline and remove `TokenTree::{open_tt,close_tt}`.Nicholas Nethercote-2/+2
They both have a single call site.
2022-04-17Rollup merge of #95346 - Aaron1011:stablize-const-extern-fn, r=pnkfelixDylan DPC-0/+3
Stablize `const_extern_fn` for "Rust" and "C" All other ABIs are left unstable for now. cc #64926
2022-04-16Rollup merge of #94985 - dtolnay:constattr, r=pnkfelixDylan DPC-2/+2
Parse inner attributes on inline const block According to https://github.com/rust-lang/rust/pull/84414#issuecomment-826150936, inner attributes are intended to be supported *"in all containers for statements (or some subset of statements)"*. This PR adds inner attribute parsing and pretty-printing for inline const blocks (https://github.com/rust-lang/rust/issues/76001), which contain statements just like an unsafe block or a loop body. ```rust let _ = const { #![allow(...)] let x = (); x }; ```
2022-04-16Rollup merge of #95859 - rainy-me:unterminated-nested-block-comment, ↵Dylan DPC-10/+50
r=petrochenkov Improve diagnostics for unterminated nested block comment close #95283 (This is my first time try to messing around with rust compiler and might get a lot of things wrong... :bow: )
2022-04-14refactor: change to use peekablerainy-me-20/+17
2022-04-13couple of clippy::complexity fixesMatthias Krüger-3/+3
2022-04-14improve diagnostics for unterminated nested block commentrainy-me-10/+53
2022-04-12use `to_string` instead of `format!`Takayuki Maeda-1/+1
2022-04-10better error for binder on associated type boundMichael Goulet-12/+36
2022-04-07Auto merge of #95715 - nnethercote:shrink-Nonterminal, r=davidtwcobors-8/+8
Shrink `Nonterminal` Small consistency and performance improvements. r? `@petrochenkov`
2022-04-07Shrink `Nonterminal`.Nicholas Nethercote-8/+8
By heap allocating the argument within `NtPath`, `NtVis`, and `NtStmt`. This slightly reduces cumulative and peak allocation amounts, most notably on `deep-vector`.