@@ -17,10 +17,10 @@ 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 , AttrKind , AttrStyle , Attribute , Ident } ;
20
+ use syntax:: ast:: { self , AttrStyle , Ident } ;
21
21
use syntax:: attr;
22
22
use syntax:: source_map:: DUMMY_SP ;
23
- use syntax:: util:: comments;
23
+ use syntax:: util:: comments:: strip_doc_comment_decoration ;
24
24
use syntax_pos:: hygiene:: MacroKind ;
25
25
use syntax_pos:: symbol:: { sym, Symbol } ;
26
26
use syntax_pos:: { self , FileName } ;
@@ -502,58 +502,33 @@ impl Attributes {
502
502
let mut cfg = Cfg :: True ;
503
503
let mut doc_line = 0 ;
504
504
505
- /// If `attr` is a doc comment, strips the leading and (if present)
506
- /// trailing comments symbols, e.g. `///`, `/**`, and `*/`. Otherwise,
507
- /// returns `attr` unchanged.
508
- pub fn with_doc_comment_markers_stripped < T > (
509
- attr : & Attribute ,
510
- f : impl FnOnce ( & Attribute ) -> T ,
511
- ) -> T {
512
- match attr. kind {
513
- AttrKind :: Normal ( _) => f ( attr) ,
514
- AttrKind :: DocComment ( comment) => {
515
- let comment =
516
- Symbol :: intern ( & comments:: strip_doc_comment_decoration ( & comment. as_str ( ) ) ) ;
517
- f ( & Attribute {
518
- kind : AttrKind :: DocComment ( comment) ,
519
- id : attr. id ,
520
- style : attr. style ,
521
- span : attr. span ,
522
- } )
523
- }
524
- }
525
- }
526
-
527
505
let other_attrs = attrs
528
506
. iter ( )
529
507
. filter_map ( |attr| {
530
- with_doc_comment_markers_stripped ( attr, |attr| {
508
+ if let Some ( value) = attr. doc_str ( ) {
509
+ let ( value, mk_fragment) : ( _ , fn ( _, _, _) -> _ ) = if attr. is_doc_comment ( ) {
510
+ ( strip_doc_comment_decoration ( & value. as_str ( ) ) , DocFragment :: SugaredDoc )
511
+ } else {
512
+ ( value. to_string ( ) , DocFragment :: RawDoc )
513
+ } ;
514
+
515
+ let line = doc_line;
516
+ doc_line += value. lines ( ) . count ( ) ;
517
+ doc_strings. push ( mk_fragment ( line, attr. span , value) ) ;
518
+
519
+ if sp. is_none ( ) {
520
+ sp = Some ( attr. span ) ;
521
+ }
522
+ None
523
+ } else {
531
524
if attr. check_name ( sym:: doc) {
532
525
if let Some ( mi) = attr. meta ( ) {
533
- if let Some ( value) = mi. value_str ( ) {
534
- // Extracted #[doc = "..."]
535
- let value = value. to_string ( ) ;
536
- let line = doc_line;
537
- doc_line += value. lines ( ) . count ( ) ;
538
-
539
- if attr. is_doc_comment ( ) {
540
- doc_strings
541
- . push ( DocFragment :: SugaredDoc ( line, attr. span , value) ) ;
542
- } else {
543
- doc_strings. push ( DocFragment :: RawDoc ( line, attr. span , value) ) ;
544
- }
545
-
546
- if sp. is_none ( ) {
547
- sp = Some ( attr. span ) ;
548
- }
549
- return None ;
550
- } else if let Some ( cfg_mi) = Attributes :: extract_cfg ( & mi) {
526
+ if let Some ( cfg_mi) = Attributes :: extract_cfg ( & mi) {
551
527
// Extracted #[doc(cfg(...))]
552
528
match Cfg :: parse ( cfg_mi) {
553
529
Ok ( new_cfg) => cfg &= new_cfg,
554
530
Err ( e) => diagnostic. span_err ( e. span , e. msg ) ,
555
531
}
556
- return None ;
557
532
} else if let Some ( ( filename, contents) ) =
558
533
Attributes :: extract_include ( & mi)
559
534
{
@@ -566,7 +541,7 @@ impl Attributes {
566
541
}
567
542
}
568
543
Some ( attr. clone ( ) )
569
- } )
544
+ }
570
545
} )
571
546
. collect ( ) ;
572
547
@@ -589,7 +564,7 @@ impl Attributes {
589
564
590
565
let inner_docs = attrs
591
566
. 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