Skip to content

Commit d1baa25

Browse files
committed
clippy_lint: Add 'ref_option_ref' refactor code
1 parent 213dbf7 commit d1baa25

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

clippy_lints/src/ref_option_ref.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{last_path_segment, match_def_path, paths, snippet, span_lint_and_sugg};
2-
use rustc_hir::{GenericArg, Local, Mutability, TyKind};
2+
use rustc_hir::{GenericArg, Local, Mutability, Ty, TyKind};
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_session::{declare_lint_pass, declare_tool_lint};
55

@@ -34,12 +34,20 @@ declare_lint_pass!(RefOptionRef => [REF_OPTION_REF]);
3434

3535
impl<'tcx> LateLintPass<'tcx> for RefOptionRef {
3636
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) {
37+
38+
if let Some(ref ty) = local.ty {
39+
self.check_ref_option_ref(cx, ty);
40+
}
41+
}
42+
}
43+
44+
impl RefOptionRef {
45+
fn check_ref_option_ref(&self, cx: &LateContext<'tcx>, ty: &'tcx Ty<'tcx>) {
3746
if_chain! {
38-
if let Some(ref ty) = local.ty;
3947
if let TyKind::Rptr(_, ref mut_ty) = ty.kind;
4048
if mut_ty.mutbl == Mutability::Not;
4149
if let TyKind::Path(ref qpath) = &mut_ty.ty.kind ;
42-
if let Some(def_id) = cx.typeck_results().qpath_res(qpath, local.hir_id).opt_def_id();
50+
if let Some(def_id) = cx.typeck_results().qpath_res(qpath, ty.hir_id).opt_def_id();
4351
if match_def_path(cx, def_id, &paths::OPTION);
4452
if let Some(ref params) = last_path_segment(qpath).args ;
4553
if !params.parenthesized;
@@ -57,9 +65,9 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef {
5765
"since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>",
5866
"try",
5967
format!("Option<{}>", &snippet(cx, inner_ty.span, "..")),
60-
Applicability::MachineApplicable,
68+
Applicability::Unspecified,
6169
);
6270
}
6371
}
6472
}
65-
}
73+
}

0 commit comments

Comments
 (0)