You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
suggest replacing let else with ? statement where applicable #8755
I guess the question_mark lint could be extended to handle this case? Also, maybe one needs to watch out to not suggest let-else first (#8437) to then suggest ?, but suggest ? right away. IDK how conflicts like this are handled.
Given the two samples that we have, I think that most of the times the lint would fire is for functions that return Option. If we simplify for Option, that means that checking for the pattern should be pretty easy. For Result it doesn't make that much sense, as the else clause can't access the thing inside Err.
Yes, would love to see the question_mark lint extended to let-else, and also the mention by @est31 to not first suggest manual_let_else on a block of code, followed by question_mark on the refactored code.
We currently have two patterns in our codebase with both Option and Result where the question mark operator could/should be suggested:
let x = None::<u32>;// Suggest ? hereletSome(x) = x else{returnNone;};// Suggest .ok()? hereletOk(x) = std::fs::read_to_string("foo")else{returnNone;};
Activity
est31 commentedon Apr 27, 2022
I guess the
question_marklint could be extended to handle this case? Also, maybe one needs to watch out to not suggest let-else first (#8437) to then suggest?, but suggest?right away. IDK how conflicts like this are handled.est31 commentedon Jan 11, 2023
Another example where this lint would have been useful: rust-lang/cargo@cf716fc
est31 commentedon Jan 11, 2023
Given the two samples that we have, I think that most of the times the lint would fire is for functions that return
Option. If we simplify forOption, that means that checking for the pattern should be pretty easy. ForResultit doesn't make that much sense, as theelseclause can't access the thing insideErr.MarijnS95 commentedon Jan 24, 2023
Yes, would love to see the
question_marklint extended tolet-else, and also the mention by @est31 to not first suggestmanual_let_elseon a block of code, followed byquestion_markon the refactored code.We currently have two patterns in our codebase with both
OptionandResultwhere the question mark operator could/should be suggested:Thanks!
Auto merge of #10924 - est31:manual_let_else_question_mark, r=Centri3…