@@ -17,9 +17,9 @@ use rustc::ty::layout::VariantIdx;
17
17
use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
18
18
use rustc_index:: vec:: IndexVec ;
19
19
use rustc_target:: spec:: abi:: Abi ;
20
- use syntax:: ast:: { self , Attribute , AttrStyle , AttrKind , Ident } ;
20
+ use syntax:: ast:: { self , AttrStyle , Ident } ;
21
21
use syntax:: attr;
22
- use syntax:: util:: comments;
22
+ use syntax:: util:: comments:: strip_doc_comment_decoration ;
23
23
use syntax:: source_map:: DUMMY_SP ;
24
24
use syntax_pos:: hygiene:: MacroKind ;
25
25
use syntax_pos:: symbol:: { Symbol , sym} ;
@@ -507,51 +507,26 @@ impl Attributes {
507
507
let mut cfg = Cfg :: True ;
508
508
let mut doc_line = 0 ;
509
509
510
- /// If `attr` is a doc comment, strips the leading and (if present)
511
- /// trailing comments symbols, e.g. `///`, `/**`, and `*/`. Otherwise,
512
- /// returns `attr` unchanged.
513
- pub fn with_doc_comment_markers_stripped < T > (
514
- attr : & Attribute ,
515
- f : impl FnOnce ( & Attribute ) -> T ,
516
- ) -> T {
517
- match attr. kind {
518
- AttrKind :: Normal ( _) => {
519
- f ( attr)
520
- }
521
- AttrKind :: DocComment ( comment) => {
522
- let comment =
523
- Symbol :: intern ( & comments:: strip_doc_comment_decoration ( & comment. as_str ( ) ) ) ;
524
- f ( & Attribute {
525
- kind : AttrKind :: DocComment ( comment) ,
526
- id : attr. id ,
527
- style : attr. style ,
528
- span : attr. span ,
529
- } )
530
- }
531
- }
532
- }
533
-
534
510
let other_attrs = attrs. iter ( ) . filter_map ( |attr| {
535
- with_doc_comment_markers_stripped ( attr, |attr| {
536
- if attr. check_name ( sym:: doc) {
537
- if let Some ( mi) = attr. meta ( ) {
538
- if let Some ( value) = mi. value_str ( ) {
539
- // Extracted #[doc = "..."]
540
- let value = value. to_string ( ) ;
541
- let line = doc_line;
542
- doc_line += value. lines ( ) . count ( ) ;
511
+ if let Some ( value) = attr. doc_str ( ) {
512
+ let ( value, mk_fragment) : ( _ , fn ( _, _, _) -> _ ) = if attr. is_doc_comment ( ) {
513
+ ( strip_doc_comment_decoration ( & value. as_str ( ) ) , DocFragment :: SugaredDoc )
514
+ } else {
515
+ ( value. to_string ( ) , DocFragment :: RawDoc )
516
+ } ;
543
517
544
- if attr. is_doc_comment ( ) {
545
- doc_strings. push ( DocFragment :: SugaredDoc ( line, attr. span , value) ) ;
546
- } else {
547
- doc_strings. push ( DocFragment :: RawDoc ( line, attr. span , value) ) ;
548
- }
518
+ let line = doc_line;
519
+ doc_line += value. lines ( ) . count ( ) ;
520
+ doc_strings. push ( mk_fragment ( line, attr. span , value) ) ;
549
521
550
- if sp. is_none ( ) {
551
- sp = Some ( attr. span ) ;
552
- }
553
- return None ;
554
- } else if let Some ( cfg_mi) = Attributes :: extract_cfg ( & mi) {
522
+ if sp. is_none ( ) {
523
+ sp = Some ( attr. span ) ;
524
+ }
525
+ None
526
+ } else {
527
+ if attr. check_name ( sym:: doc) {
528
+ if let Some ( mi) = attr. meta ( ) {
529
+ if let Some ( cfg_mi) = Attributes :: extract_cfg ( & mi) {
555
530
// Extracted #[doc(cfg(...))]
556
531
match Cfg :: parse ( cfg_mi) {
557
532
Ok ( new_cfg) => cfg &= new_cfg,
@@ -570,7 +545,7 @@ impl Attributes {
570
545
}
571
546
}
572
547
Some ( attr. clone ( ) )
573
- } )
548
+ }
574
549
} ) . collect ( ) ;
575
550
576
551
// treat #[target_feature(enable = "feat")] attributes as if they were
@@ -589,7 +564,7 @@ impl Attributes {
589
564
}
590
565
591
566
let inner_docs = attrs. iter ( )
592
- . filter ( |a| a. check_name ( sym :: doc ) )
567
+ . filter ( |a| a. doc_str ( ) . is_some ( ) )
593
568
. next ( )
594
569
. map_or ( true , |a| a. style == AttrStyle :: Inner ) ;
595
570
0 commit comments