File tree Expand file tree Collapse file tree 4 files changed +36
-32
lines changed Expand file tree Collapse file tree 4 files changed +36
-32
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ macro_rules! diagnostics {
32
32
}
33
33
34
34
diagnostics ! [
35
+ BreakOutsideOfLoop ,
35
36
InactiveCode ,
36
37
MacroError ,
37
38
MissingFields ,
@@ -98,28 +99,9 @@ pub struct NoSuchField {
98
99
pub field : InFile < AstPtr < ast:: RecordExprField > > ,
99
100
}
100
101
101
- // Diagnostic: break-outside-of-loop
102
- //
103
- // This diagnostic is triggered if the `break` keyword is used outside of a loop.
104
102
#[ derive( Debug ) ]
105
103
pub struct BreakOutsideOfLoop {
106
- pub file : HirFileId ,
107
- pub expr : AstPtr < ast:: Expr > ,
108
- }
109
-
110
- impl Diagnostic for BreakOutsideOfLoop {
111
- fn code ( & self ) -> DiagnosticCode {
112
- DiagnosticCode ( "break-outside-of-loop" )
113
- }
114
- fn message ( & self ) -> String {
115
- "break outside of loop" . to_string ( )
116
- }
117
- fn display_source ( & self ) -> InFile < SyntaxNodePtr > {
118
- InFile { file_id : self . file , value : self . expr . clone ( ) . into ( ) }
119
- }
120
- fn as_any ( & self ) -> & ( dyn Any + Send + ' static ) {
121
- self
122
- }
104
+ pub expr : InFile < AstPtr < ast:: Expr > > ,
123
105
}
124
106
125
107
// Diagnostic: missing-unsafe
Original file line number Diff line number Diff line change @@ -1080,10 +1080,10 @@ impl Function {
1080
1080
acc. push ( NoSuchField { field } . into ( ) )
1081
1081
}
1082
1082
hir_ty:: InferenceDiagnostic :: BreakOutsideOfLoop { expr } => {
1083
- let ptr = source_map
1083
+ let expr = source_map
1084
1084
. expr_syntax ( * expr)
1085
1085
. expect ( "break outside of loop in synthetic syntax" ) ;
1086
- sink . push ( BreakOutsideOfLoop { file : ptr . file_id , expr : ptr . value } )
1086
+ acc . push ( BreakOutsideOfLoop { expr } . into ( ) )
1087
1087
}
1088
1088
}
1089
1089
}
Original file line number Diff line number Diff line change 4
4
//! macro-expanded files, but we need to present them to the users in terms of
5
5
//! original files. So we need to map the ranges.
6
6
7
+ mod break_outside_of_loop;
7
8
mod inactive_code;
8
9
mod macro_error;
9
10
mod missing_fields;
@@ -218,6 +219,7 @@ pub(crate) fn diagnostics(
218
219
for diag in diags {
219
220
#[ rustfmt:: skip]
220
221
let d = match diag {
222
+ AnyDiagnostic :: BreakOutsideOfLoop ( d) => break_outside_of_loop:: break_outside_of_loop ( & ctx, & d) ,
221
223
AnyDiagnostic :: MacroError ( d) => macro_error:: macro_error ( & ctx, & d) ,
222
224
AnyDiagnostic :: MissingFields ( d) => missing_fields:: missing_fields ( & ctx, & d) ,
223
225
AnyDiagnostic :: NoSuchField ( d) => no_such_field:: no_such_field ( & ctx, & d) ,
@@ -711,16 +713,6 @@ mod foo;
711
713
) ;
712
714
}
713
715
714
- #[ test]
715
- fn break_outside_of_loop ( ) {
716
- check_diagnostics (
717
- r#"
718
- fn foo() { break; }
719
- //^^^^^ break outside of loop
720
- "# ,
721
- ) ;
722
- }
723
-
724
716
#[ test]
725
717
fn missing_unsafe_diagnostic_with_raw_ptr ( ) {
726
718
check_diagnostics (
Original file line number Diff line number Diff line change
1
+ use crate :: diagnostics:: { Diagnostic , DiagnosticsContext } ;
2
+
3
+ // Diagnostic: break-outside-of-loop
4
+ //
5
+ // This diagnostic is triggered if the `break` keyword is used outside of a loop.
6
+ pub ( super ) fn break_outside_of_loop (
7
+ ctx : & DiagnosticsContext < ' _ > ,
8
+ d : & hir:: BreakOutsideOfLoop ,
9
+ ) -> Diagnostic {
10
+ Diagnostic :: new (
11
+ "break-outside-of-loop" ,
12
+ "break outside of loop" ,
13
+ ctx. sema . diagnostics_display_range ( d. expr . clone ( ) . map ( |it| it. into ( ) ) ) . range ,
14
+ )
15
+ }
16
+
17
+ #[ cfg( test) ]
18
+ mod tests {
19
+ use crate :: diagnostics:: tests:: check_diagnostics;
20
+
21
+ #[ test]
22
+ fn break_outside_of_loop ( ) {
23
+ check_diagnostics (
24
+ r#"
25
+ fn foo() { break; }
26
+ //^^^^^ break outside of loop
27
+ "# ,
28
+ ) ;
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments