Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 17, 2024
1 parent f75bcf3 commit bf2a126
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/ui/object-safety/erroneous_signature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
trait Foo {
fn err(&self) -> MissingType;
//~^ ERROR cannot find type `MissingType` in this scope
}

impl Foo for i32 {
fn err(&self) -> MissingType {
//~^ ERROR cannot find type `MissingType` in this scope
0
}
}

fn coerce(x: &i32) -> &dyn Foo {
//~^ ERROR `Foo` cannot be made into an object
x
}

fn main() {}
32 changes: 32 additions & 0 deletions tests/ui/object-safety/erroneous_signature.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error[E0412]: cannot find type `MissingType` in this scope
--> $DIR/erroneous_signature.rs:2:22
|
LL | fn err(&self) -> MissingType;
| ^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `MissingType` in this scope
--> $DIR/erroneous_signature.rs:7:22
|
LL | fn err(&self) -> MissingType {
| ^^^^^^^^^^^ not found in this scope

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/erroneous_signature.rs:13:24
|
LL | fn coerce(x: &i32) -> &dyn Foo {
| ^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/erroneous_signature.rs:2:8
|
LL | trait Foo {
| --- this trait cannot be made into an object...
LL | fn err(&self) -> MissingType;
| ^^^ ...because method `err` has errors in its signature
= help: consider moving `err` to another trait
= help: only type `i32` implements the trait, consider using it directly instead

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0038, E0412.
For more information about an error, try `rustc --explain E0038`.

0 comments on commit bf2a126

Please sign in to comment.