mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Review fixes
This commit is contained in:
parent
02962b374e
commit
0d2328f3ea
5 changed files with 68 additions and 25 deletions
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1160,7 +1160,37 @@ fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn return_pos_impl_trait() {
|
||||
fn simple_return_pos_impl_trait() {
|
||||
mark::check!(lower_rpit);
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
trait Trait<T> {
|
||||
fn foo(&self) -> T;
|
||||
}
|
||||
fn bar() -> impl Trait<u64> { 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<u64>
|
||||
109..112 'bar': fn bar() -> impl Trait<u64>
|
||||
109..114 'bar()': impl Trait<u64>
|
||||
120..121 'a': impl Trait<u64>
|
||||
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<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
|
|||
fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { 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<Item = impl Trait<u128>>, impl Trait<u128>)
|
||||
369..370 'c': impl Iterator<Item = impl Trait<u128>>
|
||||
372..373 'd': impl Trait<u128>
|
||||
377..380 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
|
||||
377..387 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
|
||||
381..386 '1u128': u128
|
||||
393..394 'c': impl Iterator<Item = impl Trait<u128>>
|
||||
393..401 'c.next()': impl Trait<u128>
|
||||
292..414 '{ ...o(); }': ()
|
||||
302..308 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
|
||||
303..304 'a': impl Iterator<Item = impl Trait<u32>>
|
||||
306..307 'b': impl Trait<u64>
|
||||
311..314 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
|
||||
311..316 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
|
||||
322..323 'a': impl Iterator<Item = impl Trait<u32>>
|
||||
322..330 'a.next()': impl Trait<u32>
|
||||
322..336 'a.next().foo()': u32
|
||||
342..343 'b': impl Trait<u64>
|
||||
342..349 'b.foo()': u64
|
||||
359..365 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
|
||||
360..361 'c': impl Iterator<Item = impl Trait<u128>>
|
||||
363..364 'd': impl Trait<u128>
|
||||
368..371 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
|
||||
368..378 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
|
||||
372..377 '1u128': u128
|
||||
384..385 'c': impl Iterator<Item = impl Trait<u128>>
|
||||
384..392 'c.next()': impl Trait<u128>
|
||||
384..398 'c.next().foo()': u128
|
||||
404..405 'd': impl Trait<u128>
|
||||
404..411 'd.foo()': u128
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
|
|
@ -369,6 +369,7 @@ impl RootDatabase {
|
|||
hir::db::ImplDatumQuery
|
||||
hir::db::AssociatedTyValueQuery
|
||||
hir::db::TraitSolveQuery
|
||||
hir::db::ReturnTypeImplTraitsQuery
|
||||
|
||||
// SymbolsDatabase
|
||||
crate::symbol_index::FileSymbolsQuery
|
||||
|
|
Loading…
Reference in a new issue