better test
This commit is contained in:
parent
48a3ba9a33
commit
894ce921a0
2 changed files with 15 additions and 35 deletions
|
@ -1,23 +1,28 @@
|
||||||
|
// run-pass
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
#![feature(const_fn_trait_bound)]
|
#![feature(const_fn_trait_bound)]
|
||||||
#![feature(const_mut_refs)]
|
#![feature(const_mut_refs)]
|
||||||
#![feature(const_panic)]
|
#![feature(const_panic)]
|
||||||
|
|
||||||
struct S;
|
struct S<'a>(&'a mut u8);
|
||||||
|
|
||||||
impl const Drop for S {
|
impl<'a> const Drop for S<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// NB: There is no way to tell that a const destructor is ran,
|
*self.0 += 1;
|
||||||
// because even if we can operate on mutable variables, it will
|
|
||||||
// not be reflected because everything is `const`. So we panic
|
|
||||||
// here, attempting to make the CTFE engine error.
|
|
||||||
panic!("much const drop")
|
|
||||||
//~^ ERROR evaluation of constant value failed
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn a<T: ~const Drop>(_: T) {}
|
const fn a<T: ~const Drop>(_: T) {}
|
||||||
|
|
||||||
const _: () = a(S);
|
const fn b() -> u8 {
|
||||||
|
let mut c = 0;
|
||||||
|
let _ = S(&mut c);
|
||||||
|
a(S(&mut c));
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
const C: u8 = b();
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
assert_eq!(C, 2);
|
||||||
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
error[E0080]: evaluation of constant value failed
|
|
||||||
--> $DIR/const-drop.rs:14:9
|
|
||||||
|
|
|
||||||
LL | panic!("much const drop")
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
| |
|
|
||||||
| the evaluated program panicked at 'much const drop', $DIR/const-drop.rs:14:9
|
|
||||||
| inside `<S as Drop>::drop` at $SRC_DIR/std/src/panic.rs:LL:COL
|
|
||||||
...
|
|
||||||
LL | const fn a<T: ~const Drop>(_: T) {}
|
|
||||||
| - inside `a::<S>` at $DIR/const-drop.rs:19:35
|
|
||||||
LL |
|
|
||||||
LL | const _: () = a(S);
|
|
||||||
| ---- inside `_` at $DIR/const-drop.rs:21:15
|
|
||||||
|
|
|
||||||
::: $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
|
||||||
|
|
|
||||||
LL | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
|
|
||||||
| ------------------------------------------------------- inside `std::ptr::drop_in_place::<S> - shim(Some(S))` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
|
||||||
|
|
|
||||||
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0080`.
|
|
Loading…
Add table
Add a link
Reference in a new issue