about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/pat.rs
AgeCommit message (Collapse)AuthorLines
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-1/+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-30Account for `ref` and `mut` in the wrong place for pattern ident renamingEsteban Küber-1/+33
If the user writes `S { ref field: name }` instead of `S { field: ref name }`, we suggest the correct code. Fix #72298.
2023-09-12Only suggest turbofish in patterns if we may recoverLeón Orell Valerian Liehr-1/+2
2023-08-04Rollup merge of #113999 - Centri3:macro-arm-expand, r=wesleywiserMatthias Krüger-2/+6
Specify macro is invalid in certain contexts Adds a note when a macro is used where it really shouldn't be. Closes #113766
2023-08-03Rollup merge of #114300 - MU001999:fix/turbofish-pat, r=estebankMatthias Krüger-22/+46
Suggests turbofish in patterns Fixes #114112 r? ```@estebank```
2023-08-03Avoid too many expected symbols and reduce `None`sr0cky-15/+28
2023-08-03Apply suggestionsr0cky-2/+4
2023-08-03Keep the suggestion for wrong arbitrary self typesMu001999-14/+22
2023-08-01Suggests turbofish in patternsMu001999-0/+1
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-3/+3
2023-07-24Recover from some macrosCatherine Flores-5/+1
2023-07-24Specify macro is invalid in certain contextsCatherine-2/+10
2023-07-20Don't translate compiler-internal bug messagesOli Scherer-33/+16
2023-06-03Fix suggestion for matching struct with `..` on both ends许杰友 Jieyou Xu (Joe)-12/+45
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-3/+3
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-05-01Rip it outNilstrieb-5/+5
My type ascription Oh rip it out Ah If you think we live too much then You can sacrifice diagnostics Don't mix your garbage Into my syntax So many weird hacks keep diagnostics alive Yet I don't even step outside So many bad diagnostics keep tyasc alive Yet tyasc doesn't even bother to survive!
2023-04-27Migrate trivially translatable `rustc_parse` diagnosticsclubby789-13/+8
2023-03-20feat: implement error recovery in `expected_ident_found`Ezra Shaw-2/+8
2023-03-19refactor: improve "ident starts with number" errorEzra Shaw-5/+1
2023-03-09feat/refactor: improve errors in case of ident with number at startEzra Shaw-0/+4
2023-02-22errors: generate typed identifiers in each crateDavid Wood-3/+2
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-21Use `ThinVec` in `ast::PatKind::Struct`.Nicholas Nethercote-4/+4
2023-02-21Use `ThinVec` in various AST types.Nicholas Nethercote-2/+3
This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions.
2023-02-02Rollup merge of #107493 - clubby789:range-fat-arrow-followup, r=estebankMatthias Krüger-1/+1
Improve diagnostic for missing space in range pattern Improves the diagnostic in #107425 by turning it into a note explaining the parsing issue. r? `@compiler-errors`
2023-02-02Rollup merge of #106919 - compiler-errors:underscore-typo-in-field-pat, ↵Matthias Krüger-7/+11
r=jackh726 Recover `_` as `..` in field pattern
2023-02-02Improve diagnostic for missing space in range patternclubby789-1/+1
2023-02-02Recover _ as .. in field patternMichael Goulet-7/+11
2023-02-02Revert "Teach parser to understand fake anonymous enum syntax" and related ↵Michael Goulet-2/+1
commits Revert "review comment: Remove AST AnonTy" This reverts commit 020cca8d36cb678e3ddc2ead41364be314d19e93. Revert "Ensure macros are not affected" This reverts commit 12d18e403139eeeeb339e8611b2bed4910864edb. Revert "Emit fewer errors on patterns with possible type ascription" This reverts commit c847a01a3b1f620c4fdb98c75805033e768975d1. Revert "Teach parser to understand fake anonymous enum syntax" This reverts commit 2d824206655bfb26cb5eed43490ee396542b153e.
2023-02-01Convert rustc_parse::parser::pat::Expected to enumXiretza-16/+32
This is required in order to support translatable diagnostics.
2023-02-01rustc_parse: migrate more to diagnostic structsXiretza-177/+104
2023-01-28Migrate some range parsing diagnosticsclubby789-19/+8
2023-01-28Check for missing space between fat arrow and range patternclubby789-13/+31
2023-01-17Teach parser to understand fake anonymous enum syntaxEsteban Küber-1/+2
Parse `-> Ty | OtherTy`. Parse type ascription in top level patterns.
2023-01-14Fix some missed double spaces.André Vennberg-1/+1
2022-12-23Always suggest as `MachineApplicable` in `recover_intersection_pat`Yuki Okushi-12/+6
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-12-05Parameterise `Parser::{recover_unclosed_char,handle_missing_lit}`.Nicholas Nethercote-9/+13
These two methods both produce a `MetaItemLit`, and then some of the call sites convert the `MetaItemLit` to a `token::Lit` with `as_token_lit`. This commit parameterises these two methods with a `mk_lit_char` closure, which can be used to produce either `MetaItemLit` or `token::Lit` directly as necessary.
2022-12-02Remove `token::Lit` from `ast::MetaItemLit`.Nicholas Nethercote-1/+1
`token::Lit` contains a `kind` field that indicates what kind of literal it is. `ast::MetaItemLit` currently wraps a `token::Lit` but also has its own `kind` field. This means that `ast::MetaItemLit` encodes the literal kind in two different ways. This commit changes `ast::MetaItemLit` so it no longer wraps `token::Lit`. It now contains the `symbol` and `suffix` fields from `token::Lit`, but not the `kind` field, eliminating the redundancy.
2022-11-22`rustc_parse`: remove `ref` patternsMaybe Waffle-3/+3
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-1/+1
`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways: - For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used. - For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used. In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`). This commit splits `MacArgs` in two: - `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`. - `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`. Various other related things are renamed as well. These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values.
2022-11-17Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and ↵Nicholas Nethercote-2/+6
patterns.
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-1/+1
Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. This commit changes the language very slightly. Some programs that used to not compile now will compile. This is because some invalid literals that are removed by `cfg` or attribute macros will no longer trigger errors. See this comment for more details: https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
2022-10-22Recover unclosed char literal being parsed as lifetimeMichael Goulet-0/+20
2022-10-08Stabilize half_open_range_patternsUrgau-1/+0
2022-09-30Remove expr_parentheses_needed from ParseSessMichael Goulet-1/+2
2022-09-27Move rustc_parse diagnostic structs to separate moduleXiretza-1/+1
2022-09-06Auto merge of #101362 - compiler-errors:unnecessary-let, r=cjgillotbors-1/+8
Suggest removing unnecessary prefix let in patterns Helps with #101291, though I think `@estebank` probably wants this: > Finally, I think it'd be nice if we could detect that we don't know for sure and "just" swallow the rest of the expression (find the next ; accounting for nested braces) or the end of the item (easier). ... to be implemented before we close that issue out completely.
2022-09-03Suggest removing unnecessary prefix let in patternsMichael Goulet-1/+8
2022-09-02Refactor and re-use BindingAnnotationCameron Steffen-23/+19
2022-08-22Use `AttrVec` in more places.Nicholas Nethercote-4/+4
In some places we use `Vec<Attribute>` and some places we use `ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points where we have to convert between `Vec` and `ThinVec`. This commit changes the places that use `Vec<Attribute>` to use `AttrVec`. A lot of this is mechanical and boring, but there are some interesting parts: - It adds a few new methods to `ThinVec`. - It implements `MapInPlace` for `ThinVec`, and introduces a macro to avoid the repetition of this trait for `Vec`, `SmallVec`, and `ThinVec`. Overall, it makes the code a little nicer, and has little effect on performance. But it is a precursor to removing `rustc_data_structures::thin_vec::ThinVec` and replacing it with `thin_vec::ThinVec`, which is implemented more efficiently.
2022-08-17Box the `MacCall` in various types.Nicholas Nethercote-1/+1