diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-12 15:40:28 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-12 15:40:28 +0100 |
commit | f9e67d692d915b326bd20a4c487039ade377029b (patch) | |
tree | 649f0226ded68ee7883b66ebfbbfcc371d1fba74 /crates/hir/src/lib.rs | |
parent | c1c2c92e47d1db2386f40c446c5a5122912048a7 (diff) | |
parent | 0413d51317a2470c94f82d93e66a3d009fce41a3 (diff) |
Merge #9230
9230: internal: move inference diagnostics to hir r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/hir/src/lib.rs')
-rw-r--r-- | crates/hir/src/lib.rs | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 0bb3767c1..a21a9da21 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -36,13 +36,14 @@ use std::{iter, sync::Arc}; | |||
36 | use arrayvec::ArrayVec; | 36 | use arrayvec::ArrayVec; |
37 | use base_db::{CrateDisplayName, CrateId, Edition, FileId}; | 37 | use base_db::{CrateDisplayName, CrateId, Edition, FileId}; |
38 | use diagnostics::{ | 38 | use diagnostics::{ |
39 | InactiveCode, MacroError, UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, | 39 | BreakOutsideOfLoop, InactiveCode, MacroError, MissingUnsafe, NoSuchField, |
40 | UnresolvedMacroCall, UnresolvedModule, UnresolvedProcMacro, | 40 | UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, |
41 | UnresolvedModule, UnresolvedProcMacro, | ||
41 | }; | 42 | }; |
42 | use either::Either; | 43 | use either::Either; |
43 | use hir_def::{ | 44 | use hir_def::{ |
44 | adt::{ReprKind, VariantData}, | 45 | adt::{ReprKind, VariantData}, |
45 | body::BodyDiagnostic, | 46 | body::{BodyDiagnostic, SyntheticSyntax}, |
46 | expr::{BindingAnnotation, LabelId, Pat, PatId}, | 47 | expr::{BindingAnnotation, LabelId, Pat, PatId}, |
47 | item_tree::ItemTreeNode, | 48 | item_tree::ItemTreeNode, |
48 | lang_item::LangItemTarget, | 49 | lang_item::LangItemTarget, |
@@ -1042,6 +1043,35 @@ impl Function { | |||
1042 | } | 1043 | } |
1043 | } | 1044 | } |
1044 | 1045 | ||
1046 | let infer = db.infer(self.id.into()); | ||
1047 | let (_, source_map) = db.body_with_source_map(self.id.into()); | ||
1048 | for d in &infer.diagnostics { | ||
1049 | match d { | ||
1050 | hir_ty::InferenceDiagnostic::NoSuchField { expr } => { | ||
1051 | let field = source_map.field_syntax(*expr); | ||
1052 | sink.push(NoSuchField { file: field.file_id, field: field.value }) | ||
1053 | } | ||
1054 | hir_ty::InferenceDiagnostic::BreakOutsideOfLoop { expr } => { | ||
1055 | let ptr = source_map | ||
1056 | .expr_syntax(*expr) | ||
1057 | .expect("break outside of loop in synthetic syntax"); | ||
1058 | sink.push(BreakOutsideOfLoop { file: ptr.file_id, expr: ptr.value }) | ||
1059 | } | ||
1060 | } | ||
1061 | } | ||
1062 | |||
1063 | for expr in hir_ty::diagnostics::missing_unsafe(db, self.id.into()) { | ||
1064 | match source_map.as_ref().expr_syntax(expr) { | ||
1065 | Ok(in_file) => { | ||
1066 | sink.push(MissingUnsafe { file: in_file.file_id, expr: in_file.value }) | ||
1067 | } | ||
1068 | Err(SyntheticSyntax) => { | ||
1069 | // FIXME: The `expr` was desugared, report or assert that | ||
1070 | // this dosen't happen. | ||
1071 | } | ||
1072 | } | ||
1073 | } | ||
1074 | |||
1045 | hir_ty::diagnostics::validate_module_item(db, krate, self.id.into(), sink); | 1075 | hir_ty::diagnostics::validate_module_item(db, krate, self.id.into(), sink); |
1046 | hir_ty::diagnostics::validate_body(db, self.id.into(), sink); | 1076 | hir_ty::diagnostics::validate_body(db, self.id.into(), sink); |
1047 | } | 1077 | } |