Skip to content

Drop tracking ignores borrows with projections #93648

Closed
@tmiasko

Description

@tmiasko

For example:

fn main() {
    let _ = async {
        let mut s = (String::new(),);
        s.0.push_str("abc");
        std::mem::drop(s);
        async {}.await;
    };
}
$ rustc +nightly-2022-01-22 --edition=2021 b.rs
error: internal compiler error: compiler/rustc_mir_transform/src/generator.rs:755:13: Broken MIR: generator contains type (String,) in MIR, but typeck only knows about {ResumeTy, impl Future<Output = [async output]>, ()} and []

The TryFrom<&PlaceWithHirId<'_>> for TrackedValue fails for places with projections, so in that case borrow is never recorded:

impl TryFrom<&PlaceWithHirId<'_>> for TrackedValue {
type Error = TrackedValueConversionError;
fn try_from(place_with_id: &PlaceWithHirId<'_>) -> Result<Self, Self::Error> {
if !place_with_id.place.projections.is_empty() {
debug!(
"TrackedValue from PlaceWithHirId: {:?} has projections, which are not supported.",
place_with_id
);
return Err(TrackedValueConversionError::PlaceProjectionsNotSupported);
}

fn borrow(
&mut self,
place_with_id: &expr_use_visitor::PlaceWithHirId<'tcx>,
_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));
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions