Remove is_path_lang_item
This commit is contained in:
parent
748a593a7f
commit
d32ef64ed5
7 changed files with 24 additions and 24 deletions
|
|
@ -1,9 +1,10 @@
|
|||
use std::ops::ControlFlow;
|
||||
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::sym;
|
||||
use clippy_utils::ty::is_type_diagnostic_item;
|
||||
use clippy_utils::visitors::{Visitable, for_each_expr};
|
||||
use clippy_utils::{is_path_lang_item, sym};
|
||||
use rustc_ast::LitKind;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
|
|
@ -180,7 +181,9 @@ fn check_struct<'tcx>(
|
|||
.fields()
|
||||
.iter()
|
||||
.filter_map(|field| {
|
||||
if field_accesses.contains(&field.ident.name) || is_path_lang_item(cx, field.ty, LangItem::PhantomData) {
|
||||
if field_accesses.contains(&field.ident.name)
|
||||
|| field.ty.basic_res().is_lang_item(cx, LangItem::PhantomData)
|
||||
{
|
||||
None
|
||||
} else {
|
||||
Some((field.span, "this field is unused"))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use clippy_config::Conf;
|
|||
use clippy_config::types::PubUnderscoreFieldsBehaviour;
|
||||
use clippy_utils::attrs::is_doc_hidden;
|
||||
use clippy_utils::diagnostics::span_lint_hir_and_then;
|
||||
use clippy_utils::is_path_lang_item;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use rustc_hir::{FieldDef, Item, ItemKind, LangItem};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::impl_lint_pass;
|
||||
|
|
@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
|
|||
// We ignore fields that have `#[doc(hidden)]`.
|
||||
&& !is_doc_hidden(cx.tcx.hir_attrs(field.hir_id))
|
||||
// We ignore fields that are `PhantomData`.
|
||||
&& !is_path_lang_item(cx, field.ty, LangItem::PhantomData)
|
||||
&& !field.ty.basic_res().is_lang_item(cx, LangItem::PhantomData)
|
||||
{
|
||||
span_lint_hir_and_then(
|
||||
cx,
|
||||
|
|
|
|||
|
|
@ -4,14 +4,15 @@ use clippy_config::Conf;
|
|||
use clippy_config::types::MatchLintBehaviour;
|
||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::res::MaybeQPath;
|
||||
use clippy_utils::source::snippet_with_applicability;
|
||||
use clippy_utils::sugg::Sugg;
|
||||
use clippy_utils::ty::{implements_trait, is_copy, is_type_diagnostic_item};
|
||||
use clippy_utils::usage::local_used_after_expr;
|
||||
use clippy_utils::{
|
||||
eq_expr_value, fn_def_id_with_node_args, higher, is_else_clause, is_in_const_context, is_lint_allowed,
|
||||
is_path_lang_item, is_res_lang_ctor, pat_and_expr_can_be_question_mark, path_res, path_to_local, path_to_local_id,
|
||||
peel_blocks, peel_blocks_with_stmt, span_contains_cfg, span_contains_comment, sym,
|
||||
is_res_lang_ctor, pat_and_expr_can_be_question_mark, path_res, path_to_local, path_to_local_id, peel_blocks,
|
||||
peel_blocks_with_stmt, span_contains_cfg, span_contains_comment, sym,
|
||||
};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk};
|
||||
|
|
@ -521,11 +522,11 @@ impl QuestionMark {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_try_block(cx: &LateContext<'_>, bl: &Block<'_>) -> bool {
|
||||
fn is_try_block(bl: &Block<'_>) -> bool {
|
||||
if let Some(expr) = bl.expr
|
||||
&& let ExprKind::Call(callee, [_]) = expr.kind
|
||||
{
|
||||
is_path_lang_item(cx, callee, LangItem::TryTraitFromOutput)
|
||||
callee.opt_lang_path() == Some(LangItem::TryTraitFromOutput)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
@ -581,8 +582,8 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
|
||||
if is_try_block(cx, block) {
|
||||
fn check_block(&mut self, _: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
|
||||
if is_try_block(block) {
|
||||
*self
|
||||
.try_block_depth_stack
|
||||
.last_mut()
|
||||
|
|
@ -598,8 +599,8 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark {
|
|||
self.try_block_depth_stack.pop();
|
||||
}
|
||||
|
||||
fn check_block_post(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
|
||||
if is_try_block(cx, block) {
|
||||
fn check_block_post(&mut self, _: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
|
||||
if is_try_block(block) {
|
||||
*self
|
||||
.try_block_depth_stack
|
||||
.last_mut()
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ use clippy_config::Conf;
|
|||
use clippy_utils::consts::{ConstEvalCtxt, Constant};
|
||||
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then};
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::res::MaybeQPath;
|
||||
use clippy_utils::source::{SpanRangeExt, snippet, snippet_with_applicability};
|
||||
use clippy_utils::sugg::Sugg;
|
||||
use clippy_utils::ty::implements_trait;
|
||||
use clippy_utils::{
|
||||
expr_use_ctxt, fn_def_id, get_parent_expr, higher, is_in_const_context, is_integer_const, is_path_lang_item,
|
||||
path_to_local,
|
||||
expr_use_ctxt, fn_def_id, get_parent_expr, higher, is_in_const_context, is_integer_const, path_to_local,
|
||||
};
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_ast::ast::RangeLimits;
|
||||
|
|
@ -370,7 +370,7 @@ fn can_switch_ranges<'tcx>(
|
|||
// Check if `expr` is the argument of a compiler-generated `IntoIter::into_iter(expr)`
|
||||
if let ExprKind::Call(func, [arg]) = parent_expr.kind
|
||||
&& arg.hir_id == use_ctxt.child_id
|
||||
&& is_path_lang_item(cx, func, LangItem::IntoIterIntoIter)
|
||||
&& func.opt_lang_path() == Some(LangItem::IntoIterIntoIter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::res::{MaybeDef, MaybeResPath};
|
||||
use clippy_utils::source::snippet_opt;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def_id::DefId;
|
||||
|
|
@ -30,7 +31,7 @@ pub(super) fn check(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, def_id: DefId)
|
|||
}
|
||||
|
||||
fn replacement(cx: &LateContext<'_>, cty: &hir::Ty<'_>) -> Option<(Span, String)> {
|
||||
if clippy_utils::is_path_lang_item(cx, cty, hir::LangItem::String) {
|
||||
if cty.basic_res().is_lang_item(cx, hir::LangItem::String) {
|
||||
return Some((cty.span, "str".into()));
|
||||
}
|
||||
if clippy_utils::is_path_diagnostic_item(cx, cty, sym::Vec) {
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
|
|||
&& !id.is_local()
|
||||
{
|
||||
if let Some(lang) = self.cx.tcx.lang_items().from_def_id(id) {
|
||||
chain!(self, "is_path_lang_item(cx, {path}, LangItem::{}", lang.name());
|
||||
chain!(self, "{path}.res(cx).is_lang_item(cx, LangItem::{}", lang.name());
|
||||
} else if let Some(name) = self.cx.tcx.get_diagnostic_name(id) {
|
||||
chain!(self, "is_path_diagnostic_item(cx, {path}, sym::{name})");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ use crate::ast_utils::unordered_over;
|
|||
use crate::consts::{ConstEvalCtxt, Constant};
|
||||
use crate::higher::Range;
|
||||
use crate::msrvs::Msrv;
|
||||
use crate::res::{MaybeDef, MaybeResPath};
|
||||
use crate::ty::{adt_and_variant_of_res, can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type};
|
||||
use crate::visitors::for_each_expr_without_closures;
|
||||
|
||||
|
|
@ -437,12 +438,6 @@ pub fn qpath_generic_tys<'tcx>(qpath: &QPath<'tcx>) -> impl Iterator<Item = &'tc
|
|||
})
|
||||
}
|
||||
|
||||
/// If `maybe_path` is a path node which resolves to an item, resolves it to a `DefId` and checks if
|
||||
/// it matches the given lang item.
|
||||
pub fn is_path_lang_item<'tcx>(cx: &LateContext<'_>, maybe_path: &impl MaybePath<'tcx>, lang_item: LangItem) -> bool {
|
||||
path_def_id(cx, maybe_path).is_some_and(|id| cx.tcx.lang_items().get(lang_item) == Some(id))
|
||||
}
|
||||
|
||||
/// If `maybe_path` is a path node which resolves to an item, resolves it to a `DefId` and checks if
|
||||
/// it matches the given diagnostic item.
|
||||
pub fn is_path_diagnostic_item<'tcx>(
|
||||
|
|
@ -788,7 +783,7 @@ fn is_default_equivalent_from(cx: &LateContext<'_>, from_func: &Expr<'_>, arg: &
|
|||
ExprKind::Lit(hir::Lit {
|
||||
node: LitKind::Str(sym, _),
|
||||
..
|
||||
}) => return sym.is_empty() && is_path_lang_item(cx, ty, LangItem::String),
|
||||
}) => return sym.is_empty() && ty.basic_res().is_lang_item(cx, LangItem::String),
|
||||
ExprKind::Array([]) => return is_path_diagnostic_item(cx, ty, sym::Vec),
|
||||
ExprKind::Repeat(_, len) => {
|
||||
if let ConstArgKind::Anon(anon_const) = len.kind
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue