use if_chain::if_chain;
use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
-use rustc_hir::{lang_items::LangItem, BinOpKind, Expr, ExprKind, QPath};
+use rustc_hir::{BinOpKind, Expr, ExprKind, QPath};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
// Get the variable name
let var_name = ares_path.segments[0].ident.name.as_str();
- const INT_TYPES: [LangItem; 5] = [
- LangItem::I8,
- LangItem::I16,
- LangItem::I32,
- LangItem::I64,
- LangItem::Isize
- ];
-
match cond_num_val.kind {
ExprKind::Lit(ref cond_lit) => {
// Check if the constant is zero
if name.ident.as_str() == "MIN";
if let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id);
if let Some(impl_id) = cx.tcx.impl_of_method(const_id);
- let mut int_ids = INT_TYPES.iter().filter_map(|&ty| cx.tcx.lang_items().require(ty).ok());
- if int_ids.any(|int_id| int_id == impl_id);
+ if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl
+ if cx.tcx.type_of(impl_id).is_integral();
then {
print_lint_and_sugg(cx, var_name, expr)
}
if name.ident.as_str() == "min_value";
if let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id);
if let Some(impl_id) = cx.tcx.impl_of_method(func_id);
- let mut int_ids = INT_TYPES.iter().filter_map(|&ty| cx.tcx.lang_items().require(ty).ok());
- if int_ids.any(|int_id| int_id == impl_id);
+ if let None = cx.tcx.impl_trait_ref(impl_id); // An inherent impl
+ if cx.tcx.type_of(impl_id).is_integral();
then {
print_lint_and_sugg(cx, var_name, expr)
}
"to_owned" => is_diag_trait_item(cx, method_def_id, sym::ToOwned),
"to_path_buf" => is_diag_item_method(cx, method_def_id, sym::Path),
"to_vec" => {
- cx.tcx
- .impl_of_method(method_def_id)
- .map(|impl_did| Some(impl_did) == cx.tcx.lang_items().slice_alloc_impl())
- == Some(true)
+ cx.tcx.impl_of_method(method_def_id)
+ .filter(|&impl_did| {
+ cx.tcx.type_of(impl_did).is_slice() && cx.tcx.impl_trait_ref(impl_did).is_none()
+ })
+ .is_some()
},
_ => false,
}
if count <= 1;
if let Some(call_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
if let Some(impl_id) = cx.tcx.impl_of_method(call_id);
- let lang_items = cx.tcx.lang_items();
- if lang_items.slice_impl() == Some(impl_id) || lang_items.str_impl() == Some(impl_id);
+ if cx.tcx.impl_trait_ref(impl_id).is_none();
+ let self_ty = cx.tcx.type_of(impl_id);
+ if self_ty.is_slice() || self_ty.is_str();
then {
// Ignore empty slice and string literals when used with a literal count.
if matches!(self_arg.kind, ExprKind::Array([]))
|| matches!(self_arg.kind, ExprKind::Lit(Spanned { node: LitKind::Str(s, _), .. }) if s.is_empty())
-
{
return;
}
"the resulting iterator will always return `None`")
} else {
(format!("`{}` called with `1` split", method_name),
- if lang_items.slice_impl() == Some(impl_id) {
+ if self_ty.is_slice() {
"the resulting iterator will always return the entire slice followed by `None`"
} else {
"the resulting iterator will always return the entire string followed by `None`"
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter;
-use rustc_middle::ty::{self, AssocItems, AssocKind, Ty};
+use rustc_middle::ty::{self, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use rustc_span::symbol::Symbol;
method_renames: &'static [(&'static str, &'static str)],
ref_prefix: RefPrefix,
deref_ty: DerefTy<'tcx>,
- deref_assoc_items: Option<(DefId, &'tcx AssocItems<'tcx>)>,
}
impl PtrArg<'_> {
fn build_msg(&self) -> String {
if params.get(i).map_or(true, |p| !is_lint_allowed(cx, PTR_ARG, p.hir_id));
then {
- let (method_renames, deref_ty, deref_impl_id) = match cx.tcx.get_diagnostic_name(adt.did()) {
+ let (method_renames, deref_ty) = match cx.tcx.get_diagnostic_name(adt.did()) {
Some(sym::Vec) => (
[("clone", ".to_owned()")].as_slice(),
DerefTy::Slice(
}),
substs.type_at(0),
),
- cx.tcx.lang_items().slice_impl()
),
Some(sym::String) => (
[("clone", ".to_owned()"), ("as_str", "")].as_slice(),
DerefTy::Str,
- cx.tcx.lang_items().str_impl()
),
Some(sym::PathBuf) => (
[("clone", ".to_path_buf()"), ("as_path", "")].as_slice(),
DerefTy::Path,
- None,
),
Some(sym::Cow) if mutability == Mutability::Not => {
let ty_name = name.args
mutability,
},
deref_ty,
- deref_assoc_items: deref_impl_id.map(|id| (id, cx.tcx.associated_items(id))),
});
}
}
// If the types match check for methods which exist on both types. e.g. `Vec::len` and
// `slice::len`
ty::Adt(def, _)
- if def.did() == args.ty_did
- && (i != 0
- || self.cx.tcx.trait_of_item(id).is_some()
- || !args.deref_assoc_items.map_or(false, |(id, items)| {
- items
- .find_by_name_and_kind(self.cx.tcx, name.ident, AssocKind::Fn, id)
- .is_some()
- })) =>
+ if def.did() == args.ty_did =>
{
set_skip_flag();
},
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk};
use rustc_hir::{
- def, lang_items, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Constness, Destination, Expr,
+ def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Constness, Destination, Expr,
ExprKind, FnDecl, ForeignItem, HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem, Local,
- MatchSource, Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, Target,
+ MatchSource, Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind,
TraitItem, TraitItemKind, TraitRef, TyKind, UnOp,
};
use rustc_lint::{LateContext, Level, Lint, LintContext};
_ => None,
}
}
- fn find_primitive(tcx: TyCtxt<'_>, name: &str) -> Option<DefId> {
- if let Some(&(index, Target::Impl)) = lang_items::ITEM_REFS.get(&Symbol::intern(name)) {
- tcx.lang_items().items()[index]
- } else {
- None
- }
+ fn find_primitive(_tcx: TyCtxt<'_>, _name: &str) -> Option<DefId> {
+ // FIXME: Deal with this without relying on lang items or by only
+ // looking at a single impl.
+ None
}
fn find_crate(tcx: TyCtxt<'_>, name: &str) -> Option<DefId> {
tcx.crates(())
let mut a = vec![1, 2, 3, 4];
a.iter().sum::<i32>();
- a.sort_unstable();
+ a.sort_unstable(); // FIXME: Warn here
- let _ = 2.0f32.clamp(3.0f32, 4.0f32);
+ let _ = 2.0f32.clamp(3.0f32, 4.0f32); // FIXME: Warn here
let _ = 2.0f64.clamp(3.0f64, 4.0f64);
}
LL | a.iter().sum::<i32>();
| ^^^^^^^^^^^^^^^^^^^^^
-error: use of a disallowed method `slice::sort_unstable`
- --> $DIR/conf_disallowed_methods.rs:13:5
- |
-LL | a.sort_unstable();
- | ^^^^^^^^^^^^^^^^^
-
-error: use of a disallowed method `f32::clamp`
- --> $DIR/conf_disallowed_methods.rs:15:13
- |
-LL | let _ = 2.0f32.clamp(3.0f32, 4.0f32);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 5 previous errors
+error: aborting due to 3 previous errors