Skip to content

Commit d32ef64

Browse files
committed
Remove is_path_lang_item
1 parent 748a593 commit d32ef64

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

clippy_lints/src/missing_fields_in_debug.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::ops::ControlFlow;
22

33
use clippy_utils::diagnostics::span_lint_and_then;
4+
use clippy_utils::res::{MaybeDef, MaybeResPath};
5+
use clippy_utils::sym;
46
use clippy_utils::ty::is_type_diagnostic_item;
57
use clippy_utils::visitors::{Visitable, for_each_expr};
6-
use clippy_utils::{is_path_lang_item, sym};
78
use rustc_ast::LitKind;
89
use rustc_data_structures::fx::FxHashSet;
910
use rustc_hir::def::{DefKind, Res};
@@ -180,7 +181,9 @@ fn check_struct<'tcx>(
180181
.fields()
181182
.iter()
182183
.filter_map(|field| {
183-
if field_accesses.contains(&field.ident.name) || is_path_lang_item(cx, field.ty, LangItem::PhantomData) {
184+
if field_accesses.contains(&field.ident.name)
185+
|| field.ty.basic_res().is_lang_item(cx, LangItem::PhantomData)
186+
{
184187
None
185188
} else {
186189
Some((field.span, "this field is unused"))

clippy_lints/src/pub_underscore_fields.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_config::Conf;
22
use clippy_config::types::PubUnderscoreFieldsBehaviour;
33
use clippy_utils::attrs::is_doc_hidden;
44
use clippy_utils::diagnostics::span_lint_hir_and_then;
5-
use clippy_utils::is_path_lang_item;
5+
use clippy_utils::res::{MaybeDef, MaybeResPath};
66
use rustc_hir::{FieldDef, Item, ItemKind, LangItem};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::impl_lint_pass;
@@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
7676
// We ignore fields that have `#[doc(hidden)]`.
7777
&& !is_doc_hidden(cx.tcx.hir_attrs(field.hir_id))
7878
// We ignore fields that are `PhantomData`.
79-
&& !is_path_lang_item(cx, field.ty, LangItem::PhantomData)
79+
&& !field.ty.basic_res().is_lang_item(cx, LangItem::PhantomData)
8080
{
8181
span_lint_hir_and_then(
8282
cx,

clippy_lints/src/question_mark.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ use clippy_config::Conf;
44
use clippy_config::types::MatchLintBehaviour;
55
use clippy_utils::diagnostics::span_lint_and_sugg;
66
use clippy_utils::msrvs::{self, Msrv};
7+
use clippy_utils::res::MaybeQPath;
78
use clippy_utils::source::snippet_with_applicability;
89
use clippy_utils::sugg::Sugg;
910
use clippy_utils::ty::{implements_trait, is_copy, is_type_diagnostic_item};
1011
use clippy_utils::usage::local_used_after_expr;
1112
use clippy_utils::{
1213
eq_expr_value, fn_def_id_with_node_args, higher, is_else_clause, is_in_const_context, is_lint_allowed,
13-
is_path_lang_item, is_res_lang_ctor, pat_and_expr_can_be_question_mark, path_res, path_to_local, path_to_local_id,
14-
peel_blocks, peel_blocks_with_stmt, span_contains_cfg, span_contains_comment, sym,
14+
is_res_lang_ctor, pat_and_expr_can_be_question_mark, path_res, path_to_local, path_to_local_id, peel_blocks,
15+
peel_blocks_with_stmt, span_contains_cfg, span_contains_comment, sym,
1516
};
1617
use rustc_errors::Applicability;
1718
use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk};
@@ -521,11 +522,11 @@ impl QuestionMark {
521522
}
522523
}
523524

524-
fn is_try_block(cx: &LateContext<'_>, bl: &Block<'_>) -> bool {
525+
fn is_try_block(bl: &Block<'_>) -> bool {
525526
if let Some(expr) = bl.expr
526527
&& let ExprKind::Call(callee, [_]) = expr.kind
527528
{
528-
is_path_lang_item(cx, callee, LangItem::TryTraitFromOutput)
529+
callee.opt_lang_path() == Some(LangItem::TryTraitFromOutput)
529530
} else {
530531
false
531532
}
@@ -581,8 +582,8 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark {
581582
}
582583
}
583584

584-
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
585-
if is_try_block(cx, block) {
585+
fn check_block(&mut self, _: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
586+
if is_try_block(block) {
586587
*self
587588
.try_block_depth_stack
588589
.last_mut()
@@ -598,8 +599,8 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark {
598599
self.try_block_depth_stack.pop();
599600
}
600601

601-
fn check_block_post(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
602-
if is_try_block(cx, block) {
602+
fn check_block_post(&mut self, _: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
603+
if is_try_block(block) {
603604
*self
604605
.try_block_depth_stack
605606
.last_mut()

clippy_lints/src/ranges.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use clippy_config::Conf;
22
use clippy_utils::consts::{ConstEvalCtxt, Constant};
33
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then};
44
use clippy_utils::msrvs::{self, Msrv};
5+
use clippy_utils::res::MaybeQPath;
56
use clippy_utils::source::{SpanRangeExt, snippet, snippet_with_applicability};
67
use clippy_utils::sugg::Sugg;
78
use clippy_utils::ty::implements_trait;
89
use clippy_utils::{
9-
expr_use_ctxt, fn_def_id, get_parent_expr, higher, is_in_const_context, is_integer_const, is_path_lang_item,
10-
path_to_local,
10+
expr_use_ctxt, fn_def_id, get_parent_expr, higher, is_in_const_context, is_integer_const, path_to_local,
1111
};
1212
use rustc_ast::Mutability;
1313
use rustc_ast::ast::RangeLimits;
@@ -370,7 +370,7 @@ fn can_switch_ranges<'tcx>(
370370
// Check if `expr` is the argument of a compiler-generated `IntoIter::into_iter(expr)`
371371
if let ExprKind::Call(func, [arg]) = parent_expr.kind
372372
&& arg.hir_id == use_ctxt.child_id
373-
&& is_path_lang_item(cx, func, LangItem::IntoIterIntoIter)
373+
&& func.opt_lang_path() == Some(LangItem::IntoIterIntoIter)
374374
{
375375
return true;
376376
}

clippy_lints/src/types/owned_cow.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use clippy_utils::res::{MaybeDef, MaybeResPath};
23
use clippy_utils::source::snippet_opt;
34
use rustc_errors::Applicability;
45
use rustc_hir::def_id::DefId;
@@ -30,7 +31,7 @@ pub(super) fn check(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, def_id: DefId)
3031
}
3132

3233
fn replacement(cx: &LateContext<'_>, cty: &hir::Ty<'_>) -> Option<(Span, String)> {
33-
if clippy_utils::is_path_lang_item(cx, cty, hir::LangItem::String) {
34+
if cty.basic_res().is_lang_item(cx, hir::LangItem::String) {
3435
return Some((cty.span, "str".into()));
3536
}
3637
if clippy_utils::is_path_diagnostic_item(cx, cty, sym::Vec) {

clippy_lints/src/utils/author.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
296296
&& !id.is_local()
297297
{
298298
if let Some(lang) = self.cx.tcx.lang_items().from_def_id(id) {
299-
chain!(self, "is_path_lang_item(cx, {path}, LangItem::{}", lang.name());
299+
chain!(self, "{path}.res(cx).is_lang_item(cx, LangItem::{}", lang.name());
300300
} else if let Some(name) = self.cx.tcx.get_diagnostic_name(id) {
301301
chain!(self, "is_path_diagnostic_item(cx, {path}, sym::{name})");
302302
} else {

clippy_utils/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ use crate::ast_utils::unordered_over;
132132
use crate::consts::{ConstEvalCtxt, Constant};
133133
use crate::higher::Range;
134134
use crate::msrvs::Msrv;
135+
use crate::res::{MaybeDef, MaybeResPath};
135136
use crate::ty::{adt_and_variant_of_res, can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type};
136137
use crate::visitors::for_each_expr_without_closures;
137138

@@ -437,12 +438,6 @@ pub fn qpath_generic_tys<'tcx>(qpath: &QPath<'tcx>) -> impl Iterator<Item = &'tc
437438
})
438439
}
439440

440-
/// If `maybe_path` is a path node which resolves to an item, resolves it to a `DefId` and checks if
441-
/// it matches the given lang item.
442-
pub fn is_path_lang_item<'tcx>(cx: &LateContext<'_>, maybe_path: &impl MaybePath<'tcx>, lang_item: LangItem) -> bool {
443-
path_def_id(cx, maybe_path).is_some_and(|id| cx.tcx.lang_items().get(lang_item) == Some(id))
444-
}
445-
446441
/// If `maybe_path` is a path node which resolves to an item, resolves it to a `DefId` and checks if
447442
/// it matches the given diagnostic item.
448443
pub fn is_path_diagnostic_item<'tcx>(
@@ -788,7 +783,7 @@ fn is_default_equivalent_from(cx: &LateContext<'_>, from_func: &Expr<'_>, arg: &
788783
ExprKind::Lit(hir::Lit {
789784
node: LitKind::Str(sym, _),
790785
..
791-
}) => return sym.is_empty() && is_path_lang_item(cx, ty, LangItem::String),
786+
}) => return sym.is_empty() && ty.basic_res().is_lang_item(cx, LangItem::String),
792787
ExprKind::Array([]) => return is_path_diagnostic_item(cx, ty, sym::Vec),
793788
ExprKind::Repeat(_, len) => {
794789
if let ConstArgKind::Anon(anon_const) = len.kind

0 commit comments

Comments
 (0)