Skip to content

Suggest potentially missing value in empty conditional expression arms with inferred type #99525

Description

@estebank

When given

fn d(opt_str: Option<String>) {
    let s = if let Some(s) = opt_str {
        //~^ ERROR mismatched types
    } else {
        String::new()
    };
}

we should mention that s might be missing in the if branch of the expression, like we do for

fn d(opt_str: Option<String>) {
    let s: String = if let Some(s) = opt_str {
        //~^ ERROR mismatched types
    } else {
        String::new()
    };
}

#98784 (comment)

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    P-lowLow priority
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    D-papercutDiagnostics: An error or lint that needs small tweaks.
    on Jul 20, 2022
  2. compiler-errors commented on Jul 20, 2022

    @compiler-errors
    Contributor

    Actually this aligns perfectly with a refactoring of IfExpressionCause I was looking at last night...

  3. compiler-errors commented on Jul 20, 2022

    @compiler-errors
    Contributor

    Since we already suggest removing semicolon bidirectionally i.e. if a { b; } else { c } and if a { b } else { c; }, we should be able to do the same with the return binding suggestion too.

    @rustbot claim

  4. added 2 commits that reference this issue on Jul 22, 2022
    36478ef
    92bebac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.P-lowLow priorityT-compilerRelevant to the compiler 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