diff options
author | Florian Diebold <[email protected]> | 2020-05-08 18:48:03 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-05-08 18:48:03 +0100 |
commit | d0129c4ddba3b72e7b26e94e9c25546d37dbf166 (patch) | |
tree | 465c1af378252ce1fea0f47e30f69892332761a0 /crates/ra_hir_ty/src/infer.rs | |
parent | f8bf94a4b94074eb344e495dfb4dab4bec6bc20e (diff) |
Add diagnostic for break outside of loop
Diffstat (limited to 'crates/ra_hir_ty/src/infer.rs')
-rw-r--r-- | crates/ra_hir_ty/src/infer.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 413904518..a21ad8d86 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs | |||
@@ -717,11 +717,15 @@ mod diagnostics { | |||
717 | use hir_def::{expr::ExprId, FunctionId}; | 717 | use hir_def::{expr::ExprId, FunctionId}; |
718 | use hir_expand::diagnostics::DiagnosticSink; | 718 | use hir_expand::diagnostics::DiagnosticSink; |
719 | 719 | ||
720 | use crate::{db::HirDatabase, diagnostics::NoSuchField}; | 720 | use crate::{ |
721 | db::HirDatabase, | ||
722 | diagnostics::{BreakOutsideOfLoop, NoSuchField}, | ||
723 | }; | ||
721 | 724 | ||
722 | #[derive(Debug, PartialEq, Eq, Clone)] | 725 | #[derive(Debug, PartialEq, Eq, Clone)] |
723 | pub(super) enum InferenceDiagnostic { | 726 | pub(super) enum InferenceDiagnostic { |
724 | NoSuchField { expr: ExprId, field: usize }, | 727 | NoSuchField { expr: ExprId, field: usize }, |
728 | BreakOutsideOfLoop { expr: ExprId }, | ||
725 | } | 729 | } |
726 | 730 | ||
727 | impl InferenceDiagnostic { | 731 | impl InferenceDiagnostic { |
@@ -737,6 +741,13 @@ mod diagnostics { | |||
737 | let field = source_map.field_syntax(*expr, *field); | 741 | let field = source_map.field_syntax(*expr, *field); |
738 | sink.push(NoSuchField { file: field.file_id, field: field.value }) | 742 | sink.push(NoSuchField { file: field.file_id, field: field.value }) |
739 | } | 743 | } |
744 | InferenceDiagnostic::BreakOutsideOfLoop { expr } => { | ||
745 | let (_, source_map) = db.body_with_source_map(owner.into()); | ||
746 | let ptr = source_map | ||
747 | .expr_syntax(*expr) | ||
748 | .expect("break outside of loop in synthetic syntax"); | ||
749 | sink.push(BreakOutsideOfLoop { file: ptr.file_id, expr: ptr.value }) | ||
750 | } | ||
740 | } | 751 | } |
741 | } | 752 | } |
742 | } | 753 | } |