diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2020-01-19 17:27:37 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2020-02-02 11:52:34 -0800 |
| commit | d72bcdb42cc10a20c2eef49e5f8cd2782f44b922 (patch) | |
| tree | 9342efd73bc0a1d7a35281d8e3258bfbceed6b8d /src/test | |
| parent | 1c9242f83fdea3e4c7a452d1453370ee81a900af (diff) | |
| download | rust-d72bcdb42cc10a20c2eef49e5f8cd2782f44b922.tar.gz rust-d72bcdb42cc10a20c2eef49e5f8cd2782f44b922.zip | |
When object unsafe trait uses itself in associated item suggest using `Self`
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/suggestions/object-unsafe-trait-should-use-self.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr | 47 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/object-unsafe-trait-should-use-self.rs b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.rs new file mode 100644 index 00000000000..75f99075eb1 --- /dev/null +++ b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.rs @@ -0,0 +1,16 @@ +#![allow(bare_trait_objects)] +trait A: Sized { + fn f(a: A) -> A; + //~^ ERROR associated item referring to unboxed trait object for its own trait + //~| ERROR the trait `A` cannot be made into an object +} +trait B { + fn f(a: B) -> B; + //~^ ERROR associated item referring to unboxed trait object for its own trait + //~| ERROR the trait `B` cannot be made into an object +} +trait C { + fn f(&self, a: C) -> C; +} + +fn main() {} diff --git a/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr new file mode 100644 index 00000000000..70d069d2aa2 --- /dev/null +++ b/src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr @@ -0,0 +1,47 @@ +error: associated item referring to unboxed trait object for its own trait + --> $DIR/object-unsafe-trait-should-use-self.rs:3:13 + | +LL | trait A: Sized { + | - in this trait +LL | fn f(a: A) -> A; + | ^ ^ + | +help: you might have meant to use `Self` to refer to the materialized type + | +LL | fn f(a: Self) -> Self; + | ^^^^ ^^^^ + +error[E0038]: the trait `A` cannot be made into an object + --> $DIR/object-unsafe-trait-should-use-self.rs:3:13 + | +LL | trait A: Sized { + | ----- the trait cannot require that `Self : Sized` +LL | fn f(a: A) -> A; + | ^ the trait `A` cannot be made into an object + | + = note: the trait cannot require that `Self : Sized` + +error: associated item referring to unboxed trait object for its own trait + --> $DIR/object-unsafe-trait-should-use-self.rs:8:13 + | +LL | trait B { + | - in this trait +LL | fn f(a: B) -> B; + | ^ ^ + | +help: you might have meant to use `Self` to refer to the materialized type + | +LL | fn f(a: Self) -> Self; + | ^^^^ ^^^^ + +error[E0038]: the trait `B` cannot be made into an object + --> $DIR/object-unsafe-trait-should-use-self.rs:8:13 + | +LL | fn f(a: B) -> B; + | - ^ the trait `B` cannot be made into an object + | | + | associated function `f` has no `self` parameter + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0038`. |
