From 20b12c2bacb2bba46429806907543a7530a37f8a Mon Sep 17 00:00:00 2001 From: dfireBird Date: Wed, 27 Mar 2024 23:00:08 +0530 Subject: [PATCH] fix lifetime length are not added in count of params in highlight --- crates/hir-ty/src/method_resolution.rs | 6 ++++-- crates/ide/src/syntax_highlighting/tests.rs | 17 +++++++++++++++++ 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(); +}