Skip to content

Erase regions when checking for missing Copy predicates #94688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
self.mir_hir_id(),
rustc_infer::traits::ObligationCauseCode::MiscObligation,
);
fulfill_cx.register_bound(&infcx, self.param_env, ty, copy_did, cause);
let errors = fulfill_cx.select_where_possible(&infcx);
fulfill_cx.register_bound(
&infcx,
self.param_env,
// Erase any region vids from the type, which may not be resolved
infcx.tcx.erase_regions(ty),
copy_did,
cause,
);
// Select all, including ambiguous predicates
let errors = fulfill_cx.select_all_or_error(&infcx);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a drive-by, I can revert it if it's useless. I thought we should also process ambiguous predicates below, not just the definitely-error ones.


// Only emit suggestion if all required predicates are on generic
errors
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/borrowck/copy-suggestion-region-vid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub struct DataStruct();

pub struct HelperStruct<'n> {
pub helpers: [Vec<&'n i64>; 2],
pub is_empty: bool,
}

impl DataStruct {
pub fn f(&self) -> HelperStruct {
let helpers = [vec![], vec![]];

HelperStruct { helpers, is_empty: helpers[0].is_empty() }
//~^ ERROR borrow of moved value
}
}

fn main() {}
14 changes: 14 additions & 0 deletions src/test/ui/borrowck/copy-suggestion-region-vid.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0382]: borrow of moved value: `helpers`
--> $DIR/copy-suggestion-region-vid.rs:12:43
|
LL | let helpers = [vec![], vec![]];
| ------- move occurs because `helpers` has type `[Vec<&i64>; 2]`, which does not implement the `Copy` trait
LL |
LL | HelperStruct { helpers, is_empty: helpers[0].is_empty() }
| ------- ^^^^^^^^^^^^^^^^^^^^^ value borrowed here after move
| |
| value moved here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0382`.