From 393f9cc0ba2bc40700722830e14a0e659a42f96a Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Sun, 22 Sep 2024 06:17:33 +0300 Subject: [PATCH] Consider lifetime GATs object unsafe --- .../crates/hir-ty/src/object_safety.rs | 2 +- .../crates/hir-ty/src/object_safety/tests.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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])], + ); +}