diff options
| author | Michael Goulet <michael@errs.io> | 2023-09-02 04:33:58 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-09-02 04:58:23 +0000 |
| commit | 7a6b52bf0d29b614df0e9528798462ad8ab53d7e (patch) | |
| tree | 77ff188009c1643d0e26f96e3aca2a7ff945637b /tests/ui/impl-trait | |
| parent | 361f8ba847af0288b1beb3b84f6b7b4d3850bb43 (diff) | |
| download | rust-7a6b52bf0d29b614df0e9528798462ad8ab53d7e.tar.gz rust-7a6b52bf0d29b614df0e9528798462ad8ab53d7e.zip | |
RPITITs are considered object-safe, they're always on Self:Sized methods
Diffstat (limited to 'tests/ui/impl-trait')
| -rw-r--r-- | tests/ui/impl-trait/in-trait/issue-102140.stderr | 6 | ||||
| -rw-r--r-- | tests/ui/impl-trait/in-trait/object-safety-sized.rs | 23 | ||||
| -rw-r--r-- | tests/ui/impl-trait/in-trait/object-safety.rs | 1 | ||||
| -rw-r--r-- | tests/ui/impl-trait/in-trait/object-safety.stderr | 17 |
4 files changed, 29 insertions, 18 deletions
diff --git a/tests/ui/impl-trait/in-trait/issue-102140.stderr b/tests/ui/impl-trait/in-trait/issue-102140.stderr index 5d55b9fa4f9..18bb63745d7 100644 --- a/tests/ui/impl-trait/in-trait/issue-102140.stderr +++ b/tests/ui/impl-trait/in-trait/issue-102140.stderr @@ -6,7 +6,11 @@ LL | MyTrait::foo(&self) | | | required by a bound introduced by this call | - = help: the trait `MyTrait` is implemented for `Outer` +help: consider removing the leading `&`-reference + | +LL - MyTrait::foo(&self) +LL + MyTrait::foo(self) + | error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied --> $DIR/issue-102140.rs:23:9 diff --git a/tests/ui/impl-trait/in-trait/object-safety-sized.rs b/tests/ui/impl-trait/in-trait/object-safety-sized.rs new file mode 100644 index 00000000000..f221cfbb176 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/object-safety-sized.rs @@ -0,0 +1,23 @@ +// check-pass +// revisions: current next +//[next] compile-flags: -Ztrait-solver=next + +#![feature(return_position_impl_trait_in_trait)] + +fn main() { + let vec: Vec<Box<dyn Trait>> = Vec::new(); + + for i in vec { + i.fn_2(); + } +} + +trait OtherTrait {} + +trait Trait { + fn fn_1(&self) -> impl OtherTrait + where + Self: Sized; + + fn fn_2(&self) -> bool; +} diff --git a/tests/ui/impl-trait/in-trait/object-safety.rs b/tests/ui/impl-trait/in-trait/object-safety.rs index 9a231e59b09..dd35b9a2d8a 100644 --- a/tests/ui/impl-trait/in-trait/object-safety.rs +++ b/tests/ui/impl-trait/in-trait/object-safety.rs @@ -19,5 +19,4 @@ fn main() { //~| ERROR the trait `Foo` cannot be made into an object let s = i.baz(); //~^ ERROR the trait `Foo` cannot be made into an object - //~| ERROR the trait `Foo` cannot be made into an object } diff --git a/tests/ui/impl-trait/in-trait/object-safety.stderr b/tests/ui/impl-trait/in-trait/object-safety.stderr index 0170dc5d0fc..4a3b3b11465 100644 --- a/tests/ui/impl-trait/in-trait/object-safety.stderr +++ b/tests/ui/impl-trait/in-trait/object-safety.stderr @@ -14,21 +14,6 @@ LL | fn baz(&self) -> impl Debug; = help: consider moving `baz` to another trait error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety.rs:20:15 - | -LL | let s = i.baz(); - | ^^^ `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/object-safety.rs:7:22 - | -LL | trait Foo { - | --- this trait cannot be made into an object... -LL | fn baz(&self) -> impl Debug; - | ^^^^^^^^^^ ...because method `baz` references an `impl Trait` type in its return type - = help: consider moving `baz` to another trait - -error[E0038]: the trait `Foo` cannot be made into an object --> $DIR/object-safety.rs:20:13 | LL | let s = i.baz(); @@ -59,6 +44,6 @@ LL | fn baz(&self) -> impl Debug; = help: consider moving `baz` to another trait = note: required for the cast from `Box<u32>` to `Box<dyn Foo>` -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0038`. |
