about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
AgeCommit message (Collapse)AuthorLines
2021-10-07some clippy::perf fixesMatthias Krüger-1/+1
2021-10-04Use `TokenKind::similar_tokens()`Fabian Wolff-1/+4
2021-10-03Try to recover from a `=>` -> `=` or `->` typo in a match armFabian Wolff-1/+15
2021-09-23Rollup merge of #89023 - Wardenfar:issue-85066, r=nagisaJubilee-0/+14
Resolve issue : Somewhat confusing error with extended_key_value_attributes Fixes #85066
2021-09-22Rollup merge of #89046 - oli-obk:fix_oflo, r=estebankthe8472-0/+1
"Fix" an overflow in byte position math r? `@estebank` help! I fixed the ICE only to brick the diagnostic. I mean, it was wrong previously (using an already expanded macro span), but it is really bad now XD
2021-09-20Add some more tracingOli Scherer-0/+1
2021-09-19Suggest replacing braces for brackets on array-esque invalid block exprHirochika Matsumoto-4/+54
Newcomers may write `{1, 2, 3}` for making arrays, and the current error message is not informative enough to quickly convince them what is needed to fix the error. This PR implements a diagnostic for this case, and its output looks like this: ```text error: this code is interpreted as a block expression, not an array --> src/lib.rs:1:22 | 1 | const FOO: [u8; 3] = { | ______________________^ 2 | | 1, 2, 3 3 | | }; | |_^ | = note: to define an array, one would use square brackets instead of curly braces help: try using [] instead of {} | 1 | const FOO: [u8; 3] = [ 2 | 1, 2, 3 3 | ]; | ``` Fix #87672
2021-09-19Resolve issue 85066Theo-0/+14
Fix : use struct_dummy Fix different os messages
2021-09-17Use `multipart_suggestion`Yuki Okushi-1/+1
2021-09-16Rollup merge of #88729 - estebank:struct-literal-using-parens, r=oli-obkManish Goregaokar-10/+91
Recover from `Foo(a: 1, b: 2)` Detect likely `struct` literal using parentheses as delimiters and emit targeted suggestion instead of type ascription parse error. Fix #61326.
2021-09-14review comment: move recovery code to its own functionEsteban Kuber-2/+19
2021-09-09Emit proper errors on missing closure bracesSasha Pourcelot-4/+26
This commit focuses on emitting clean errors for the following syntax error: ``` Some(42).map(|a| dbg!(a); a ); ``` Previous implementation tried to recover after parsing the closure body (the `dbg` expression) by replacing the next `;` with a `,`, which made the next expression belong to the next function argument. As such, the following errors were emitted (among others): - the semicolon token was not expected, - a is not in scope, - Option::map is supposed to take one argument, not two. This commit allows us to gracefully handle this situation by adding giving the parser the ability to remember when it has just parsed a closure body inside a function call. When this happens, we can treat the unexpected `;` specifically and try to parse as much statements as possible in order to eat the whole block. When we can't parse statements anymore, we generate a clean error indicating that the braces are missing, and return an ExprKind::Err.
2021-09-08Rollup merge of #88553 - theo-lw:issue-88276, r=estebankJack Huey-0/+20
Improve diagnostics for unary plus operators (#88276) This pull request improves the diagnostics emitted on parsing a unary plus operator. See #88276. Before: ``` error: expected expression, found `+` --> src/main.rs:2:13 | 2 | let x = +1; | ^ expected expression ``` After: ``` error: leading `+` is not supported --> main.rs:2:13 | 2 | let x = +1; | ^ | | | unexpected `+` | help: try removing the `+` ```
2021-09-07Recover from `Foo(a: 1, b: 2)`Esteban Kuber-10/+74
Detect likely `struct` literal using parentheses as delimiters and emit targeted suggestion instead of type ascription parse error. Fix #61326.
2021-09-04Use verbose suggestions and only match if the + is seen before a numeric literalTheodore Luo Wang-4/+3
2021-09-01Undo debug statementsTheodore Luo Wang-11/+1
2021-09-01Update formattingTheodore Luo Wang-1/+1
2021-09-01Add checks for a block before a unary plus. Fix failing testsTheodore Luo Wang-8/+22
2021-08-31Apply formattingTheodore Luo Wang-1/+6
2021-08-31Improve error checking on unary plusTheodore Luo Wang-0/+12
2021-08-31Rollup merge of #88450 - notriddle:notriddle/maybe_whole_expr, r=cjgillotMara Bos-2/+2
fix(rustc_parse): correct span in `maybe_whole_expr!` Fixes #87812
2021-08-29Auto merge of #88262 - klensy:pprust-cow, r=nagisabors-1/+1
Cow'ify some pprust methods Reduce number of potential needless de/allocations by using `Cow<'static, str>` instead of explicit `String` type.
2021-08-28fix(rustc_parse): incorrect span information for macro path exprMichael Howell-1/+1
Old error output: 3 | let _: usize = $f; | ----- ^ expected `usize`, found struct `Baz` | | | expected due to this New error output: 3 | let _: usize = $f; | ----- ^^ expected `usize`, found struct `Baz` | | | expected due to this
2021-08-28fix(rustc_parse): incorrect span information for macro block exprMichael Howell-1/+1
Old error output: = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this expression in parentheses | 4 | break '_l $f(;) | ^ ^ New error output: = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this expression in parentheses | 4 | break '_l ($f); | ^ ^
2021-08-25Convert some functions to return Cow<'static,str> instead of String to ↵klensy-1/+1
reduce potential reallocations
2021-08-22Fix typos “a”→“an”Frank Steffahn-1/+1
2021-08-15Introduce hir::ExprKind::Let - Take 2Caio-1/+1
2021-07-31Require parentheses to avoid confusions around labeled break and loop ↵Fabian Wolff-4/+51
expressions
2021-07-30Use multispan suggestions more oftenEsteban Küber-8/+6
* Use more accurate span for `async move` suggestion * Use more accurate span for deref suggestion * Use `multipart_suggestion` more often
2021-07-18Auto merge of #87071 - inquisitivecrystal:inclusive-range, r=estebankbors-4/+6
Add diagnostics for mistyped inclusive range Inclusive ranges are correctly typed as `..=`. However, it's quite easy to think of it as being like `==`, and type `..==` instead. This PR adds helpful diagnostics for this case. Resolves #86395 (there are some other cases there, but I think those should probably have separate issues). r? `@estebank`
2021-07-14Suggest a path separator if a stray colon is found in a match armFabian Wolff-4/+4
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2021-07-11Give a helpful error for the mistake `..==`Aris Merchant-4/+6
2021-06-22Auto merge of #85193 - pnkfelix:readd-support-for-inner-attrs-within-match, ↵bors-1/+2
r=nikomatsakis Re-add support for parsing (and pretty-printing) inner-attributes in match body Re-add support for parsing (and pretty-printing) inner-attributes within body of a `match`. In other words, we can do `match EXPR { #![inner_attr] ARM_1 ARM_2 ... }` again. I believe this unbreaks the only four crates that crater flagged as broken by PR #83312. (I am putting this up so that the lang-team can check it out and decide whether it changes their mind about what to do regarding PR #83312.)
2021-06-17Use `AttrVec` for `Arm`, `FieldDef`, and `Variant`Yuki Okushi-2/+2
2021-06-10Add support for using qualified paths with structs in expression and patternRyan Levick-9/+19
position.
2021-06-06parser: Ensure that all nonterminals have tokens after parsingVadim Petrochenkov-11/+1
2021-05-11Re-add support for parsing (and pretty-printing) inner-attributes within ↵Felix S. Klock II-1/+2
body of a `match`. In other words, we can do `match EXPR { #![inner_attr] ARM_1 ARM_2 ... }` again. I believe this unbreaks the only four crates that crater flagged as broken by PR 83312. (I am putting this up so that the lang-team can check it out and decide whether it changes their mind about what to do regarding PR 83312.)
2021-05-03parser: Remove support for inner attributes on non-block expressionsVadim Petrochenkov-10/+4
2021-04-11Implement token-based handling of attributes during expansionAaron Hill-7/+5
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-04-06Use AnonConst for asm! constantsAmanieu d'Antras-1/+1
2021-03-25Avoid double-collection for expression nonterminalsAaron Hill-0/+15
2021-03-19stabilize or_patternsmark-4/+4
2021-03-16ast: Reduce size of `ExprKind` by boxing fields of `ExprKind::Struct`Vadim Petrochenkov-1/+5
2021-03-16ast/hir: Rename field-related structuresVadim Petrochenkov-6/+6
StructField -> FieldDef ("field definition") Field -> ExprField ("expression field", not "field expression") FieldPat -> PatField ("pattern field", not "field pattern") Also rename visiting and other methods working on them.
2021-03-03Detect match arm body without bracesEsteban Küber-0/+111
Fix #82524.
2021-02-21remove unneccessary wrapping of return value in mk_await_expr()Matthias Krüger-3/+3
2021-02-21rustc_parse: remove unneccessary wrapping of return value in fn mk_range() ↵Matthias Krüger-5/+5
which would always return Ok(..)
2021-02-18Rollup merge of #82236 - matthiaskrgr:useless_conv, r=jyn514Dylan DPC-1/+1
avoid converting types into themselves (clippy::useless_conversion)
2021-02-17avoid converting types into themselves (clippy::useless_conversion)Matthias Krüger-1/+1
2021-02-15Simplify pattern grammar by allowing nested leading vertmark-4/+4
Along the way, we also implement a handful of diagnostics improvements and fixes, particularly with respect to the special handling of `||` in place of `|` and when there are leading verts in function params, which don't allow top-level or-patterns anyway.