Repository: rust-analyzer/rust-analyzer
Pull request #6018 (2020-09-16 19:11:13)

Correct project_root path for ProjectJson.
It was already the folder containing the rust-project.json file, not the file itself.  This also removes the Option-ness of it, since it's now an infallible operation to set the member value.


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 72ec686246..f35d63df2f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -162,9 +162,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
 
 [[package]]
 name = "chalk-derive"
-version = "0.27.0"
+version = "0.25.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d5444ff2a211fe2a863e44d16a368c3d8a314d489de21b8eeb6879f14dd5d4a8"
+checksum = "624e14d3f029186e6ffd97081ffa082f98ddd5df20655b6f0e8efb83dd8ac8b4"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -174,9 +174,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-ir"
-version = "0.27.0"
+version = "0.25.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e39c3db1dd4abfaa7658faaa62e5fe998a982a592b710bd971fad5b6adfcfdef"
+checksum = "118c68eccdda5604af50bbef84c94550f3854f76989cb03c36ffd36cc2ffe958"
 dependencies = [
  "chalk-derive",
  "lazy_static",
@@ -184,9 +184,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-recursive"
-version = "0.27.0"
+version = "0.25.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3bfae328eff80ca54dcd0d731725bbb56136ac21c59261b68f1e5498e056b306"
+checksum = "5130de3065e3cdfd2ab6d7d70b02b917bafbc096f270c9a643c23da249053606"
 dependencies = [
  "chalk-derive",
  "chalk-ir",
@@ -197,9 +197,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-solve"
-version = "0.27.0"
+version = "0.25.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a673abe3077adc25f8ee0894198aed494a5bb0ce50ee993900d0ee1a44e1948a"
+checksum = "45b235a1f568b28707f117b2d30eabbee9cbcfccaa0d6e9697300400c8ca0996"
 dependencies = [
  "chalk-derive",
  "chalk-ir",
diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs
index 6190906da9..9a8eb4edec 100644
--- a/crates/hir_def/src/data.rs
+++ b/crates/hir_def/src/data.rs
@@ -54,7 +54,6 @@ pub struct TypeAliasData {
     pub name: Name,
     pub type_ref: Option<TypeRef>,
     pub visibility: RawVisibility,
-    pub is_extern: bool,
     /// Bounds restricting the type alias itself (eg. `type Ty: Bound;` in a trait or impl).
     pub bounds: Vec<TypeBound>,
 }
@@ -72,7 +71,6 @@ impl TypeAliasData {
             name: typ.name.clone(),
             type_ref: typ.type_ref.clone(),
             visibility: item_tree[typ.visibility].clone(),
-            is_extern: typ.is_extern,
             bounds: typ.bounds.to_vec(),
         })
     }
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index 52abb8e7f1..e14722caeb 100644
--- a/crates/hir_def/src/item_tree.rs
+++ b/crates/hir_def/src/item_tree.rs
@@ -592,7 +592,6 @@ pub struct TypeAlias {
     pub bounds: Box<[TypeBound]>,
     pub generic_params: GenericParamsId,
     pub type_ref: Option<TypeRef>,
-    pub is_extern: bool,
     pub ast_id: FileAstId<ast::TypeAlias>,
 }
 
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index d93377c3bd..6a503d7853 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -364,7 +364,6 @@ impl Ctx {
             generic_params,
             type_ref,
             ast_id,
-            is_extern: false,
         };
         Some(id(self.data().type_aliases.alloc(res)))
     }
@@ -559,9 +558,8 @@ impl Ctx {
                             statik.into()
                         }
                         ast::ExternItem::TypeAlias(ty) => {
-                            let foreign_ty = self.lower_type_alias(&ty)?;
-                            self.data().type_aliases[foreign_ty.index].is_extern = true;
-                            foreign_ty.into()
+                            let id = self.lower_type_alias(&ty)?;
+                            id.into()
                         }
                         ast::ExternItem::MacroCall(_) => return None,
                     };
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml
index bc86df2b16..7d02aaf955 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.27.0" }
-chalk-ir = { version = "0.27.0" }
-chalk-recursive = { version = "0.27.0" }
+chalk-solve = { version = "0.25.0" }
+chalk-ir = { version = "0.25.0" }
+chalk-recursive = { version = "0.25.0" }
 
 stdx = { path = "../stdx", version = "0.0.0" }
 hir_def = { path = "../hir_def", version = "0.0.0" }
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index f389c5a4b3..efb48c7ee4 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -380,15 +380,6 @@ impl HirDisplay for ApplicationTy {
                     write!(f, ">")?;
                 }
             }
-            TypeCtor::ForeignType(type_alias) => {
-                let type_alias = f.db.type_alias_data(type_alias);
-                write!(f, "{}", type_alias.name)?;
-                if self.parameters.len() > 0 {
-                    write!(f, "<")?;
-                    f.write_joined(&*self.parameters.0, ", ")?;
-                    write!(f, ">")?;
-                }
-            }
             TypeCtor::OpaqueType(opaque_ty_id) => {
                 match opaque_ty_id {
                     OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 768d95effa..f16d1fc979 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -134,9 +134,6 @@ pub enum TypeCtor {
     /// representing the Future::Output type.
     OpaqueType(OpaqueTyId),
 
-    /// Represents a foreign type declared in external blocks.
-    ForeignType(TypeAliasId),
-
     /// The type of a specific closure.
     ///
     /// The closure signature is stored in a `FnPtr` type in the first type
@@ -171,10 +168,6 @@ impl TypeCtor {
                 let generic_params = generics(db.upcast(), type_alias.into());
                 generic_params.len()
             }
-            TypeCtor::ForeignType(type_alias) => {
-                let generic_params = generics(db.upcast(), type_alias.into());
-                generic_params.len()
-            }
             TypeCtor::OpaqueType(opaque_ty_id) => {
                 match opaque_ty_id {
                     OpaqueTyId::ReturnTypeImplTrait(func, _) => {
@@ -211,9 +204,6 @@ impl TypeCtor {
             TypeCtor::AssociatedType(type_alias) => {
                 Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate)
             }
-            TypeCtor::ForeignType(type_alias) => {
-                Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate)
-            }
             TypeCtor::OpaqueType(opaque_ty_id) => match opaque_ty_id {
                 OpaqueTyId::ReturnTypeImplTrait(func, _) => {
                     Some(func.lookup(db.upcast()).module(db.upcast()).krate)
@@ -241,7 +231,6 @@ impl TypeCtor {
             TypeCtor::Adt(adt) => Some(adt.into()),
             TypeCtor::FnDef(callable) => Some(callable.into()),
             TypeCtor::AssociatedType(type_alias) => Some(type_alias.into()),
-            TypeCtor::ForeignType(type_alias) => Some(type_alias.into()),
             TypeCtor::OpaqueType(_impl_trait_id) => None,
         }
     }
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 708e2af0fa..cd574e983f 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -1101,14 +1101,10 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
     let resolver = t.resolver(db.upcast());
     let ctx =
         TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
+    let type_ref = &db.type_alias_data(t).type_ref;
     let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
-    if db.type_alias_data(t).is_extern {
-        Binders::new(substs.len(), Ty::apply(TypeCtor::ForeignType(t), substs))
-    } else {
-        let type_ref = &db.type_alias_data(t).type_ref;
-        let inner = Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error));
-        Binders::new(substs.len(), inner)
-    }
+    let inner = Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error));
+    Binders::new(substs.len(), inner)
 }
 
 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index 8961df4049..ec59145c70 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -250,14 +250,6 @@ impl Ty {
                 TypeCtor::Adt(def_id) => {
                     return Some(std::iter::once(def_id.module(db.upcast()).krate).collect())
                 }
-                TypeCtor::ForeignType(type_alias_id) => {
-                    return Some(
-                        std::iter::once(
-                            type_alias_id.lookup(db.upcast()).module(db.upcast()).krate,
-                        )
-                        .collect(),
-                    )
-                }
                 TypeCtor::Bool => lang_item_crate!("bool"),
                 TypeCtor::Char => lang_item_crate!("char"),
                 TypeCtor::Float(f) => match f.bitness {
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 27f0ed628f..57d0a32df0 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -23,8 +23,7 @@ use crate::{
     ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
 };
 use mapping::{
-    convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsAssocType,
-    TypeAliasAsValue,
+    convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue,
 };
 
 pub use self::interner::*;
@@ -341,7 +340,7 @@ pub(crate) fn associated_ty_data_query(
     id: AssocTypeId,
 ) -> Arc<AssociatedTyDatum> {
     debug!("associated_ty_data {:?}", id);
-    let type_alias: TypeAliasId = from_chalk::<TypeAliasAsAssocType, _>(db, id).0;
+    let type_alias: TypeAliasId = from_chalk(db, id);
     let trait_ = match type_alias.lookup(db.upcast()).container {
         AssocContainerId::TraitId(t) => t,
         _ => panic!("associated type not in trait"),
@@ -395,10 +394,8 @@ pub(crate) fn trait_datum_query(
         fundamental: false,
     };
     let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars);
-    let associated_ty_ids = trait_data
-        .associated_types()
-        .map(|type_alias| TypeAliasAsAssocType(type_alias).to_chalk(db))
-        .collect();
+    let associated_ty_ids =
+        trait_data.associated_types().map(|type_alias| type_alias.to_chalk(db)).collect();
     let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses };
     let well_known =
         lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name));
@@ -436,7 +433,6 @@ fn lang_attr_from_well_known_trait(attr: WellKnownTrait) -> &'static str {
         WellKnownTrait::FnMut => "fn_mut",
         WellKnownTrait::Fn => "fn",
         WellKnownTrait::Unsize => "unsize",
-        WellKnownTrait::Unpin => "unpin",
     }
 }
 
@@ -580,7 +576,7 @@ fn type_alias_associated_ty_value(
     let value_bound = rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) };
     let value = rust_ir::AssociatedTyValue {
         impl_id: impl_id.to_chalk(db),
-        associated_ty_id: TypeAliasAsAssocType(assoc_ty).to_chalk(db),
+        associated_ty_id: assoc_ty.to_chalk(db),
         value: make_binders(value_bound, ty.num_binders),
     };
     Arc::new(value)
@@ -615,11 +611,9 @@ pub(crate) fn fn_def_datum_query(
     };
     let datum = FnDefDatum {
         id: fn_def_id,
-        sig: chalk_ir::FnSig {
-            abi: (),
-            safety: chalk_ir::Safety::Safe,
-            variadic: sig.value.is_varargs,
-        },
+        abi: (),
+        safety: chalk_ir::Safety::Safe,
+        variadic: sig.value.is_varargs,
         binders: make_binders(bound, sig.num_binders),
     };
     Arc::new(datum)
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs
index f9304b7d0c..eb35db3ffc 100644
--- a/crates/hir_ty/src/traits/chalk/interner.rs
+++ b/crates/hir_ty/src/traits/chalk/interner.rs
@@ -12,7 +12,6 @@ pub struct Interner;
 
 pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
 pub type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
-pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
 pub type TraitId = chalk_ir::TraitId<Interner>;
 pub type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
 pub type AdtId = chalk_ir::AdtId<Interner>;
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index d42f4bba9e..d6bacba1d3 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -34,11 +34,9 @@ impl ToChalk for Ty {
                     let substitution = apply_ty.parameters.to_chalk(db).shifted_in(&Interner);
                     chalk_ir::TyData::Function(chalk_ir::FnPointer {
                         num_binders: 0,
-                        sig: chalk_ir::FnSig {
-                            abi: (),
-                            safety: chalk_ir::Safety::Safe,
-                            variadic: is_varargs,
-                        },
+                        abi: (),
+                        safety: chalk_ir::Safety::Safe,
+                        variadic: is_varargs,
                         substitution,
                     })
                     .intern(&Interner)
@@ -50,7 +48,7 @@ impl ToChalk for Ty {
                 }
             },
             Ty::Projection(proj_ty) => {
-                let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db);
+                let associated_ty_id = proj_ty.associated_ty.to_chalk(db);
                 let substitution = proj_ty.parameters.to_chalk(db);
                 chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
                     associated_ty_id,
