]> git.lizzy.rs Git - rust.git/commitdiff
Stored linter messages in constants.
authorTristian Celestin <tcelesti@redhat.com>
Sun, 26 Feb 2017 22:57:56 +0000 (17:57 -0500)
committerTristian Celestin <tcelesti@redhat.com>
Sun, 26 Feb 2017 22:57:56 +0000 (17:57 -0500)
Use is_copy() function instead of calling moves_by_default()

clippy_lints/src/drop_forget_copy.rs

index 16259f33e7e24e18265df8335f32361f913cfa2f..8c6f6a2773838cfd4224bdcef5ceb6841a2f4808 100644 (file)
@@ -1,7 +1,9 @@
 use rustc::lint::*;
-use rustc::ty;
 use rustc::hir::*;
-use utils::{match_def_path, paths, span_note_and_lint};
+use utils::{match_def_path, paths, span_note_and_lint, is_copy};
+
+const DROP_COPY_SUMMARY:&'static str = "calls to `std::mem::drop` with a value that implements Copy";
+const FORGET_COPY_SUMMARY:&'static str = "calls to `std::mem::forget` with a value that implements Copy";
 
 /// **What it does:** Checks for calls to `std::mem::drop` with a value
 /// that derives the Copy trait
@@ -20,7 +22,7 @@
 declare_lint! {
     pub DROP_COPY,
     Warn,
-    "calls to `std::mem::drop` with a value that implements Copy"
+    DROP_COPY_SUMMARY
 }
 
 /// **What it does:** Checks for calls to `std::mem::forget` with a value that
@@ -44,7 +46,7 @@
 declare_lint! {
     pub FORGET_COPY,
     Warn,
-    "calls to `std::mem::forget` with a value that implements Copy"
+    FORGET_COPY_SUMMARY
 }
 
 #[allow(missing_copy_implementations)]
@@ -69,25 +71,21 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
 
             if match_def_path(cx.tcx, def_id, &paths::DROP) {
                 lint = DROP_COPY;
-                msg = "call to `std::mem::drop` with a value that implements Copy. \
-                       Dropping a copy leaves the original intact.";
+                msg = DROP_COPY_SUMMARY.to_string() + ". Dropping a copy leaves the original intact.";
             } else if match_def_path(cx.tcx, def_id, &paths::MEM_FORGET) {
                 lint = FORGET_COPY;
-                msg = "call to `std::mem::forget` with a value that implements Copy. \
-                       Forgetting a copy leaves the original intact.";
+                msg = FORGET_COPY_SUMMARY.to_string() + ". Forgetting a copy leaves the original intact.";
             } else {
                 return;
             }
 
             let arg = &args[0];
             let arg_ty = cx.tables.expr_ty(arg);
-
-            let parameter_environment = ty::ParameterEnvironment::for_item(cx.tcx, arg.id);
-            if !arg_ty.moves_by_default(cx.tcx.global_tcx(), &parameter_environment, arg.span) {
+            if is_copy(cx, arg_ty, cx.tcx.hir.get_parent(arg.id)) {
                 span_note_and_lint(cx,
                                    lint,
                                    expr.span,
-                                   msg,
+                                   &msg,
                                    arg.span,
                                    &format!("argument has type {}", arg_ty.sty));
             }