@@ -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;
@@ -1759,7 +1759,8 @@ declare_clippy_lint! {
17591759
17601760declare_clippy_lint ! {
17611761 /// ### What it does
1762- /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases (such as String::as_str).
1762+ /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases
1763+ /// (such as `String::as_str`) on `Option`.
17631764 ///
17641765 /// ### Why is this bad?
17651766 /// Readability, this can be written more concisely as
@@ -1783,6 +1784,33 @@ declare_clippy_lint! {
17831784 "using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`"
17841785}
17851786
1787+ declare_clippy_lint ! {
1788+ /// ### What it does
1789+ /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases
1790+ /// (such as `String::as_str`) on `Result`.
1791+ ///
1792+ /// ### Why is this bad?
1793+ /// Readability, this can be written more concisely as
1794+ /// `_.as_deref()`.
1795+ ///
1796+ /// ### Example
1797+ /// ```no_run
1798+ /// # let res = Ok::<_, ()>("".to_string());
1799+ /// res.as_ref().map(String::as_str)
1800+ /// # ;
1801+ /// ```
1802+ /// Use instead:
1803+ /// ```no_run
1804+ /// # let res = OK::<_, ()>("".to_string());
1805+ /// res.as_deref()
1806+ /// # ;
1807+ /// ```
1808+ #[ clippy:: version = "1.83.0" ]
1809+ pub RESULT_AS_REF_DEREF ,
1810+ complexity,
1811+ "using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`"
1812+ }
1813+
17861814declare_clippy_lint ! {
17871815 /// ### What it does
17881816 /// Checks for usage of `iter().next()` on a Slice or an Array
@@ -4252,6 +4280,7 @@ impl_lint_pass!(Methods => [
42524280 ZST_OFFSET ,
42534281 FILETYPE_IS_FILE ,
42544282 OPTION_AS_REF_DEREF ,
4283+ RESULT_AS_REF_DEREF ,
42554284 UNNECESSARY_LAZY_EVALUATIONS ,
42564285 MAP_COLLECT_RESULT_UNIT ,
42574286 FROM_ITER_INSTEAD_OF_COLLECT ,
@@ -4821,8 +4850,8 @@ impl Methods {
48214850 }
48224851 if let Some ( ( name, recv2, args, span2, _) ) = method_call ( recv) {
48234852 match ( name, args) {
4824- ( "as_mut" , [ ] ) => option_as_ref_deref :: check ( cx, expr, recv2, m_arg, true , & self . msrv ) ,
4825- ( "as_ref" , [ ] ) => option_as_ref_deref :: check ( cx, expr, recv2, m_arg, false , & self . msrv ) ,
4853+ ( "as_mut" , [ ] ) => manual_as_ref_deref :: check ( cx, expr, recv2, m_arg, true , & self . msrv ) ,
4854+ ( "as_ref" , [ ] ) => manual_as_ref_deref :: check ( cx, expr, recv2, m_arg, false , & self . msrv ) ,
48264855 ( "filter" , [ f_arg] ) => {
48274856 filter_map:: check ( cx, expr, recv2, f_arg, span2, recv, m_arg, span, false ) ;
48284857 } ,
0 commit comments