Skip to content

Commit a1571b6

Browse files
committed
syntax::attr: remove usage of lexer
1 parent 255b12a commit a1571b6

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/libsyntax/attr/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem};
1414
use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam};
1515
use crate::mut_visit::visit_clobber;
1616
use crate::source_map::{BytePos, Spanned};
17-
use crate::parse::lexer::comments::doc_comment_style;
1817
use crate::parse;
1918
use crate::token::{self, Token};
2019
use crate::ptr::P;
@@ -401,11 +400,11 @@ pub fn mk_attr_outer(item: MetaItem) -> Attribute {
401400
mk_attr(AttrStyle::Outer, item.path, item.kind.tokens(item.span), item.span)
402401
}
403402

404-
pub fn mk_doc_comment(comment: Symbol, span: Span) -> Attribute {
403+
pub fn mk_doc_comment(style: AttrStyle, comment: Symbol, span: Span) -> Attribute {
405404
Attribute {
406405
kind: AttrKind::DocComment(comment),
407406
id: mk_attr_id(),
408-
style: doc_comment_style(&comment.as_str()),
407+
style,
409408
span,
410409
}
411410
}

src/libsyntax/parse/parser/attr.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use super::{SeqSep, Parser, TokenType, PathStyle};
22
use crate::attr;
33
use crate::ast;
4+
use crate::parse::lexer::comments;
45
use crate::token::{self, Nonterminal, DelimToken};
56
use crate::tokenstream::{TokenStream, TokenTree};
67
use crate::source_map::Span;
78

9+
use syntax_pos::Symbol;
810
use errors::PResult;
911

1012
use log::debug;
@@ -45,7 +47,7 @@ impl<'a> Parser<'a> {
4547
just_parsed_doc_comment = false;
4648
}
4749
token::DocComment(s) => {
48-
let attr = attr::mk_doc_comment(s, self.token.span);
50+
let attr = self.mk_doc_comment(s);
4951
if attr.style != ast::AttrStyle::Outer {
5052
let mut err = self.fatal("expected outer doc comment");
5153
err.note("inner doc comments like this (starting with \
@@ -62,6 +64,11 @@ impl<'a> Parser<'a> {
6264
Ok(attrs)
6365
}
6466

67+
fn mk_doc_comment(&self, s: Symbol) -> ast::Attribute {
68+
let style = comments::doc_comment_style(&s.as_str());
69+
attr::mk_doc_comment(style, s, self.token.span)
70+
}
71+
6572
/// Matches `attribute = # ! [ meta_item ]`.
6673
///
6774
/// If `permit_inner` is `true`, then a leading `!` indicates an inner
@@ -230,7 +237,7 @@ impl<'a> Parser<'a> {
230237
}
231238
token::DocComment(s) => {
232239
// We need to get the position of this token before we bump.
233-
let attr = attr::mk_doc_comment(s, self.token.span);
240+
let attr = self.mk_doc_comment(s);
234241
if attr.style == ast::AttrStyle::Inner {
235242
attrs.push(attr);
236243
self.bump();

0 commit comments

Comments
 (0)