@@ -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;
@@ -79,7 +80,6 @@ mod obfuscated_if_else;
7980mod ok_expect;
8081mod open_options;
8182mod option_as_ref_cloned;
82- mod option_as_ref_deref;
8383mod option_map_or_err_ok;
8484mod option_map_or_none;
8585mod option_map_unwrap_or;
@@ -1762,7 +1762,8 @@ declare_clippy_lint! {
17621762
17631763declare_clippy_lint ! {
17641764 /// ### What it does
1765- /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases (such as String::as_str).
1765+ /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases
1766+ /// (such as `String::as_str`) on `Option`.
17661767 ///
17671768 /// ### Why is this bad?
17681769 /// Readability, this can be written more concisely as
@@ -1786,6 +1787,33 @@ declare_clippy_lint! {
17861787 "using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`"
17871788}
17881789
1790+ declare_clippy_lint ! {
1791+ /// ### What it does
1792+ /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases
1793+ /// (such as `String::as_str`) on `Result`.
1794+ ///
1795+ /// ### Why is this bad?
1796+ /// Readability, this can be written more concisely as
1797+ /// `_.as_deref()`.
1798+ ///
1799+ /// ### Example
1800+ /// ```no_run
1801+ /// # let res = Ok::<_, ()>("".to_string());
1802+ /// res.as_ref().map(String::as_str)
1803+ /// # ;
1804+ /// ```
1805+ /// Use instead:
1806+ /// ```no_run
1807+ /// # let res = Ok::<_, ()>("".to_string());
1808+ /// res.as_deref()
1809+ /// # ;
1810+ /// ```
1811+ #[ clippy:: version = "1.84.0" ]
1812+ pub RESULT_AS_REF_DEREF ,
1813+ complexity,
1814+ "using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`"
1815+ }
1816+
17891817declare_clippy_lint ! {
17901818 /// ### What it does
17911819 /// Checks for usage of `iter().next()` on a Slice or an Array
@@ -4339,6 +4367,7 @@ impl_lint_pass!(Methods => [
43394367 ZST_OFFSET ,
43404368 FILETYPE_IS_FILE ,
43414369 OPTION_AS_REF_DEREF ,
4370+ RESULT_AS_REF_DEREF ,
43424371 UNNECESSARY_LAZY_EVALUATIONS ,
43434372 MAP_COLLECT_RESULT_UNIT ,
43444373 FROM_ITER_INSTEAD_OF_COLLECT ,
@@ -4932,8 +4961,8 @@ impl Methods {
49324961 }
49334962 if let Some ( ( name, recv2, args, span2, _) ) = method_call ( recv) {
49344963 match ( name, args) {
4935- ( "as_mut" , [ ] ) => option_as_ref_deref :: check ( cx, expr, recv2, m_arg, true , & self . msrv ) ,
4936- ( "as_ref" , [ ] ) => option_as_ref_deref :: check ( cx, expr, recv2, m_arg, false , & self . msrv ) ,
4964+ ( "as_mut" , [ ] ) => manual_as_ref_deref :: check ( cx, expr, recv2, m_arg, true , & self . msrv ) ,
4965+ ( "as_ref" , [ ] ) => manual_as_ref_deref :: check ( cx, expr, recv2, m_arg, false , & self . msrv ) ,
49374966 ( "filter" , [ f_arg] ) => {
49384967 filter_map:: check ( cx, expr, recv2, f_arg, span2, recv, m_arg, span, false ) ;
49394968 } ,
0 commit comments