From b7546150b2f372bc31f908c41c0078936c3d8b66 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sat, 27 Oct 2018 14:55:07 -0700 Subject: [PATCH] back out bogus `Ok`-wrapping suggestion on `?` arm type mismatch This suggestion was introduced in #51938 / 6cc78bf8d7 (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 #52537, #52598, #54578, #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 #52537, resolves #54578. --- src/librustc/infer/error_reporting/mod.rs | 12 +-------- ...51632-try-desugar-incompatible-types.fixed | 25 ------------------- ...ue-51632-try-desugar-incompatible-types.rs | 3 --- ...1632-try-desugar-incompatible-types.stderr | 7 ++---- 4 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 src/test/ui/issues/issue-51632-try-desugar-incompatible-types.fixed diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 8b4669c89fe..d19c495af3b 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -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) { diff --git a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.fixed b/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.fixed deleted file mode 100644 index 016cff914bd..00000000000 --- a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.fixed +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// run-rustfix - -#![allow(dead_code)] - -fn missing_discourses() -> Result { - Ok(1) -} - -fn forbidden_narratives() -> Result { - Ok(missing_discourses()?) - //~^ ERROR try expression alternatives have incompatible types - //~| HELP try wrapping with a success variant -} - -fn main() {} diff --git a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.rs b/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.rs index 315773a85f0..32ea715b64f 100644 --- a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.rs +++ b/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.rs @@ -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 { @@ -19,7 +17,6 @@ fn missing_discourses() -> Result { fn forbidden_narratives() -> Result { missing_discourses()? //~^ ERROR try expression alternatives have incompatible types - //~| HELP try wrapping with a success variant } fn main() {} diff --git a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.stderr b/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.stderr index a50af5624c0..590cbff67a4 100644 --- a/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.stderr +++ b/src/test/ui/issues/issue-51632-try-desugar-incompatible-types.stderr @@ -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` found type `isize`