From 72712b8a428e17d63c413522c770e8f1f0587455 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 20 Feb 2019 22:36:54 +0100 Subject: Fix handling of generics in tuple variants and refactor a bit Also make them display a tiny bit nicer. Fixes #860. --- crates/ra_hir/src/generics.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'crates/ra_hir/src/generics.rs') diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index fcc513353..c494beeb0 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -87,4 +87,17 @@ impl GenericParams { let parent_count = self.count_parent_params(); parent_count + self.params.len() } + + fn for_each_param<'a>(&'a self, f: &mut impl FnMut(&'a GenericParam)) { + if let Some(parent) = &self.parent_params { + parent.for_each_param(f); + } + self.params.iter().for_each(f); + } + + pub fn params_including_parent(&self) -> Vec<&GenericParam> { + let mut vec = Vec::with_capacity(self.count_params_including_parent()); + self.for_each_param(&mut |p| vec.push(p)); + vec + } } -- cgit v1.2.3