about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDuddino <rezziandrea106@gmail.com>2020-04-15 10:57:22 +0200
committerDuddino <rezziandrea106@gmail.com>2020-04-15 10:58:12 +0200
commitfbc4168d809dae0408c2520ccfe585f564ad4a0b (patch)
tree15c21f7db77e3031fdf80091fcf48112bdfedfe3 /src
parentce994b633d9143dd00140c64fe53194a2927dff1 (diff)
downloadrust-fbc4168d809dae0408c2520ccfe585f564ad4a0b.tar.gz
rust-fbc4168d809dae0408c2520ccfe585f564ad4a0b.zip
Provide better compiler output when using `?` on `Option` in fn returning `Result` and vice-versa
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trait_selection/traits/error_reporting/mod.rs4
-rw-r--r--src/test/ui/option-to-result.stderr4
-rw-r--r--src/test/ui/try-on-option.stderr4
3 files changed, 6 insertions, 6 deletions
diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs
index a77ea33bcde..904720125d3 100644
--- a/src/librustc_trait_selection/traits/error_reporting/mod.rs
+++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs
@@ -321,7 +321,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                             err.span_suggestion_verbose(
                                 span.shrink_to_lo(),
                                 "consider converting the `Option<T>` into a `Result<T, _>` using `Option::ok_or` or `Option::ok_or_else`",
-                                ".ok_or_else(|_| /* error value */)".to_string(),
+                                ".ok_or_else(|| /* error value */)".to_string(),
                                 Applicability::HasPlaceholders,
                             );
                         } else if is_try && is_from && should_convert_result_to_option {
@@ -329,7 +329,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                                 span.shrink_to_lo(),
                                 "consider converting the `Result<T, _>` into an `Option<T>` using `Result::ok`",
                                 ".ok()".to_string(),
-                                Applicability::HasPlaceholders,
+                                Applicability::MachineApplicable,
                             );
                         }
 
diff --git a/src/test/ui/option-to-result.stderr b/src/test/ui/option-to-result.stderr
index 3c51bcece57..f673ef7fc1e 100644
--- a/src/test/ui/option-to-result.stderr
+++ b/src/test/ui/option-to-result.stderr
@@ -8,8 +8,8 @@ LL |     a?;
    = note: required by `std::convert::From::from`
 help: consider converting the `Option<T>` into a `Result<T, _>` using `Option::ok_or` or `Option::ok_or_else`
    |
-LL |     a.ok_or_else(|_| /* error value */)?;
-   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |     a.ok_or_else(|| /* error value */)?;
+   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0277]: `?` couldn't convert the error to `std::option::NoneError`
   --> $DIR/option-to-result.rs:11:6
diff --git a/src/test/ui/try-on-option.stderr b/src/test/ui/try-on-option.stderr
index d1c0276a67a..7a4bb75967b 100644
--- a/src/test/ui/try-on-option.stderr
+++ b/src/test/ui/try-on-option.stderr
@@ -8,8 +8,8 @@ LL |     x?;
    = note: required by `std::convert::From::from`
 help: consider converting the `Option<T>` into a `Result<T, _>` using `Option::ok_or` or `Option::ok_or_else`
    |
-LL |     x.ok_or_else(|_| /* error value */)?;
-   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |     x.ok_or_else(|| /* error value */)?;
+   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
   --> $DIR/try-on-option.rs:13:5