Move E0508 diagnostic into mod borrowck_errors shared between ast- and mir-borrowck.
This commit is contained in:
parent
a12cefb497
commit
a995b56a5e
4 changed files with 67 additions and 58 deletions
|
|
@ -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, _) |
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -1126,6 +1126,51 @@ You can find more information about borrowing in the rust-book:
|
|||
http://doc.rust-lang.org/book/first-edition/references-and-borrowing.html
|
||||
"##,
|
||||
|
||||
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();
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
|
||||
}
|
||||
|
||||
register_diagnostics! {
|
||||
|
|
|
|||
|
|
@ -203,6 +203,26 @@ pub trait BorrowckErrors {
|
|||
format!("cannot move out of {}", move_from_desc));
|
||||
err
|
||||
}
|
||||
|
||||
fn cannot_move_out_of_interior_noncopy(&self,
|
||||
move_from_span: Span,
|
||||
ty: ty::Ty,
|
||||
is_index: bool,
|
||||
o: Origin)
|
||||
-> DiagnosticBuilder
|
||||
{
|
||||
let type_name = match (&ty.sty, is_index) {
|
||||
(&ty::TyArray(_, _), true) => "array",
|
||||
(&ty::TySlice(_), _) => "slice",
|
||||
_ => span_bug!(move_from_span, "this path should not cause illegal move"),
|
||||
};
|
||||
let mut err = struct_span_err!(self, move_from_span, E0508,
|
||||
"cannot move out of type `{}`, \
|
||||
a non-copy {}{OGN}",
|
||||
ty, type_name, OGN=o);
|
||||
err.span_label(move_from_span, "cannot move out of here");
|
||||
err
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, 'tcx, 'gcx> BorrowckErrors for TyCtxt<'b, 'tcx, 'gcx> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue