fix lifetime length are not added in count of params in highlight

This commit is contained in:
dfireBird 2024-03-27 23:00:08 +05:30
parent 4b33850c39
commit 20b12c2bac
No known key found for this signature in database
GPG key ID: 26D522CA5FC2B93D
2 changed files with 21 additions and 2 deletions

View file

@ -644,7 +644,8 @@ pub fn is_dyn_method(
let ItemContainerId::TraitId(trait_id) = func.lookup(db.upcast()).container else { let ItemContainerId::TraitId(trait_id) = func.lookup(db.upcast()).container else {
return None; 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 fn_params = fn_subst.len(Interner) - trait_params;
let trait_ref = TraitRef { let trait_ref = TraitRef {
trait_id: to_chalk_trait_id(trait_id), 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 { let ItemContainerId::TraitId(trait_id) = func.lookup(db.upcast()).container else {
return (func, fn_subst); 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 fn_params = fn_subst.len(Interner) - trait_params;
let trait_ref = TraitRef { let trait_ref = TraitRef {
trait_id: to_chalk_trait_id(trait_id), trait_id: to_chalk_trait_id(trait_id),

View file

@ -1229,3 +1229,20 @@ fn benchmark_syntax_highlighting_parser() {
}; };
assert_eq!(hash, 1169); 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();
}