diff options
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 5 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 27 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 5 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/path.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/unify.rs | 8 |
5 files changed, 21 insertions, 26 deletions
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index cf0a3add4..7e8846f27 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -6,7 +6,6 @@ | |||
6 | 6 | ||
7 | use chalk_ir::{Mutability, TyVariableKind}; | 7 | use chalk_ir::{Mutability, TyVariableKind}; |
8 | use hir_def::lang_item::LangItemTarget; | 8 | use hir_def::lang_item::LangItemTarget; |
9 | use test_utils::mark; | ||
10 | 9 | ||
11 | use crate::{autoderef, traits::Solution, Obligation, Substs, TraitRef, Ty}; | 10 | use crate::{autoderef, traits::Solution, Obligation, Substs, TraitRef, Ty}; |
12 | 11 | ||
@@ -35,7 +34,7 @@ impl<'a> InferenceContext<'a> { | |||
35 | ty1.clone() | 34 | ty1.clone() |
36 | } else { | 35 | } else { |
37 | if let (Ty::FnDef(..), Ty::FnDef(..)) = (ty1, ty2) { | 36 | if let (Ty::FnDef(..), Ty::FnDef(..)) = (ty1, ty2) { |
38 | mark::hit!(coerce_fn_reification); | 37 | cov_mark::hit!(coerce_fn_reification); |
39 | // Special case: two function types. Try to coerce both to | 38 | // Special case: two function types. Try to coerce both to |
40 | // pointers to have a chance at getting a match. See | 39 | // pointers to have a chance at getting a match. See |
41 | // https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916 | 40 | // https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916 |
@@ -45,7 +44,7 @@ impl<'a> InferenceContext<'a> { | |||
45 | let ptr_ty2 = Ty::fn_ptr(sig2); | 44 | let ptr_ty2 = Ty::fn_ptr(sig2); |
46 | self.coerce_merge_branch(&ptr_ty1, &ptr_ty2) | 45 | self.coerce_merge_branch(&ptr_ty1, &ptr_ty2) |
47 | } else { | 46 | } else { |
48 | mark::hit!(coerce_merge_fail_fallback); | 47 | cov_mark::hit!(coerce_merge_fail_fallback); |
49 | ty1.clone() | 48 | ty1.clone() |
50 | } | 49 | } |
51 | } | 50 | } |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index cf1f1038a..262177ffb 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -8,11 +8,10 @@ use hir_def::{ | |||
8 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, | 8 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, |
9 | path::{GenericArg, GenericArgs}, | 9 | path::{GenericArg, GenericArgs}, |
10 | resolver::resolver_for_expr, | 10 | resolver::resolver_for_expr, |
11 | AdtId, AssocContainerId, FieldId, Lookup, | 11 | AssocContainerId, FieldId, Lookup, |
12 | }; | 12 | }; |
13 | use hir_expand::name::{name, Name}; | 13 | use hir_expand::name::{name, Name}; |
14 | use syntax::ast::RangeOp; | 14 | use syntax::ast::RangeOp; |
15 | use test_utils::mark; | ||
16 | 15 | ||
17 | use crate::{ | 16 | use crate::{ |
18 | autoderef, | 17 | autoderef, |
@@ -21,8 +20,8 @@ use crate::{ | |||
21 | primitive::{self, UintTy}, | 20 | primitive::{self, UintTy}, |
22 | traits::{FnTrait, InEnvironment}, | 21 | traits::{FnTrait, InEnvironment}, |
23 | utils::{generics, variant_data, Generics}, | 22 | utils::{generics, variant_data, Generics}, |
24 | Binders, CallableDefId, FnPointer, FnSig, Obligation, OpaqueTyId, Rawness, Scalar, Substs, | 23 | AdtId, Binders, CallableDefId, FnPointer, FnSig, Obligation, OpaqueTyId, Rawness, Scalar, |
25 | TraitRef, Ty, | 24 | Substs, TraitRef, Ty, |
26 | }; | 25 | }; |
27 | 26 | ||
28 | use super::{ | 27 | use super::{ |
@@ -429,14 +428,14 @@ impl<'a> InferenceContext<'a> { | |||
429 | Ty::Tuple(_, substs) => { | 428 | Ty::Tuple(_, substs) => { |
430 | name.as_tuple_index().and_then(|idx| substs.0.get(idx).cloned()) | 429 | name.as_tuple_index().and_then(|idx| substs.0.get(idx).cloned()) |
431 | } | 430 | } |
432 | Ty::Adt(AdtId::StructId(s), parameters) => { | 431 | Ty::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => { |
433 | self.db.struct_data(s).variant_data.field(name).map(|local_id| { | 432 | self.db.struct_data(s).variant_data.field(name).map(|local_id| { |
434 | let field = FieldId { parent: s.into(), local_id }; | 433 | let field = FieldId { parent: s.into(), local_id }; |
435 | self.write_field_resolution(tgt_expr, field); | 434 | self.write_field_resolution(tgt_expr, field); |
436 | self.db.field_types(s.into())[field.local_id].clone().subst(¶meters) | 435 | self.db.field_types(s.into())[field.local_id].clone().subst(¶meters) |
437 | }) | 436 | }) |
438 | } | 437 | } |
439 | Ty::Adt(AdtId::UnionId(u), parameters) => { | 438 | Ty::Adt(AdtId(hir_def::AdtId::UnionId(u)), parameters) => { |
440 | self.db.union_data(u).variant_data.field(name).map(|local_id| { | 439 | self.db.union_data(u).variant_data.field(name).map(|local_id| { |
441 | let field = FieldId { parent: u.into(), local_id }; | 440 | let field = FieldId { parent: u.into(), local_id }; |
442 | self.write_field_resolution(tgt_expr, field); | 441 | self.write_field_resolution(tgt_expr, field); |
@@ -498,7 +497,7 @@ impl<'a> InferenceContext<'a> { | |||
498 | _ => (), | 497 | _ => (), |
499 | } | 498 | } |
500 | sb = sb.fill(repeat_with(|| self.table.new_type_var())); | 499 | sb = sb.fill(repeat_with(|| self.table.new_type_var())); |
501 | Ty::Adt(box_, sb.build()) | 500 | Ty::adt_ty(box_, sb.build()) |
502 | } else { | 501 | } else { |
503 | Ty::Unknown | 502 | Ty::Unknown |
504 | } | 503 | } |
@@ -565,7 +564,7 @@ impl<'a> InferenceContext<'a> { | |||
565 | let ret = op::binary_op_return_ty(*op, lhs_ty.clone(), rhs_ty.clone()); | 564 | let ret = op::binary_op_return_ty(*op, lhs_ty.clone(), rhs_ty.clone()); |
566 | 565 | ||
567 | if ret == Ty::Unknown { | 566 | if ret == Ty::Unknown { |
568 | mark::hit!(infer_expr_inner_binary_operator_overload); | 567 | cov_mark::hit!(infer_expr_inner_binary_operator_overload); |
569 | 568 | ||
570 | self.resolve_associated_type_with_params( | 569 | self.resolve_associated_type_with_params( |
571 | lhs_ty, | 570 | lhs_ty, |
@@ -586,31 +585,31 @@ impl<'a> InferenceContext<'a> { | |||
586 | let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect)); | 585 | let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect)); |
587 | match (range_type, lhs_ty, rhs_ty) { | 586 | match (range_type, lhs_ty, rhs_ty) { |
588 | (RangeOp::Exclusive, None, None) => match self.resolve_range_full() { | 587 | (RangeOp::Exclusive, None, None) => match self.resolve_range_full() { |
589 | Some(adt) => Ty::Adt(adt, Substs::empty()), | 588 | Some(adt) => Ty::adt_ty(adt, Substs::empty()), |
590 | None => Ty::Unknown, | 589 | None => Ty::Unknown, |
591 | }, | 590 | }, |
592 | (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() { | 591 | (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() { |
593 | Some(adt) => Ty::Adt(adt, Substs::single(ty)), | 592 | Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), |
594 | None => Ty::Unknown, | 593 | None => Ty::Unknown, |
595 | }, | 594 | }, |
596 | (RangeOp::Inclusive, None, Some(ty)) => { | 595 | (RangeOp::Inclusive, None, Some(ty)) => { |
597 | match self.resolve_range_to_inclusive() { | 596 | match self.resolve_range_to_inclusive() { |
598 | Some(adt) => Ty::Adt(adt, Substs::single(ty)), | 597 | Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), |
599 | None => Ty::Unknown, | 598 | None => Ty::Unknown, |
600 | } | 599 | } |
601 | } | 600 | } |
602 | (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() { | 601 | (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() { |
603 | Some(adt) => Ty::Adt(adt, Substs::single(ty)), | 602 | Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), |
604 | None => Ty::Unknown, | 603 | None => Ty::Unknown, |
605 | }, | 604 | }, |
606 | (RangeOp::Inclusive, Some(_), Some(ty)) => { | 605 | (RangeOp::Inclusive, Some(_), Some(ty)) => { |
607 | match self.resolve_range_inclusive() { | 606 | match self.resolve_range_inclusive() { |
608 | Some(adt) => Ty::Adt(adt, Substs::single(ty)), | 607 | Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), |
609 | None => Ty::Unknown, | 608 | None => Ty::Unknown, |
610 | } | 609 | } |
611 | } | 610 | } |
612 | (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() { | 611 | (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() { |
613 | Some(adt) => Ty::Adt(adt, Substs::single(ty)), | 612 | Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), |
614 | None => Ty::Unknown, | 613 | None => Ty::Unknown, |
615 | }, | 614 | }, |
616 | (RangeOp::Inclusive, _, None) => Ty::Unknown, | 615 | (RangeOp::Inclusive, _, None) => Ty::Unknown, |
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index eb099311c..a0ac8d80f 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs | |||
@@ -10,7 +10,6 @@ use hir_def::{ | |||
10 | FieldId, | 10 | FieldId, |
11 | }; | 11 | }; |
12 | use hir_expand::name::Name; | 12 | use hir_expand::name::Name; |
13 | use test_utils::mark; | ||
14 | 13 | ||
15 | use super::{BindingMode, Expectation, InferenceContext}; | 14 | use super::{BindingMode, Expectation, InferenceContext}; |
16 | use crate::{lower::lower_to_chalk_mutability, utils::variant_data, Substs, Ty}; | 15 | use crate::{lower::lower_to_chalk_mutability, utils::variant_data, Substs, Ty}; |
@@ -108,7 +107,7 @@ impl<'a> InferenceContext<'a> { | |||
108 | } | 107 | } |
109 | } | 108 | } |
110 | } else if let Pat::Ref { .. } = &body[pat] { | 109 | } else if let Pat::Ref { .. } = &body[pat] { |
111 | mark::hit!(match_ergonomics_ref); | 110 | cov_mark::hit!(match_ergonomics_ref); |
112 | // When you encounter a `&pat` pattern, reset to Move. | 111 | // When you encounter a `&pat` pattern, reset to Move. |
113 | // This is so that `w` is by value: `let (_, &w) = &(1, &2);` | 112 | // This is so that `w` is by value: `let (_, &w) = &(1, &2);` |
114 | default_bm = BindingMode::Move; | 113 | default_bm = BindingMode::Move; |
@@ -237,7 +236,7 @@ impl<'a> InferenceContext<'a> { | |||
237 | }; | 236 | }; |
238 | 237 | ||
239 | let inner_ty = self.infer_pat(*inner, inner_expected, default_bm); | 238 | let inner_ty = self.infer_pat(*inner, inner_expected, default_bm); |
240 | Ty::Adt(box_adt, Substs::single(inner_ty)) | 239 | Ty::adt_ty(box_adt, Substs::single(inner_ty)) |
241 | } | 240 | } |
242 | None => Ty::Unknown, | 241 | None => Ty::Unknown, |
243 | }, | 242 | }, |
diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs index 5d541104e..ae3554bac 100644 --- a/crates/hir_ty/src/infer/path.rs +++ b/crates/hir_ty/src/infer/path.rs | |||
@@ -260,7 +260,7 @@ impl<'a> InferenceContext<'a> { | |||
260 | })); | 260 | })); |
261 | Some(trait_substs) | 261 | Some(trait_substs) |
262 | } | 262 | } |
263 | AssocContainerId::ContainerId(_) => None, | 263 | AssocContainerId::ModuleId(_) => None, |
264 | }; | 264 | }; |
265 | 265 | ||
266 | self.write_assoc_resolution(id, item); | 266 | self.write_assoc_resolution(id, item); |
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 99a89a7f3..54fcfed10 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs | |||
@@ -5,8 +5,6 @@ use std::borrow::Cow; | |||
5 | use chalk_ir::{FloatTy, IntTy, TyVariableKind}; | 5 | use chalk_ir::{FloatTy, IntTy, TyVariableKind}; |
6 | use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; | 6 | use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; |
7 | 7 | ||
8 | use test_utils::mark; | ||
9 | |||
10 | use super::{InferenceContext, Obligation}; | 8 | use super::{InferenceContext, Obligation}; |
11 | use crate::{ | 9 | use crate::{ |
12 | BoundVar, Canonical, DebruijnIndex, GenericPredicate, InEnvironment, InferenceVar, Scalar, | 10 | BoundVar, Canonical, DebruijnIndex, GenericPredicate, InEnvironment, InferenceVar, Scalar, |
@@ -387,7 +385,7 @@ impl InferenceTable { | |||
387 | // more than once | 385 | // more than once |
388 | for i in 0..3 { | 386 | for i in 0..3 { |
389 | if i > 0 { | 387 | if i > 0 { |
390 | mark::hit!(type_var_resolves_to_int_var); | 388 | cov_mark::hit!(type_var_resolves_to_int_var); |
391 | } | 389 | } |
392 | match &*ty { | 390 | match &*ty { |
393 | Ty::InferenceVar(tv, _) => { | 391 | Ty::InferenceVar(tv, _) => { |
@@ -416,7 +414,7 @@ impl InferenceTable { | |||
416 | Ty::InferenceVar(tv, kind) => { | 414 | Ty::InferenceVar(tv, kind) => { |
417 | let inner = tv.to_inner(); | 415 | let inner = tv.to_inner(); |
418 | if tv_stack.contains(&inner) { | 416 | if tv_stack.contains(&inner) { |
419 | mark::hit!(type_var_cycles_resolve_as_possible); | 417 | cov_mark::hit!(type_var_cycles_resolve_as_possible); |
420 | // recursive type | 418 | // recursive type |
421 | return self.type_variable_table.fallback_value(tv, kind); | 419 | return self.type_variable_table.fallback_value(tv, kind); |
422 | } | 420 | } |
@@ -443,7 +441,7 @@ impl InferenceTable { | |||
443 | Ty::InferenceVar(tv, kind) => { | 441 | Ty::InferenceVar(tv, kind) => { |
444 | let inner = tv.to_inner(); | 442 | let inner = tv.to_inner(); |
445 | if tv_stack.contains(&inner) { | 443 | if tv_stack.contains(&inner) { |
446 | mark::hit!(type_var_cycles_resolve_completely); | 444 | cov_mark::hit!(type_var_cycles_resolve_completely); |
447 | // recursive type | 445 | // recursive type |
448 | return self.type_variable_table.fallback_value(tv, kind); | 446 | return self.type_variable_table.fallback_value(tv, kind); |
449 | } | 447 | } |