diff options
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 16 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 9 |
3 files changed, 14 insertions, 19 deletions
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 4b7f31521..7be914451 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -47,10 +47,7 @@ impl<'a> InferenceContext<'a> { | |||
47 | // pointers to have a chance at getting a match. See | 47 | // pointers to have a chance at getting a match. See |
48 | // https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916 | 48 | // https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916 |
49 | let sig = match (ty1.kind(&Interner), ty2.kind(&Interner)) { | 49 | let sig = match (ty1.kind(&Interner), ty2.kind(&Interner)) { |
50 | (TyKind::FnDef(..), TyKind::FnDef(..)) | 50 | (TyKind::FnDef(..) | TyKind::Closure(..), TyKind::FnDef(..) | TyKind::Closure(..)) => { |
51 | | (TyKind::Closure(..), TyKind::FnDef(..)) | ||
52 | | (TyKind::FnDef(..), TyKind::Closure(..)) | ||
53 | | (TyKind::Closure(..), TyKind::Closure(..)) => { | ||
54 | // FIXME: we're ignoring safety here. To be more correct, if we have one FnDef and one Closure, | 51 | // FIXME: we're ignoring safety here. To be more correct, if we have one FnDef and one Closure, |
55 | // we should be coercing the closure to a fn pointer of the safety of the FnDef | 52 | // we should be coercing the closure to a fn pointer of the safety of the FnDef |
56 | cov_mark::hit!(coerce_fn_reification); | 53 | cov_mark::hit!(coerce_fn_reification); |
@@ -448,8 +445,7 @@ fn safe_to_unsafe_fn_ty(fn_ty: FnPointer) -> FnPointer { | |||
448 | 445 | ||
449 | fn coerce_mutabilities(from: Mutability, to: Mutability) -> Result<(), TypeError> { | 446 | fn coerce_mutabilities(from: Mutability, to: Mutability) -> Result<(), TypeError> { |
450 | match (from, to) { | 447 | match (from, to) { |
451 | (Mutability::Mut, Mutability::Mut) | 448 | (Mutability::Mut, Mutability::Mut | Mutability::Not) |
452 | | (Mutability::Mut, Mutability::Not) | ||
453 | | (Mutability::Not, Mutability::Not) => Ok(()), | 449 | | (Mutability::Not, Mutability::Not) => Ok(()), |
454 | (Mutability::Not, Mutability::Mut) => Err(TypeError), | 450 | (Mutability::Not, Mutability::Mut) => Err(TypeError), |
455 | } | 451 | } |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 5ea2e5934..4e4f6e5a4 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -593,11 +593,11 @@ impl<'a> InferenceContext<'a> { | |||
593 | UnaryOp::Neg => { | 593 | UnaryOp::Neg => { |
594 | match inner_ty.kind(&Interner) { | 594 | match inner_ty.kind(&Interner) { |
595 | // Fast path for builtins | 595 | // Fast path for builtins |
596 | TyKind::Scalar(Scalar::Int(_)) | 596 | TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_) | Scalar::Float(_)) |
597 | | TyKind::Scalar(Scalar::Uint(_)) | 597 | | TyKind::InferenceVar( |
598 | | TyKind::Scalar(Scalar::Float(_)) | 598 | _, |
599 | | TyKind::InferenceVar(_, TyVariableKind::Integer) | 599 | TyVariableKind::Integer | TyVariableKind::Float, |
600 | | TyKind::InferenceVar(_, TyVariableKind::Float) => inner_ty, | 600 | ) => inner_ty, |
601 | // Otherwise we resolve via the std::ops::Neg trait | 601 | // Otherwise we resolve via the std::ops::Neg trait |
602 | _ => self | 602 | _ => self |
603 | .resolve_associated_type(inner_ty, self.resolve_ops_neg_output()), | 603 | .resolve_associated_type(inner_ty, self.resolve_ops_neg_output()), |
@@ -606,9 +606,7 @@ impl<'a> InferenceContext<'a> { | |||
606 | UnaryOp::Not => { | 606 | UnaryOp::Not => { |
607 | match inner_ty.kind(&Interner) { | 607 | match inner_ty.kind(&Interner) { |
608 | // Fast path for builtins | 608 | // Fast path for builtins |
609 | TyKind::Scalar(Scalar::Bool) | 609 | TyKind::Scalar(Scalar::Bool | Scalar::Int(_) | Scalar::Uint(_)) |
610 | | TyKind::Scalar(Scalar::Int(_)) | ||
611 | | TyKind::Scalar(Scalar::Uint(_)) | ||
612 | | TyKind::InferenceVar(_, TyVariableKind::Integer) => inner_ty, | 610 | | TyKind::InferenceVar(_, TyVariableKind::Integer) => inner_ty, |
613 | // Otherwise we resolve via the std::ops::Not trait | 611 | // Otherwise we resolve via the std::ops::Not trait |
614 | _ => self | 612 | _ => self |
@@ -735,7 +733,7 @@ impl<'a> InferenceContext<'a> { | |||
735 | Expr::Array(array) => { | 733 | Expr::Array(array) => { |
736 | let elem_ty = | 734 | let elem_ty = |
737 | match expected.to_option(&mut self.table).as_ref().map(|t| t.kind(&Interner)) { | 735 | match expected.to_option(&mut self.table).as_ref().map(|t| t.kind(&Interner)) { |
738 | Some(TyKind::Array(st, _)) | Some(TyKind::Slice(st)) => st.clone(), | 736 | Some(TyKind::Array(st, _) | TyKind::Slice(st)) => st.clone(), |
739 | _ => self.table.new_type_var(), | 737 | _ => self.table.new_type_var(), |
740 | }; | 738 | }; |
741 | 739 | ||
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 035f4ded6..58cb23e9d 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs | |||
@@ -297,10 +297,11 @@ fn is_non_ref_pat(body: &hir_def::body::Body, pat: PatId) -> bool { | |||
297 | Expr::Literal(Literal::String(..)) => false, | 297 | Expr::Literal(Literal::String(..)) => false, |
298 | _ => true, | 298 | _ => true, |
299 | }, | 299 | }, |
300 | Pat::Bind { mode: BindingAnnotation::Mutable, subpat: Some(subpat), .. } | 300 | Pat::Bind { |
301 | | Pat::Bind { mode: BindingAnnotation::Unannotated, subpat: Some(subpat), .. } => { | 301 | mode: BindingAnnotation::Mutable | BindingAnnotation::Unannotated, |
302 | is_non_ref_pat(body, *subpat) | 302 | subpat: Some(subpat), |
303 | } | 303 | .. |
304 | } => is_non_ref_pat(body, *subpat), | ||
304 | Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Box { .. } | Pat::Missing => false, | 305 | Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Box { .. } | Pat::Missing => false, |
305 | } | 306 | } |
306 | } | 307 | } |