@@ -224,125 +224,93 @@ impl NameClass {
224
224
225
225
let parent = name. syntax ( ) . parent ( ) ?;
226
226
227
- if let Some ( bind_pat) = ast:: IdentPat :: cast ( parent. clone ( ) ) {
228
- if let Some ( def) = sema. resolve_bind_pat_to_const ( & bind_pat) {
227
+ let def = if let Some ( item) = ast:: Item :: cast ( parent. clone ( ) ) {
228
+ match item {
229
+ ast:: Item :: MacroRules ( it) => {
230
+ Definition :: Macro ( sema. to_def ( & ast:: Macro :: MacroRules ( it) ) ?)
231
+ }
232
+ ast:: Item :: MacroDef ( it) => {
233
+ Definition :: Macro ( sema. to_def ( & ast:: Macro :: MacroDef ( it) ) ?)
234
+ }
235
+ ast:: Item :: Const ( it) => Definition :: Const ( sema. to_def ( & it) ?) ,
236
+ ast:: Item :: Fn ( it) => Definition :: Function ( sema. to_def ( & it) ?) ,
237
+ ast:: Item :: Module ( it) => Definition :: Module ( sema. to_def ( & it) ?) ,
238
+ ast:: Item :: Static ( it) => Definition :: Static ( sema. to_def ( & it) ?) ,
239
+ ast:: Item :: Trait ( it) => Definition :: Trait ( sema. to_def ( & it) ?) ,
240
+ ast:: Item :: TypeAlias ( it) => Definition :: TypeAlias ( sema. to_def ( & it) ?) ,
241
+ ast:: Item :: Enum ( it) => Definition :: Adt ( hir:: Adt :: Enum ( sema. to_def ( & it) ?) ) ,
242
+ ast:: Item :: Struct ( it) => Definition :: Adt ( hir:: Adt :: Struct ( sema. to_def ( & it) ?) ) ,
243
+ ast:: Item :: Union ( it) => Definition :: Adt ( hir:: Adt :: Union ( sema. to_def ( & it) ?) ) ,
244
+ _ => return None ,
245
+ }
246
+ } else if let Some ( it) = ast:: IdentPat :: cast ( parent. clone ( ) ) {
247
+ if let Some ( def) = sema. resolve_bind_pat_to_const ( & it) {
229
248
return Some ( NameClass :: ConstReference ( Definition :: from ( def) ) ) ;
230
249
}
231
- }
232
250
233
- match_ast ! {
234
- match parent {
235
- ast:: Rename ( it) => {
236
- if let Some ( use_tree) = it. syntax( ) . parent( ) . and_then( ast:: UseTree :: cast) {
237
- let path = use_tree. path( ) ?;
238
- let path_segment = path. segment( ) ?;
239
- let name_ref = path_segment. name_ref( ) ?;
240
- let name_ref = if name_ref. self_token( ) . is_some( ) {
241
- use_tree
242
- . syntax( )
243
- . parent( )
244
- . as_ref( )
245
- // Skip over UseTreeList
246
- . and_then( |it| {
247
- let use_tree = it. parent( ) . and_then( ast:: UseTree :: cast) ?;
248
- let path = use_tree. path( ) ?;
249
- let path_segment = path. segment( ) ?;
250
- path_segment. name_ref( )
251
- } ) . unwrap_or( name_ref)
252
- } else {
253
- name_ref
254
- } ;
255
- let name_ref_class = NameRefClass :: classify( sema, & name_ref) ?;
256
-
257
- Some ( NameClass :: Definition ( match name_ref_class {
258
- NameRefClass :: Definition ( def) => def,
259
- NameRefClass :: FieldShorthand { local_ref: _, field_ref } => {
260
- Definition :: Field ( field_ref)
261
- }
262
- } ) )
263
- } else {
264
- let extern_crate = it. syntax( ) . parent( ) . and_then( ast:: ExternCrate :: cast) ?;
265
- let krate = sema. resolve_extern_crate( & extern_crate) ?;
266
- let root_module = krate. root_module( sema. db) ;
267
- Some ( NameClass :: Definition ( Definition :: Module ( root_module) ) )
251
+ let local = sema. to_def ( & it) ?;
252
+ let pat_parent = it. syntax ( ) . parent ( ) ;
253
+ if let Some ( record_pat_field) = pat_parent. and_then ( ast:: RecordPatField :: cast) {
254
+ if record_pat_field. name_ref ( ) . is_none ( ) {
255
+ if let Some ( field) = sema. resolve_record_pat_field ( & record_pat_field) {
256
+ return Some ( NameClass :: PatFieldShorthand {
257
+ local_def : local,
258
+ field_ref : field,
259
+ } ) ;
268
260
}
269
- } ,
270
- ast:: IdentPat ( it) => {
271
- let local = sema. to_def( & it) ?;
261
+ }
262
+ }
272
263
273
- if let Some ( record_pat_field) = it. syntax( ) . parent( ) . and_then( ast:: RecordPatField :: cast) {
274
- if record_pat_field. name_ref( ) . is_none( ) {
275
- if let Some ( field) = sema. resolve_record_pat_field( & record_pat_field) {
276
- return Some ( NameClass :: PatFieldShorthand { local_def: local, field_ref: field } ) ;
277
- }
278
- }
279
- }
264
+ Definition :: Local ( local)
265
+ } else if let Some ( it) = ast:: Rename :: cast ( parent. clone ( ) ) {
266
+ if let Some ( use_tree) = it. syntax ( ) . parent ( ) . and_then ( ast:: UseTree :: cast) {
267
+ let path = use_tree. path ( ) ?;
268
+ let path_segment = path. segment ( ) ?;
269
+ let name_ref = path_segment. name_ref ( ) ?;
270
+ let name_ref = if name_ref. self_token ( ) . is_some ( ) {
271
+ use_tree
272
+ . syntax ( )
273
+ . parent ( )
274
+ . as_ref ( )
275
+ // Skip over UseTreeList
276
+ . and_then ( |it| {
277
+ let use_tree = it. parent ( ) . and_then ( ast:: UseTree :: cast) ?;
278
+ let path = use_tree. path ( ) ?;
279
+ let path_segment = path. segment ( ) ?;
280
+ path_segment. name_ref ( )
281
+ } )
282
+ . unwrap_or ( name_ref)
283
+ } else {
284
+ name_ref
285
+ } ;
286
+ let name_ref_class = NameRefClass :: classify ( sema, & name_ref) ?;
280
287
281
- Some ( NameClass :: Definition ( Definition :: Local ( local) ) )
282
- } ,
283
- ast:: SelfParam ( it) => {
284
- let def = sema. to_def( & it) ?;
285
- Some ( NameClass :: Definition ( Definition :: Local ( def) ) )
286
- } ,
287
- ast:: RecordField ( it) => {
288
- let field: hir:: Field = sema. to_def( & it) ?;
289
- Some ( NameClass :: Definition ( Definition :: Field ( field) ) )
290
- } ,
291
- ast:: Module ( it) => {
292
- let def = sema. to_def( & it) ?;
293
- Some ( NameClass :: Definition ( Definition :: Module ( def) ) )
294
- } ,
295
- ast:: Struct ( it) => {
296
- let def: hir:: Struct = sema. to_def( & it) ?;
297
- Some ( NameClass :: Definition ( Definition :: Adt ( def. into( ) ) ) )
298
- } ,
299
- ast:: Union ( it) => {
300
- let def: hir:: Union = sema. to_def( & it) ?;
301
- Some ( NameClass :: Definition ( Definition :: Adt ( def. into( ) ) ) )
302
- } ,
303
- ast:: Enum ( it) => {
304
- let def: hir:: Enum = sema. to_def( & it) ?;
305
- Some ( NameClass :: Definition ( Definition :: Adt ( def. into( ) ) ) )
306
- } ,
307
- ast:: Trait ( it) => {
308
- let def: hir:: Trait = sema. to_def( & it) ?;
309
- Some ( NameClass :: Definition ( Definition :: Trait ( def) ) )
310
- } ,
311
- ast:: Static ( it) => {
312
- let def: hir:: Static = sema. to_def( & it) ?;
313
- Some ( NameClass :: Definition ( Definition :: Static ( def) ) )
314
- } ,
315
- ast:: Variant ( it) => {
316
- let def: hir:: Variant = sema. to_def( & it) ?;
317
- Some ( NameClass :: Definition ( Definition :: Variant ( def) ) )
318
- } ,
319
- ast:: Fn ( it) => {
320
- let def: hir:: Function = sema. to_def( & it) ?;
321
- Some ( NameClass :: Definition ( Definition :: Function ( def) ) )
322
- } ,
323
- ast:: Const ( it) => {
324
- let def: hir:: Const = sema. to_def( & it) ?;
325
- Some ( NameClass :: Definition ( Definition :: Const ( def) ) )
326
- } ,
327
- ast:: TypeAlias ( it) => {
328
- let def: hir:: TypeAlias = sema. to_def( & it) ?;
329
- Some ( NameClass :: Definition ( Definition :: TypeAlias ( def) ) )
330
- } ,
331
- ast:: Macro ( it) => {
332
- let def = sema. to_def( & it) ?;
333
- Some ( NameClass :: Definition ( Definition :: Macro ( def) ) )
334
- } ,
335
- ast:: TypeParam ( it) => {
336
- let def = sema. to_def( & it) ?;
337
- Some ( NameClass :: Definition ( Definition :: GenericParam ( def. into( ) ) ) )
338
- } ,
339
- ast:: ConstParam ( it) => {
340
- let def = sema. to_def( & it) ?;
341
- Some ( NameClass :: Definition ( Definition :: GenericParam ( def. into( ) ) ) )
342
- } ,
343
- _ => None ,
288
+ match name_ref_class {
289
+ NameRefClass :: Definition ( def) => def,
290
+ NameRefClass :: FieldShorthand { local_ref : _, field_ref } => {
291
+ Definition :: Field ( field_ref)
292
+ }
293
+ }
294
+ } else {
295
+ let extern_crate = it. syntax ( ) . parent ( ) . and_then ( ast:: ExternCrate :: cast) ?;
296
+ let krate = sema. resolve_extern_crate ( & extern_crate) ?;
297
+ let root_module = krate. root_module ( sema. db ) ;
298
+ Definition :: Module ( root_module)
344
299
}
345
- }
300
+ } else {
301
+ match_ast ! {
302
+ match parent {
303
+ ast:: SelfParam ( it) => Definition :: Local ( sema. to_def( & it) ?) ,
304
+ ast:: RecordField ( it) => Definition :: Field ( sema. to_def( & it) ?) ,
305
+ ast:: Variant ( it) => Definition :: Variant ( sema. to_def( & it) ?) ,
306
+ ast:: TypeParam ( it) => Definition :: GenericParam ( sema. to_def( & it) ?. into( ) ) ,
307
+ ast:: ConstParam ( it) => Definition :: GenericParam ( sema. to_def( & it) ?. into( ) ) ,
308
+ _ => return None ,
309
+ }
310
+ }
311
+ } ;
312
+
313
+ Some ( NameClass :: Definition ( def) )
346
314
}
347
315
348
316
pub fn classify_lifetime (
0 commit comments