Make diangostic item names consistent
This commit is contained in:
parent
f03eb6bef8
commit
eec856bfbc
123 changed files with 244 additions and 248 deletions
|
@ -966,8 +966,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
let is_option_or_result = parent_self_ty.map_or(false, |def_id| {
|
let is_option_or_result = parent_self_ty.map_or(false, |def_id| {
|
||||||
tcx.is_diagnostic_item(sym::option_type, def_id)
|
tcx.is_diagnostic_item(sym::Option, def_id)
|
||||||
|| tcx.is_diagnostic_item(sym::result_type, def_id)
|
|| tcx.is_diagnostic_item(sym::Result, def_id)
|
||||||
});
|
});
|
||||||
FnSelfUseKind::Normal { self_arg, implicit_into_iter, is_option_or_result }
|
FnSelfUseKind::Normal { self_arg, implicit_into_iter, is_option_or_result }
|
||||||
});
|
});
|
||||||
|
|
|
@ -400,8 +400,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
| ty::Opaque(def_id, _) => def_id,
|
| ty::Opaque(def_id, _) => def_id,
|
||||||
_ => return err,
|
_ => return err,
|
||||||
};
|
};
|
||||||
let is_option = self.infcx.tcx.is_diagnostic_item(sym::option_type, def_id);
|
let is_option = self.infcx.tcx.is_diagnostic_item(sym::Option, def_id);
|
||||||
let is_result = self.infcx.tcx.is_diagnostic_item(sym::result_type, def_id);
|
let is_result = self.infcx.tcx.is_diagnostic_item(sym::Result, def_id);
|
||||||
if (is_option || is_result) && use_spans.map_or(true, |v| !v.for_closure()) {
|
if (is_option || is_result) && use_spans.map_or(true, |v| !v.for_closure()) {
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
span.shrink_to_hi(),
|
span.shrink_to_hi(),
|
||||||
|
|
|
@ -2533,7 +2533,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
/// within `?` desugaring.
|
/// within `?` desugaring.
|
||||||
pub fn is_try_conversion(&self, span: Span, trait_def_id: DefId) -> bool {
|
pub fn is_try_conversion(&self, span: Span, trait_def_id: DefId) -> bool {
|
||||||
span.is_desugaring(DesugaringKind::QuestionMark)
|
span.is_desugaring(DesugaringKind::QuestionMark)
|
||||||
&& self.tcx.is_diagnostic_item(sym::from_trait, trait_def_id)
|
&& self.tcx.is_diagnostic_item(sym::From, trait_def_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -812,7 +812,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
|
||||||
_ => return,
|
_ => return,
|
||||||
}
|
}
|
||||||
|
|
||||||
let debug = match cx.tcx.get_diagnostic_item(sym::debug_trait) {
|
let debug = match cx.tcx.get_diagnostic_item(sym::Debug) {
|
||||||
Some(debug) => debug,
|
Some(debug) => debug,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,9 +33,9 @@ impl LateLintPass<'_> for DefaultHashTypes {
|
||||||
// don't lint imports, only actual usages
|
// don't lint imports, only actual usages
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let replace = if cx.tcx.is_diagnostic_item(sym::hashmap_type, def_id) {
|
let replace = if cx.tcx.is_diagnostic_item(sym::HashMap, def_id) {
|
||||||
"FxHashMap"
|
"FxHashMap"
|
||||||
} else if cx.tcx.is_diagnostic_item(sym::hashset_type, def_id) {
|
} else if cx.tcx.is_diagnostic_item(sym::HashSet, def_id) {
|
||||||
"FxHashSet"
|
"FxHashSet"
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -84,7 +84,7 @@ fn lint_cstring_as_ptr(
|
||||||
) {
|
) {
|
||||||
let source_type = cx.typeck_results().expr_ty(source);
|
let source_type = cx.typeck_results().expr_ty(source);
|
||||||
if let ty::Adt(def, substs) = source_type.kind() {
|
if let ty::Adt(def, substs) = source_type.kind() {
|
||||||
if cx.tcx.is_diagnostic_item(sym::result_type, def.did) {
|
if cx.tcx.is_diagnostic_item(sym::Result, def.did) {
|
||||||
if let ty::Adt(adt, _) = substs.type_at(0).kind() {
|
if let ty::Adt(adt, _) = substs.type_at(0).kind() {
|
||||||
if cx.tcx.is_diagnostic_item(sym::cstring_type, adt.did) {
|
if cx.tcx.is_diagnostic_item(sym::cstring_type, adt.did) {
|
||||||
cx.struct_span_lint(TEMPORARY_CSTRING_AS_PTR, as_ptr_span, |diag| {
|
cx.struct_span_lint(TEMPORARY_CSTRING_AS_PTR, as_ptr_span, |diag| {
|
||||||
|
|
|
@ -130,14 +130,14 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
|
||||||
ty::Ref(_, r, _) if *r.kind() == ty::Str,
|
ty::Ref(_, r, _) if *r.kind() == ty::Str,
|
||||||
) || matches!(
|
) || matches!(
|
||||||
ty.ty_adt_def(),
|
ty.ty_adt_def(),
|
||||||
Some(ty_def) if cx.tcx.is_diagnostic_item(sym::string_type, ty_def.did),
|
Some(ty_def) if cx.tcx.is_diagnostic_item(sym::String, ty_def.did),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (suggest_display, suggest_debug) = cx.tcx.infer_ctxt().enter(|infcx| {
|
let (suggest_display, suggest_debug) = cx.tcx.infer_ctxt().enter(|infcx| {
|
||||||
let display = is_str || cx.tcx.get_diagnostic_item(sym::display_trait).map(|t| {
|
let display = is_str || cx.tcx.get_diagnostic_item(sym::Display).map(|t| {
|
||||||
infcx.type_implements_trait(t, ty, InternalSubsts::empty(), cx.param_env).may_apply()
|
infcx.type_implements_trait(t, ty, InternalSubsts::empty(), cx.param_env).may_apply()
|
||||||
}) == Some(true);
|
}) == Some(true);
|
||||||
let debug = !display && cx.tcx.get_diagnostic_item(sym::debug_trait).map(|t| {
|
let debug = !display && cx.tcx.get_diagnostic_item(sym::Debug).map(|t| {
|
||||||
infcx.type_implements_trait(t, ty, InternalSubsts::empty(), cx.param_env).may_apply()
|
infcx.type_implements_trait(t, ty, InternalSubsts::empty(), cx.param_env).may_apply()
|
||||||
}) == Some(true);
|
}) == Some(true);
|
||||||
(display, debug)
|
(display, debug)
|
||||||
|
|
|
@ -133,7 +133,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> {
|
||||||
/// If the given predicate is the trait `fmt::Pointer`, returns the bound parameter type.
|
/// If the given predicate is the trait `fmt::Pointer`, returns the bound parameter type.
|
||||||
fn is_pointer_trait(&self, bound: &PredicateKind<'tcx>) -> Option<Ty<'tcx>> {
|
fn is_pointer_trait(&self, bound: &PredicateKind<'tcx>) -> Option<Ty<'tcx>> {
|
||||||
if let ty::PredicateKind::Trait(predicate) = bound {
|
if let ty::PredicateKind::Trait(predicate) = bound {
|
||||||
if self.tcx.is_diagnostic_item(sym::pointer_trait, predicate.def_id()) {
|
if self.tcx.is_diagnostic_item(sym::Pointer, predicate.def_id()) {
|
||||||
Some(predicate.trait_ref.self_ty())
|
Some(predicate.trait_ref.self_ty())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -169,6 +169,7 @@ symbols! {
|
||||||
Default,
|
Default,
|
||||||
Deref,
|
Deref,
|
||||||
DirBuilder,
|
DirBuilder,
|
||||||
|
Display,
|
||||||
DoubleEndedIterator,
|
DoubleEndedIterator,
|
||||||
Duration,
|
Duration,
|
||||||
Encodable,
|
Encodable,
|
||||||
|
@ -194,6 +195,7 @@ symbols! {
|
||||||
Hasher,
|
Hasher,
|
||||||
Implied,
|
Implied,
|
||||||
Input,
|
Input,
|
||||||
|
Into,
|
||||||
IntoIterator,
|
IntoIterator,
|
||||||
IoRead,
|
IoRead,
|
||||||
IoWrite,
|
IoWrite,
|
||||||
|
@ -204,6 +206,7 @@ symbols! {
|
||||||
Left,
|
Left,
|
||||||
LinkedList,
|
LinkedList,
|
||||||
LintPass,
|
LintPass,
|
||||||
|
Mutex,
|
||||||
None,
|
None,
|
||||||
Ok,
|
Ok,
|
||||||
Option,
|
Option,
|
||||||
|
@ -219,6 +222,7 @@ symbols! {
|
||||||
PathBuf,
|
PathBuf,
|
||||||
Pending,
|
Pending,
|
||||||
Pin,
|
Pin,
|
||||||
|
Pointer,
|
||||||
Poll,
|
Poll,
|
||||||
ProcMacro,
|
ProcMacro,
|
||||||
ProcMacroHack,
|
ProcMacroHack,
|
||||||
|
@ -242,6 +246,7 @@ symbols! {
|
||||||
Send,
|
Send,
|
||||||
SeqCst,
|
SeqCst,
|
||||||
Some,
|
Some,
|
||||||
|
String,
|
||||||
StructuralEq,
|
StructuralEq,
|
||||||
StructuralPartialEq,
|
StructuralPartialEq,
|
||||||
Sync,
|
Sync,
|
||||||
|
@ -249,12 +254,15 @@ symbols! {
|
||||||
ToOwned,
|
ToOwned,
|
||||||
ToString,
|
ToString,
|
||||||
Try,
|
Try,
|
||||||
|
TryFrom,
|
||||||
|
TryInto,
|
||||||
Ty,
|
Ty,
|
||||||
TyCtxt,
|
TyCtxt,
|
||||||
TyKind,
|
TyKind,
|
||||||
Unknown,
|
Unknown,
|
||||||
UnsafeArg,
|
UnsafeArg,
|
||||||
Vec,
|
Vec,
|
||||||
|
VecDeque,
|
||||||
Yield,
|
Yield,
|
||||||
_DECLS,
|
_DECLS,
|
||||||
_Self,
|
_Self,
|
||||||
|
@ -507,7 +515,6 @@ symbols! {
|
||||||
debug_assert_macro,
|
debug_assert_macro,
|
||||||
debug_assertions,
|
debug_assertions,
|
||||||
debug_struct,
|
debug_struct,
|
||||||
debug_trait,
|
|
||||||
debug_trait_builder,
|
debug_trait_builder,
|
||||||
debug_tuple,
|
debug_tuple,
|
||||||
decl_macro,
|
decl_macro,
|
||||||
|
@ -653,7 +660,6 @@ symbols! {
|
||||||
from_output,
|
from_output,
|
||||||
from_residual,
|
from_residual,
|
||||||
from_size_align_unchecked,
|
from_size_align_unchecked,
|
||||||
from_trait,
|
|
||||||
from_usize,
|
from_usize,
|
||||||
fsub_fast,
|
fsub_fast,
|
||||||
fundamental,
|
fundamental,
|
||||||
|
@ -676,8 +682,6 @@ symbols! {
|
||||||
gt,
|
gt,
|
||||||
half_open_range_patterns,
|
half_open_range_patterns,
|
||||||
hash,
|
hash,
|
||||||
hashmap_type,
|
|
||||||
hashset_type,
|
|
||||||
hexagon_target_feature,
|
hexagon_target_feature,
|
||||||
hidden,
|
hidden,
|
||||||
homogeneous_aggregate,
|
homogeneous_aggregate,
|
||||||
|
@ -722,7 +726,6 @@ symbols! {
|
||||||
instruction_set,
|
instruction_set,
|
||||||
intel,
|
intel,
|
||||||
into_iter,
|
into_iter,
|
||||||
into_trait,
|
|
||||||
intra_doc_pointers,
|
intra_doc_pointers,
|
||||||
intrinsics,
|
intrinsics,
|
||||||
irrefutable_let_patterns,
|
irrefutable_let_patterns,
|
||||||
|
@ -913,7 +916,6 @@ symbols! {
|
||||||
optin_builtin_traits,
|
optin_builtin_traits,
|
||||||
option,
|
option,
|
||||||
option_env,
|
option_env,
|
||||||
option_type,
|
|
||||||
options,
|
options,
|
||||||
or,
|
or,
|
||||||
or_patterns,
|
or_patterns,
|
||||||
|
@ -955,7 +957,6 @@ symbols! {
|
||||||
plugins,
|
plugins,
|
||||||
pointee_trait,
|
pointee_trait,
|
||||||
pointer,
|
pointer,
|
||||||
pointer_trait,
|
|
||||||
pointer_trait_fmt,
|
pointer_trait_fmt,
|
||||||
poll,
|
poll,
|
||||||
position,
|
position,
|
||||||
|
@ -1051,7 +1052,6 @@ symbols! {
|
||||||
repr_transparent,
|
repr_transparent,
|
||||||
residual,
|
residual,
|
||||||
result,
|
result,
|
||||||
result_type,
|
|
||||||
rhs,
|
rhs,
|
||||||
rintf32,
|
rintf32,
|
||||||
rintf64,
|
rintf64,
|
||||||
|
@ -1152,7 +1152,6 @@ symbols! {
|
||||||
self_in_typedefs,
|
self_in_typedefs,
|
||||||
self_struct_ctor,
|
self_struct_ctor,
|
||||||
semitransparent,
|
semitransparent,
|
||||||
send_trait,
|
|
||||||
shl,
|
shl,
|
||||||
shl_assign,
|
shl_assign,
|
||||||
should_panic,
|
should_panic,
|
||||||
|
@ -1262,7 +1261,6 @@ symbols! {
|
||||||
store,
|
store,
|
||||||
str,
|
str,
|
||||||
str_alloc,
|
str_alloc,
|
||||||
string_type,
|
|
||||||
stringify,
|
stringify,
|
||||||
struct_field_attributes,
|
struct_field_attributes,
|
||||||
struct_inherit,
|
struct_inherit,
|
||||||
|
@ -1277,7 +1275,6 @@ symbols! {
|
||||||
suggestion,
|
suggestion,
|
||||||
sym,
|
sym,
|
||||||
sync,
|
sync,
|
||||||
sync_trait,
|
|
||||||
t32,
|
t32,
|
||||||
target_abi,
|
target_abi,
|
||||||
target_arch,
|
target_arch,
|
||||||
|
@ -1323,9 +1320,7 @@ symbols! {
|
||||||
truncf64,
|
truncf64,
|
||||||
try_blocks,
|
try_blocks,
|
||||||
try_from,
|
try_from,
|
||||||
try_from_trait,
|
|
||||||
try_into,
|
try_into,
|
||||||
try_into_trait,
|
|
||||||
try_trait_v2,
|
try_trait_v2,
|
||||||
tt,
|
tt,
|
||||||
tuple,
|
tuple,
|
||||||
|
@ -1397,8 +1392,6 @@ symbols! {
|
||||||
var,
|
var,
|
||||||
variant_count,
|
variant_count,
|
||||||
vec,
|
vec,
|
||||||
vec_type,
|
|
||||||
vecdeque_type,
|
|
||||||
version,
|
version,
|
||||||
vis,
|
vis,
|
||||||
visible_private_types,
|
visible_private_types,
|
||||||
|
|
|
@ -533,9 +533,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
// example).
|
// example).
|
||||||
|
|
||||||
let trait_is_debug =
|
let trait_is_debug =
|
||||||
self.tcx.is_diagnostic_item(sym::debug_trait, trait_ref.def_id());
|
self.tcx.is_diagnostic_item(sym::Debug, trait_ref.def_id());
|
||||||
let trait_is_display =
|
let trait_is_display =
|
||||||
self.tcx.is_diagnostic_item(sym::display_trait, trait_ref.def_id());
|
self.tcx.is_diagnostic_item(sym::Display, trait_ref.def_id());
|
||||||
|
|
||||||
let in_std_macro =
|
let in_std_macro =
|
||||||
match obligation.cause.span.ctxt().outer_expn_data().macro_def_id {
|
match obligation.cause.span.ctxt().outer_expn_data().macro_def_id {
|
||||||
|
|
|
@ -702,7 +702,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
.filter_map(|lang_item| self.tcx.lang_items().require(*lang_item).ok())
|
.filter_map(|lang_item| self.tcx.lang_items().require(*lang_item).ok())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
never_suggest_borrow.push(self.tcx.get_diagnostic_item(sym::send_trait).unwrap());
|
never_suggest_borrow.push(self.tcx.get_diagnostic_item(sym::Send).unwrap());
|
||||||
|
|
||||||
let param_env = obligation.param_env;
|
let param_env = obligation.param_env;
|
||||||
let trait_ref = trait_ref.skip_binder();
|
let trait_ref = trait_ref.skip_binder();
|
||||||
|
@ -1634,8 +1634,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
// Special case the primary error message when send or sync is the trait that was
|
// Special case the primary error message when send or sync is the trait that was
|
||||||
// not implemented.
|
// not implemented.
|
||||||
let is_send = self.tcx.is_diagnostic_item(sym::send_trait, trait_ref.def_id);
|
let is_send = self.tcx.is_diagnostic_item(sym::Send, trait_ref.def_id);
|
||||||
let is_sync = self.tcx.is_diagnostic_item(sym::sync_trait, trait_ref.def_id);
|
let is_sync = self.tcx.is_diagnostic_item(sym::Sync, trait_ref.def_id);
|
||||||
let hir = self.tcx.hir();
|
let hir = self.tcx.hir();
|
||||||
let trait_explanation = if is_send || is_sync {
|
let trait_explanation = if is_send || is_sync {
|
||||||
let (trait_name, trait_verb) =
|
let (trait_name, trait_verb) =
|
||||||
|
|
|
@ -438,7 +438,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||||
let mut label = true;
|
let mut label = true;
|
||||||
// Check `impl From<self.expr_ty> for self.cast_ty {}` for accurate suggestion:
|
// Check `impl From<self.expr_ty> for self.cast_ty {}` for accurate suggestion:
|
||||||
if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr.span) {
|
if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr.span) {
|
||||||
if let Some(from_trait) = fcx.tcx.get_diagnostic_item(sym::from_trait) {
|
if let Some(from_trait) = fcx.tcx.get_diagnostic_item(sym::From) {
|
||||||
let ty = fcx.resolve_vars_if_possible(self.cast_ty);
|
let ty = fcx.resolve_vars_if_possible(self.cast_ty);
|
||||||
// Erase regions to avoid panic in `prove_value` when calling
|
// Erase regions to avoid panic in `prove_value` when calling
|
||||||
// `type_implements_trait`.
|
// `type_implements_trait`.
|
||||||
|
|
|
@ -983,7 +983,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
sym::Copy,
|
sym::Copy,
|
||||||
sym::Hash,
|
sym::Hash,
|
||||||
sym::Default,
|
sym::Default,
|
||||||
sym::debug_trait,
|
sym::Debug,
|
||||||
];
|
];
|
||||||
let mut derives = unsatisfied_predicates
|
let mut derives = unsatisfied_predicates
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -572,7 +572,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
on the left and may require reallocation. This \
|
on the left and may require reallocation. This \
|
||||||
requires ownership of the string on the left";
|
requires ownership of the string on the left";
|
||||||
|
|
||||||
let string_type = self.tcx.get_diagnostic_item(sym::string_type);
|
let string_type = self.tcx.get_diagnostic_item(sym::String);
|
||||||
let is_std_string = |ty: Ty<'tcx>| match ty.ty_adt_def() {
|
let is_std_string = |ty: Ty<'tcx>| match ty.ty_adt_def() {
|
||||||
Some(ty_def) => Some(ty_def.did) == string_type,
|
Some(ty_def) => Some(ty_def.did) == string_type,
|
||||||
None => false,
|
None => false,
|
||||||
|
|
|
@ -126,7 +126,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
{
|
{
|
||||||
match adjusted_ty.kind() {
|
match adjusted_ty.kind() {
|
||||||
ty::Adt(ty::AdtDef { did, .. }, _)
|
ty::Adt(ty::AdtDef { did, .. }, _)
|
||||||
if self.tcx.is_diagnostic_item(sym::vec_type, *did) =>
|
if self.tcx.is_diagnostic_item(sym::Vec, *did) =>
|
||||||
{
|
{
|
||||||
return self.negative_index(adjusted_ty, index_expr.span, base_expr);
|
return self.negative_index(adjusted_ty, index_expr.span, base_expr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -877,7 +877,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let auto_traits_def_id = vec![
|
let auto_traits_def_id = vec![
|
||||||
self.tcx.lang_items().clone_trait(),
|
self.tcx.lang_items().clone_trait(),
|
||||||
self.tcx.lang_items().sync_trait(),
|
self.tcx.lang_items().sync_trait(),
|
||||||
self.tcx.get_diagnostic_item(sym::send_trait),
|
self.tcx.get_diagnostic_item(sym::Send),
|
||||||
self.tcx.lang_items().unpin_trait(),
|
self.tcx.lang_items().unpin_trait(),
|
||||||
self.tcx.get_diagnostic_item(sym::unwind_safe_trait),
|
self.tcx.get_diagnostic_item(sym::unwind_safe_trait),
|
||||||
self.tcx.get_diagnostic_item(sym::ref_unwind_safe_trait),
|
self.tcx.get_diagnostic_item(sym::ref_unwind_safe_trait),
|
||||||
|
|
|
@ -88,7 +88,7 @@ const MAXIMUM_ZST_CAPACITY: usize = 1 << (usize::BITS - 1); // Largest possible
|
||||||
/// [`extend`]: VecDeque::extend
|
/// [`extend`]: VecDeque::extend
|
||||||
/// [`append`]: VecDeque::append
|
/// [`append`]: VecDeque::append
|
||||||
/// [`make_contiguous`]: VecDeque::make_contiguous
|
/// [`make_contiguous`]: VecDeque::make_contiguous
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "vecdeque_type")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "VecDeque")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_insignificant_dtor]
|
#[rustc_insignificant_dtor]
|
||||||
pub struct VecDeque<
|
pub struct VecDeque<
|
||||||
|
|
|
@ -289,7 +289,7 @@ use crate::vec::Vec;
|
||||||
/// [`Deref`]: core::ops::Deref "ops::Deref"
|
/// [`Deref`]: core::ops::Deref "ops::Deref"
|
||||||
/// [`as_str()`]: String::as_str
|
/// [`as_str()`]: String::as_str
|
||||||
#[derive(PartialOrd, Eq, Ord)]
|
#[derive(PartialOrd, Eq, Ord)]
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "string_type")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "String")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct String {
|
pub struct String {
|
||||||
vec: Vec<u8>,
|
vec: Vec<u8>,
|
||||||
|
|
|
@ -395,7 +395,7 @@ mod spec_extend;
|
||||||
/// [`MaybeUninit`]: core::mem::MaybeUninit
|
/// [`MaybeUninit`]: core::mem::MaybeUninit
|
||||||
/// [owned slice]: Box
|
/// [owned slice]: Box
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "vec_type")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "Vec")]
|
||||||
#[rustc_insignificant_dtor]
|
#[rustc_insignificant_dtor]
|
||||||
pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
|
pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
|
||||||
buf: RawVec<T, A>,
|
buf: RawVec<T, A>,
|
||||||
|
|
|
@ -269,7 +269,7 @@ pub trait AsMut<T: ?Sized> {
|
||||||
///
|
///
|
||||||
/// [`String`]: ../../std/string/struct.String.html
|
/// [`String`]: ../../std/string/struct.String.html
|
||||||
/// [`Vec`]: ../../std/vec/struct.Vec.html
|
/// [`Vec`]: ../../std/vec/struct.Vec.html
|
||||||
#[rustc_diagnostic_item = "into_trait"]
|
#[rustc_diagnostic_item = "Into"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub trait Into<T>: Sized {
|
pub trait Into<T>: Sized {
|
||||||
/// Performs the conversion.
|
/// Performs the conversion.
|
||||||
|
@ -358,7 +358,7 @@ pub trait Into<T>: Sized {
|
||||||
/// [`String`]: ../../std/string/struct.String.html
|
/// [`String`]: ../../std/string/struct.String.html
|
||||||
/// [`from`]: From::from
|
/// [`from`]: From::from
|
||||||
/// [book]: ../../book/ch09-00-error-handling.html
|
/// [book]: ../../book/ch09-00-error-handling.html
|
||||||
#[rustc_diagnostic_item = "from_trait"]
|
#[rustc_diagnostic_item = "From"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_on_unimplemented(on(
|
#[rustc_on_unimplemented(on(
|
||||||
all(_Self = "&str", T = "std::string::String"),
|
all(_Self = "&str", T = "std::string::String"),
|
||||||
|
@ -385,7 +385,7 @@ pub trait From<T>: Sized {
|
||||||
///
|
///
|
||||||
/// This suffers the same restrictions and reasoning as implementing
|
/// This suffers the same restrictions and reasoning as implementing
|
||||||
/// [`Into`], see there for details.
|
/// [`Into`], see there for details.
|
||||||
#[rustc_diagnostic_item = "try_into_trait"]
|
#[rustc_diagnostic_item = "TryInto"]
|
||||||
#[stable(feature = "try_from", since = "1.34.0")]
|
#[stable(feature = "try_from", since = "1.34.0")]
|
||||||
pub trait TryInto<T>: Sized {
|
pub trait TryInto<T>: Sized {
|
||||||
/// The type returned in the event of a conversion error.
|
/// The type returned in the event of a conversion error.
|
||||||
|
@ -465,7 +465,7 @@ pub trait TryInto<T>: Sized {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`try_from`]: TryFrom::try_from
|
/// [`try_from`]: TryFrom::try_from
|
||||||
#[rustc_diagnostic_item = "try_from_trait"]
|
#[rustc_diagnostic_item = "TryFrom"]
|
||||||
#[stable(feature = "try_from", since = "1.34.0")]
|
#[stable(feature = "try_from", since = "1.34.0")]
|
||||||
pub trait TryFrom<T>: Sized {
|
pub trait TryFrom<T>: Sized {
|
||||||
/// The type returned in the event of a conversion error.
|
/// The type returned in the event of a conversion error.
|
||||||
|
|
|
@ -617,7 +617,7 @@ impl Display for Arguments<'_> {
|
||||||
label = "`{Self}` cannot be formatted using `{{:?}}` because it doesn't implement `{Debug}`"
|
label = "`{Self}` cannot be formatted using `{{:?}}` because it doesn't implement `{Debug}`"
|
||||||
)]
|
)]
|
||||||
#[doc(alias = "{:?}")]
|
#[doc(alias = "{:?}")]
|
||||||
#[rustc_diagnostic_item = "debug_trait"]
|
#[rustc_diagnostic_item = "Debug"]
|
||||||
#[cfg_attr(not(bootstrap), rustc_trivial_field_reads)]
|
#[cfg_attr(not(bootstrap), rustc_trivial_field_reads)]
|
||||||
pub trait Debug {
|
pub trait Debug {
|
||||||
/// Formats the value using the given formatter.
|
/// Formats the value using the given formatter.
|
||||||
|
@ -710,7 +710,7 @@ pub use macros::Debug;
|
||||||
note = "in format strings you may be able to use `{{:?}}` (or {{:#?}} for pretty-print) instead"
|
note = "in format strings you may be able to use `{{:?}}` (or {{:#?}} for pretty-print) instead"
|
||||||
)]
|
)]
|
||||||
#[doc(alias = "{}")]
|
#[doc(alias = "{}")]
|
||||||
#[rustc_diagnostic_item = "display_trait"]
|
#[rustc_diagnostic_item = "Display"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub trait Display {
|
pub trait Display {
|
||||||
/// Formats the value using the given formatter.
|
/// Formats the value using the given formatter.
|
||||||
|
@ -1003,7 +1003,7 @@ pub trait UpperHex {
|
||||||
/// assert_eq!(&l_ptr[..2], "0x");
|
/// assert_eq!(&l_ptr[..2], "0x");
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_diagnostic_item = "pointer_trait"]
|
#[rustc_diagnostic_item = "Pointer"]
|
||||||
pub trait Pointer {
|
pub trait Pointer {
|
||||||
/// Formats the value using the given formatter.
|
/// Formats the value using the given formatter.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
|
@ -30,7 +30,7 @@ use crate::hash::Hasher;
|
||||||
/// [arc]: ../../std/sync/struct.Arc.html
|
/// [arc]: ../../std/sync/struct.Arc.html
|
||||||
/// [ub]: ../../reference/behavior-considered-undefined.html
|
/// [ub]: ../../reference/behavior-considered-undefined.html
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "send_trait")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "Send")]
|
||||||
#[rustc_on_unimplemented(
|
#[rustc_on_unimplemented(
|
||||||
message = "`{Self}` cannot be sent between threads safely",
|
message = "`{Self}` cannot be sent between threads safely",
|
||||||
label = "`{Self}` cannot be sent between threads safely"
|
label = "`{Self}` cannot be sent between threads safely"
|
||||||
|
@ -459,7 +459,7 @@ pub macro Copy($item:item) {
|
||||||
/// [transmute]: crate::mem::transmute
|
/// [transmute]: crate::mem::transmute
|
||||||
/// [nomicon-send-and-sync]: ../../nomicon/send-and-sync.html
|
/// [nomicon-send-and-sync]: ../../nomicon/send-and-sync.html
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "sync_trait")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "Sync")]
|
||||||
#[lang = "sync"]
|
#[lang = "sync"]
|
||||||
#[rustc_on_unimplemented(
|
#[rustc_on_unimplemented(
|
||||||
message = "`{Self}` cannot be shared between threads safely",
|
message = "`{Self}` cannot be shared between threads safely",
|
||||||
|
|
|
@ -509,7 +509,7 @@ use crate::{
|
||||||
|
|
||||||
/// The `Option` type. See [the module level documentation](self) for more.
|
/// The `Option` type. See [the module level documentation](self) for more.
|
||||||
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
|
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
|
||||||
#[rustc_diagnostic_item = "option_type"]
|
#[rustc_diagnostic_item = "Option"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub enum Option<T> {
|
pub enum Option<T> {
|
||||||
/// No value
|
/// No value
|
||||||
|
|
|
@ -498,7 +498,7 @@ use crate::{convert, fmt, hint};
|
||||||
/// See the [module documentation](self) for details.
|
/// See the [module documentation](self) for details.
|
||||||
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
|
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
|
||||||
#[must_use = "this `Result` may be an `Err` variant, which should be handled"]
|
#[must_use = "this `Result` may be an `Err` variant, which should be handled"]
|
||||||
#[rustc_diagnostic_item = "result_type"]
|
#[rustc_diagnostic_item = "Result"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub enum Result<T, E> {
|
pub enum Result<T, E> {
|
||||||
/// Contains the success value
|
/// Contains the success value
|
||||||
|
|
|
@ -203,7 +203,7 @@ use crate::sys;
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "hashmap_type")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "HashMap")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_insignificant_dtor]
|
#[rustc_insignificant_dtor]
|
||||||
pub struct HashMap<K, V, S = RandomState> {
|
pub struct HashMap<K, V, S = RandomState> {
|
||||||
|
|
|
@ -107,7 +107,7 @@ use super::map::{map_try_reserve_error, RandomState};
|
||||||
/// [`HashMap`]: crate::collections::HashMap
|
/// [`HashMap`]: crate::collections::HashMap
|
||||||
/// [`RefCell`]: crate::cell::RefCell
|
/// [`RefCell`]: crate::cell::RefCell
|
||||||
/// [`Cell`]: crate::cell::Cell
|
/// [`Cell`]: crate::cell::Cell
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "hashset_type")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "HashSet")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct HashSet<T, S = RandomState> {
|
pub struct HashSet<T, S = RandomState> {
|
||||||
base: base::HashSet<T, S>,
|
base: base::HashSet<T, S>,
|
||||||
|
|
|
@ -162,7 +162,7 @@ use crate::sys_common::mutex as sys;
|
||||||
/// assert_eq!(*res_mutex.lock().unwrap(), 800);
|
/// assert_eq!(*res_mutex.lock().unwrap(), 800);
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "mutex_type")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "Mutex")]
|
||||||
pub struct Mutex<T: ?Sized> {
|
pub struct Mutex<T: ?Sized> {
|
||||||
inner: sys::MovableMutex,
|
inner: sys::MovableMutex,
|
||||||
poison: poison::Flag,
|
poison: poison::Flag,
|
||||||
|
|
|
@ -260,8 +260,8 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
|
||||||
},
|
},
|
||||||
ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => {
|
ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => {
|
||||||
let type_of_receiver = cx.typeck_results().expr_ty(&args[0]);
|
let type_of_receiver = cx.typeck_results().expr_ty(&args[0]);
|
||||||
if !is_type_diagnostic_item(cx, type_of_receiver, sym::option_type)
|
if !is_type_diagnostic_item(cx, type_of_receiver, sym::Option)
|
||||||
&& !is_type_diagnostic_item(cx, type_of_receiver, sym::result_type)
|
&& !is_type_diagnostic_item(cx, type_of_receiver, sym::Result)
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: &
|
||||||
return Some(span);
|
return Some(span);
|
||||||
},
|
},
|
||||||
ty::Adt(&ty::AdtDef { did, .. }, _) => {
|
ty::Adt(&ty::AdtDef { did, .. }, _) => {
|
||||||
if ctx.tcx.is_diagnostic_item(sym::string_type, did) {
|
if ctx.tcx.is_diagnostic_item(sym::String, did) {
|
||||||
return Some(span);
|
return Some(span);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -67,7 +67,7 @@ impl CognitiveComplexity {
|
||||||
helper.visit_expr(expr);
|
helper.visit_expr(expr);
|
||||||
let CcHelper { cc, returns } = helper;
|
let CcHelper { cc, returns } = helper;
|
||||||
let ret_ty = cx.typeck_results().node_type(expr.hir_id);
|
let ret_ty = cx.typeck_results().node_type(expr.hir_id);
|
||||||
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::result_type) {
|
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::Result) {
|
||||||
returns
|
returns
|
||||||
} else {
|
} else {
|
||||||
#[allow(clippy::integer_division)]
|
#[allow(clippy::integer_division)]
|
||||||
|
|
|
@ -307,7 +307,7 @@ fn lint_for_missing_headers<'tcx>(
|
||||||
}
|
}
|
||||||
if !headers.errors {
|
if !headers.errors {
|
||||||
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
|
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
|
||||||
if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) {
|
if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::Result) {
|
||||||
span_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
MISSING_ERRORS_DOC,
|
MISSING_ERRORS_DOC,
|
||||||
|
@ -325,7 +325,7 @@ fn lint_for_missing_headers<'tcx>(
|
||||||
if let ty::Opaque(_, subs) = ret_ty.kind();
|
if let ty::Opaque(_, subs) = ret_ty.kind();
|
||||||
if let Some(gen) = subs.types().next();
|
if let Some(gen) = subs.types().next();
|
||||||
if let ty::Generator(_, subs, _) = gen.kind();
|
if let ty::Generator(_, subs, _) = gen.kind();
|
||||||
if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::result_type);
|
if is_type_diagnostic_item(cx, subs.as_generator().return_ty(), sym::Result);
|
||||||
then {
|
then {
|
||||||
span_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
|
@ -760,8 +760,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
|
||||||
// check for `unwrap`
|
// check for `unwrap`
|
||||||
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
|
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
|
||||||
let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs();
|
let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs();
|
||||||
if is_type_diagnostic_item(self.cx, reciever_ty, sym::option_type)
|
if is_type_diagnostic_item(self.cx, reciever_ty, sym::Option)
|
||||||
|| is_type_diagnostic_item(self.cx, reciever_ty, sym::result_type)
|
|| is_type_diagnostic_item(self.cx, reciever_ty, sym::Result)
|
||||||
{
|
{
|
||||||
self.panic_span = Some(expr.span);
|
self.panic_span = Some(expr.span);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
||||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
|
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
|
||||||
if cx.tcx.is_diagnostic_item(sym::from_trait, impl_trait_ref.def_id);
|
if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.def_id);
|
||||||
then {
|
then {
|
||||||
lint_impl_body(cx, item.span, impl_.items);
|
lint_impl_body(cx, item.span, impl_.items);
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,8 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
|
||||||
// check for `unwrap`
|
// check for `unwrap`
|
||||||
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
|
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
|
||||||
let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs();
|
let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs();
|
||||||
if is_type_diagnostic_item(self.lcx, reciever_ty, sym::option_type)
|
if is_type_diagnostic_item(self.lcx, reciever_ty, sym::Option)
|
||||||
|| is_type_diagnostic_item(self.lcx, reciever_ty, sym::result_type)
|
|| is_type_diagnostic_item(self.lcx, reciever_ty, sym::Result)
|
||||||
{
|
{
|
||||||
self.result.push(expr.span);
|
self.result.push(expr.span);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if format_args.format_string_symbols == [kw::Empty];
|
if format_args.format_string_symbols == [kw::Empty];
|
||||||
if match cx.typeck_results().expr_ty(value).peel_refs().kind() {
|
if match cx.typeck_results().expr_ty(value).peel_refs().kind() {
|
||||||
ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::string_type, adt.did),
|
ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::String, adt.did),
|
||||||
ty::Str => true,
|
ty::Str => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl LateLintPass<'_> for FromOverInto {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let hir::ItemKind::Impl{ .. } = &item.kind;
|
if let hir::ItemKind::Impl{ .. } = &item.kind;
|
||||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
|
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
|
||||||
if cx.tcx.is_diagnostic_item(sym::into_trait, impl_trait_ref.def_id);
|
if cx.tcx.is_diagnostic_item(sym::Into, impl_trait_ref.def_id);
|
||||||
|
|
||||||
then {
|
then {
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
|
|
|
@ -98,5 +98,5 @@ impl LateLintPass<'tcx> for FromStrRadix10 {
|
||||||
|
|
||||||
/// Checks if a Ty is `String` or `&str`
|
/// Checks if a Ty is `String` or `&str`
|
||||||
fn is_ty_stringish(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
|
fn is_ty_stringish(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
|
||||||
is_type_diagnostic_item(cx, ty, sym::string_type) || is_type_diagnostic_item(cx, ty, sym::str)
|
is_type_diagnostic_item(cx, ty, sym::String) || is_type_diagnostic_item(cx, ty, sym::str)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ fn check_result_unit_err(cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, item_span
|
||||||
if !in_external_macro(cx.sess(), item_span);
|
if !in_external_macro(cx.sess(), item_span);
|
||||||
if let hir::FnRetTy::Return(ty) = decl.output;
|
if let hir::FnRetTy::Return(ty) = decl.output;
|
||||||
let ty = hir_ty_to_ty(cx.tcx, ty);
|
let ty = hir_ty_to_ty(cx.tcx, ty);
|
||||||
if is_type_diagnostic_item(cx, ty, sym::result_type);
|
if is_type_diagnostic_item(cx, ty, sym::Result);
|
||||||
if let ty::Adt(_, substs) = ty.kind();
|
if let ty::Adt(_, substs) = ty.kind();
|
||||||
let err_ty = substs.type_at(1);
|
let err_ty = substs.type_at(1);
|
||||||
if err_ty.is_unit();
|
if err_ty.is_unit();
|
||||||
|
|
|
@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if is_future {
|
if is_future {
|
||||||
let send_trait = cx.tcx.get_diagnostic_item(sym::send_trait).unwrap();
|
let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap();
|
||||||
let span = decl.output.span();
|
let span = decl.output.span();
|
||||||
let send_result = cx.tcx.infer_ctxt().enter(|infcx| {
|
let send_result = cx.tcx.infer_ctxt().enter(|infcx| {
|
||||||
let cause = traits::ObligationCause::misc(span, hir_id);
|
let cause = traits::ObligationCause::misc(span, hir_id);
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for GetLastWithLen {
|
||||||
// Argument 0 (the struct we're calling the method on) is a vector
|
// Argument 0 (the struct we're calling the method on) is a vector
|
||||||
if let Some(struct_calling_on) = args.get(0);
|
if let Some(struct_calling_on) = args.get(0);
|
||||||
let struct_ty = cx.typeck_results().expr_ty(struct_calling_on);
|
let struct_ty = cx.typeck_results().expr_ty(struct_calling_on);
|
||||||
if is_type_diagnostic_item(cx, struct_ty, sym::vec_type);
|
if is_type_diagnostic_item(cx, struct_ty, sym::Vec);
|
||||||
|
|
||||||
// Argument to "get" is a subtraction
|
// Argument to "get" is a subtraction
|
||||||
if let Some(get_index_arg) = args.get(1);
|
if let Some(get_index_arg) = args.get(1);
|
||||||
|
|
|
@ -8,6 +8,7 @@ use rustc_hir::{Expr, ExprKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
use rustc_span::sym;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// ### What it does
|
/// ### What it does
|
||||||
|
@ -141,7 +142,7 @@ fn is_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Opt
|
||||||
if let ExprKind::MethodCall(path, _span, [self_arg, ..], _) = &expr.kind;
|
if let ExprKind::MethodCall(path, _span, [self_arg, ..], _) = &expr.kind;
|
||||||
if path.ident.as_str() == "lock";
|
if path.ident.as_str() == "lock";
|
||||||
let ty = cx.typeck_results().expr_ty(self_arg);
|
let ty = cx.typeck_results().expr_ty(self_arg);
|
||||||
if is_type_diagnostic_item(cx, ty, sym!(mutex_type));
|
if is_type_diagnostic_item(cx, ty, sym::Mutex);
|
||||||
then {
|
then {
|
||||||
Some(self_arg)
|
Some(self_arg)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -225,14 +225,14 @@ impl<'tcx> ImplicitHasherType<'tcx> {
|
||||||
|
|
||||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||||
|
|
||||||
if is_type_diagnostic_item(cx, ty, sym::hashmap_type) && params_len == 2 {
|
if is_type_diagnostic_item(cx, ty, sym::HashMap) && params_len == 2 {
|
||||||
Some(ImplicitHasherType::HashMap(
|
Some(ImplicitHasherType::HashMap(
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
ty,
|
ty,
|
||||||
snippet(cx, params[0].span, "K"),
|
snippet(cx, params[0].span, "K"),
|
||||||
snippet(cx, params[1].span, "V"),
|
snippet(cx, params[1].span, "V"),
|
||||||
))
|
))
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::hashset_type) && params_len == 1 {
|
} else if is_type_diagnostic_item(cx, ty, sym::HashSet) && params_len == 1 {
|
||||||
Some(ImplicitHasherType::HashSet(
|
Some(ImplicitHasherType::HashSet(
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
ty,
|
ty,
|
||||||
|
@ -347,7 +347,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.cx.tcx.is_diagnostic_item(sym::hashmap_type, ty_did) {
|
if self.cx.tcx.is_diagnostic_item(sym::HashMap, ty_did) {
|
||||||
if method.ident.name == sym::new {
|
if method.ident.name == sym::new {
|
||||||
self.suggestions
|
self.suggestions
|
||||||
.insert(e.span, "HashMap::default()".to_string());
|
.insert(e.span, "HashMap::default()".to_string());
|
||||||
|
@ -360,7 +360,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if self.cx.tcx.is_diagnostic_item(sym::hashset_type, ty_did) {
|
} else if self.cx.tcx.is_diagnostic_item(sym::HashSet, ty_did) {
|
||||||
if method.ident.name == sym::new {
|
if method.ident.name == sym::new {
|
||||||
self.suggestions
|
self.suggestions
|
||||||
.insert(e.span, "HashSet::default()".to_string());
|
.insert(e.span, "HashSet::default()".to_string());
|
||||||
|
|
|
@ -210,11 +210,11 @@ const INFINITE_COLLECTORS: &[Symbol] = &[
|
||||||
sym::BinaryHeap,
|
sym::BinaryHeap,
|
||||||
sym::BTreeMap,
|
sym::BTreeMap,
|
||||||
sym::BTreeSet,
|
sym::BTreeSet,
|
||||||
sym::hashmap_type,
|
sym::HashMap,
|
||||||
sym::hashset_type,
|
sym::HashSet,
|
||||||
sym::LinkedList,
|
sym::LinkedList,
|
||||||
sym::vec_type,
|
sym::Vec,
|
||||||
sym::vecdeque_type,
|
sym::VecDeque,
|
||||||
];
|
];
|
||||||
|
|
||||||
fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
|
fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
|
||||||
|
|
|
@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
|
||||||
if impl_item.generics.params.is_empty();
|
if impl_item.generics.params.is_empty();
|
||||||
|
|
||||||
// Check if return type is String
|
// Check if return type is String
|
||||||
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::string_type);
|
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String);
|
||||||
|
|
||||||
// Filters instances of to_string which are required by a trait
|
// Filters instances of to_string which are required by a trait
|
||||||
if trait_ref_of_method(cx, impl_item.hir_id()).is_none();
|
if trait_ref_of_method(cx, impl_item.hir_id()).is_none();
|
||||||
|
|
|
@ -245,10 +245,10 @@ enum LenOutput<'tcx> {
|
||||||
fn parse_len_output(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option<LenOutput<'tcx>> {
|
fn parse_len_output(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option<LenOutput<'tcx>> {
|
||||||
match *sig.output().kind() {
|
match *sig.output().kind() {
|
||||||
ty::Int(_) | ty::Uint(_) => Some(LenOutput::Integral),
|
ty::Int(_) | ty::Uint(_) => Some(LenOutput::Integral),
|
||||||
ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::option_type, adt.did) => {
|
ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Option, adt.did) => {
|
||||||
subs.type_at(0).is_integral().then(|| LenOutput::Option(adt.did))
|
subs.type_at(0).is_integral().then(|| LenOutput::Option(adt.did))
|
||||||
},
|
},
|
||||||
ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::result_type, adt.did) => subs
|
ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Result, adt.did) => subs
|
||||||
.type_at(0)
|
.type_at(0)
|
||||||
.is_integral()
|
.is_integral()
|
||||||
.then(|| LenOutput::Result(adt.did, subs.type_at(1))),
|
.then(|| LenOutput::Result(adt.did, subs.type_at(1))),
|
||||||
|
|
|
@ -54,11 +54,11 @@ fn is_ref_iterable_type(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||||
// will allow further borrows afterwards
|
// will allow further borrows afterwards
|
||||||
let ty = cx.typeck_results().expr_ty(e);
|
let ty = cx.typeck_results().expr_ty(e);
|
||||||
is_iterable_array(ty, cx) ||
|
is_iterable_array(ty, cx) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
is_type_diagnostic_item(cx, ty, sym::Vec) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::LinkedList) ||
|
is_type_diagnostic_item(cx, ty, sym::LinkedList) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::hashmap_type) ||
|
is_type_diagnostic_item(cx, ty, sym::HashMap) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::hashset_type) ||
|
is_type_diagnostic_item(cx, ty, sym::HashSet) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::vecdeque_type) ||
|
is_type_diagnostic_item(cx, ty, sym::VecDeque) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::BinaryHeap) ||
|
is_type_diagnostic_item(cx, ty, sym::BinaryHeap) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::BTreeMap) ||
|
is_type_diagnostic_item(cx, ty, sym::BTreeMap) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::BTreeSet)
|
is_type_diagnostic_item(cx, ty, sym::BTreeSet)
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx
|
||||||
_ => arg,
|
_ => arg,
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_type_diagnostic_item(cx, ty, sym::hashmap_type) || is_type_diagnostic_item(cx, ty, sym::BTreeMap) {
|
if is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap) {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
FOR_KV_MAP,
|
FOR_KV_MAP,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use rustc_span::symbol::sym;
|
||||||
/// Checks for `for` loops over `Option`s and `Result`s.
|
/// Checks for `for` loops over `Option`s and `Result`s.
|
||||||
pub(super) fn check(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
|
pub(super) fn check(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
|
||||||
let ty = cx.typeck_results().expr_ty(arg);
|
let ty = cx.typeck_results().expr_ty(arg);
|
||||||
if is_type_diagnostic_item(cx, ty, sym::option_type) {
|
if is_type_diagnostic_item(cx, ty, sym::Option) {
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
FOR_LOOPS_OVER_FALLIBLES,
|
FOR_LOOPS_OVER_FALLIBLES,
|
||||||
|
@ -26,7 +26,7 @@ pub(super) fn check(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
|
||||||
snippet(cx, arg.span, "_")
|
snippet(cx, arg.span, "_")
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::result_type) {
|
} else if is_type_diagnostic_item(cx, ty, sym::Result) {
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
FOR_LOOPS_OVER_FALLIBLES,
|
FOR_LOOPS_OVER_FALLIBLES,
|
||||||
|
|
|
@ -332,7 +332,7 @@ fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'_>) -> bool {
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
is_slice || is_type_diagnostic_item(cx, ty, sym::vec_type) || is_type_diagnostic_item(cx, ty, sym::vecdeque_type)
|
is_slice || is_type_diagnostic_item(cx, ty, sym::Vec) || is_type_diagnostic_item(cx, ty, sym::VecDeque)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
|
fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
|
||||||
|
|
|
@ -29,8 +29,8 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
|
||||||
let mut applicability = Applicability::MaybeIncorrect;
|
let mut applicability = Applicability::MaybeIncorrect;
|
||||||
let is_empty_sugg = "next().is_none()".to_string();
|
let is_empty_sugg = "next().is_none()".to_string();
|
||||||
let method_name = &*method.ident.name.as_str();
|
let method_name = &*method.ident.name.as_str();
|
||||||
let sugg = if is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
let sugg = if is_type_diagnostic_item(cx, ty, sym::Vec) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::vecdeque_type) ||
|
is_type_diagnostic_item(cx, ty, sym::VecDeque) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::LinkedList) ||
|
is_type_diagnostic_item(cx, ty, sym::LinkedList) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::BinaryHeap) {
|
is_type_diagnostic_item(cx, ty, sym::BinaryHeap) {
|
||||||
match method_name {
|
match method_name {
|
||||||
|
@ -47,7 +47,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if is_type_diagnostic_item(cx, ty, sym::BTreeMap) ||
|
else if is_type_diagnostic_item(cx, ty, sym::BTreeMap) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::hashmap_type) {
|
is_type_diagnostic_item(cx, ty, sym::HashMap) {
|
||||||
match method_name {
|
match method_name {
|
||||||
"is_empty" => is_empty_sugg,
|
"is_empty" => is_empty_sugg,
|
||||||
_ => return,
|
_ => return,
|
||||||
|
@ -79,8 +79,8 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo
|
||||||
if let ExprKind::MethodCall(method_name, collect_span, &[ref iter_source], ..) = init_expr.kind;
|
if let ExprKind::MethodCall(method_name, collect_span, &[ref iter_source], ..) = init_expr.kind;
|
||||||
if method_name.ident.name == sym!(collect) && is_trait_method(cx, init_expr, sym::Iterator);
|
if method_name.ident.name == sym!(collect) && is_trait_method(cx, init_expr, sym::Iterator);
|
||||||
let ty = cx.typeck_results().expr_ty(init_expr);
|
let ty = cx.typeck_results().expr_ty(init_expr);
|
||||||
if is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
if is_type_diagnostic_item(cx, ty, sym::Vec) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::vecdeque_type) ||
|
is_type_diagnostic_item(cx, ty, sym::VecDeque) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::BinaryHeap) ||
|
is_type_diagnostic_item(cx, ty, sym::BinaryHeap) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym::LinkedList);
|
is_type_diagnostic_item(cx, ty, sym::LinkedList);
|
||||||
if let Some(iter_calls) = detect_iter_and_into_iters(block, id);
|
if let Some(iter_calls) = detect_iter_and_into_iters(block, id);
|
||||||
|
|
|
@ -192,7 +192,7 @@ fn get_vec_push<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) -> Option<(&
|
||||||
if let Some(self_expr) = args.get(0);
|
if let Some(self_expr) = args.get(0);
|
||||||
if let Some(pushed_item) = args.get(1);
|
if let Some(pushed_item) = args.get(1);
|
||||||
// Check that the method being called is push() on a Vec
|
// Check that the method being called is push() on a Vec
|
||||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(self_expr), sym::vec_type);
|
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(self_expr), sym::Vec);
|
||||||
if path.ident.name.as_str() == "push";
|
if path.ident.name.as_str() == "push";
|
||||||
then {
|
then {
|
||||||
return Some((self_expr, pushed_item))
|
return Some((self_expr, pushed_item))
|
||||||
|
|
|
@ -61,8 +61,8 @@ impl LateLintPass<'_> for ManualMap {
|
||||||
|
|
||||||
let (scrutinee_ty, ty_ref_count, ty_mutability) =
|
let (scrutinee_ty, ty_ref_count, ty_mutability) =
|
||||||
peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrutinee));
|
peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrutinee));
|
||||||
if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::option_type)
|
if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::Option)
|
||||||
&& is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::option_type))
|
&& is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Option))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl LateLintPass<'_> for ManualOkOr {
|
||||||
if args.len() == 3;
|
if args.len() == 3;
|
||||||
let method_receiver = &args[0];
|
let method_receiver = &args[0];
|
||||||
let ty = cx.typeck_results().expr_ty(method_receiver);
|
let ty = cx.typeck_results().expr_ty(method_receiver);
|
||||||
if is_type_diagnostic_item(cx, ty, sym::option_type);
|
if is_type_diagnostic_item(cx, ty, sym::Option);
|
||||||
let or_expr = &args[1];
|
let or_expr = &args[1];
|
||||||
if is_ok_wrapping(cx, &args[2]);
|
if is_ok_wrapping(cx, &args[2]);
|
||||||
if let ExprKind::Call(Expr { kind: ExprKind::Path(err_path), .. }, &[ref err_arg]) = or_expr.kind;
|
if let ExprKind::Call(Expr { kind: ExprKind::Path(err_path), .. }, &[ref err_arg]) = or_expr.kind;
|
||||||
|
|
|
@ -82,9 +82,9 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Match(scrutinee, match_arms, _) = expr.kind;
|
if let ExprKind::Match(scrutinee, match_arms, _) = expr.kind;
|
||||||
let ty = cx.typeck_results().expr_ty(scrutinee);
|
let ty = cx.typeck_results().expr_ty(scrutinee);
|
||||||
if let Some(ty_name) = if is_type_diagnostic_item(cx, ty, sym::option_type) {
|
if let Some(ty_name) = if is_type_diagnostic_item(cx, ty, sym::Option) {
|
||||||
Some("Option")
|
Some("Option")
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::result_type) {
|
} else if is_type_diagnostic_item(cx, ty, sym::Result) {
|
||||||
Some("Result")
|
Some("Result")
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
|
||||||
if args.len() == 2;
|
if args.len() == 2;
|
||||||
if method.ident.name == sym::map;
|
if method.ident.name == sym::map;
|
||||||
let ty = cx.typeck_results().expr_ty(&args[0]);
|
let ty = cx.typeck_results().expr_ty(&args[0]);
|
||||||
if is_type_diagnostic_item(cx, ty, sym::option_type) || is_trait_method(cx, e, sym::Iterator);
|
if is_type_diagnostic_item(cx, ty, sym::Option) || is_trait_method(cx, e, sym::Iterator);
|
||||||
if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind;
|
if let hir::ExprKind::Closure(_, _, body_id, _, _) = args[1].kind;
|
||||||
then {
|
then {
|
||||||
let closure_body = cx.tcx.hir().body(body_id);
|
let closure_body = cx.tcx.hir().body(body_id);
|
||||||
|
|
|
@ -206,9 +206,9 @@ fn lint_map_unit_fn(cx: &LateContext<'_>, stmt: &hir::Stmt<'_>, expr: &hir::Expr
|
||||||
let var_arg = &map_args[0];
|
let var_arg = &map_args[0];
|
||||||
|
|
||||||
let (map_type, variant, lint) =
|
let (map_type, variant, lint) =
|
||||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::option_type) {
|
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::Option) {
|
||||||
("Option", "Some", OPTION_MAP_UNIT_FN)
|
("Option", "Some", OPTION_MAP_UNIT_FN)
|
||||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::result_type) {
|
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(var_arg), sym::Result) {
|
||||||
("Result", "Ok", RESULT_MAP_UNIT_FN)
|
("Result", "Ok", RESULT_MAP_UNIT_FN)
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -93,7 +93,7 @@ fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Opti
|
||||||
fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
fn is_vector(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||||
let ty = cx.typeck_results().expr_ty(expr);
|
let ty = cx.typeck_results().expr_ty(expr);
|
||||||
let ty = ty.peel_refs();
|
let ty = ty.peel_refs();
|
||||||
is_type_diagnostic_item(cx, ty, sym::vec_type)
|
is_type_diagnostic_item(cx, ty, sym::Vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
fn is_full_range(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchResultOk {
|
||||||
if let ExprKind::MethodCall(_, ok_span, [ref result_types_0, ..], _) = let_expr.kind; //check is expr.ok() has type Result<T,E>.ok(, _)
|
if let ExprKind::MethodCall(_, ok_span, [ref result_types_0, ..], _) = let_expr.kind; //check is expr.ok() has type Result<T,E>.ok(, _)
|
||||||
if let PatKind::TupleStruct(QPath::Resolved(_, x), y, _) = let_pat.kind; //get operation
|
if let PatKind::TupleStruct(QPath::Resolved(_, x), y, _) = let_pat.kind; //get operation
|
||||||
if method_chain_args(let_expr, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized;
|
if method_chain_args(let_expr, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized;
|
||||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(result_types_0), sym::result_type);
|
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(result_types_0), sym::Result);
|
||||||
if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some";
|
if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some";
|
||||||
|
|
||||||
then {
|
then {
|
||||||
|
|
|
@ -948,7 +948,7 @@ fn check_overlapping_arms<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms
|
||||||
|
|
||||||
fn check_wild_err_arm<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm<'tcx>]) {
|
fn check_wild_err_arm<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm<'tcx>]) {
|
||||||
let ex_ty = cx.typeck_results().expr_ty(ex).peel_refs();
|
let ex_ty = cx.typeck_results().expr_ty(ex).peel_refs();
|
||||||
if is_type_diagnostic_item(cx, ex_ty, sym::result_type) {
|
if is_type_diagnostic_item(cx, ex_ty, sym::Result) {
|
||||||
for arm in arms {
|
for arm in arms {
|
||||||
if let PatKind::TupleStruct(ref path, inner, _) = arm.pat.kind {
|
if let PatKind::TupleStruct(ref path, inner, _) = arm.pat.kind {
|
||||||
let path_str = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false));
|
let path_str = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false));
|
||||||
|
@ -1025,8 +1025,8 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
|
||||||
let adt_def = match ty.kind() {
|
let adt_def = match ty.kind() {
|
||||||
ty::Adt(adt_def, _)
|
ty::Adt(adt_def, _)
|
||||||
if adt_def.is_enum()
|
if adt_def.is_enum()
|
||||||
&& !(is_type_diagnostic_item(cx, ty, sym::option_type)
|
&& !(is_type_diagnostic_item(cx, ty, sym::Option)
|
||||||
|| is_type_diagnostic_item(cx, ty, sym::result_type)) =>
|
|| is_type_diagnostic_item(cx, ty, sym::Result)) =>
|
||||||
{
|
{
|
||||||
adt_def
|
adt_def
|
||||||
},
|
},
|
||||||
|
@ -1869,7 +1869,7 @@ mod redundant_pattern_match {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for std types which implement drop, but only for memory allocation.
|
// Check for std types which implement drop, but only for memory allocation.
|
||||||
else if is_type_diagnostic_item(cx, ty, sym::vec_type)
|
else if is_type_diagnostic_item(cx, ty, sym::Vec)
|
||||||
|| is_type_lang_item(cx, ty, LangItem::OwnedBox)
|
|| is_type_lang_item(cx, ty, LangItem::OwnedBox)
|
||||||
|| is_type_diagnostic_item(cx, ty, sym::Rc)
|
|| is_type_diagnostic_item(cx, ty, sym::Rc)
|
||||||
|| is_type_diagnostic_item(cx, ty, sym::Arc)
|
|| is_type_diagnostic_item(cx, ty, sym::Arc)
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx E
|
||||||
let ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
let ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
||||||
let caller_type = if ty.is_str() {
|
let caller_type = if ty.is_str() {
|
||||||
"str"
|
"str"
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::string_type) {
|
} else if is_type_diagnostic_item(cx, ty, sym::String) {
|
||||||
"String"
|
"String"
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span,
|
||||||
let inner_ty = match recv_ty.kind() {
|
let inner_ty = match recv_ty.kind() {
|
||||||
// `Option<T>` -> `T`
|
// `Option<T>` -> `T`
|
||||||
ty::Adt(adt, subst)
|
ty::Adt(adt, subst)
|
||||||
if cx.tcx.is_diagnostic_item(sym::option_type, adt.did) && meets_msrv(msrv, &msrvs::OPTION_COPIED) =>
|
if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && meets_msrv(msrv, &msrvs::OPTION_COPIED) =>
|
||||||
{
|
{
|
||||||
subst.type_at(0)
|
subst.type_at(0)
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Spa
|
||||||
&& {
|
&& {
|
||||||
let arg_type = cx.typeck_results().expr_ty(&call_args[0]);
|
let arg_type = cx.typeck_results().expr_ty(&call_args[0]);
|
||||||
let base_type = arg_type.peel_refs();
|
let base_type = arg_type.peel_refs();
|
||||||
*base_type.kind() == ty::Str || is_type_diagnostic_item(cx, base_type, sym::string_type)
|
*base_type.kind() == ty::Str || is_type_diagnostic_item(cx, base_type, sym::String)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
&call_args[0]
|
&call_args[0]
|
||||||
|
@ -46,7 +46,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Spa
|
||||||
// converted to string.
|
// converted to string.
|
||||||
fn requires_to_string(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool {
|
fn requires_to_string(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool {
|
||||||
let arg_ty = cx.typeck_results().expr_ty(arg);
|
let arg_ty = cx.typeck_results().expr_ty(arg);
|
||||||
if is_type_diagnostic_item(cx, arg_ty, sym::string_type) {
|
if is_type_diagnostic_item(cx, arg_ty, sym::String) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if let ty::Ref(_, ty, ..) = arg_ty.kind() {
|
if let ty::Ref(_, ty, ..) = arg_ty.kind() {
|
||||||
|
@ -113,9 +113,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Spa
|
||||||
}
|
}
|
||||||
|
|
||||||
let receiver_type = cx.typeck_results().expr_ty_adjusted(&args[0]);
|
let receiver_type = cx.typeck_results().expr_ty_adjusted(&args[0]);
|
||||||
let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym::option_type) {
|
let closure_args = if is_type_diagnostic_item(cx, receiver_type, sym::Option) {
|
||||||
"||"
|
"||"
|
||||||
} else if is_type_diagnostic_item(cx, receiver_type, sym::result_type) {
|
} else if is_type_diagnostic_item(cx, receiver_type, sym::Result) {
|
||||||
"|_|"
|
"|_|"
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -10,9 +10,9 @@ use super::EXPECT_USED;
|
||||||
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
|
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
|
||||||
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
||||||
|
|
||||||
let mess = if is_type_diagnostic_item(cx, obj_ty, sym::option_type) {
|
let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) {
|
||||||
Some((EXPECT_USED, "an Option", "None"))
|
Some((EXPECT_USED, "an Option", "None"))
|
||||||
} else if is_type_diagnostic_item(cx, obj_ty, sym::result_type) {
|
} else if is_type_diagnostic_item(cx, obj_ty, sym::Result) {
|
||||||
Some((EXPECT_USED, "a Result", "Err"))
|
Some((EXPECT_USED, "a Result", "Err"))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -12,7 +12,7 @@ use super::EXTEND_WITH_DRAIN;
|
||||||
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<'_>) {
|
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<'_>) {
|
||||||
let ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
let ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if is_type_diagnostic_item(cx, ty, sym::vec_type);
|
if is_type_diagnostic_item(cx, ty, sym::Vec);
|
||||||
//check source object
|
//check source object
|
||||||
if let ExprKind::MethodCall(src_method, _, [drain_vec, drain_arg], _) = &arg.kind;
|
if let ExprKind::MethodCall(src_method, _, [drain_vec, drain_arg], _) = &arg.kind;
|
||||||
if src_method.ident.as_str() == "drain";
|
if src_method.ident.as_str() == "drain";
|
||||||
|
@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg:
|
||||||
//check if actual src type is mutable for code suggestion
|
//check if actual src type is mutable for code suggestion
|
||||||
let immutable = src_ty.is_mutable_ptr();
|
let immutable = src_ty.is_mutable_ptr();
|
||||||
let src_ty = src_ty.peel_refs();
|
let src_ty = src_ty.peel_refs();
|
||||||
if is_type_diagnostic_item(cx, src_ty, sym::vec_type);
|
if is_type_diagnostic_item(cx, src_ty, sym::Vec);
|
||||||
//check drain range
|
//check drain range
|
||||||
if let src_ty_range = cx.typeck_results().expr_ty(drain_arg).peel_refs();
|
if let src_ty_range = cx.typeck_results().expr_ty(drain_arg).peel_refs();
|
||||||
if is_type_lang_item(cx, src_ty_range, LangItem::RangeFull);
|
if is_type_lang_item(cx, src_ty_range, LangItem::RangeFull);
|
||||||
|
|
|
@ -61,7 +61,7 @@ fn lint_filter_some_map_unwrap(
|
||||||
methods_span: Span,
|
methods_span: Span,
|
||||||
) {
|
) {
|
||||||
let iterator = is_trait_method(cx, expr, sym::Iterator);
|
let iterator = is_trait_method(cx, expr, sym::Iterator);
|
||||||
let option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(filter_recv), sym::option_type);
|
let option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(filter_recv), sym::Option);
|
||||||
if (iterator || option) && is_option_filter_map(cx, filter_arg, map_arg) {
|
if (iterator || option) && is_option_filter_map(cx, filter_arg, map_arg) {
|
||||||
let msg = "`filter` for `Some` followed by `unwrap`";
|
let msg = "`filter` for `Some` followed by `unwrap`";
|
||||||
let help = "consider using `flatten` instead";
|
let help = "consider using `flatten` instead";
|
||||||
|
@ -120,9 +120,9 @@ pub(super) fn check<'tcx>(
|
||||||
if let PatKind::Binding(_, filter_param_id, _, None) = filter_pat.kind;
|
if let PatKind::Binding(_, filter_param_id, _, None) = filter_pat.kind;
|
||||||
if let ExprKind::MethodCall(path, _, [filter_arg], _) = filter_body.value.kind;
|
if let ExprKind::MethodCall(path, _, [filter_arg], _) = filter_body.value.kind;
|
||||||
if let Some(opt_ty) = cx.typeck_results().expr_ty(filter_arg).ty_adt_def();
|
if let Some(opt_ty) = cx.typeck_results().expr_ty(filter_arg).ty_adt_def();
|
||||||
if let Some(is_result) = if cx.tcx.is_diagnostic_item(sym::option_type, opt_ty.did) {
|
if let Some(is_result) = if cx.tcx.is_diagnostic_item(sym::Option, opt_ty.did) {
|
||||||
Some(false)
|
Some(false)
|
||||||
} else if cx.tcx.is_diagnostic_item(sym::result_type, opt_ty.did) {
|
} else if cx.tcx.is_diagnostic_item(sym::Result, opt_ty.did) {
|
||||||
Some(true)
|
Some(true)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, arg
|
||||||
_ if arg_ty.is_fn() => arg_ty.fn_sig(cx.tcx),
|
_ if arg_ty.is_fn() => arg_ty.fn_sig(cx.tcx),
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
if !is_type_diagnostic_item(cx, sig.output().skip_binder(), sym::option_type) {
|
if !is_type_diagnostic_item(cx, sig.output().skip_binder(), sym::Option) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
|
|
|
@ -27,13 +27,13 @@ pub(super) fn check<'tcx>(
|
||||||
let caller_type = if derefs_to_slice(cx, recv, expr_ty).is_some() {
|
let caller_type = if derefs_to_slice(cx, recv, expr_ty).is_some() {
|
||||||
needs_ref = get_args_str.parse::<usize>().is_ok();
|
needs_ref = get_args_str.parse::<usize>().is_ok();
|
||||||
"slice"
|
"slice"
|
||||||
} else if is_type_diagnostic_item(cx, expr_ty, sym::vec_type) {
|
} else if is_type_diagnostic_item(cx, expr_ty, sym::Vec) {
|
||||||
needs_ref = get_args_str.parse::<usize>().is_ok();
|
needs_ref = get_args_str.parse::<usize>().is_ok();
|
||||||
"Vec"
|
"Vec"
|
||||||
} else if is_type_diagnostic_item(cx, expr_ty, sym::vecdeque_type) {
|
} else if is_type_diagnostic_item(cx, expr_ty, sym::VecDeque) {
|
||||||
needs_ref = get_args_str.parse::<usize>().is_ok();
|
needs_ref = get_args_str.parse::<usize>().is_ok();
|
||||||
"VecDeque"
|
"VecDeque"
|
||||||
} else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym::hashmap_type) {
|
} else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym::HashMap) {
|
||||||
needs_ref = true;
|
needs_ref = true;
|
||||||
"HashMap"
|
"HashMap"
|
||||||
} else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym::BTreeMap) {
|
} else if !is_mut && is_type_diagnostic_item(cx, expr_ty, sym::BTreeMap) {
|
||||||
|
|
|
@ -55,7 +55,7 @@ fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_type_diagnostic_item(cx, ty, sym::string_type) {
|
if is_type_diagnostic_item(cx, ty, sym::String) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ use super::ITER_CLONED_COLLECT;
|
||||||
|
|
||||||
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, recv: &'tcx hir::Expr<'_>) {
|
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, recv: &'tcx hir::Expr<'_>) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::vec_type);
|
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Vec);
|
||||||
if let Some(slice) = derefs_to_slice(cx, recv, cx.typeck_results().expr_ty(recv));
|
if let Some(slice) = derefs_to_slice(cx, recv, cx.typeck_results().expr_ty(recv));
|
||||||
if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite());
|
if let Some(to_replace) = expr.span.trim_start(slice.span.source_callsite());
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,13 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx E
|
||||||
let ty = cx.typeck_results().expr_ty(recv);
|
let ty = cx.typeck_results().expr_ty(recv);
|
||||||
let caller_type = if derefs_to_slice(cx, recv, ty).is_some() {
|
let caller_type = if derefs_to_slice(cx, recv, ty).is_some() {
|
||||||
"slice"
|
"slice"
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::vec_type) {
|
} else if is_type_diagnostic_item(cx, ty, sym::Vec) {
|
||||||
"Vec"
|
"Vec"
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::vecdeque_type) {
|
} else if is_type_diagnostic_item(cx, ty, sym::VecDeque) {
|
||||||
"VecDeque"
|
"VecDeque"
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::hashset_type) {
|
} else if is_type_diagnostic_item(cx, ty, sym::HashSet) {
|
||||||
"HashSet"
|
"HashSet"
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::hashmap_type) {
|
} else if is_type_diagnostic_item(cx, ty, sym::HashMap) {
|
||||||
"HashMap"
|
"HashMap"
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::BTreeMap) {
|
} else if is_type_diagnostic_item(cx, ty, sym::BTreeMap) {
|
||||||
"BTreeMap"
|
"BTreeMap"
|
||||||
|
|
|
@ -64,6 +64,6 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, cal
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_vec_or_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) -> bool {
|
fn is_vec_or_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) -> bool {
|
||||||
is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::vec_type)
|
is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Vec)
|
||||||
|| matches!(&cx.typeck_results().expr_ty(expr).peel_refs().kind(), ty::Array(_, _))
|
|| matches!(&cx.typeck_results().expr_ty(expr).peel_refs().kind(), ty::Array(_, _))
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,9 @@ pub(super) fn check<'tcx>(
|
||||||
let mut_str = if is_mut { "_mut" } else { "" };
|
let mut_str = if is_mut { "_mut" } else { "" };
|
||||||
let caller_type = if derefs_to_slice(cx, iter_recv, cx.typeck_results().expr_ty(iter_recv)).is_some() {
|
let caller_type = if derefs_to_slice(cx, iter_recv, cx.typeck_results().expr_ty(iter_recv)).is_some() {
|
||||||
"slice"
|
"slice"
|
||||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(iter_recv), sym::vec_type) {
|
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(iter_recv), sym::Vec) {
|
||||||
"Vec"
|
"Vec"
|
||||||
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(iter_recv), sym::vecdeque_type) {
|
} else if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(iter_recv), sym::VecDeque) {
|
||||||
"VecDeque"
|
"VecDeque"
|
||||||
} else {
|
} else {
|
||||||
iter_nth_zero::check(cx, expr, nth_recv, nth_arg);
|
iter_nth_zero::check(cx, expr, nth_recv, nth_arg);
|
||||||
|
|
|
@ -123,7 +123,7 @@ fn parse_iter_usage(
|
||||||
return if_chain! {
|
return if_chain! {
|
||||||
if match_def_path(cx, did, &paths::ITERTOOLS_NEXT_TUPLE);
|
if match_def_path(cx, did, &paths::ITERTOOLS_NEXT_TUPLE);
|
||||||
if let ty::Adt(adt_def, subs) = cx.typeck_results().expr_ty(e).kind();
|
if let ty::Adt(adt_def, subs) = cx.typeck_results().expr_ty(e).kind();
|
||||||
if cx.tcx.is_diagnostic_item(sym::option_type, adt_def.did);
|
if cx.tcx.is_diagnostic_item(sym::Option, adt_def.did);
|
||||||
if let ty::Tuple(subs) = subs.type_at(0).kind();
|
if let ty::Tuple(subs) = subs.type_at(0).kind();
|
||||||
if subs.len() == 2;
|
if subs.len() == 2;
|
||||||
then {
|
then {
|
||||||
|
@ -193,7 +193,7 @@ fn parse_iter_usage(
|
||||||
&& cx
|
&& cx
|
||||||
.typeck_results()
|
.typeck_results()
|
||||||
.type_dependent_def_id(e.hir_id)
|
.type_dependent_def_id(e.hir_id)
|
||||||
.map_or(false, |id| is_diag_item_method(cx, id, sym::option_type)) =>
|
.map_or(false, |id| is_diag_item_method(cx, id, sym::Option)) =>
|
||||||
{
|
{
|
||||||
(Some(UnwrapKind::Unwrap), e.span)
|
(Some(UnwrapKind::Unwrap), e.span)
|
||||||
},
|
},
|
||||||
|
|
|
@ -36,14 +36,14 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option<RepeatKind> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let ty = cx.typeck_results().expr_ty(e);
|
let ty = cx.typeck_results().expr_ty(e);
|
||||||
if is_type_diagnostic_item(cx, ty, sym::string_type)
|
if is_type_diagnostic_item(cx, ty, sym::String)
|
||||||
|| (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).map_or(false, TyS::is_str))
|
|| (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).map_or(false, TyS::is_str))
|
||||||
|| (match_type(cx, ty, &paths::COW) && get_ty_param(ty).map_or(false, TyS::is_str))
|
|| (match_type(cx, ty, &paths::COW) && get_ty_param(ty).map_or(false, TyS::is_str))
|
||||||
{
|
{
|
||||||
Some(RepeatKind::String)
|
Some(RepeatKind::String)
|
||||||
} else {
|
} else {
|
||||||
let ty = ty.peel_refs();
|
let ty = ty.peel_refs();
|
||||||
(ty.is_str() || is_type_diagnostic_item(cx, ty, sym::string_type)).then(|| RepeatKind::String)
|
(ty.is_str() || is_type_diagnostic_item(cx, ty, sym::String)).then(|| RepeatKind::String)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ pub(super) fn check(
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Call(repeat_fn, [repeat_arg]) = take_self_arg.kind;
|
if let ExprKind::Call(repeat_fn, [repeat_arg]) = take_self_arg.kind;
|
||||||
if is_expr_path_def_path(cx, repeat_fn, &paths::ITER_REPEAT);
|
if is_expr_path_def_path(cx, repeat_fn, &paths::ITER_REPEAT);
|
||||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(collect_expr), sym::string_type);
|
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(collect_expr), sym::String);
|
||||||
if let Some(collect_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id);
|
if let Some(collect_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id);
|
||||||
if let Some(take_id) = cx.typeck_results().type_dependent_def_id(take_expr.hir_id);
|
if let Some(take_id) = cx.typeck_results().type_dependent_def_id(take_expr.hir_id);
|
||||||
if let Some(iter_trait_id) = cx.tcx.get_diagnostic_item(sym::Iterator);
|
if let Some(iter_trait_id) = cx.tcx.get_diagnostic_item(sym::Iterator);
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub(super) fn check(
|
||||||
if is_trait_method(cx, collect_recv, sym::Iterator);
|
if is_trait_method(cx, collect_recv, sym::Iterator);
|
||||||
// return of collect `Result<(),_>`
|
// return of collect `Result<(),_>`
|
||||||
let collect_ret_ty = cx.typeck_results().expr_ty(expr);
|
let collect_ret_ty = cx.typeck_results().expr_ty(expr);
|
||||||
if is_type_diagnostic_item(cx, collect_ret_ty, sym::result_type);
|
if is_type_diagnostic_item(cx, collect_ret_ty, sym::Result);
|
||||||
if let ty::Adt(_, substs) = collect_ret_ty.kind();
|
if let ty::Adt(_, substs) = collect_ret_ty.kind();
|
||||||
if let Some(result_t) = substs.types().next();
|
if let Some(result_t) = substs.types().next();
|
||||||
if result_t.is_unit();
|
if result_t.is_unit();
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub(super) fn check<'tcx>(
|
||||||
_ => map_closure_ty.fn_sig(cx.tcx),
|
_ => map_closure_ty.fn_sig(cx.tcx),
|
||||||
};
|
};
|
||||||
let map_closure_return_ty = cx.tcx.erase_late_bound_regions(map_closure_sig.output());
|
let map_closure_return_ty = cx.tcx.erase_late_bound_regions(map_closure_sig.output());
|
||||||
is_type_diagnostic_item(cx, map_closure_return_ty, sym::option_type)
|
is_type_diagnostic_item(cx, map_closure_return_ty, sym::Option)
|
||||||
},
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
@ -55,9 +55,9 @@ pub(super) fn check<'tcx>(
|
||||||
// lint if caller of `.map().flatten()` is an Option or Result
|
// lint if caller of `.map().flatten()` is an Option or Result
|
||||||
let caller_type = match cx.typeck_results().expr_ty(recv).kind() {
|
let caller_type = match cx.typeck_results().expr_ty(recv).kind() {
|
||||||
ty::Adt(adt, _) => {
|
ty::Adt(adt, _) => {
|
||||||
if cx.tcx.is_diagnostic_item(sym::option_type, adt.did) {
|
if cx.tcx.is_diagnostic_item(sym::Option, adt.did) {
|
||||||
"Option"
|
"Option"
|
||||||
} else if cx.tcx.is_diagnostic_item(sym::result_type, adt.did) {
|
} else if cx.tcx.is_diagnostic_item(sym::Result, adt.did) {
|
||||||
"Result"
|
"Result"
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -19,8 +19,8 @@ pub(super) fn check(
|
||||||
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if is_trait_method(cx, expr, sym::Iterator)
|
if is_trait_method(cx, expr, sym::Iterator)
|
||||||
|| is_type_diagnostic_item(cx, caller_ty, sym::result_type)
|
|| is_type_diagnostic_item(cx, caller_ty, sym::Result)
|
||||||
|| is_type_diagnostic_item(cx, caller_ty, sym::option_type);
|
|| is_type_diagnostic_item(cx, caller_ty, sym::Option);
|
||||||
if is_expr_identity_function(cx, map_arg);
|
if is_expr_identity_function(cx, map_arg);
|
||||||
if let Some(sugg_span) = expr.span.trim_start(caller.span);
|
if let Some(sugg_span) = expr.span.trim_start(caller.span);
|
||||||
then {
|
then {
|
||||||
|
|
|
@ -22,8 +22,8 @@ pub(super) fn check<'tcx>(
|
||||||
msrv: Option<&RustcVersion>,
|
msrv: Option<&RustcVersion>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// lint if the caller of `map()` is an `Option`
|
// lint if the caller of `map()` is an `Option`
|
||||||
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::option_type);
|
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option);
|
||||||
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::result_type);
|
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
|
||||||
|
|
||||||
if is_result && !meets_msrv(msrv, &msrvs::RESULT_MAP_OR_ELSE) {
|
if is_result && !meets_msrv(msrv, &msrvs::RESULT_MAP_OR_ELSE) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -12,7 +12,7 @@ use super::OK_EXPECT;
|
||||||
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
|
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
// lint if the caller of `ok()` is a `Result`
|
// lint if the caller of `ok()` is a `Result`
|
||||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::result_type);
|
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
|
||||||
let result_type = cx.typeck_results().expr_ty(recv);
|
let result_type = cx.typeck_results().expr_ty(recv);
|
||||||
if let Some(error_type) = get_error_type(cx, result_type);
|
if let Some(error_type) = get_error_type(cx, result_type);
|
||||||
if has_debug_impl(error_type, cx);
|
if has_debug_impl(error_type, cx);
|
||||||
|
@ -33,7 +33,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
|
||||||
/// Given a `Result<T, E>` type, return its error type (`E`).
|
/// Given a `Result<T, E>` type, return its error type (`E`).
|
||||||
fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
|
fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::result_type) => substs.types().nth(1),
|
ty::Adt(_, substs) if is_type_diagnostic_item(cx, ty, sym::Result) => substs.types().nth(1),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,6 @@ fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
|
||||||
/// This checks whether a given type is known to implement Debug.
|
/// This checks whether a given type is known to implement Debug.
|
||||||
fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool {
|
fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool {
|
||||||
cx.tcx
|
cx.tcx
|
||||||
.get_diagnostic_item(sym::debug_trait)
|
.get_diagnostic_item(sym::Debug)
|
||||||
.map_or(false, |debug| implements_trait(cx, ty, debug, &[]))
|
.map_or(false, |debug| implements_trait(cx, ty, debug, &[]))
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub(super) fn check<'tcx>(
|
||||||
let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not);
|
let same_mutability = |m| (is_mut && m == &hir::Mutability::Mut) || (!is_mut && m == &hir::Mutability::Not);
|
||||||
|
|
||||||
let option_ty = cx.typeck_results().expr_ty(as_ref_recv);
|
let option_ty = cx.typeck_results().expr_ty(as_ref_recv);
|
||||||
if !is_type_diagnostic_item(cx, option_ty, sym::option_type) {
|
if !is_type_diagnostic_item(cx, option_ty, sym::Option) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,8 @@ pub(super) fn check<'tcx>(
|
||||||
def_arg: &'tcx hir::Expr<'_>,
|
def_arg: &'tcx hir::Expr<'_>,
|
||||||
map_arg: &'tcx hir::Expr<'_>,
|
map_arg: &'tcx hir::Expr<'_>,
|
||||||
) {
|
) {
|
||||||
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::option_type);
|
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option);
|
||||||
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::result_type);
|
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
|
||||||
|
|
||||||
// There are two variants of this `map_or` lint:
|
// There are two variants of this `map_or` lint:
|
||||||
// (1) using `map_or` as an adapter from `Result<T,E>` to `Option<T>`
|
// (1) using `map_or` as an adapter from `Result<T,E>` to `Option<T>`
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub(super) fn check<'tcx>(
|
||||||
map_span: Span,
|
map_span: Span,
|
||||||
) {
|
) {
|
||||||
// lint if the caller of `map()` is an `Option`
|
// lint if the caller of `map()` is an `Option`
|
||||||
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::option_type) {
|
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option) {
|
||||||
if !is_copy(cx, cx.typeck_results().expr_ty(unwrap_arg)) {
|
if !is_copy(cx, cx.typeck_results().expr_ty(unwrap_arg)) {
|
||||||
// Do not lint if the `map` argument uses identifiers in the `map`
|
// Do not lint if the `map` argument uses identifiers in the `map`
|
||||||
// argument that are also used in the `unwrap_or` argument
|
// argument that are also used in the `unwrap_or` argument
|
||||||
|
|
|
@ -105,7 +105,7 @@ pub(super) fn check<'tcx>(
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_type_diagnostic_item(cx, ty, sym::vec_type) {
|
if is_type_diagnostic_item(cx, ty, sym::Vec) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ pub(super) fn check<'tcx>(
|
||||||
else if search_method == "find" {
|
else if search_method == "find" {
|
||||||
let is_string_or_str_slice = |e| {
|
let is_string_or_str_slice = |e| {
|
||||||
let self_ty = cx.typeck_results().expr_ty(e).peel_refs();
|
let self_ty = cx.typeck_results().expr_ty(e).peel_refs();
|
||||||
if is_type_diagnostic_item(cx, self_ty, sym::string_type) {
|
if is_type_diagnostic_item(cx, self_ty, sym::String) {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
*self_ty.kind() == ty::Str
|
*self_ty.kind() == ty::Str
|
||||||
|
|
|
@ -12,7 +12,7 @@ use super::STRING_EXTEND_CHARS;
|
||||||
|
|
||||||
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
|
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
|
||||||
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
||||||
if !is_type_diagnostic_item(cx, obj_ty, sym::string_type) {
|
if !is_type_diagnostic_item(cx, obj_ty, sym::String) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Some(arglists) = method_chain_args(arg, &["chars"]) {
|
if let Some(arglists) = method_chain_args(arg, &["chars"]) {
|
||||||
|
@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
|
||||||
let self_ty = cx.typeck_results().expr_ty(target).peel_refs();
|
let self_ty = cx.typeck_results().expr_ty(target).peel_refs();
|
||||||
let ref_str = if *self_ty.kind() == ty::Str {
|
let ref_str = if *self_ty.kind() == ty::Str {
|
||||||
""
|
""
|
||||||
} else if is_type_diagnostic_item(cx, self_ty, sym::string_type) {
|
} else if is_type_diagnostic_item(cx, self_ty, sym::String) {
|
||||||
"&"
|
"&"
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<
|
||||||
let in_ty = cx.typeck_results().node_type(body.params[0].hir_id);
|
let in_ty = cx.typeck_results().node_type(body.params[0].hir_id);
|
||||||
match cx.typeck_results().expr_ty(&body.value).kind() {
|
match cx.typeck_results().expr_ty(&body.value).kind() {
|
||||||
ty::Adt(adt, subst)
|
ty::Adt(adt, subst)
|
||||||
if cx.tcx.is_diagnostic_item(sym::option_type, adt.did)
|
if cx.tcx.is_diagnostic_item(sym::Option, adt.did)
|
||||||
&& TyS::same_type(in_ty, subst.type_at(0)) =>
|
&& TyS::same_type(in_ty, subst.type_at(0)) =>
|
||||||
{
|
{
|
||||||
"filter"
|
"filter"
|
||||||
|
|
|
@ -18,8 +18,8 @@ pub(super) fn check<'tcx>(
|
||||||
arg: &'tcx hir::Expr<'_>,
|
arg: &'tcx hir::Expr<'_>,
|
||||||
simplify_using: &str,
|
simplify_using: &str,
|
||||||
) {
|
) {
|
||||||
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::option_type);
|
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option);
|
||||||
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::result_type);
|
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
|
||||||
|
|
||||||
if is_option || is_result {
|
if is_option || is_result {
|
||||||
if let hir::ExprKind::Closure(_, _, eid, _, _) = arg.kind {
|
if let hir::ExprKind::Closure(_, _, eid, _, _) = arg.kind {
|
||||||
|
|
|
@ -19,8 +19,8 @@ pub(super) fn check<'tcx>(
|
||||||
// ^^^^^^^^^- recv ^^^^^^^^^^^^^^^^- u_arg
|
// ^^^^^^^^^- recv ^^^^^^^^^^^^^^^^- u_arg
|
||||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- expr
|
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- expr
|
||||||
let recv_ty = cx.typeck_results().expr_ty(recv);
|
let recv_ty = cx.typeck_results().expr_ty(recv);
|
||||||
let is_option = is_type_diagnostic_item(cx, recv_ty, sym::option_type);
|
let is_option = is_type_diagnostic_item(cx, recv_ty, sym::Option);
|
||||||
let is_result = is_type_diagnostic_item(cx, recv_ty, sym::result_type);
|
let is_result = is_type_diagnostic_item(cx, recv_ty, sym::Result);
|
||||||
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if is_option || is_result;
|
if is_option || is_result;
|
||||||
|
|
|
@ -10,9 +10,9 @@ use super::UNWRAP_USED;
|
||||||
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
|
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
|
||||||
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
|
||||||
|
|
||||||
let mess = if is_type_diagnostic_item(cx, obj_ty, sym::option_type) {
|
let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) {
|
||||||
Some((UNWRAP_USED, "an Option", "None"))
|
Some((UNWRAP_USED, "an Option", "None"))
|
||||||
} else if is_type_diagnostic_item(cx, obj_ty, sym::result_type) {
|
} else if is_type_diagnostic_item(cx, obj_ty, sym::Result) {
|
||||||
Some((UNWRAP_USED, "a Result", "Err"))
|
Some((UNWRAP_USED, "a Result", "Err"))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub(super) fn derefs_to_slice<'tcx>(
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Slice(_) => true,
|
ty::Slice(_) => true,
|
||||||
ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),
|
ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),
|
||||||
ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::vec_type),
|
ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::Vec),
|
||||||
ty::Array(_, size) => size.try_eval_usize(cx.tcx, cx.param_env).is_some(),
|
ty::Array(_, size) => size.try_eval_usize(cx.tcx, cx.param_env).is_some(),
|
||||||
ty::Ref(_, inner, _) => may_slice(cx, inner),
|
ty::Ref(_, inner, _) => may_slice(cx, inner),
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -122,7 +122,7 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, item_hir_id: hir::HirId, decl: &hir::
|
||||||
fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
|
fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
|
||||||
let ty = ty.peel_refs();
|
let ty = ty.peel_refs();
|
||||||
if let Adt(def, substs) = ty.kind() {
|
if let Adt(def, substs) = ty.kind() {
|
||||||
let is_keyed_type = [sym::hashmap_type, sym::BTreeMap, sym::hashset_type, sym::BTreeSet]
|
let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet]
|
||||||
.iter()
|
.iter()
|
||||||
.any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did));
|
.any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did));
|
||||||
if is_keyed_type && is_interior_mutable_type(cx, substs.type_at(0), span) {
|
if is_keyed_type && is_interior_mutable_type(cx, substs.type_at(0), span) {
|
||||||
|
@ -147,11 +147,11 @@ fn is_interior_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Sp
|
||||||
// that of their type parameters. Note: we don't include `HashSet` and `HashMap`
|
// that of their type parameters. Note: we don't include `HashSet` and `HashMap`
|
||||||
// because they have no impl for `Hash` or `Ord`.
|
// because they have no impl for `Hash` or `Ord`.
|
||||||
let is_std_collection = [
|
let is_std_collection = [
|
||||||
sym::option_type,
|
sym::Option,
|
||||||
sym::result_type,
|
sym::Result,
|
||||||
sym::LinkedList,
|
sym::LinkedList,
|
||||||
sym::vec_type,
|
sym::Vec,
|
||||||
sym::vecdeque_type,
|
sym::VecDeque,
|
||||||
sym::BTreeMap,
|
sym::BTreeMap,
|
||||||
sym::BTreeSet,
|
sym::BTreeSet,
|
||||||
sym::Rc,
|
sym::Rc,
|
||||||
|
|
|
@ -6,6 +6,7 @@ use rustc_hir::{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};
|
||||||
|
use rustc_span::sym;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// ### What it does
|
/// ### What it does
|
||||||
|
@ -51,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for MutMutexLock {
|
||||||
if path.ident.name == sym!(lock);
|
if path.ident.name == sym!(lock);
|
||||||
let ty = cx.typeck_results().expr_ty(self_arg);
|
let ty = cx.typeck_results().expr_ty(self_arg);
|
||||||
if let ty::Ref(_, inner_ty, Mutability::Mut) = ty.kind();
|
if let ty::Ref(_, inner_ty, Mutability::Mut) = ty.kind();
|
||||||
if is_type_diagnostic_item(cx, inner_ty, sym!(mutex_type));
|
if is_type_diagnostic_item(cx, inner_ty, sym::Mutex);
|
||||||
then {
|
then {
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -8,6 +8,7 @@ use rustc_hir::Expr;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
|
use rustc_span::sym;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// ### What it does
|
/// ### What it does
|
||||||
|
@ -74,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for Mutex {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||||
let ty = cx.typeck_results().expr_ty(expr);
|
let ty = cx.typeck_results().expr_ty(expr);
|
||||||
if let ty::Adt(_, subst) = ty.kind() {
|
if let ty::Adt(_, subst) = ty.kind() {
|
||||||
if is_type_diagnostic_item(cx, ty, sym!(mutex_type)) {
|
if is_type_diagnostic_item(cx, ty, sym::Mutex) {
|
||||||
let mutex_param = subst.type_at(0);
|
let mutex_param = subst.type_at(0);
|
||||||
if let Some(atomic_name) = get_atomic_name(mutex_param) {
|
if let Some(atomic_name) = get_atomic_name(mutex_param) {
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref {
|
||||||
let outer_ty = typeck.expr_ty(expr);
|
let outer_ty = typeck.expr_ty(expr);
|
||||||
|
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if is_type_diagnostic_item(cx,outer_ty,sym::option_type);
|
if is_type_diagnostic_item(cx,outer_ty,sym::Option);
|
||||||
if let ExprKind::MethodCall(path, _, [sub_expr], _) = expr.kind;
|
if let ExprKind::MethodCall(path, _, [sub_expr], _) = expr.kind;
|
||||||
let symbol = path.ident.as_str();
|
let symbol = path.ident.as_str();
|
||||||
if symbol=="as_deref" || symbol=="as_deref_mut";
|
if symbol=="as_deref" || symbol=="as_deref_mut";
|
||||||
|
|
|
@ -206,7 +206,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
||||||
|
|
||||||
let deref_span = spans_need_deref.get(&canonical_id);
|
let deref_span = spans_need_deref.get(&canonical_id);
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if is_type_diagnostic_item(cx, ty, sym::vec_type);
|
if is_type_diagnostic_item(cx, ty, sym::Vec);
|
||||||
if let Some(clone_spans) =
|
if let Some(clone_spans) =
|
||||||
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]);
|
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_owned()")]);
|
||||||
if let TyKind::Path(QPath::Resolved(_, path)) = input.kind;
|
if let TyKind::Path(QPath::Resolved(_, path)) = input.kind;
|
||||||
|
@ -245,7 +245,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_type_diagnostic_item(cx, ty, sym::string_type) {
|
if is_type_diagnostic_item(cx, ty, sym::String) {
|
||||||
if let Some(clone_spans) =
|
if let Some(clone_spans) =
|
||||||
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) {
|
get_spans(cx, Some(body.id()), idx, &[("clone", ".to_string()"), ("as_str", "")]) {
|
||||||
diag.span_suggestion(
|
diag.span_suggestion(
|
||||||
|
|
|
@ -70,7 +70,7 @@ declare_lint_pass!(OptionIfLetElse => [OPTION_IF_LET_ELSE]);
|
||||||
fn is_result_ok(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool {
|
fn is_result_ok(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool {
|
||||||
if let ExprKind::MethodCall(path, _, &[ref receiver], _) = &expr.kind {
|
if let ExprKind::MethodCall(path, _, &[ref receiver], _) = &expr.kind {
|
||||||
path.ident.name.as_str() == "ok"
|
path.ident.name.as_str() == "ok"
|
||||||
&& is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(receiver), sym::result_type)
|
&& is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(receiver), sym::Result)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicInResultFn {
|
||||||
span: Span,
|
span: Span,
|
||||||
hir_id: hir::HirId,
|
hir_id: hir::HirId,
|
||||||
) {
|
) {
|
||||||
if !matches!(fn_kind, FnKind::Closure) && is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) {
|
if !matches!(fn_kind, FnKind::Closure) && is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::Result) {
|
||||||
lint_impl_body(cx, span, body);
|
lint_impl_body(cx, span, body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,7 +258,7 @@ fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id:
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ty::Ref(_, ty, Mutability::Not) = ty.kind() {
|
if let ty::Ref(_, ty, Mutability::Not) = ty.kind() {
|
||||||
if is_type_diagnostic_item(cx, ty, sym::vec_type) {
|
if is_type_diagnostic_item(cx, ty, sym::Vec) {
|
||||||
if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_owned()")]) {
|
if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_owned()")]) {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
|
@ -288,7 +288,7 @@ fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id:
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::string_type) {
|
} else if is_type_diagnostic_item(cx, ty, sym::String) {
|
||||||
if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_string()"), ("as_str", "")]) {
|
if let Some(spans) = get_spans(cx, opt_body_id, idx, &[("clone", ".to_string()"), ("as_str", "")]) {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -143,7 +143,7 @@ impl QuestionMark {
|
||||||
fn is_option(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool {
|
fn is_option(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool {
|
||||||
let expr_ty = cx.typeck_results().expr_ty(expression);
|
let expr_ty = cx.typeck_results().expr_ty(expression);
|
||||||
|
|
||||||
is_type_diagnostic_item(cx, expr_ty, sym::option_type)
|
is_type_diagnostic_item(cx, expr_ty, sym::Option)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expression_returns_none(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool {
|
fn expression_returns_none(cx: &LateContext<'_>, expression: &Expr<'_>) -> bool {
|
||||||
|
|
|
@ -123,7 +123,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
|
||||||
let from_borrow = match_def_path(cx, fn_def_id, &paths::CLONE_TRAIT_METHOD)
|
let from_borrow = match_def_path(cx, fn_def_id, &paths::CLONE_TRAIT_METHOD)
|
||||||
|| match_def_path(cx, fn_def_id, &paths::TO_OWNED_METHOD)
|
|| match_def_path(cx, fn_def_id, &paths::TO_OWNED_METHOD)
|
||||||
|| (match_def_path(cx, fn_def_id, &paths::TO_STRING_METHOD)
|
|| (match_def_path(cx, fn_def_id, &paths::TO_STRING_METHOD)
|
||||||
&& is_type_diagnostic_item(cx, arg_ty, sym::string_type));
|
&& is_type_diagnostic_item(cx, arg_ty, sym::String));
|
||||||
|
|
||||||
let from_deref = !from_borrow
|
let from_deref = !from_borrow
|
||||||
&& (match_def_path(cx, fn_def_id, &paths::PATH_TO_PATH_BUF)
|
&& (match_def_path(cx, fn_def_id, &paths::PATH_TO_PATH_BUF)
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef {
|
||||||
if let Some(res) = last.res;
|
if let Some(res) = last.res;
|
||||||
if let Some(def_id) = res.opt_def_id();
|
if let Some(def_id) = res.opt_def_id();
|
||||||
|
|
||||||
if cx.tcx.is_diagnostic_item(sym::option_type, def_id);
|
if cx.tcx.is_diagnostic_item(sym::Option, def_id);
|
||||||
if let Some(params) = last_path_segment(qpath).args ;
|
if let Some(params) = last_path_segment(qpath).args ;
|
||||||
if !params.parenthesized;
|
if !params.parenthesized;
|
||||||
if let Some(inner_ty) = params.args.iter().find_map(|arg| match arg {
|
if let Some(inner_ty) = params.args.iter().find_map(|arg| match arg {
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for RepeatOnce {
|
||||||
format!("{}.to_vec()", snippet(cx, receiver.span, r#""...""#)),
|
format!("{}.to_vec()", snippet(cx, receiver.span, r#""...""#)),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else if is_type_diagnostic_item(cx, ty, sym::string_type) {
|
} else if is_type_diagnostic_item(cx, ty, sym::String) {
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
REPEAT_ONCE,
|
REPEAT_ONCE,
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue