Skip to content

Commit 918c17a

Browse files
authored
Rollup merge of #117695 - 3tilley:prioritise-unwrap-expect-over-last-method-call, r=compiler-errors
Reorder checks to make sure potential missing expect on Option/Result… … runs before removing last method call Fixes #117669
2 parents 03d6e7a + 1854776 commit 918c17a

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

compiler/rustc_hir_typeck/src/demand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3434

3535
// Use `||` to give these suggestions a precedence
3636
let suggested = self.suggest_missing_parentheses(err, expr)
37+
|| self.suggest_missing_unwrap_expect(err, expr, expected, expr_ty)
3738
|| self.suggest_remove_last_method_call(err, expr, expected)
3839
|| self.suggest_associated_const(err, expr, expected)
3940
|| self.suggest_deref_ref_or_into(err, expr, expected, expr_ty, expected_ty_expr)
@@ -49,8 +50,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4950
|| self.suggest_into(err, expr, expr_ty, expected)
5051
|| self.suggest_floating_point_literal(err, expr, expected)
5152
|| self.suggest_null_ptr_for_literal_zero_given_to_ptr_arg(err, expr, expected)
52-
|| self.suggest_coercing_result_via_try_operator(err, expr, expected, expr_ty)
53-
|| self.suggest_missing_unwrap_expect(err, expr, expected, expr_ty);
53+
|| self.suggest_coercing_result_via_try_operator(err, expr, expected, expr_ty);
5454

5555
if !suggested {
5656
self.note_source_of_type_mismatch_constraint(

tests/ui/suggestions/issue-117669.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let abs: i32 = 3i32.checked_abs();
3+
//~^ ERROR mismatched types
4+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-117669.rs:2:20
3+
|
4+
LL | let abs: i32 = 3i32.checked_abs();
5+
| --- ^^^^^^^^^^^^^^^^^^ expected `i32`, found `Option<i32>`
6+
| |
7+
| expected due to this
8+
|
9+
= note: expected type `i32`
10+
found enum `Option<i32>`
11+
help: consider using `Option::expect` to unwrap the `Option<i32>` value, panicking if the value is an `Option::None`
12+
|
13+
LL | let abs: i32 = 3i32.checked_abs().expect("REASON");
14+
| +++++++++++++++++
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)