about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
AgeCommit message (Collapse)AuthorLines
2022-05-16keep bounds where they wereChristian Poveda-2/+1
2022-05-16migrate `maybe_recover_from_bad_type_plus` diagnosticChristian Poveda-25/+48
2022-05-11ast: Introduce some traits to get AST node properties genericallyVadim Petrochenkov-10/+8
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
2022-05-11Rollup merge of #96543 - nnethercote:rm-make_token_stream-hacks, r=Aaron1011Yuki Okushi-40/+1
Remove hacks in `make_token_stream`. `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. r? `@Aaron1011`
2022-05-11Remove some unnecessary invisible delimiter checks.Nicholas Nethercote-2/+1
These seem to have no useful effect... they don't seem useful from a code inspection point of view, and they affect anything in the test suite.
2022-05-07Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errorsbors-19/+20
Begin fixing all the broken doctests in `compiler/` Begins to fix #95994. All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are. There are also a few that I marked `ignore` that could maybe be made to work but seem less important. Each `ignore` has a rough "reason" for ignoring after it parentheses, with - `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax" - `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy. - `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR. - `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup. Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful. I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-04Auto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkovbors-10/+3
Overhaul `MacArgs` Motivation: - Clarify some code that I found hard to understand. - Eliminate one use of three places where `TokenKind::Interpolated` values are created. r? `@petrochenkov`
2022-05-05Overhaul `MacArgs::Eq`.Nicholas Nethercote-10/+3
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-11/+11
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-218/+223
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/+12
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-218/+223
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-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/+23
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-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`