Skip to content

Commit 0d2328f

Browse files
committed
Review fixes
1 parent 02962b3 commit 0d2328f

File tree

5 files changed

+68
-25
lines changed

5 files changed

+68
-25
lines changed

crates/ra_hir/src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub use hir_ty::db::{
1818
GenericDefaultsQuery, GenericPredicatesForParamQuery, GenericPredicatesQuery, HirDatabase,
1919
HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, ImplsForTraitQuery,
2020
ImplsInCrateQuery, InferQueryQuery, InternAssocTyValueQuery, InternChalkImplQuery,
21-
InternTypeCtorQuery, InternTypeParamIdQuery, StructDatumQuery, TraitDatumQuery,
22-
TraitSolveQuery, TyQuery, ValueTyQuery,
21+
InternTypeCtorQuery, InternTypeParamIdQuery, ReturnTypeImplTraitsQuery, StructDatumQuery,
22+
TraitDatumQuery, TraitSolveQuery, TyQuery, ValueTyQuery,
2323
};
2424

2525
#[test]

crates/ra_hir_ty/src/display.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fmt;
44

55
use crate::{
66
db::HirDatabase, utils::generics, ApplicationTy, CallableDef, FnSig, GenericPredicate,
7-
Obligation, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
7+
Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
88
};
99
use hir_def::{
1010
find_path, generics::TypeParamProvenance, item_scope::ItemInNs, AdtId, AssocContainerId,
@@ -361,7 +361,7 @@ impl HirDisplay for ApplicationTy {
361361
}
362362
TypeCtor::OpaqueType(opaque_ty_id) => {
363363
let bounds = match opaque_ty_id {
364-
crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
364+
OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
365365
let datas =
366366
f.db.return_type_impl_traits(func).expect("impl trait id without data");
367367
let data = (*datas)
@@ -448,7 +448,7 @@ impl HirDisplay for Ty {
448448
}
449449
Ty::Opaque(opaque_ty) => {
450450
let bounds = match opaque_ty.opaque_ty_id {
451-
crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
451+
OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
452452
let datas =
453453
f.db.return_type_impl_traits(func).expect("impl trait id without data");
454454
let data = (*datas)

crates/ra_hir_ty/src/lower.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ use hir_def::{
2121
HasModule, ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId,
2222
UnionId, VariantId,
2323
};
24+
use hir_expand::name::Name;
2425
use ra_arena::map::ArenaMap;
2526
use ra_db::CrateId;
27+
use test_utils::mark;
2628

2729
use crate::{
2830
db::HirDatabase,
@@ -35,7 +37,6 @@ use crate::{
3537
ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, ReturnTypeImplTraits, Substs,
3638
TraitEnvironment, TraitRef, Ty, TypeCtor, TypeWalk,
3739
};
38-
use hir_expand::name::Name;
3940

4041
#[derive(Debug)]
4142
pub struct TyLoweringContext<'a> {
@@ -220,10 +221,7 @@ impl Ty {
220221

221222
let func = match ctx.resolver.generic_def() {
222223
Some(GenericDefId::FunctionId(f)) => f,
223-
_ => {
224-
// this shouldn't happen
225-
return (Ty::Unknown, None);
226-
}
224+
_ => panic!("opaque impl trait lowering in non-function"),
227225
};
228226
let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx);
229227
let generics = generics(ctx.db.upcast(), func.into());
@@ -719,6 +717,7 @@ fn assoc_type_bindings_from_type_bound<'a>(
719717

720718
impl ReturnTypeImplTrait {
721719
fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self {
720+
mark::hit!(lower_rpit);
722721
let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0));
723722
let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| {
724723
bounds

crates/ra_hir_ty/src/tests/traits.rs

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,37 @@ fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
11601160
}
11611161

11621162
#[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() {
11641194
assert_snapshot!(
11651195
infer(r#"
11661196
trait Iterator {
@@ -1174,12 +1204,12 @@ fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
11741204
fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
11751205
11761206
fn test() {
1177-
// let (a, b) = bar();
1178-
// a.next().foo();
1179-
// b.foo();
1207+
let (a, b) = bar();
1208+
a.next().foo();
1209+
b.foo();
11801210
let (c, d) = baz(1u128);
1181-
c.next();//.foo();
1182-
// d.foo();
1211+
c.next().foo();
1212+
d.foo();
11831213
}
11841214
"#),
11851215
@r###"
@@ -1192,15 +1222,28 @@ fn test() {
11921222
269..280 '{ loop {} }': ({unknown}, {unknown})
11931223
271..278 'loop {}': !
11941224
276..278 '{}': ()
1195-
292..429 '{ ...o(); }': ()
1196-
368..374 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1197-
369..370 'c': impl Iterator<Item = impl Trait<u128>>
1198-
372..373 'd': impl Trait<u128>
1199-
377..380 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1200-
377..387 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1201-
381..386 '1u128': u128
1202-
393..394 'c': impl Iterator<Item = impl Trait<u128>>
1203-
393..401 'c.next()': impl Trait<u128>
1225+
292..414 '{ ...o(); }': ()
1226+
302..308 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1227+
303..304 'a': impl Iterator<Item = impl Trait<u32>>
1228+
306..307 'b': impl Trait<u64>
1229+
311..314 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1230+
311..316 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1231+
322..323 'a': impl Iterator<Item = impl Trait<u32>>
1232+
322..330 'a.next()': impl Trait<u32>
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
12041247
"###
12051248
);
12061249
}

crates/ra_ide_db/src/change.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ impl RootDatabase {
369369
hir::db::ImplDatumQuery
370370
hir::db::AssociatedTyValueQuery
371371
hir::db::TraitSolveQuery
372+
hir::db::ReturnTypeImplTraitsQuery
372373

373374
// SymbolsDatabase
374375
crate::symbol_index::FileSymbolsQuery

0 commit comments

Comments
 (0)