diff options
author | Florian Diebold <[email protected]> | 2020-06-05 16:41:58 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-06-05 16:41:58 +0100 |
commit | 0d2328f3eaf69c6a50fe6c1e946257bd3503d751 (patch) | |
tree | ae6cfd699840c47bc1e051a0b3c13d62babd5177 /crates/ra_hir_ty/src | |
parent | 02962b374ecefd6f2a75956f4fb18806531d1d51 (diff) |
Review fixes
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/display.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/lower.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 73 |
3 files changed, 65 insertions, 23 deletions
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 | ||
5 | use crate::{ | 5 | use 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 | }; |
9 | use hir_def::{ | 9 | use 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 | }; |
24 | use hir_expand::name::Name; | ||
24 | use ra_arena::map::ArenaMap; | 25 | use ra_arena::map::ArenaMap; |
25 | use ra_db::CrateId; | 26 | use ra_db::CrateId; |
27 | use test_utils::mark; | ||
26 | 28 | ||
27 | use crate::{ | 29 | use 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 | }; |
38 | use hir_expand::name::Name; | ||
39 | 40 | ||
40 | #[derive(Debug)] | 41 | #[derive(Debug)] |
41 | pub struct TyLoweringContext<'a> { | 42 | pub 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 | ||
720 | impl ReturnTypeImplTrait { | 718 | impl 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] |
1163 | fn return_pos_impl_trait() { | 1163 | fn simple_return_pos_impl_trait() { |
1164 | mark::check!(lower_rpit); | ||
1165 | assert_snapshot!( | ||
1166 | infer(r#" | ||
1167 | trait Trait<T> { | ||
1168 | fn foo(&self) -> T; | ||
1169 | } | ||
1170 | fn bar() -> impl Trait<u64> { loop {} } | ||
1171 | |||
1172 | fn 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] | ||
1193 | fn more_return_pos_impl_trait() { | ||
1164 | assert_snapshot!( | 1194 | assert_snapshot!( |
1165 | infer(r#" | 1195 | infer(r#" |
1166 | trait Iterator { | 1196 | trait Iterator { |
@@ -1174,12 +1204,12 @@ fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} } | |||
1174 | fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} } | 1204 | fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} } |
1175 | 1205 | ||
1176 | fn test() { | 1206 | fn 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 | } |