From 0d2328f3eaf69c6a50fe6c1e946257bd3503d751 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 5 Jun 2020 17:41:58 +0200 Subject: Review fixes --- crates/ra_hir/src/db.rs | 4 +- crates/ra_hir_ty/src/display.rs | 6 +-- crates/ra_hir_ty/src/lower.rs | 9 ++--- crates/ra_hir_ty/src/tests/traits.rs | 73 ++++++++++++++++++++++++++++-------- crates/ra_ide_db/src/change.rs | 1 + 5 files changed, 68 insertions(+), 25 deletions(-) (limited to 'crates') 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::{ GenericDefaultsQuery, GenericPredicatesForParamQuery, GenericPredicatesQuery, HirDatabase, HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, ImplsForTraitQuery, ImplsInCrateQuery, InferQueryQuery, InternAssocTyValueQuery, InternChalkImplQuery, - InternTypeCtorQuery, InternTypeParamIdQuery, StructDatumQuery, TraitDatumQuery, - TraitSolveQuery, TyQuery, ValueTyQuery, + InternTypeCtorQuery, InternTypeParamIdQuery, ReturnTypeImplTraitsQuery, StructDatumQuery, + TraitDatumQuery, TraitSolveQuery, TyQuery, ValueTyQuery, }; #[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; use crate::{ db::HirDatabase, utils::generics, ApplicationTy, CallableDef, FnSig, GenericPredicate, - Obligation, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, + Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, }; use hir_def::{ find_path, generics::TypeParamProvenance, item_scope::ItemInNs, AdtId, AssocContainerId, @@ -361,7 +361,7 @@ impl HirDisplay for ApplicationTy { } TypeCtor::OpaqueType(opaque_ty_id) => { let bounds = match opaque_ty_id { - crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => { + OpaqueTyId::ReturnTypeImplTrait(func, idx) => { let datas = f.db.return_type_impl_traits(func).expect("impl trait id without data"); let data = (*datas) @@ -448,7 +448,7 @@ impl HirDisplay for Ty { } Ty::Opaque(opaque_ty) => { let bounds = match opaque_ty.opaque_ty_id { - crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => { + OpaqueTyId::ReturnTypeImplTrait(func, idx) => { let datas = f.db.return_type_impl_traits(func).expect("impl trait id without data"); 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::{ HasModule, ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId, }; +use hir_expand::name::Name; use ra_arena::map::ArenaMap; use ra_db::CrateId; +use test_utils::mark; use crate::{ db::HirDatabase, @@ -35,7 +37,6 @@ use crate::{ ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TypeCtor, TypeWalk, }; -use hir_expand::name::Name; #[derive(Debug)] pub struct TyLoweringContext<'a> { @@ -220,10 +221,7 @@ impl Ty { let func = match ctx.resolver.generic_def() { Some(GenericDefId::FunctionId(f)) => f, - _ => { - // this shouldn't happen - return (Ty::Unknown, None); - } + _ => panic!("opaque impl trait lowering in non-function"), }; let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx); let generics = generics(ctx.db.upcast(), func.into()); @@ -719,6 +717,7 @@ fn assoc_type_bindings_from_type_bound<'a>( impl ReturnTypeImplTrait { fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self { + mark::hit!(lower_rpit); let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)); let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { 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, y: &impl Trait) { } #[test] -fn return_pos_impl_trait() { +fn simple_return_pos_impl_trait() { + mark::check!(lower_rpit); + assert_snapshot!( + infer(r#" +trait Trait { + fn foo(&self) -> T; +} +fn bar() -> impl Trait { loop {} } + +fn test() { + let a = bar(); + a.foo(); +} +"#), + @r###" + 30..34 'self': &Self + 72..83 '{ loop {} }': ! + 74..81 'loop {}': ! + 79..81 '{}': () + 95..130 '{ ...o(); }': () + 105..106 'a': impl Trait + 109..112 'bar': fn bar() -> impl Trait + 109..114 'bar()': impl Trait + 120..121 'a': impl Trait + 120..127 'a.foo()': u64 + "### + ); +} + +#[test] +fn more_return_pos_impl_trait() { assert_snapshot!( infer(r#" trait Iterator { @@ -1174,12 +1204,12 @@ fn bar() -> (impl Iterator>, impl Trait) { loop {} } fn baz(t: T) -> (impl Iterator>, impl Trait) { loop {} } fn test() { - // let (a, b) = bar(); - // a.next().foo(); - // b.foo(); + let (a, b) = bar(); + a.next().foo(); + b.foo(); let (c, d) = baz(1u128); - c.next();//.foo(); - // d.foo(); + c.next().foo(); + d.foo(); } "#), @r###" @@ -1192,15 +1222,28 @@ fn test() { 269..280 '{ loop {} }': ({unknown}, {unknown}) 271..278 'loop {}': ! 276..278 '{}': () - 292..429 '{ ...o(); }': () - 368..374 '(c, d)': (impl Iterator>, impl Trait) - 369..370 'c': impl Iterator> - 372..373 'd': impl Trait - 377..380 'baz': fn baz(u128) -> (impl Iterator>, impl Trait) - 377..387 'baz(1u128)': (impl Iterator>, impl Trait) - 381..386 '1u128': u128 - 393..394 'c': impl Iterator> - 393..401 'c.next()': impl Trait + 292..414 '{ ...o(); }': () + 302..308 '(a, b)': (impl Iterator>, impl Trait) + 303..304 'a': impl Iterator> + 306..307 'b': impl Trait + 311..314 'bar': fn bar() -> (impl Iterator>, impl Trait) + 311..316 'bar()': (impl Iterator>, impl Trait) + 322..323 'a': impl Iterator> + 322..330 'a.next()': impl Trait + 322..336 'a.next().foo()': u32 + 342..343 'b': impl Trait + 342..349 'b.foo()': u64 + 359..365 '(c, d)': (impl Iterator>, impl Trait) + 360..361 'c': impl Iterator> + 363..364 'd': impl Trait + 368..371 'baz': fn baz(u128) -> (impl Iterator>, impl Trait) + 368..378 'baz(1u128)': (impl Iterator>, impl Trait) + 372..377 '1u128': u128 + 384..385 'c': impl Iterator> + 384..392 'c.next()': impl Trait + 384..398 'c.next().foo()': u128 + 404..405 'd': impl Trait + 404..411 'd.foo()': u128 "### ); } 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 { hir::db::ImplDatumQuery hir::db::AssociatedTyValueQuery hir::db::TraitSolveQuery + hir::db::ReturnTypeImplTraitsQuery // SymbolsDatabase crate::symbol_index::FileSymbolsQuery -- cgit v1.2.3