Skip to content

Commit e9f1b06

Browse files
committed
Use ast attributes every where (remove HIR attributes).
This could be a [breaking-change] if your lint or syntax extension (is that even possible?) uses HIR attributes or literals.
1 parent d2e13e8 commit e9f1b06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1072
-2563
lines changed

src/librustc/front/map/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use metadata::inline::InlinedItem as II;
1717
use middle::def_id::DefId;
1818

1919
use syntax::abi;
20-
use syntax::ast::{Name, NodeId, Ident, CRATE_NODE_ID, DUMMY_NODE_ID};
20+
use syntax::ast::{self, Name, NodeId, Ident, CRATE_NODE_ID, DUMMY_NODE_ID};
2121
use syntax::codemap::{Span, Spanned};
2222
use syntax::parse::token;
2323

@@ -538,7 +538,7 @@ impl<'ast> Map<'ast> {
538538

539539
/// Given a node ID, get a list of of attributes associated with the AST
540540
/// corresponding to the Node ID
541-
pub fn attrs(&self, id: NodeId) -> &'ast [Attribute] {
541+
pub fn attrs(&self, id: NodeId) -> &'ast [ast::Attribute] {
542542
let attrs = match self.find(id) {
543543
Some(NodeItem(i)) => Some(&i.attrs[..]),
544544
Some(NodeForeignItem(fi)) => Some(&fi.attrs[..]),

src/librustc/lint/context.rs

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ use std::cell::RefCell;
3737
use std::cmp;
3838
use std::mem;
3939
use syntax::ast_util::IdVisitingOperation;
40-
use rustc_front::attr::{self, AttrMetaMethods};
41-
use rustc_front::util;
40+
use syntax::attr::{self, AttrMetaMethods};
4241
use syntax::codemap::Span;
4342
use syntax::parse::token::InternedString;
4443
use syntax::ast;
4544
use rustc_front::hir;
4645
use rustc_front::visit::{self, Visitor, FnKind};
46+
use rustc_front::util;
4747
use syntax::visit::Visitor as SyntaxVisitor;
4848
use syntax::diagnostic;
4949

@@ -286,7 +286,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $($args:expr),*) => ({
286286
/// Parse the lint attributes into a vector, with `Err`s for malformed lint
287287
/// attributes. Writing this as an iterator is an enormous mess.
288288
// See also the hir version just below.
289-
pub fn gather_attrs(attrs: &[hir::Attribute])
289+
pub fn gather_attrs(attrs: &[ast::Attribute])
290290
-> Vec<Result<(InternedString, Level, Span), Span>> {
291291
let mut out = vec!();
292292
for attr in attrs {
@@ -299,39 +299,7 @@ pub fn gather_attrs(attrs: &[hir::Attribute])
299299

300300
let meta = &attr.node.value;
301301
let metas = match meta.node {
302-
hir::MetaList(_, ref metas) => metas,
303-
_ => {
304-
out.push(Err(meta.span));
305-
continue;
306-
}
307-
};
308-
309-
for meta in metas {
310-
out.push(match meta.node {
311-
hir::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)),
312-
_ => Err(meta.span),
313-
});
314-
}
315-
}
316-
out
317-
}
318-
// Copy-pasted from the above function :-(
319-
pub fn gather_attrs_from_hir(attrs: &[::rustc_front::hir::Attribute])
320-
-> Vec<Result<(InternedString, Level, Span), Span>> {
321-
use ::rustc_front::attr::AttrMetaMethods;
322-
323-
let mut out = vec!();
324-
for attr in attrs {
325-
let level = match Level::from_str(&attr.name()) {
326-
None => continue,
327-
Some(lvl) => lvl,
328-
};
329-
330-
::rustc_front::attr::mark_used(attr);
331-
332-
let meta = &attr.node.value;
333-
let metas = match meta.node {
334-
::rustc_front::hir::MetaList(_, ref metas) => metas,
302+
ast::MetaList(_, ref metas) => metas,
335303
_ => {
336304
out.push(Err(meta.span));
337305
continue;
@@ -340,9 +308,7 @@ pub fn gather_attrs_from_hir(attrs: &[::rustc_front::hir::Attribute])
340308

341309
for meta in metas {
342310
out.push(match meta.node {
343-
::rustc_front::hir::MetaWord(ref lint_name) => {
344-
Ok((lint_name.clone(), level, meta.span))
345-
}
311+
ast::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)),
346312
_ => Err(meta.span),
347313
});
348314
}
@@ -454,7 +420,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
454420
/// current lint context, call the provided function, then reset the
455421
/// lints in effect to their previous state.
456422
fn with_lint_attrs<F>(&mut self,
457-
attrs: &[hir::Attribute],
423+
attrs: &[ast::Attribute],
458424
f: F) where
459425
F: FnOnce(&mut Context),
460426
{
@@ -675,7 +641,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
675641
visit::walk_path(self, p);
676642
}
677643

678-
fn visit_attribute(&mut self, attr: &hir::Attribute) {
644+
fn visit_attribute(&mut self, attr: &ast::Attribute) {
679645
run_lints!(self, check_attribute, attr);
680646
}
681647
}

src/librustc/lint/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use syntax::ast;
3939
use rustc_front::hir;
4040

4141
pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate, gather_attrs,
42-
gather_attrs_from_hir, GatherNodeLevels};
42+
GatherNodeLevels};
4343

4444
/// Specification of a single lint.
4545
#[derive(Copy, Clone, Debug)]
@@ -158,14 +158,14 @@ pub trait LintPass {
158158
fn check_explicit_self(&mut self, _: &Context, _: &hir::ExplicitSelf) { }
159159
fn check_mac(&mut self, _: &Context, _: &ast::Mac) { }
160160
fn check_path(&mut self, _: &Context, _: &hir::Path, _: ast::NodeId) { }
161-
fn check_attribute(&mut self, _: &Context, _: &hir::Attribute) { }
161+
fn check_attribute(&mut self, _: &Context, _: &ast::Attribute) { }
162162

163163
/// Called when entering a syntax node that can have lint attributes such
164164
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
165-
fn enter_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) { }
165+
fn enter_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { }
166166

167167
/// Counterpart to `enter_lint_attrs`.
168-
fn exit_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) { }
168+
fn exit_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { }
169169
}
170170

