Skip to content

[19_smart_pointers/cow1.rs] Stale comment in owned_mutation test is confusing #2303

@Bombonchik

Description

@Bombonchik

Hi,

I found a confusing comment in the cow1.rs exercise, inside the #[cfg(test)] module.

File: exercises/19_smart_pointers/cow1.rs
Test: owned_mutation

The test contains this comment:

    // Of course this is also the case if a mutation does occur (not all
    // numbers are absolute). In this case, the call to `to_mut()` in the
    // `abs_all` function returns a reference to the same data as before.

The last sentence, "...the abs_all function returns a reference...", is incorrect. The abs_all function provided in the exercise has this signature and returns unit ():

fn abs_all(input: &mut Cow<[i32]>) {
    // ...
}

This comment is very confusing for learners, as it describes behavior that doesn't match the code.

It looks like this comment is a "stale" leftover from a previous version of the exercise where abs_all did return a reference, like in this screenshot:

Image

To avoid confusion, this stale comment should probably be updated to remove the incorrect part about the return value, or be re-written entirely.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions