Skip to content

Drop: model #[may_dangle] / dropck eyepatch #424

Description

@nikomatsakis

Description

The "dropck eyepatch" (#[may_dangle]) allows a Drop impl to declare that it won't access the data behind certain generic parameters during drop. This relaxes the borrow checker's requirements.

unsafe impl<#[may_dangle] T> Drop for Vec<T> {
    fn drop(&mut self) { /* deallocates memory but doesn't read T values */ }
}

Without #[may_dangle], the borrow checker would require that T outlives the Vec<T> value. With it, T is allowed to dangle.

Mentoring notes

Background: Read the Nomicon section on dropck and RFC 1327.

Where to start:

  1. Add #[may_dangle] as an attribute on type parameters in Drop impls (grammar change)
  2. In the drop-glue checking logic (depends on "detect implicit use" above), skip the outlives requirement for parameters marked #[may_dangle]

Prerequisite: "Detect implicit use at scope exit" must be implemented first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    so you want a challengeChallenging projects for people who are committed.

    Type

    No type

    Projects

    Status
    Needs triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions