Allow name querying for derive helpers

This commit is contained in:
Lukas Wirth 2022-07-24 14:32:39 +02:00
parent aa1491ecde
commit ddad2847ab
8 changed files with 53 additions and 18 deletions

View file

@ -35,6 +35,7 @@ use hir_ty::{
method_resolution, Adjust, Adjustment, AutoBorrow, InferenceResult, Interner, Substitution,
TyExt, TyKind, TyLoweringContext,
};
use itertools::Itertools;
use smallvec::SmallVec;
use syntax::{
ast::{self, AstNode},
@ -487,10 +488,16 @@ impl SourceAnalyzer {
{
// FIXME: Multiple derives can have the same helper
let name_ref = name_ref.as_name();
if let Some(&(_, derive, _)) =
helpers.iter().find(|(name, ..)| *name == name_ref)
for (macro_id, mut helpers) in
helpers.iter().group_by(|(_, macro_id, ..)| macro_id).into_iter()
{
return Some(PathResolution::DeriveHelper(DeriveHelper { derive }));
if let Some(idx) = helpers.position(|(name, ..)| *name == name_ref)
{
return Some(PathResolution::DeriveHelper(DeriveHelper {
derive: *macro_id,
idx,
}));
}
}
}
}