diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-25 21:33:21 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-25 21:33:21 +0100 |
commit | 5587d0a3e3599063a8993e9a44a7628abbabae8b (patch) | |
tree | 77d3d645249361e8a4730be803338caccddeefa0 /crates/hir_def/src/body.rs | |
parent | e23083f39813f9559c041b295d23534cd2125913 (diff) | |
parent | 5c9f31d4c28478b4373e6cf5ec155745c840ee3f (diff) |
Merge #8973
8973: internal: move diagnostics to hir r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/hir_def/src/body.rs')
-rw-r--r-- | crates/hir_def/src/body.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 98b485b60..c521879c8 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | //! Defines `Body`: a lowered representation of bodies of functions, statics and | 1 | //! Defines `Body`: a lowered representation of bodies of functions, statics and |
2 | //! consts. | 2 | //! consts. |
3 | mod lower; | 3 | mod lower; |
4 | mod diagnostics; | ||
5 | #[cfg(test)] | 4 | #[cfg(test)] |
6 | mod tests; | 5 | mod tests; |
7 | pub mod scope; | 6 | pub mod scope; |
@@ -9,17 +8,16 @@ pub mod scope; | |||
9 | use std::{mem, ops::Index, sync::Arc}; | 8 | use std::{mem, ops::Index, sync::Arc}; |
10 | 9 | ||
11 | use base_db::CrateId; | 10 | use base_db::CrateId; |
12 | use cfg::CfgOptions; | 11 | use cfg::{CfgExpr, CfgOptions}; |
13 | use drop_bomb::DropBomb; | 12 | use drop_bomb::DropBomb; |
14 | use either::Either; | 13 | use either::Either; |
15 | use hir_expand::{ | 14 | use hir_expand::{ |
16 | ast_id_map::AstIdMap, diagnostics::DiagnosticSink, hygiene::Hygiene, AstId, ExpandResult, | 15 | ast_id_map::AstIdMap, hygiene::Hygiene, AstId, ExpandResult, HirFileId, InFile, MacroDefId, |
17 | HirFileId, InFile, MacroDefId, | ||
18 | }; | 16 | }; |
19 | use la_arena::{Arena, ArenaMap}; | 17 | use la_arena::{Arena, ArenaMap}; |
20 | use profile::Count; | 18 | use profile::Count; |
21 | use rustc_hash::FxHashMap; | 19 | use rustc_hash::FxHashMap; |
22 | use syntax::{ast, AstNode, AstPtr}; | 20 | use syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; |
23 | 21 | ||
24 | use crate::{ | 22 | use crate::{ |
25 | attr::{Attrs, RawAttrs}, | 23 | attr::{Attrs, RawAttrs}, |
@@ -273,12 +271,20 @@ pub struct BodySourceMap { | |||
273 | 271 | ||
274 | /// Diagnostics accumulated during body lowering. These contain `AstPtr`s and so are stored in | 272 | /// Diagnostics accumulated during body lowering. These contain `AstPtr`s and so are stored in |
275 | /// the source map (since they're just as volatile). | 273 | /// the source map (since they're just as volatile). |
276 | diagnostics: Vec<diagnostics::BodyDiagnostic>, | 274 | diagnostics: Vec<BodyDiagnostic>, |
277 | } | 275 | } |
278 | 276 | ||
279 | #[derive(Default, Debug, Eq, PartialEq, Clone, Copy)] | 277 | #[derive(Default, Debug, Eq, PartialEq, Clone, Copy)] |
280 | pub struct SyntheticSyntax; | 278 | pub struct SyntheticSyntax; |
281 | 279 | ||
280 | #[derive(Debug, Eq, PartialEq)] | ||
281 | pub enum BodyDiagnostic { | ||
282 | InactiveCode { node: InFile<SyntaxNodePtr>, cfg: CfgExpr, opts: CfgOptions }, | ||
283 | MacroError { node: InFile<AstPtr<ast::MacroCall>>, message: String }, | ||
284 | UnresolvedProcMacro { node: InFile<AstPtr<ast::MacroCall>> }, | ||
285 | UnresolvedMacroCall { node: InFile<AstPtr<ast::MacroCall>>, path: ModPath }, | ||
286 | } | ||
287 | |||
282 | impl Body { | 288 | impl Body { |
283 | pub(crate) fn body_with_source_map_query( | 289 | pub(crate) fn body_with_source_map_query( |
284 | db: &dyn DefDatabase, | 290 | db: &dyn DefDatabase, |
@@ -416,9 +422,8 @@ impl BodySourceMap { | |||
416 | self.field_map.get(&src).cloned() | 422 | self.field_map.get(&src).cloned() |
417 | } | 423 | } |
418 | 424 | ||
419 | pub(crate) fn add_diagnostics(&self, _db: &dyn DefDatabase, sink: &mut DiagnosticSink<'_>) { | 425 | /// Get a reference to the body source map's diagnostics. |
420 | for diag in &self.diagnostics { | 426 | pub fn diagnostics(&self) -> &[BodyDiagnostic] { |
421 | diag.add_to(sink); | 427 | &self.diagnostics |
422 | } | ||
423 | } | 428 | } |
424 | } | 429 | } |