Skip to content

Commit

Permalink
back out bogus Ok-wrapping suggestion on ? arm type mismatch
Browse files Browse the repository at this point in the history
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 (as repeatedly
reported in Issues rust-lang#52537, rust-lang#52598, rust-lang#54578, rust-lang#55336), and incorrect
suggestions carry more badness than marginal good suggestions do
goodness. Just get rid of it (unless and until someone figures out how
to do it correctly).

Resolves rust-lang#52537, resolves rust-lang#54578.
  • Loading branch information
zackmdavis committed Oct 27, 2018
1 parent f32f111 commit b754615
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 44 deletions.
12 changes: 1 addition & 11 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,17 +479,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err.span_label(arm_span, msg);
}
}
hir::MatchSource::TryDesugar => {
// Issue #51632
if let Ok(try_snippet) = self.tcx.sess.source_map().span_to_snippet(arm_span) {
err.span_suggestion_with_applicability(
arm_span,
"try wrapping with a success variant",
format!("Ok({})", try_snippet),
Applicability::MachineApplicable,
);
}
}
hir::MatchSource::TryDesugar => {}
_ => {
let msg = "match arm with an incompatible type";
if self.tcx.sess.source_map().is_multiline(arm_span) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-rustfix

#![allow(dead_code)]

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

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
error[E0308]: try expression alternatives have incompatible types
--> $DIR/issue-51632-try-desugar-incompatible-types.rs:20:5
--> $DIR/issue-51632-try-desugar-incompatible-types.rs:18:5
|
LL | missing_discourses()?
| ^^^^^^^^^^^^^^^^^^^^^
| |
| expected enum `std::result::Result`, found isize
| help: try wrapping with a success variant: `Ok(missing_discourses()?)`
| ^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found isize
|
= note: expected type `std::result::Result<isize, ()>`
found type `isize`
Expand Down

0 comments on commit b754615

Please sign in to comment.