Auto merge of #107844 - Zeegomo:no-drop-and-rep, r=cjgillot
Desugaring of drop and replace at MIR build This commit desugars the drop and replace deriving from an assignment at MIR build, avoiding the construction of the `DropAndReplace` terminator (which will be removed in a following PR). In order to retain the same error messages for replaces a new `DesugaringKind::Replace` variant is introduced. The changes in the borrowck are also useful for future work in moving drop elaboration before borrowck, as no `DropAndReplace` would be present there anymore. Notes on test diffs: * `tests/ui/borrowck/issue-58776-borrowck-scans-children`: the assignment deriving from the desugaring kills the borrow. * `tests/ui/async-await/async-fn-size-uninit-locals.rs`, `tests/mir-opt/issue_41110.test.ElaborateDrops.after.mir`, `tests/mir-opt/issue_41888.main.ElaborateDrops.after.mir`: drop elaboration generates (or reads from) a useless drop flag due to an issue with the dataflow analysis. Will be fixed independently by https://github.com/rust-lang/rust/pull/106430. See https://github.com/rust-lang/rust/pull/104488 for more context
This commit is contained in:
commit
14c54b637b
22 changed files with 286 additions and 157 deletions
|
@ -14,7 +14,7 @@ use rustc_mir_dataflow::un_derefer::UnDerefer;
|
|||
use rustc_mir_dataflow::MoveDataParamEnv;
|
||||
use rustc_mir_dataflow::{on_all_children_bits, on_all_drop_children_bits};
|
||||
use rustc_mir_dataflow::{Analysis, ResultsCursor};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{DesugaringKind, Span};
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use std::fmt;
|
||||
|
||||
|
@ -425,10 +425,19 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
|
|||
bb,
|
||||
),
|
||||
LookupResult::Parent(..) => {
|
||||
self.tcx.sess.delay_span_bug(
|
||||
terminator.source_info.span,
|
||||
&format!("drop of untracked value {:?}", bb),
|
||||
);
|
||||
if !matches!(
|
||||
terminator.source_info.span.desugaring_kind(),
|
||||
Some(DesugaringKind::Replace),
|
||||
) {
|
||||
self.tcx.sess.delay_span_bug(
|
||||
terminator.source_info.span,
|
||||
&format!("drop of untracked value {:?}", bb),
|
||||
);
|
||||
}
|
||||
// A drop and replace behind a pointer/array/whatever.
|
||||
// The borrow checker requires that these locations are initialized before the assignment,
|
||||
// so we just leave an unconditional drop.
|
||||
assert!(!data.is_cleanup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue