diff options
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/code_model.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 031c91ccf..a101d724e 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -186,6 +186,16 @@ impl_from!( | |||
186 | for ModuleDef | 186 | for ModuleDef |
187 | ); | 187 | ); |
188 | 188 | ||
189 | impl From<VariantDef> for ModuleDef { | ||
190 | fn from(var: VariantDef) -> Self { | ||
191 | match var { | ||
192 | VariantDef::Struct(t) => Adt::from(t).into(), | ||
193 | VariantDef::Union(t) => Adt::from(t).into(), | ||
194 | VariantDef::EnumVariant(t) => t.into(), | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | |||
189 | impl ModuleDef { | 199 | impl ModuleDef { |
190 | pub fn module(self, db: &dyn HirDatabase) -> Option<Module> { | 200 | pub fn module(self, db: &dyn HirDatabase) -> Option<Module> { |
191 | match self { | 201 | match self { |
@@ -752,6 +762,13 @@ impl Function { | |||
752 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { | 762 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { |
753 | hir_ty::diagnostics::validate_body(db, self.id.into(), sink) | 763 | hir_ty::diagnostics::validate_body(db, self.id.into(), sink) |
754 | } | 764 | } |
765 | |||
766 | /// Whether this function declaration has a definition. | ||
767 | /// | ||
768 | /// This is false in the case of required (not provided) trait methods. | ||
769 | pub fn has_body(self, db: &dyn HirDatabase) -> bool { | ||
770 | db.function_data(self.id).has_body | ||
771 | } | ||
755 | } | 772 | } |
756 | 773 | ||
757 | // Note: logically, this belongs to `hir_ty`, but we are not using it there yet. | 774 | // Note: logically, this belongs to `hir_ty`, but we are not using it there yet. |
@@ -1372,7 +1389,7 @@ impl Type { | |||
1372 | r#trait: Trait, | 1389 | r#trait: Trait, |
1373 | args: &[Type], | 1390 | args: &[Type], |
1374 | alias: TypeAlias, | 1391 | alias: TypeAlias, |
1375 | ) -> Option<Ty> { | 1392 | ) -> Option<Type> { |
1376 | let subst = Substs::build_for_def(db, r#trait.id) | 1393 | let subst = Substs::build_for_def(db, r#trait.id) |
1377 | .push(self.ty.value.clone()) | 1394 | .push(self.ty.value.clone()) |
1378 | .fill(args.iter().map(|t| t.ty.value.clone())) | 1395 | .fill(args.iter().map(|t| t.ty.value.clone())) |
@@ -1393,6 +1410,10 @@ impl Type { | |||
1393 | Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), | 1410 | Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), |
1394 | Solution::Ambig(_) => None, | 1411 | Solution::Ambig(_) => None, |
1395 | } | 1412 | } |
1413 | .map(|ty| Type { | ||
1414 | krate: self.krate, | ||
1415 | ty: InEnvironment { value: ty, environment: Arc::clone(&self.ty.environment) }, | ||
1416 | }) | ||
1396 | } | 1417 | } |
1397 | 1418 | ||
1398 | pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { | 1419 | pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { |