]> git.lizzy.rs Git - rust.git/commitdiff
get clippy to compile again
authorlcnr <rust@lcnr.de>
Fri, 18 Mar 2022 12:33:40 +0000 (13:33 +0100)
committerlcnr <rust@lcnr.de>
Wed, 30 Mar 2022 09:23:58 +0000 (11:23 +0200)
clippy_lints/src/implicit_saturating_sub.rs
clippy_lints/src/methods/implicit_clone.rs
clippy_lints/src/methods/suspicious_splitn.rs
clippy_lints/src/ptr.rs
clippy_utils/src/lib.rs
tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs
tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr

index 6515975fbffdc8b1b723e4196059168ebdda1256..ae4158662d46459c26419250fe5a2cd62cece2cb 100644 (file)
@@ -3,7 +3,7 @@
 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};
 
@@ -82,14 +82,6 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
 
                 // 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
@@ -105,8 +97,8 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
                             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)
                             }
@@ -118,8 +110,8 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
                             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)
                             }
index 6e64e7f62220704fa6759a79d690428a38f63664..c98cdfbca434e9dd9bfbdcede516e322be519e97 100644 (file)
@@ -49,10 +49,11 @@ pub fn is_clone_like(cx: &LateContext<'_>, method_name: &str, method_def_id: hir
         "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,
     }
index 1c546a15bf62b331a5993e378aee11e7c832dc72..55567d8625e529dfc541d3bf937284c130a9e516 100644 (file)
@@ -12,13 +12,13 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se
         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;
             }
@@ -28,7 +28,7 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se
                 "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`"
index ba1997e70e1314ee631fdf87832121c6372250f8..9d4313827f7c6afa048b68d70c1dc3d46ba2e6a1 100644 (file)
@@ -16,7 +16,7 @@
 };
 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;
@@ -308,7 +308,6 @@ struct PtrArg<'tcx> {
     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 {
@@ -411,7 +410,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
                 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(
@@ -424,17 +423,14 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
                                     }),
                                 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
@@ -470,7 +466,6 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
                             mutability,
                         },
                         deref_ty,
-                        deref_assoc_items: deref_impl_id.map(|id| (id, cx.tcx.associated_items(id))),
                     });
                 }
             }
@@ -607,14 +602,7 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
                             // 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();
                             },
index cd20abd94ed256811487649df709158ec74f4a01..b55075943b29a1f733182a907c6a280e72d5b67d 100644 (file)
@@ -77,9 +77,9 @@
 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};
@@ -479,12 +479,10 @@ fn item_child_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: &str) -> Option<Res>
             _ => 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(())
index 338b3b5b28f429b9700d5849886109698f758242..f8086bd2e4d042126e3ace5feab5f2c8d955a2fc 100644 (file)
@@ -10,8 +10,8 @@ fn main() {
     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);
 }
index 5533676aea287b80677e8ec9f9cd0423dd52e405..999ead10d51829dae9d73903f9cd2c92df6bb4be 100644 (file)
@@ -20,17 +20,5 @@ error: use of a disallowed method `std::iter::Iterator::sum`
 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