diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2017-10-03 15:54:12 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2017-10-04 12:47:46 +0200 |
| commit | a995b56a5e7352aec0aafd4972c3faaeed94083d (patch) | |
| tree | bb8b1a0e11e6a36b7c6d7b4b08e3bf75b719491f /src/librustc_borrowck | |
| parent | a12cefb497fa6ebc397f7f2f2f14f2f2712b965d (diff) | |
| download | rust-a995b56a5e7352aec0aafd4972c3faaeed94083d.tar.gz rust-a995b56a5e7352aec0aafd4972c3faaeed94083d.zip | |
Move E0508 diagnostic into mod borrowck_errors shared between ast- and mir-borrowck.
Diffstat (limited to 'src/librustc_borrowck')
| -rw-r--r-- | src/librustc_borrowck/borrowck/gather_loans/move_error.rs | 15 | ||||
| -rw-r--r-- | src/librustc_borrowck/diagnostics.rs | 45 |
2 files changed, 2 insertions, 58 deletions
diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs index b56e7e1d72e..ef89b569a83 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs @@ -147,19 +147,8 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &'a BorrowckCtxt<'a, 'tcx>, move_from.span, &move_from.descriptive_string(bccx.tcx), Origin::Ast) } Categorization::Interior(ref b, mc::InteriorElement(ik)) => { - let type_name = match (&b.ty.sty, ik) { - (&ty::TyArray(_, _), Kind::Index) => "array", - (&ty::TySlice(_), _) => "slice", - _ => { - span_bug!(move_from.span, "this path should not cause illegal move"); - }, - }; - let mut err = struct_span_err!(bccx, move_from.span, E0508, - "cannot move out of type `{}`, \ - a non-copy {}", - b.ty, type_name); - err.span_label(move_from.span, "cannot move out of here"); - err + bccx.cannot_move_out_of_interior_noncopy( + move_from.span, b.ty, ik == Kind::Index, Origin::Ast) } Categorization::Downcast(ref b, _) | diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index 8fd17943c3a..85e8e0e54fa 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -317,51 +317,6 @@ fn main() { ``` "##, - -E0508: r##" -A value was moved out of a non-copy fixed-size array. - -Example of erroneous code: - -```compile_fail,E0508 -struct NonCopy; - -fn main() { - let array = [NonCopy; 1]; - let _value = array[0]; // error: cannot move out of type `[NonCopy; 1]`, - // a non-copy fixed-size array -} -``` - -The first element was moved out of the array, but this is not -possible because `NonCopy` does not implement the `Copy` trait. - -Consider borrowing the element instead of moving it: - -``` -struct NonCopy; - -fn main() { - let array = [NonCopy; 1]; - let _value = &array[0]; // Borrowing is allowed, unlike moving. -} -``` - -Alternatively, if your type implements `Clone` and you need to own the value, -consider borrowing and then cloning: - -``` -#[derive(Clone)] -struct NonCopy; - -fn main() { - let array = [NonCopy; 1]; - // Now you can clone the array element. - let _value = array[0].clone(); -} -``` -"##, - E0509: r##" This error occurs when an attempt is made to move out of a value whose type implements the `Drop` trait. |
