add tests for structured suggestion

This commit is contained in:
Esteban Küber 2020-01-31 19:04:58 -08:00
parent a52ec87a17
commit 542130bde9
5 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,12 @@
trait Trait {
fn baz(&self, _: Self) {}
fn bat(&self) -> Self {}
}
fn bar(x: &dyn Trait) {} //~ ERROR the trait `Trait` cannot be made into an object
trait Other: Sized {}
fn foo(x: &dyn Other) {} //~ ERROR the trait `Other` cannot be made into an object
fn main() {}

View File

@ -0,0 +1,30 @@
error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/object-unsafe-trait-references-self.rs:6:11
|
LL | trait Trait {
| ----- this trait cannot be made into an object...
LL | fn baz(&self, _: Self) {}
| ---- ...because method `baz` references the `Self` type in this parameter
LL | fn bat(&self) -> Self {}
| ---- ...because method `bat` references the `Self` type in its return type
...
LL | fn bar(x: &dyn Trait) {}
| ^^^^^^^^^^ the trait `Trait` cannot be made into an object
|
= help: consider moving `baz` to another trait
= help: consider moving `bat` to another trait
error[E0038]: the trait `Other` cannot be made into an object
--> $DIR/object-unsafe-trait-references-self.rs:10:11
|
LL | trait Other: Sized {}
| ----- ----- ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
LL |
LL | fn foo(x: &dyn Other) {}
| ^^^^^^^^^^ the trait `Other` cannot be made into an object
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0038`.

View File

@ -0,0 +1,13 @@
// run-rustfix
#![allow(unused_variables, dead_code)]
trait Trait {
fn foo() where Self: Other, Self: Sized, { }
fn bar(self: &Self) {} //~ ERROR invalid `self` parameter type
}
fn bar(x: &dyn Trait) {} //~ ERROR the trait `Trait` cannot be made into an object
trait Other {}
fn main() {}

View File

@ -0,0 +1,13 @@
// run-rustfix
#![allow(unused_variables, dead_code)]
trait Trait {
fn foo() where Self: Other, { }
fn bar(self: ()) {} //~ ERROR invalid `self` parameter type
}
fn bar(x: &dyn Trait) {} //~ ERROR the trait `Trait` cannot be made into an object
trait Other {}
fn main() {}

View File

@ -0,0 +1,35 @@
error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/object-unsafe-trait-should-use-where-sized.rs:9:11
|
LL | trait Trait {
| ----- this trait cannot be made into an object...
LL | fn foo() where Self: Other, { }
| --- ...because associated function `foo` has no `self` parameter
LL | fn bar(self: ()) {}
| -- ...because method `bar`'s `self` parameter cannot be dispatched on
...
LL | fn bar(x: &dyn Trait) {}
| ^^^^^^^^^^ the trait `Trait` cannot be made into an object
|
help: consider turning `foo` into a method by giving it a `&self` argument or constraining it so it does not apply to trait objects
|
LL | fn foo() where Self: Other, Self: Sized, { }
| ^^^^^^^^^^^^^
help: consider changing method `bar`'s `self` parameter to be `&self`
|
LL | fn bar(self: &Self) {}
| ^^^^^
error[E0307]: invalid `self` parameter type: ()
--> $DIR/object-unsafe-trait-should-use-where-sized.rs:6:18
|
LL | fn bar(self: ()) {}
| ^^
|
= note: type of `self` must be `Self` or a type that dereferences to it
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0038, E0307.
For more information about an error, try `rustc --explain E0038`.