Skip to content

Commit 6906c68

Browse files
committed
extract type comparison
1 parent 5b32853 commit 6906c68

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

clippy_lints/src/use_self.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplVisitor<'a, 'tcx> {
167167
}
168168

169169
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
170+
fn expr_ty_matches<'a, 'tcx>(expr: &'tcx Expr<'tcx>, self_ty: Ty<'tcx>, cx: &LateContext<'a, 'tcx>) -> bool {
171+
cx.tcx
172+
.typeck_tables_of(expr.hir_id.owner.to_def_id())
173+
.node_type(expr.hir_id)
174+
== self_ty
175+
}
170176
match expr.kind {
171177
ExprKind::Struct(QPath::Resolved(_, path), ..) => {
172-
if self
173-
.cx
174-
.tcx
175-
.typeck_tables_of(expr.hir_id.owner.to_def_id())
176-
.node_type(expr.hir_id)
177-
== self.self_ty
178-
{
178+
if expr_ty_matches(expr, self.self_ty, self.cx) {
179179
match path.res {
180180
def::Res::SelfTy(..) => (),
181181
def::Res::Def(DefKind::Variant, _) => span_lint_ignore_last_segment(self.cx, path),
@@ -201,13 +201,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplVisitor<'a, 'tcx> {
201201
},
202202
_,
203203
) => {
204-
if self
205-
.cx
206-
.tcx
207-
.typeck_tables_of(expr.hir_id.owner.to_def_id())
208-
.node_type(expr.hir_id)
209-
== self.self_ty
210-
{
204+
if expr_ty_matches(expr, self.self_ty, self.cx) {
211205
match ctor_of {
212206
def::CtorOf::Struct => span_lint(self.cx, path.span),
213207
def::CtorOf::Variant => span_lint_ignore_last_segment(self.cx, path),

0 commit comments

Comments
 (0)