171171
/// A lint pass boxed up as a trait object.

src/librustc/metadata/creader.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ use syntax::abi;
3333
use syntax::codemap::{self, Span, mk_sp, Pos};
3434
use syntax::parse;
3535
use syntax::attr;
36+
use syntax::attr::AttrMetaMethods;
3637
use syntax::parse::token::InternedString;
3738
use syntax::util::small_vector::SmallVector;
3839
use rustc_front::visit;
3940
use rustc_front::hir;
40-
use rustc_front::attr as attr_front;
41-
use rustc_front::attr::AttrMetaMethods;
42-
use rustc_front::lowering::unlower_attribute;
4341
use log;
4442

4543
pub struct LocalCrateReader<'a, 'b:'a> {
@@ -79,10 +77,9 @@ fn dump_crates(cstore: &CStore) {
7977
fn should_link(i: &ast::Item) -> bool {
8078
!attr::contains_name(&i.attrs, "no_link")
8179
}
82-
8380
// Dup for the hir
8481
fn should_link_hir(i: &hir::Item) -> bool {
85-
!attr_front::contains_name(&i.attrs, "no_link")
82+
!attr::contains_name(&i.attrs, "no_link")
8683
}
8784

8885
struct CrateInfo {
@@ -329,7 +326,7 @@ impl<'a> CrateReader<'a> {
329326
let attrs = decoder::get_crate_attributes(data);
330327
for attr in &attrs {
331328
if &attr.name()[..] == "staged_api" {
332-
match attr.node.value.node { hir::MetaWord(_) => return true, _ => (/*pass*/) }
329+
match attr.node.value.node { ast::MetaWord(_) => return true, _ => (/*pass*/) }
333330
}
334331
}
335332

@@ -483,7 +480,7 @@ impl<'a> CrateReader<'a> {
483480
p.abort_if_errors();
484481
macros.push(ast::MacroDef {
485482
ident: name.ident(),
486-
attrs: attrs.iter().map(|a| unlower_attribute(a)).collect(),
483+
attrs: attrs,
487484
id: ast::DUMMY_NODE_ID,
488485
span: span,
489486
imported_from: Some(item.ident),

src/librustc/metadata/csearch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use util::nodemap::FnvHashMap;
2121

2222
use std::rc::Rc;
2323
use syntax::ast;
24-
use rustc_front::attr;
24+
use syntax::attr;
2525
use rustc_front::hir;
2626

2727
#[derive(Copy, Clone)]
@@ -186,7 +186,7 @@ pub fn get_methods_if_impl(cstore: &cstore::CStore,
186186

187187
pub fn get_item_attrs(cstore: &cstore::CStore,
188188
def_id: DefId)
189-
-> Vec<hir::Attribute> {
189+
-> Vec<ast::Attribute> {
190190
let cdata = cstore.get_crate_data(def_id.krate);
191191
decoder::get_item_attrs(&*cdata, def_id.node)
192192
}
@@ -197,7 +197,7 @@ pub fn get_struct_field_names(cstore: &cstore::CStore, def: DefId) -> Vec<ast::N
197197
}
198198

199199
pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: DefId) -> FnvHashMap<ast::NodeId,
200-
Vec<hir::Attribute>> {
200+
Vec<ast::Attribute>> {
201201
let cdata = cstore.get_crate_data(def.krate);
202202
decoder::get_struct_field_attrs(&*cdata)
203203
}

src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::rc::Rc;
2727
use std::path::PathBuf;
2828
use flate::Bytes;
2929
use syntax::ast;
30-
use rustc_front::attr;
30+
use syntax::attr;
3131
use syntax::codemap;
3232
use syntax::parse::token;
3333
use syntax::parse::token::IdentInterner;

src/librustc/metadata/decoder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub use self::DefLike::*;
1616
use self::Family::*;
1717

1818
use front::map as ast_map;
19-
use rustc_front::print::pprust;
2019
use rustc_front::hir;
2120

2221
use back::svh::Svh;
@@ -46,12 +45,13 @@ use std::str;
4645
use rbml::reader;
4746
use rbml;
4847
use serialize::Decodable;
49-
use rustc_front::attr;
48+
use syntax::attr;
5049
use syntax::parse::token::{IdentInterner, special_idents};
5150
use syntax::parse::token;
5251
use syntax::ast;
5352
use syntax::abi;
5453
use syntax::codemap;
54+
use syntax::print::pprust;
5555
use syntax::ptr::P;
5656

5757

@@ -1041,7 +1041,7 @@ pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd,
10411041

10421042
pub fn get_item_attrs(cdata: Cmd,
10431043
orig_node_id: ast::NodeId)
1044-
-> Vec<hir::Attribute> {
1044+
-> Vec<ast::Attribute> {
10451045
// The attributes for a tuple struct are attached to the definition, not the ctor;
10461046
// we assume that someone passing in a tuple struct ctor is actually wanting to
10471047
// look at the definition
@@ -1051,7 +1051,7 @@ pub fn get_item_attrs(cdata: Cmd,
10511051
get_attributes(item)
10521052
}
10531053

1054-
pub fn get_struct_field_attrs(cdata: Cmd) -> FnvHashMap<ast::NodeId, Vec<hir::Attribute>> {
1054+
pub fn get_struct_field_attrs(cdata: Cmd) -> FnvHashMap<ast::NodeId, Vec<ast::Attribute>> {
10551055
let data = rbml::Doc::new(cdata.data());
10561056
let fields = reader::get_doc(data, tag_struct_fields);
10571057
reader::tagged_docs(fields, tag_struct_field).map(|field| {
@@ -1079,7 +1079,7 @@ pub fn get_struct_field_names(intr: &IdentInterner, cdata: Cmd, id: ast::NodeId)
10791079
})).collect()
10801080
}
10811081

1082-
fn get_meta_items(md: rbml::Doc) -> Vec<P<hir::MetaItem>> {
1082+
fn get_meta_items(md: rbml::Doc) -> Vec<P<ast::MetaItem>> {
10831083
reader::tagged_docs(md, tag_meta_item_word).map(|meta_item_doc| {
10841084
let nd = reader::get_doc(meta_item_doc, tag_meta_item_name);
10851085
let n = token::intern_and_get_ident(nd.as_str_slice());
@@ -1100,7 +1100,7 @@ fn get_meta_items(md: rbml::Doc) -> Vec<P<hir::MetaItem>> {
11001100
})).collect()
11011101
}
11021102

1103-
fn get_attributes(md: rbml::Doc) -> Vec<hir::Attribute> {
1103+
fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> {
11041104
match reader::maybe_get_doc(md, tag_attributes) {
11051105
Some(attrs_d) => {
11061106
reader::tagged_docs(attrs_d, tag_attribute).map(|attr_doc| {
@@ -1113,9 +1113,9 @@ fn get_attributes(md: rbml::Doc) -> Vec<hir::Attribute> {
11131113
assert_eq!(meta_items.len(), 1);
11141114
let meta_item = meta_items.into_iter().nth(0).unwrap();
11151115
codemap::Spanned {
1116-
node: hir::Attribute_ {
1116+
node: ast::Attribute_ {
11171117
id: attr::mk_attr_id(),
1118-
style: hir::AttrOuter,
1118+
style: ast::AttrOuter,
11191119
value: meta_item,
11201120
is_sugared_doc: is_sugared_doc,
11211121
},
@@ -1139,7 +1139,7 @@ fn list_crate_attributes(md: rbml::Doc, hash: &Svh,
11391139
write!(out, "\n\n")
11401140
}
11411141

1142-
pub fn get_crate_attributes(data: &[u8]) -> Vec<hir::Attribute> {
1142+
pub fn get_crate_attributes(data: &[u8]) -> Vec<ast::Attribute> {
11431143
get_attributes(rbml::Doc::new(data))
11441144
}
11451145

@@ -1337,7 +1337,7 @@ pub fn get_plugin_registrar_fn(data: &[u8]) -> Option<ast::NodeId> {
13371337
}
13381338

13391339
pub fn each_exported_macro<F>(data: &[u8], intr: &IdentInterner, mut f: F) where
1340-
F: FnMut(ast::Name, Vec<hir::Attribute>, String) -> bool,
1340+
F: FnMut(ast::Name, Vec<ast::Attribute>, String) -> bool,
13411341
{
13421342
let macros = reader::get_doc(rbml::Doc::new(data), tag_macro_defs);
13431343
for macro_doc in reader::tagged_docs(macros, tag_macro_def) {

0 commit comments

Comments
 (0)