Skip to content

Commit f1ce294

Browse files
committed
clippy: support QPath::LangItem
This commit updates clippy with the introduction of `QPath::LangItem` so that it still compiles. Signed-off-by: David Wood <[email protected]>
1 parent dde93c9 commit f1ce294

20 files changed

+117
-130
lines changed

src/tools/clippy/clippy_lints/src/default_trait_access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess {
6868
);
6969
}
7070
},
71-
QPath::TypeRelative(..) => {},
71+
QPath::TypeRelative(..) | QPath::LangItem(..) => {},
7272
}
7373
}
7474
}

src/tools/clippy/clippy_lints/src/indexing_slicing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
8989
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
9090
if let ExprKind::Index(ref array, ref index) = &expr.kind {
9191
let ty = cx.typeck_results().expr_ty(array);
92-
if let Some(range) = higher::range(cx, index) {
92+
if let Some(range) = higher::range(index) {
9393
// Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..]
9494
if let ty::Array(_, s) = ty.kind {
9595
let size: u128 = if let Some(size) = s.try_eval_usize(cx.tcx, cx.param_env) {

src/tools/clippy/clippy_lints/src/infinite_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
171171
Finite
172172
}
173173
},
174-
ExprKind::Struct(..) => higher::range(cx, expr).map_or(false, |r| r.end.is_none()).into(),
174+
ExprKind::Struct(..) => higher::range(expr).map_or(false, |r| r.end.is_none()).into(),
175175
_ => Finite,
176176
}
177177
}

src/tools/clippy/clippy_lints/src/len_zero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ fn check_len(
262262
fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
263263
/// Special case ranges until `range_is_empty` is stabilized. See issue 3807.
264264
fn should_skip_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
265-
higher::range(cx, expr).map_or(false, |_| {
265+
higher::range(expr).map_or(false, |_| {
266266
!cx.tcx
267267
.features()
268268
.declared_lib_features

src/tools/clippy/clippy_lints/src/loops.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ fn detect_manual_memcpy<'tcx>(
10031003
start: Some(start),
10041004
end: Some(end),
10051005
limits,
1006-
}) = higher::range(cx, arg)
1006+
}) = higher::range(arg)
10071007
{
10081008
// the var must be a single name
10091009
if let PatKind::Binding(_, canonical_id, _, _) = pat.kind {
@@ -1177,7 +1177,7 @@ fn check_for_loop_range<'tcx>(
11771177
start: Some(start),
11781178
ref end,
11791179
limits,
1180-
}) = higher::range(cx, arg)
1180+
}) = higher::range(arg)
11811181
{
11821182
// the var must be a single name
11831183
if let PatKind::Binding(_, canonical_id, ident, _) = pat.kind {
@@ -1679,7 +1679,7 @@ fn check_for_mut_range_bound(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'
16791679
start: Some(start),
16801680
end: Some(end),
16811681
..
1682-
}) = higher::range(cx, arg)
1682+
}) = higher::range(arg)
16831683
{
16841684
let mut_ids = vec![check_for_mutability(cx, start), check_for_mutability(cx, end)];
16851685
if mut_ids[0].is_some() || mut_ids[1].is_some() {

src/tools/clippy/clippy_lints/src/match_on_vec_items.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::utils::{self, is_type_diagnostic_item, match_type, snippet, span_lint_and_sugg, walk_ptrs_ty};
1+
use crate::utils::{is_type_diagnostic_item, is_type_lang_item, snippet, span_lint_and_sugg};
2+
use crate::utils::walk_ptrs_ty;
23
use if_chain::if_chain;
34
use rustc_errors::Applicability;
4-
use rustc_hir::{Expr, ExprKind, MatchSource};
5+
use rustc_hir::{Expr, ExprKind, LangItem, MatchSource};
56
use rustc_lint::{LateContext, LateLintPass, LintContext};
67
use rustc_middle::lint::in_external_macro;
78
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -96,5 +97,5 @@ fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
9697
fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
9798
let ty = cx.typeck_results().expr_ty(expr);
9899
let ty = walk_ptrs_ty(ty);
99-
match_type(cx, ty, &utils::paths::RANGE_FULL)
100+
is_type_lang_item(cx, ty, LangItem::RangeFull)
100101
}

src/tools/clippy/clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ fn lint_iter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, iter_
22712271
if_chain! {
22722272
if let hir::ExprKind::Index(ref caller_var, ref index_expr) = &caller_expr.kind;
22732273
if let Some(higher::Range { start: Some(start_expr), end: None, limits: ast::RangeLimits::HalfOpen })
2274-
= higher::range(cx, index_expr);
2274+
= higher::range(index_expr);
22752275
if let hir::ExprKind::Lit(ref start_lit) = &start_expr.kind;
22762276
if let ast::LitKind::Int(start_idx, _) = start_lit.node;
22772277
then {

src/tools/clippy/clippy_lints/src/misc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
433433
return;
434434
}
435435
let binding = match expr.kind {
436+
ExprKind::Path(hir::QPath::LangItem(..)) => None,
436437
ExprKind::Path(ref qpath) => {
437438
let binding = last_path_segment(qpath).ident.as_str();
438439
if binding.starts_with('_') &&

src/tools/clippy/clippy_lints/src/ranges.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for Ranges {
147147
if let ExprKind::MethodCall(ref iter_path, _, ref iter_args , _) = *iter;
148148
if iter_path.ident.name == sym!(iter);
149149
// range expression in `.zip()` call: `0..x.len()`
150-
if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(cx, zip_arg);
150+
if let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(zip_arg);
151151
if is_integer_const(cx, start, 0);
152152
// `.len()` call
153153
if let ExprKind::MethodCall(ref len_path, _, ref len_args, _) = end.kind;
@@ -180,7 +180,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) {
180180
start,
181181
end: Some(end),
182182
limits: RangeLimits::HalfOpen
183-
}) = higher::range(cx, expr);
183+
}) = higher::range(expr);
184184
if let Some(y) = y_plus_one(cx, end);
185185
then {
186186
let span = if expr.span.from_expansion() {
@@ -225,7 +225,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) {
225225
// inclusive range minus one: `x..=(y-1)`
226226
fn check_inclusive_range_minus_one(cx: &LateContext<'_>, expr: &Expr<'_>) {
227227
if_chain! {
228-
if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(cx, expr);
228+
if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(expr);
229229
if let Some(y) = y_minus_one(cx, end);
230230
then {
231231
span_lint_and_then(
@@ -279,7 +279,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) {
279279
}
280280

281281
if_chain! {
282-
if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(cx, expr);
282+
if let Some(higher::Range { start: Some(start), end: Some(end), limits }) = higher::range(expr);
283283
let ty = cx.typeck_results().expr_ty(start);
284284
if let ty::Int(_) | ty::Uint(_) = ty.kind;
285285
if let Some((start_idx, _)) = constant(cx, cx.typeck_results(), start);

src/tools/clippy/clippy_lints/src/try_err.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::utils::{
2-
is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet, snippet_with_macro_callsite,
3-
span_lint_and_sugg,
2+
is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet,
3+
snippet_with_macro_callsite, span_lint_and_sugg,
44
};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
7-
use rustc_hir::{Expr, ExprKind, MatchSource};
7+
use rustc_hir::{Expr, ExprKind, QPath, LangItem, MatchSource};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_middle::lint::in_external_macro;
1010
use rustc_middle::ty::{self, Ty};
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
6262
if let ExprKind::Match(ref match_arg, _, MatchSource::TryDesugar) = expr.kind;
6363
if let ExprKind::Call(ref match_fun, ref try_args) = match_arg.kind;
6464
if let ExprKind::Path(ref match_fun_path) = match_fun.kind;
65-
if match_qpath(match_fun_path, &paths::TRY_INTO_RESULT);
65+
if matches!(match_fun_path, QPath::LangItem(LangItem::TryIntoResult, _));
6666
if let Some(ref try_arg) = try_args.get(0);
6767
if let ExprKind::Call(ref err_fun, ref err_args) = try_arg.kind;
6868
if let Some(ref err_arg) = err_args.get(0);

0 commit comments

Comments
 (0)