mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-07 12:33:14 +00:00
Report cannot move errors in promoted MIR
This commit is contained in:
parent
ec1f28f961
commit
34eb2c1d4f
@ -180,11 +180,14 @@ fn do_mir_borrowck<'a, 'tcx>(
|
|||||||
let location_table = &LocationTable::new(&body);
|
let location_table = &LocationTable::new(&body);
|
||||||
|
|
||||||
let mut errors_buffer = Vec::new();
|
let mut errors_buffer = Vec::new();
|
||||||
let (move_data, move_errors): (MoveData<'tcx>, Option<Vec<(Place<'tcx>, MoveError<'tcx>)>>) =
|
let (move_data, move_errors): (MoveData<'tcx>, Vec<(Place<'tcx>, MoveError<'tcx>)>) =
|
||||||
match MoveData::gather_moves(&body, tcx, param_env) {
|
match MoveData::gather_moves(&body, tcx, param_env) {
|
||||||
Ok(move_data) => (move_data, None),
|
Ok(move_data) => (move_data, Vec::new()),
|
||||||
Err((move_data, move_errors)) => (move_data, Some(move_errors)),
|
Err((move_data, move_errors)) => (move_data, move_errors),
|
||||||
};
|
};
|
||||||
|
let promoted_errors = promoted
|
||||||
|
.iter_enumerated()
|
||||||
|
.map(|(idx, body)| (idx, MoveData::gather_moves(&body, tcx, param_env)));
|
||||||
|
|
||||||
let mdpe = MoveDataParamEnv { move_data, param_env };
|
let mdpe = MoveDataParamEnv { move_data, param_env };
|
||||||
|
|
||||||
@ -264,6 +267,41 @@ fn do_mir_borrowck<'a, 'tcx>(
|
|||||||
_ => true,
|
_ => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
for (idx, move_data_results) in promoted_errors {
|
||||||
|
let promoted_body = &promoted[idx];
|
||||||
|
let dominators = promoted_body.dominators();
|
||||||
|
|
||||||
|
if let Err((move_data, move_errors)) = move_data_results {
|
||||||
|
let mut promoted_mbcx = MirBorrowckCtxt {
|
||||||
|
infcx,
|
||||||
|
body: promoted_body,
|
||||||
|
mir_def_id: def_id.to_def_id(),
|
||||||
|
move_data: &move_data,
|
||||||
|
location_table: &LocationTable::new(promoted_body),
|
||||||
|
movable_generator,
|
||||||
|
locals_are_invalidated_at_exit,
|
||||||
|
access_place_error_reported: Default::default(),
|
||||||
|
reservation_error_reported: Default::default(),
|
||||||
|
reservation_warnings: Default::default(),
|
||||||
|
move_error_reported: BTreeMap::new(),
|
||||||
|
uninitialized_error_reported: Default::default(),
|
||||||
|
errors_buffer,
|
||||||
|
regioncx: regioncx.clone(),
|
||||||
|
used_mut: Default::default(),
|
||||||
|
used_mut_upvars: SmallVec::new(),
|
||||||
|
borrow_set: borrow_set.clone(),
|
||||||
|
dominators,
|
||||||
|
upvars: Vec::new(),
|
||||||
|
local_names: IndexVec::from_elem(None, &promoted_body.local_decls),
|
||||||
|
region_names: RefCell::default(),
|
||||||
|
next_region_name: RefCell::new(1),
|
||||||
|
polonius_output: None,
|
||||||
|
};
|
||||||
|
promoted_mbcx.report_move_errors(move_errors);
|
||||||
|
errors_buffer = promoted_mbcx.errors_buffer;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let dominators = body.dominators();
|
let dominators = body.dominators();
|
||||||
|
|
||||||
let mut mbcx = MirBorrowckCtxt {
|
let mut mbcx = MirBorrowckCtxt {
|
||||||
@ -301,9 +339,7 @@ fn do_mir_borrowck<'a, 'tcx>(
|
|||||||
borrows: flow_borrows,
|
borrows: flow_borrows,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(errors) = move_errors {
|
mbcx.report_move_errors(move_errors);
|
||||||
mbcx.report_move_errors(errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
dataflow::visit_results(
|
dataflow::visit_results(
|
||||||
&body,
|
&body,
|
||||||
|
10
src/test/ui/borrowck/move-error-in-promoted-2.rs
Normal file
10
src/test/ui/borrowck/move-error-in-promoted-2.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Regression test for #70934
|
||||||
|
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
&([S][0],);
|
||||||
|
//~^ ERROR cannot move out of type `[S; 1]`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
12
src/test/ui/borrowck/move-error-in-promoted-2.stderr
Normal file
12
src/test/ui/borrowck/move-error-in-promoted-2.stderr
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
error[E0508]: cannot move out of type `[S; 1]`, a non-copy array
|
||||||
|
--> $DIR/move-error-in-promoted-2.rs:6:7
|
||||||
|
|
|
||||||
|
LL | &([S][0],);
|
||||||
|
| ^^^^^^
|
||||||
|
| |
|
||||||
|
| cannot move out of here
|
||||||
|
| move occurs because value has type `S`, which does not implement the `Copy` trait
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0508`.
|
17
src/test/ui/borrowck/move-error-in-promoted.rs
Normal file
17
src/test/ui/borrowck/move-error-in-promoted.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Regression test for #70934
|
||||||
|
|
||||||
|
fn f() {
|
||||||
|
const C: [S2; 1] = [S2];
|
||||||
|
let _ = S1(C[0]).clone();
|
||||||
|
//~^ ERROR cannot move out of type `[S2; 1]`
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct S1(S2);
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct S2;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
f();
|
||||||
|
}
|
12
src/test/ui/borrowck/move-error-in-promoted.stderr
Normal file
12
src/test/ui/borrowck/move-error-in-promoted.stderr
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
error[E0508]: cannot move out of type `[S2; 1]`, a non-copy array
|
||||||
|
--> $DIR/move-error-in-promoted.rs:5:16
|
||||||
|
|
|
||||||
|
LL | let _ = S1(C[0]).clone();
|
||||||
|
| ^^^^
|
||||||
|
| |
|
||||||
|
| cannot move out of here
|
||||||
|
| move occurs because value has type `S2`, which does not implement the `Copy` trait
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0508`.
|
Loading…
Reference in New Issue
Block a user