Skip to content

[cargo fix] unit_arg removes calls to functions with side-effects #4741

Closed
@soruh

Description

@soruh

When running cargo fix --clippy -Z unstable-options the following happens:

fn function_with_side_effects_but_unit_return() {
    print("This is a side-effect!");
}

This

fn some_function() -> Result<()> {
    // ...
    Ok(function_with_side_effects_but_unit_return())
}

will be turned into this

fn some_function() -> Result<()> {
    // ...
    Ok(())
}

but it should either be turned into this

fn some_function() -> Result<()> {
    // ...
    function_with_side_effects_but_unit_return();
    Ok(())
}

or not be changed at all.

This behavior results from the unit_arg Lint, so that probably should be changed to no longer being MachineApplicable or it's "fixing" logic should be adjusted to produce the above result.

I don't know if the "Known problems" section is used for problems when using cargo fix, but I think while this is being looked into it might make sense to add this there.

Only tested on this version:

$ cargo clippy -V
clippy 0.0.212 (e8d5a9e 2019-10-22)
$ cargo -V
cargo 1.40.0-nightly (3a9abe3f0 2019-10-15)
$ rustc -V
rustc 1.40.0-nightly (4a8c5b20c 2019-10-23)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-documentationArea: Adding or improving documentationI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions