Open
Description
Given the following code (playground):
trait A {}
trait B {
fn f(&self)
where
Self: A,
{
}
}
struct S;
impl B for S {}
fn main() {
let _p = &S as &dyn B;
}
The current output is:
warning: the trait `B` cannot be made into an object
--> src/main.rs:4:8
|
4 | fn f(&self)
| ^
|
= note: `#[warn(where_clauses_object_safety)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>
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>
--> src/main.rs:4:8
|
3 | trait B {
| - this trait cannot be made into an object...
4 | fn f(&self)
| ^ ...because method `f` references the `Self` type in its `where` clause
= help: consider moving `f` to another trait
The first part of the error message should refer to line 16, in main()
, where the program tries to make a trait B
object. Other 'object safety' errors do this correctly (e.g. if trait B
is not object-safe because one of its methods has Self
in return position).
S: #51443