Skip to content

needless_return_with_question_mark lints when never type is used for coercion #11616

Closed
@y21

Description

@y21

Summary

Inspired by #11613. It's similar but imo not quite the same issue. This one is more about coercions:

fn foo() -> Result<(), ()> {
    let _x: String = {
        return Err(())?; // <--- should not lint here
    };
    Ok(())
}

return's never type is used to get typeck to coerce the type of the block to something else, but that won't happen with its suggestion (just Err(...)?).

It might be that the block here has the NeverToAny adjust that we can use to suppress the lint in these cases.

Lint Name

needless_return_with_question_mark

Reproducer

🆙

Version

rustc 1.74.0-nightly (37390d656 2023-09-24)
binary: rustc
commit-hash: 37390d65636dd67e263753a3c04fbc60dcc4348e
commit-date: 2023-09-24
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0

Additional Labels

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions