diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-12-07 21:28:29 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-12-28 12:33:18 +0300 |
| commit | 3d57b8bcc0a6a0378a9cea0291bb76d44bec6ff8 (patch) | |
| tree | 6ed3c1b94ff90cfe6e72625d51824ed67e5e0112 /src/libsyntax | |
| parent | 3a087ad3a924be12343bb035bf9b63ed81f650bf (diff) | |
| download | rust-3d57b8bcc0a6a0378a9cea0291bb76d44bec6ff8.tar.gz rust-3d57b8bcc0a6a0378a9cea0291bb76d44bec6ff8.zip | |
doc comments: Less attribute mimicking
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/attr/builtin.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/attr/mod.rs | 24 |
3 files changed, 17 insertions, 13 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c98942abaf3..0a2004a8229 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -2364,10 +2364,6 @@ pub enum AttrKind { /// A doc comment (e.g. `/// ...`, `//! ...`, `/** ... */`, `/*! ... */`). /// Doc attributes (e.g. `#[doc="..."]`) are represented with the `Normal` /// variant (which is much less compact and thus more expensive). - /// - /// Note: `self.has_name(sym::doc)` and `self.check_name(sym::doc)` succeed - /// for this variant, but this may change in the future. - /// ``` DocComment(Symbol), } diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 65b67981474..bf64333830e 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -16,7 +16,7 @@ use syntax_pos::{symbol::sym, symbol::Symbol, Span}; use rustc_error_codes::*; pub fn is_builtin_attr(attr: &Attribute) -> bool { - attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some() + attr.is_doc_comment() || attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some() } enum AttrError { diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 82685e98386..0cd300384f8 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -139,7 +139,7 @@ impl Attribute { pub fn has_name(&self, name: Symbol) -> bool { match self.kind { AttrKind::Normal(ref item) => item.path == name, - AttrKind::DocComment(_) => name == sym::doc, + AttrKind::DocComment(_) => false, } } @@ -163,7 +163,7 @@ impl Attribute { None } } - AttrKind::DocComment(_) => Some(Ident::new(sym::doc, self.span)), + AttrKind::DocComment(_) => None, } } pub fn name_or_empty(&self) -> Symbol { @@ -173,7 +173,7 @@ impl Attribute { pub fn value_str(&self) -> Option<Symbol> { match self.kind { AttrKind::Normal(ref item) => item.meta(self.span).and_then(|meta| meta.value_str()), - AttrKind::DocComment(comment) => Some(comment), + AttrKind::DocComment(..) => None, } } @@ -279,17 +279,27 @@ impl Attribute { } } + pub fn doc_str(&self) -> Option<Symbol> { + match self.kind { + AttrKind::DocComment(symbol) => Some(symbol), + AttrKind::Normal(ref item) if item.path == sym::doc => { + item.meta(self.span).and_then(|meta| meta.value_str()) + } + _ => None, + } + } + pub fn get_normal_item(&self) -> &AttrItem { match self.kind { AttrKind::Normal(ref item) => item, - AttrKind::DocComment(_) => panic!("unexpected sugared doc"), + AttrKind::DocComment(_) => panic!("unexpected doc comment"), } } pub fn unwrap_normal_item(self) -> AttrItem { match self.kind { AttrKind::Normal(item) => item, - AttrKind::DocComment(_) => panic!("unexpected sugared doc"), + AttrKind::DocComment(_) => panic!("unexpected doc comment"), } } @@ -297,9 +307,7 @@ impl Attribute { pub fn meta(&self) -> Option<MetaItem> { match self.kind { AttrKind::Normal(ref item) => item.meta(self.span), - AttrKind::DocComment(comment) => { - Some(mk_name_value_item_str(Ident::new(sym::doc, self.span), comment, self.span)) - } + AttrKind::DocComment(..) => None, } } } |
