summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
AgeCommit message (Collapse)AuthorLines
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.
2021-02-13Address review commentsAaron Hill-15/+6
2021-02-13Require passing an `AttrWrapper` to `collect_tokens_trailing_token`Aaron Hill-160/+232
This is a pure refactoring split out from #80689. It represents the most invasive part of that PR, requiring changes in every caller of `parse_outer_attributes` In order to eagerly expand `#[cfg]` attributes while preserving the original `TokenStream`, we need to know the range of tokens that corresponds to every attribute target. This is accomplished by making `parse_outer_attributes` return an opaque `AttrWrapper` struct. An `AttrWrapper` must be converted to a plain `AttrVec` by passing it to `collect_tokens_trailing_token`. This makes it difficult to accidentally construct an AST node with attributes without calling `collect_tokens_trailing_token`, since AST nodes store an `AttrVec`, not an `AttrWrapper`. As a result, we now call `collect_tokens_trailing_token` for attribute targets which only support inert attributes, such as generic arguments and struct fields. Currently, the constructed `LazyTokenStream` is simply discarded. Future PRs will record the token range corresponding to the attribute target, allowing those tokens to be removed from an enclosing `collect_tokens_trailing_token` call if necessary.
2021-01-21Parse loop labels missing a leading `'`Esteban Küber-6/+48
When encountering the following typo: ```rust a: loop { break 'a; } ``` provide an appropriate suggestion.
2021-01-20Force token collection to run when parsing nonterminalsAaron Hill-1/+5
Fixes #81007 Previously, we would fail to collect tokens in the proper place when only builtin attributes were present. As a result, we would end up with attribute tokens in the collected `TokenStream`, leading to duplication when we attempted to prepend the attributes from the AST node. We now explicitly track when token collection must be performed due to nomterminal parsing.
2021-01-13Set tokens on AST node in `collect_tokens`Aaron Hill-16/+4
A new `HasTokens` trait is introduced, which is used to move logic from the callers of `collect_tokens` into the body of `collect_tokens`. In addition to reducing duplication, this paves the way for PR #80689, which needs to perform additional logic during token collection.
2021-01-12Auto merge of #76580 - rokob:iss76011, r=estebankbors-4/+5
Suggest async {} for async || {} Fixes #76011 This adds support for adding help diagnostics to the feature gating checks and then uses it for the async_closure gate to add the extra bit of help information as described in the issue.
2020-12-31Consistently call editions "Rust 20xx" in messages.Mara Bos-1/+1
2020-12-31Add edition 2021.Mara Bos-2/+3
2020-12-25Rollup merge of #80160 - diondokter:move_async_fix, r=davidtwcoDylan DPC-4/+14
Implemented a compiler diagnostic for move async mistake Fixes #79694 First time contributing, so I hope I'm doing everything right. (If not, please correct me!) This code performs a check when a move capture clause is parsed. The check is to detect if the user has reversed the async move keywords and to provide a diagnostic with a suggestion to fix it. Checked code: ```rust fn main() { move async { }; } ``` Previous output: ```txt PS C:\Repos\move_async_test> cargo build Compiling move_async_test v0.1.0 (C:\Repos\move_async_test) error: expected one of `|` or `||`, found keyword `async` --> src\main.rs:2:10 | 2 | move async { }; | ^^^^^ expected one of `|` or `||` error: aborting due to previous error error: could not compile `move_async_test` ``` New output: ```txt PS C:\Repos\move_async_test> cargo +dev build Compiling move_async_test v0.1.0 (C:\Repos\move_async_test) error: the order of `move` and `async` is incorrect --> src\main.rs:2:13 | 2 | let _ = move async { }; | ^^^^^^^^^^ | help: try switching the order | 2 | let _ = async move { }; | ^^^^^^^^^^ error: aborting due to previous error error: could not compile `move_async_test` ``` Is there a file/module where these kind of things are tested? Would love some feedback 😄
2020-12-21Implemented a compiler diagnostic for move async mistakeDion Dokter-4/+14
Ran the tidy check Following the diagnostic guide better Diagnostic generation is now relegated to its own function in the diagnostics module. Added tests Fixed the ui test
2020-12-19implement edition-specific :pat behavior for 2015/18mark-4/+4
2020-12-03Gracefully handle confusing -> with : in function return typemibac138-2/+3
2020-12-01Gracefully handle mistyping -> as => in function return typemibac138-2/+2
2020-11-27Update error to reflect that integer literals can have float suffixesCamelid-2/+2
For example, `1` is parsed as an integer literal, but it can be turned into a float with the suffix `f32`. Now the error calls them "numeric literals" and notes that you can add a float suffix since they can be either integers or floats.
2020-11-14Add underscore expressions for destructuring assignmentsFabian Zaiser-0/+3
Co-authored-by: varkor <github@varkor.com>
2020-11-11Implement destructuring assignment for structs and slicesFabian Zaiser-2/+8
Co-authored-by: varkor <github@varkor.com>
2020-10-27Fix typo in commentsRobert Grosse-1/+1
2020-10-27Auto merge of #77502 - varkor:const-generics-suggest-enclosing-braces, ↵bors-1/+13
r=petrochenkov Suggest that expressions that look like const generic arguments should be enclosed in brackets I pulled out the changes for const expressions from https://github.com/rust-lang/rust/pull/71592 (without the trait object diagnostic changes) and made some small changes; the implementation is `@estebank's.` We're also going to want to make some changes separately to account for trait objects (they result in poor diagnostics, as is evident from one of the test cases here), such as an adaption of https://github.com/rust-lang/rust/pull/72273. Fixes https://github.com/rust-lang/rust/issues/70753. r? `@petrochenkov`
2020-10-26Suggest expressions that look like const generic arguments should be ↵varkor-1/+13
enclosed in brackets Co-Authored-By: Esteban Kuber <github@kuber.com.ar>
2020-10-24Auto merge of #77255 - Aaron1011:feature/collect-attr-tokens, r=petrochenkovbors-1/+1
Unconditionally capture tokens for attributes. This allows us to avoid synthesizing tokens in `prepend_attr`, since we have the original tokens available. We still need to synthesize tokens when expanding `cfg_attr`, but this is an unavoidable consequence of the syntax of `cfg_attr` - the user does not supply the `#` and `[]` tokens that a `cfg_attr` expands to. This is based on PR https://github.com/rust-lang/rust/pull/77250 - this PR exposes a bug in the current `collect_tokens` implementation, which is fixed by the rewrite.