about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
AgeCommit message (Collapse)AuthorLines
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-6/+6
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-17Auto merge of #114292 - estebank:issue-71039, r=b-naberbors-2/+2
More detail when expecting expression but encountering bad macro argument On nested macro invocations where the same macro fragment changes fragment type from one to the next, point at the chain of invocations and at the macro fragment definition place, explaining that the change has occurred. Fix #71039. ``` error: expected expression, found pattern `1 + 1` --> $DIR/trace_faulty_macros.rs:49:37 | LL | (let $p:pat = $e:expr) => {test!(($p,$e))}; | ------- -- this is interpreted as expression, but it is expected to be pattern | | | this macro fragment matcher is expression ... LL | (($p:pat, $e:pat)) => {let $p = $e;}; | ------ ^^ expected expression | | | this macro fragment matcher is pattern ... LL | test!(let x = 1+1); | ------------------ | | | | | this is expected to be expression | in this macro invocation | = note: when forwarding a matched fragment to another macro-by-example, matchers in the second macro will see an opaque AST of the fragment type, not the underlying tokens = note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info) ```
2023-11-16More detail when expecting expression but encountering bad macro argumentEsteban Küber-2/+2
Partially address #71039.
2023-11-14Detect more `=>` typosEsteban Küber-9/+10
Handle and recover `match expr { pat >= { arm } }`.
2023-11-09Suggest fix for ; within let-chainssjwang05-4/+20
2023-11-04fmtDinu Blanovschi-3/+1
2023-11-04feat(hir): Store the `Span` of the `move` keywordDinu Blanovschi-1/+4
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-2/+2
Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused.
2023-10-27Handle `move` generatorsOli Scherer-11/+8
2023-10-27Feature gate `gen` blocks, even in 2024 editionOli Scherer-1/+2
2023-10-27Add gen blocks to ast and do some broken ast loweringOli Scherer-18/+14
2023-10-26Reserve `gen` keyword for `gen {}` blocks and `gen fn` in 2024 editionOli Scherer-0/+18
2023-10-20s/generator/coroutine/Oli Scherer-1/+1
2023-10-15Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstriebbors-30/+34
Format all the let-chains in compiler crates Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped). This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else. I will also add this commit to the ignore list after it has landed. The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree. ``` ~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates ~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif ``` cc `@rust-lang/rustfmt` r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :> cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
2023-10-13Auto merge of #116645 - estebank:issue-116608, r=oli-obkbors-3/+15
Detect ruby-style closure in parser When parsing a closure without a body that is surrounded by a block, suggest moving the opening brace after the closure head. Fix #116608.
2023-10-13Format all the let chains in compilerMichael Goulet-30/+34
2023-10-12Detect ruby-style closure in parserEsteban Küber-3/+15
When parsing a closure without a body that is surrounded by a block, suggest moving the opening brace after the closure head. Fix #116608.
2023-10-12Rename `Token::is_op` as `Token::is_punct`.Nicholas Nethercote-1/+1
For consistency with `proc_macro::Punct`.
2023-10-04review commentsEsteban Küber-3/+2
2023-10-03Detect missing `=>` after match guard during parsingEsteban Küber-19/+74
``` error: expected one of `,`, `:`, or `}`, found `.` --> $DIR/missing-fat-arrow.rs:25:14 | LL | Some(a) if a.value == b { | - while parsing this struct LL | a.value = 1; | -^ expected one of `,`, `:`, or `}` | | | while parsing this struct field | help: try naming a field | LL | a: a.value = 1; | ++ help: you might have meant to start a match arm after the match guard | LL | Some(a) if a.value == b => { | ++ ``` Fix #78585.
2023-09-13Address review commentsMatthew Jasper-4/+13
- Add doc comment to new type - Restore "only supported directly in conditions of `if` and `while` expressions" note - Rename variant with clearer name
2023-09-11Reduce double errors for invalid let expressionsMatthew Jasper-3/+2
Previously some invalid let expressions would result in both a feature error and a parsing error. Avoid this and ensure that we only emit the parsing error when this happens.
2023-09-11Move let expression checking to parsingMatthew Jasper-121/+248
There was an incomplete version of the check in parsing and a second version in AST validation. This meant that some, but not all, invalid uses were allowed inside macros/disabled cfgs. It also means that later passes have a hard time knowing when the let expression is in a valid location, sometimes causing ICEs. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress later errors and MIR construction for invalid let expressions.
2023-08-28Allow stuct literals in if let guardsMatthew Jasper-3/+1
This is consistent with normal match guards.
2023-08-19Fix a stack overflow with long else if chainsJohn Kåre Alsaker-1/+2
2023-08-18Use `interpolated_or_expr_span` in one suitable place.Nicholas Nethercote-7/+1
2023-08-18Refactor `interpolated_or_expr_span`.Nicholas Nethercote-20/+12
It's much more complicated than it needs to be, and it doesn't modify the expression. We can do the `Result` handling outside of it, and change it to just return a span. Also fix an errant comma that makes the comment hard to read.
2023-08-04Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31Matthias Krüger-4/+7
Improve spans for indexing expressions fixes #114388 Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR. r? compiler-errors
2023-08-04Improve spans for indexing expressionsNilstrieb-4/+7
Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.
2023-08-03Rollup merge of #114300 - MU001999:fix/turbofish-pat, r=estebankMatthias Krüger-2/+2
Suggests turbofish in patterns Fixes #114112 r? ```@estebank```
2023-08-03Avoid too many expected symbols and reduce `None`sr0cky-3/+3
2023-08-03Remove `MacDelimiter`.Nicholas Nethercote-1/+1
It's the same as `Delimiter`, minus the `Invisible` variant. I'm generally in favour of using types to make impossible states unrepresentable, but this one feels very low-value, and the conversions between the two types are annoying and confusing. Look at the change in `src/tools/rustfmt/src/expr.rs` for an example: the old code converted from `MacDelimiter` to `Delimiter` and back again, for no good reason. This suggests the author was confused about the types.
2023-08-03Keep the suggestion for wrong arbitrary self typesMu001999-5/+5
2023-08-02Move `TokenCursor::break_last_token` into `Parser`.Nicholas Nethercote-1/+1
Similar to the last commit, it's more of a `Parser`-level concern than a `TokenCursor`-level concern. And the struct size reductions are nice. After this change, `TokenCursor` is as minimal as possible (two fields and two methods) which is nice.
2023-07-30Rollup merge of #114256 - Urgau:fix-issue-114180, r=WaffleLapkinMatthias Krüger-1/+1
Fix invalid suggestion for mismatched types in closure arguments This PR fixes the invalid suggestion for mismatched types in closure arguments. The invalid suggestion came from a wrongly created span in the parser for closure arguments that don't have a type specified. Specifically, the span in this case was the last token span, but in the case of tuples, the span represented the last parenthesis instead of the whole tuple, which is fixed by taking the more accurate span of the pattern. There is one unfortunate downside of this fix, it worsens even more the diagnostic for mismatched types in closure args without an explicit type. This happens because there is no correct span for implied inferred type. I tried also fixing this but it's a rabbit hole. Fixes https://github.com/rust-lang/rust/issues/114180
2023-07-30Fix invalid suggestion for mismatched types in closure argumentsUrgau-1/+1
The invalid suggestion came from a wrongly created span in `rustc_parse' for closure arguments that didn't have a type specified. Specifically, the span in this case was the last token span, but in the case of tuples, the span represented the last parenthesis instead of the whole tuple, which is fixed by taking the more accurate span of the pattern.
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-2/+2
2023-07-24Optimize format usageYuri Astrakhan-1/+1
Per #112156, using `&` in `format!` may cause a small perf delay, so I tried to clean up one module at a time format usage. This PR includes a few removals of the ref in format (they do compile locally without the ref), as well as a few format inlining for consistency.
2023-07-22Support interpolated block for try and asyncMichael Goulet-4/+10
2023-07-19Make it clearer that edition functions are >=, not ==Michael Goulet-5/+5
2023-06-27Rollup merge of #112978 - compiler-errors:bad-block-sugg, r=davidtwcoMatthias Krüger-0/+4
Add suggestion for bad block fragment error Makes it a bit clearer how to fix this parser restriction
2023-06-27Rollup merge of #112518 - chenyukang:yukang-fix-112458, r=davidtwcoMatthias Krüger-2/+8
Detect actual span for getting unexpected token from parsing macros Fixes #112458
2023-06-23Add suggestion for bad block fragment errorMichael Goulet-0/+4
2023-06-19Syntatically accept `become` expressionsMaybe Waffle-0/+12
2023-06-15Handle interpolated literal errorsMichael Goulet-6/+3
2023-06-11Detect actual span for getting unexpected token from parsing macrosyukang-2/+8
2023-06-09Move parse_seq_to_before_end closure to own functionest31-43/+37
2023-06-08Support float-like tuple indices in offset_of!()est31-2/+45
The tokenizer gives us whole float literal tokens, we have to split them up in order to be able to create field access from them.
2023-06-08Move float breaking out of Parser::parse_expr_tuple_field_access_floatest31-22/+53
Purely a refactor in preparation of using it in offset_of!() parsing
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-4/+4