aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/db.rs4
-rw-r--r--crates/ra_hir_ty/src/display.rs6
-rw-r--r--crates/ra_hir_ty/src/lower.rs9
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs73
-rw-r--r--crates/ra_ide_db/src/change.rs1
5 files changed, 68 insertions, 25 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index ec931b34f..693cd40cf 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -18,8 +18,8 @@ pub use hir_ty::db::{
18 GenericDefaultsQuery, GenericPredicatesForParamQuery, GenericPredicatesQuery, HirDatabase, 18 GenericDefaultsQuery, GenericPredicatesForParamQuery, GenericPredicatesQuery, HirDatabase,
19 HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, ImplsForTraitQuery, 19 HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, ImplsForTraitQuery,
20 ImplsInCrateQuery, InferQueryQuery, InternAssocTyValueQuery, InternChalkImplQuery, 20 ImplsInCrateQuery, InferQueryQuery, InternAssocTyValueQuery, InternChalkImplQuery,
21 InternTypeCtorQuery, InternTypeParamIdQuery, StructDatumQuery, TraitDatumQuery, 21 InternTypeCtorQuery, InternTypeParamIdQuery, ReturnTypeImplTraitsQuery, StructDatumQuery,
22 TraitSolveQuery, TyQuery, ValueTyQuery, 22 TraitDatumQuery, TraitSolveQuery, TyQuery, ValueTyQuery,
23}; 23};
24 24
25#[test] 25#[test]
diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs
index 3e63a2415..3c97e1354 100644
--- a/crates/ra_hir_ty/src/display.rs
+++ b/crates/ra_hir_ty/src/display.rs
@@ -4,7 +4,7 @@ use std::fmt;
4 4
5use crate::{ 5use crate::{
6 db::HirDatabase, utils::generics, ApplicationTy, CallableDef, FnSig, GenericPredicate, 6 db::HirDatabase, utils::generics, ApplicationTy, CallableDef, FnSig, GenericPredicate,
7 Obligation, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, 7 Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
8}; 8};
9use hir_def::{ 9use hir_def::{
10 find_path, generics::TypeParamProvenance, item_scope::ItemInNs, AdtId, AssocContainerId, 10 find_path, generics::TypeParamProvenance, item_scope::ItemInNs, AdtId, AssocContainerId,
@@ -361,7 +361,7 @@ impl HirDisplay for ApplicationTy {
361 } 361 }
362 TypeCtor::OpaqueType(opaque_ty_id) => { 362 TypeCtor::OpaqueType(opaque_ty_id) => {
363 let bounds = match opaque_ty_id { 363 let bounds = match opaque_ty_id {
364 crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => { 364 OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
365 let datas = 365 let datas =
366 f.db.return_type_impl_traits(func).expect("impl trait id without data"); 366 f.db.return_type_impl_traits(func).expect("impl trait id without data");
367 let data = (*datas) 367 let data = (*datas)
@@ -448,7 +448,7 @@ impl HirDisplay for Ty {
448 } 448 }
449 Ty::Opaque(opaque_ty) => { 449 Ty::Opaque(opaque_ty) => {
450 let bounds = match opaque_ty.opaque_ty_id { 450 let bounds = match opaque_ty.opaque_ty_id {
451 crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => { 451 OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
452 let datas = 452 let datas =
453 f.db.return_type_impl_traits(func).expect("impl trait id without data"); 453 f.db.return_type_impl_traits(func).expect("impl trait id without data");
454 let data = (*datas) 454 let data = (*datas)
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index dfc018b0b..a05cbd7fc 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -21,8 +21,10 @@ use hir_def::{
21 HasModule, ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, 21 HasModule, ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId,
22 UnionId, VariantId, 22 UnionId, VariantId,
23}; 23};
24use hir_expand::name::Name;
24use ra_arena::map::ArenaMap; 25use ra_arena::map::ArenaMap;
25use ra_db::CrateId; 26use ra_db::CrateId;
27use test_utils::mark;
26 28
27use crate::{ 29use crate::{
28 db::HirDatabase, 30 db::HirDatabase,
@@ -35,7 +37,6 @@ use crate::{
35 ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, ReturnTypeImplTraits, Substs, 37 ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, ReturnTypeImplTraits, Substs,
36 TraitEnvironment, TraitRef, Ty, TypeCtor, TypeWalk, 38 TraitEnvironment, TraitRef, Ty, TypeCtor, TypeWalk,
37}; 39};
38use hir_expand::name::Name;
39 40
40#[derive(Debug)] 41#[derive(Debug)]
41pub struct TyLoweringContext<'a> { 42pub struct TyLoweringContext<'a> {
@@ -220,10 +221,7 @@ impl Ty {
220 221
221 let func = match ctx.resolver.generic_def() { 222 let func = match ctx.resolver.generic_def() {
222 Some(GenericDefId::FunctionId(f)) => f, 223 Some(GenericDefId::FunctionId(f)) => f,
223 _ => { 224 _ => panic!("opaque impl trait lowering in non-function"),
224 // this shouldn't happen
225 return (Ty::Unknown, None);
226 }
227 }; 225 };
228 let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx); 226 let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx);
229 let generics = generics(ctx.db.upcast(), func.into()); 227 let generics = generics(ctx.db.upcast(), func.into());
@@ -719,6 +717,7 @@ fn assoc_type_bindings_from_type_bound<'a>(
719 717
720impl ReturnTypeImplTrait { 718impl ReturnTypeImplTrait {
721 fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self { 719 fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self {
720 mark::hit!(lower_rpit);
722 let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)); 721 let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0));
723 let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { 722 let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| {
724 bounds 723 bounds
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs
index d83dc6d79..0c538a62d 100644
--- a/crates/ra_hir_ty/src/tests/traits.rs
+++ b/crates/ra_hir_ty/src/tests/traits.rs
@@ -1160,7 +1160,37 @@ fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1160} 1160}
1161 1161
1162#[test] 1162#[test]
1163fn return_pos_impl_trait() { 1163fn simple_return_pos_impl_trait() {
1164 mark::check!(lower_rpit);
1165 assert_snapshot!(
1166 infer(r#"
1167trait Trait<T> {
1168 fn foo(&self) -> T;
1169}
1170fn bar() -> impl Trait<u64> { loop {} }
1171
1172fn test() {
1173 let a = bar();
1174 a.foo();
1175}
1176"#),
1177 @r###"
1178 30..34 'self': &Self
1179 72..83 '{ loop {} }': !
1180 74..81 'loop {}': !
1181 79..81 '{}': ()
1182 95..130 '{ ...o(); }': ()
1183 105..106 'a': impl Trait<u64>
1184 109..112 'bar': fn bar() -> impl Trait<u64>
1185 109..114 'bar()': impl Trait<u64>
1186 120..121 'a': impl Trait<u64>
1187 120..127 'a.foo()': u64
1188 "###
1189 );
1190}
1191
1192#[test]
1193fn more_return_pos_impl_trait() {
1164 assert_snapshot!( 1194 assert_snapshot!(
1165 infer(r#" 1195 infer(r#"
1166trait Iterator { 1196trait Iterator {
@@ -1174,12 +1204,12 @@ fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1174fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} } 1204fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1175 1205
1176fn test() { 1206fn test() {
1177 // let (a, b) = bar(); 1207 let (a, b) = bar();
1178 // a.next().foo(); 1208 a.next().foo();
1179 // b.foo(); 1209 b.foo();
1180 let (c, d) = baz(1u128); 1210 let (c, d) = baz(1u128);
1181 c.next();//.foo(); 1211 c.next().foo();
1182 // d.foo(); 1212 d.foo();
1183} 1213}
1184"#), 1214"#),
1185 @r###" 1215 @r###"
@@ -1192,15 +1222,28 @@ fn test() {
1192 269..280 '{ loop {} }': ({unknown}, {unknown}) 1222 269..280 '{ loop {} }': ({unknown}, {unknown})
1193 271..278 'loop {}': ! 1223 271..278 'loop {}': !
1194 276..278 '{}': () 1224 276..278 '{}': ()
1195 292..429 '{ ...o(); }': () 1225 292..414 '{ ...o(); }': ()
1196 368..374 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>) 1226 302..308 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1197 369..370 'c': impl Iterator<Item = impl Trait<u128>> 1227 303..304 'a': impl Iterator<Item = impl Trait<u32>>
1198 372..373 'd': impl Trait<u128> 1228 306..307 'b': impl Trait<u64>
1199 377..380 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>) 1229 311..314 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1200 377..387 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>) 1230 311..316 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1201 381..386 '1u128': u128 1231 322..323 'a': impl Iterator<Item = impl Trait<u32>>
1202 393..394 'c': impl Iterator<Item = impl Trait<u128>> 1232 322..330 'a.next()': impl Trait<u32>
1203 393..401 'c.next()': impl Trait<u128> 1233 322..336 'a.next().foo()': u32
1234 342..343 'b': impl Trait<u64>
1235 342..349 'b.foo()': u64
1236 359..365 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1237 360..361 'c': impl Iterator<Item = impl Trait<u128>>
1238 363..364 'd': impl Trait<u128>
1239 368..371 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1240 368..378 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1241 372..377 '1u128': u128
1242 384..385 'c': impl Iterator<Item = impl Trait<u128>>
1243 384..392 'c.next()': impl Trait<u128>
1244 384..398 'c.next().foo()': u128
1245 404..405 'd': impl Trait<u128>
1246 404..411 'd.foo()': u128
1204 "### 1247 "###
1205 ); 1248 );
1206} 1249}
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs
index 8446ef88e..1f4d2c076 100644
--- a/crates/ra_ide_db/src/change.rs
+++ b/crates/ra_ide_db/src/change.rs
@@ -369,6 +369,7 @@ impl RootDatabase {
369 hir::db::ImplDatumQuery 369 hir::db::ImplDatumQuery
370 hir::db::AssociatedTyValueQuery 370 hir::db::AssociatedTyValueQuery
371 hir::db::TraitSolveQuery 371 hir::db::TraitSolveQuery
372 hir::db::ReturnTypeImplTraitsQuery
372 373
373 // SymbolsDatabase 374 // SymbolsDatabase
374 crate::symbol_index::FileSymbolsQuery 375 crate::symbol_index::FileSymbolsQuery