Skip to content

Commit

Permalink
introduce tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Jul 1, 2024
1 parent 221e274 commit 1f41fbe
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/ui/dropck/const_drop_is_valid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![feature(effects)]
//~^ WARN: the feature `effects` is incomplete

struct A();

impl const Drop for A {}
//~^ ERROR: const trait impls are experimental
//~| const `impl` for trait `Drop` which is not marked with `#[const_trait]`
//~| not all trait items implemented, missing: `drop`

fn main() {}
45 changes: 45 additions & 0 deletions tests/ui/dropck/const_drop_is_valid.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
error[E0658]: const trait impls are experimental
--> $DIR/const_drop_is_valid.rs:6:6
|
LL | impl const Drop for A {}
| ^^^^^
|
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/const_drop_is_valid.rs:1:12
|
LL | #![feature(effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default

error: using `#![feature(effects)]` without enabling next trait solver globally
|
= note: the next trait solver must be enabled globally for the effects feature to work correctly
= help: use `-Znext-solver` to enable

error: const `impl` for trait `Drop` which is not marked with `#[const_trait]`
--> $DIR/const_drop_is_valid.rs:6:12
|
LL | impl const Drop for A {}
| ^^^^
|
= 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[E0046]: not all trait items implemented, missing: `drop`
--> $DIR/const_drop_is_valid.rs:6:1
|
LL | impl const Drop for A {}
| ^^^^^^^^^^^^^^^^^^^^^ missing `drop` in implementation
|
= help: implement the missing item: `fn drop(&mut self) { todo!() }`

error: aborting due to 4 previous errors; 1 warning emitted

Some errors have detailed explanations: E0046, E0658.
For more information about an error, try `rustc --explain E0046`.
12 changes: 12 additions & 0 deletions tests/ui/dropck/constrained_by_assoc_type_equality.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
struct Foo<T: Trait>(T);

trait Trait {
type Assoc;
}

impl<T: Trait<Assoc = U>, U: ?Sized> Drop for Foo<T> {
//~^ ERROR: `Drop` impl requires `<T as Trait>::Assoc == U`
fn drop(&mut self) {}
}

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/dropck/constrained_by_assoc_type_equality.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0367]: `Drop` impl requires `<T as Trait>::Assoc == U` but the struct it is implemented for does not
--> $DIR/constrained_by_assoc_type_equality.rs:7:15
|
LL | impl<T: Trait<Assoc = U>, U: ?Sized> Drop for Foo<T> {
| ^^^^^^^^^
|
note: the implementor must specify the same requirement
--> $DIR/constrained_by_assoc_type_equality.rs:1:1
|
LL | struct Foo<T: Trait>(T);
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0367`.
8 changes: 8 additions & 0 deletions tests/ui/dropck/unconstrained_const_param_on_drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ known-bug: unknown
//@ failure-status: 101

struct Foo {}

impl<const UNUSED: usize> Drop for Foo {}

fn main() {}
Loading

0 comments on commit 1f41fbe

Please sign in to comment.