1
1
use std:: collections:: { HashMap , HashSet } ;
2
- use std:: iter:: once;
2
+ use std:: {
3
+ iter:: { once, FromIterator } ,
4
+ sync:: Mutex ,
5
+ } ;
3
6
4
7
use hir:: {
5
8
db:: DefDatabase , Adt , AsAssocItem , AsName , AssocItemContainer , AttrDef , Crate , Documentation ,
6
9
FieldSource , HasSource , HirDisplay , Hygiene , ItemInNs , ModPath , Module , ModuleDef ,
7
10
ModuleSource , Semantics ,
8
11
} ;
9
12
use itertools:: Itertools ;
10
- use lazy_static:: lazy_static;
11
- use maplit:: { hashmap, hashset} ;
13
+ use once_cell:: sync:: Lazy ;
12
14
use pulldown_cmark:: { CowStr , Event , Options , Parser , Tag } ;
13
15
use pulldown_cmark_to_cmark:: cmark;
14
16
use ra_db:: SourceDatabase ;
@@ -419,14 +421,26 @@ enum Namespace {
419
421
Macros ,
420
422
}
421
423
422
- lazy_static ! (
423
- /// Map of namespaces to identifying prefixes and suffixes as defined by RFC1946.
424
- static ref NS_MAP : HashMap <Namespace , ( HashSet <& ' static str >, HashSet <& ' static str >) > = hashmap!{
425
- Namespace :: Types => ( hashset!{ "type" , "struct" , "enum" , "mod" , "trait" , "union" , "module" } , hashset!{ } ) ,
426
- Namespace :: Values => ( hashset!{ "value" , "function" , "fn" , "method" , "const" , "static" , "mod" , "module" } , hashset!{ "()" } ) ,
427
- Namespace :: Macros => ( hashset!{ "macro" } , hashset!{ "!" } )
428
- } ;
429
- ) ;
424
+ static NS_MAP : Lazy <
425
+ HashMap < Namespace , ( HashSet < & ' static & ' static str > , HashSet < & ' static & ' static str > ) > ,
426
+ > = Lazy :: new ( || {
427
+ let mut map = HashMap :: new ( ) ;
428
+ map. insert ( Namespace :: Types , ( HashSet :: new ( ) , HashSet :: new ( ) ) ) ;
429
+ map. insert (
430
+ Namespace :: Values ,
431
+ (
432
+ HashSet :: from_iter (
433
+ [ "value" , "function" , "fn" , "method" , "const" , "static" , "mod" , "module" ] . iter ( ) ,
434
+ ) ,
435
+ HashSet :: from_iter ( [ "()" ] . iter ( ) ) ,
436
+ ) ,
437
+ ) ;
438
+ map. insert (
439
+ Namespace :: Macros ,
440
+ ( HashSet :: from_iter ( [ "macro" ] . iter ( ) ) , HashSet :: from_iter ( [ "!" ] . iter ( ) ) ) ,
441
+ ) ;
442
+ map
443
+ } ) ;
430
444
431
445
impl Namespace {
432
446
/// Extract the specified namespace from an intra-doc-link if one exists.
@@ -437,7 +451,7 @@ impl Namespace {
437
451
prefixes
438
452
. iter ( )
439
453
. map ( |prefix| {
440
- s. starts_with ( prefix)
454
+ s. starts_with ( * prefix)
441
455
&& s. chars ( )
442
456
. nth ( prefix. len ( ) + 1 )
443
457
. map ( |c| c == '@' || c == ' ' )
@@ -447,7 +461,7 @@ impl Namespace {
447
461
|| suffixes
448
462
. iter ( )
449
463
. map ( |suffix| {
450
- s. starts_with ( suffix)
464
+ s. starts_with ( * suffix)
451
465
&& s. chars ( )
452
466
. nth ( suffix. len ( ) + 1 )
453
467
. map ( |c| c == '@' || c == ' ' )
@@ -464,8 +478,8 @@ impl Namespace {
464
478
fn strip_prefixes_suffixes ( mut s : & str ) -> & str {
465
479
s = s. trim_matches ( '`' ) ;
466
480
NS_MAP . iter ( ) . for_each ( |( _, ( prefixes, suffixes) ) | {
467
- prefixes. iter ( ) . for_each ( |prefix| s = s. trim_start_matches ( prefix) ) ;
468
- suffixes. iter ( ) . for_each ( |suffix| s = s. trim_end_matches ( suffix) ) ;
481
+ prefixes. iter ( ) . for_each ( |prefix| s = s. trim_start_matches ( * prefix) ) ;
482
+ suffixes. iter ( ) . for_each ( |suffix| s = s. trim_end_matches ( * suffix) ) ;
469
483
} ) ;
470
484
s. trim_start_matches ( "@" ) . trim ( )
471
485
}
0 commit comments