@@ -19,10 +19,9 @@ use crate::{
19
19
resolution:: errors:: ResolverError ,
20
20
} ,
21
21
hir_def:: expr:: { HirExpression , HirIdent } ,
22
- lexer:: Lexer ,
23
22
node_interner:: { DefinitionKind , DependencyId , FuncId , NodeInterner , StructId , TraitId } ,
24
- parser:: { Item , ItemKind , Parser } ,
25
- token:: SecondaryAttribute ,
23
+ parser:: { Item , ItemKind } ,
24
+ token:: { MetaAttribute , SecondaryAttribute } ,
26
25
Type , TypeBindings , UnificationError ,
27
26
} ;
28
27
@@ -162,10 +161,9 @@ impl<'context> Elaborator<'context> {
162
161
if let SecondaryAttribute :: Meta ( attribute) = attribute {
163
162
self . elaborate_in_comptime_context ( |this| {
164
163
if let Err ( error) = this. run_comptime_attribute_name_on_item (
165
- & attribute. contents ,
164
+ attribute,
166
165
item. clone ( ) ,
167
166
span,
168
- attribute. contents_span ,
169
167
attribute_context,
170
168
generated_items,
171
169
) {
@@ -177,27 +175,21 @@ impl<'context> Elaborator<'context> {
177
175
178
176
fn run_comptime_attribute_name_on_item (
179
177
& mut self ,
180
- attribute : & str ,
178
+ attribute : & MetaAttribute ,
181
179
item : Value ,
182
180
span : Span ,
183
- attribute_span : Span ,
184
181
attribute_context : AttributeContext ,
185
182
generated_items : & mut CollectedItems ,
186
183
) -> Result < ( ) , ( CompilationError , FileId ) > {
187
184
self . file = attribute_context. attribute_file ;
188
185
self . local_module = attribute_context. attribute_module ;
189
186
190
- let location = Location :: new ( attribute_span, self . file ) ;
191
- let Some ( ( function, arguments) ) = Self :: parse_attribute ( attribute, location) ? else {
192
- return Err ( (
193
- ResolverError :: UnableToParseAttribute {
194
- attribute : attribute. to_string ( ) ,
195
- span : attribute_span,
196
- }
197
- . into ( ) ,
198
- self . file ,
199
- ) ) ;
187
+ let location = Location :: new ( attribute. span , self . file ) ;
188
+ let function = Expression {
189
+ kind : ExpressionKind :: Variable ( attribute. name . clone ( ) ) ,
190
+ span : attribute. span ,
200
191
} ;
192
+ let arguments = attribute. arguments . clone ( ) ;
201
193
202
194
// Elaborate the function, rolling back any errors generated in case it is unknown
203
195
let error_count = self . errors . len ( ) ;
@@ -211,7 +203,7 @@ impl<'context> Elaborator<'context> {
211
203
return Err ( (
212
204
ResolverError :: AttributeFunctionIsNotAPath {
213
205
function : function_string,
214
- span : attribute_span ,
206
+ span : attribute . span ,
215
207
}
216
208
. into ( ) ,
217
209
self . file ,
@@ -223,7 +215,7 @@ impl<'context> Elaborator<'context> {
223
215
return Err ( (
224
216
ResolverError :: AttributeFunctionNotInScope {
225
217
name : function_string,
226
- span : attribute_span ,
218
+ span : attribute . span ,
227
219
}
228
220
. into ( ) ,
229
221
self . file ,
@@ -269,38 +261,6 @@ impl<'context> Elaborator<'context> {
269
261
Ok ( ( ) )
270
262
}
271
263
272
- /// Parses an attribute in the form of a function call (e.g. `#[foo(a b, c d)]`) into
273
- /// the function and quoted arguments called (e.g. `("foo", vec![(a b, location), (c d, location)])`)
274
- #[ allow( clippy:: type_complexity) ]
275
- pub ( crate ) fn parse_attribute (
276
- annotation : & str ,
277
- location : Location ,
278
- ) -> Result < Option < ( Expression , Vec < Expression > ) > , ( CompilationError , FileId ) > {
279
- let ( tokens, mut lexing_errors) = Lexer :: lex ( annotation) ;
280
- if !lexing_errors. is_empty ( ) {
281
- return Err ( ( lexing_errors. swap_remove ( 0 ) . into ( ) , location. file ) ) ;
282
- }
283
-
284
- let Some ( expression) = Parser :: for_tokens ( tokens) . parse_option ( Parser :: parse_expression)
285
- else {
286
- return Ok ( None ) ;
287
- } ;
288
-
289
- let ( mut func, mut arguments) = match expression. kind {
290
- ExpressionKind :: Call ( call) => ( * call. func , call. arguments ) ,
291
- ExpressionKind :: Variable ( _) => ( expression, Vec :: new ( ) ) ,
292
- _ => return Ok ( None ) ,
293
- } ;
294
-
295
- func. span = func. span . shift_by ( location. span . start ( ) ) ;
296
-
297
- for argument in & mut arguments {
298
- argument. span = argument. span . shift_by ( location. span . start ( ) ) ;
299
- }
300
-
301
- Ok ( Some ( ( func, arguments) ) )
302
- }
303
-
304
264
fn handle_attribute_arguments (
305
265
interpreter : & mut Interpreter ,
306
266
item : & Value ,
0 commit comments