about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
AgeCommit message (Collapse)AuthorLines
2024-04-18Simplify `static_assert_size`s.Nicholas Nethercote-3/+3
We want to run them on all 64-bit platforms.
2024-04-17Rename `BindingAnnotation` to `BindingMode`Jules Bertholet-18/+16
2024-04-17Rollup merge of #124051 - dtolnay:emptyset, r=compiler-errorsMatthias Krüger-1/+1
Fix empty-set symbol in comments The symbol in the original code is U+00D8 "LATIN CAPITAL LETTER O WITH STROKE" (https://en.wikipedia.org/wiki/%C3%98) which is an uppercase letter in Danish, Norwegian, Faroese, and Southern Sámi alphabets. The symbol that was intended is U+2205 "EMPTY SET" (https://en.wikipedia.org/wiki/Empty_set#Notation). | Before | After | |---|---| | ![Screenshot from 2024-04-16 18-25-01](https://github.com/rust-lang/rust/assets/1940490/9b8b0624-cfa5-4b89-84e5-4c2b39c2cb8f) | ![Screenshot from 2024-04-16 18-25-05](https://github.com/rust-lang/rust/assets/1940490/6f6b34c3-0e47-4ba0-856d-be1dc164c94c) |
2024-04-17Rollup merge of #122813 - nnethercote:nicer-quals, r=compiler-errorsMatthias Krüger-5/+2
Qualifier tweaking Adding and removing qualifiers in some cases that make things nicer. Details in individual commits. r? `@compiler-errors`
2024-04-16Fix empty-set symbol in commentsDavid Tolnay-1/+1
2024-04-16Auto merge of #123468 - compiler-errors:precise-capturing, r=oli-obkbors-8/+51
Implement syntax for `impl Trait` to specify its captures explicitly (`feature(precise_capturing)`) Implements `impl use<'a, 'b, T, U> Sized` syntax that allows users to explicitly list the captured parameters for an opaque, rather than inferring it from the opaque's bounds (or capturing *all* lifetimes under 2024-edition capture rules). This allows us to exclude some implicit captures, so this syntax may be used as a migration strategy for changes due to #117587. We represent this list of captured params as `PreciseCapturingArg` in AST and HIR, resolving them between `rustc_resolve` and `resolve_bound_vars`. Later on, we validate that the opaques only capture the parameters in this list. We artificially limit the feature to *require* mentioning all type and const parameters, since we don't currently have support for non-lifetime bivariant generics. This can be relaxed in the future. We also may need to limit this to require naming *all* lifetime parameters for RPITIT, since GATs have no variance. I have to investigate this. This can also be relaxed in the future. r? `@oli-obk` Tracking issue: - https://github.com/rust-lang/rust/issues/123432
2024-04-16Avoid unnecessary `rustc_span::DUMMY_SP` usage.Nicholas Nethercote-5/+2
In some cases `DUMMY_SP` is already imported. In other cases this commit adds the necessary import, in files where `DUMMY_SP` is used more than once.
2024-04-16Rollup merge of #123462 - fmease:rn-mod-sep-to-path-sep, r=nnethercoteLeón Orell Valerian Liehr-26/+26
Cleanup: Rename `ModSep` to `PathSep` `::` is usually referred to as the *path separator* (citation needed). The existing name `ModSep` for *module separator* is a bit misleading since it in fact separates the segments of arbitrary path segments, not only ones resolving to modules. Let me just give a shout-out to associated items (`T::Assoc`, `<Ty as Trait>::function`) and enum variants (`Option::None`). Motivation: Reduce friction for new contributors, prevent potential confusion. cc `@petrochenkov` r? nnethercote or compiler
2024-04-15More polishingMichael Goulet-1/+3
2024-04-15Use a path instead of an ident (and stop manually resolving)Michael Goulet-2/+5
2024-04-15Validation and other thingsMichael Goulet-1/+1
2024-04-15Implement resolution, parse use<Self>Michael Goulet-1/+7
2024-04-15Use dedicated PreciseCapturingArg for representing what goes in use<>Michael Goulet-7/+23
2024-04-15Parsing , pre-lowering support for precise capturesMichael Goulet-6/+22
2024-04-14store the span of the nested part of the use tree in the astPietro Albini-2/+6
2024-04-12Rollup merge of #123223 - estebank:issue-123079, r=pnkfelixMatthias Krüger-13/+7
Fix invalid silencing of parsing error Given ```rust macro_rules! a { ( ) => { impl<'b> c for d { e::<f'g> } }; } ``` ensure an error is emitted. Fix #123079.
2024-04-11remove some things that do not need to beMatthias Krüger-2/+1
2024-04-10Properly handle emojis as literal prefix in macrosEsteban Küber-1/+4
Do not accept the following ```rust macro_rules! lexes {($($_:tt)*) => {}} lexes!(🐛"foo"); ``` Before, invalid emoji identifiers were gated during parsing instead of lexing in all cases, but this didn't account for macro expansion of literal prefixes. Fix #123696.
2024-04-08parser: reduce visibility of unnecessary public `UnmatchedDelim`Yutaro Ohno-5/+2
`lexer::UnmatchedDelim` struct in `rustc_parse` is unnecessary public outside of the crate. This commit reduces the visibility to `pub(crate)`. Beside, this removes unnecessary field `expected_delim` that causes warnings after changing the visibility.
2024-04-07Fix invalid silencing of parsing errorEsteban Küber-13/+7
Given ```rust macro_rules! a { ( ) => { impl<'b> c for d { e::<f'g> } }; } ``` ensure an error is emitted. Fix #123079.
2024-04-04Rename ModSep to PathSepLeón Orell Valerian Liehr-26/+26
2024-04-03Rollup merge of #123401 - Zalathar:assert-size-aarch64, r=fmeaseJacob Pratt-3/+3
Check `x86_64` size assertions on `aarch64`, too (Context: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Checking.20size.20assertions.20on.20aarch64.3F) Currently the compiler has around 30 sets of `static_assert_size!` for various size-critical data structures (e.g. various IR nodes), guarded by `#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]`. (Presumably this cfg avoids having to maintain separate size values for 32-bit targets and unusual 64-bit targets. Apparently it may have been necessary before the i128/u128 alignment changes, too.) This is slightly incovenient for people on aarch64 workstations (e.g. Macs), because the assertions normally aren't checked until we push to a PR. So this PR adds `aarch64` to the `#[cfg(..)]` guarding all of those assertions in the compiler. --- Implemented with a simple find/replace. Verified by manually inspecting each `static_assert_size!` in `compiler/`, and checking that either the replacement succeeded, or adding aarch64 wouldn't have been appropriate.
2024-04-03Check `x86_64` size assertions on `aarch64`, tooZalathar-3/+3
This makes it easier for contributors on aarch64 workstations (e.g. Macs) to notice when these assertions have been violated.
2024-04-02Don't ICE for postfix match after asMichael Goulet-0/+1
2024-03-29Auto merge of #123080 - Jules-Bertholet:mut-ref-mut, r=Nadrierilbors-35/+32
Match ergonomics 2024: implement mutable by-reference bindings Implements the mutable by-reference bindings portion of match ergonomics 2024 (#123076), with the `mut ref`/`mut ref mut` syntax, under feature gate `mut_ref`. r? `@Nadrieril` `@rustbot` label A-patterns A-edition-2024
2024-03-27Feature gateJules Bertholet-0/+4
2024-03-27chore: fix some commentsxiaoxiangxianzi-1/+1
Signed-off-by: xiaoxiangxianzi <zhaoyizheng@outlook.com>
2024-03-27Implement `mut ref`/`mut ref mut`Jules Bertholet-35/+28
2024-03-26Rollup merge of #122120 - fmease:sugg-assoc-ty-bound-on-eq-bound, ↵Matthias Krüger-10/+31
r=compiler-errors Suggest associated type bounds on problematic associated equality bounds Fixes #105056. TL;DR: Suggest `Trait<Ty: Bound>` on `Trait<Ty = Bound>` in Rust >=2021. ~~Blocked on #122055 (stabilization of `associated_type_bounds`), I'd say.~~ (merged)
2024-03-25Clarify `parse_dot_suffix_expr`.Nicholas Nethercote-16/+19
For the `MiddleDot` case, current behaviour: - For a case like `1.2`, `sym1` is `1` and `sym2` is `2`, and `self.token` holds `1.2`. - It creates a new ident token from `sym1` that it puts into `self.token`. - Then it does `bump_with` with a new dot token, which moves the `sym1` token into `prev_token`. - Then it does `bump_with` with a new ident token from `sym2`, which moves the `dot` token into `prev_token` and discards the `sym1` token. - Then it does `bump`, which puts whatever is next into `self.token`, moves the `sym2` token into `prev_token`, and discards the `dot` token altogether. New behaviour: - Skips creating and inserting the `sym1` and dot tokens, because they are unnecessary. - This also demonstrates that the comment about `Spacing::Alone` is wrong -- that value is never used. That comment was added in #77250, and AFAICT it has always been incorrect. The commit also expands comments. I found this code hard to read previously, the examples in comments make it easier.
2024-03-25Change `parse_expr_tuple_field_access`.Nicholas Nethercote-10/+15
Pass in the span for the field rather than using `prev_token`. Also rename it `mk_expr_tuple_field_access`, because it doesn't do any actual parsing, it just creates an expression with what it's given. Not much of a clarity win by itself, but unlocks additional subsequent simplifications.
2024-03-25Remove `next_token` handling from `parse_expr_tuple_field_access`.Nicholas Nethercote-18/+10
It's clearer at the call site.
2024-03-25Inline and remove `Parser::parse_expr_tuple_field_access_float`.Nicholas Nethercote-36/+38
It has a single call site, and afterwards all the calls to `parse_expr_tuple_field_access` are in a single method, which is nice.
2024-03-24Rollup merge of #122217 - estebank:issue-119685, r=fmeaseMatthias Krüger-11/+88
Handle str literals written with `'` lexed as lifetime Given `'hello world'` and `'1 str', provide a structured suggestion for a valid string literal: ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-3.rs:2:26 | LL | println!('hello world'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("hello world"); | ~ ~ ``` ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-1.rs:2:20 | LL | println!('1 + 1'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("1 + 1"); | ~ ~ ``` Fix #119685.
2024-03-23Suggest assoc ty bound on lifetime in eq constraintLeón Orell Valerian Liehr-10/+31
2024-03-22Rollup merge of #121619 - RossSmyth:pfix_match, r=petrochenkovMatthias Krüger-5/+24
Experimental feature postfix match This has a basic experimental implementation for the RFC postfix match (rust-lang/rfcs#3295, #121618). [Liaison is](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Postfix.20Match.20Liaison/near/423301844) ```@scottmcm``` with the lang team's [experimental feature gate process](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md). This feature has had an RFC for a while, and there has been discussion on it for a while. It would probably be valuable to see it out in the field rather than continue discussing it. This feature also allows to see how popular postfix expressions like this are for the postfix macros RFC, as those will take more time to implement. It is entirely implemented in the parser, so it should be relatively easy to remove if needed. This PR is split in to 5 commits to ease review. 1. The implementation of the feature & gating. 2. Add a MatchKind field, fix uses, fix pretty. 3. Basic rustfmt impl, as rustfmt crashes upon seeing this syntax without a fix. 4. Add new MatchSource to HIR for Clippy & other HIR consumers
2024-03-21Rollup merge of #122793 - compiler-errors:deref-pat-syntax, r=NadrierilMatthias Krüger-1/+19
Implement macro-based deref!() syntax for deref patterns Stop using `box PAT` syntax for deref patterns, and instead use a perma-unstable macro. Blocked on #122222 r? `@Nadrieril`
2024-03-21Rollup merge of #122752 - nnethercote:Interpolated-cleanups, r=petrochenkovMatthias Krüger-90/+63
Interpolated cleanups Various cleanups I made while working on attempts to remove `Interpolated`, that are worth merging now. Best reviewed one commit at a time. r? `@petrochenkov`
2024-03-21Implement macro-based deref!() syntax for deref patternsMichael Goulet-1/+19
Stop using `box PAT` syntax for deref patterns, as it's misleading and also causes their semantics being tangled up.
2024-03-21Auto merge of #122822 - matthiaskrgr:rollup-rjgmnbe, r=matthiaskrgrbors-5/+15
Rollup of 8 pull requests Successful merges: - #122222 (deref patterns: bare-bones feature gate and typechecking) - #122358 (Don't ICE when encountering bound regions in generator interior type) - #122696 (Add bare metal riscv32 target.) - #122773 (make "expected paren or brace" error translatable) - #122795 (Inherit `RUSTC_BOOTSTRAP` when testing wasm) - #122799 (Replace closures with `_` when suggesting fully qualified path for method call) - #122801 (Fix misc printing issues in emit=stable_mir) - #122806 (Make `type_ascribe!` not a built-in) Failed merges: - #122771 (add some comments to hir::ModuleItems) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-21Auto merge of #122718 - workingjubilee:eyeliner-for-contrast, r=lcnrbors-0/+13
Inline a bunch of trivial conditions in parser It is often the case that these small, conditional functions, when inlined, reveal notable optimization opportunities to LLVM. While saethlin has done a lot of good work on making these kinds of small functions not need `#[inline]` tags as much, being clearer about what we want inlined will get both the MIR opts and LLVM to pursue it more aggressively. On local perf runs, this seems fruitful. Let's see what rust-timer says. r? `@ghost`
2024-03-20Make type_ascribe! not a built-inMichael Goulet-5/+15
2024-03-21Streamline `NamedMatch`.Nicholas Nethercote-6/+22
This commit combines `MatchedTokenTree` and `MatchedNonterminal`, which are often considered together, into a single `MatchedSingle`. It shares a representation with the newly-parameterized `ParseNtResult`. This will also make things much simpler if/when variants from `Interpolated` start being moved to `ParseNtResult`.
2024-03-21Remove non-useful code path.Nicholas Nethercote-17/+0
It has no effect on anything in the test suite.
2024-03-21Fix some formatting.Nicholas Nethercote-5/+3
2024-03-21Use better variable names in some `maybe_whole!` calls.Nicholas Nethercote-5/+5
2024-03-21Use `maybe_whole!` to streamline `parse_stmt_without_recovery`.Nicholas Nethercote-11/+5
2024-03-21Use `maybe_whole!` to streamline `parse_item_common`.Nicholas Nethercote-16/+11
This requires changing `maybe_whole!` so it allows the value to be modified.
2024-03-21Rewrite `parse_meta_item`.Nicholas Nethercote-11/+7
It can't use `maybe_whole`, but it can match `maybe_whole` more closely. Also add a test for a case that wasn't previously covered.
2024-03-21Use `maybe_whole!` to streamline `parse_attr_item`.Nicholas Nethercote-19/+10