Generalize cases where specific move error ocurrs
Trigger new diagnostic in `compile-fail/regions-escape-bound-fn.rs` test, and not only in `compile-fail/regions-escape-bound-fn-2.rs`.
This commit is contained in:
parent
c31c60cbb9
commit
2c5f2df201
6 changed files with 11 additions and 9 deletions
|
|
@ -1071,8 +1071,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// #45983: when trying to assign the contents of an argument to a binding outside of a
|
||||
// closure, provide a specific message pointing this out.
|
||||
if let (&SubregionOrigin::BindingTypeIsNotValidAtDecl(ref external_span),
|
||||
&SubregionOrigin::Subtype(_),
|
||||
&RegionKind::ReFree(ref free_region)) = (&sub_origin, &sup_origin, sup_region) {
|
||||
&RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) {
|
||||
let hir = &self.tcx.hir;
|
||||
if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
|
||||
match hir.get(node_id) {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ fn expect_bound_supply_nothing() {
|
|||
// it to escape into `f`:
|
||||
let mut f: Option<&u32> = None;
|
||||
closure_expecting_bound(|x| {
|
||||
f = Some(x); //~ ERROR E0495
|
||||
f = Some(x); //~ ERROR borrowed data cannot be moved outside of its closure
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ fn expect_bound_supply_bound() {
|
|||
// closure:
|
||||
let mut f: Option<&u32> = None;
|
||||
closure_expecting_bound(|x: &u32| {
|
||||
f = Some(x); //~ ERROR E0495
|
||||
f = Some(x); //~ ERROR borrowed data cannot be moved outside of its closure
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ fn expect_bound_supply_named<'x>() {
|
|||
|
||||
// And we still cannot let `x` escape into `f`.
|
||||
f = Some(x);
|
||||
//~^ ERROR cannot infer
|
||||
//~^ ERROR borrowed data cannot be moved outside of its closure
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ impl CrateId {
|
|||
}
|
||||
|
||||
pub fn remove_package_from_database() {
|
||||
let mut lines_to_use: Vec<&CrateId> = Vec::new(); //~ ERROR E0495
|
||||
let mut lines_to_use: Vec<&CrateId> = Vec::new();
|
||||
//~^ ERROR borrowed data cannot be moved outside of its closure
|
||||
let push_id = |installed_id: &CrateId| {
|
||||
lines_to_use.push(installed_id);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,5 +16,5 @@ fn with_int<F>(f: F) where F: FnOnce(&isize) {
|
|||
fn main() {
|
||||
let mut x = None;
|
||||
with_int(|y| x = Some(y));
|
||||
//~^ ERROR borrowed data cannot be moved outside of its closure
|
||||
//~^ ERROR borrowed data cannot be moved outside of its closure
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,5 +15,6 @@ fn with_int<F>(f: F) where F: FnOnce(&isize) {
|
|||
|
||||
fn main() {
|
||||
let mut x: Option<&isize> = None;
|
||||
with_int(|y| x = Some(y)); //~ ERROR cannot infer
|
||||
with_int(|y| x = Some(y));
|
||||
//~^ ERROR borrowed data cannot be moved outside of its closure
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,5 +13,6 @@ fn with_int(f: &mut FnMut(&isize)) {
|
|||
|
||||
fn main() {
|
||||
let mut x: Option<&isize> = None;
|
||||
with_int(&mut |y| x = Some(y)); //~ ERROR cannot infer
|
||||
with_int(&mut |y| x = Some(y));
|
||||
//~^ ERROR borrowed data cannot be moved outside of its closure
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue