Skip to content

Confusing docs for core::ops::ControlFlow #133963

Closed
@snprajwal

Description

Location

core::ops::ControlFlow and all its methods. Rust docs link

Summary

The docs for core::ops::ControlFlow::is_break() look like:

assert!(ControlFlow::<i32, String>::Break(3).is_break());
assert!(!ControlFlow::<String, i32>::Continue(3).is_break());

Firstly, the types switch across the two examples, which is unintuitive. The reader needs to spare the brain cells to identify which type represents Continue and Break in each case (even though the variant being used is different), which could also distract them from noticing the ! in the second statement. This would be much clearer if it looks like:

assert!(ControlFlow::<String, i32>::Break("stop right there!").is_break());
assert!(!ControlFlow::<String, i32>::Continue(42).is_break());

The main change being that the types are consistent across the examples.

The same change would look good for the other methods on this enum.

I'm happy to submit a PR if someone greenlights this :)

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions