1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Issue #26656: Verify that trait objects cannot bypass dropck.
13 // Using this instead of Fn etc. to take HRTB out of the equation.
14 trait Trigger
<B
> { fn fire(&self, b: &mut B); }
15 impl<B
: Button
> Trigger
<B
> for () {
16 fn fire(&self, b
: &mut B
) {
22 trait Button { fn push(&self); }
23 struct Zook
<B
> { button: B, trigger: Box<Trigger<B>+'static> }
25 impl<B
> Drop
for Zook
<B
> {
27 self.trigger
.fire(&mut self.button
);
32 struct Bomb { usable: bool }
33 impl Drop
for Bomb { fn drop(&mut self) { self.usable = false; }
}
34 impl Bomb { fn activate(&self) { assert!(self.usable) }
}
36 enum B
<'a
> { HarmlessButton, BigRedButton(&'a Bomb) }
37 impl<'a
> Button
for B
<'a
> {
39 if let B
::BigRedButton(borrowed
) = *self {
46 let (mut zook
, ticking
);
47 zook
= Zook
{ button
: B
::HarmlessButton
,
48 trigger
: Box
::new(()) };
49 ticking
= Bomb { usable: true }
;
50 zook
.button
= B
::BigRedButton(&ticking
);
52 //~^^ ERROR `ticking` does not live long enough