From 0a5b38f9c3d5beb641b146b2a7c56c8b4257633e Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Fri, 11 Oct 2019 14:01:02 +0200 Subject: move Attribute::with_desugared_doc to librustdoc --- src/libsyntax/attr/mod.rs | 29 ++--------------------------- src/libsyntax/parse/lexer/comments.rs | 2 +- src/libsyntax/parse/lexer/tokentrees.rs | 3 ++- 3 files changed, 5 insertions(+), 29 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 4aec5040881..27de084ae98 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -13,8 +13,8 @@ use crate::ast::{AttrItem, AttrId, AttrStyle, Name, Ident, Path, PathSegment}; use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem}; use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam}; use crate::mut_visit::visit_clobber; -use crate::source_map::{BytePos, Spanned, DUMMY_SP}; -use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration}; +use crate::source_map::{BytePos, Spanned}; +use crate::parse::lexer::comments::doc_comment_style; use crate::parse::parser::Parser; use crate::parse::PResult; use crate::parse::token::{self, Token}; @@ -312,31 +312,6 @@ impl Attribute { span: self.span, }) } - - /// Converts `self` to a normal `#[doc="foo"]` comment, if it is a - /// comment like `///` or `/** */`. (Returns `self` unchanged for - /// non-sugared doc attributes.) - pub fn with_desugared_doc(&self, f: F) -> T where - F: FnOnce(&Attribute) -> T, - { - if self.is_sugared_doc { - let comment = self.value_str().unwrap(); - let meta = mk_name_value_item_str( - Ident::with_dummy_span(sym::doc), - Symbol::intern(&strip_doc_comment_decoration(&comment.as_str())), - DUMMY_SP, - ); - f(&Attribute { - item: AttrItem { path: meta.path, tokens: meta.kind.tokens(meta.span) }, - id: self.id, - style: self.style, - is_sugared_doc: true, - span: self.span, - }) - } else { - f(self) - } - } } /* Constructors */ diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 5121a9ef7b5..ac79ce323bf 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -176,7 +176,7 @@ fn split_block_comment_into_lines( // it appears this function is called only from pprust... that's // probably not a good thing. -pub fn gather_comments(sess: &ParseSess, path: FileName, src: String) -> Vec { +crate fn gather_comments(sess: &ParseSess, path: FileName, src: String) -> Vec { let cm = SourceMap::new(sess.source_map().path_mapping().clone()); let source_file = cm.new_source_file(path, src); let text = (*source_file.src.as_ref().unwrap()).clone(); diff --git a/src/libsyntax/parse/lexer/tokentrees.rs b/src/libsyntax/parse/lexer/tokentrees.rs index b4dd23c9f9b..853723de14f 100644 --- a/src/libsyntax/parse/lexer/tokentrees.rs +++ b/src/libsyntax/parse/lexer/tokentrees.rs @@ -1,8 +1,9 @@ use rustc_data_structures::fx::FxHashMap; use syntax_pos::Span; +use super::{StringReader, UnmatchedBrace}; + use crate::print::pprust::token_to_string; -use crate::parse::lexer::{StringReader, UnmatchedBrace}; use crate::parse::token::{self, Token}; use crate::parse::PResult; use crate::tokenstream::{DelimSpan, IsJoint::{self, *}, TokenStream, TokenTree, TreeAndJoint}; -- cgit 1.4.1-3-g733a5