about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
AgeCommit message (Collapse)AuthorLines
2021-09-15Rollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwcoManish Goregaokar-35/+16
Revert anon union parsing Revert PR #84571 and #85515, which implemented anonymous union parsing in a manner that broke the context-sensitivity for the `union` keyword and thus broke stable Rust code. Fix #88583.
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-14Auto merge of #88914 - GuillaumeGomez:rollup-h5svc6w, r=GuillaumeGomezbors-1/+14
Rollup of 7 pull requests Successful merges: - #88033 (Add links for primitives in "jump to definition" feature) - #88722 (Make `UnsafeCell::get_mut` const) - #88851 (Fix duplicate bounds for const_trait_impl) - #88859 (interpreter PointerArithmetic: use new Size helper methods) - #88885 (Fix jump def background) - #88894 (Improve error message for missing trait in trait impl) - #88896 (Reduce possibility of flaky tests) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-09-13Auto merge of #87915 - estebank:fancy-spans, r=oli-obkbors-39/+46
Use smaller spans for some structured suggestions Use more accurate suggestion spans for * argument parse error * fully qualified path * missing code block type * numeric casts
2021-09-12Improve error message for missing trait in trait implFabian Wolff-1/+14
2021-09-11Rollup merge of #88668 - hvdijk:x32, r=joshtriplettJubilee-1/+1
Change more x64 size checks to not apply to x32. Commit 95e096d6 changed a bunch of size checks already, but more have been added, so this fixes the new ones the same way: the various size checks that are conditional on target_arch = "x86_64" were not intended to apply to x86_64-unknown-linux-gnux32, so add target_pointer_width = "64" to the conditions.
2021-09-09Emit proper errors on missing closure bracesSasha Pourcelot-9/+124
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-09Re-add 71a7f8f1884b2c83eeb4a545eef16df1f2ea6476 post-revert.Felix S. Klock II-1/+4
2021-09-09Revert "Implement Anonymous{Struct, Union} in the AST"Felix S. Klock II-35/+13
This reverts commit 059b68dd677808e14e560802d235ad40beeba71e. Note that this was manually adjusted to retain some of the refactoring introduced by commit 059b68dd677808e14e560802d235ad40beeba71e, so that it could likewise retain the correction introduced in commit 5b4bc05fa57be19bb5962f4b7c0f165e194e3151
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-06Accept `m!{ .. }.method()` and `m!{ .. }?` statements.Mara Bos-11/+14
2021-09-05Change more x64 size checks to not apply to x32.Harald van Dijk-1/+1
Commit 95e096d6 changed a bunch of size checks already, but more have been added, so this fixes the new ones the same way: the various size checks that are conditional on target_arch = "x86_64" were not intended to apply to x86_64-unknown-linux-gnux32, so add target_pointer_width = "64" to the conditions.
2021-09-05Rollup merge of #88257 - estebank:invalid-attr-error, r=oli-obkMara Bos-21/+119
Provide more context on incorrect inner attribute Suggest changing an inner attribute into an outer attribute if followed by an item.
2021-09-04Use verbose suggestions and only match if the + is seen before a numeric literalTheodore Luo Wang-4/+3
2021-09-04Auto merge of #88598 - estebank:type-ascription-can-die-in-a-fire, r=wesleywiserbors-4/+16
Detect bare blocks with type ascription that were meant to be a `struct` literal Address part of #34255. Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
2021-09-03Auto merge of #88597 - cjgillot:lower-global, r=petrochenkovbors-2/+1
Move global analyses from lowering to resolution Split off https://github.com/rust-lang/rust/pull/87234 r? `@petrochenkov`
2021-09-03Detect bare blocks with type ascription that were meant to be a `struct` literalEsteban Kuber-4/+16
Address part of #34255. Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
2021-09-03Auto merge of #88386 - estebank:unmatched-delims, r=jackh726bors-3/+18
Point at unclosed delimiters as part of the primary MultiSpan Both the place where the parser encounters a needed closed delimiter and the unclosed opening delimiter are important, so they should get the same level of highlighting in the output. _Context: https://twitter.com/mwk4/status/1430631546432675840_
2021-09-02Provide more context on incorrect inner attributeEsteban Kuber-21/+119
Suggest changing an inner attribute into an outer attribute if followed by an item.
2021-09-01Compute proc_macros in resolutions.Camille GILLOT-2/+1
2021-09-01Undo debug statementsTheodore Luo Wang-14/+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/+25
2021-08-31Apply formattingTheodore Luo Wang-1/+6
2021-08-31Improve error checking on unary plusTheodore Luo Wang-0/+12
2021-09-01Auto merge of #87688 - camsteffen:let-else, r=cjgillotbors-10/+68
Introduce `let...else` Tracking issue: #87335 The trickiest part for me was enforcing the diverging else block with clear diagnostics. Perhaps the obvious solution is to expand to `let _: ! = ..`, but I decided against this because, when a "mismatched type" error is found in typeck, there is no way to trace where in the HIR the expected type originated, AFAICT. In order to pass down this information, I believe we should introduce `Expectation::LetElseNever(HirId)` or maybe add `HirId` to `Expectation::HasType`, but I left that as a future enhancement. For now, I simply assert that the block is `!` with a custom `ObligationCauseCode`, and I think this is clear enough, at least to start. The downside here is that the error points at the entire block rather than the specific expression with the wrong type. I left a todo to this effect. Overall, I believe this PR is feature-complete with regard to the RFC.
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-30Handle let-else initializer edge case errorsCameron Steffen-0/+46
2021-08-30Add let-else to ASTCameron Steffen-10/+22
2021-08-29Auto merge of #88262 - klensy:pprust-cow, r=nagisabors-2/+2
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-27Point at unclosed delimiters as part of the primary MultiSpanEsteban Kuber-3/+18
Both the place where the parser encounters a needed closed delimiter and the unclosed opening delimiter are important, so they should get the same level of highlighting in the output.
2021-08-27Introduce `~const`Deadbeef-26/+20
- [x] Removed `?const` and change uses of `?const` - [x] Added `~const` to the AST. It is gated behind const_trait_impl. - [x] Validate `~const` in ast_validation. - [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and `ConstIfConst` allowing future extensions) - [ ] Adjust trait selection and pre-existing code to use `BoundConstness`. - [ ] Optional steps (*for this PR, obviously*) - [ ] Fix #88155 - [ ] Do something with constness bounds in chalk
2021-08-25Use if-let guards in the codebaseLéo Lanteri Thauvin-19/+18
2021-08-25Convert some functions to return Cow<'static,str> instead of String to ↵klensy-2/+2
reduce potential reallocations
2021-08-22Fix more “a”/“an” typosFrank Steffahn-1/+1
2021-08-22Fix typos “a”→“an”Frank Steffahn-9/+9
2021-08-18Remove box syntax from rustc_parseest31-7/+7
2021-08-15Introduce hir::ExprKind::Let - Take 2Caio-1/+1
2021-08-12Use smaller spans for some structured suggestionsEsteban Kuber-39/+46
Use more accurate suggestion spans for * argument parse error * fully qualified path * missing code block type * numeric casts * E0212
2021-08-08Auto merge of #87235 - poliorcetics:issue-87217-fn-quali-order, r=nagisabors-1/+34
Improve diagnostics for wrongly ordered keywords in function declaration Fix #87217 `@rustbot` label A-diagnostics T-compiler
2021-08-04Auto merge of #87026 - FabianWolff:issue-86948, r=estebankbors-4/+51
Allow labeled loops as value expressions for `break` Fixes #86948. This is currently allowed: ```rust return 'label: loop { break 'label 42; }; break ('label: loop { break 'label 42; }); break 1 + 'label: loop { break 'label 42; }; break 'outer 'inner: loop { break 'inner 42; }; ``` But not this: ```rust break 'label: loop { break 'label 42; }; ``` I have fixed this, so that the above now parses as an unlabeled break with a labeled loop as its value expression.
2021-08-03Rollup merge of #87646 - JohnTitor:fix-parser-ice, r=oli-obkYuki Okushi-3/+1
Fix a parser ICE on invalid `fn` body Fixes #87635 A better fix would add a check for `fn` body on `expected_one_of_not_found` but I haven't come up with a graceful way. Any idea? r? ```@oli-obk``` ```@estebank```
2021-08-02Better message for invalid keyword placement in fnAlexis Bourget-1/+34
After this commit, `unsafe async fn ...` now suggests the `async unsafe` fix instead of misunderstanding the issue. This is not perfect for repeated keywords (`const async const`) and for keywords that are misplaced after `extern "some abi"` because of the way `check_fn_font_matter` works, but changing it breaks so many tests and diagnostics it has been judged too high a cost for this PR.
2021-08-01Auto merge of #87449 - matthiaskrgr:clippyy_v2, r=nagisabors-2/+1
more clippy::complexity fixes (also a couple of clippy::perf fixes)
2021-07-31Require parentheses to avoid confusions around labeled break and loop ↵Fabian Wolff-4/+51
expressions
2021-07-31Fix a parser ICE on invalid `fn` bodyYuki Okushi-3/+1
2021-07-30Use multispan suggestions more oftenEsteban Küber-10/+8
* Use more accurate span for `async move` suggestion * Use more accurate span for deref suggestion * Use `multipart_suggestion` more often
2021-07-25clippy::filter_map_identityMatthias Krüger-2/+1