Auto merge of #81089 - m-ou-se:rollup-z7iac6i, r=m-ou-se
Rollup of 17 pull requests Successful merges: - #78455 (Introduce {Ref, RefMut}::try_map for optional projections in RefCell) - #80144 (Remove giant badge in README) - #80614 (Explain why borrows can't be held across yield point in async blocks) - #80670 (TrustedRandomAaccess specialization composes incorrectly for nested iter::Zips) - #80681 (Clarify what the effects of a 'logic error' are) - #80764 (Re-stabilize Weak::as_ptr and friends for unsized T) - #80901 (Make `x.py --color always` apply to logging too) - #80902 (Add a regression test for #76281) - #80941 (Do not suggest invalid code in pattern with loop) - #80968 (Stabilize the poll_map feature) - #80971 (Put all feature gate tests under `feature-gates/`) - #81021 (Remove doctree::Import) - #81040 (doctest: Reset errors before dropping the parse session) - #81060 (Add a regression test for #50041) - #81065 (codegen_cranelift: Fix redundant semicolon warn) - #81069 (Add sample code for Rc::new_cyclic) - #81081 (Add test for #34792) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
8a6518427e
38 changed files with 615 additions and 234 deletions
|
@ -824,7 +824,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
|||
}
|
||||
ty => unreachable!("bswap {}", ty),
|
||||
}
|
||||
};
|
||||
}
|
||||
let res = CValue::by_val(swap(&mut fx.bcx, arg), fx.layout_of(T));
|
||||
ret.write_cvalue(fx, res);
|
||||
};
|
||||
|
|
|
@ -50,3 +50,24 @@ fn foo() -> Box<Fn(u32) -> u32> {
|
|||
|
||||
Now that the closure has its own copy of the data, there's no need to worry
|
||||
about safety.
|
||||
|
||||
This error may also be encountered while using `async` blocks:
|
||||
|
||||
```compile_fail,E0373,edition2018
|
||||
use std::future::Future;
|
||||
|
||||
async fn f() {
|
||||
let v = vec![1, 2, 3i32];
|
||||
spawn(async { //~ ERROR E0373
|
||||
println!("{:?}", v)
|
||||
});
|
||||
}
|
||||
|
||||
fn spawn<F: Future + Send + 'static>(future: F) {
|
||||
unimplemented!()
|
||||
}
|
||||
```
|
||||
|
||||
Similarly to closures, `async` blocks are not executed immediately and may
|
||||
capture closed-over data by reference. For more information, see
|
||||
https://rust-lang.github.io/async-book/03_async_await/01_chapter.html.
|
||||
|
|
|
@ -141,6 +141,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
self.add_moved_or_invoked_closure_note(location, used_place, &mut err);
|
||||
|
||||
let mut is_loop_move = false;
|
||||
let mut in_pattern = false;
|
||||
|
||||
for move_site in &move_site_vec {
|
||||
let move_out = self.move_data.moves[(*move_site).moi];
|
||||
|
@ -256,6 +257,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
"ref ".to_string(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
in_pattern = true;
|
||||
}
|
||||
|
||||
if let Some(DesugaringKind::ForLoop(_)) = move_span.desugaring_kind() {
|
||||
|
@ -302,7 +304,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
let place = &self.move_data.move_paths[mpi].place;
|
||||
let ty = place.ty(self.body, self.infcx.tcx).ty;
|
||||
|
||||
if is_loop_move {
|
||||
// If we're in pattern, we do nothing in favor of the previous suggestion (#80913).
|
||||
if is_loop_move & !in_pattern {
|
||||
if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
|
||||
// We have a `&mut` ref, we need to reborrow on each iteration (#62112).
|
||||
err.span_suggestion_verbose(
|
||||
|
@ -1318,21 +1321,30 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
Applicability::MachineApplicable,
|
||||
);
|
||||
|
||||
let msg = match category {
|
||||
match category {
|
||||
ConstraintCategory::Return(_) | ConstraintCategory::OpaqueType => {
|
||||
format!("{} is returned here", kind)
|
||||
let msg = format!("{} is returned here", kind);
|
||||
err.span_note(constraint_span, &msg);
|
||||
}
|
||||
ConstraintCategory::CallArgument => {
|
||||
fr_name.highlight_region_name(&mut err);
|
||||
format!("function requires argument type to outlive `{}`", fr_name)
|
||||
if matches!(use_span.generator_kind(), Some(GeneratorKind::Async(_))) {
|
||||
err.note(
|
||||
"async blocks are not executed immediately and must either take a \
|
||||
reference or ownership of outside variables they use",
|
||||
);
|
||||
} else {
|
||||
let msg = format!("function requires argument type to outlive `{}`", fr_name);
|
||||
err.span_note(constraint_span, &msg);
|
||||
}
|
||||
}
|
||||
_ => bug!(
|
||||
"report_escaping_closure_capture called with unexpected constraint \
|
||||
category: `{:?}`",
|
||||
category
|
||||
),
|
||||
};
|
||||
err.span_note(constraint_span, &msg);
|
||||
}
|
||||
|
||||
err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue