Skip to content

Rework trait parameter patterns #1771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Mar 27, 2025

This updates the description of trait parameter patterns, primarily to shift it to the style where the main text describes the behavior in the current edition, and changes in the edition are moved to separate edition blocks.

The specific changes:

  • Rework the edition presentation (as per our style guide).
  • Try to use more consistent wording.
  • Add examples.
  • Rename some of the rules to switch to the updated edition style, and try to be a little clearer about their intent.
  • Change the way it refers to "methods". The reference used to define methods as a separate kind of associated item, but we changed it so that functions allow an optional SelfParam, and methods aren't as special as they used to be. This text was still written assuming the previous presentation.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Mar 27, 2025
Comment on lines +336 to +353
r[items.traits.params.restriction-patterns.edition2018]
> [!EDITION-2018]
> Prior to the 2018 edition, parameters in associated functions with a body are limited to the following kinds of patterns:
>
> * [IDENTIFIER]
> * `mut` [IDENTIFIER]
> * [`_`][WildcardPattern]
> * `&` [IDENTIFIER]
> * `&&` [IDENTIFIER]
>
> ```rust,edition2015,compile_fail,E0642
> // 2015 Edition
> trait T {
> fn f1((a, b): (i32, i32)) {} // ERROR: pattern not allowed
> }
> ```
>
> Beginning in 2018, all irrefutable patterns are allowed as described in [items.traits.params.patterns-with-body].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a thought for another PR, but I wonder whether it'd be useful for us to link from these edition differences blocks to the relevant chapter of the edition guide.

* `&&` [IDENTIFIER]
```rust,compile_fail,E0642
trait T {
fn f2(&x: &i32); // ERROR: Patterns aren't allowed in functions without bodies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be lowercased to match the others. I'll fix.

@traviscross traviscross force-pushed the trait-pattern-edition-rework branch from e9890c7 to a319552 Compare April 1, 2025 21:35
> ```rust,edition2015
> // 2015 Edition
> trait T {
> fn f(i32); // Parameter identifiers are not required.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other things here are going with the // OK: .. pattern, so I'll edit to match that.

This updates the description of trait parameter patterns, primarily to
shift it to the style where the main text describes the behavior in the
current edition, and changes in the edition are moved to separate
edition blocks.

The specific changes:

- Rework the edition presentation (as per our style guide).
- Try to use more consistent wording.
- Add examples.
- Rename some of the rules to switch to the updated edition style, and
  try to be a little clearer about their intent.
- Change the way it refers to "methods". The reference used to define
  methods as a separate kind of associated item, but we changed it so
  that functions allow an optional _SelfParam_, and methods aren't as
  special as they used to be. This text was still written assuming the
  previous presentation.
@traviscross traviscross force-pushed the trait-pattern-edition-rework branch from a319552 to 7cdad30 Compare April 1, 2025 21:37
@traviscross traviscross added this pull request to the merge queue Apr 1, 2025
Merged via the queue into rust-lang:master with commit d1e0e0a Apr 1, 2025
5 checks passed
Zalathar added a commit to Zalathar/rust that referenced this pull request Apr 8, 2025
Update books

## rust-lang/reference

12 commits in e95ebdfee02514d93f79ec92ae310a804e87f01f..46435cd4eba11b66acaa42c01da5c80ad88aee4b
2025-04-07 14:21:21 UTC to 2025-03-25 20:13:17 UTC

- Update book.toml fix the authors field (rust-lang/reference#1780)
- Update precedence table for borrow operators (rust-lang/reference#1776)
- Add the ability for rules to be specified in link definitions (rust-lang/reference#1775)
- Rework trait parameter patterns (rust-lang/reference#1771)
- Fix header rules (rust-lang/reference#1770)
- Add test wrappers (rust-lang/reference#1774)
- Update tools to Rust 2024 (rust-lang/reference#1773)
- Define byte (rust-lang/reference#1772)
- Fix CSS for new footnote style (rust-lang/reference#1777)
- do not reference LLVM in our definition of UB (rust-lang/reference#1750)
- Tweak reference for precise capturing in traits (rust-lang/reference#1769)
- Add edition admonitions (rust-lang/reference#1764)

## rust-lang/rust-by-example

2 commits in 6f69823c28ae8d929d6c815181c73d3e99ef16d3..0d7964d5b22cf920237ef1282d869564b4883b88
2025-04-07 11:19:31 UTC to 2025-03-29 02:25:52 UTC

- Rename count to index for clarity (rust-lang/rust-by-example#1920)
- Fixing grammar in panic section (rust-lang/rust-by-example#1916)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 8, 2025
Update books

## rust-lang/reference

12 commits in e95ebdfee02514d93f79ec92ae310a804e87f01f..46435cd4eba11b66acaa42c01da5c80ad88aee4b
2025-04-07 14:21:21 UTC to 2025-03-25 20:13:17 UTC

- Update book.toml fix the authors field (rust-lang/reference#1780)
- Update precedence table for borrow operators (rust-lang/reference#1776)
- Add the ability for rules to be specified in link definitions (rust-lang/reference#1775)
- Rework trait parameter patterns (rust-lang/reference#1771)
- Fix header rules (rust-lang/reference#1770)
- Add test wrappers (rust-lang/reference#1774)
- Update tools to Rust 2024 (rust-lang/reference#1773)
- Define byte (rust-lang/reference#1772)
- Fix CSS for new footnote style (rust-lang/reference#1777)
- do not reference LLVM in our definition of UB (rust-lang/reference#1750)
- Tweak reference for precise capturing in traits (rust-lang/reference#1769)
- Add edition admonitions (rust-lang/reference#1764)

## rust-lang/rust-by-example

2 commits in 6f69823c28ae8d929d6c815181c73d3e99ef16d3..0d7964d5b22cf920237ef1282d869564b4883b88
2025-04-07 11:19:31 UTC to 2025-03-29 02:25:52 UTC

- Rename count to index for clarity (rust-lang/rust-by-example#1920)
- Fixing grammar in panic section (rust-lang/rust-by-example#1916)
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 9, 2025
Rollup merge of rust-lang#139491 - rustbot:docs-update, r=ehuss

Update books

## rust-lang/reference

12 commits in e95ebdfee02514d93f79ec92ae310a804e87f01f..46435cd4eba11b66acaa42c01da5c80ad88aee4b
2025-04-07 14:21:21 UTC to 2025-03-25 20:13:17 UTC

- Update book.toml fix the authors field (rust-lang/reference#1780)
- Update precedence table for borrow operators (rust-lang/reference#1776)
- Add the ability for rules to be specified in link definitions (rust-lang/reference#1775)
- Rework trait parameter patterns (rust-lang/reference#1771)
- Fix header rules (rust-lang/reference#1770)
- Add test wrappers (rust-lang/reference#1774)
- Update tools to Rust 2024 (rust-lang/reference#1773)
- Define byte (rust-lang/reference#1772)
- Fix CSS for new footnote style (rust-lang/reference#1777)
- do not reference LLVM in our definition of UB (rust-lang/reference#1750)
- Tweak reference for precise capturing in traits (rust-lang/reference#1769)
- Add edition admonitions (rust-lang/reference#1764)

## rust-lang/rust-by-example

2 commits in 6f69823c28ae8d929d6c815181c73d3e99ef16d3..0d7964d5b22cf920237ef1282d869564b4883b88
2025-04-07 11:19:31 UTC to 2025-03-29 02:25:52 UTC

- Rename count to index for clarity (rust-lang/rust-by-example#1920)
- Fixing grammar in panic section (rust-lang/rust-by-example#1916)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: The marked PR is awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants