reference icon indicating copy to clipboard operation
reference copied to clipboard

Confusing unrelated code example in Implementations after items.impl.trait.safety

Open MetaflameDragon opened this issue 9 months ago • 1 comments

Immediately after the section about unsafe trait impls, there's a seemingly unrelated code example showing what appears to be an implementation of standard and custom traits (none of which are unsafe).

https://github.com/rust-lang/reference/blob/62882004d22f64eef6b4c45a4a534eee948cf664/src/items/implementations.md?plain=1#L125-L159

I found it fairly confusing, because I was expecting that a code example immediately after an important remark like that would show an example of it, but it appears to be a simple demonstration of the common syntax.

Every other code block in this file follows my expectations of the code example elaborating on the previous rule, just this one code block appears completely unrelated to the rule before it.

https://github.com/rust-lang/reference/blob/62882004d22f64eef6b4c45a4a534eee948cf664/src/items/implementations.md?plain=1#L63-L99 (The code example here shows multiple impl blocks)

I would have expected the example code (the one with Circle) to be placed after the items.impl.trait.intro paragraph - would that make more sense? Otherwise, I think that the code block should at least be more clearly detached from the unsafe rule, because it's not an example of an unsafe trait impl.

MetaflameDragon avatar Mar 06 '25 15:03 MetaflameDragon

I think both of those examples are associated with their respective sections ("Trait implementations" and "Inherent implementations"), not the rule that immediately precedes that. They kinda show a culmination of multiple rules.

I suppose the question is, if moved to the intro, does it make sense to show an example before the rules that describe it?

I'm thinking of maybe shrinking the examples a little, move them to their respective "intro", and then create new examples for specialized rules like items.impl.inherent.coherence that narrowly illustrate that one rule.

ehuss avatar Mar 20 '25 02:03 ehuss