rust-analyzer incorrectly hints that a trait with an associated type that is generic over a lifetime is object safe, which conflicts with rustc saying the trait is not objects safe.
editor or extension: VSCode rust-analyzer v0.4.2114 (pre-release)
code snippet to reproduce:
trait Foo {
type Bar<'a>;
}
fn main() {
let baz: &dyn Foo = todo!();
}
When hovering trait Foo (#17779), rust-analyzer claims // Object Safety: Yes; however, compiling this code yields this error which explicitly says trait Foo is not object safe:
https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> src/main.rs:2:10
|
1 | trait Foo {
| --- this trait cannot be made into an object...
2 | type Bar<'a>;
| ^^^ ...because it contains the generic associated type `Bar`
= help: consider moving `Bar` to another trait
error[E0038]: the trait `Foo` cannot be made into an object
--> src/main.rs:6:14
|
6 | let baz: &dyn Foo = todo!();
| ^^^^^^^^ `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>
--> src/main.rs:2:10
|
1 | trait Foo {
| --- this trait cannot be made into an object...
2 | type Bar<'a>;
| ^^^ ...because it contains the generic associated type `Bar`
= help: consider moving `Bar` to another trait
For more information about this error, try `rustc --explain E0038`.
rust-analyzer incorrectly hints that a trait with an associated type that is generic over a lifetime is object safe, which conflicts with rustc saying the trait is not objects safe.
rust-analyzer version: 0.4.2111-standalone (94b526fc8 2024-09-15)
rustc version: rustc 1.81.0 (eeb90cda1 2024-09-04)
editor or extension: VSCode rust-analyzer v0.4.2114 (pre-release)
code snippet to reproduce:
When hovering
trait Foo
(#17779), rust-analyzer claims// Object Safety: Yes
; however, compiling this code yields this error which explicitly saystrait Foo
is not object safe: