@@ -17,9 +17,9 @@ 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 , Attribute , AttrStyle , AttrKind , Ident } ;
20+ use syntax:: ast:: { self , AttrStyle , Ident } ;
2121use syntax:: attr;
22- use syntax:: util:: comments;
22+ use syntax:: util:: comments:: strip_doc_comment_decoration ;
2323use syntax:: source_map:: DUMMY_SP ;
2424use syntax_pos:: hygiene:: MacroKind ;
2525use syntax_pos:: symbol:: { Symbol , sym} ;
@@ -507,51 +507,26 @@ impl Attributes {
507507 let mut cfg = Cfg :: True ;
508508 let mut doc_line = 0 ;
509509
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-
534510 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+ } ;
543517
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) ) ;
549521
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) {
555530 // Extracted #[doc(cfg(...))]
556531 match Cfg :: parse ( cfg_mi) {
557532 Ok ( new_cfg) => cfg &= new_cfg,
@@ -570,7 +545,7 @@ impl Attributes {
570545 }
571546 }
572547 Some ( attr. clone ( ) )
573- } )
548+ }
574549 } ) . collect ( ) ;
575550
576551 // treat #[target_feature(enable = "feat")] attributes as if they were
@@ -589,7 +564,7 @@ impl Attributes {
589564 }
590565
591566 let inner_docs = attrs. 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