diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/object_safety.rs b/src/tools/rust-analyzer/crates/hir-ty/src/object_safety.rs index 89bf3619a0c..a4c66268555 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/object_safety.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/object_safety.rs @@ -349,7 +349,7 @@ fn object_safety_violation_for_assoc_item( ControlFlow::Continue(()) } else { let generic_params = db.generic_params(item.into()); - if generic_params.len_type_or_consts() > 0 { + if !generic_params.is_empty() { cb(ObjectSafetyViolation::GAT(it)) } else { ControlFlow::Continue(()) diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/object_safety/tests.rs b/src/tools/rust-analyzer/crates/hir-ty/src/object_safety/tests.rs index 3dc08c4619e..c2a9117c5be 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/object_safety/tests.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/object_safety/tests.rs @@ -378,3 +378,16 @@ pub trait Error: core::fmt::Debug + core::fmt::Display { [("Error", vec![])], ); } + +#[test] +fn lifetime_gat_is_object_unsafe() { + check_object_safety( + r#" +//- minicore: dispatch_from_dyn +trait Foo { + type Bar<'a>; +} +"#, + [("Foo", vec![ObjectSafetyViolationKind::GAT])], + ); +}