Use LanguageItems::require less
This commit is contained in:
parent
a6180ede5c
commit
1c8e658820
16 changed files with 34 additions and 45 deletions
|
@ -23,7 +23,6 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
|
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::intravisit::{walk_generics, Visitor as _};
|
use rustc_hir::intravisit::{walk_generics, Visitor as _};
|
||||||
use rustc_hir::lang_items::LangItem;
|
|
||||||
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
|
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
|
||||||
use rustc_middle::middle::stability::AllowUnstable;
|
use rustc_middle::middle::stability::AllowUnstable;
|
||||||
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
|
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
|
||||||
|
@ -884,9 +883,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let sized_def_id = tcx.lang_items().require(LangItem::Sized);
|
let sized_def_id = tcx.lang_items().sized_trait();
|
||||||
match (&sized_def_id, unbound) {
|
match (&sized_def_id, unbound) {
|
||||||
(Ok(sized_def_id), Some(tpb))
|
(Some(sized_def_id), Some(tpb))
|
||||||
if tpb.path.res == Res::Def(DefKind::Trait, *sized_def_id) =>
|
if tpb.path.res == Res::Def(DefKind::Trait, *sized_def_id) =>
|
||||||
{
|
{
|
||||||
// There was in fact a `?Sized` bound, return without doing anything
|
// There was in fact a `?Sized` bound, return without doing anything
|
||||||
|
@ -906,7 +905,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
// There was no `?Sized` bound; add implicitly sized if `Sized` is available.
|
// There was no `?Sized` bound; add implicitly sized if `Sized` is available.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sized_def_id.is_err() {
|
if sized_def_id.is_none() {
|
||||||
// No lang item for `Sized`, so we can't add it as a bound.
|
// No lang item for `Sized`, so we can't add it as a bound.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2456,7 +2456,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_lang_item(self, ty: Ty<'tcx>, item: LangItem) -> Option<Ty<'tcx>> {
|
pub fn mk_lang_item(self, ty: Ty<'tcx>, item: LangItem) -> Option<Ty<'tcx>> {
|
||||||
let def_id = self.lang_items().require(item).ok()?;
|
let def_id = self.lang_items().get(item)?;
|
||||||
Some(self.mk_generic_adt(def_id, ty))
|
Some(self.mk_generic_adt(def_id, ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1019,7 +1019,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
let mut never_suggest_borrow: Vec<_> =
|
let mut never_suggest_borrow: Vec<_> =
|
||||||
[LangItem::Copy, LangItem::Clone, LangItem::Unpin, LangItem::Sized]
|
[LangItem::Copy, LangItem::Clone, LangItem::Unpin, LangItem::Sized]
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|lang_item| self.tcx.lang_items().require(*lang_item).ok())
|
.filter_map(|lang_item| self.tcx.lang_items().get(*lang_item))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if let Some(def_id) = self.tcx.get_diagnostic_item(sym::Send) {
|
if let Some(def_id) = self.tcx.get_diagnostic_item(sym::Send) {
|
||||||
|
|
|
@ -6,11 +6,12 @@ use rustc_hir::intravisit::{
|
||||||
walk_fn_decl, walk_generic_param, walk_generics, walk_impl_item_ref, walk_item, walk_param_bound,
|
walk_fn_decl, walk_generic_param, walk_generics, walk_impl_item_ref, walk_item, walk_param_bound,
|
||||||
walk_poly_trait_ref, walk_trait_ref, walk_ty, Visitor,
|
walk_poly_trait_ref, walk_trait_ref, walk_ty, Visitor,
|
||||||
};
|
};
|
||||||
|
use rustc_hir::lang_items;
|
||||||
use rustc_hir::FnRetTy::Return;
|
use rustc_hir::FnRetTy::Return;
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem,
|
BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem,
|
||||||
ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, TraitFn,
|
ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, TraitFn, TraitItem,
|
||||||
TraitItem, TraitItemKind, Ty, TyKind, WherePredicate,
|
TraitItemKind, Ty, TyKind, WherePredicate,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::nested_filter as middle_nested_filter;
|
use rustc_middle::hir::nested_filter as middle_nested_filter;
|
||||||
|
@ -364,8 +365,6 @@ fn unique_lifetimes(lts: &[RefLt]) -> usize {
|
||||||
lts.iter().collect::<FxHashSet<_>>().len()
|
lts.iter().collect::<FxHashSet<_>>().len()
|
||||||
}
|
}
|
||||||
|
|
||||||
const CLOSURE_TRAIT_BOUNDS: [LangItem; 3] = [LangItem::Fn, LangItem::FnMut, LangItem::FnOnce];
|
|
||||||
|
|
||||||
/// A visitor usable for `rustc_front::visit::walk_ty()`.
|
/// A visitor usable for `rustc_front::visit::walk_ty()`.
|
||||||
struct RefVisitor<'a, 'tcx> {
|
struct RefVisitor<'a, 'tcx> {
|
||||||
cx: &'a LateContext<'tcx>,
|
cx: &'a LateContext<'tcx>,
|
||||||
|
@ -424,12 +423,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
||||||
|
|
||||||
fn visit_poly_trait_ref(&mut self, poly_tref: &'tcx PolyTraitRef<'tcx>) {
|
fn visit_poly_trait_ref(&mut self, poly_tref: &'tcx PolyTraitRef<'tcx>) {
|
||||||
let trait_ref = &poly_tref.trait_ref;
|
let trait_ref = &poly_tref.trait_ref;
|
||||||
if CLOSURE_TRAIT_BOUNDS.iter().any(|&item| {
|
if let Some(id) = trait_ref.trait_def_id() && lang_items::FN_TRAITS.iter().any(|&item| {
|
||||||
self.cx
|
self.cx.tcx.lang_items().get(item) == Some(id)
|
||||||
.tcx
|
|
||||||
.lang_items()
|
|
||||||
.require(item)
|
|
||||||
.map_or(false, |id| Some(id) == trait_ref.trait_def_id())
|
|
||||||
}) {
|
}) {
|
||||||
let mut sub_visitor = RefVisitor::new(self.cx);
|
let mut sub_visitor = RefVisitor::new(self.cx);
|
||||||
sub_visitor.visit_trait_ref(trait_ref);
|
sub_visitor.visit_trait_ref(trait_ref);
|
||||||
|
|
|
@ -92,7 +92,7 @@ fn check_into_iter(
|
||||||
&& match_def_path(cx, filter_def_id, &paths::CORE_ITER_FILTER)
|
&& match_def_path(cx, filter_def_id, &paths::CORE_ITER_FILTER)
|
||||||
&& let hir::ExprKind::MethodCall(_, struct_expr, [], _) = &into_iter_expr.kind
|
&& let hir::ExprKind::MethodCall(_, struct_expr, [], _) = &into_iter_expr.kind
|
||||||
&& let Some(into_iter_def_id) = cx.typeck_results().type_dependent_def_id(into_iter_expr.hir_id)
|
&& let Some(into_iter_def_id) = cx.typeck_results().type_dependent_def_id(into_iter_expr.hir_id)
|
||||||
&& cx.tcx.lang_items().require(hir::LangItem::IntoIterIntoIter).ok() == Some(into_iter_def_id)
|
&& Some(into_iter_def_id) == cx.tcx.lang_items().into_iter_fn()
|
||||||
&& match_acceptable_type(cx, left_expr, msrv)
|
&& match_acceptable_type(cx, left_expr, msrv)
|
||||||
&& SpanlessEq::new(cx).eq_expr(left_expr, struct_expr) {
|
&& SpanlessEq::new(cx).eq_expr(left_expr, struct_expr) {
|
||||||
suggest(cx, parent_expr, left_expr, target_expr);
|
suggest(cx, parent_expr, left_expr, target_expr);
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub(crate) trait BindInsteadOfMap {
|
||||||
const GOOD_METHOD_NAME: &'static str;
|
const GOOD_METHOD_NAME: &'static str;
|
||||||
|
|
||||||
fn no_op_msg(cx: &LateContext<'_>) -> Option<String> {
|
fn no_op_msg(cx: &LateContext<'_>) -> Option<String> {
|
||||||
let variant_id = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM).ok()?;
|
let variant_id = cx.tcx.lang_items().get(Self::VARIANT_LANG_ITEM)?;
|
||||||
let item_id = cx.tcx.parent(variant_id);
|
let item_id = cx.tcx.parent(variant_id);
|
||||||
Some(format!(
|
Some(format!(
|
||||||
"using `{}.{}({})`, which is a no-op",
|
"using `{}.{}({})`, which is a no-op",
|
||||||
|
@ -52,7 +52,7 @@ pub(crate) trait BindInsteadOfMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lint_msg(cx: &LateContext<'_>) -> Option<String> {
|
fn lint_msg(cx: &LateContext<'_>) -> Option<String> {
|
||||||
let variant_id = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM).ok()?;
|
let variant_id = cx.tcx.lang_items().get(Self::VARIANT_LANG_ITEM)?;
|
||||||
let item_id = cx.tcx.parent(variant_id);
|
let item_id = cx.tcx.parent(variant_id);
|
||||||
Some(format!(
|
Some(format!(
|
||||||
"using `{}.{}(|x| {}(y))`, which is more succinctly expressed as `{}(|x| y)`",
|
"using `{}.{}(|x| {}(y))`, which is more succinctly expressed as `{}(|x| y)`",
|
||||||
|
@ -144,7 +144,7 @@ pub(crate) trait BindInsteadOfMap {
|
||||||
fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) -> bool {
|
fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) -> bool {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let Some(adt) = cx.typeck_results().expr_ty(recv).ty_adt_def();
|
if let Some(adt) = cx.typeck_results().expr_ty(recv).ty_adt_def();
|
||||||
if let Ok(vid) = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM);
|
if let Some(vid) = cx.tcx.lang_items().get(Self::VARIANT_LANG_ITEM);
|
||||||
if adt.did() == cx.tcx.parent(vid);
|
if adt.did() == cx.tcx.parent(vid);
|
||||||
then {} else { return false; }
|
then {} else { return false; }
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ pub(crate) trait BindInsteadOfMap {
|
||||||
|
|
||||||
fn is_variant(cx: &LateContext<'_>, res: Res) -> bool {
|
fn is_variant(cx: &LateContext<'_>, res: Res) -> bool {
|
||||||
if let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fn), id) = res {
|
if let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fn), id) = res {
|
||||||
if let Ok(variant_id) = cx.tcx.lang_items().require(Self::VARIANT_LANG_ITEM) {
|
if let Some(variant_id) = cx.tcx.lang_items().get(Self::VARIANT_LANG_ITEM) {
|
||||||
return cx.tcx.parent(id) == variant_id;
|
return cx.tcx.parent(id) == variant_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use clippy_utils::source::snippet_opt;
|
||||||
use clippy_utils::ty::{get_associated_type, get_iterator_item_ty, implements_trait};
|
use clippy_utils::ty::{get_associated_type, get_iterator_item_ty, implements_trait};
|
||||||
use clippy_utils::{fn_def_id, get_parent_expr};
|
use clippy_utils::{fn_def_id, get_parent_expr};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{def_id::DefId, Expr, ExprKind, LangItem};
|
use rustc_hir::{def_id::DefId, Expr, ExprKind};
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_span::{sym, Symbol};
|
use rustc_span::{sym, Symbol};
|
||||||
|
|
||||||
|
@ -100,5 +100,5 @@ pub fn check_for_loop_iter(
|
||||||
|
|
||||||
/// Returns true if the named method is `IntoIterator::into_iter`.
|
/// Returns true if the named method is `IntoIterator::into_iter`.
|
||||||
pub fn is_into_iter(cx: &LateContext<'_>, callee_def_id: DefId) -> bool {
|
pub fn is_into_iter(cx: &LateContext<'_>, callee_def_id: DefId) -> bool {
|
||||||
cx.tcx.lang_items().require(LangItem::IntoIterIntoIter) == Ok(callee_def_id)
|
Some(callee_def_id) == cx.tcx.lang_items().into_iter_fn()
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use clippy_utils::visitors::find_all_ret_expressions;
|
||||||
use clippy_utils::{fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, return_ty};
|
use clippy_utils::{fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, return_ty};
|
||||||
use clippy_utils::{meets_msrv, msrvs};
|
use clippy_utils::{meets_msrv, msrvs};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node};
|
use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, ItemKind, Node};
|
||||||
use rustc_hir_typeck::{FnCtxt, Inherited};
|
use rustc_hir_typeck::{FnCtxt, Inherited};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
|
@ -378,7 +378,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
|
||||||
Node::Expr(parent_expr) => {
|
Node::Expr(parent_expr) => {
|
||||||
if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr)
|
if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr)
|
||||||
{
|
{
|
||||||
if cx.tcx.lang_items().require(LangItem::IntoFutureIntoFuture) == Ok(callee_def_id) {
|
if Some(callee_def_id) == cx.tcx.lang_items().into_future_fn() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub(super) fn check<'tcx>(
|
||||||
let rty = cx.typeck_results().expr_ty(rhs);
|
let rty = cx.typeck_results().expr_ty(rhs);
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let Some((_, lang_item)) = binop_traits(op.node);
|
if let Some((_, lang_item)) = binop_traits(op.node);
|
||||||
if let Ok(trait_id) = cx.tcx.lang_items().require(lang_item);
|
if let Some(trait_id) = cx.tcx.lang_items().get(lang_item);
|
||||||
let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id;
|
let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id;
|
||||||
if trait_ref_of_method(cx, parent_fn)
|
if trait_ref_of_method(cx, parent_fn)
|
||||||
.map_or(true, |t| t.path.res.def_id() != trait_id);
|
.map_or(true, |t| t.path.res.def_id() != trait_id);
|
||||||
|
|
|
@ -60,8 +60,8 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let hir::ExprKind::Binary(binop, _, _) | hir::ExprKind::AssignOp(binop, ..) = expr.kind;
|
if let hir::ExprKind::Binary(binop, _, _) | hir::ExprKind::AssignOp(binop, ..) = expr.kind;
|
||||||
if let Some((binop_trait_lang, op_assign_trait_lang)) = binop_traits(binop.node);
|
if let Some((binop_trait_lang, op_assign_trait_lang)) = binop_traits(binop.node);
|
||||||
if let Ok(binop_trait_id) = cx.tcx.lang_items().require(binop_trait_lang);
|
if let Some(binop_trait_id) = cx.tcx.lang_items().get(binop_trait_lang);
|
||||||
if let Ok(op_assign_trait_id) = cx.tcx.lang_items().require(op_assign_trait_lang);
|
if let Some(op_assign_trait_id) = cx.tcx.lang_items().get(op_assign_trait_lang);
|
||||||
|
|
||||||
// Check for more than one binary operation in the implemented function
|
// Check for more than one binary operation in the implemented function
|
||||||
// Linting when multiple operations are involved can result in false positives
|
// Linting when multiple operations are involved can result in false positives
|
||||||
|
@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl {
|
||||||
(&OP_ASSIGN_TRAITS, SUSPICIOUS_OP_ASSIGN_IMPL),
|
(&OP_ASSIGN_TRAITS, SUSPICIOUS_OP_ASSIGN_IMPL),
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.find(|&(ts, _)| ts.iter().any(|&t| Ok(trait_id) == cx.tcx.lang_items().require(t)));
|
.find(|&(ts, _)| ts.iter().any(|&t| Some(trait_id) == cx.tcx.lang_items().get(t)));
|
||||||
if count_binops(body.value) == 1;
|
if count_binops(body.value) == 1;
|
||||||
then {
|
then {
|
||||||
span_lint(
|
span_lint(
|
||||||
|
|
|
@ -3,7 +3,7 @@ use clippy_utils::{match_def_path, paths};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_ast::ast::LitKind;
|
use rustc_ast::ast::LitKind;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
|
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryOwnedEmptyStrings {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if cx.tcx.lang_items().require(LangItem::FromFrom).ok() == Some(fun_def_id);
|
if Some(fun_def_id) == cx.tcx.lang_items().from_fn();
|
||||||
if let [.., last_arg] = args;
|
if let [.., last_arg] = args;
|
||||||
if let ExprKind::Lit(spanned) = &last_arg.kind;
|
if let ExprKind::Lit(spanned) = &last_arg.kind;
|
||||||
if let LitKind::Str(symbol, _) = spanned.node;
|
if let LitKind::Str(symbol, _) = spanned.node;
|
||||||
|
|
|
@ -3,7 +3,6 @@ use clippy_utils::ty::{match_type, peel_mid_ty_refs_is_mutable};
|
||||||
use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, paths, peel_ref_operators};
|
use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, paths, peel_ref_operators};
|
||||||
use rustc_ast::Mutability;
|
use rustc_ast::Mutability;
|
||||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||||
use rustc_hir::lang_items::LangItem;
|
|
||||||
use rustc_hir::{Block, Expr, ExprKind, HirId, Local, Node, PatKind, PathSegment, StmtKind};
|
use rustc_hir::{Block, Expr, ExprKind, HirId, Local, Node, PatKind, PathSegment, StmtKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::nested_filter::OnlyBodies;
|
use rustc_middle::hir::nested_filter::OnlyBodies;
|
||||||
|
@ -132,11 +131,11 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
|
||||||
// If the Peekable is passed to a function, stop
|
// If the Peekable is passed to a function, stop
|
||||||
ExprKind::Call(_, args) => {
|
ExprKind::Call(_, args) => {
|
||||||
if let Some(func_did) = fn_def_id(self.cx, expr)
|
if let Some(func_did) = fn_def_id(self.cx, expr)
|
||||||
&& let Ok(into_iter_did) = self
|
&& let Some(into_iter_did) = self
|
||||||
.cx
|
.cx
|
||||||
.tcx
|
.tcx
|
||||||
.lang_items()
|
.lang_items()
|
||||||
.require(LangItem::IntoIterIntoIter)
|
.into_iter_fn()
|
||||||
&& func_did == into_iter_did
|
&& func_did == into_iter_did
|
||||||
{
|
{
|
||||||
// Probably a for loop desugar, stop searching
|
// Probably a for loop desugar, stop searching
|
||||||
|
|
|
@ -5,7 +5,7 @@ use clippy_utils::ty::{is_type_diagnostic_item, same_type_and_consts};
|
||||||
use clippy_utils::{get_parent_expr, is_trait_method, match_def_path, paths};
|
use clippy_utils::{get_parent_expr, is_trait_method, match_def_path, paths};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{Expr, ExprKind, HirId, LangItem, MatchSource};
|
use rustc_hir::{Expr, ExprKind, HirId, MatchSource};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
|
@ -153,7 +153,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
|
||||||
}
|
}
|
||||||
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if cx.tcx.lang_items().require(LangItem::FromFrom).ok() == Some(def_id);
|
if Some(def_id) == cx.tcx.lang_items().from_fn();
|
||||||
if same_type_and_consts(a, b);
|
if same_type_and_consts(a, b);
|
||||||
|
|
||||||
then {
|
then {
|
||||||
|
|
|
@ -152,7 +152,7 @@ impl UnnecessaryDefPath {
|
||||||
has_ctor,
|
has_ctor,
|
||||||
),
|
),
|
||||||
(0, Item::LangItem(item)) => (
|
(0, Item::LangItem(item)) => (
|
||||||
format!("{cx_snip}.tcx.lang_items().require(LangItem::{item}).ok() == Some({def_snip})"),
|
format!("{cx_snip}.tcx.lang_items().get(LangItem::{item}) == Some({def_snip})"),
|
||||||
has_ctor,
|
has_ctor,
|
||||||
),
|
),
|
||||||
// match_trait_method
|
// match_trait_method
|
||||||
|
@ -184,7 +184,7 @@ impl UnnecessaryDefPath {
|
||||||
(3, Item::LangItem(item)) => (
|
(3, Item::LangItem(item)) => (
|
||||||
format!(
|
format!(
|
||||||
"path_res({cx_snip}, {def_snip}).opt_def_id()\
|
"path_res({cx_snip}, {def_snip}).opt_def_id()\
|
||||||
.map_or(false, |id| {cx_snip}.tcx.lang_items().require(LangItem::{item}).ok() == Some(id))",
|
.map_or(false, |id| {cx_snip}.tcx.lang_items().get(LangItem::{item}) == Some(id))",
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
|
|
|
@ -247,7 +247,7 @@ pub fn in_constant(cx: &LateContext<'_>, id: HirId) -> bool {
|
||||||
/// For example, use this to check whether a function call or a pattern is `Some(..)`.
|
/// For example, use this to check whether a function call or a pattern is `Some(..)`.
|
||||||
pub fn is_res_lang_ctor(cx: &LateContext<'_>, res: Res, lang_item: LangItem) -> bool {
|
pub fn is_res_lang_ctor(cx: &LateContext<'_>, res: Res, lang_item: LangItem) -> bool {
|
||||||
if let Res::Def(DefKind::Ctor(..), id) = res
|
if let Res::Def(DefKind::Ctor(..), id) = res
|
||||||
&& let Ok(lang_id) = cx.tcx.lang_items().require(lang_item)
|
&& let Some(lang_id) = cx.tcx.lang_items().get(lang_item)
|
||||||
&& let Some(id) = cx.tcx.opt_parent(id)
|
&& let Some(id) = cx.tcx.opt_parent(id)
|
||||||
{
|
{
|
||||||
id == lang_id
|
id == lang_id
|
||||||
|
@ -303,7 +303,7 @@ pub fn is_lang_item_or_ctor(cx: &LateContext<'_>, did: DefId, item: LangItem) ->
|
||||||
_ => did,
|
_ => did,
|
||||||
};
|
};
|
||||||
|
|
||||||
cx.tcx.lang_items().require(item).map_or(false, |id| id == did)
|
cx.tcx.lang_items().get(item) == Some(did)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_unit_expr(expr: &Expr<'_>) -> bool {
|
pub fn is_unit_expr(expr: &Expr<'_>) -> bool {
|
||||||
|
|
|
@ -318,11 +318,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb
|
||||||
/// Returns `false` if the `LangItem` is not defined.
|
/// Returns `false` if the `LangItem` is not defined.
|
||||||
pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool {
|
pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool {
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Adt(adt, _) => cx
|
ty::Adt(adt, _) => cx.tcx.lang_items().get(lang_item) == Some(adt.did()),
|
||||||
.tcx
|
|
||||||
.lang_items()
|
|
||||||
.require(lang_item)
|
|
||||||
.map_or(false, |li| li == adt.did()),
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue