Skip to content

Commit e5d9da7

Browse files
authored
Rollup merge of rust-lang#55423 - zackmdavis:back_out_bogus_ok_wrapping_suggestion, r=estebank
back out bogus `Ok`-wrapping suggestion on `?` arm type mismatch This suggestion was introduced in rust-lang#51938 / 6cc78bf (while introducing different language for type errors coming from `?` rather than a `match`), but it has a lot of false-positives, and incorrect suggestions carry more badness than marginal good suggestions do goodness. I regret not doing this earlier. 😞 Resolves rust-lang#52537, resolves rust-lang#54578. r? @estebank
2 parents 97ff2d6 + b754615 commit e5d9da7

File tree

4 files changed

+3
-44
lines changed

4 files changed

+3
-44
lines changed

src/librustc/infer/error_reporting/mod.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
479479
err.span_label(arm_span, msg);
480480
}
481481
}
482-
hir::MatchSource::TryDesugar => {
483-
// Issue #51632
484-
if let Ok(try_snippet) = self.tcx.sess.source_map().span_to_snippet(arm_span) {
485-
err.span_suggestion_with_applicability(
486-
arm_span,
487-
"try wrapping with a success variant",
488-
format!("Ok({})", try_snippet),
489-
Applicability::MachineApplicable,
490-
);
491-
}
492-
}
482+
hir::MatchSource::TryDesugar => {}
493483
_ => {
494484
let msg = "match arm with an incompatible type";
495485
if self.tcx.sess.source_map().is_multiline(arm_span) {

src/test/ui/issues/issue-51632-try-desugar-incompatible-types.fixed

-25
This file was deleted.

src/test/ui/issues/issue-51632-try-desugar-incompatible-types.rs

-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// run-rustfix
12-
1311
#![allow(dead_code)]
1412

1513
fn missing_discourses() -> Result<isize, ()> {
@@ -19,7 +17,6 @@ fn missing_discourses() -> Result<isize, ()> {
1917
fn forbidden_narratives() -> Result<isize, ()> {
2018
missing_discourses()?
2119
//~^ ERROR try expression alternatives have incompatible types
22-
//~| HELP try wrapping with a success variant
2320
}
2421

2522
fn main() {}

src/test/ui/issues/issue-51632-try-desugar-incompatible-types.stderr

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
error[E0308]: try expression alternatives have incompatible types
2-
--> $DIR/issue-51632-try-desugar-incompatible-types.rs:20:5
2+
--> $DIR/issue-51632-try-desugar-incompatible-types.rs:18:5
33
|
44
LL | missing_discourses()?
5-
| ^^^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| expected enum `std::result::Result`, found isize
8-
| help: try wrapping with a success variant: `Ok(missing_discourses()?)`
5+
| ^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found isize
96
|
107
= note: expected type `std::result::Result<isize, ()>`
118
found type `isize`

0 commit comments

Comments
 (0)