about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
AgeCommit message (Collapse)AuthorLines
2023-01-31Rollup merge of #107467 - WaffleLapkin:uneq, r=oli-obkGuillaume Gomez-22/+22
Improve enum checks Some light refactoring.
2023-01-31Auto merge of #105650 - cassaundra:float-literal-suggestion, r=pnkfelixbors-1/+10
Fix invalid float literal suggestions when recovering an integer Only suggest adding a zero to integers with a preceding dot when the change will result in a valid floating point literal. For example, `.0x0` should not be turned into `0.0x0`. r? nnethercote
2023-01-30Fix invalid float literal suggestions when recovering an integerCassaundra Smith-1/+10
Only suggest adding a zero to integers with a preceding dot when the change will result in a valid floating point literal. For example, `.0x0` should not be turned into `0.0x0`.
2023-01-30Replace enum `==`s with `match`es where it makes senseMaybe Waffle-22/+22
2023-01-29Insert whitespace to avoid ident concatenation in suggestionRyo Yoshida-1/+1
2023-01-28Migrate some range parsing diagnosticsclubby789-19/+8
2023-01-28Check for missing space between fat arrow and range patternclubby789-14/+32
2023-01-28Rollup merge of #107190 - fmease:fix-81698, r=compiler-errorsMatthias Krüger-14/+56
Recover from more const arguments that are not wrapped in curly braces Recover from some array, borrow, tuple & arithmetic expressions in const argument positions that lack curly braces and provide a suggestion to fix the issue continuing where #92884 left off. Examples of such expressions: `[]`, `[0]`, `[1, 2]`, `[0; 0xff]`, `&9`, `("", 0)` and `(1 + 2) * 3` (we previously did not recover from them). I am not entirely happy with my current solution because the code that recovers from `[0]` (coinciding with a malformed slice type) and `[0; 0]` (coinciding with a malformed array type) is quite fragile as the aforementioned snippets are actually successfully parsed as types by `parse_ty` since it itself already recovers from them (returning `[⟨error⟩]` and `[⟨error⟩; 0]` respectively) meaning I have to manually look for `TyKind::Err`s and construct a separate diagnostic for the suggestion to attach to (thereby emitting two diagnostics in total). Fixes #81698. `@rustbot` label A-diagnostics r? diagnostics
2023-01-27recover more unbraced const argsLeón Orell Valerian Liehr-14/+56
2023-01-26Rollup merge of #106960 - estebank:parse-anon-enums, r=cjgillotMatthias Krüger-18/+104
Teach parser to understand fake anonymous enum syntax Parse `Ty | OtherTy` in function argument and return types. Parse type ascription in top level patterns. Minimally address #100741.
2023-01-23Add suggestion to remove if in let...else blockEdward Shen-13/+20
Adds an additional hint to failures where we encounter an else keyword while we're parsing an if-let block. This is likely that the user has accidentally mixed if-let and let...else together.
2023-01-23review comment: Remove AST AnonTyEsteban Küber-1/+1
2023-01-20Rollup merge of #106783 - WaffleLapkin:break-my-ident, r=wesleywiserMatthias Krüger-7/+54
Recover labels written as identifiers This adds recovery for `break label expr` and `continue label`, as well as a test for `break label`.
2023-01-17Rollup merge of #104505 - WaffleLapkin:no-double-spaces-in-comments, r=jackh726Matthias Krüger-2/+2
Remove double spaces after dots in comments Most of the comments do not have double spaces, so I assume these are typos.
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-2/+2
2023-01-17Rollup merge of #106712 - Ezrashaw:impl-ref-trait, r=estebankMatthias Krüger-4/+36
make error emitted on `impl &Trait` nicer Fixes #106694 Turned out to be simpler than I thought, also added UI test. Before: ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9bda53271ef3a8886793cf427b8cea91)) ```text error: expected one of `:`, ``@`,` or `|`, found `)` --> src/main.rs:2:22 | 2 | fn foo(_: impl &Trait) {} | ^ expected one of `:`, ``@`,` or `|` | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) help: if this is a parameter name, give it a type | 2 | fn foo(_: impl Trait: &TypeName) {} | ~~~~~~~~~~~~~~~~ help: if this is a type, explicitly ignore the parameter name | 2 | fn foo(_: impl _: &Trait) {} | ++ error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, `~`, lifetime, or path, found `&` --> src/main.rs:2:16 | 2 | fn foo(_: impl &Trait) {} | -^ expected one of 9 possible tokens | | | help: missing `,` error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path, found `&` --> src/main.rs:3:11 | 3 | fn bar<T: &Trait>(_: T) {} | ^ expected one of 10 possible tokens ``` After: ```text error: expected a trait, found type --> <anon>:2:16 | 2 | fn foo(_: impl &Trait) {} | -^^^^^ | | | help: consider removing the indirection error: expected a trait, found type --> <anon>:3:11 | 3 | fn bar<T: &Trait>(_: T) {} | -^^^^^ | | | help: consider removing the indirection ```
2023-01-17Emit fewer errors on patterns with possible type ascriptionEsteban Küber-0/+2
2023-01-17Teach parser to understand fake anonymous enum syntaxEsteban Küber-18/+102
Parse `-> Ty | OtherTy`. Parse type ascription in top level patterns.
2023-01-16fix dropping diagnostic without emitEzra Shaw-1/+2
2023-01-15Rollup merge of #106863 - anden3:compiler-double-spaces, r=NilstriebMatthias Krüger-1/+1
Remove various double spaces in compiler source comments. Was asked to do it by `@Nilstrieb`
2023-01-15make error emitted on `impl &Trait` nicerEzra Shaw-4/+35
2023-01-14Rollup merge of #106849 - WaffleLapkin:unvec, r=NilstriebMatthias Krüger-3/+2
Allocate one less vec while parsing arrays Probably does not matter, but imo a little bit nicer.
2023-01-14Fix some missed double spaces.André Vennberg-1/+1
2023-01-14Allocate one less vec in `parser/expr.rs`Maybe Waffle-3/+2
2023-01-14Improve comments in `parser/expr.rs`Maybe Waffle-9/+13
2023-01-14Make `LhsExpr::AlreadyParsed` a named structMaybe Waffle-6/+12
2023-01-13Recover labels written as identifiersMaybe Waffle-5/+52
2023-01-13Auto merge of #106004 - fee1-dead-contrib:const-closures, r=oli-obkbors-1/+17
Const closures cc https://github.com/rust-lang/rust/issues/106003
2023-01-12Remove an `unwrap()` from parser that can be written as if-let-chainMaybe Waffle-2/+2
2023-01-12parse const closuresDeadbeef-1/+17
2023-01-12Auto merge of #106537 - ↵bors-13/+119
fmease:recover-where-clause-before-tuple-struct-body, r=estebank Recover from where clauses placed before tuple struct bodies Open to any suggestions regarding the phrasing of the diagnostic. Fixes #100790. `@rustbot` label A-diagnostics r? diagnostics
2023-01-11parser: recover from where clauses placed before tuple struct bodiesLeón Orell Valerian Liehr-13/+119
2023-01-11Detect struct literal needing parenthesesEsteban Küber-15/+38
Fix #82051.
2023-01-08Do not emit structured suggestion for turbofish with wrong spanEsteban Küber-2/+10
Fix #79161.
2023-01-06Tiny formatting fixEsteban Küber-6/+7
2022-12-30Auto merge of #106268 - kraktus:patch-2, r=Nilstriebbors-1/+1
fix comment for `TokenCursor::desugar` the hashes of the text were forgotten.
2022-12-29Auto merge of #106266 - matthiaskrgr:rollup-cxrdbzy, r=matthiaskrgrbors-3/+94
Rollup of 9 pull requests Successful merges: - #104531 (Provide a better error and a suggestion for `Fn` traits with lifetime params) - #105899 (`./x doc library --open` opens `std`) - #106190 (Account for multiple multiline spans with empty padding) - #106202 (Trim more paths in obligation types) - #106234 (rustdoc: simplify settings, help, and copy button CSS by not reusing) - #106236 (docs/test: add docs and a UI test for `E0514` and `E0519`) - #106259 (Update Clippy) - #106260 (Fix index out of bounds issues in rustdoc) - #106263 (Formatter should not try to format non-Rust files) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-12-29fix comment for `TokenCursor::desugar`kraktus-1/+1
the hashes of the text were forgotten.
2022-12-29Rollup merge of #106242 - estebank:diff-markers, r=jyn514Matthias Krüger-5/+120
Detect diff markers in the parser Partly address #32059.
2022-12-29Rollup merge of #106221 - Nilstrieb:rptr-more-like-ref-actually, ↵Matthias Krüger-2/+2
r=compiler-errors Rename `Rptr` to `Ref` in AST and HIR The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-29Provide a better error for `Fn` traits with lifetime paramsYutaro Ohno-3/+94
Currently, given `Fn`-family traits with lifetime params like `Fn<'a>(&'a str) -> bool`, many unhelpful errors show up. These are a bit confusing. This commit allows these situations to suggest simply using higher-ranked trait bounds like `for<'a> Fn(&'a str) -> bool`.
2022-12-28Add support for diff3 formatEsteban Küber-0/+7
2022-12-28Tweak wordingEsteban Küber-6/+17
2022-12-28Account for ADT bodies and struct expressionsEsteban Küber-2/+30
2022-12-28Detect diff markers in the parserEsteban Küber-3/+72
Partly address #32059.
2022-12-28Rollup merge of #105570 - Nilstrieb:actual-best-failure, r=compiler-errorsMatthias Krüger-0/+4
Properly calculate best failure in macro matching Previously, we used spans. This was not good. Sometimes, the span of the token that failed to match may come from a position later in the file which has been transcribed into a token stream way earlier in the file. If precisely this token fails to match, we think that it was the best match because its span is so high, even though other arms might have gotten further in the token stream. We now try to properly use the location in the token stream. This needs a little cleanup as the `best_failure` field is getting out of hand but it should be mostly good to go. I hope I didn't violate too many abstraction boundaries..
2022-12-28Rename `Rptr` to `Ref` in AST and HIRNilstrieb-2/+2
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-28Rollup merge of #106176 - compiler-errors:fn-kw-as-fn-trait, r=estebankMatthias Krüger-3/+45
Recover `fn` keyword as `Fn` trait in bounds `impl fn()` -> `impl Fn()` Fixes #82515
2022-12-27Rollup merge of #106066 - JohnTitor:rm-bindings-after-at-fixme, ↵Matthias Krüger-12/+6
r=compiler-errors Always suggest as `MachineApplicable` in `recover_intersection_pat` This resolves one FIXME in `recover_intersection_pat` by always applying `MachineApplicable` when suggesting, as `bindings_after_at` is now stable. This also separates a test to apply `// run-rustfix`. Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-12-27Recover `fn` keyword as `Fn` trait in boundsMichael Goulet-3/+45