rust/src/test/ui/rfc-2632-const-trait-impl/const-drop.rs

29 lines
428 B
Rust
Raw Normal View History

2021-09-01 08:07:49 -05:00
// run-pass
2021-09-01 06:55:16 -05:00
#![feature(const_trait_impl)]
#![feature(const_fn_trait_bound)]
#![feature(const_mut_refs)]
#![feature(const_panic)]
2021-09-01 08:07:49 -05:00
struct S<'a>(&'a mut u8);
2021-09-01 06:55:16 -05:00
2021-09-01 08:07:49 -05:00
impl<'a> const Drop for S<'a> {
2021-09-01 06:55:16 -05:00
fn drop(&mut self) {
2021-09-01 08:07:49 -05:00
*self.0 += 1;
2021-09-01 06:55:16 -05:00
}
}
const fn a<T: ~const Drop>(_: T) {}
2021-09-01 08:07:49 -05:00
const fn b() -> u8 {
let mut c = 0;
let _ = S(&mut c);
a(S(&mut c));
c
}
const C: u8 = b();
2021-09-01 06:55:16 -05:00
2021-09-01 08:07:49 -05:00
fn main() {
assert_eq!(C, 2);
}