@@ -52,6 +52,7 @@ mod iter_skip_zero;
5252mod iter_with_drain;
5353mod iterator_step_by_zero;
5454mod join_absolute_paths;
55+ mod manual_as_ref_deref;
5556mod manual_c_str_literals;
5657mod manual_inspect;
5758mod manual_is_variant_and;
@@ -76,7 +77,6 @@ mod obfuscated_if_else;
7677mod ok_expect;
7778mod open_options;
7879mod option_as_ref_cloned;
79- mod option_as_ref_deref;
8080mod option_map_or_err_ok;
8181mod option_map_or_none;
8282mod option_map_unwrap_or;
@@ -1758,7 +1758,8 @@ declare_clippy_lint! {
17581758
17591759declare_clippy_lint ! {
17601760 /// ### What it does
1761- /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases (such as String::as_str).
1761+ /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases
1762+ /// (such as `String::as_str`) on `Option`.
17621763 ///
17631764 /// ### Why is this bad?
17641765 /// Readability, this can be written more concisely as
@@ -1782,6 +1783,33 @@ declare_clippy_lint! {
17821783 "using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`"
17831784}
17841785
1786+ declare_clippy_lint ! {
1787+ /// ### What it does
1788+ /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases
1789+ /// (such as `String::as_str`) on `Result`.
1790+ ///
1791+ /// ### Why is this bad?
1792+ /// Readability, this can be written more concisely as
1793+ /// `_.as_deref()`.
1794+ ///
1795+ /// ### Example
1796+ /// ```no_run
1797+ /// # let res = Ok::<_, ()>("".to_string());
1798+ /// res.as_ref().map(String::as_str)
1799+ /// # ;
1800+ /// ```
1801+ /// Use instead:
1802+ /// ```no_run
1803+ /// # let res = OK::<_, ()>("".to_string());
1804+ /// res.as_deref()
1805+ /// # ;
1806+ /// ```
1807+ #[ clippy:: version = "1.83.0" ]
1808+ pub RESULT_AS_REF_DEREF ,
1809+ complexity,
1810+ "using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`"
1811+ }
1812+
17851813declare_clippy_lint ! {
17861814 /// ### What it does
17871815 /// Checks for usage of `iter().next()` on a Slice or an Array
@@ -4223,6 +4251,7 @@ impl_lint_pass!(Methods => [
42234251 ZST_OFFSET ,
42244252 FILETYPE_IS_FILE ,
42254253 OPTION_AS_REF_DEREF ,
4254+ RESULT_AS_REF_DEREF ,
42264255 UNNECESSARY_LAZY_EVALUATIONS ,
42274256 MAP_COLLECT_RESULT_UNIT ,
42284257 FROM_ITER_INSTEAD_OF_COLLECT ,
@@ -4791,8 +4820,8 @@ impl Methods {
47914820 }
47924821 if let Some ( ( name, recv2, args, span2, _) ) = method_call ( recv) {
47934822 match ( name, args) {
4794- ( "as_mut" , [ ] ) => option_as_ref_deref :: check ( cx, expr, recv2, m_arg, true , & self . msrv ) ,
4795- ( "as_ref" , [ ] ) => option_as_ref_deref :: check ( cx, expr, recv2, m_arg, false , & self . msrv ) ,
4823+ ( "as_mut" , [ ] ) => manual_as_ref_deref :: check ( cx, expr, recv2, m_arg, true , & self . msrv ) ,
4824+ ( "as_ref" , [ ] ) => manual_as_ref_deref :: check ( cx, expr, recv2, m_arg, false , & self . msrv ) ,
47964825 ( "filter" , [ f_arg] ) => {
47974826 filter_map:: check ( cx, expr, recv2, f_arg, span2, recv, m_arg, span, false ) ;
47984827 } ,
0 commit comments