Skip to content

Commit c0c452b

Browse files
authored
Rollup merge of rust-lang#94688 - compiler-errors:free-regions-in-copy-predicate-check, r=oli-obk
Erase regions when checking for missing Copy predicates Fixes rust-lang#94662
2 parents a795f0f + 5ddaa2d commit c0c452b

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
448448
self.mir_hir_id(),
449449
rustc_infer::traits::ObligationCauseCode::MiscObligation,
450450
);
451-
fulfill_cx.register_bound(&infcx, self.param_env, ty, copy_did, cause);
452-
let errors = fulfill_cx.select_where_possible(&infcx);
451+
fulfill_cx.register_bound(
452+
&infcx,
453+
self.param_env,
454+
// Erase any region vids from the type, which may not be resolved
455+
infcx.tcx.erase_regions(ty),
456+
copy_did,
457+
cause,
458+
);
459+
// Select all, including ambiguous predicates
460+
let errors = fulfill_cx.select_all_or_error(&infcx);
453461

454462
// Only emit suggestion if all required predicates are on generic
455463
errors
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub struct DataStruct();
2+
3+
pub struct HelperStruct<'n> {
4+
pub helpers: [Vec<&'n i64>; 2],
5+
pub is_empty: bool,
6+
}
7+
8+
impl DataStruct {
9+
pub fn f(&self) -> HelperStruct {
10+
let helpers = [vec![], vec![]];
11+
12+
HelperStruct { helpers, is_empty: helpers[0].is_empty() }
13+
//~^ ERROR borrow of moved value
14+
}
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0382]: borrow of moved value: `helpers`
2+
--> $DIR/copy-suggestion-region-vid.rs:12:43
3+
|
4+
LL | let helpers = [vec![], vec![]];
5+
| ------- move occurs because `helpers` has type `[Vec<&i64>; 2]`, which does not implement the `Copy` trait
6+
LL |
7+
LL | HelperStruct { helpers, is_empty: helpers[0].is_empty() }
8+
| ------- ^^^^^^^^^^^^^^^^^^^^^ value borrowed here after move
9+
| |
10+
| value moved here
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)