mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +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,
|
GenericDefaultsQuery, GenericPredicatesForParamQuery, GenericPredicatesQuery, HirDatabase,
|
||||||
HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, ImplsForTraitQuery,
|
HirDatabaseStorage, ImplDatumQuery, ImplSelfTyQuery, ImplTraitQuery, ImplsForTraitQuery,
|
||||||
ImplsInCrateQuery, InferQueryQuery, InternAssocTyValueQuery, InternChalkImplQuery,
|
ImplsInCrateQuery, InferQueryQuery, InternAssocTyValueQuery, InternChalkImplQuery,
|
||||||
InternTypeCtorQuery, InternTypeParamIdQuery, StructDatumQuery, TraitDatumQuery,
|
InternTypeCtorQuery, InternTypeParamIdQuery, ReturnTypeImplTraitsQuery, StructDatumQuery,
|
||||||
TraitSolveQuery, TyQuery, ValueTyQuery,
|
TraitDatumQuery, TraitSolveQuery, TyQuery, ValueTyQuery,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::fmt;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, utils::generics, ApplicationTy, CallableDef, FnSig, GenericPredicate,
|
db::HirDatabase, utils::generics, ApplicationTy, CallableDef, FnSig, GenericPredicate,
|
||||||
Obligation, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
|
Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
|
||||||
};
|
};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
find_path, generics::TypeParamProvenance, item_scope::ItemInNs, AdtId, AssocContainerId,
|
find_path, generics::TypeParamProvenance, item_scope::ItemInNs, AdtId, AssocContainerId,
|
||||||
|
@ -361,7 +361,7 @@ impl HirDisplay for ApplicationTy {
|
||||||
}
|
}
|
||||||
TypeCtor::OpaqueType(opaque_ty_id) => {
|
TypeCtor::OpaqueType(opaque_ty_id) => {
|
||||||
let bounds = match opaque_ty_id {
|
let bounds = match opaque_ty_id {
|
||||||
crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
|
OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
|
||||||
let datas =
|
let datas =
|
||||||
f.db.return_type_impl_traits(func).expect("impl trait id without data");
|
f.db.return_type_impl_traits(func).expect("impl trait id without data");
|
||||||
let data = (*datas)
|
let data = (*datas)
|
||||||
|
@ -448,7 +448,7 @@ impl HirDisplay for Ty {
|
||||||
}
|
}
|
||||||
Ty::Opaque(opaque_ty) => {
|
Ty::Opaque(opaque_ty) => {
|
||||||
let bounds = match opaque_ty.opaque_ty_id {
|
let bounds = match opaque_ty.opaque_ty_id {
|
||||||
crate::OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
|
OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
|
||||||
let datas =
|
let datas =
|
||||||
f.db.return_type_impl_traits(func).expect("impl trait id without data");
|
f.db.return_type_impl_traits(func).expect("impl trait id without data");
|
||||||
let data = (*datas)
|
let data = (*datas)
|
||||||
|
|
|
@ -21,8 +21,10 @@ use hir_def::{
|
||||||
HasModule, ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId,
|
HasModule, ImplId, LocalFieldId, Lookup, StaticId, StructId, TraitId, TypeAliasId, TypeParamId,
|
||||||
UnionId, VariantId,
|
UnionId, VariantId,
|
||||||
};
|
};
|
||||||
|
use hir_expand::name::Name;
|
||||||
use ra_arena::map::ArenaMap;
|
use ra_arena::map::ArenaMap;
|
||||||
use ra_db::CrateId;
|
use ra_db::CrateId;
|
||||||
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
|
@ -35,7 +37,6 @@ use crate::{
|
||||||
ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, ReturnTypeImplTraits, Substs,
|
ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, ReturnTypeImplTraits, Substs,
|
||||||
TraitEnvironment, TraitRef, Ty, TypeCtor, TypeWalk,
|
TraitEnvironment, TraitRef, Ty, TypeCtor, TypeWalk,
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TyLoweringContext<'a> {
|
pub struct TyLoweringContext<'a> {
|
||||||
|
@ -220,10 +221,7 @@ impl Ty {
|
||||||
|
|
||||||
let func = match ctx.resolver.generic_def() {
|
let func = match ctx.resolver.generic_def() {
|
||||||
Some(GenericDefId::FunctionId(f)) => f,
|
Some(GenericDefId::FunctionId(f)) => f,
|
||||||
_ => {
|
_ => panic!("opaque impl trait lowering in non-function"),
|
||||||
// this shouldn't happen
|
|
||||||
return (Ty::Unknown, None);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx);
|
let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx);
|
||||||
let generics = generics(ctx.db.upcast(), func.into());
|
let generics = generics(ctx.db.upcast(), func.into());
|
||||||
|
@ -719,6 +717,7 @@ fn assoc_type_bindings_from_type_bound<'a>(
|
||||||
|
|
||||||
impl ReturnTypeImplTrait {
|
impl ReturnTypeImplTrait {
|
||||||
fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self {
|
fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self {
|
||||||
|
mark::hit!(lower_rpit);
|
||||||
let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0));
|
let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0));
|
||||||
let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| {
|
let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| {
|
||||||
bounds
|
bounds
|
||||||
|
|
|
@ -1160,7 +1160,37 @@ fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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!(
|
assert_snapshot!(
|
||||||
infer(r#"
|
infer(r#"
|
||||||
trait Iterator {
|
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 baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
|
||||||
|
|
||||||
fn test() {
|
fn test() {
|
||||||
// let (a, b) = bar();
|
let (a, b) = bar();
|
||||||
// a.next().foo();
|
a.next().foo();
|
||||||
// b.foo();
|
b.foo();
|
||||||
let (c, d) = baz(1u128);
|
let (c, d) = baz(1u128);
|
||||||
c.next();//.foo();
|
c.next().foo();
|
||||||
// d.foo();
|
d.foo();
|
||||||
}
|
}
|
||||||
"#),
|
"#),
|
||||||
@r###"
|
@r###"
|
||||||
|
@ -1192,15 +1222,28 @@ fn test() {
|
||||||
269..280 '{ loop {} }': ({unknown}, {unknown})
|
269..280 '{ loop {} }': ({unknown}, {unknown})
|
||||||
271..278 'loop {}': !
|
271..278 'loop {}': !
|
||||||
276..278 '{}': ()
|
276..278 '{}': ()
|
||||||
292..429 '{ ...o(); }': ()
|
292..414 '{ ...o(); }': ()
|
||||||
368..374 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
|
302..308 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
|
||||||
369..370 'c': impl Iterator<Item = impl Trait<u128>>
|
303..304 'a': impl Iterator<Item = impl Trait<u32>>
|
||||||
372..373 'd': impl Trait<u128>
|
306..307 'b': impl Trait<u64>
|
||||||
377..380 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
|
311..314 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
|
||||||
377..387 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
|
311..316 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
|
||||||
381..386 '1u128': u128
|
322..323 'a': impl Iterator<Item = impl Trait<u32>>
|
||||||
393..394 'c': impl Iterator<Item = impl Trait<u128>>
|
322..330 'a.next()': impl Trait<u32>
|
||||||
393..401 'c.next()': impl Trait<u128>
|
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::ImplDatumQuery
|
||||||
hir::db::AssociatedTyValueQuery
|
hir::db::AssociatedTyValueQuery
|
||||||
hir::db::TraitSolveQuery
|
hir::db::TraitSolveQuery
|
||||||
|
hir::db::ReturnTypeImplTraitsQuery
|
||||||
|
|
||||||
// SymbolsDatabase
|
// SymbolsDatabase
|
||||||
crate::symbol_index::FileSymbolsQuery
|
crate::symbol_index::FileSymbolsQuery
|
||||||
|
|
Loading…
Reference in a new issue