Auto merge of #28793 - Ms2ger:AttrStyle, r=alexcrichton
This commit is contained in:
commit
a004ff5caf
@ -1119,7 +1119,7 @@ fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> {
|
||||
codemap::Spanned {
|
||||
node: ast::Attribute_ {
|
||||
id: attr::mk_attr_id(),
|
||||
style: ast::AttrOuter,
|
||||
style: ast::AttrStyle::Outer,
|
||||
value: meta_item,
|
||||
is_sugared_doc: is_sugared_doc,
|
||||
},
|
||||
|
@ -180,7 +180,7 @@ pub fn mk_attr_id() -> AttrId {
|
||||
pub fn mk_attr_inner(id: AttrId, item: P<MetaItem>) -> Attribute {
|
||||
dummy_spanned(Attribute_ {
|
||||
id: id,
|
||||
style: hir::AttrInner,
|
||||
style: hir::AttrStyle::Inner,
|
||||
value: item,
|
||||
is_sugared_doc: false,
|
||||
})
|
||||
@ -190,7 +190,7 @@ pub fn mk_attr_inner(id: AttrId, item: P<MetaItem>) -> Attribute {
|
||||
pub fn mk_attr_outer(id: AttrId, item: P<MetaItem>) -> Attribute {
|
||||
dummy_spanned(Attribute_ {
|
||||
id: id,
|
||||
style: hir::AttrOuter,
|
||||
style: hir::AttrStyle::Outer,
|
||||
value: item,
|
||||
is_sugared_doc: false,
|
||||
})
|
||||
|
@ -285,10 +285,10 @@ impl LateLintPass for UnusedAttributes {
|
||||
}).is_some();
|
||||
if known_crate || plugin_crate {
|
||||
let msg = match attr.node.style {
|
||||
ast::AttrOuter => "crate-level attribute should be an inner \
|
||||
attribute: add an exclamation mark: #![foo]",
|
||||
ast::AttrInner => "crate-level attribute should be in the \
|
||||
root module",
|
||||
ast::AttrStyle::Outer => "crate-level attribute should be an inner \
|
||||
attribute: add an exclamation mark: #![foo]",
|
||||
ast::AttrStyle::Inner => "crate-level attribute should be in the \
|
||||
root module",
|
||||
};
|
||||
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, msg);
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
// The Rust abstract syntax tree.
|
||||
|
||||
pub use self::AttrStyle::*;
|
||||
pub use self::BindingMode::*;
|
||||
pub use self::BinOp_::*;
|
||||
pub use self::BlockCheckMode::*;
|
||||
@ -1019,8 +1018,8 @@ impl TokenTree {
|
||||
match *self {
|
||||
TtToken(_, token::DocComment(name)) => {
|
||||
match doc_comment_style(&name.as_str()) {
|
||||
AttrOuter => 2,
|
||||
AttrInner => 3
|
||||
AttrStyle::Outer => 2,
|
||||
AttrStyle::Inner => 3
|
||||
}
|
||||
}
|
||||
TtToken(_, token::SpecialVarNt(..)) => 2,
|
||||
@ -1041,7 +1040,7 @@ impl TokenTree {
|
||||
TtToken(sp, token::Pound)
|
||||
}
|
||||
(&TtToken(sp, token::DocComment(name)), 1)
|
||||
if doc_comment_style(&name.as_str()) == AttrInner => {
|
||||
if doc_comment_style(&name.as_str()) == AttrStyle::Inner => {
|
||||
TtToken(sp, token::Not)
|
||||
}
|
||||
(&TtToken(sp, token::DocComment(name)), _) => {
|
||||
@ -1658,8 +1657,8 @@ pub type Attribute = Spanned<Attribute_>;
|
||||
/// distinguished for pretty-printing.
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
pub enum AttrStyle {
|
||||
AttrOuter,
|
||||
AttrInner,
|
||||
Outer,
|
||||
Inner,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
|
@ -156,7 +156,7 @@ impl AttributeMethods for Attribute {
|
||||
InternedString::new("doc"),
|
||||
token::intern_and_get_ident(&strip_doc_comment_decoration(
|
||||
&comment)));
|
||||
if self.node.style == ast::AttrOuter {
|
||||
if self.node.style == ast::AttrStyle::Outer {
|
||||
f(&mk_attr_outer(self.node.id, meta))
|
||||
} else {
|
||||
f(&mk_attr_inner(self.node.id, meta))
|
||||
@ -203,7 +203,7 @@ pub fn mk_attr_id() -> AttrId {
|
||||
pub fn mk_attr_inner(id: AttrId, item: P<MetaItem>) -> Attribute {
|
||||
dummy_spanned(Attribute_ {
|
||||
id: id,
|
||||
style: ast::AttrInner,
|
||||
style: ast::AttrStyle::Inner,
|
||||
value: item,
|
||||
is_sugared_doc: false,
|
||||
})
|
||||
@ -213,7 +213,7 @@ pub fn mk_attr_inner(id: AttrId, item: P<MetaItem>) -> Attribute {
|
||||
pub fn mk_attr_outer(id: AttrId, item: P<MetaItem>) -> Attribute {
|
||||
dummy_spanned(Attribute_ {
|
||||
id: id,
|
||||
style: ast::AttrOuter,
|
||||
style: ast::AttrStyle::Outer,
|
||||
value: item,
|
||||
is_sugared_doc: false,
|
||||
})
|
||||
|
@ -1079,7 +1079,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||
fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute {
|
||||
respan(sp, ast::Attribute_ {
|
||||
id: attr::mk_attr_id(),
|
||||
style: ast::AttrOuter,
|
||||
style: ast::AttrStyle::Outer,
|
||||
value: mi,
|
||||
is_sugared_doc: false,
|
||||
})
|
||||
|
@ -660,7 +660,7 @@ fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool
|
||||
if attr.check_name("macro_escape") {
|
||||
fld.cx.span_warn(attr.span, "macro_escape is a deprecated synonym for macro_use");
|
||||
is_use = true;
|
||||
if let ast::AttrInner = attr.node.style {
|
||||
if let ast::AttrStyle::Inner = attr.node.style {
|
||||
fld.cx.fileline_help(attr.span, "consider an outer attribute, \
|
||||
#[macro_use] mod ...");
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ pub mod rt {
|
||||
let mut r = vec![];
|
||||
// FIXME: The spans could be better
|
||||
r.push(ast::TtToken(self.span, token::Pound));
|
||||
if self.node.style == ast::AttrInner {
|
||||
if self.node.style == ast::AttrStyle::Inner {
|
||||
r.push(ast::TtToken(self.span, token::Not));
|
||||
}
|
||||
r.push(ast::TtDelimited(self.span, Rc::new(ast::Delimited {
|
||||
|
@ -44,7 +44,7 @@ impl<'a> ParserAttr for Parser<'a> {
|
||||
self.span.lo,
|
||||
self.span.hi
|
||||
);
|
||||
if attr.node.style != ast::AttrOuter {
|
||||
if attr.node.style != ast::AttrStyle::Outer {
|
||||
panic!(self.fatal("expected outer comment"));
|
||||
}
|
||||
attrs.push(attr);
|
||||
@ -79,9 +79,9 @@ impl<'a> ParserAttr for Parser<'a> {
|
||||
self.fileline_help(span,
|
||||
"place inner attribute at the top of the module or block");
|
||||
}
|
||||
ast::AttrInner
|
||||
ast::AttrStyle::Inner
|
||||
} else {
|
||||
ast::AttrOuter
|
||||
ast::AttrStyle::Outer
|
||||
};
|
||||
|
||||
panictry!(self.expect(&token::OpenDelim(token::Bracket)));
|
||||
@ -101,7 +101,7 @@ impl<'a> ParserAttr for Parser<'a> {
|
||||
panictry!(self.bump());
|
||||
self.span_warn(span, "this inner attribute syntax is deprecated. \
|
||||
The new syntax is `#![foo]`, with a bang and no semicolon");
|
||||
style = ast::AttrInner;
|
||||
style = ast::AttrStyle::Inner;
|
||||
}
|
||||
|
||||
return Spanned {
|
||||
@ -131,7 +131,7 @@ impl<'a> ParserAttr for Parser<'a> {
|
||||
}
|
||||
|
||||
let attr = self.parse_attribute(true);
|
||||
assert!(attr.node.style == ast::AttrInner);
|
||||
assert!(attr.node.style == ast::AttrStyle::Inner);
|
||||
attrs.push(attr);
|
||||
}
|
||||
token::DocComment(s) => {
|
||||
@ -139,7 +139,7 @@ impl<'a> ParserAttr for Parser<'a> {
|
||||
let Span { lo, hi, .. } = self.span;
|
||||
let str = self.id_to_interned_str(ast::Ident::with_empty_ctxt(s));
|
||||
let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), str, lo, hi);
|
||||
if attr.node.style == ast::AttrInner {
|
||||
if attr.node.style == ast::AttrStyle::Inner {
|
||||
attrs.push(attr);
|
||||
panictry!(self.bump());
|
||||
} else {
|
||||
|
@ -52,9 +52,9 @@ pub fn is_doc_comment(s: &str) -> bool {
|
||||
pub fn doc_comment_style(comment: &str) -> ast::AttrStyle {
|
||||
assert!(is_doc_comment(comment));
|
||||
if comment.starts_with("//!") || comment.starts_with("/*!") {
|
||||
ast::AttrInner
|
||||
ast::AttrStyle::Inner
|
||||
} else {
|
||||
ast::AttrOuter
|
||||
ast::AttrStyle::Outer
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -709,7 +709,7 @@ pub trait PrintState<'a> {
|
||||
let mut count = 0;
|
||||
for attr in attrs {
|
||||
match attr.node.style {
|
||||
ast::AttrInner => {
|
||||
ast::AttrStyle::Inner => {
|
||||
try!(self.print_attribute(attr));
|
||||
count += 1;
|
||||
}
|
||||
@ -727,7 +727,7 @@ pub trait PrintState<'a> {
|
||||
let mut count = 0;
|
||||
for attr in attrs {
|
||||
match attr.node.style {
|
||||
ast::AttrOuter => {
|
||||
ast::AttrStyle::Outer => {
|
||||
try!(self.print_attribute(attr));
|
||||
count += 1;
|
||||
}
|
||||
@ -747,8 +747,8 @@ pub trait PrintState<'a> {
|
||||
word(self.writer(), &attr.value_str().unwrap())
|
||||
} else {
|
||||
match attr.node.style {
|
||||
ast::AttrInner => try!(word(self.writer(), "#![")),
|
||||
ast::AttrOuter => try!(word(self.writer(), "#[")),
|
||||
ast::AttrStyle::Inner => try!(word(self.writer(), "#![")),
|
||||
ast::AttrStyle::Outer => try!(word(self.writer(), "#[")),
|
||||
}
|
||||
try!(self.print_meta_item(&*attr.meta()));
|
||||
word(self.writer(), "]")
|
||||
|
@ -154,7 +154,7 @@ impl fold::Folder for PreludeInjector {
|
||||
span: self.span,
|
||||
node: ast::Attribute_ {
|
||||
id: attr::mk_attr_id(),
|
||||
style: ast::AttrOuter,
|
||||
style: ast::AttrStyle::Outer,
|
||||
value: P(ast::MetaItem {
|
||||
span: self.span,
|
||||
node: ast::MetaWord(special_idents::prelude_import.name.as_str()),
|
||||
|
Loading…
x
Reference in New Issue
Block a user