aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-20 08:47:42 +0000
committerGitHub <[email protected]>2019-11-20 08:47:42 +0000
commitd24e8f9ea42dd2d08b2e02f8106690fd4baa8071 (patch)
tree3da030379556170d1d18235c234ae95bbe28fba4 /crates/ra_hir/src
parent4340d9b0e435bde11c0cc79e9f284856a836ccdc (diff)
parent0e771915faf057ec4561224b75ec9b5be93d71c8 (diff)
Merge #2321
2321: Allow non-path default type parameters r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/generics.rs11
-rw-r--r--crates/ra_hir/src/ty/lower.rs4
-rw-r--r--crates/ra_hir/src/ty/tests.rs24
3 files changed, 29 insertions, 10 deletions
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 8925ba3a9..78fab1a13 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -5,12 +5,9 @@
5 5
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use hir_def::{ 8use hir_def::type_ref::{TypeBound, TypeRef};
9 path::Path,
10 type_ref::{TypeBound, TypeRef},
11};
12use hir_expand::name::{self, AsName}; 9use hir_expand::name::{self, AsName};
13use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; 10use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
14 11
15use crate::{ 12use crate::{
16 db::{AstDatabase, DefDatabase, HirDatabase}, 13 db::{AstDatabase, DefDatabase, HirDatabase},
@@ -24,7 +21,7 @@ pub struct GenericParam {
24 // FIXME: give generic params proper IDs 21 // FIXME: give generic params proper IDs
25 pub idx: u32, 22 pub idx: u32,
26 pub name: Name, 23 pub name: Name,
27 pub default: Option<Path>, 24 pub default: Option<TypeRef>,
28} 25}
29 26
30/// Data about the generic parameters of a function, struct, impl, etc. 27/// Data about the generic parameters of a function, struct, impl, etc.
@@ -140,7 +137,7 @@ impl GenericParams {
140 for (idx, type_param) in params.type_params().enumerate() { 137 for (idx, type_param) in params.type_params().enumerate() {
141 let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); 138 let name = type_param.name().map_or_else(Name::missing, |it| it.as_name());
142 // FIXME: Use `Path::from_src` 139 // FIXME: Use `Path::from_src`
143 let default = type_param.default_type().and_then(|t| t.path()).and_then(Path::from_ast); 140 let default = type_param.default_type().map(TypeRef::from_ast);
144 141
145 let param = GenericParam { idx: idx as u32 + start, name: name.clone(), default }; 142 let param = GenericParam { idx: idx as u32 + start, name: name.clone(), default };
146 self.params.push(param); 143 self.params.push(param);
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index de3c56097..03db38605 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -611,9 +611,7 @@ pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) ->
611 let defaults = generic_params 611 let defaults = generic_params
612 .params_including_parent() 612 .params_including_parent()
613 .into_iter() 613 .into_iter()
614 .map(|p| { 614 .map(|p| p.default.as_ref().map_or(Ty::Unknown, |t| Ty::from_hir(db, &resolver, t)))
615 p.default.as_ref().map_or(Ty::Unknown, |path| Ty::from_hir_path(db, &resolver, path))
616 })
617 .collect(); 615 .collect();
618 616
619 Substs(defaults) 617 Substs(defaults)
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index c1024d03c..abfaffb5e 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -1980,6 +1980,30 @@ fn test() {
1980} 1980}
1981 1981
1982#[test] 1982#[test]
1983fn infer_associated_method_generics_with_default_tuple_param() {
1984 let t = type_at(
1985 r#"
1986//- /main.rs
1987struct Gen<T=()> {
1988 val: T
1989}
1990
1991impl<T> Gen<T> {
1992 pub fn make() -> Gen<T> {
1993 loop { }
1994 }
1995}
1996
1997fn test() {
1998 let a = Gen::make();
1999 a.val<|>;
2000}
2001"#,
2002 );
2003 assert_eq!(t, "()");
2004}
2005
2006#[test]
1983fn infer_associated_method_generics_without_args() { 2007fn infer_associated_method_generics_without_args() {
1984 assert_snapshot!( 2008 assert_snapshot!(
1985 infer(r#" 2009 infer(r#"