about summary refs log tree commit diff
path: root/compiler/rustc_parse
AgeCommit message (Collapse)AuthorLines
2024-03-26Rollup merge of #122120 - fmease:sugg-assoc-ty-bound-on-eq-bound, ↵Matthias Krüger-14/+37
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-12/+90
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-14/+37
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-92/+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-19/+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
2024-03-20Rollup merge of #122540 - WaffleLapkin:ununexpected, r=estebankMatthias Krüger-13/+23
Do not use `?`-induced skewing of type inference in the compiler This prevents breakage from #122412 and is generally a good idea. r? `@estebank`
2024-03-19Inline conditionals in the parserJubilee Young-0/+13
There are a bunch of small helper conditionals we use. Inline them to get slightly better perf in a few cases, especially when rustc is compiled without PGO.
2024-03-19Rollup merge of #122717 - ↵Matthias Krüger-1/+4
workingjubilee:handle-call-call-call-call-calling-me-maybe, r=compiler-errors Ensure stack before parsing dot-or-call There are many cases where, due to codegen or a massively unruly codebase, a deeply nested `call(call(call(call(call(call(call(call(call(f())))))))))` can happen. This is a spot where it would be good to grow our stack, so that we can survive to tell the programmer their code is dubiously written. Closes https://github.com/rust-lang/rust/issues/122715
2024-03-18Ensure stack before parsing dot-or-callJubilee Young-1/+4
There are many cases where, due to codegen or a massively unruly codebase, a deeply nested call(call(call(call(call(call(call(call(call(f()))))))))) can happen. This is a spot where it would be good to grow our stack, so that we can survive to tell the programmer their code is dubiously written.
2024-03-19Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obkbors-2/+0
Stabilize associated type bounds (RFC 2289) This PR stabilizes associated type bounds, which were laid out in [RFC 2289]. This gives us a shorthand to express nested type bounds that would otherwise need to be expressed with nested `impl Trait` or broken into several `where` clauses. ### What are we stabilizing? We're stabilizing the associated item bounds syntax, which allows us to put bounds in associated type position within other bounds, i.e. `T: Trait<Assoc: Bounds...>`. See [RFC 2289] for motivation. In all position, the associated type bound syntax expands into a set of two (or more) bounds, and never anything else (see "How does this differ[...]" section for more info). Associated type bounds are stabilized in four positions: * **`where` clauses (and APIT)** - This is equivalent to breaking up the bound into two (or more) `where` clauses. For example, `where T: Trait<Assoc: Bound>` is equivalent to `where T: Trait, <T as Trait>::Assoc: Bound`. * **Supertraits** - Similar to above, `trait CopyIterator: Iterator<Item: Copy> {}`. This is almost equivalent to breaking up the bound into two (or more) `where` clauses; however, the bound on the associated item is implied whenever the trait is used. See #112573/#112629. * **Associated type item bounds** - This allows constraining the *nested* rigid projections that are associated with a trait's associated types. e.g. `trait Trait { type Assoc: Trait2<Assoc2: Copy>; }`. * **opaque item bounds (RPIT, TAIT)** - This allows constraining associated types that are associated with the opaque without having to *name* the opaque. For example, `impl Iterator<Item: Copy>` defines an iterator whose item is `Copy` without having to actually name that item bound. The latter three are not expressible in surface Rust (though for associated type item bounds, this will change in #120752, which I don't believe should block this PR), so this does represent a slight expansion of what can be expressed in trait bounds. ### How does this differ from the RFC? Compared to the RFC, the current implementation *always* desugars associated type bounds to sets of `ty::Clause`s internally. Specifically, it does *not* introduce a position-dependent desugaring as laid out in [RFC 2289], and in particular: * It does *not* desugar to anonymous associated items in associated type item bounds. * It does *not* desugar to nested RPITs in RPIT bounds, nor nested TAITs in TAIT bounds. This position-dependent desugaring laid out in the RFC existed simply to side-step limitations of the trait solver, which have mostly been fixed in #120584. The desugaring laid out in the RFC also added unnecessary complication to the design of the feature, and introduces its own limitations to, for example: * Conditionally lowering to nested `impl Trait` in certain positions such as RPIT and TAIT means that we inherit the limitations of RPIT/TAIT, namely lack of support for higher-ranked opaque inference. See this code example: https://github.com/rust-lang/rust/pull/120752#issuecomment-1979412531. * Introducing anonymous associated types makes traits no longer object safe, since anonymous associated types are not nameable, and all associated types must be named in `dyn` types. This last point motivates why this PR is *not* stabilizing support for associated type bounds in `dyn` types, e.g, `dyn Assoc<Item: Bound>`. Why? Because `dyn` types need to have *concrete* types for all associated items, this would necessitate a distinct lowering for associated type bounds, which seems both complicated and unnecessary compared to just requiring the user to write `impl Trait` themselves. See #120719. ### Implementation history: Limited to the significant behavioral changes and fixes and relevant PRs, ping me if I left something out-- * #57428 * #108063 * #110512 * #112629 * #120719 * #120584 Closes #52662 [RFC 2289]: https://rust-lang.github.io/rfcs/2289-associated-type-bounds.html
2024-03-17fix rustdoc testEsteban Küber-1/+1
2024-03-17Silence redundant error on char literal that was meant to be a string in ↵Esteban Küber-1/+10
2021 edition
2024-03-17review comment: `str` -> string in messagesEsteban Küber-3/+3
2024-03-17Use shorter span for existing `'` -> `"` structured suggestionEsteban Küber-6/+25
2024-03-17Handle str literals written with `'` lexed as lifetimeEsteban Küber-4/+54
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-15Make `unexpected` always "return" `PResult<()>` & add `unexpected_any`Maybe Waffle-13/+23
This prevents breakage when `?` no longer skews inference.
2024-03-14Rename `ast::StmtKind::Local` into `ast::StmtKind::Let`Guillaume Gomez-4/+4
2024-03-12Fix ICE in diagnostics for parenthesized type argumentsDaniel Sedlak-21/+31
2024-03-11Rollup merge of #122152 - wutchzone:120892, r=fmeaseJubilee-2/+84
Improve diagnostics for parenthesized type arguments Fixes #120892 r? fmease
2024-03-11Rename `AddToDiagnostic` as `Subdiagnostic`.Nicholas Nethercote-15/+15
To match `derive(Subdiagnostic)`. Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
2024-03-11Rename `IntoDiagnostic` as `Diagnostic`.Nicholas Nethercote-6/+6
To match `derive(Diagnostic)`. Also rename `into_diagnostic` as `into_diag`.
2024-03-11Rename `IntoDiagnosticArg` as `IntoDiagArg`.Nicholas Nethercote-1/+1
Also rename `into_diagnostic_arg` as `into_diag_arg`, and `NotIntoDiagnosticArg` as `NotInotDiagArg`.
2024-03-10Rollup merge of #121860 - mu001999:master, r=NilstriebMatthias Krüger-4/+0
Add a tidy check that checks whether the fluent slugs only appear once As ``````@Nilstrieb`````` said in https://github.com/rust-lang/rust/pull/121828#issuecomment-1972622855: > Might make sense to have a tidy check that checks whether the fluent slugs only appear once in the source code and lint for that there's a tidy check already for sorting We can get the tidy check error: ``` tidy check tidy error: /path/to/rust/compiler/rustc_const_eval/messages.ftl: message `const_eval_invalid_align` is not used tidy error: /path/to/rust/compiler/rustc_lint/messages.ftl: message `lint_trivial_untranslatable_diag` is not used tidy error: /path/to/rust/compiler/rustc_parse/messages.ftl: message `parse_invalid_literal_suffix` is not used tidy error: /path/to/rust/compiler/rustc_infer/messages.ftl: message `infer_need_type_info_in_coroutine` is not used tidy error: /path/to/rust/compiler/rustc_passes/messages.ftl: message `passes_expr_not_allowed_in_context` is not used tidy error: /path/to/rust/compiler/rustc_passes/messages.ftl: message `passes_layout` is not used tidy error: /path/to/rust/compiler/rustc_parse/messages.ftl: message `parse_not_supported` is not used ``` r? ``````@Nilstrieb``````
2024-03-09Improve diagnostics for parenthesized type argumentsDaniel Sedlak-2/+84
2024-03-09Rollup merge of #122160 - jieyouxu:eager-translate-help-use-latest-edition, ↵Matthias Krüger-1/+1
r=cjgillot Eagerly translate `HelpUseLatestEdition` in parser diagnostics Fixes #122130. This makes me suspicious of these other two usage of `add_to_diagnostic()`. Would they *also* crash? I haven't attempted to construct test cases for them. ``` compiler/rustc_parse/src/parser/expr.rs 3453: errors::HelpUseLatestEdition::new().add_to_diagnostic(e); compiler/rustc_hir_typeck/src/expr.rs 2603: HelpUseLatestEdition::new().add_to_diagnostic(&mut err); ``` This also seems like a footgun?
2024-03-08Stabilize associated type boundsMichael Goulet-2/+0
2024-03-08Rollup merge of #121563 - Jarcho:use_cf, r=petrochenkovMatthias Krüger-7/+9
Use `ControlFlow` in visitors. Follow up to #121256 This does have a few small behaviour changes in some diagnostic output where the visitor will now find the first match rather than the last match. The change in `find_anon_types.rs` has the only affected test. I don't see this being an issue as the last occurrence isn't any better of a choice than the first.
2024-03-08Rollup merge of #119365 - nbdd0121:asm-goto, r=AmanieuMatthias Krüger-1/+1
Add asm goto support to `asm!` Tracking issue: #119364 This PR implements asm-goto support, using the syntax described in "future possibilities" section of [RFC2873](https://rust-lang.github.io/rfcs/2873-inline-asm.html#asm-goto). Currently I have only implemented the `label` part, not the `fallthrough` part (i.e. fallthrough is implicit). This doesn't reduce the expressive though, since you can use label-break to get arbitrary control flow or simply set a value and rely on jump threading optimisation to get the desired control flow. I can add that later if deemed necessary. r? ``@Amanieu`` cc ``@ojeda``
2024-03-07Eagerly translate HelpUseLatestEdition in parser diagnostics许杰友 Jieyou Xu (Joe)-1/+1
2024-03-06Cancel parsing ever made during recoveryclubby789-6/+10
2024-03-06Add MatchKind member to the Match expr for pretty printing & fmtRoss Smyth-8/+10
2024-03-05Add postfix-match experimental featureRoss Smyth-1/+18
Co-authored-by: Josh Stone <jistone@redhat.com>
2024-03-05Use `ControlFlow` in AST visitors.Jason Newcomb-7/+9