@@ -17,10 +17,10 @@ use rustc::ty::layout::VariantIdx;
1717use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
1818use rustc_index:: vec:: IndexVec ;
1919use rustc_target:: spec:: abi:: Abi ;
20- use syntax:: ast:: { self , AttrKind , AttrStyle , Attribute , Ident } ;
20+ use syntax:: ast:: { self , AttrStyle , Ident } ;
2121use syntax:: attr;
2222use syntax:: source_map:: DUMMY_SP ;
23- use syntax:: util:: comments;
23+ use syntax:: util:: comments:: strip_doc_comment_decoration ;
2424use syntax_pos:: hygiene:: MacroKind ;
2525use syntax_pos:: symbol:: { sym, Symbol } ;
2626use syntax_pos:: { self , FileName } ;
@@ -502,58 +502,33 @@ impl Attributes {
502502 let mut cfg = Cfg :: True ;
503503 let mut doc_line = 0 ;
504504
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-
527505 let other_attrs = attrs
528506 . iter ( )
529507 . 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 {
531524 if attr. check_name ( sym:: doc) {
532525 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) {
551527 // Extracted #[doc(cfg(...))]
552528 match Cfg :: parse ( cfg_mi) {
553529 Ok ( new_cfg) => cfg &= new_cfg,
554530 Err ( e) => diagnostic. span_err ( e. span , e. msg ) ,
555531 }
556- return None ;
557532 } else if let Some ( ( filename, contents) ) =
558533 Attributes :: extract_include ( & mi)
559534 {
@@ -566,7 +541,7 @@ impl Attributes {
566541 }
567542 }
568543 Some ( attr. clone ( ) )
569- } )
544+ }
570545 } )
571546 . collect ( ) ;
572547
@@ -589,7 +564,7 @@ impl Attributes {
589564
590565 let inner_docs = attrs
591566 . iter ( )
592- . filter ( |a| a. check_name ( sym :: doc ) )
567+ . filter ( |a| a. doc_str ( ) . is_some ( ) )
593568 . next ( )
594569 . map_or ( true , |a| a. style == AttrStyle :: Inner ) ;
595570
0 commit comments