]> git.lizzy.rs Git - rust.git/commitdiff
Provide better compiler output when using `?` on `Option` in fn returning `Result...
authorDuddino <rezziandrea106@gmail.com>
Wed, 15 Apr 2020 08:57:22 +0000 (10:57 +0200)
committerDuddino <rezziandrea106@gmail.com>
Wed, 15 Apr 2020 08:58:12 +0000 (10:58 +0200)
src/librustc_trait_selection/traits/error_reporting/mod.rs
src/test/ui/option-to-result.stderr
src/test/ui/try-on-option.stderr

index a77ea33bcde091a5c326fc359988dd37ce42d1b1..904720125d3d74b2ab4e934c24093ae4972cf4b1 100644 (file)
@@ -321,7 +321,7 @@ fn report_selection_error(
                             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 @@ fn report_selection_error(
                                 span.shrink_to_lo(),
                                 "consider converting the `Result<T, _>` into an `Option<T>` using `Result::ok`",
                                 ".ok()".to_string(),
-                                Applicability::HasPlaceholders,
+                                Applicability::MachineApplicable,
                             );
                         }
 
index 3c51bcece570b4eb51fdd779ee03b913be804ced..f673ef7fc1e690af24e09538f339193e5101eeeb 100644 (file)
@@ -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
index d1c0276a67ad2a69c54eb849fb3305a5b5133dab..7a4bb75967b1f8764e08b978f2904506293774fa 100644 (file)
@@ -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