Skip to content

Commit a36d9a7

Browse files
committed
move is_ty_alias to clippy_utils
1 parent 1190c02 commit a36d9a7

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

clippy_lints/src/useless_conversion.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg};
2+
use clippy_utils::is_ty_alias;
23
use clippy_utils::source::{snippet, snippet_with_context};
34
use clippy_utils::sugg::Sugg;
45
use clippy_utils::ty::{is_copy, is_type_diagnostic_item, same_type_and_consts};
56
use clippy_utils::{get_parent_expr, is_trait_method, match_def_path, path_to_local, paths};
67
use if_chain::if_chain;
78
use rustc_errors::Applicability;
8-
use rustc_hir::def::{DefKind, Res};
9-
use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, MatchSource, Node, PatKind, QPath, TyKind};
9+
use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, MatchSource, Node, PatKind};
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::ty;
1212
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -197,12 +197,3 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
197197
}
198198
}
199199
}
200-
201-
/// `cx.qpath_res` seems to return `AssocFn` so we do this instead
202-
fn is_ty_alias(qpath: &QPath<'_>) -> bool {
203-
match *qpath {
204-
QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias, ..)),
205-
QPath::TypeRelative(ty, _) if let TyKind::Path(qpath) = ty.kind => is_ty_alias(&qpath),
206-
_ => false,
207-
}
208-
}

clippy_utils/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(array_chunks)]
22
#![feature(box_patterns)]
3+
#![feature(if_let_guard)]
34
#![feature(let_chains)]
45
#![feature(lint_reasons)]
56
#![feature(never_type)]
@@ -282,6 +283,15 @@ pub fn is_wild(pat: &Pat<'_>) -> bool {
282283
matches!(pat.kind, PatKind::Wild)
283284
}
284285

286+
/// Checks if the given `QPath` belongs to a type alias.
287+
pub fn is_ty_alias(qpath: &QPath<'_>) -> bool {
288+
match *qpath {
289+
QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias, ..)),
290+
QPath::TypeRelative(ty, _) if let TyKind::Path(qpath) = ty.kind => { is_ty_alias(&qpath) },
291+
_ => false,
292+
}
293+
}
294+
285295
/// Checks if the method call given in `expr` belongs to the given trait.
286296
/// This is a deprecated function, consider using [`is_trait_method`].
287297
pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool {

0 commit comments

Comments
 (0)