@@ -244,77 +244,71 @@ fn highlight_name_ref(
244
244
name_ref : ast:: NameRef ,
245
245
) -> Highlight {
246
246
let db = sema. db ;
247
- highlight_method_call_by_name_ref ( sema, krate, & name_ref) . unwrap_or_else ( || {
248
- let name_class = match NameRefClass :: classify ( sema, & name_ref) {
249
- Some ( name_kind) => name_kind,
250
- None => {
251
- return if syntactic_name_ref_highlighting {
252
- highlight_name_ref_by_syntax ( name_ref, sema, krate)
253
- } else {
254
- // FIXME: Workaround for https://github.com/rust-analyzer/rust-analyzer/issues/10708
255
- //
256
- // Some popular proc macros (namely async_trait) will rewrite `self` in such a way that it no
257
- // longer resolves via NameRefClass. If we can't be resolved, but we know we're a self token,
258
- // within a function with a self param, pretend to still be `self`, rather than
259
- // an unresolved reference.
260
- if name_ref. self_token ( ) . is_some ( ) && is_in_fn_with_self_param ( & name_ref) {
261
- SymbolKind :: SelfParam . into ( )
262
- } else {
263
- HlTag :: UnresolvedReference . into ( )
264
- }
265
- } ;
266
- }
267
- } ;
268
- let mut h = match name_class {
269
- NameRefClass :: Definition ( def) => {
270
- if let Definition :: Local ( local) = & def {
271
- if let Some ( name) = local. name ( db) {
272
- let shadow_count = bindings_shadow_count. entry ( name. clone ( ) ) . or_default ( ) ;
273
- * binding_hash = Some ( calc_binding_hash ( & name, * shadow_count) )
274
- }
275
- } ;
247
+ if let Some ( res) = highlight_method_call_by_name_ref ( sema, krate, & name_ref) {
248
+ return res;
249
+ }
276
250
277
- let mut h = highlight_def ( sema, krate, def) ;
251
+ let name_class = match NameRefClass :: classify ( sema, & name_ref) {
252
+ Some ( name_kind) => name_kind,
253
+ None if syntactic_name_ref_highlighting => {
254
+ return highlight_name_ref_by_syntax ( name_ref, sema, krate)
255
+ }
256
+ // FIXME: Workaround for https://github.com/rust-analyzer/rust-analyzer/issues/10708
257
+ //
258
+ // Some popular proc macros (namely async_trait) will rewrite `self` in such a way that it no
259
+ // longer resolves via NameRefClass. If we can't be resolved, but we know we're a self token,
260
+ // within a function with a self param, pretend to still be `self`, rather than
261
+ // an unresolved reference.
262
+ None if name_ref. self_token ( ) . is_some ( ) && is_in_fn_with_self_param ( & name_ref) => {
263
+ return SymbolKind :: SelfParam . into ( )
264
+ }
265
+ None => return HlTag :: UnresolvedReference . into ( ) ,
266
+ } ;
267
+ let mut h = match name_class {
268
+ NameRefClass :: Definition ( def) => {
269
+ if let Definition :: Local ( local) = & def {
270
+ if let Some ( name) = local. name ( db) {
271
+ let shadow_count = bindings_shadow_count. entry ( name. clone ( ) ) . or_default ( ) ;
272
+ * binding_hash = Some ( calc_binding_hash ( & name, * shadow_count) )
273
+ }
274
+ } ;
275
+
276
+ let mut h = highlight_def ( sema, krate, def) ;
278
277
279
- match def {
280
- Definition :: Local ( local)
281
- if is_consumed_lvalue ( name_ref. syntax ( ) , & local, db) =>
278
+ match def {
279
+ Definition :: Local ( local) if is_consumed_lvalue ( name_ref. syntax ( ) , & local, db) => {
280
+ h |= HlMod :: Consuming ;
281
+ }
282
+ Definition :: Trait ( trait_) if trait_. is_unsafe ( db) => {
283
+ if ast:: Impl :: for_trait_name_ref ( & name_ref)
284
+ . map_or ( false , |impl_| impl_. unsafe_token ( ) . is_some ( ) )
282
285
{
283
- h |= HlMod :: Consuming ;
286
+ h |= HlMod :: Unsafe ;
284
287
}
285
- Definition :: Trait ( trait_) if trait_. is_unsafe ( db) => {
286
- if ast:: Impl :: for_trait_name_ref ( & name_ref)
287
- . map_or ( false , |impl_| impl_. unsafe_token ( ) . is_some ( ) )
288
- {
289
- h |= HlMod :: Unsafe ;
290
- }
291
- }
292
- Definition :: Field ( field) => {
293
- if let Some ( parent) = name_ref. syntax ( ) . parent ( ) {
294
- if matches ! ( parent. kind( ) , FIELD_EXPR | RECORD_PAT_FIELD ) {
295
- if let hir:: VariantDef :: Union ( _) = field. parent_def ( db) {
296
- h |= HlMod :: Unsafe ;
297
- }
288
+ }
289
+ Definition :: Field ( field) => {
290
+ if let Some ( parent) = name_ref. syntax ( ) . parent ( ) {
291
+ if matches ! ( parent. kind( ) , FIELD_EXPR | RECORD_PAT_FIELD ) {
292
+ if let hir:: VariantDef :: Union ( _) = field. parent_def ( db) {
293
+ h |= HlMod :: Unsafe ;
298
294
}
299
295
}
300
296
}
301
- _ => ( ) ,
302
297
}
303
-
304
- h
305
- }
306
- NameRefClass :: FieldShorthand { .. } => SymbolKind :: Field . into ( ) ,
307
- } ;
308
- if h. tag == HlTag :: Symbol ( SymbolKind :: Module ) {
309
- if name_ref. self_token ( ) . is_some ( ) {
310
- return SymbolKind :: SelfParam . into ( ) ;
311
- }
312
- if name_ref. crate_token ( ) . is_some ( ) || name_ref. super_token ( ) . is_some ( ) {
313
- h. tag = HlTag :: Keyword ;
298
+ _ => ( ) ,
314
299
}
300
+
301
+ h
315
302
}
316
- h
317
- } )
303
+ NameRefClass :: FieldShorthand { .. } => SymbolKind :: Field . into ( ) ,
304
+ } ;
305
+ if name_ref. self_token ( ) . is_some ( ) {
306
+ h. tag = HlTag :: Symbol ( SymbolKind :: SelfParam ) ;
307
+ }
308
+ if name_ref. crate_token ( ) . is_some ( ) || name_ref. super_token ( ) . is_some ( ) {
309
+ h. tag = HlTag :: Keyword ;
310
+ }
311
+ h
318
312
}
319
313
320
314
fn highlight_name (
0 commit comments