Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #16960 - dfireBird:fix-16958, r=lnicola
fix: lifetime length are not added in count of params in highlight I found these two instances easily but I wonder how many such instances are there. Fixes #16958
bors 2024-03-28
parent 4b33850 · parent 20b12c2 · commit ad51a17
-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 064d317835..6f52a60e92 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 74d3e663d6..c2990fd76e 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();
+}