Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dropck can be bypassed via associated types #26657

Closed
arielb1 opened this issue Jun 29, 2015 · 0 comments
Closed

dropck can be bypassed via associated types #26657

arielb1 opened this issue Jun 29, 2015 · 0 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-destructors Area: Destructors (`Drop`, …)

Comments

@arielb1
Copy link
Contributor

arielb1 commented Jun 29, 2015

STR

// Using this instead of Fn etc. to take HRTB out of the equation.
trait Trigger<B> { fn fire(&self, b: &mut B); }
impl<B: Button> Trigger<B> for () {
    fn fire(&self, b: &mut B) {
        b.push();
    }
}

// Still unsound Zook
trait Button { fn push(&self); }
struct Zook<B: Button> { button: B }

impl<B: Button> Drop for Zook<B> {
    fn drop(&mut self) {
        self.button.push();
    }
}


trait Associator {
    type As;
}

impl<B: Button> Associator for B {
    type As = Zook<B>;
}
struct Wrap<A: Associator>(<A as Associator>::As);

// AND
struct Bomb { usable: bool }
impl Drop for Bomb { fn drop(&mut self) { self.usable = false; } }
impl Bomb { fn activate(&self) { assert!(self.usable) } }

enum B<'a> { HarmlessButton, BigRedButton(&'a Bomb) }
impl<'a> Button for B<'a> {
    fn push(&self) {
        if let B::BigRedButton(borrowed) = *self {
            borrowed.activate();
        }
    }
}

fn main() {
    let (mut w, ticking): (Wrap<B>, _);
    w = Wrap(Zook { button: B::HarmlessButton });
    ticking = Bomb { usable: true };
    w.0.button = B::BigRedButton(&ticking);
}

Notes

This seems like just an implementation bug to me - we should check that projections are also drop-valid. cc @pnkfelix.

@steveklabnik steveklabnik added the A-associated-items Area: Associated items (types, constants & functions) label Jul 6, 2015
@pnkfelix pnkfelix added the A-destructors Area: Destructors (`Drop`, …) label Jul 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-destructors Area: Destructors (`Drop`, …)
Projects
None yet
Development

No branches or pull requests

3 participants