rust/src/doc
Jubilee f542909d1c
Rollup merge of #138780 - trifectatechfoundation:loop_match_attr, r=oli-obk,traviscross
Add `#[loop_match]` for improved DFA codegen

tracking issue: https://github.com/rust-lang/rust/issues/132306
project goal: https://github.com/rust-lang/rust-project-goals/issues/258

This PR adds the `#[loop_match]` attribute, which aims to improve code generation for state machines. For some (very exciting) benchmarks, see https://github.com/rust-lang/rust-project-goals/issues/258#issuecomment-2732965199

Currently, a very restricted syntax pattern is accepted. We'd like to get feedback and merge this now before we go too far in a direction that others have concerns with.

## current state

We accept code that looks like this

```rust
#[loop_match]
loop {
    state = 'blk: {
        match state {
            State::A => {
                #[const_continue]
                break 'blk State::B
            }
            State::B => { /* ... */ }
            /* ... */
        }
    }
}
```

- a loop should have the same semantics with and without `#[loop_match]`: normal `continue` and `break` continue to work
- `#[const_continue]` is only allowed in loops annotated with `#[loop_match]`
- the loop body needs to have this particular shape (a single assignment to the match scrutinee, with the body a labelled block containing just a match)

## future work

- perform const evaluation on the `break` value
- support more state/scrutinee types

## maybe future work

- allow `continue 'label value` syntax, which `#[const_continue]` could then use.
- allow the match to be on an arbitrary expression (e.g. `State::Initial`)
- attempt to also optimize `break`/`continue` expressions that are not marked with `#[const_continue]`

r? ``@traviscross``
2025-06-24 19:45:30 -07:00
..
book@8a6d44e45b Update books 2025-06-19 04:45:42 +02:00
edition-guide@aa6ce337c0 Update books 2025-05-21 01:50:12 +02:00
embedded-book@10fa1e0843 Update books 2025-06-02 19:01:18 +02:00
man Update rustc man page to match rustc --help 2022-08-01 22:03:18 +00:00
nomicon@8b61acfaea Update books 2025-06-02 19:01:18 +02:00
reference@50fc1628f3 Update books 2025-06-19 04:45:42 +02:00
rust-by-example@05c7d8bae6 Update books 2025-06-19 04:45:42 +02:00
rustc Auto merge of #140772 - mati865:gnullvm-host, r=Kobzol 2025-06-19 00:21:07 +00:00
rustc-dev-guide Rollup merge of #141597 - Oneirical:unquestionable-instruction, r=jieyouxu 2025-06-23 06:07:19 +02:00
rustdoc Update extracted-doctest feature documentation 2025-06-11 13:44:22 +02:00
style-guide style: Never break within a nullary function call func() or a unit literal () 2025-05-07 20:36:06 +01:00
unstable-book Rollup merge of #138780 - trifectatechfoundation:loop_match_attr, r=oli-obk,traviscross 2025-06-24 19:45:30 -07:00
complement-design-faq.md
complement-lang-faq.md
complement-project-faq.md
favicon.inc doc: no shortcut in rel="icon" 2022-01-28 13:42:48 +01:00
footer.inc avoid reuse tripping over copyright notices 2023-03-09 12:24:43 +01:00
full-toc.inc
grammar.md
guide-crates.md
guide-error-handling.md
guide-ffi.md
guide-macros.md
guide-ownership.md
guide-plugins.md Remove support for compiler plugins. 2023-11-04 08:50:46 +11:00
guide-pointers.md
guide-strings.md
guide-tasks.md
guide-testing.md
guide-unsafe.md
guide.md
index.md doc: add release notes to standalone doc bundle 2023-11-13 16:00:31 -07:00
intro.md
not_found.md rustdoc: consistentify #TOC and #ModNav to lowercase 2024-08-20 16:51:40 -07:00
redirect.inc doc: no shortcut in rel="icon" 2022-01-28 13:42:48 +01:00
reference.md Update reference.md 2021-07-10 19:51:36 +02:00
robots.txt Block version-specific docs from search engines 2020-03-14 02:29:35 +00:00
rust.css Fix heading anchors in doc pages. 2024-03-18 09:13:18 -07:00
rust.md
rustdoc.md
tutorial.md
version_info.html.template