Drop tracking: track borrows of projections
Previous efforts to ignore partially consumed values meant we were also not considering borrows of a projection. This led to cases where we'd miss borrowed types which MIR expected to be there, leading to ICEs.
This commit is contained in:
parent
29185844c4
commit
97b24f3236
@ -116,6 +116,18 @@ fn hir_id(&self) -> HirId {
|
||||
TrackedValue::Variable(hir_id) | TrackedValue::Temporary(hir_id) => *hir_id,
|
||||
}
|
||||
}
|
||||
|
||||
fn from_place_with_projections_allowed(place_with_id: &PlaceWithHirId<'_>) -> Self {
|
||||
match place_with_id.place.base {
|
||||
PlaceBase::Rvalue | PlaceBase::StaticItem => {
|
||||
TrackedValue::Temporary(place_with_id.hir_id)
|
||||
}
|
||||
PlaceBase::Local(hir_id)
|
||||
| PlaceBase::Upvar(ty::UpvarId { var_path: ty::UpvarPath { hir_id }, .. }) => {
|
||||
TrackedValue::Variable(hir_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a reason why we might not be able to convert a HirId or Place
|
||||
@ -142,15 +154,7 @@ fn try_from(place_with_id: &PlaceWithHirId<'_>) -> Result<Self, Self::Error> {
|
||||
return Err(TrackedValueConversionError::PlaceProjectionsNotSupported);
|
||||
}
|
||||
|
||||
match place_with_id.place.base {
|
||||
PlaceBase::Rvalue | PlaceBase::StaticItem => {
|
||||
Ok(TrackedValue::Temporary(place_with_id.hir_id))
|
||||
}
|
||||
PlaceBase::Local(hir_id)
|
||||
| PlaceBase::Upvar(ty::UpvarId { var_path: ty::UpvarPath { hir_id }, .. }) => {
|
||||
Ok(TrackedValue::Variable(hir_id))
|
||||
}
|
||||
}
|
||||
Ok(TrackedValue::from_place_with_projections_allowed(place_with_id))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,9 +96,9 @@ fn borrow(
|
||||
_diag_expr_id: HirId,
|
||||
_bk: rustc_middle::ty::BorrowKind,
|
||||
) {
|
||||
place_with_id
|
||||
.try_into()
|
||||
.map_or(false, |tracked_value| self.places.borrowed.insert(tracked_value));
|
||||
self.places
|
||||
.borrowed
|
||||
.insert(TrackedValue::from_place_with_projections_allowed(place_with_id));
|
||||
}
|
||||
|
||||
fn mutate(
|
||||
|
12
src/test/ui/async-await/issue-93648.rs
Normal file
12
src/test/ui/async-await/issue-93648.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// edition:2021
|
||||
// build-pass
|
||||
// compile-flags: -Zdrop-tracking
|
||||
|
||||
fn main() {
|
||||
let _ = async {
|
||||
let mut s = (String::new(),);
|
||||
s.0.push_str("abc");
|
||||
std::mem::drop(s);
|
||||
async {}.await;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user