Rollup merge of #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 #51938 / 6cc78bf8d7
(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 #52537, resolves #54578.
r? @estebank
This commit is contained in:
commit
e5d9da76f2
4 changed files with 3 additions and 44 deletions
|
@ -479,17 +479,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
err.span_label(arm_span, msg);
|
err.span_label(arm_span, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::MatchSource::TryDesugar => {
|
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,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
let msg = "match arm with an incompatible type";
|
let msg = "match arm with an incompatible type";
|
||||||
if self.tcx.sess.source_map().is_multiline(arm_span) {
|
if self.tcx.sess.source_map().is_multiline(arm_span) {
|
||||||
|
|
|
@ -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 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<isize, ()> {
|
|
||||||
Ok(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn forbidden_narratives() -> Result<isize, ()> {
|
|
||||||
Ok(missing_discourses()?)
|
|
||||||
//~^ ERROR try expression alternatives have incompatible types
|
|
||||||
//~| HELP try wrapping with a success variant
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
|
@ -8,8 +8,6 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// run-rustfix
|
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
fn missing_discourses() -> Result<isize, ()> {
|
fn missing_discourses() -> Result<isize, ()> {
|
||||||
|
@ -19,7 +17,6 @@ fn missing_discourses() -> Result<isize, ()> {
|
||||||
fn forbidden_narratives() -> Result<isize, ()> {
|
fn forbidden_narratives() -> Result<isize, ()> {
|
||||||
missing_discourses()?
|
missing_discourses()?
|
||||||
//~^ ERROR try expression alternatives have incompatible types
|
//~^ ERROR try expression alternatives have incompatible types
|
||||||
//~| HELP try wrapping with a success variant
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
error[E0308]: try expression alternatives have incompatible types
|
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()?
|
LL | missing_discourses()?
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found isize
|
||||||
| |
|
|
||||||
| expected enum `std::result::Result`, found isize
|
|
||||||
| help: try wrapping with a success variant: `Ok(missing_discourses()?)`
|
|
||||||
|
|
|
|
||||||
= note: expected type `std::result::Result<isize, ()>`
|
= note: expected type `std::result::Result<isize, ()>`
|
||||||
found type `isize`
|
found type `isize`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue