Make diagnostics clearer for `?` operators by JohnTitor · Pull Request #86382 ·...
source link: https://github.com/rust-lang/rust/pull/86382
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
help: you can convert an `i32` to a `u32` and panic if the converted value doesn't fit
|
LL | let y: u32 = x.try_into().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^
For some reason this suggestion is fine in stable and nightly, but it isn't here.
// #71309: `src` may contain `?` at the end, trim it
// as it makes suggestions incorrect.
let suggestion = format!(
"{}{}.try_into().unwrap()",
prefix,
with_opt_paren(&src).trim_end_matches('?')
);
(expr.span, msg, suggestion)
Ah! I see. That trim_end_matches
is incorrect. The case I mentioned is supposed to suggest x?.try_into().unwrap()
, but this "blind" removal of the trailing ?
is getting rid of it. Do we have a test where the removal of the ?
is correct?
Oh, somehow I misunderstood your previous review comment (#75029 (comment)), fixed.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK