diff options
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/code_model.rs | 47 | ||||
-rw-r--r-- | crates/hir/src/diagnostics.rs | 3 | ||||
-rw-r--r-- | crates/hir/src/semantics/source_to_def.rs | 4 |
3 files changed, 51 insertions, 3 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 031c91ccf..b65be4fe1 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 { |
@@ -245,6 +255,25 @@ impl ModuleDef { | |||
245 | ModuleDef::BuiltinType(it) => Some(it.as_name()), | 255 | ModuleDef::BuiltinType(it) => Some(it.as_name()), |
246 | } | 256 | } |
247 | } | 257 | } |
258 | |||
259 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { | ||
260 | let id = match self { | ||
261 | ModuleDef::Adt(it) => match it { | ||
262 | Adt::Struct(it) => it.id.into(), | ||
263 | Adt::Enum(it) => it.id.into(), | ||
264 | Adt::Union(it) => it.id.into(), | ||
265 | }, | ||
266 | ModuleDef::Trait(it) => it.id.into(), | ||
267 | ModuleDef::Function(it) => it.id.into(), | ||
268 | ModuleDef::TypeAlias(it) => it.id.into(), | ||
269 | ModuleDef::Module(it) => it.id.into(), | ||
270 | ModuleDef::Const(it) => it.id.into(), | ||
271 | ModuleDef::Static(it) => it.id.into(), | ||
272 | _ => return, | ||
273 | }; | ||
274 | |||
275 | hir_ty::diagnostics::validate_module_item(db, id, sink) | ||
276 | } | ||
248 | } | 277 | } |
249 | 278 | ||
250 | pub use hir_def::{ | 279 | pub use hir_def::{ |
@@ -348,6 +377,8 @@ impl Module { | |||
348 | let crate_def_map = db.crate_def_map(self.id.krate); | 377 | let crate_def_map = db.crate_def_map(self.id.krate); |
349 | crate_def_map.add_diagnostics(db.upcast(), self.id.local_id, sink); | 378 | crate_def_map.add_diagnostics(db.upcast(), self.id.local_id, sink); |
350 | for decl in self.declarations(db) { | 379 | for decl in self.declarations(db) { |
380 | decl.diagnostics(db, sink); | ||
381 | |||
351 | match decl { | 382 | match decl { |
352 | crate::ModuleDef::Function(f) => f.diagnostics(db, sink), | 383 | crate::ModuleDef::Function(f) => f.diagnostics(db, sink), |
353 | crate::ModuleDef::Module(m) => { | 384 | crate::ModuleDef::Module(m) => { |
@@ -750,7 +781,15 @@ impl Function { | |||
750 | } | 781 | } |
751 | 782 | ||
752 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { | 783 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { |
753 | hir_ty::diagnostics::validate_body(db, self.id.into(), sink) | 784 | hir_ty::diagnostics::validate_module_item(db, self.id.into(), sink); |
785 | hir_ty::diagnostics::validate_body(db, self.id.into(), sink); | ||
786 | } | ||
787 | |||
788 | /// Whether this function declaration has a definition. | ||
789 | /// | ||
790 | /// This is false in the case of required (not provided) trait methods. | ||
791 | pub fn has_body(self, db: &dyn HirDatabase) -> bool { | ||
792 | db.function_data(self.id).has_body | ||
754 | } | 793 | } |
755 | } | 794 | } |
756 | 795 | ||
@@ -1372,7 +1411,7 @@ impl Type { | |||
1372 | r#trait: Trait, | 1411 | r#trait: Trait, |
1373 | args: &[Type], | 1412 | args: &[Type], |
1374 | alias: TypeAlias, | 1413 | alias: TypeAlias, |
1375 | ) -> Option<Ty> { | 1414 | ) -> Option<Type> { |
1376 | let subst = Substs::build_for_def(db, r#trait.id) | 1415 | let subst = Substs::build_for_def(db, r#trait.id) |
1377 | .push(self.ty.value.clone()) | 1416 | .push(self.ty.value.clone()) |
1378 | .fill(args.iter().map(|t| t.ty.value.clone())) | 1417 | .fill(args.iter().map(|t| t.ty.value.clone())) |
@@ -1393,6 +1432,10 @@ impl Type { | |||
1393 | Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), | 1432 | Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), |
1394 | Solution::Ambig(_) => None, | 1433 | Solution::Ambig(_) => None, |
1395 | } | 1434 | } |
1435 | .map(|ty| Type { | ||
1436 | krate: self.krate, | ||
1437 | ty: InEnvironment { value: ty, environment: Arc::clone(&self.ty.environment) }, | ||
1438 | }) | ||
1396 | } | 1439 | } |
1397 | 1440 | ||
1398 | pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { | 1441 | pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { |
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 363164b9b..da2b40849 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs | |||
@@ -2,5 +2,6 @@ | |||
2 | pub use hir_def::diagnostics::UnresolvedModule; | 2 | pub use hir_def::diagnostics::UnresolvedModule; |
3 | pub use hir_expand::diagnostics::{Diagnostic, DiagnosticSink, DiagnosticSinkBuilder}; | 3 | pub use hir_expand::diagnostics::{Diagnostic, DiagnosticSink, DiagnosticSinkBuilder}; |
4 | pub use hir_ty::diagnostics::{ | 4 | pub use hir_ty::diagnostics::{ |
5 | MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkInTailExpr, NoSuchField, | 5 | IncorrectCase, MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkInTailExpr, |
6 | NoSuchField, | ||
6 | }; | 7 | }; |
diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 5918b9541..66fc11611 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs | |||
@@ -189,6 +189,10 @@ impl SourceToDefCtx<'_, '_> { | |||
189 | let def = self.type_alias_to_def(container.with_value(it))?; | 189 | let def = self.type_alias_to_def(container.with_value(it))?; |
190 | def.into() | 190 | def.into() |
191 | }, | 191 | }, |
192 | ast::Variant(it) => { | ||
193 | let def = self.enum_variant_to_def(container.with_value(it))?; | ||
194 | VariantId::from(def).into() | ||
195 | }, | ||
192 | _ => continue, | 196 | _ => continue, |
193 | } | 197 | } |
194 | }; | 198 | }; |