@@ -116,8 +114,7 @@ impl ToChalk for Ty {
                 Ty::Placeholder(db.lookup_intern_type_param_id(interned_id))
             }
             chalk_ir::TyData::Alias(chalk_ir::AliasTy::Projection(proj)) => {
-                let associated_ty =
-                    from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0;
+                let associated_ty = from_chalk(db, proj.associated_ty_id);
                 let parameters = from_chalk(db, proj.substitution);
                 Ty::Projection(ProjectionTy { associated_ty, parameters })
             }
@@ -128,7 +125,7 @@ impl ToChalk for Ty {
             }
             chalk_ir::TyData::Function(chalk_ir::FnPointer {
                 num_binders,
-                sig: chalk_ir::FnSig { variadic, .. },
+                variadic,
                 substitution,
                 ..
             }) => {
@@ -293,9 +290,8 @@ impl ToChalk for TypeCtor {
     fn to_chalk(self, db: &dyn HirDatabase) -> TypeName<Interner> {
         match self {
             TypeCtor::AssociatedType(type_alias) => {
-                let assoc_type = TypeAliasAsAssocType(type_alias);
-                let assoc_type_id = assoc_type.to_chalk(db);
-                TypeName::AssociatedType(assoc_type_id)
+                let type_id = type_alias.to_chalk(db);
+                TypeName::AssociatedType(type_id)
             }
 
             TypeCtor::OpaqueType(impl_trait_id) => {
@@ -303,12 +299,6 @@ impl ToChalk for TypeCtor {
                 TypeName::OpaqueType(id)
             }
 
-            TypeCtor::ForeignType(type_alias) => {
-                let foreign_type = TypeAliasAsForeignType(type_alias);
-                let foreign_type_id = foreign_type.to_chalk(db);
-                TypeName::Foreign(foreign_type_id)
-            }
-
             TypeCtor::Bool => TypeName::Scalar(Scalar::Bool),
             TypeCtor::Char => TypeName::Scalar(Scalar::Char),
             TypeCtor::Int(int_ty) => TypeName::Scalar(int_ty_to_chalk(int_ty)),
@@ -349,9 +339,7 @@ impl ToChalk for TypeCtor {
     fn from_chalk(db: &dyn HirDatabase, type_name: TypeName<Interner>) -> TypeCtor {
         match type_name {
             TypeName::Adt(struct_id) => TypeCtor::Adt(struct_id.0),
-            TypeName::AssociatedType(type_id) => {
-                TypeCtor::AssociatedType(from_chalk::<TypeAliasAsAssocType, _>(db, type_id).0)
-            }
+            TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)),
             TypeName::OpaqueType(opaque_type_id) => {
                 TypeCtor::OpaqueType(from_chalk(db, opaque_type_id))
             }
@@ -391,10 +379,6 @@ impl ToChalk for TypeCtor {
                 TypeCtor::Closure { def, expr }
             }
 
-            TypeName::Foreign(foreign_def_id) => {
-                TypeCtor::ForeignType(from_chalk::<TypeAliasAsForeignType, _>(db, foreign_def_id).0)
-            }
-
             TypeName::Error => {
                 // this should not be reached, since we don't represent TypeName::Error with TypeCtor
                 unreachable!()
@@ -504,31 +488,15 @@ impl ToChalk for CallableDefId {
     }
 }
 
-pub struct TypeAliasAsAssocType(pub TypeAliasId);
-
-impl ToChalk for TypeAliasAsAssocType {
+impl ToChalk for TypeAliasId {
     type Chalk = AssocTypeId;
 
     fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId {
-        chalk_ir::AssocTypeId(self.0.as_intern_id())
-    }
-
-    fn from_chalk(_db: &dyn HirDatabase, assoc_type_id: AssocTypeId) -> TypeAliasAsAssocType {
-        TypeAliasAsAssocType(InternKey::from_intern_id(assoc_type_id.0))
-    }
-}
-
-pub struct TypeAliasAsForeignType(pub TypeAliasId);
-
-impl ToChalk for TypeAliasAsForeignType {
-    type Chalk = ForeignDefId;
-
-    fn to_chalk(self, _db: &dyn HirDatabase) -> ForeignDefId {
-        chalk_ir::ForeignDefId(self.0.as_intern_id())
+        chalk_ir::AssocTypeId(self.as_intern_id())
     }
 
-    fn from_chalk(_db: &dyn HirDatabase, foreign_def_id: ForeignDefId) -> TypeAliasAsForeignType {
-        TypeAliasAsForeignType(InternKey::from_intern_id(foreign_def_id.0))
+    fn from_chalk(_db: &dyn HirDatabase, type_alias_id: AssocTypeId) -> TypeAliasId {
+        InternKey::from_intern_id(type_alias_id.0)
     }
 }
 
@@ -612,7 +580,7 @@ impl ToChalk for ProjectionTy {
 
     fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> {
         chalk_ir::ProjectionTy {
-            associated_ty_id: TypeAliasAsAssocType(self.associated_ty).to_chalk(db),
+            associated_ty_id: self.associated_ty.to_chalk(db),
             substitution: self.parameters.to_chalk(db),
         }
     }
@@ -622,11 +590,7 @@ impl ToChalk for ProjectionTy {
         projection_ty: chalk_ir::ProjectionTy<Interner>,
     ) -> ProjectionTy {
         ProjectionTy {
-            associated_ty: from_chalk::<TypeAliasAsAssocType, _>(
-                db,
-                projection_ty.associated_ty_id,
-            )
-            .0,
+            associated_ty: from_chalk(db, projection_ty.associated_ty_id),
             parameters: from_chalk(db, projection_ty.substitution),
         }
     }
@@ -825,8 +789,7 @@ pub(super) fn generic_predicate_to_inline_bound(
             let alias_eq_bound = rust_ir::AliasEqBound {
                 value: proj.ty.clone().to_chalk(db),
                 trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self },
-                associated_ty_id: TypeAliasAsAssocType(proj.projection_ty.associated_ty)
-                    .to_chalk(db),
+                associated_ty_id: proj.projection_ty.associated_ty.to_chalk(db),
                 parameters: Vec::new(), // FIXME we don't support generic associated types yet
             };
             Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound))
diff --git a/crates/hir_ty/src/traits/chalk/tls.rs b/crates/hir_ty/src/traits/chalk/tls.rs
index b4568cff64..cb6b0fe81f 100644
--- a/crates/hir_ty/src/traits/chalk/tls.rs
+++ b/crates/hir_ty/src/traits/chalk/tls.rs
@@ -4,7 +4,7 @@ use std::fmt;
 use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication, TypeName};
 use itertools::Itertools;
 
-use super::{from_chalk, Interner, TypeAliasAsAssocType};
+use super::{from_chalk, Interner};
 use crate::{db::HirDatabase, CallableDefId, TypeCtor};
 use hir_def::{AdtId, AssocContainerId, DefWithBodyId, Lookup, TypeAliasId};
 
@@ -77,10 +77,6 @@ impl DebugContext<'_> {
                     write!(f, "{{impl trait of async block {} of {:?}}}", idx.into_raw(), def)?;
                 }
             },
-            TypeCtor::ForeignType(type_alias) => {
-                let name = self.0.type_alias_data(type_alias).name.clone();
-                write!(f, "{}", name)?;
-            }
             TypeCtor::Closure { def, expr } => {
                 write!(f, "{{closure {:?} in ", expr.into_raw())?;
                 match def {
@@ -123,7 +119,7 @@ impl DebugContext<'_> {
         id: super::AssocTypeId,
         fmt: &mut fmt::Formatter<'_>,
     ) -> Result<(), fmt::Error> {
-        let type_alias: TypeAliasId = from_chalk::<TypeAliasAsAssocType, _>(self.0, id).0;
+        let type_alias: TypeAliasId = from_chalk(self.0, id);
         let type_alias_data = self.0.type_alias_data(type_alias);
         let trait_ = match type_alias.lookup(self.0.upcast()).container {
             AssocContainerId::TraitId(t) => t,
@@ -157,8 +153,7 @@ impl DebugContext<'_> {
         projection_ty: &chalk_ir::ProjectionTy<Interner>,
         fmt: &mut fmt::Formatter<'_>,
     ) -> Result<(), fmt::Error> {
-        let type_alias: TypeAliasId =
-            from_chalk::<TypeAliasAsAssocType, _>(self.0, projection_ty.associated_ty_id).0;
+        let type_alias: TypeAliasId = from_chalk(self.0, projection_ty.associated_ty_id);
         let type_alias_data = self.0.type_alias_data(type_alias);
         let trait_ = match type_alias.lookup(self.0.upcast()).container {
             AssocContainerId::TraitId(t) => t,
diff --git a/crates/ide/src/completion/complete_trait_impl.rs b/crates/ide/src/completion/complete_trait_impl.rs
index ff115df928..bff2603b82 100644
--- a/crates/ide/src/completion/complete_trait_impl.rs
+++ b/crates/ide/src/completion/complete_trait_impl.rs
@@ -86,46 +86,36 @@ fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, Synt
         token = token.prev_token()?;
     }
 
-    let impl_item_offset = match token.kind() {
-        // `impl .. { const <|> }`
-        // ERROR      0
-        //   CONST_KW <- *
-        SyntaxKind::CONST_KW => 0,
-        // `impl .. { fn/type <|> }`
-        // FN/TYPE_ALIAS  0
-        //   FN_KW        <- *
-        SyntaxKind::FN_KW | SyntaxKind::TYPE_KW => 0,
-        // `impl .. { fn/type/const foo<|> }`
-        // FN/TYPE_ALIAS/CONST  1
-        //  NAME                0
-        //    IDENT             <- *
-        SyntaxKind::IDENT if token.parent().kind() == SyntaxKind::NAME => 1,
-        // `impl .. { foo<|> }`
-        // MACRO_CALL       3
-        //  PATH            2
-        //    PATH_SEGMENT  1
-        //      NAME_REF    0
-        //        IDENT     <- *
-        SyntaxKind::IDENT if token.parent().kind() == SyntaxKind::NAME_REF => 3,
-        _ => return None,
-    };
+    let (kind, trigger, impl_def_offset) = token.ancestors().find_map(|p| match p.kind() {
+        // `const` can be a modifier of an item, so the `const` token may be inside another item syntax node.
+        // Eg. `impl .. { const <|> fn bar() .. }`
+        SyntaxKind::FN | SyntaxKind::TYPE_ALIAS | SyntaxKind::CONST
+            if token.kind() == SyntaxKind::CONST_KW =>
+        {
+            Some((ImplCompletionKind::Const, p, 2))
+        }
+        SyntaxKind::FN => Some((ImplCompletionKind::Fn, p, 2)),
+        SyntaxKind::TYPE_ALIAS => Some((ImplCompletionKind::TypeAlias, p, 2)),
+        SyntaxKind::CONST => Some((ImplCompletionKind::Const, p, 2)),
+        // `impl .. { const <|> }` is parsed as:
+        // IMPL
+        //   ASSOC_ITEM_LIST
+        //     ERROR
+        //       CONST_KW <- token
+        //     WHITESPACE <- ctx.token
+        SyntaxKind::ERROR
+            if p.first_token().map_or(false, |t| t.kind() == SyntaxKind::CONST_KW) =>
+        {
+            Some((ImplCompletionKind::Const, p, 2))
+        }
+        SyntaxKind::NAME_REF => Some((ImplCompletionKind::All, p, 5)),
+        _ => None,
+    })?;
 
-    let impl_item = token.ancestors().nth(impl_item_offset)?;
-    // Must directly belong to an impl block.
-    // IMPL
-    //   ASSOC_ITEM_LIST
-    //     <item>
-    let impl_def = ast::Impl::cast(impl_item.parent()?.parent()?)?;
-    let kind = match impl_item.kind() {
-        // `impl ... { const <|> fn/type/const }`
-        _ if token.kind() == SyntaxKind::CONST_KW => ImplCompletionKind::Const,
-        SyntaxKind::CONST | SyntaxKind::ERROR => ImplCompletionKind::Const,
-        SyntaxKind::TYPE_ALIAS => ImplCompletionKind::TypeAlias,
-        SyntaxKind::FN => ImplCompletionKind::Fn,
-        SyntaxKind::MACRO_CALL => ImplCompletionKind::All,
-        _ => return None,
-    };
-    Some((kind, impl_item, impl_def))
+    let impl_def = (0..impl_def_offset - 1)
+        .try_fold(trigger.parent()?, |t, _| t.parent())
+        .and_then(ast::Impl::cast)?;
+    Some((kind, trigger, impl_def))
 }
 
 fn add_function_impl(
@@ -271,191 +261,19 @@ ta type TestType = \n\
     }
 
     #[test]
-    fn no_completion_inside_fn() {
+    fn no_nested_fn_completions() {
         check(
             r"
-trait Test { fn test(); fn test2(); }
-struct T;
-
-impl Test for T {
-    fn test() {
-        t<|>
-    }
-}
-",
-            expect![[""]],
-        );
-
-        check(
-            r"
-trait Test { fn test(); fn test2(); }
-struct T;
-
-impl Test for T {
-    fn test() {
-        fn t<|>
-    }
+trait Test {
+    fn test();
+    fn test2();
 }
-",
-            expect![[""]],
-        );
-
-        check(
-            r"
-trait Test { fn test(); fn test2(); }
 struct T;
 
 impl Test for T {
     fn test() {
-        fn <|>
-    }
-}
-",
-            expect![[""]],
-        );
-
-        // https://github.com/rust-analyzer/rust-analyzer/pull/5976#issuecomment-692332191
-        check(
-            r"
-trait Test { fn test(); fn test2(); }
-struct T;
-
-impl Test for T {
-    fn test() {
-        foo.<|>
-    }
-}
-",
-            expect![[""]],
-        );
-
-        check(
-            r"
-trait Test { fn test(_: i32); fn test2(); }
-struct T;
-
-impl Test for T {
-    fn test(t<|>)
-}
-",
-            expect![[""]],
-        );
-
-        check(
-            r"
-trait Test { fn test(_: fn()); fn test2(); }
-struct T;
-
-impl Test for T {
-    fn test(f: fn <|>)
-}
-",
-            expect![[""]],
-        );
-    }
-
-    #[test]
-    fn no_completion_inside_const() {
-        check(
-            r"
-trait Test { const TEST: fn(); const TEST2: u32; type Test; fn test(); }
-struct T;
-
-impl Test for T {
-    const TEST: fn <|>
-}
-",
-            expect![[""]],
-        );
-
-        check(
-            r"
-trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
-struct T;
-
-impl Test for T {
-    const TEST: T<|>
-}
-",
-            expect![[""]],
-        );
-
-        check(
-            r"
-trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
-struct T;
-
-impl Test for T {
-    const TEST: u32 = f<|>
-}
-",
-            expect![[""]],
-        );
-
-        check(
-            r"
-trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
-struct T;
-
-impl Test for T {
-    const TEST: u32 = {
         t<|>
-    };
-}
-",
-            expect![[""]],
-        );
-
-        check(
-            r"
-trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
-struct T;
-
-impl Test for T {
-    const TEST: u32 = {
-        fn <|>
-    };
-}
-",
-            expect![[""]],
-        );
-
-        check(
-            r"
-trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
-struct T;
-
-impl Test for T {
-    const TEST: u32 = {
-        fn t<|>
-    };
-}
-",
-            expect![[""]],
-        );
     }
-
-    #[test]
-    fn no_completion_inside_type() {
-        check(
-            r"
-trait Test { type Test; type Test2; fn test(); }
-struct T;
-
-impl Test for T {
-    type Test = T<|>;
-}
-",
-            expect![[""]],
-        );
-
-        check(
-            r"
-trait Test { type Test; type Test2; fn test(); }
-struct T;
-
-impl Test for T {
-    type Test = fn <|>;
 }
 ",
             expect![[""]],
diff --git a/crates/project_model/src/project_json.rs b/crates/project_model/src/project_json.rs
index 545f254aae..a6895ecdd5 100644
--- a/crates/project_model/src/project_json.rs
+++ b/crates/project_model/src/project_json.rs
@@ -13,7 +13,7 @@ use crate::cfg_flag::CfgFlag;
 #[derive(Clone, Debug, Eq, PartialEq)]
 pub struct ProjectJson {
     pub(crate) sysroot_src: Option<AbsPathBuf>,
-    project_root: Option<AbsPathBuf>,
+    project_root: AbsPathBuf,
     crates: Vec<Crate>,
 }
 
@@ -34,10 +34,17 @@ pub struct Crate {
 }
 
 impl ProjectJson {
+    /// Create a new ProjectJson instance.
+    ///
+    /// # Arguments
+    ///
+    /// * `base` - The path to the workspace root (i.e. the folder containing `rust-project.json`)
+    /// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via
+    ///            configuration.
     pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson {
         ProjectJson {
             sysroot_src: data.sysroot_src.map(|it| base.join(it)),
-            project_root: base.parent().map(AbsPath::to_path_buf),
+            project_root: base.to_path_buf(),
             crates: data
                 .crates
                 .into_iter()
@@ -85,17 +92,17 @@ impl ProjectJson {
                 .collect::<Vec<_>>(),
         }
     }
+    /// Returns the number of crates in the project.
     pub fn n_crates(&self) -> usize {
         self.crates.len()
     }
+    /// Returns an iterator over the crates in the project.
     pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ {
         self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate))
     }
-    pub fn path(&self) -> Option<&AbsPath> {
-        match &self.project_root {
-            Some(p) => Some(p.as_path()),
-            None => None,
-        }
+    /// Returns the path to the project's root folder.
+    pub fn path(&self) -> &AbsPath {
+        &self.project_root
     }
 }
 
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index b819618cb4..a052f36a71 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -249,7 +249,7 @@ impl GlobalState {
                     // Enable flychecks for json projects if a custom flycheck command was supplied
                     // in the workspace configuration.
                     match config {
-                        FlycheckConfig::CustomCommand { .. } => project.path(),
+                        FlycheckConfig::CustomCommand { .. } => Some(project.path()),
                         _ => None,
                     }
                 }
diff --git a/editors/code/package.json b/editors/code/package.json
index c57fbdda2a..86a70a89a7 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -879,10 +879,6 @@
             {
                 "id": "unsafe",
                 "description": "Style for unsafe operations"
-            },
-            {
-                "id": "consuming",
-                "description": "Style for non-Copy lvalues consumed by method/function call"
             }
         ],
         "semanticTokenScopes": [


Test patch:
diff --git a/crates/hir_def/src/item_tree/tests.rs b/crates/hir_def/src/item_tree/tests.rs
index eed3d0d6ff..620e697d4a 100644
--- a/crates/hir_def/src/item_tree/tests.rs
+++ b/crates/hir_def/src/item_tree/tests.rs
@@ -236,7 +236,7 @@ fn smoke() {
             #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]
             Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::<TypeAlias>(0)), Const(Idx::<Const>(0)), Function(Idx::<Function>(0)), Function(Idx::<Function>(1))], ast_id: FileAstId::<syntax::ast::generated::nodes::Trait>(2) }
             > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }]
-            > TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, is_extern: false, ast_id: FileAstId::<syntax::ast::generated::nodes::TypeAlias>(8) }
+            > TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, ast_id: FileAstId::<syntax::ast::generated::nodes::TypeAlias>(8) }
             > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }]
             > Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::<syntax::ast::generated::nodes::Const>(9) }
             > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_method"))] }, input: None }]) }]
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs
index 0f17ff1517..23b2601e64 100644
--- a/crates/hir_ty/src/tests/method_resolution.rs
+++ b/crates/hir_ty/src/tests/method_resolution.rs
@@ -1051,39 +1051,3 @@ fn dyn_trait_super_trait_not_in_scope() {
         "#]],
     );
 }
-
-#[test]
-fn method_resolution_foreign_opaque_type() {
-    check_infer(
-        r#"
-        extern "C" {
-            type S;
-            fn f() -> &'static S;
-        }
-
-        impl S {
-            fn foo(&self) -> bool {
-                true
-            }
-        }
-
-        fn test() {
-            let s = unsafe { f() };
-            s.foo();
-        }
-        "#,
-        expect![[r#"
-            75..79 'self': &S
-            89..109 '{     ...     }': bool
-            99..103 'true': bool
-            123..167 '{     ...o(); }': ()
-            133..134 's': &S
-            137..151 'unsafe { f() }': &S
-            144..151 '{ f() }': &S
-            146..147 'f': fn f() -> &S
-            146..149 'f()': &S
-            157..158 's': &S
-            157..164 's.foo()': bool
-        "#]],
-    );
-}