about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
AgeCommit message (Collapse)AuthorLines
2022-07-29Recover from c++ style `enum struct`Obei Sideg-0/+19
new error message: `enum` and `struct` are mutually exclusive new suggestion: replace `enum struct` with `enum`
2022-07-29dont call type ascription 'cast'Michael Goulet-6/+7
2022-07-29Remove `TreeAndSpacing`.Nicholas Nethercote-36/+36
A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`.
2022-07-28remove an unnecessary line breakTakayuki Maeda-1/+0
2022-07-25Remove let-chain close brace check.Eric Huss-4/+1
2022-07-24Update doc comments that refer to config parameterDaniel Bevenius-2/+2
This commit updates the source_file_to_parser and the maybe_source_file_to_parse function's doc comments which currently refer to a config parameter. The doc comments have been updated to refer to the 'session' parameter similar to the doc comment for try_file_to_source_file, which also takes a &Session parameter.
2022-07-23Do not suggest adding `;` when `,` is also a choiceMichael Goulet-1/+2
2022-07-16Stabilize `let_chains`Caio-24/+8
2022-07-14Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillotDylan DPC-26/+22
Implement `for<>` lifetime binder for closures This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following: ```rust let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) }; // ^^^^^^^^^^^--- new! ``` cc ``@Aaron1011`` ``@cjgillot``
2022-07-13Rollup merge of #99030 - rust-lang:notriddle/field-recovery, r=petrochenkovDylan DPC-0/+18
diagnostics: error messages when struct literals fail to parse If an expression is supplied where a field is expected, the parser can become convinced that it's a shorthand field syntax when it's not. This PR addresses it by explicitly recording the permitted `:` token immediately after the identifier, and also adds a suggestion to insert the name of the field if it looks like a complex expression. Fixes #98917
2022-07-12Update compiler/rustc_parse/src/parser/expr.rsMichael Howell-1/+1
Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2022-07-12Parse closure bindersMaybe Waffle-26/+22
This is first step in implementing RFC 3216. - Parse `for<'a>` before closures in ast - Error in lowering - Add `closure_lifetime_binder` feature
2022-07-12Rollup merge of #98633 - c410-f3r:yet-another-let-chain, r=estebankDylan DPC-8/+24
Fix last `let_chains` blocker In order to forbid things like `let x = (let y = 1);` or `if let a = 1 && { let x = let y = 1; } {}`, the parser **HAS** to know the context of `let`. This context thing is not a surprise in the parser because you can see **a lot** of ad hoc fixes mixing parsing logic with validation logic creating code that looks more like spaghetti with tomato sauce. To make things even greater, a new ad hoc fix was added to only allow `let`s in a valid `let_chains` context by checking the previously processed token. This was the only solution I could think of and believe me, I thought about it for a long time 👍 In the long term, it should be preferable to segregate different responsibilities or create a more robust and cleaner parser framework. cc https://github.com/rust-lang/rust/pull/94927 cc https://github.com/rust-lang/rust/issues/53667
2022-07-08Fix last let_chains blockerCaio-8/+24
2022-07-08Auto merge of #98638 - bjorn3:less_string_interning, r=tmiaskobors-2/+1
Use less string interning This removes string interning in a couple of places where doing so won't result in perf improvements. I also switched one place to use pre-interned symbols.
2022-07-07diagnostics: suggest naming a field after failing to parseMichael Howell-0/+13
2022-07-07diagnostics: mention the `:` token when struct fields fail to parseMichael Howell-0/+5
2022-07-07Auto merge of #98827 - aDotInTheVoid:suggest-extern-block, r=nagisabors-1/+10
Suggest using block for `extern "abi" fn` with no body `@rustbot` modify labels: +A-diagnostics
2022-07-03Auto merge of #98673 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrumbors-2/+2
Bump bootstrap compiler r? `@Mark-Simulacrum`
2022-07-02ast: Add span to `Extern`Nixon Enraght-Moony-1/+10
2022-07-01update cfg(bootstrap)sPietro Albini-2/+2
2022-06-29Rollup merge of #98668 - TaKO8Ki:avoid-many-&str-to-string-conversions, ↵Matthias Krüger-7/+4
r=Dylan-DPC Avoid some `&str` to `String` conversions with `MultiSpan::push_span_label` This patch removes some`&str` to `String` conversions with `MultiSpan::push_span_label`.
2022-06-29avoid many `&str` to `String` conversions with `MultiSpan::push_span_label`Takayuki Maeda-7/+4
2022-06-28Use pre-interned symbols in import recoverybjorn3-2/+1
2022-06-27various: add `rustc_lint_diagnostics` to diag fnsDavid Wood-0/+3
The `rustc_lint_diagnostics` attribute is used by the diagnostic translation/struct migration lints to identify calls where non-translatable diagnostics or diagnostics outwith impls are being created. Any function used in creating a diagnostic should be annotated with this attribute so this commit adds the attribute to many more functions. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-26Rollup merge of #98428 - davidtwco:translation-derive-typed-identifiers, ↵Matthias Krüger-12/+12
r=oli-obk macros: use typed identifiers in diag and subdiag derive Using typed identifiers instead of strings with the Fluent identifiers in the diagnostic and subdiagnostic derives - this enables the diagnostic derive to benefit from the compile-time validation that comes with typed identifiers, namely that use of a non-existent Fluent identifier will not compile. r? `````@oli-obk`````
2022-06-25[rustc_parse] Forbid lets in certain placesCaio-4/+32
2022-06-24macros: use typed identifiers in subdiag deriveDavid Wood-3/+3
As in the diagnostic derive, using typed identifiers in the subdiagnostic derive improves the diagnostics of using the subdiagnostic derive as Fluent messages will be confirmed to exist at compile-time. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-24macros: use typed identifiers in diag deriveDavid Wood-9/+9
Using typed identifiers instead of strings with the Fluent identifier enables the diagnostic derive to benefit from the compile-time validation that comes with typed identifiers - use of a non-existent Fluent identifier will not compile. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-20Rollup merge of #98183 - dtolnay:emptybound, r=lcnrYuki Okushi-1/+4
Fix pretty printing of empty bound lists in where-clause Repro: ```rust macro_rules! assert_item_stringify { ($item:item $expected:literal) => { assert_eq!(stringify!($item), $expected); }; } fn main() { assert_item_stringify! { fn f<'a, T>() where 'a:, T: {} "fn f<'a, T>() where 'a:, T: {}" } } ``` Previously this assertion would fail because rustc renders the where-clause as `where 'a, T` which is invalid syntax. This PR makes the above assertion pass. This bug also affects `-Zunpretty=expanded`. The intention is for that to emit syntactically valid code, but the buggy output is not valid Rust syntax. ```console $ rustc <(echo "fn f<'a, T>() where 'a:, T: {}") -Zunpretty=expanded #![feature(prelude_import)] #![no_std] #[prelude_import] use ::std::prelude::rust_2015::*; #[macro_use] extern crate std; fn f<'a, T>() where 'a, T {} ``` ```console $ rustc <(echo "fn f<'a, T>() where 'a:, T: {}") -Zunpretty=expanded | rustc - error: expected `:`, found `,` --> <anon>:7:23 | 7 | fn f<'a, T>() where 'a, T {} | ^ expected `:` ```
2022-06-17remove the rest of unnecessary `to_string`Takayuki Maeda-4/+4
2022-06-16Fix pretty printing of empty type bound lists in where-clauseDavid Tolnay-1/+4
2022-06-16Do not suggest adding semicolon/changing delimiters for macros in item ↵Chayim Refael Friedman-21/+25
position that originates in macros
2022-06-13Improve parsing errors and suggestions for bad if statementsMichael Goulet-43/+82
2022-06-14Rollup merge of #95211 - terrarier2111:improve-parser, r=compiler-errorsYuki Okushi-9/+88
Improve parser diagnostics This pr fixes https://github.com/rust-lang/rust/issues/93867 and contains a couple of diagnostics related changes to the parser. Here is a short list with some of the changes: - don't suggest the same thing that is the current token - suggest removing the current token if the following token is one of the suggestions (maybe incorrect) - tell the user to put a type or lifetime after where if there is none (as a warning) - reduce the amount of tokens suggested (via the new eat_noexpect and check_noexpect methods) If any of these changes are undesirable, i can remove them, thanks!
2022-06-13remove unnecessary `to_string` and `String::new` for `tool_only_span_suggestion`Takayuki Maeda-1/+1
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-127/+96
2022-06-12Improves parser diagnostics, fixes #93867threadexception-9/+88
2022-06-12use `create_snapshot_for_diagnostic` instead of `clone`Takayuki Maeda-2/+2
2022-06-08Rollup merge of #97857 - ChayimFriedman2:box-identifier-help, r=compiler-errorsMichael Goulet-4/+57
Suggest escaping `box` as identifier Fixes #97810.
2022-06-08Suggest escaping `box` as identifierChayim Refael Friedman-4/+57
2022-06-08Rollup merge of #97823 - compiler-errors:missing-comma-match-arm, r=estebankDylan DPC-13/+38
Recover missing comma after match arm If we're missing a comma after a match arm expression, try parsing another pattern and a following `=>`. If we find both of those, then recover by suggesting to insert a `,`. Fixes #80112
2022-06-07recover `import` instead of `use` in itemMichael Goulet-20/+49
2022-06-07Recover missing comma after match armMichael Goulet-13/+38
2022-06-06Add spaces before and after expr in add {} suggestionWaffle Maybe-2/+2
Co-authored-by: Michael Goulet <michael@errs.io>
2022-06-05Suggest removing label in `'label: non_block_expr`Maybe Waffle-3/+14
2022-06-05Do not suggest adding labeled block if there are no labeled breaksMaybe Waffle-0/+23
2022-06-05Suggest adding `{}` for `'label: non_block_expr`Maybe Waffle-2/+28
2022-06-02Rollup merge of #97587 - pvdrz:maybe-recover-from-bad-qpath-stage-2, r=davidtwcoDylan DPC-44/+77
Migrate more diagnostics to use the `#[derive(SessionDiagnostic)]` r? ``@davidtwco``
2022-06-02Rollup merge of #97166 - nnethercote:move-conditions-out, r=estebankYuki Okushi-50/+41
Move conditions out of recover/report functions. `Parser` has six recover/report functions that are passed a boolean, and nothing is done if the boolean has a particular value. This PR moves the tests outside the functions. This has the following effects. - The number of lines of code goes down. - Some `use` items become shorter. - Avoids the strangeness whereby 11 out of 12 calls to `maybe_recover_from_bad_qpath` pass `true` as the second argument. - Makes it clear at the call site that only one of `maybe_recover_from_bad_type_plus` and `maybe_report_ambiguous_plus` will be run. r? `@estebank`