about summary refs log tree commit diff
diff options
context:
space:
mode:
authordfireBird <me@dfirebird.dev>2024-03-27 23:00:08 +0530
committerdfireBird <me@dfirebird.dev>2024-03-27 23:21:17 +0530
commit20b12c2bacb2bba46429806907543a7530a37f8a (patch)
tree730c0e9b5ad79bb7f31a9bb0de9e4f4bede829a9
parent4b33850c39049047e2deb4269b60bd8330b68031 (diff)
downloadrust-20b12c2bacb2bba46429806907543a7530a37f8a.tar.gz
rust-20b12c2bacb2bba46429806907543a7530a37f8a.zip
fix lifetime length are not added in count of params in highlight
-rw-r--r--crates/hir-ty/src/method_resolution.rs6
-rw-r--r--crates/ide/src/syntax_highlighting/tests.rs17
2 files changed, 21 insertions, 2 deletions
diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs
index 064d317835f..6f52a60e925 100644
--- a/crates/hir-ty/src/method_resolution.rs
+++ b/crates/hir-ty/src/method_resolution.rs
@@ -644,7 +644,8 @@ pub fn is_dyn_method(
     let ItemContainerId::TraitId(trait_id) = func.lookup(db.upcast()).container else {
         return None;
     };
-    let trait_params = db.generic_params(trait_id.into()).type_or_consts.len();
+    let generic_params = db.generic_params(trait_id.into());
+    let trait_params = generic_params.type_or_consts.len() + generic_params.lifetimes.len();
     let fn_params = fn_subst.len(Interner) - trait_params;
     let trait_ref = TraitRef {
         trait_id: to_chalk_trait_id(trait_id),
@@ -686,7 +687,8 @@ pub(crate) fn lookup_impl_method_query(
     let ItemContainerId::TraitId(trait_id) = func.lookup(db.upcast()).container else {
         return (func, fn_subst);
     };
-    let trait_params = db.generic_params(trait_id.into()).type_or_consts.len();
+    let generic_params = db.generic_params(trait_id.into());
+    let trait_params = generic_params.type_or_consts.len() + generic_params.lifetimes.len();
     let fn_params = fn_subst.len(Interner) - trait_params;
     let trait_ref = TraitRef {
         trait_id: to_chalk_trait_id(trait_id),
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index 74d3e663d64..c2990fd76ea 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -1229,3 +1229,20 @@ fn benchmark_syntax_highlighting_parser() {
     };
     assert_eq!(hash, 1169);
 }
+
+#[test]
+fn highlight_trait_with_lifetimes_regression_16958() {
+    let (analysis, file_id) = fixture::file(
+        r#"
+pub trait Deserialize<'de> {
+    fn deserialize();
+}
+
+fn f<'de, T: Deserialize<'de>>() {
+    T::deserialize();
+}
+"#
+        .trim(),
+    );
+    let _ = analysis.highlight(HL_CONFIG, file_id).unwrap();
+}