about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/stmt.rs
AgeCommit message (Collapse)AuthorLines
2022-10-24fix #103425, remove extra type error after missing semicolon erroryukang-29/+36
2022-09-27Rework "inner attribute not permitted" errorsXiretza-2/+7
2022-09-27Migrate more rustc_parse diagnostics to diagnostic structsXiretza-64/+30
2022-09-27Move rustc_parse diagnostic structs to separate moduleXiretza-3/+2
2022-08-22Use `AttrVec` in more places.Nicholas Nethercote-9/+7
In some places we use `Vec<Attribute>` and some places we use `ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points where we have to convert between `Vec` and `ThinVec`. This commit changes the places that use `Vec<Attribute>` to use `AttrVec`. A lot of this is mechanical and boring, but there are some interesting parts: - It adds a few new methods to `ThinVec`. - It implements `MapInPlace` for `ThinVec`, and introduces a macro to avoid the repetition of this trait for `Vec`, `SmallVec`, and `ThinVec`. Overall, it makes the code a little nicer, and has little effect on performance. But it is a precursor to removing `rustc_data_structures::thin_vec::ThinVec` and replacing it with `thin_vec::ThinVec`, which is implemented more efficiently.
2022-08-20Auto merge of #100564 - nnethercote:box-ast-MacCall, r=spastorinobors-1/+1
Box the `MacCall` in various types. r? `@spastorino`
2022-08-20Rollup merge of #100667 - Xiretza:diag-structs-parser-ivd, r=davidtwcoMatthias Krüger-19/+12
Migrate "invalid variable declaration" errors to SessionDiagnostic After seeing the great blog post on Inside Rust, I decided to try my hand at this. Just one diagnostic for now to get used to the workflow and to check if this is the way to do it or if there are any problems.
2022-08-17Migrate "invalid variable declaration" errors to SessionDiagnosticXiretza-19/+12
2022-08-17Fix documentation of rustc_parse::parser::Parser::parse_stmt_without_recoveryXiretza-1/+1
Something seems to have gotten out of sync during the creation of #81177, where both the argument and comment were introduced.
2022-08-17Box the `MacCall` in various types.Nicholas Nethercote-1/+1
2022-08-15Rollup merge of #100559 - nnethercote:parser-simplifications, r=compiler-errorsMatthias Krüger-3/+3
Parser simplifications Best reviewed one commit at a time. r? ``@compiler-errors``
2022-08-15Simplify attribute handling in `parse_bottom_expr`.Nicholas Nethercote-3/+3
`Parser::parse_bottom_expr` currently constructs an empty `attrs` and then passes it to a large number of other functions. This makes the code harder to read than it should be, because it's not clear that many `attrs` arguments are always empty. This commit removes `attrs` and the passing, simplifying a lot of functions. The commit also renames `Parser::mk_expr` (which takes an `attrs` argument) as `mk_expr_with_attrs`, and introduces a new `mk_expr` which creates an expression with no attributes, which is the more common case.
2022-08-14Rollup merge of #100253 - obeis:issue-100197, r=cjgillotMatthias Krüger-0/+13
Recover from mutable variable declaration where `mut` is placed before `let` Closes #100197
2022-08-09Recover from mutable variable declaration where `mut` is placed before `let`Obei Sideg-0/+13
2022-08-04Suggest removing `let` if `let const` is usedObei Sideg-0/+16
2022-06-13Improve parsing errors and suggestions for bad if statementsMichael Goulet-3/+16
2022-06-14Rollup merge of #95211 - terrarier2111:improve-parser, r=compiler-errorsYuki Okushi-1/+4
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`Takayuki Maeda-3/+3
2022-06-12Improves parser diagnostics, fixes #93867threadexception-1/+4
2022-06-02Rollup merge of #97166 - nnethercote:move-conditions-out, r=estebankYuki Okushi-1/+1
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`
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-2/+2
2022-05-19Move condition out of `maybe_recover_from_bad_qpath`.Nicholas Nethercote-1/+1
2022-05-11ast: Introduce some traits to get AST node properties genericallyVadim Petrochenkov-4/+2
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-8/+8
2022-04-27Avoid producing `NoDelim` values in `MacArgs::delim()`.Nicholas Nethercote-16/+20
2022-04-07Shrink `Nonterminal`.Nicholas Nethercote-2/+2
By heap allocating the argument within `NtPath`, `NtVis`, and `NtStmt`. This slightly reduces cumulative and peak allocation amounts, most notably on `deep-vector`.
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-2/+2
2022-02-28Rollup merge of #94445 - c410-f3r:more-let-chains, r=cjgillotMatthias Krüger-9/+7
4 - Make more use of `let_chains` Continuation of #94376. cc #53667
2022-02-28Tweak diagnosticsEsteban Kuber-18/+20
* Recover from invalid `'label: ` before block. * Make suggestion to enclose statements in a block multipart. * Point at `match`, `while`, `loop` and `unsafe` keywords when failing to parse their expression. * Do not suggest `{ ; }`. * Do not suggest `|` when very unlikely to be what was wanted (in `let` statements).
2022-02-284 - Make more use of `let_chains`Caio-9/+7
Continuation of #94376. cc #53667
2022-02-23rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".Eduard-Mihai Burtescu-2/+5
2022-02-23rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.Eduard-Mihai Burtescu-2/+2
2022-02-21Better error if the user tries to do assignment ... elseest31-0/+10
2022-02-19Adopt let else in more placesest31-3/+2
2021-12-04Do not add `;` to expected tokens list when it's wrongMichael Howell-4/+10
There's a few spots where semicolons are checked for to do error recovery, and should not be suggested (or checked for other stuff). Fixes #87647
2021-10-18Rollup merge of #89974 - est31:let_else_if_error, r=nagisaMatthias Krüger-5/+16
Nicer error message if the user attempts to do let...else if Gives a nice "conditional `else if` is not supported for `let...else`" error when encountering a `let...else if` pattern, as suggested in the [let...else tracking issue](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205).
2021-10-17Nicer error message if the user attempts to do let...else ifest31-5/+16
2021-10-17Some "parenthesis" and "parentheses" fixesr00ster91-2/+2
2021-09-15Rollup merge of #88690 - m-ou-se:macro-braces-dot-question-expr-parse, r=nagisaManish Goregaokar-11/+14
Accept `m!{ .. }.method()` and `m!{ .. }?` statements. This PR fixes something that I keep running into when using `quote!{}.into()` in a proc macro to convert the `proc_macro2::TokenStream` to a `proc_macro::TokenStream`: Before: ``` error: expected expression, found `.` --> src/lib.rs:6:6 | 4 | quote! { 5 | ... 6 | }.into() | ^ expected expression ``` After: ``` ``` (No output, compiles fine.) --- Context: For expressions like `{ 1 }` and `if true { 1 } else { 2 }`, we accept them as full statements without a trailing `;`, which means the following is not accepted: ```rust { 1 } - 1 // error ``` since that is parsed as two statements: `{ 1 }` and `-1`. Syntactically correct, but the type of `{ 1 }` should be `()` as there is no `;`. However, for specifically `.` and `?` after the `}`, we do [continue parsing it as an expression](https://github.com/rust-lang/rust/blob/13db8440bbbe42870bc828d4ec3e965b38670277/compiler/rustc_parse/src/parser/expr.rs#L864-L876): ```rust { "abc" }.len(); // ok ``` For braced macro invocations, we do not do this: ```rust vec![1, 2, 3].len(); // ok vec!{1, 2, 3}.len(); // error ``` (It parses `vec!{1, 2, 3}` as a full statement, and then complains about `.len()` not being a valid expression.) This PR changes this to also look for a `.` and `?` after a braced macro invocation. We can be sure the macro is an expression and not a full statement in those cases, since no statement can start with a `.` or `?`.
2021-09-06Accept `m!{ .. }.method()` and `m!{ .. }?` statements.Mara Bos-11/+14
2021-09-03Detect bare blocks with type ascription that were meant to be a `struct` literalEsteban Kuber-1/+8
Address part of #34255. Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
2021-08-30Handle let-else initializer edge case errorsCameron Steffen-0/+46
2021-08-30Add let-else to ASTCameron Steffen-10/+22
2021-08-25Use if-let guards in the codebaseLéo Lanteri Thauvin-11/+9
2021-06-10Add support for using qualified paths with structs in expression and patternRyan Levick-1/+1
position.
2021-06-06parser: Ensure that all nonterminals have tokens after parsingVadim Petrochenkov-9/+14
2021-05-08Rename `Parser::span_fatal_err` -> `Parser::span_err`Joshua Nelson-1/+1
The name was misleading, it wasn't actually a fatal error.
2021-04-11Implement token-based handling of attributes during expansionAaron Hill-32/+33
This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2021-03-19stabilize or_patternsmark-3/+2
2021-03-13Improve the wording for the `can't reassign` errorYuki Okushi-1/+2