Remove the old variants replaced by Ty::Apply

This commit is contained in:
Florian Diebold 2019-03-17 19:37:09 +01:00
parent 7a8ba53542
commit 8a5fbf4713
12 changed files with 265 additions and 403 deletions

View file

@ -1,4 +1,4 @@
use hir::{Ty, AdtDef};
use hir::{Ty, AdtDef, TypeName};
use crate::completion::{CompletionContext, Completions};
@ -24,23 +24,20 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) {
for receiver in receiver.autoderef(ctx.db) {
match receiver {
Ty::Adt { def_id, ref substs, .. } => {
match def_id {
AdtDef::Struct(s) => {
for field in s.fields(ctx.db) {
acc.add_field(ctx, field, substs);
}
Ty::Apply(a_ty) => match a_ty.name {
TypeName::Adt(AdtDef::Struct(s)) => {
for field in s.fields(ctx.db) {
acc.add_field(ctx, field, &a_ty.parameters);
}
// TODO unions
AdtDef::Enum(_) => (),
}
}
Ty::Tuple(fields) => {
for (i, ty) in fields.iter().enumerate() {
acc.add_pos_field(ctx, i, ty);
// TODO unions
TypeName::Tuple => {
for (i, ty) in a_ty.parameters.iter().enumerate() {
acc.add_pos_field(ctx, i, ty);
}
}
}
_ => {}
},
_ => {}
};
}

View file

@ -1,4 +1,4 @@
use hir::{Ty, AdtDef};
use hir::AdtDef;
use crate::completion::{CompletionContext, Completions};
@ -15,8 +15,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon
None => return,
};
let ty = infer_result[expr].clone();
let (adt, substs) = match ty {
Ty::Adt { def_id, ref substs, .. } => (def_id, substs),
let (adt, substs) = match ty.as_adt() {
Some(res) => res,
_ => return,
};
match adt {

View file

@ -87,14 +87,12 @@ pub(crate) fn reference_definition(
if let Some(expr) = struct_lit.and_then(|lit| source_map.node_expr(lit.into())) {
let ty = infer_result[expr].clone();
if let hir::Ty::Adt { def_id, .. } = ty {
if let hir::AdtDef::Struct(s) = def_id {
let hir_path = hir::Path::from_name_ref(name_ref);
let hir_name = hir_path.as_ident().unwrap();
if let Some((hir::AdtDef::Struct(s), _)) = ty.as_adt() {
let hir_path = hir::Path::from_name_ref(name_ref);
let hir_name = hir_path.as_ident().unwrap();
if let Some(field) = s.field(db, hir_name) {
return Exact(NavigationTarget::from_field(db, field));
}
if let Some(field) = s.field(db, hir_name) {
return Exact(NavigationTarget::from_field(db, field));
}
}
}
@ -124,7 +122,7 @@ pub(crate) fn reference_definition(
Some(Resolution::SelfType(impl_block)) => {
let ty = impl_block.target_ty(db);
if let hir::Ty::Adt { def_id, .. } = ty {
if let Some((def_id, _)) = ty.as_adt() {
return Exact(NavigationTarget::from_adt_def(db, def_id));
}
}

View file

@ -517,23 +517,8 @@ The Some variant
assert_eq!("u32", &type_name);
}
// FIXME: improve type_of to make this work
#[test]
fn test_type_of_for_expr_1() {
let (analysis, range) = single_file_with_range(
"
fn main() {
let foo = <|>1 + foo_test<|>;
}
",
);
let type_name = analysis.type_of(range).unwrap().unwrap();
assert_eq!("{unknown}", &type_name);
}
#[test]
fn test_type_of_for_expr_2() {
fn test_type_of_for_expr() {
let (analysis, range) = single_file_with_range(
"
fn main() {