Implement ~const Destruct in new solver

This commit is contained in:
Michael Goulet 2024-10-29 20:08:55 +00:00
parent a7d9ebdf08
commit 59408add4d
16 changed files with 266 additions and 74 deletions

View file

@ -7,25 +7,13 @@ LL | impl const Drop for Panic { fn drop(&mut self) { panic!(); } }
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
= note: adding a non-const method body in the future would be a breaking change
error[E0716]: temporary value dropped while borrowed
--> $DIR/promoted_const_call.rs:10:26
|
LL | let _: &'static _ = &id(&Panic);
| ---------- ^^^^^^^^^^ creates a temporary value which is freed while still in use
| |
| type annotation requires that borrow lasts for `'static`
...
LL | };
| - temporary value is freed at the end of this statement
error[E0716]: temporary value dropped while borrowed
error[E0493]: destructor of `Panic` cannot be evaluated at compile-time
--> $DIR/promoted_const_call.rs:10:30
|
LL | let _: &'static _ = &id(&Panic);
| ---------- ^^^^^ - temporary value is freed at the end of this statement
| | |
| | creates a temporary value which is freed while still in use
| type annotation requires that borrow lasts for `'static`
| ^^^^^ - value is dropped here
| |
| the destructor for this type cannot be evaluated in constants
error[E0716]: temporary value dropped while borrowed
--> $DIR/promoted_const_call.rs:16:26
@ -69,6 +57,7 @@ LL | let _: &'static _ = &&(Panic, 0).1;
LL | }
| - temporary value is freed at the end of this statement
error: aborting due to 7 previous errors
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0716`.
Some errors have detailed explanations: E0493, E0716.
For more information about an error, try `rustc --explain E0493`.

View file

@ -72,6 +72,12 @@ note: required by a bound in `t::ConstDropWithBound`
LL | pub struct ConstDropWithBound<T: const SomeTrait>(pub core::marker::PhantomData<T>);
| ^^^^^ required by this bound in `ConstDropWithBound`
error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time
--> $DIR/const-drop.rs:23:13
|
LL | let _ = S(&mut c);
| ^^^^^^^^^ the destructor for this type cannot be evaluated in constant functions
error[E0493]: destructor of `T` cannot be evaluated at compile-time
--> $DIR/const-drop.rs:18:32
|
@ -84,7 +90,7 @@ error[E0277]: the trait bound `T: ~const SomeTrait` is not satisfied
LL | T::foo();
| ^^^^^^^^
error: aborting due to 10 previous errors
error: aborting due to 11 previous errors
Some errors have detailed explanations: E0277, E0493.
For more information about an error, try `rustc --explain E0277`.

View file

@ -72,6 +72,14 @@ note: required by a bound in `t::ConstDropWithBound`
LL | pub struct ConstDropWithBound<T: const SomeTrait>(pub core::marker::PhantomData<T>);
| ^^^^^ required by this bound in `ConstDropWithBound`
error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time
--> $DIR/const-drop.rs:23:13
|
LL | let _ = S(&mut c);
| ^^^^^^^^^- value is dropped here
| |
| the destructor for this type cannot be evaluated in constant functions
error[E0493]: destructor of `T` cannot be evaluated at compile-time
--> $DIR/const-drop.rs:18:32
|
@ -86,7 +94,7 @@ error[E0277]: the trait bound `T: ~const SomeTrait` is not satisfied
LL | T::foo();
| ^^^^^^^^
error: aborting due to 10 previous errors
error: aborting due to 11 previous errors
Some errors have detailed explanations: E0277, E0493.
For more information about an error, try `rustc --explain E0277`.

View file

@ -444,12 +444,12 @@ impl<T: ?Sized> Deref for Ref<'_, T> {
#[lang = "clone"]
#[rustc_trivial_field_reads]
// FIXME: #[const_trait]
#[const_trait]
pub trait Clone: Sized {
fn clone(&self) -> Self;
fn clone_from(&mut self, source: &Self)
where
// FIXME: Self: ~const Destruct,
Self: ~const Destruct,
{
*self = source.clone()
}
@ -458,7 +458,7 @@ pub trait Clone: Sized {
#[lang = "structural_peq"]
pub trait StructuralPartialEq {}
// FIXME: const fn drop<T: ~const Destruct>(_: T) {}
pub const fn drop<T: ~const Destruct>(_: T) {}
#[rustc_intrinsic_must_be_overridden]
#[rustc_intrinsic]

View file

@ -0,0 +1,37 @@
//@ aux-build:minicore.rs
//@ compile-flags: --crate-type=lib -Znext-solver
#![feature(no_core, const_trait_impl)]
#![no_std]
#![no_core]
extern crate minicore;
use minicore::*;
struct Contains<T>(T);
struct NotDropImpl;
impl Drop for NotDropImpl {
fn drop(&mut self) {}
}
#[const_trait] trait Foo {}
impl Foo for () {}
struct Conditional<T: Foo>(T);
impl<T> const Drop for Conditional<T> where T: ~const Foo {
fn drop(&mut self) {}
}
const fn test() {
let _ = NotDropImpl;
//~^ ERROR destructor of `NotDropImpl` cannot be evaluated at compile-time
let _ = Contains(NotDropImpl);
//~^ ERROR destructor of `Contains<NotDropImpl>` cannot be evaluated at compile-time
let _ = Conditional(());
//~^ ERROR destructor of `Conditional<()>` cannot be evaluated at compile-time
}
const fn drop_arbitrary<T>(_: T) {
//~^ ERROR destructor of `T` cannot be evaluated at compile-time
}

View file

@ -0,0 +1,36 @@
error[E0493]: destructor of `NotDropImpl` cannot be evaluated at compile-time
--> $DIR/minicore-drop-fail.rs:27:13
|
LL | let _ = NotDropImpl;
| ^^^^^^^^^^^- value is dropped here
| |
| the destructor for this type cannot be evaluated in constant functions
error[E0493]: destructor of `Contains<NotDropImpl>` cannot be evaluated at compile-time
--> $DIR/minicore-drop-fail.rs:29:13
|
LL | let _ = Contains(NotDropImpl);
| ^^^^^^^^^^^^^^^^^^^^^- value is dropped here
| |
| the destructor for this type cannot be evaluated in constant functions
error[E0493]: destructor of `Conditional<()>` cannot be evaluated at compile-time
--> $DIR/minicore-drop-fail.rs:31:13
|
LL | let _ = Conditional(());
| ^^^^^^^^^^^^^^^- value is dropped here
| |
| the destructor for this type cannot be evaluated in constant functions
error[E0493]: destructor of `T` cannot be evaluated at compile-time
--> $DIR/minicore-drop-fail.rs:35:28
|
LL | const fn drop_arbitrary<T>(_: T) {
| ^ the destructor for this type cannot be evaluated in constant functions
LL |
LL | }
| - value is dropped here
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0493`.