Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
estebank opened this issue Jul 20, 2022 · 2 comments · Fixed by #99539
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Jul 20, 2022

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)

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Jul 20, 2022
@compiler-errors
Copy link
Member

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

@compiler-errors
Copy link
Member

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

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 22, 2022
…-suggestions, r=fee1-dead

Improve suggestions for returning binding

Fixes rust-lang#99525

Also reworks the cause codes for match and if a bit, I think cleaning them up in a positive way.
We no longer need to call `could_remove_semicolon` in successful code, which might save a few cycles?
@bors bors closed this as completed in 92bebac Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants