about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/pat.rs
AgeCommit message (Collapse)AuthorLines
2025-08-14Pass the target type down to `parse_attribute_list`Jonathan Brouwer-2/+2
2025-08-09remove `P`Deadbeef-3/+2
2025-06-30Introduce `ByteSymbol`.Nicholas Nethercote-8/+4
It's like `Symbol` but for byte strings. The interner is now used for both `Symbol` and `ByteSymbol`. E.g. if you intern `"dog"` and `b"dog"` you'll get a `Symbol` and a `ByteSymbol` with the same index and the characters will only be stored once. The motivation for this is to eliminate the `Arc`s in `ast::LitKind`, to make `ast::LitKind` impl `Copy`, and to avoid the need to arena-allocate `ast::LitKind` in HIR. The latter change reduces peak memory by a non-trivial amount on literal-heavy benchmarks such as `deep-vector` and `tuple-stress`. `Encoder`, `Decoder`, `SpanEncoder`, and `SpanDecoder` all get some changes so that they can handle normal strings and byte strings. This change does slow down compilation of programs that use `include_bytes!` on large files, because the contents of those files are now interned (hashed). This makes `include_bytes!` more similar to `include_str!`, though `include_bytes!` contents still aren't escaped, and hashing is still much cheaper than escaping.
2025-05-05Auto merge of #140453 - Zoxc:next-disambiguator, r=oli-obkbors-2/+1
Remove global `next_disambiguator` state and handle it with a `DisambiguatorState` type This removes `Definitions.next_disambiguator` as it doesn't guarantee deterministic def paths when `create_def` is called in parallel. Instead a new `DisambiguatorState` type is passed as a mutable reference to `create_def` to help create unique def paths. `create_def` calls with distinct `DisambiguatorState` instances must ensure that that the def paths are unique without its help. Anon associated types did rely on this global state for uniqueness and are changed to use (method they're defined in + their position in the method return type) as the `DefPathData` to ensure uniqueness. This also means that the method they're defined in appears in error messages, which is nicer. `DefPathData::NestedStatic` is added to use for nested data inside statics instead of reusing `DefPathData::AnonConst` to avoid conflicts with those. cc `@oli-obk`
2025-04-28We always use the current item as parent, so no need to pass itOli Scherer-2/+1
2025-04-28Add or-patterns to pattern typesOli Scherer-0/+5
2025-03-28Add `{ast,hir,thir}::PatKind::Missing` variants.Nicholas Nethercote-0/+1
"Missing" patterns are possible in bare fn types (`fn f(u32)`) and similar places. Currently these are represented in the AST with `ast::PatKind::Ident` with no `by_ref`, no `mut`, an empty ident, and no sub-pattern. This flows through to `{hir,thir}::PatKind::Binding` for HIR and THIR. This is a bit nasty. It's very non-obvious, and easy to forget to check for the exceptional empty identifier case. This commit adds a new variant, `PatKind::Missing`, to do it properly. The process I followed: - Add a `Missing` variant to `{ast,hir,thir}::PatKind`. - Chang `parse_param_general` to produce `ast::PatKind::Missing` instead of `ast::PatKind::Missing`. - Look through `kw::Empty` occurrences to find functions where an existing empty ident check needs replacing with a `PatKind::Missing` check: `print_param`, `check_trait_item`, `is_named_param`. - Add a `PatKind::Missing => unreachable!(),` arm to every exhaustive match identified by the compiler. - Find which arms are actually reachable by running the test suite, changing them to something appropriate, usually by looking at what would happen to a `PatKind::Ident`/`PatKind::Binding` with no ref, no `mut`, an empty ident, and no subpattern. Quite a few of the `unreachable!()` arms were never reached. This makes sense because `PatKind::Missing` can't happen in every pattern, only in places like bare fn tys and trait fn decls. I also tried an alternative approach: modifying `ast::Param::pat` to hold an `Option<P<Pat>>` instead of a `P<Pat>`, but that quickly turned into a very large and painful change. Adding `PatKind::Missing` is much easier.
2025-03-07Pass `Option<Symbol>` to `def_path_data`/`create_def` methods.Nicholas Nethercote-2/+2
It's clearer than using `kw::Empty` to mean `None`.
2025-03-06Remove the `Option` part of range ends in the HIROli Scherer-10/+112
2025-02-24Introduce new parsing infrastructure and types for parsed attributesJana Dönszelmann-1/+1
fixup docs in parser
2025-02-11Add a TyPat in the AST to reuse the generic arg lowering logicOli Scherer-69/+11
2025-02-04Allow using named consts in pattern typesOli Scherer-13/+14
2025-02-03Use a different hir type for patterns in pattern types than we use in match ↵Oli Scherer-2/+78
patterns
2025-01-29Eliminate PatKind::PathOli Scherer-10/+23
2025-01-22Enforce that all spans are lowered in ast loweringOli Scherer-14/+10
2025-01-08Rename PatKind::Lit to ExprOli Scherer-2/+2
2025-01-08Exhaustively handle expressions in patternsOli Scherer-13/+46
2024-12-31add guard patterns to HIR and implement loweringMax Niederman-2/+3
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-13Keep track of patterns that could have introduced a binding, but didn'tEsteban Küber-1/+8
When we recover from a pattern parse error, or a pattern uses `..`, we keep track of that and affect resolution error for missing bindings that could have been provided by that pattern. We differentiate between `..` and parse recovery. We silence resolution errors likely caused by the pattern parse error. ``` error[E0425]: cannot find value `title` in this scope --> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:19:30 | LL | println!("[{}]({})", title, url); | ^^^^^ not found in this scope | note: `Website` has a field `title` which could have been included in this pattern, but it wasn't --> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:17:12 | LL | / struct Website { LL | | url: String, LL | | title: Option<String> , | | ----- defined here LL | | } | |_- ... LL | if let Website { url, .. } = website { | ^^^^^^^^^^^^^^^^^^^ this pattern doesn't include `title`, which is available in `Website` ``` Fix #74863.
2024-11-24add guard pattern AST nodeMax Niederman-0/+2
2024-10-28more consistent debug_assertionsAdwin White-12/+18
2024-10-28Add duplicate lowering checkAdwin White-2/+2
2024-10-28Lower AST node id only onceAdwin White-19/+39
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-09-20Conditionally allow lowering RTN (..) in pathsMichael Goulet-1/+4
2024-07-29Reformat `use` declarations.Nicholas Nethercote-8/+8
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-04-28Add a note to the ArbitraryExpressionInPattern errorest31-1/+5
2024-04-17Rename `BindingAnnotation` to `BindingMode`Jules Bertholet-1/+1
2024-03-21Implement macro-based deref!() syntax for deref patternsMichael Goulet-0/+3
Stop using `box PAT` syntax for deref patterns, as it's misleading and also causes their semantics being tangled up.
2024-02-25Add `ErrorGuaranteed` to `ast::ExprKind::Err`Lieselotte-1/+1
2024-02-25Add `ast::ExprKind::Dummy`Lieselotte-1/+2
2024-02-07No need to take ImplTraitContext by refMichael Goulet-3/+3
2024-01-17Add `PatKind::Err`Lieselotte-0/+1
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-4/+4
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-23bool->enum for ast::PatKind::Struct presence of `..`Alona Enraght-Moony-1/+1
See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed.
2023-11-29Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errorsMatthias Krüger-0/+1
Add `never_patterns` feature gate This PR adds the feature gate and most basic parsing for the experimental `never_patterns` feature. See the tracking issue (https://github.com/rust-lang/rust/issues/118155) for details on the experiment. `@scottmcm` has agreed to be my lang-team liaison for this experiment.
2023-11-29Add `never_patterns` feature gateNadrieril-0/+1
2023-11-28Reduce exposure of some things.Nicholas Nethercote-1/+1
2023-08-06lower impl const to bind to host effect paramDeadbeef-0/+3
2023-02-25Add ErrorGuaranteed to HIR ExprKind::ErrMichael Goulet-2/+2
2022-12-25fix more clippy::style findingsMatthias Krüger-3/+3
match_result_ok obfuscated_if_else single_char_add writeln_empty_string collapsible_match iter_cloned_collect unnecessary_mut_passed
2022-11-22`rustc_ast_lowering`: remove `ref` patternsMaybe Waffle-27/+27
2022-11-11Introduce `ExprKind::IncludedBytes`clubby789-1/+4
2022-10-11rustc_hir: Less error-prone methods for accessing `PartialRes` resolutionVadim Petrochenkov-1/+1
2022-09-08Introduce `DotDotPos`.Nicholas Nethercote-2/+2
This shrinks `hir::Pat` from 88 to 72 bytes.
2022-09-06Pass ImplTraitContext as &mut to avoid the need of ↵Santiago Pastorino-3/+3
ImplTraitContext::reborrow later on
2022-09-06Auto merge of #101241 - camsteffen:refactor-binding-annotations, r=cjgillotbors-18/+9
`BindingAnnotation` refactor * `ast::BindingMode` is deleted and replaced with `hir::BindingAnnotation` (which is moved to `ast`) * `BindingAnnotation` is changed from an enum to a tuple struct e.g. `BindingAnnotation(ByRef::No, Mutability::Mut)` * Associated constants added for convenience `BindingAnnotation::{NONE, REF, MUT, REF_MUT}` One goal is to make it more clear that `BindingAnnotation` merely represents syntax `ref mut` and not the actual binding mode. This was especially confusing since we had `ast::BindingMode`->`hir::BindingAnnotation`->`thir::BindingMode`. I wish there were more symmetry between `ByRef` and `Mutability` (variant) naming (maybe `Mutable::Yes`?), and I also don't love how long the name `BindingAnnotation` is, but this seems like the best compromise. Ideas welcome.
2022-09-05Address review comments.Nicholas Nethercote-1/+1
2022-09-05Make `hir::PathSegment::hir_id` non-optional.Nicholas Nethercote-1/+2