Avoid wrong unwrap suggestions for never option value - #162276
Avoid wrong unwrap suggestions for never option value#162276chenyukang wants to merge 2 commits into
Conversation
|
r? @tiif rustbot has assigned @tiif. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
Mostly LGTM, but I'm not sure it makes sense to target only one of the two possible suggestions that this code can emit.
r? me @rustbot author
| "use the `?` operator to extract the `{found}` value, propagating \ | ||
| {article} `{kind}::{variant}` value to the caller" |
There was a problem hiding this comment.
Does this suggestion make sense when inner_ty is ! or should we suppress the suggestion regardless of sugg_operator? If x: Option<!> then x? must be an unconditional early return, which seems dubious and certainly doesn't contribute to actually getting a value of the expected type.
(If we should suppress this suggestion to, then the control flow could also be a little simpler.)
There was a problem hiding this comment.
Yes, I added a test and updated the code to remove the invalid suggestion.
This makes me thinking it's a more general issue because a lot of suggestion code are using may_coerce here https://github.com/rust-lang/rust/pull/162276/changes#diff-a188fa3dba59dd225d4a65e08961d2937f6418bc6126716e001303bf946d6ee3L2370, and it may not right for never type in suggestion scenario.
cc277a8 to
34a7b47
Compare
Fixes #162241