Skip to content

Commit f177a00

Browse files
committed
Refactor P<ast::MetaItem> -> ast::MetaItem.
1 parent e97686d commit f177a00

File tree

14 files changed

+54
-58
lines changed

14 files changed

+54
-58
lines changed

src/librustc/middle/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub enum NativeLibraryKind {
9393
pub struct NativeLibrary {
9494
pub kind: NativeLibraryKind,
9595
pub name: String,
96-
pub cfg: Option<P<ast::MetaItem>>,
96+
pub cfg: Option<ast::MetaItem>,
9797
}
9898

9999
/// The data we save and restore about an inlined item or method. This is not

src/librustc_borrowck/borrowck/mir/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use borrowck::BorrowckCtxt;
1212

1313
use syntax::ast::{self, MetaItem};
14-
use syntax::ptr::P;
1514
use syntax_pos::{Span, DUMMY_SP};
1615

1716
use rustc::hir;
@@ -35,7 +34,7 @@ use self::dataflow::{MaybeInitializedLvals, MaybeUninitializedLvals};
3534
use self::dataflow::{DefinitelyInitializedLvals};
3635
use self::gather_moves::{MoveData, MovePathIndex, LookupResult};
3736

38-
fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<P<MetaItem>> {
37+
fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<MetaItem> {
3938
for attr in attrs {
4039
if attr.check_name("rustc_mir") {
4140
let items = attr.meta_item_list();

src/librustc_incremental/calculate_svh/svh_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
919919
if !attr.is_sugared_doc &&
920920
!IGNORED_ATTRIBUTES.contains(&&*attr.value.name().as_str()) {
921921
SawAttribute(attr.style).hash(self.st);
922-
self.hash_meta_item(&*attr.value);
922+
self.hash_meta_item(&attr.value);
923923
}
924924
}
925925
}

src/libsyntax/ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ pub type NestedMetaItem = Spanned<NestedMetaItemKind>;
505505
#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Debug, PartialEq)]
506506
pub enum NestedMetaItemKind {
507507
/// A full MetaItem, for recursive meta items.
508-
MetaItem(P<MetaItem>),
508+
MetaItem(MetaItem),
509509
/// A literal.
510510
///
511511
/// E.g. "foo", 64, true
@@ -1758,7 +1758,7 @@ pub struct AttrId(pub usize);
17581758
pub struct Attribute {
17591759
pub id: AttrId,
17601760
pub style: AttrStyle,
1761-
pub value: P<MetaItem>,
1761+
pub value: MetaItem,
17621762
pub is_sugared_doc: bool,
17631763
pub span: Span,
17641764
}

src/libsyntax/attr.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn is_known(attr: &Attribute) -> bool {
107107

108108
impl NestedMetaItem {
109109
/// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
110-
pub fn meta_item(&self) -> Option<&P<MetaItem>> {
110+
pub fn meta_item(&self) -> Option<&MetaItem> {
111111
match self.node {
112112
NestedMetaItemKind::MetaItem(ref item) => Some(&item),
113113
_ => None
@@ -145,7 +145,7 @@ impl NestedMetaItem {
145145
}
146146

147147
/// Returns a MetaItem if self is a MetaItem with Kind Word.
148-
pub fn word(&self) -> Option<&P<MetaItem>> {
148+
pub fn word(&self) -> Option<&MetaItem> {
149149
self.meta_item().and_then(|meta_item| if meta_item.is_word() {
150150
Some(meta_item)
151151
} else {
@@ -294,37 +294,37 @@ impl Attribute {
294294

295295
/* Constructors */
296296

297-
pub fn mk_name_value_item_str(name: Name, value: InternedString) -> P<MetaItem> {
297+
pub fn mk_name_value_item_str(name: Name, value: InternedString) -> MetaItem {
298298
let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::StrStyle::Cooked));
299299
mk_spanned_name_value_item(DUMMY_SP, name, value_lit)
300300
}
301301

302-
pub fn mk_name_value_item(name: Name, value: ast::Lit) -> P<MetaItem> {
302+
pub fn mk_name_value_item(name: Name, value: ast::Lit) -> MetaItem {
303303
mk_spanned_name_value_item(DUMMY_SP, name, value)
304304
}
305305

306-
pub fn mk_list_item(name: Name, items: Vec<NestedMetaItem>) -> P<MetaItem> {
306+
pub fn mk_list_item(name: Name, items: Vec<NestedMetaItem>) -> MetaItem {
307307
mk_spanned_list_item(DUMMY_SP, name, items)
308308
}
309309

310310
pub fn mk_list_word_item(name: Name) -> ast::NestedMetaItem {
311311
dummy_spanned(NestedMetaItemKind::MetaItem(mk_spanned_word_item(DUMMY_SP, name)))
312312
}
313313

314-
pub fn mk_word_item(name: Name) -> P<MetaItem> {
314+
pub fn mk_word_item(name: Name) -> MetaItem {
315315
mk_spanned_word_item(DUMMY_SP, name)
316316
}
317317

318-
pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> P<MetaItem> {
319-
P(MetaItem { span: sp, name: name, node: MetaItemKind::NameValue(value) })
318+
pub fn mk_spanned_name_value_item(sp: Span, name: Name, value: ast::Lit) -> MetaItem {
319+
MetaItem { span: sp, name: name, node: MetaItemKind::NameValue(value) }
320320
}
321321

322-
pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec<NestedMetaItem>) -> P<MetaItem> {
323-
P(MetaItem { span: sp, name: name, node: MetaItemKind::List(items) })
322+
pub fn mk_spanned_list_item(sp: Span, name: Name, items: Vec<NestedMetaItem>) -> MetaItem {
323+
MetaItem { span: sp, name: name, node: MetaItemKind::List(items) }
324324
}
325325

326-
pub fn mk_spanned_word_item(sp: Span, name: Name) -> P<MetaItem> {
327-
P(MetaItem { span: sp, name: name, node: MetaItemKind::Word })
326+
pub fn mk_spanned_word_item(sp: Span, name: Name) -> MetaItem {
327+
MetaItem { span: sp, name: name, node: MetaItemKind::Word }
328328
}
329329

330330

@@ -341,12 +341,12 @@ pub fn mk_attr_id() -> AttrId {
341341
}
342342

343343
/// Returns an inner attribute with the given value.
344-
pub fn mk_attr_inner(id: AttrId, item: P<MetaItem>) -> Attribute {
344+
pub fn mk_attr_inner(id: AttrId, item: MetaItem) -> Attribute {
345345
mk_spanned_attr_inner(DUMMY_SP, id, item)
346346
}
347347

348348
/// Returns an innter attribute with the given value and span.
349-
pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: P<MetaItem>) -> Attribute {
349+
pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: MetaItem) -> Attribute {
350350
Attribute {
351351
id: id,
352352
style: ast::AttrStyle::Inner,
@@ -358,12 +358,12 @@ pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: P<MetaItem>) -> Attribu
358358

359359

360360
/// Returns an outer attribute with the given value.
361-
pub fn mk_attr_outer(id: AttrId, item: P<MetaItem>) -> Attribute {
361+
pub fn mk_attr_outer(id: AttrId, item: MetaItem) -> Attribute {
362362
mk_spanned_attr_outer(DUMMY_SP, id, item)
363363
}
364364

365365
/// Returns an outer attribute with the given value and span.
366-
pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: P<MetaItem>) -> Attribute {
366+
pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: MetaItem) -> Attribute {
367367
Attribute {
368368
id: id,
369369
style: ast::AttrStyle::Outer,
@@ -373,7 +373,7 @@ pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: P<MetaItem>) -> Attribu
373373
}
374374
}
375375

376-
pub fn mk_doc_attr_outer(id: AttrId, item: P<MetaItem>, is_sugared_doc: bool) -> Attribute {
376+
pub fn mk_doc_attr_outer(id: AttrId, item: MetaItem, is_sugared_doc: bool) -> Attribute {
377377
Attribute {
378378
id: id,
379379
style: ast::AttrStyle::Outer,
@@ -390,11 +390,11 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: By
390390
Attribute {
391391
id: id,
392392
style: style,
393-
value: P(MetaItem {
393+
value: MetaItem {
394394
span: mk_sp(lo, hi),
395395
name: token::intern("doc"),
396396
node: MetaItemKind::NameValue(lit),
397-
}),
397+
},
398398
is_sugared_doc: true,
399399
span: mk_sp(lo, hi),
400400
}
@@ -423,8 +423,7 @@ pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str)
423423
.and_then(|at| at.value_str())
424424
}
425425

426-
pub fn last_meta_item_value_str_by_name(items: &[P<MetaItem>], name: &str)
427-
-> Option<InternedString> {
426+
pub fn last_meta_item_value_str_by_name(items: &[MetaItem], name: &str) -> Option<InternedString> {
428427
items.iter()
429428
.rev()
430429
.find(|mi| mi.check_name(name))
@@ -859,7 +858,7 @@ pub fn find_deprecation(diagnostic: &Handler, attrs: &[Attribute],
859858
find_deprecation_generic(diagnostic, attrs.iter(), item_sp)
860859
}
861860

862-
pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
861+
pub fn require_unique_names(diagnostic: &Handler, metas: &[MetaItem]) {
863862
let mut set = HashSet::new();
864863
for meta in metas {
865864
let name = meta.name();

src/libsyntax/ext/build.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,22 @@ pub trait AstBuilder {
275275
generics: Generics) -> P<ast::Item>;
276276
fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> P<ast::Item>;
277277

278-
fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute;
278+
fn attribute(&self, sp: Span, mi: ast::MetaItem) -> ast::Attribute;
279279

280-
fn meta_word(&self, sp: Span, w: ast::Name) -> P<ast::MetaItem>;
280+
fn meta_word(&self, sp: Span, w: ast::Name) -> ast::MetaItem;
281281

282282
fn meta_list_item_word(&self, sp: Span, w: ast::Name) -> ast::NestedMetaItem;
283283

284284
fn meta_list(&self,
285285
sp: Span,
286286
name: ast::Name,
287287
mis: Vec<ast::NestedMetaItem> )
288-
-> P<ast::MetaItem>;
288+
-> ast::MetaItem;
289289
fn meta_name_value(&self,
290290
sp: Span,
291291
name: ast::Name,
292292
value: ast::LitKind)
293-
-> P<ast::MetaItem>;
293+
-> ast::MetaItem;
294294

295295
fn item_use(&self, sp: Span,
296296
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item>;
@@ -1146,11 +1146,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
11461146
self.item_ty_poly(span, name, ty, Generics::default())
11471147
}
11481148

1149-
fn attribute(&self, sp: Span, mi: P<ast::MetaItem>) -> ast::Attribute {
1149+
fn attribute(&self, sp: Span, mi: ast::MetaItem) -> ast::Attribute {
11501150
attr::mk_spanned_attr_outer(sp, attr::mk_attr_id(), mi)
11511151
}
11521152

1153-
fn meta_word(&self, sp: Span, w: ast::Name) -> P<ast::MetaItem> {
1153+
fn meta_word(&self, sp: Span, w: ast::Name) -> ast::MetaItem {
11541154
attr::mk_spanned_word_item(sp, w)
11551155
}
11561156

@@ -1159,12 +1159,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
11591159
}
11601160

11611161
fn meta_list(&self, sp: Span, name: ast::Name, mis: Vec<ast::NestedMetaItem>)
1162-
-> P<ast::MetaItem> {
1162+
-> ast::MetaItem {
11631163
attr::mk_spanned_list_item(sp, name, mis)
11641164
}
11651165

11661166
fn meta_name_value(&self, sp: Span, name: ast::Name, value: ast::LitKind)
1167-
-> P<ast::MetaItem> {
1167+
-> ast::MetaItem {
11681168
attr::mk_spanned_name_value_item(sp, name, respan(sp, value))
11691169
}
11701170

src/libsyntax/ext/quote.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub mod rt {
211211
impl_to_tokens_slice! { P<ast::Item>, [] }
212212
impl_to_tokens_slice! { ast::Arg, [TokenTree::Token(DUMMY_SP, token::Comma)] }
213213

214-
impl ToTokens for P<ast::MetaItem> {
214+
impl ToTokens for ast::MetaItem {
215215
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
216216
let nt = token::NtMeta(self.clone());
217217
vec![TokenTree::Token(DUMMY_SP, token::Interpolated(Rc::new(nt)))]
@@ -405,7 +405,7 @@ pub fn parse_block_panic(parser: &mut Parser) -> P<Block> {
405405
panictry!(parser.parse_block())
406406
}
407407

408-
pub fn parse_meta_item_panic(parser: &mut Parser) -> P<ast::MetaItem> {
408+
pub fn parse_meta_item_panic(parser: &mut Parser) -> ast::MetaItem {
409409
panictry!(parser.parse_meta_item())
410410
}
411411

src/libsyntax/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ fn contains_novel_literal(item: &ast::MetaItem) -> bool {
995995
NameValue(ref lit) => !lit.node.is_str(),
996996
List(ref list) => list.iter().any(|li| {
997997
match li.node {
998-
MetaItem(ref mi) => contains_novel_literal(&**mi),
998+
MetaItem(ref mi) => contains_novel_literal(&mi),
999999
Literal(_) => true,
10001000
}
10011001
}),
@@ -1013,7 +1013,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
10131013
self.context.check_attribute(attr, false);
10141014
}
10151015

1016-
if contains_novel_literal(&*(attr.value)) {
1016+
if contains_novel_literal(&attr.value) {
10171017
gate_feature_post!(&self, attr_literals, attr.span,
10181018
"non-string literals in attributes, or string \
10191019
literals in top-level positions, are experimental");

src/libsyntax/fold.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ pub trait Folder : Sized {
4343
noop_fold_crate(c, self)
4444
}
4545

46-
fn fold_meta_items(&mut self, meta_items: Vec<P<MetaItem>>) -> Vec<P<MetaItem>> {
46+
fn fold_meta_items(&mut self, meta_items: Vec<MetaItem>) -> Vec<MetaItem> {
4747
noop_fold_meta_items(meta_items, self)
4848
}
4949

5050
fn fold_meta_list_item(&mut self, list_item: NestedMetaItem) -> NestedMetaItem {
5151
noop_fold_meta_list_item(list_item, self)
5252
}
5353

54-
fn fold_meta_item(&mut self, meta_item: P<MetaItem>) -> P<MetaItem> {
54+
fn fold_meta_item(&mut self, meta_item: MetaItem) -> MetaItem {
5555
noop_fold_meta_item(meta_item, self)
5656
}
5757

@@ -293,8 +293,7 @@ pub trait Folder : Sized {
293293
}
294294
}
295295

296-
pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>, fld: &mut T)
297-
-> Vec<P<MetaItem>> {
296+
pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<MetaItem>, fld: &mut T) -> Vec<MetaItem> {
298297
meta_items.move_map(|x| fld.fold_meta_item(x))
299298
}
300299

@@ -519,18 +518,18 @@ pub fn noop_fold_meta_list_item<T: Folder>(li: NestedMetaItem, fld: &mut T)
519518
}
520519
}
521520

522-
pub fn noop_fold_meta_item<T: Folder>(mi: P<MetaItem>, fld: &mut T) -> P<MetaItem> {
523-
mi.map(|MetaItem { name, node, span }| MetaItem {
524-
name: name,
525-
node: match node {
521+
pub fn noop_fold_meta_item<T: Folder>(mi: MetaItem, fld: &mut T) -> MetaItem {
522+
MetaItem {
523+
name: mi.name,
524+
node: match mi.node {
526525
MetaItemKind::Word => MetaItemKind::Word,
527526
MetaItemKind::List(mis) => {
528527
MetaItemKind::List(mis.move_map(|e| fld.fold_meta_list_item(e)))
529528
},
530529
MetaItemKind::NameValue(s) => MetaItemKind::NameValue(s),
531530
},
532-
span: fld.new_span(span)
533-
})
531+
span: fld.new_span(mi.span)
532+
}
534533
}
535534

536535
pub fn noop_fold_arg<T: Folder>(Arg {id, pat, ty}: Arg, fld: &mut T) -> Arg {

src/libsyntax/parse/attr.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use parse::common::SeqSep;
1616
use parse::PResult;
1717
use parse::token;
1818
use parse::parser::{Parser, TokenType};
19-
use ptr::P;
2019

2120
#[derive(PartialEq, Eq, Debug)]
2221
enum InnerAttributeParsePolicy<'a> {
@@ -211,7 +210,7 @@ impl<'a> Parser<'a> {
211210
///
212211
/// meta_item : IDENT ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ;
213212
/// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
214-
pub fn parse_meta_item(&mut self) -> PResult<'a, P<ast::MetaItem>> {
213+
pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> {
215214
let nt_meta = match self.token {
216215
token::Interpolated(ref nt) => match **nt {
217216
token::NtMeta(ref e) => Some(e.clone()),
@@ -235,7 +234,7 @@ impl<'a> Parser<'a> {
235234
ast::MetaItemKind::Word
236235
};
237236
let hi = self.prev_span.hi;
238-
Ok(P(ast::MetaItem { name: ident.name, node: node, span: mk_sp(lo, hi) }))
237+
Ok(ast::MetaItem { name: ident.name, node: node, span: mk_sp(lo, hi) })
239238
}
240239

241240
/// matches meta_item_inner : (meta_item | UNSUFFIXED_LIT) ;

src/libsyntax/parse/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn parse_item_from_source_str<'a>(name: String, source: String, sess: &'a Pa
117117
}
118118

119119
pub fn parse_meta_from_source_str<'a>(name: String, source: String, sess: &'a ParseSess)
120-
-> PResult<'a, P<ast::MetaItem>> {
120+
-> PResult<'a, ast::MetaItem> {
121121
new_parser_from_source_str(sess, name, source).parse_meta_item()
122122
}
123123

src/libsyntax/parse/token.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pub enum Nonterminal {
301301
NtTy(P<ast::Ty>),
302302
NtIdent(ast::SpannedIdent),
303303
/// Stuff inside brackets for attributes
304-
NtMeta(P<ast::MetaItem>),
304+
NtMeta(ast::MetaItem),
305305
NtPath(ast::Path),
306306
NtTT(tokenstream::TokenTree),
307307
// These are not exposed to macros, but are used by quasiquote.

src/libsyntax/std_inject.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess,
6969
krate.module.items.insert(0, P(ast::Item {
7070
attrs: vec![ast::Attribute {
7171
style: ast::AttrStyle::Outer,
72-
value: P(ast::MetaItem {
72+
value: ast::MetaItem {
7373
name: token::intern("prelude_import"),
7474
node: ast::MetaItemKind::Word,
7575
span: span,
76-
}),
76+
},
7777
id: attr::mk_attr_id(),
7878
is_sugared_doc: false,
7979
span: span,

0 commit comments

Comments
 (0)