about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2019-05-04 22:28:22 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2019-06-03 12:59:08 +0100
commitf309f917c21f371a1cff8f917518aa29e2f6b850 (patch)
tree15c0a1f3054c678db786d3b3b9259ed312b02d9d
parent5cfa70f76088f973dd66f5bea9c6b0867378c16d (diff)
downloadrust-f309f917c21f371a1cff8f917518aa29e2f6b850.tar.gz
rust-f309f917c21f371a1cff8f917518aa29e2f6b850.zip
Add method to note types don't implement `Copy`
-rw-r--r--src/librustc_mir/borrow_check/conflict_errors.rs24
-rw-r--r--src/librustc_mir/borrow_check/error_reporting.rs26
-rw-r--r--src/librustc_mir/borrow_check/move_errors.rs13
3 files changed, 38 insertions, 25 deletions
diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs
index e3a79b24cab..f8e73e838df 100644
--- a/src/librustc_mir/borrow_check/conflict_errors.rs
+++ b/src/librustc_mir/borrow_check/conflict_errors.rs
@@ -234,22 +234,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                         );
                     }
                 }
-                if let Place::Base(PlaceBase::Local(local)) = place {
+                let span = if let Place::Base(PlaceBase::Local(local)) = place {
                     let decl = &self.mir.local_decls[*local];
-                    err.span_label(
-                        decl.source_info.span,
-                        format!(
-                            "move occurs because {} has type `{}`, \
-                                which does not implement the `Copy` trait",
-                            note_msg, ty,
-                    ));
+                    Some(decl.source_info.span)
                 } else {
-                    err.note(&format!(
-                        "move occurs because {} has type `{}`, \
-                         which does not implement the `Copy` trait",
-                        note_msg, ty
-                    ));
-                }
+                    None
+                };
+                self.note_type_does_not_implement_copy(
+                    &mut err,
+                    &note_msg,
+                    ty,
+                    span,
+                );
             }
 
             if let Some((_, mut old_err)) = self.move_error_reported
diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs
index dea755411cc..3f977ea198b 100644
--- a/src/librustc_mir/borrow_check/error_reporting.rs
+++ b/src/librustc_mir/borrow_check/error_reporting.rs
@@ -2,9 +2,9 @@ use rustc::hir;
 use rustc::hir::def::Namespace;
 use rustc::hir::def_id::DefId;
 use rustc::mir::{
-    AggregateKind, BindingForm, ClearCrossCrate, Constant, Field, Local,
-    LocalKind, Location, Operand, Place, PlaceBase, ProjectionElem, Rvalue,
-    Statement, StatementKind, Static, StaticKind, TerminatorKind,
+    AggregateKind, Constant, Field, Local, LocalKind, Location, Operand,
+    Place, PlaceBase, ProjectionElem, Rvalue, Statement, StatementKind, Static,
+    StaticKind, TerminatorKind,
 };
 use rustc::ty::{self, DefIdTree, Ty};
 use rustc::ty::layout::VariantIdx;
@@ -381,6 +381,26 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
             false
         }
     }
+
+    /// Add a note that a type does not implement `Copy`
+    pub(super) fn note_type_does_not_implement_copy(
+        &self,
+        err: &mut DiagnosticBuilder<'a>,
+        place_desc: &str,
+        ty: Ty<'tcx>,
+        span: Option<Span>,
+    ) {
+        let message = format!(
+            "move occurs because {} has type `{}`, which does not implement the `Copy` trait",
+            place_desc,
+            ty,
+        );
+        if let Some(span) = span {
+            err.span_label(span, message);
+        } else {
+            err.note(&message);
+        }
+    }
 }
 
 impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs
index 63d5cd4372f..2e3c92acb2c 100644
--- a/src/librustc_mir/borrow_check/move_errors.rs
+++ b/src/librustc_mir/borrow_check/move_errors.rs
@@ -473,14 +473,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
             }
 
             if binds_to.len() == 1 {
-                err.span_note(
-                    binding_span,
-                    &format!(
-                        "move occurs because `{}` has type `{}`, \
-                            which does not implement the `Copy` trait",
-                        bind_to.name.unwrap(),
-                        bind_to.ty
-                    ),
+                self.note_type_does_not_implement_copy(
+                    err,
+                    &format!("`{}`", bind_to.name.unwrap()),
+                    bind_to.ty,
+                    Some(binding_span)
                 );
             } else {
                 noncopy_var_spans.push(binding_span);