From 8ffd76ddc5a5cc6997693b37d691391c9d13a3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 1 Mar 2021 18:13:08 +0200 Subject: Bump deps --- Cargo.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dbd7a746e..63dacf59e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "adler" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bedc89c5c7b5550ffb9372eb5c5ffc7f9f705cc3f4a128bd4669b9745f555093" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "always-assert" @@ -1490,9 +1490,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.62" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "indexmap", "itoa", @@ -1923,18 +1923,18 @@ checksum = "06069a848f95fceae3e5e03c0ddc8cb78452b56654ee0c8e68f938cf790fb9e3" [[package]] name = "xshell" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed373ede30cea03e8c0af22f48ee1ba80efbf06fec8b4746977e6ee703878de0" +checksum = "6f18102278453c8f70ea5c514ac78cb4c73a0ef72a8273d17094b52f9584c0c1" dependencies = [ "xshell-macros", ] [[package]] name = "xshell-macros" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6af9f8119104697b0105989a73c578ce33f922d9d6f3dae0e8ae3d538db321" +checksum = "6093c460064572007f885facc70bb0ca5e40a83ea7ff8b16c1abbee56fd2e767" [[package]] name = "xtask" -- cgit v1.2.3 From 63e8bdb8a26476e8fa668dfdd16966f6ebc81471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 1 Mar 2021 18:17:03 +0200 Subject: Bump chalk --- Cargo.lock | 49 ++++++++++++++++++++---------------------------- crates/hir_ty/Cargo.toml | 6 +++--- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 63dacf59e..0476a15eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,9 +158,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chalk-derive" -version = "0.58.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e625b7c688272783140509a0de8f7aa9000217cb0982c9b10606a12b0b747ba8" +checksum = "4b9000fbcb67353dc8973ab9fd136277d321d85b79bd36b8756bb3ae0979a94a" dependencies = [ "proc-macro2", "quote", @@ -170,9 +170,9 @@ dependencies = [ [[package]] name = "chalk-ir" -version = "0.58.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c220d870128959d7d56667060d556ffdebd490f32ee0fc9f4060a76c1193f206" +checksum = "b23528d61b3557c676eccf508fa0771a38453b379f0b780154eaa7f70afe8dfc" dependencies = [ "bitflags", "chalk-derive", @@ -181,9 +181,9 @@ dependencies = [ [[package]] name = "chalk-recursive" -version = "0.58.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d8cd81a15aa936215378e695a8907b9f1af8626a27a32ee22e97a50984960da" +checksum = "a8bdd37afc666b771de8b4429fe014363d0e74aae5cc26f320f60a3eab34d744" dependencies = [ "chalk-derive", "chalk-ir", @@ -194,14 +194,14 @@ dependencies = [ [[package]] name = "chalk-solve" -version = "0.58.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55571250dfe096a4c899be88c81418284c952ce1c8a06aa16afb5781b298e9c9" +checksum = "4182c42ca319cb71c89898ebc3d2671d1fa7d928123b171b66f1797a2000b9c8" dependencies = [ "chalk-derive", "chalk-ir", "ena", - "itertools 0.9.0", + "itertools", "petgraph", "rustc-hash", "tracing", @@ -475,7 +475,7 @@ dependencies = [ "hir_def", "hir_expand", "hir_ty", - "itertools 0.10.0", + "itertools", "log", "profile", "rustc-hash", @@ -497,7 +497,7 @@ dependencies = [ "fst", "hir_expand", "indexmap", - "itertools 0.10.0", + "itertools", "la-arena", "log", "mbe", @@ -541,7 +541,7 @@ dependencies = [ "expect-test", "hir_def", "hir_expand", - "itertools 0.10.0", + "itertools", "la-arena", "log", "once_cell", @@ -579,7 +579,7 @@ dependencies = [ "ide_db", "ide_ssr", "indexmap", - "itertools 0.10.0", + "itertools", "log", "oorandom", "profile", @@ -601,7 +601,7 @@ dependencies = [ "expect-test", "hir", "ide_db", - "itertools 0.10.0", + "itertools", "profile", "rustc-hash", "stdx", @@ -619,7 +619,7 @@ dependencies = [ "expect-test", "hir", "ide_db", - "itertools 0.10.0", + "itertools", "log", "profile", "rustc-hash", @@ -638,7 +638,7 @@ dependencies = [ "expect-test", "fst", "hir", - "itertools 0.10.0", + "itertools", "log", "once_cell", "profile", @@ -657,7 +657,7 @@ dependencies = [ "expect-test", "hir", "ide_db", - "itertools 0.10.0", + "itertools", "rustc-hash", "syntax", "test_utils", @@ -714,15 +714,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "itertools" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.10.0" @@ -1206,7 +1197,7 @@ dependencies = [ "base_db", "cargo_metadata", "cfg", - "itertools 0.10.0", + "itertools", "la-arena", "log", "paths", @@ -1338,7 +1329,7 @@ dependencies = [ "ide", "ide_db", "ide_ssr", - "itertools 0.10.0", + "itertools", "jemallocator", "jod-thread", "log", @@ -1593,7 +1584,7 @@ dependencies = [ "arrayvec", "expect-test", "indexmap", - "itertools 0.10.0", + "itertools", "once_cell", "parser", "profile", diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml index 6ef9d1e7e..d1302d749 100644 --- a/crates/hir_ty/Cargo.toml +++ b/crates/hir_ty/Cargo.toml @@ -17,9 +17,9 @@ ena = "0.14.0" log = "0.4.8" rustc-hash = "1.1.0" scoped-tls = "1" -chalk-solve = { version = "0.58", default-features = false } -chalk-ir = "0.58" -chalk-recursive = "0.58" +chalk-solve = { version = "0.59", default-features = false } +chalk-ir = "0.59" +chalk-recursive = "0.59" la-arena = { version = "0.2.0", path = "../../lib/arena" } stdx = { path = "../stdx", version = "0.0.0" } -- cgit v1.2.3 From 7072f59fc61b8b487f301df1fe5eefbcc84672aa Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 1 Mar 2021 19:30:34 +0100 Subject: Use chalk_ir::Mutability --- crates/hir/src/code_model.rs | 13 ++++++++----- crates/hir_ty/src/display.rs | 19 +++++++++++++++++-- crates/hir_ty/src/infer.rs | 5 +++-- crates/hir_ty/src/infer/coerce.rs | 14 +++++++------- crates/hir_ty/src/infer/expr.rs | 21 ++++++++++++--------- crates/hir_ty/src/infer/pat.rs | 11 ++++++----- crates/hir_ty/src/lib.rs | 10 ++++------ crates/hir_ty/src/lower.rs | 12 ++++++++++-- crates/hir_ty/src/method_resolution.rs | 9 +++++---- crates/hir_ty/src/traits/chalk/mapping.rs | 28 ++++++---------------------- 10 files changed, 78 insertions(+), 64 deletions(-) diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 00b0dc082..fc1a74641 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -14,7 +14,7 @@ use hir_def::{ per_ns::PerNs, resolver::{HasResolver, Resolver}, src::HasSource as _, - type_ref::{Mutability, TypeRef}, + type_ref::TypeRef, AdtId, AssocContainerId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, ImplId, LifetimeParamId, LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId, @@ -32,8 +32,8 @@ use hir_ty::{ method_resolution, traits::{FnTrait, Solution, SolutionVariables}, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, GenericPredicate, - InEnvironment, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitEnvironment, - Ty, TyDefId, TyVariableKind, + InEnvironment, Mutability, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, + TraitEnvironment, Ty, TyDefId, TyVariableKind, }; use rustc_hash::FxHashSet; use stdx::{format_to, impl_from}; @@ -836,7 +836,7 @@ pub enum Access { impl From for Access { fn from(mutability: Mutability) -> Access { match mutability { - Mutability::Shared => Access::Shared, + Mutability::Not => Access::Shared, Mutability::Mut => Access::Exclusive, } } @@ -865,7 +865,10 @@ impl SelfParam { .params .first() .map(|param| match *param { - TypeRef::Reference(.., mutability) => mutability.into(), + TypeRef::Reference(.., mutability) => match mutability { + hir_def::type_ref::Mutability::Shared => Access::Shared, + hir_def::type_ref::Mutability::Mut => Access::Exclusive, + }, _ => Access::Owned, }) .unwrap_or(Access::Owned) diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index f3a4333cb..d4a8b48e6 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -8,6 +8,7 @@ use crate::{ TraitRef, Ty, }; use arrayvec::ArrayVec; +use chalk_ir::Mutability; use hir_def::{ db::DefDatabase, find_path, generics::TypeParamProvenance, item_scope::ItemInNs, AdtId, AssocContainerId, HasModule, Lookup, ModuleId, TraitId, @@ -291,9 +292,23 @@ impl HirDisplay for Ty { t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); if matches!(self, Ty::Raw(..)) { - write!(f, "*{}", m.as_keyword_for_ptr())?; + write!( + f, + "*{}", + match m { + Mutability::Not => "const ", + Mutability::Mut => "mut ", + } + )?; } else { - write!(f, "&{}", m.as_keyword_for_ref())?; + write!( + f, + "&{}", + match m { + Mutability::Not => "", + Mutability::Mut => "mut ", + } + )?; } let datas; diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 18a4f5e8a..4d771a91e 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -18,6 +18,7 @@ use std::mem; use std::ops::Index; use std::sync::Arc; +use chalk_ir::Mutability; use hir_def::{ body::Body, data::{ConstData, FunctionData, StaticData}, @@ -25,7 +26,7 @@ use hir_def::{ lang_item::LangItemTarget, path::{path, Path}, resolver::{HasResolver, Resolver, TypeNs}, - type_ref::{Mutability, TypeRef}, + type_ref::TypeRef, AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, FunctionId, Lookup, TraitId, TypeAliasId, VariantId, }; @@ -87,7 +88,7 @@ impl BindingMode { fn convert(annotation: BindingAnnotation) -> BindingMode { match annotation { BindingAnnotation::Unannotated | BindingAnnotation::Mutable => BindingMode::Move, - BindingAnnotation::Ref => BindingMode::Ref(Mutability::Shared), + BindingAnnotation::Ref => BindingMode::Ref(Mutability::Not), BindingAnnotation::RefMut => BindingMode::Ref(Mutability::Mut), } } diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index c33d8c61e..cf0a3add4 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs @@ -4,8 +4,8 @@ //! //! See: https://doc.rust-lang.org/nomicon/coercions.html -use chalk_ir::TyVariableKind; -use hir_def::{lang_item::LangItemTarget, type_ref::Mutability}; +use chalk_ir::{Mutability, TyVariableKind}; +use hir_def::lang_item::LangItemTarget; use test_utils::mark; use crate::{autoderef, traits::Solution, Obligation, Substs, TraitRef, Ty}; @@ -73,20 +73,20 @@ impl<'a> InferenceContext<'a> { match (&mut from_ty, to_ty) { // `*mut T` -> `*const T` // `&mut T` -> `&T` - (Ty::Raw(m1, ..), Ty::Raw(m2 @ Mutability::Shared, ..)) - | (Ty::Ref(m1, ..), Ty::Ref(m2 @ Mutability::Shared, ..)) => { + (Ty::Raw(m1, ..), Ty::Raw(m2 @ Mutability::Not, ..)) + | (Ty::Ref(m1, ..), Ty::Ref(m2 @ Mutability::Not, ..)) => { *m1 = *m2; } // `&T` -> `*const T` // `&mut T` -> `*mut T`/`*const T` - (Ty::Ref(.., substs), &Ty::Raw(m2 @ Mutability::Shared, ..)) + (Ty::Ref(.., substs), &Ty::Raw(m2 @ Mutability::Not, ..)) | (Ty::Ref(Mutability::Mut, substs), &Ty::Raw(m2, ..)) => { from_ty = Ty::Raw(m2, substs.clone()); } // Illegal mutability conversion - (Ty::Raw(Mutability::Shared, ..), Ty::Raw(Mutability::Mut, ..)) - | (Ty::Ref(Mutability::Shared, ..), Ty::Ref(Mutability::Mut, ..)) => return false, + (Ty::Raw(Mutability::Not, ..), Ty::Raw(Mutability::Mut, ..)) + | (Ty::Ref(Mutability::Not, ..), Ty::Ref(Mutability::Mut, ..)) => return false, // `{function_type}` -> `fn()` (Ty::FnDef(..), Ty::Function { .. }) => match from_ty.callable_sig(self.db) { diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 7852b3d23..cf1f1038a 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -3,7 +3,7 @@ use std::iter::{repeat, repeat_with}; use std::{mem, sync::Arc}; -use chalk_ir::TyVariableKind; +use chalk_ir::{Mutability, TyVariableKind}; use hir_def::{ expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, path::{GenericArg, GenericArgs}, @@ -15,12 +15,14 @@ use syntax::ast::RangeOp; use test_utils::mark; use crate::{ - autoderef, method_resolution, op, + autoderef, + lower::lower_to_chalk_mutability, + method_resolution, op, primitive::{self, UintTy}, traits::{FnTrait, InEnvironment}, utils::{generics, variant_data, Generics}, - Binders, CallableDefId, FnPointer, FnSig, Mutability, Obligation, OpaqueTyId, Rawness, Scalar, - Substs, TraitRef, Ty, + Binders, CallableDefId, FnPointer, FnSig, Obligation, OpaqueTyId, Rawness, Scalar, Substs, + TraitRef, Ty, }; use super::{ @@ -462,10 +464,11 @@ impl<'a> InferenceContext<'a> { cast_ty } Expr::Ref { expr, rawness, mutability } => { + let mutability = lower_to_chalk_mutability(*mutability); let expectation = if let Some((exp_inner, exp_rawness, exp_mutability)) = &expected.ty.as_reference_or_ptr() { - if *exp_mutability == Mutability::Mut && *mutability == Mutability::Shared { + if *exp_mutability == Mutability::Mut && mutability == Mutability::Not { // FIXME: throw type error - expected mut reference but found shared ref, // which cannot be coerced } @@ -479,8 +482,8 @@ impl<'a> InferenceContext<'a> { }; let inner_ty = self.infer_expr_inner(*expr, &expectation); match rawness { - Rawness::RawPtr => Ty::Raw(*mutability, Substs::single(inner_ty)), - Rawness::Ref => Ty::Ref(*mutability, Substs::single(inner_ty)), + Rawness::RawPtr => Ty::Raw(mutability, Substs::single(inner_ty)), + Rawness::Ref => Ty::Ref(mutability, Substs::single(inner_ty)), } } Expr::Box { expr } => { @@ -684,11 +687,11 @@ impl<'a> InferenceContext<'a> { } Expr::Literal(lit) => match lit { Literal::Bool(..) => Ty::Scalar(Scalar::Bool), - Literal::String(..) => Ty::Ref(Mutability::Shared, Substs::single(Ty::Str)), + Literal::String(..) => Ty::Ref(Mutability::Not, Substs::single(Ty::Str)), Literal::ByteString(..) => { let byte_type = Ty::Scalar(Scalar::Uint(UintTy::U8)); let array_type = Ty::Array(Substs::single(byte_type)); - Ty::Ref(Mutability::Shared, Substs::single(array_type)) + Ty::Ref(Mutability::Not, Substs::single(array_type)) } Literal::Char(..) => Ty::Scalar(Scalar::Char), Literal::Int(_v, ty) => match ty { diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index a318e47f3..eb099311c 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -3,17 +3,17 @@ use std::iter::repeat; use std::sync::Arc; +use chalk_ir::Mutability; use hir_def::{ expr::{BindingAnnotation, Expr, Literal, Pat, PatId, RecordFieldPat}, path::Path, - type_ref::Mutability, FieldId, }; use hir_expand::name::Name; use test_utils::mark; use super::{BindingMode, Expectation, InferenceContext}; -use crate::{utils::variant_data, Substs, Ty}; +use crate::{lower::lower_to_chalk_mutability, utils::variant_data, Substs, Ty}; impl<'a> InferenceContext<'a> { fn infer_tuple_struct_pat( @@ -103,7 +103,7 @@ impl<'a> InferenceContext<'a> { expected = inner; default_bm = match default_bm { BindingMode::Move => BindingMode::Ref(mutability), - BindingMode::Ref(Mutability::Shared) => BindingMode::Ref(Mutability::Shared), + BindingMode::Ref(Mutability::Not) => BindingMode::Ref(Mutability::Not), BindingMode::Ref(Mutability::Mut) => BindingMode::Ref(mutability), } } @@ -152,9 +152,10 @@ impl<'a> InferenceContext<'a> { } } Pat::Ref { pat, mutability } => { + let mutability = lower_to_chalk_mutability(*mutability); let expectation = match expected.as_reference() { Some((inner_ty, exp_mut)) => { - if *mutability != exp_mut { + if mutability != exp_mut { // FIXME: emit type error? } inner_ty @@ -162,7 +163,7 @@ impl<'a> InferenceContext<'a> { _ => &Ty::Unknown, }; let subty = self.infer_pat(*pat, expectation, default_bm); - Ty::Ref(*mutability, Substs::single(subty)) + Ty::Ref(mutability, Substs::single(subty)) } Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( p.as_ref(), diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 9bcaf6fa7..c2a20c480 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -27,11 +27,9 @@ use std::{iter, mem, ops::Deref, sync::Arc}; use base_db::salsa; use hir_def::{ - builtin_type::BuiltinType, - expr::ExprId, - type_ref::{Mutability, Rawness}, - AdtId, AssocContainerId, DefWithBodyId, FunctionId, GenericDefId, HasModule, LifetimeParamId, - Lookup, TraitId, TypeAliasId, TypeParamId, + builtin_type::BuiltinType, expr::ExprId, type_ref::Rawness, AdtId, AssocContainerId, + DefWithBodyId, FunctionId, GenericDefId, HasModule, LifetimeParamId, Lookup, TraitId, + TypeAliasId, TypeParamId, }; use itertools::Itertools; @@ -49,7 +47,7 @@ pub use lower::{ }; pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; -pub use chalk_ir::{BoundVar, DebruijnIndex, Scalar, TyVariableKind}; +pub use chalk_ir::{BoundVar, DebruijnIndex, Mutability, Scalar, TyVariableKind}; #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub enum Lifetime { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index ca06c9fe2..1b5843d48 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -8,6 +8,7 @@ use std::{iter, sync::Arc}; use base_db::CrateId; +use chalk_ir::Mutability; use hir_def::{ adt::StructKind, builtin_type::BuiltinType, @@ -157,7 +158,7 @@ impl Ty { } TypeRef::RawPtr(inner, mutability) => { let inner_ty = Ty::from_hir(ctx, inner); - Ty::Raw(*mutability, Substs::single(inner_ty)) + Ty::Raw(lower_to_chalk_mutability(*mutability), Substs::single(inner_ty)) } TypeRef::Array(inner) => { let inner_ty = Ty::from_hir(ctx, inner); @@ -169,7 +170,7 @@ impl Ty { } TypeRef::Reference(inner, _, mutability) => { let inner_ty = Ty::from_hir(ctx, inner); - Ty::Ref(*mutability, Substs::single(inner_ty)) + Ty::Ref(lower_to_chalk_mutability(*mutability), Substs::single(inner_ty)) } TypeRef::Placeholder => Ty::Unknown, TypeRef::Fn(params, is_varargs) => { @@ -1259,3 +1260,10 @@ pub(crate) fn return_type_impl_traits( Some(Arc::new(Binders::new(num_binders, return_type_impl_traits))) } } + +pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mutability { + match m { + hir_def::type_ref::Mutability::Shared => Mutability::Not, + hir_def::type_ref::Mutability::Mut => Mutability::Mut, + } +} diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index dd5109d4e..f301a8477 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs @@ -6,9 +6,10 @@ use std::{iter, sync::Arc}; use arrayvec::ArrayVec; use base_db::CrateId; +use chalk_ir::Mutability; use hir_def::{ - lang_item::LangItemTarget, type_ref::Mutability, AdtId, AssocContainerId, AssocItemId, - FunctionId, GenericDefId, HasModule, ImplId, Lookup, ModuleId, TraitId, TypeAliasId, + lang_item::LangItemTarget, AdtId, AssocContainerId, AssocItemId, FunctionId, GenericDefId, + HasModule, ImplId, Lookup, ModuleId, TraitId, TypeAliasId, }; use hir_expand::name::Name; use rustc_hash::{FxHashMap, FxHashSet}; @@ -251,7 +252,7 @@ impl Ty { } Ty::Str => lang_item_crate!("str_alloc", "str"), Ty::Slice(_) => lang_item_crate!("slice_alloc", "slice"), - Ty::Raw(Mutability::Shared, _) => lang_item_crate!("const_ptr"), + Ty::Raw(Mutability::Not, _) => lang_item_crate!("const_ptr"), Ty::Raw(Mutability::Mut, _) => lang_item_crate!("mut_ptr"), Ty::Dyn(_) => { return self.dyn_trait().and_then(|trait_| { @@ -429,7 +430,7 @@ fn iterate_method_candidates_with_autoref( } let refed = Canonical { kinds: deref_chain[0].kinds.clone(), - value: Ty::Ref(Mutability::Shared, Substs::single(deref_chain[0].value.clone())), + value: Ty::Ref(Mutability::Not, Substs::single(deref_chain[0].value.clone())), }; if iterate_method_candidates_by_receiver( &refed, diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 6e6055d80..db1760e6c 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -10,7 +10,7 @@ use chalk_ir::{ use chalk_solve::rust_ir; use base_db::salsa::InternKey; -use hir_def::{type_ref::Mutability, AssocContainerId, GenericDefId, Lookup, TypeAliasId}; +use hir_def::{AssocContainerId, GenericDefId, Lookup, TypeAliasId}; use crate::{ db::HirDatabase, @@ -65,7 +65,7 @@ impl ToChalk for Ty { } Ty::Raw(mutability, substs) => { let ty = substs[0].clone().to_chalk(db); - chalk_ir::TyKind::Raw(mutability.to_chalk(db), ty).intern(&Interner) + chalk_ir::TyKind::Raw(mutability, ty).intern(&Interner) } Ty::Slice(substs) => { chalk_ir::TyKind::Slice(substs[0].clone().to_chalk(db)).intern(&Interner) @@ -198,11 +198,11 @@ impl ToChalk for Ty { Ty::Tuple(cardinality, from_chalk(db, subst)) } chalk_ir::TyKind::Raw(mutability, ty) => { - Ty::Raw(from_chalk(db, mutability), Substs::single(from_chalk(db, ty))) + Ty::Raw(mutability, Substs::single(from_chalk(db, ty))) } chalk_ir::TyKind::Slice(ty) => Ty::Slice(Substs::single(from_chalk(db, ty))), chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { - Ty::Ref(from_chalk(db, mutability), Substs::single(from_chalk(db, ty))) + Ty::Ref(mutability, Substs::single(from_chalk(db, ty))) } chalk_ir::TyKind::Str => Ty::Str, chalk_ir::TyKind::Never => Ty::Never, @@ -230,12 +230,12 @@ impl ToChalk for Ty { /// fake lifetime here, because Chalks built-in logic may expect it to be there. fn ref_to_chalk( db: &dyn HirDatabase, - mutability: Mutability, + mutability: chalk_ir::Mutability, subst: Substs, ) -> chalk_ir::Ty { let arg = subst[0].clone().to_chalk(db); let lifetime = LifetimeData::Static.intern(&Interner); - chalk_ir::TyKind::Ref(mutability.to_chalk(db), lifetime, arg).intern(&Interner) + chalk_ir::TyKind::Ref(mutability, lifetime, arg).intern(&Interner) } /// We currently don't model constants, but Chalk does. So, we have to insert a @@ -313,22 +313,6 @@ impl ToChalk for OpaqueTyId { } } -impl ToChalk for Mutability { - type Chalk = chalk_ir::Mutability; - fn to_chalk(self, _db: &dyn HirDatabase) -> Self::Chalk { - match self { - Mutability::Shared => chalk_ir::Mutability::Not, - Mutability::Mut => chalk_ir::Mutability::Mut, - } - } - fn from_chalk(_db: &dyn HirDatabase, chalk: Self::Chalk) -> Self { - match chalk { - chalk_ir::Mutability::Mut => Mutability::Mut, - chalk_ir::Mutability::Not => Mutability::Shared, - } - } -} - impl ToChalk for hir_def::ImplId { type Chalk = ImplId; -- cgit v1.2.3