about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/mod.rs
AgeCommit message (Collapse)AuthorLines
2023-05-01fix testsyukang-4/+3
2023-05-01fix parser sizeyukang-1/+1
2023-05-01Rip it outNilstrieb-11/+12
My type ascription Oh rip it out Ah If you think we live too much then You can sacrifice diagnostics Don't mix your garbage Into my syntax So many weird hacks keep diagnostics alive Yet I don't even step outside So many bad diagnostics keep tyasc alive Yet tyasc doesn't even bother to survive!
2023-04-27Migrate trivially translatable `rustc_parse` diagnosticsclubby789-10/+5
2023-04-04Use a simpler atomic operation than the `compare_exchange` hammerOli Scherer-3/+1
2023-04-04Replace a lock with an atomicOli Scherer-2/+7
2023-03-20feat: implement error recovery in `expected_ident_found`Ezra Shaw-4/+9
2023-03-19refactor: refactor identifier parsing somewhatEzra Shaw-14/+13
2023-03-11Gate const closures even when they appear in macrosMichael Goulet-3/+7
2023-03-04Rollup merge of #108715 - chenyukang:yukang/cleanup-parser-delims, ↵Matthias Krüger-14/+3
r=compiler-errors Remove unclosed_delims from parser After landing https://github.com/rust-lang/rust/pull/108297 we could remove `unclosed_delims` from the parser now.
2023-03-03Remove unclosed_delims from parseryukang-14/+3
2023-03-03Match unmatched backticks in comments in compiler/est31-1/+1
2023-02-28rename unmatched_braces to unmatched_delimsyukang-5/+5
2023-02-23parser: provide better errors on closures with braces missingYutaro Ohno-1/+5
We currently provide wrong suggestions and unhelpful errors on closure bodies with braces missing. For example, given the following code: ``` fn main() { let _x = Box::new(|x|x+1;); } ``` the current output is like this: ``` error: expected expression, found `)` --> ./main.rs:2:30 | 2 | let _x = Box::new(|x|x+1;); | ^ expected expression error: closure bodies that contain statements must be surrounded by braces --> ./main.rs:2:25 | 2 | let _x = Box::new(|x|x+1;); | ^ 3 | } | ^ | ... help: try adding braces | 2 ~ let _x = Box::new(|x| {x+1;); 3 ~ }} ... error: expected `;`, found `}` --> ./main.rs:2:32 | 2 | let _x = Box::new(|x|x+1;); | ^ help: add `;` here 3 | } | - unexpected token error: aborting due to 3 previous errors ``` This commit allows outputting correct suggestions and errors. The above code would output like this: ``` error: closure bodies that contain statements must be surrounded by braces --> ./main.rs:2:25 | 2 | let _x = Box::new(|x|x+1;); | ^ ^ | note: statement found outside of a block --> ./main.rs:2:29 | 2 | let _x = Box::new(|x|x+1;); | ---^ this `;` turns the preceding closure into a statement | | | this expression is a statement because of the trailing semicolon note: the closure body may be incorrectly delimited --> ./main.rs:2:23 | 2 | let _x = Box::new(|x|x+1;); | ^^^^^^ - ...but likely you meant the closure to end here | | | this is the parsed closure... help: try adding braces | 2 | let _x = Box::new(|x| {x+1;}); | + + error: aborting due to previous error ```
2023-02-21Use `ThinVec` in various AST types.Nicholas Nethercote-8/+9
This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions.
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-15/+9
2023-02-03Rollup merge of #107551 - fee1-dead-contrib:rm_const_fnmut_helper, r=oli-obkMichael Goulet-5/+16
Replace `ConstFnMutClosure` with const closures Also fixes a parser bug. cc `@oli-obk` for compiler changes
2023-02-03Rename `Cursor`/`CursorRef` as `TokenTreeCursor`/`RefTokenTreeCursor`.Nicholas Nethercote-5/+8
This makes it clear they return token trees, and makes for a nice comparison against `TokenCursor` which returns tokens.
2023-02-03Remove `TokenCursorFrame`.Nicholas Nethercote-40/+32
The motivation here is to eliminate the `Option<(Delimiter, DelimSpan)>`, which is `None` for the outermost token stream and `Some` for all other token streams. We are already treating the innermost frame specially -- this is the `frame` vs `stack` distinction in `TokenCursor`. We can push that further so that `frame` only contains the cursor, and `stack` elements contain the delimiters for their children. When we are in the outermost token stream `stack` is empty, so there are no stored delimiters, which is what we want because the outermost token stream *has* no delimiters. This change also shrinks `TokenCursor`, which shrinks `Parser` and `LazyAttrTokenStreamImpl`, which is nice.
2023-02-03Make clear that `TokenTree::Token` shouldn't contain a delimiter.Nicholas Nethercote-1/+7
2023-02-03Improve doc comment desugaring.Nicholas Nethercote-27/+21
Sometimes the parser needs to desugar a doc comment into `#[doc = r"foo"]`. Currently it does this in a hacky way: by pushing a "fake" new frame (one without a delimiter) onto the `TokenCursor` stack. This commit changes things so that the token stream itself is modified in place. The nice thing about this is that it means `TokenCursorFrame::delim_sp` is now only `None` for the outermost frame.
2023-02-01fix parser mistaking const closures for const itemDeadbeef-5/+16
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-2/+2
2023-01-12parse const closuresDeadbeef-0/+10
2022-12-29fix comment for `TokenCursor::desugar`kraktus-1/+1
the hashes of the text were forgotten.
2022-12-28Rollup merge of #105570 - Nilstrieb:actual-best-failure, r=compiler-errorsMatthias Krüger-0/+4
Properly calculate best failure in macro matching Previously, we used spans. This was not good. Sometimes, the span of the token that failed to match may come from a position later in the file which has been transcribed into a token stream way earlier in the file. If precisely this token fails to match, we think that it was the best match because its span is so high, even though other arms might have gotten further in the token stream. We now try to properly use the location in the token stream. This needs a little cleanup as the `best_failure` field is getting out of hand but it should be mostly good to go. I hope I didn't violate too many abstraction boundaries..
2022-12-18avoid .into() conversion to identical typesMatthias Krüger-6/+2
2022-12-12Properly calculate best failure in macro matchingNilstrieb-0/+4
Previously, we used spans. This was not good. Sometimes, the span of the token that failed to match may come from a position later in the file which has been transcribed into a token stream way earlier in the file. If precisely this token fails to match, we think that it was the best match because its span is so high, even though other arms might have gotten further in the token stream. We now try to properly use the location in the token stream.
2022-12-01While parsing enum variant, the error message always disappearYiming Lei-0/+4
Because the error message that emit out is from main error of parser The information of enum variant disappears while parsing enum variant with error We only check the syntax of expecting token, i.e, in case #103869 It will error it without telling the message that this error is from pasring enum variant. Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err Check the sub-error before emitting the main error of parser and attach it. Fix #103869
2022-11-22`rustc_parse`: remove `ref` patternsMaybe Waffle-6/+6
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-31/+32
`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways: - For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used. - For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used. In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`). This commit splits `MacArgs` in two: - `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`. - `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`. Various other related things are renamed as well. These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values.
2022-11-15Only do parser recovery on retried macro matchingNilstrieb-2/+2
This prevents issues with eager parser recovery during macro matching.
2022-11-11Auto merge of #99918 - WaffleLapkin:fnFnfun, r=estebankbors-8/+50
Recover wrong-cased keywords that start items (_this pr was inspired by [this tweet](https://twitter.com/Azumanga/status/1552982326409367561)_) r? `@estebank` We've talked a bit about this recovery, but I just wanted to make sure that this is the right approach :) For now I've only added the case insensitive recovery to `use`s, since most other items like `impl` blocks, modules, functions can start with multiple keywords which complicates the matter.
2022-10-28Gate some recovery behind a flagNilstrieb-0/+1
Mainly in `expr.rs`
2022-10-26Fix typonils-1/+1
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2022-10-26Add documentationNilstrieb-1/+8
2022-10-25Add flag to forbid recovery in the parserNilstrieb-2/+21
2022-10-20fix assertion failed for break_last_token and trailing tokenyukang-0/+1
2022-10-03Add comments to `TokenCursor::desugar`.Nicholas Nethercote-1/+5
It took me some time to work out what this code was doing.
2022-10-01Replace some `bool` params with an enumMaybe Waffle-12/+13
2022-10-01Recover wrong cased keywords starting functionsMaybe Waffle-8/+22
2022-10-01recover wrong-cased `use`s (`Use`, `USE`, etc)Maybe Waffle-0/+27
2022-09-27Implement IntoDiagnosticArg for rustc_ast::token::Token(Kind)Xiretza-24/+17
2022-09-27Migrate "expected identifier" diagnostics to diagnostic structsXiretza-13/+35
2022-09-27Migrate more rustc_parse diagnostics to diagnostic structsXiretza-22/+10
2022-09-27Move rustc_parse diagnostic structs to separate moduleXiretza-1/+1
2022-09-27Migrate "invalid literal suffix" diagnostic to diagnostic structsXiretza-1/+3
2022-09-27Migrate more diagnostics in rustc_parse to diagnostic structsXiretza-27/+16
2022-09-09Rename `{Create,Lazy}TokenStream` as `{To,Lazy}AttrTokenStream`.Nicholas Nethercote-2/+2
`To` is better than `Create` for indicating that this is a non-consuming conversion, rather than creating something out of nothing. And the addition of `Attr` is because the current names makes them sound like they relate to `TokenStream`, but really they relate to `AttrTokenStream`.
2022-09-09Rename `AttrAnnotatedToken{Stream,Tree}`.Nicholas Nethercote-8/+8
These two type names are long and have long matching prefixes. I find them hard to read, especially in combinations like `AttrAnnotatedTokenStream::new(vec![AttrAnnotatedTokenTree::Token(..)])`. This commit renames them as `AttrToken{Stream,Tree}`.