From 9942cc425ba31cf47ebf9498ed3cd58f064b2b89 Mon Sep 17 00:00:00 2001 From: Jonas Marcello Date: Sun, 19 Feb 2023 22:07:33 +0100 Subject: [PATCH 1/7] Fix 14142: Annotate lifetime paramaters in doctest runnables --- crates/hir-def/src/resolver.rs | 7 ++ crates/hir/src/lib.rs | 37 ++++++++++- crates/ide/src/runnables.rs | 117 +++++++++++++++++++++++++++++++-- 3 files changed, 155 insertions(+), 6 deletions(-) diff --git a/crates/hir-def/src/resolver.rs b/crates/hir-def/src/resolver.rs index 86958e3dae..b2323915c1 100644 --- a/crates/hir-def/src/resolver.rs +++ b/crates/hir-def/src/resolver.rs @@ -459,6 +459,13 @@ impl Resolver { }) } + pub fn generic_params(&self) -> Option<&Interned> { + self.scopes().find_map(|scope| match scope { + Scope::GenericParams { params, .. } => Some(params), + _ => None, + }) + } + pub fn body_owner(&self) -> Option { self.scopes().find_map(|scope| match scope { Scope::ExprScope(it) => Some(it.owner), diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 6206a541c1..28d87e14e1 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -42,7 +42,7 @@ use hir_def::{ adt::VariantData, body::{BodyDiagnostic, SyntheticSyntax}, expr::{BindingAnnotation, ExprOrPatId, LabelId, Pat, PatId}, - generics::{TypeOrConstParamData, TypeParamProvenance}, + generics::{TypeOrConstParamData, TypeParamProvenance, LifetimeParamData}, item_tree::ItemTreeNode, lang_item::{LangItem, LangItemTarget}, layout::{Layout, LayoutError, ReprOptions}, @@ -1170,6 +1170,22 @@ impl Adt { } } + /// Returns the lifetime of the DataType + pub fn lifetime(&self, db: &dyn HirDatabase) -> Option { + let resolver = match self { + Adt::Struct(s) => s.id.resolver(db.upcast()), + Adt::Union(u) => u.id.resolver(db.upcast()), + Adt::Enum(e) => e.id.resolver(db.upcast()), + }; + resolver.generic_params().and_then(|gp| { + (&gp.lifetimes) + .iter() + // there should only be a single lifetime + // but `Arena` requires to use an iterator + .nth(0) + }).map(|arena| arena.1.clone()) + } + pub fn as_enum(&self) -> Option { if let Self::Enum(v) = self { Some(*v) @@ -3339,6 +3355,25 @@ impl Type { .map(move |ty| self.derived(ty)) } + /// Combines lifetime indicators and type arguments into a single `Vec` + pub fn lifetime_and_type_arguments<'a>(&'a self, db: &'a dyn HirDatabase) -> Vec { + let mut names = if let Some(lt) = self + .as_adt() + .and_then(|a| { + a.lifetime(db) + .and_then(|lt| Some((<.name).to_smol_str().clone())) + }) { + vec![lt] + } else { + vec![] + }; + + for ty in self.type_arguments() { + names.push(SmolStr::new(ty.display(db).to_string())) + } + names + } + pub fn iterate_method_candidates_with_traits( &self, db: &dyn HirDatabase, diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index af53adee89..2e8f3906af 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -2,7 +2,7 @@ use std::fmt; use ast::HasName; use cfg::CfgExpr; -use hir::{AsAssocItem, HasAttrs, HasSource, HirDisplay, Semantics}; +use hir::{AsAssocItem, HasAttrs, HasSource, Semantics}; use ide_assists::utils::test_related_attribute; use ide_db::{ base_db::{FilePosition, FileRange}, @@ -370,9 +370,9 @@ pub(crate) fn runnable_impl( let nav = def.try_to_nav(sema.db)?; let ty = def.self_ty(sema.db); let adt_name = ty.as_adt()?.name(sema.db); - let mut ty_args = ty.type_arguments().peekable(); + let mut ty_args = ty.lifetime_and_type_arguments(sema.db).into_iter().peekable(); let params = if ty_args.peek().is_some() { - format!("<{}>", ty_args.format_with(",", |ty, cb| cb(&ty.display(sema.db)))) + format!("<{}>", ty_args.format_with(",", |ty, cb| cb(&ty))) } else { String::new() }; @@ -436,13 +436,13 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option { let ty = imp.self_ty(db); if let Some(adt) = ty.as_adt() { let name = adt.name(db); - let mut ty_args = ty.type_arguments().peekable(); + let mut ty_args = ty.lifetime_and_type_arguments(db).into_iter().peekable(); format_to!(path, "{}", name); if ty_args.peek().is_some() { format_to!( path, "<{}>", - ty_args.format_with(",", |ty, cb| cb(&ty.display(db))) + ty_args.format_with(",", |ty, cb| cb(&ty)) ); } format_to!(path, "::{}", def_name); @@ -999,6 +999,113 @@ impl Data { ); } + #[test] + fn test_runnables_doc_test_in_impl_with_lifetime() { + check( + r#" +//- /lib.rs +$0 +fn main() {} + +struct Data<'a>; +impl Data<'a> { + /// ``` + /// let x = 5; + /// ``` + fn foo() {} +} +"#, + &[Bin, DocTest], + expect![[r#" + [ + Runnable { + use_name_in_title: false, + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 1..13, + focus_range: 4..8, + name: "main", + kind: Function, + }, + kind: Bin, + cfg: None, + }, + Runnable { + use_name_in_title: false, + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 52..106, + name: "foo", + }, + kind: DocTest { + test_id: Path( + "Data<'a>::foo", + ), + }, + cfg: None, + }, + ] + "#]], + ); + } + + #[test] + fn test_runnables_doc_test_in_impl_with_lifetime_and_types() { + check( + r#" +//- /lib.rs +$0 +fn main() {} + +struct Data<'a, T, U>; +impl Data<'a, T, U> { + /// ``` + /// let x = 5; + /// ``` + fn foo() {} +} +"#, + &[Bin, DocTest], + expect![[r#" + [ + Runnable { + use_name_in_title: false, + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 1..13, + focus_range: 4..8, + name: "main", + kind: Function, + }, + kind: Bin, + cfg: None, + }, + Runnable { + use_name_in_title: false, + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 70..124, + name: "foo", + }, + kind: DocTest { + test_id: Path( + "Data<'a,T,U>::foo", + ), + }, + cfg: None, + }, + ] + "#]], + ); + } #[test] fn test_runnables_module() { check( From 8bc75c4c28eff4664979905a7b75b890b3f84437 Mon Sep 17 00:00:00 2001 From: Jonas Marcello Date: Tue, 21 Feb 2023 21:25:56 +0100 Subject: [PATCH 2/7] return Iterator instead of Vec for combined lifetime and argument parameters --- crates/hir/src/lib.rs | 45 +++++++++++++++++-------------------- crates/ide/src/runnables.rs | 10 +++------ 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 28d87e14e1..883838293e 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -42,7 +42,7 @@ use hir_def::{ adt::VariantData, body::{BodyDiagnostic, SyntheticSyntax}, expr::{BindingAnnotation, ExprOrPatId, LabelId, Pat, PatId}, - generics::{TypeOrConstParamData, TypeParamProvenance, LifetimeParamData}, + generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance}, item_tree::ItemTreeNode, lang_item::{LangItem, LangItemTarget}, layout::{Layout, LayoutError, ReprOptions}, @@ -1177,13 +1177,16 @@ impl Adt { Adt::Union(u) => u.id.resolver(db.upcast()), Adt::Enum(e) => e.id.resolver(db.upcast()), }; - resolver.generic_params().and_then(|gp| { - (&gp.lifetimes) - .iter() - // there should only be a single lifetime - // but `Arena` requires to use an iterator - .nth(0) - }).map(|arena| arena.1.clone()) + resolver + .generic_params() + .and_then(|gp| { + (&gp.lifetimes) + .iter() + // there should only be a single lifetime + // but `Arena` requires to use an iterator + .nth(0) + }) + .map(|arena| arena.1.clone()) } pub fn as_enum(&self) -> Option { @@ -3355,23 +3358,15 @@ impl Type { .map(move |ty| self.derived(ty)) } - /// Combines lifetime indicators and type arguments into a single `Vec` - pub fn lifetime_and_type_arguments<'a>(&'a self, db: &'a dyn HirDatabase) -> Vec { - let mut names = if let Some(lt) = self - .as_adt() - .and_then(|a| { - a.lifetime(db) - .and_then(|lt| Some((<.name).to_smol_str().clone())) - }) { - vec![lt] - } else { - vec![] - }; - - for ty in self.type_arguments() { - names.push(SmolStr::new(ty.display(db).to_string())) - } - names + /// Combines lifetime indicators and type arguments into a single `Iterator` + pub fn lifetime_and_type_arguments<'a>( + &'a self, + db: &'a dyn HirDatabase, + ) -> impl Iterator + 'a { + self.as_adt() + .and_then(|a| a.lifetime(db).and_then(|lt| Some((<.name).to_smol_str()))) + .into_iter() + .chain(self.type_arguments().map(|ty| SmolStr::new(ty.display(db).to_string()))) } pub fn iterate_method_candidates_with_traits( diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 2e8f3906af..b0477e9678 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -370,7 +370,7 @@ pub(crate) fn runnable_impl( let nav = def.try_to_nav(sema.db)?; let ty = def.self_ty(sema.db); let adt_name = ty.as_adt()?.name(sema.db); - let mut ty_args = ty.lifetime_and_type_arguments(sema.db).into_iter().peekable(); + let mut ty_args = ty.lifetime_and_type_arguments(sema.db).peekable(); let params = if ty_args.peek().is_some() { format!("<{}>", ty_args.format_with(",", |ty, cb| cb(&ty))) } else { @@ -436,14 +436,10 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option { let ty = imp.self_ty(db); if let Some(adt) = ty.as_adt() { let name = adt.name(db); - let mut ty_args = ty.lifetime_and_type_arguments(db).into_iter().peekable(); + let mut ty_args = ty.lifetime_and_type_arguments(db).peekable(); format_to!(path, "{}", name); if ty_args.peek().is_some() { - format_to!( - path, - "<{}>", - ty_args.format_with(",", |ty, cb| cb(&ty)) - ); + format_to!(path, "<{}>", ty_args.format_with(",", |ty, cb| cb(&ty))); } format_to!(path, "::{}", def_name); path.retain(|c| c != ' '); From 9957bb361dac0f1edcadf3753bef13f543d57228 Mon Sep 17 00:00:00 2001 From: Jonas Marcello Date: Fri, 24 Feb 2023 21:09:16 +0100 Subject: [PATCH 3/7] Add const generics to doctest names for structt --- crates/hir/src/lib.rs | 35 +++++++++++- crates/ide/src/runnables.rs | 108 ++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 2 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 883838293e..369f9192d1 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -42,7 +42,7 @@ use hir_def::{ adt::VariantData, body::{BodyDiagnostic, SyntheticSyntax}, expr::{BindingAnnotation, ExprOrPatId, LabelId, Pat, PatId}, - generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance}, + generics::{ConstParamData, LifetimeParamData, TypeOrConstParamData, TypeParamProvenance}, item_tree::ItemTreeNode, lang_item::{LangItem, LangItemTarget}, layout::{Layout, LayoutError, ReprOptions}, @@ -1189,6 +1189,31 @@ impl Adt { .map(|arena| arena.1.clone()) } + /// Returns an iterator of all `const` generic paramaters + /// + /// This method is not well optimized, I could not statisfy the borrow + /// checker. I'm sure there are smarter ways to return the consts names + pub fn consts(&self, db: &dyn HirDatabase) -> impl Iterator { + let resolver = match self { + Adt::Struct(s) => s.id.resolver(db.upcast()), + Adt::Union(u) => u.id.resolver(db.upcast()), + Adt::Enum(e) => e.id.resolver(db.upcast()), + }; + resolver + .generic_params() + .map_or(vec![], |gp| { + gp.as_ref() + .type_or_consts + .iter() + .filter_map(|arena| match arena.1 { + TypeOrConstParamData::ConstParamData(consts) => Some(consts.clone()), + _ => None, + }) + .collect::>() + }) + .into_iter() + } + pub fn as_enum(&self) -> Option { if let Self::Enum(v) = self { Some(*v) @@ -3358,15 +3383,21 @@ impl Type { .map(move |ty| self.derived(ty)) } - /// Combines lifetime indicators and type arguments into a single `Iterator` + /// Combines lifetime indicators, type and constant parameters into a single `Iterator` pub fn lifetime_and_type_arguments<'a>( &'a self, db: &'a dyn HirDatabase, ) -> impl Iterator + 'a { + // iterate the lifetime self.as_adt() .and_then(|a| a.lifetime(db).and_then(|lt| Some((<.name).to_smol_str()))) .into_iter() + // add the type paramaters .chain(self.type_arguments().map(|ty| SmolStr::new(ty.display(db).to_string()))) + // add const paramameters + .chain(self.as_adt().map_or(vec![], |a| { + a.consts(db).map(|cs| cs.name.to_smol_str()).collect::>() + })) } pub fn iterate_method_candidates_with_traits( diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index b0477e9678..7af969c5d0 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -1102,6 +1102,114 @@ impl Data<'a, T, U> { "#]], ); } + + #[test] + fn test_runnables_doc_test_in_impl_with_const() { + check( + r#" +//- /lib.rs +$0 +fn main() {} + +struct Data; +impl Data { + /// ``` + /// let x = 5; + /// ``` + fn foo() {} +} +"#, + &[Bin, DocTest], + expect![[r#" + [ + Runnable { + use_name_in_title: false, + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 1..13, + focus_range: 4..8, + name: "main", + kind: Function, + }, + kind: Bin, + cfg: None, + }, + Runnable { + use_name_in_title: false, + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 79..133, + name: "foo", + }, + kind: DocTest { + test_id: Path( + "Data::foo", + ), + }, + cfg: None, + }, + ] + "#]], + ); + } + + #[test] + fn test_runnables_doc_test_in_impl_with_lifetime_types_and_const() { + check( + r#" +//- /lib.rs +$0 +fn main() {} + +struct Data<'a, T, const N: usize>; +impl<'a, T, const N: usize> Data<'a, T, N> { + /// ``` + /// let x = 5; + /// ``` + fn foo() {} +} +"#, + &[Bin, DocTest], + expect![[r#" + [ + Runnable { + use_name_in_title: false, + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 1..13, + focus_range: 4..8, + name: "main", + kind: Function, + }, + kind: Bin, + cfg: None, + }, + Runnable { + use_name_in_title: false, + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 100..154, + name: "foo", + }, + kind: DocTest { + test_id: Path( + "Data<'a,T,N>::foo", + ), + }, + cfg: None, + }, + ] + "#]], + ); + } #[test] fn test_runnables_module() { check( From 4ee2e469a211e55741239f1830d41a72ec18f409 Mon Sep 17 00:00:00 2001 From: Jonas Marcello Date: Fri, 24 Feb 2023 21:16:05 +0100 Subject: [PATCH 4/7] Rename the method that returns struct paramaters --- crates/hir/src/lib.rs | 2 +- crates/ide/src/runnables.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 369f9192d1..d280ff8815 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -3384,7 +3384,7 @@ impl Type { } /// Combines lifetime indicators, type and constant parameters into a single `Iterator` - pub fn lifetime_and_type_arguments<'a>( + pub fn lifetime_type_const_paramaters<'a>( &'a self, db: &'a dyn HirDatabase, ) -> impl Iterator + 'a { diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 7af969c5d0..7fc396f023 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -370,7 +370,7 @@ pub(crate) fn runnable_impl( let nav = def.try_to_nav(sema.db)?; let ty = def.self_ty(sema.db); let adt_name = ty.as_adt()?.name(sema.db); - let mut ty_args = ty.lifetime_and_type_arguments(sema.db).peekable(); + let mut ty_args = ty.lifetime_type_const_paramaters(sema.db).peekable(); let params = if ty_args.peek().is_some() { format!("<{}>", ty_args.format_with(",", |ty, cb| cb(&ty))) } else { @@ -436,7 +436,7 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option { let ty = imp.self_ty(db); if let Some(adt) = ty.as_adt() { let name = adt.name(db); - let mut ty_args = ty.lifetime_and_type_arguments(db).peekable(); + let mut ty_args = ty.lifetime_type_const_paramaters(db).peekable(); format_to!(path, "{}", name); if ty_args.peek().is_some() { format_to!(path, "<{}>", ty_args.format_with(",", |ty, cb| cb(&ty))); From 7abcc7d8624bb82ecf1292362726ea2c011fe554 Mon Sep 17 00:00:00 2001 From: Jonas Marcello Date: Mon, 27 Feb 2023 07:11:35 +0100 Subject: [PATCH 5/7] Add const to doctest runnable definition Refactor method to get type parameters to add const parameters Remove unused methods --- crates/hir/src/lib.rs | 93 ++++++++++++++++++++++++------------- crates/ide/src/runnables.rs | 54 +++++++++++++++++++++ 2 files changed, 115 insertions(+), 32 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index d280ff8815..82718b2f82 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -42,7 +42,7 @@ use hir_def::{ adt::VariantData, body::{BodyDiagnostic, SyntheticSyntax}, expr::{BindingAnnotation, ExprOrPatId, LabelId, Pat, PatId}, - generics::{ConstParamData, LifetimeParamData, TypeOrConstParamData, TypeParamProvenance}, + generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance}, item_tree::ItemTreeNode, lang_item::{LangItem, LangItemTarget}, layout::{Layout, LayoutError, ReprOptions}, @@ -1189,31 +1189,6 @@ impl Adt { .map(|arena| arena.1.clone()) } - /// Returns an iterator of all `const` generic paramaters - /// - /// This method is not well optimized, I could not statisfy the borrow - /// checker. I'm sure there are smarter ways to return the consts names - pub fn consts(&self, db: &dyn HirDatabase) -> impl Iterator { - let resolver = match self { - Adt::Struct(s) => s.id.resolver(db.upcast()), - Adt::Union(u) => u.id.resolver(db.upcast()), - Adt::Enum(e) => e.id.resolver(db.upcast()), - }; - resolver - .generic_params() - .map_or(vec![], |gp| { - gp.as_ref() - .type_or_consts - .iter() - .filter_map(|arena| match arena.1 { - TypeOrConstParamData::ConstParamData(consts) => Some(consts.clone()), - _ => None, - }) - .collect::>() - }) - .into_iter() - } - pub fn as_enum(&self) -> Option { if let Self::Enum(v) = self { Some(*v) @@ -3373,6 +3348,24 @@ impl Type { } } + /// Iterates its type arguments + /// + /// It iterates the actual type arguments when concrete types are used + /// and otherwise the generic names. + /// It does not include `const` arguments. + /// + /// For code, such as: + /// ```text + /// struct Foo + /// + /// impl Foo + /// ``` + /// + /// It iterates: + /// ```text + /// - "String" + /// - "U" + /// ``` pub fn type_arguments(&self) -> impl Iterator + '_ { self.ty .strip_references() @@ -3383,6 +3376,46 @@ impl Type { .map(move |ty| self.derived(ty)) } + /// Iterates its type and const arguments + /// + /// It iterates the actual type and const arguments when concrete types + /// are used and otherwise the generic names. + /// + /// For code, such as: + /// ```text + /// struct Foo + /// + /// impl Foo + /// ``` + /// + /// It iterates: + /// ```text + /// - "String" + /// - "U" + /// - "12" + /// ``` + pub fn type_and_const_arguments<'a>( + &'a self, + db: &'a dyn HirDatabase, + ) -> impl Iterator + 'a { + self.ty + .strip_references() + .as_adt() + .into_iter() + .flat_map(|(_, substs)| substs.iter(Interner)) + .filter_map(|arg| { + // arg can be either a `Ty` or `constant` + if let Some(ty) = arg.ty(Interner) { + Some(SmolStr::new(ty.display(db).to_string())) + // Some(ty) + } else if let Some(const_) = arg.constant(Interner) { + Some(SmolStr::new_inline(&const_.display(db).to_string())) + } else { + None + } + }) + } + /// Combines lifetime indicators, type and constant parameters into a single `Iterator` pub fn lifetime_type_const_paramaters<'a>( &'a self, @@ -3392,12 +3425,8 @@ impl Type { self.as_adt() .and_then(|a| a.lifetime(db).and_then(|lt| Some((<.name).to_smol_str()))) .into_iter() - // add the type paramaters - .chain(self.type_arguments().map(|ty| SmolStr::new(ty.display(db).to_string()))) - // add const paramameters - .chain(self.as_adt().map_or(vec![], |a| { - a.consts(db).map(|cs| cs.name.to_smol_str()).collect::>() - })) + // add the type and const paramaters + .chain(self.type_and_const_arguments(db)) } pub fn iterate_method_candidates_with_traits( diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 7fc396f023..b4fa2f9b9f 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -2272,6 +2272,60 @@ mod tests { ); } + #[test] + fn test_runnables_doc_test_in_impl_with_lifetime_type_const_value() { + check( + r#" +//- /lib.rs +$0 +fn main() {} + +struct Data<'a, A, const B: usize, C, const D: u32>; +impl Data<'a, A, 12, C, D> { + /// ``` + /// ``` + fn foo() {} +} +"#, + &[Bin, DocTest], + expect![[r#" + [ + Runnable { + use_name_in_title: false, + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 1..13, + focus_range: 4..8, + name: "main", + kind: Function, + }, + kind: Bin, + cfg: None, + }, + Runnable { + use_name_in_title: false, + nav: NavigationTarget { + file_id: FileId( + 0, + ), + full_range: 121..156, + name: "foo", + }, + kind: DocTest { + test_id: Path( + "Data<'a,A,12,C,D>::foo", + ), + }, + cfg: None, + }, + ] + "#]], + ); + } + + #[test] fn doc_test_type_params() { check( From f494d1199d79a515275c8c82206ba0d426c7e3f6 Mon Sep 17 00:00:00 2001 From: Jonas Marcello Date: Mon, 27 Feb 2023 07:15:46 +0100 Subject: [PATCH 6/7] Remove empty line --- crates/hir/src/lib.rs | 1 - crates/ide/src/runnables.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 82718b2f82..394ef4a9e0 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -3407,7 +3407,6 @@ impl Type { // arg can be either a `Ty` or `constant` if let Some(ty) = arg.ty(Interner) { Some(SmolStr::new(ty.display(db).to_string())) - // Some(ty) } else if let Some(const_) = arg.constant(Interner) { Some(SmolStr::new_inline(&const_.display(db).to_string())) } else { diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index b4fa2f9b9f..8de81206b6 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -2325,7 +2325,6 @@ impl Data<'a, A, 12, C, D> { ); } - #[test] fn doc_test_type_params() { check( From af79491ae62ebba739d3375c425b71c48f4b4905 Mon Sep 17 00:00:00 2001 From: Jonas Marcello Date: Tue, 28 Feb 2023 10:32:42 +0100 Subject: [PATCH 7/7] Rename method to generic_parameters --- crates/hir/src/lib.rs | 2 +- crates/ide/src/runnables.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 394ef4a9e0..c59e17af1f 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -3416,7 +3416,7 @@ impl Type { } /// Combines lifetime indicators, type and constant parameters into a single `Iterator` - pub fn lifetime_type_const_paramaters<'a>( + pub fn generic_parameters<'a>( &'a self, db: &'a dyn HirDatabase, ) -> impl Iterator + 'a { diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 8de81206b6..77aef710ad 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -370,7 +370,7 @@ pub(crate) fn runnable_impl( let nav = def.try_to_nav(sema.db)?; let ty = def.self_ty(sema.db); let adt_name = ty.as_adt()?.name(sema.db); - let mut ty_args = ty.lifetime_type_const_paramaters(sema.db).peekable(); + let mut ty_args = ty.generic_parameters(sema.db).peekable(); let params = if ty_args.peek().is_some() { format!("<{}>", ty_args.format_with(",", |ty, cb| cb(&ty))) } else { @@ -436,7 +436,7 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option { let ty = imp.self_ty(db); if let Some(adt) = ty.as_adt() { let name = adt.name(db); - let mut ty_args = ty.lifetime_type_const_paramaters(db).peekable(); + let mut ty_args = ty.generic_parameters(db).peekable(); format_to!(path, "{}", name); if ty_args.peek().is_some() { format_to!(path, "<{}>", ty_args.format_with(",", |ty, cb| cb(&ty)));