@@ -78,61 +78,45 @@ declare_clippy_lint! {
7878}
7979
8080declare_clippy_lint ! {
81- /// **What it does:** Checks for `.expect()` calls on `Option`s.
81+ /// **What it does:** Checks for `.expect()` calls on `Option`s and `Result`s .
8282 ///
83- /// **Why is this bad?** Usually it is better to handle the `None` case. Still,
84- /// for a lot of quick-and-dirty code, `expect` is a good choice, which is why
85- /// this lint is `Allow` by default.
83+ /// **Why is this bad?** Usually it is better to handle the `None` or `Err` case.
84+ /// Still, for a lot of quick-and-dirty code, `expect` is a good choice, which is why
85+ /// this lint is `Allow` by default.
8686 ///
87- /// **Known problems:** None.
87+ /// `result.expect()` will let the thread panic on `Err`
88+ /// values. Normally, you want to implement more sophisticated error handling,
89+ /// and propagate errors upwards with `?` operator.
8890 ///
89- /// **Example :**
91+ /// **Known problems :** None.
9092 ///
91- /// Using expect on an `Option`:
93+ /// **Examples:**
94+ /// ```rust,ignore
95+ /// # let opt = Some(1);
9296 ///
93- /// ```rust
94- /// let opt = Some(1);
97+ /// // Bad
9598 /// opt.expect("one");
96- /// ```
97- ///
98- /// Better:
9999 ///
100- /// ```rust,ignore
100+ /// // Good
101101 /// let opt = Some(1);
102102 /// opt?;
103103 /// ```
104- pub OPTION_EXPECT_USED ,
105- restriction,
106- "using `Option.expect()`, which might be better handled"
107- }
108-
109- declare_clippy_lint ! {
110- /// **What it does:** Checks for `.expect()` calls on `Result`s.
111- ///
112- /// **Why is this bad?** `result.expect()` will let the thread panic on `Err`
113- /// values. Normally, you want to implement more sophisticated error handling,
114- /// and propagate errors upwards with `?` operator.
115- ///
116- /// **Known problems:** None.
117104 ///
118- /// **Example:**
119- /// Using expect on an `Result`:
105+ /// // or
120106 ///
121107 /// ```rust
122- /// let res: Result<usize, ()> = Ok(1);
123- /// res.expect("one");
124- /// ```
108+ /// # let res: Result<usize, ()> = Ok(1);
125109 ///
126- /// Better:
110+ /// // Bad
111+ /// res.expect("one");
127112 ///
128- /// ```rust
129- /// let res: Result<usize, ()> = Ok(1);
113+ /// // Good
130114 /// res?;
131115 /// # Ok::<(), ()>(())
132116 /// ```
133- pub RESULT_EXPECT_USED ,
117+ pub EXPECT_USED ,
134118 restriction,
135- "using `Result .expect()`, which might be better handled"
119+ "using `.expect()` on `Result` or `Option `, which might be better handled"
136120}
137121
138122declare_clippy_lint ! {
@@ -1251,8 +1235,7 @@ declare_clippy_lint! {
12511235
12521236declare_lint_pass ! ( Methods => [
12531237 UNWRAP_USED ,
1254- OPTION_EXPECT_USED ,
1255- RESULT_EXPECT_USED ,
1238+ EXPECT_USED ,
12561239 SHOULD_IMPLEMENT_TRAIT ,
12571240 WRONG_SELF_CONVENTION ,
12581241 WRONG_PUB_SELF_CONVENTION ,
@@ -2407,9 +2390,9 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi
24072390 let obj_ty = walk_ptrs_ty ( cx. tables . expr_ty ( & expect_args[ 0 ] ) ) ;
24082391
24092392 let mess = if is_type_diagnostic_item ( cx, obj_ty, sym ! ( option_type) ) {
2410- Some ( ( OPTION_EXPECT_USED , "an Option" , "None" ) )
2393+ Some ( ( EXPECT_USED , "an Option" , "None" ) )
24112394 } else if is_type_diagnostic_item ( cx, obj_ty, sym ! ( result_type) ) {
2412- Some ( ( RESULT_EXPECT_USED , "a Result" , "Err" ) )
2395+ Some ( ( EXPECT_USED , "a Result" , "Err" ) )
24132396 } else {
24142397 None
24152398 } ;
0 commit comments