@@ -32,14 +32,19 @@ macro_rules! diagnostics {
3232}
3333
3434diagnostics ! [
35- UnresolvedModule ,
35+ BreakOutsideOfLoop ,
36+ InactiveCode ,
37+ MacroError ,
38+ MismatchedArgCount ,
39+ MissingFields ,
40+ MissingUnsafe ,
41+ NoSuchField ,
42+ UnimplementedBuiltinMacro ,
3643 UnresolvedExternCrate ,
3744 UnresolvedImport ,
3845 UnresolvedMacroCall ,
46+ UnresolvedModule ,
3947 UnresolvedProcMacro ,
40- MacroError ,
41- MissingFields ,
42- InactiveCode ,
4348] ;
4449
4550#[ derive( Debug ) ]
@@ -88,101 +93,22 @@ pub struct MacroError {
8893
8994#[ derive( Debug ) ]
9095pub struct UnimplementedBuiltinMacro {
91- pub file : HirFileId ,
92- pub node : SyntaxNodePtr ,
93- }
94-
95- impl Diagnostic for UnimplementedBuiltinMacro {
96- fn code ( & self ) -> DiagnosticCode {
97- DiagnosticCode ( "unimplemented-builtin-macro" )
98- }
99-
100- fn message ( & self ) -> String {
101- "unimplemented built-in macro" . to_string ( )
102- }
103-
104- fn display_source ( & self ) -> InFile < SyntaxNodePtr > {
105- InFile :: new ( self . file , self . node . clone ( ) )
106- }
107-
108- fn as_any ( & self ) -> & ( dyn Any + Send + ' static ) {
109- self
110- }
96+ pub node : InFile < SyntaxNodePtr > ,
11197}
11298
113- // Diagnostic: no-such-field
114- //
115- // This diagnostic is triggered if created structure does not have field provided in record.
11699#[ derive( Debug ) ]
117100pub struct NoSuchField {
118- pub file : HirFileId ,
119- pub field : AstPtr < ast:: RecordExprField > ,
101+ pub field : InFile < AstPtr < ast:: RecordExprField > > ,
120102}
121103
122- impl Diagnostic for NoSuchField {
123- fn code ( & self ) -> DiagnosticCode {
124- DiagnosticCode ( "no-such-field" )
125- }
126-
127- fn message ( & self ) -> String {
128- "no such field" . to_string ( )
129- }
130-
131- fn display_source ( & self ) -> InFile < SyntaxNodePtr > {
132- InFile :: new ( self . file , self . field . clone ( ) . into ( ) )
133- }
134-
135- fn as_any ( & self ) -> & ( dyn Any + Send + ' static ) {
136- self
137- }
138- }
139-
140- // Diagnostic: break-outside-of-loop
141- //
142- // This diagnostic is triggered if the `break` keyword is used outside of a loop.
143104#[ derive( Debug ) ]
144105pub struct BreakOutsideOfLoop {
145- pub file : HirFileId ,
146- pub expr : AstPtr < ast:: Expr > ,
106+ pub expr : InFile < AstPtr < ast:: Expr > > ,
147107}
148108
149- impl Diagnostic for BreakOutsideOfLoop {
150- fn code ( & self ) -> DiagnosticCode {
151- DiagnosticCode ( "break-outside-of-loop" )
152- }
153- fn message ( & self ) -> String {
154- "break outside of loop" . to_string ( )
155- }
156- fn display_source ( & self ) -> InFile < SyntaxNodePtr > {
157- InFile { file_id : self . file , value : self . expr . clone ( ) . into ( ) }
158- }
159- fn as_any ( & self ) -> & ( dyn Any + Send + ' static ) {
160- self
161- }
162- }
163-
164- // Diagnostic: missing-unsafe
165- //
166- // This diagnostic is triggered if an operation marked as `unsafe` is used outside of an `unsafe` function or block.
167109#[ derive( Debug ) ]
168110pub struct MissingUnsafe {
169- pub file : HirFileId ,
170- pub expr : AstPtr < ast:: Expr > ,
171- }
172-
173- impl Diagnostic for MissingUnsafe {
174- fn code ( & self ) -> DiagnosticCode {
175- DiagnosticCode ( "missing-unsafe" )
176- }
177- fn message ( & self ) -> String {
178- format ! ( "This operation is unsafe and requires an unsafe function or block" )
179- }
180- fn display_source ( & self ) -> InFile < SyntaxNodePtr > {
181- InFile { file_id : self . file , value : self . expr . clone ( ) . into ( ) }
182- }
183- fn as_any ( & self ) -> & ( dyn Any + Send + ' static ) {
184- self
185- }
111+ pub expr : InFile < AstPtr < ast:: Expr > > ,
186112}
187113
188114#[ derive( Debug ) ]
@@ -218,36 +144,13 @@ impl Diagnostic for ReplaceFilterMapNextWithFindMap {
218144 }
219145}
220146
221- // Diagnostic: mismatched-arg-count
222- //
223- // This diagnostic is triggered if a function is invoked with an incorrect amount of arguments.
224147#[ derive( Debug ) ]
225148pub struct MismatchedArgCount {
226- pub file : HirFileId ,
227- pub call_expr : AstPtr < ast:: Expr > ,
149+ pub call_expr : InFile < AstPtr < ast:: Expr > > ,
228150 pub expected : usize ,
229151 pub found : usize ,
230152}
231153
232- impl Diagnostic for MismatchedArgCount {
233- fn code ( & self ) -> DiagnosticCode {
234- DiagnosticCode ( "mismatched-arg-count" )
235- }
236- fn message ( & self ) -> String {
237- let s = if self . expected == 1 { "" } else { "s" } ;
238- format ! ( "Expected {} argument{}, found {}" , self . expected, s, self . found)
239- }
240- fn display_source ( & self ) -> InFile < SyntaxNodePtr > {
241- InFile { file_id : self . file , value : self . call_expr . clone ( ) . into ( ) }
242- }
243- fn as_any ( & self ) -> & ( dyn Any + Send + ' static ) {
244- self
245- }
246- fn is_experimental ( & self ) -> bool {
247- true
248- }
249- }
250-
251154#[ derive( Debug ) ]
252155pub struct RemoveThisSemicolon {
253156 pub file : HirFileId ,
0 commit comments