Skip to content

Commit

Permalink
Auto merge of #36066 - jseyfried:rollup, r=Manishearth
Browse files Browse the repository at this point in the history
Batch up libsyntax breaking changes

Batch of the following syntax-[breaking-change] changes:
 - #35591: Add a field `span: Span` to `ast::Generics`.
 - #35618: Remove variant `Mod` of `ast::PathListItemKind` and refactor the remaining variant `ast::PathListKind::Ident` to a struct `ast::PathListKind_`.
 - #35480: Change uses of `Constness` in the AST to `Spanned<Constness>`.
  - c.f. `MethodSig`, `ItemKind`
 - #35728: Refactor `cx.pat_enum()` into `cx.pat_tuple_struct()` and `cx.pat_path()`.
 - #35850: Generalize the elements of lists in attributes from `MetaItem` to a new type `NestedMetaItem` that can represent a `MetaItem` or a literal.
 - #35917: Remove traits `AttrMetaMethods`, `AttributeMethods`, and `AttrNestedMetaItemMethods`.
  - Besides removing imports of these traits, this won't cause fallout.
 - Add a variant `Union` to `ItemKind` to future proof for `union` (c.f. #36016).
 - Remove inherent methods `attrs` and `fold_attrs` of `Annotatable`.
  - Use methods `attrs` and `map_attrs` of `HasAttrs` instead.

r? @Manishearth
  • Loading branch information
bors committed Aug 30, 2016
2 parents addb753 + 02f081c commit 71ee82a
Show file tree
Hide file tree
Showing 104 changed files with 1,297 additions and 855 deletions.
18 changes: 11 additions & 7 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use session::Session;

use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax::visit;
use syntax::visit::Visitor;

Expand Down Expand Up @@ -52,18 +51,22 @@ impl<'a> CheckAttrVisitor<'a> {
return;
}
};

for word in words {
let word: &str = &word.name();
let message = match word {
let name = match word.name() {
Some(word) => word,
None => continue,
};

let message = match &*name {
"C" => {
if target != Target::Struct && target != Target::Enum {
"attribute should be applied to struct or enum"
"attribute should be applied to struct or enum"
} else {
continue
}
}
"packed" |
"simd" => {
"packed" | "simd" => {
if target != Target::Struct {
"attribute should be applied to struct"
} else {
Expand All @@ -74,13 +77,14 @@ impl<'a> CheckAttrVisitor<'a> {
"i32" | "u32" | "i64" | "u64" |
"isize" | "usize" => {
if target != Target::Enum {
"attribute should be applied to enum"
"attribute should be applied to enum"
} else {
continue
}
}
_ => continue,
};

span_err!(self.sess, attr.span, E0517, "{}", message);
}
}
Expand Down
40 changes: 26 additions & 14 deletions src/librustc/hir/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//! and returns a piece of the same type.

use hir::*;
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
use syntax::ast::MetaItemKind;
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_};
use syntax::ast::{NestedMetaItem, NestedMetaItemKind, MetaItem, MetaItemKind};
use hir;
use syntax_pos::Span;
use syntax::codemap::{respan, Spanned};
Expand All @@ -38,6 +38,10 @@ pub trait Folder : Sized {
noop_fold_meta_items(meta_items, self)
}

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

fn fold_meta_item(&mut self, meta_item: P<MetaItem>) -> P<MetaItem> {
noop_fold_meta_item(meta_item, self)
}
Expand Down Expand Up @@ -271,16 +275,10 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
ViewPathList(fld.fold_path(path),
path_list_idents.move_map(|path_list_ident| {
Spanned {
node: match path_list_ident.node {
PathListIdent { id, name, rename } => PathListIdent {
id: fld.new_id(id),
name: name,
rename: rename,
},
PathListMod { id, rename } => PathListMod {
id: fld.new_id(id),
rename: rename,
},
node: PathListItem_ {
id: fld.new_id(path_list_ident.node.id),
name: path_list_ident.node.name,
rename: path_list_ident.node.rename,
},
span: fld.new_span(path_list_ident.span),
}
Expand Down Expand Up @@ -486,13 +484,26 @@ pub fn noop_fold_attribute<T: Folder>(at: Attribute, fld: &mut T) -> Option<Attr
})
}

pub fn noop_fold_meta_list_item<T: Folder>(li: NestedMetaItem, fld: &mut T)
-> NestedMetaItem {
Spanned {
node: match li.node {
NestedMetaItemKind::MetaItem(mi) => {
NestedMetaItemKind::MetaItem(fld.fold_meta_item(mi))
},
NestedMetaItemKind::Literal(lit) => NestedMetaItemKind::Literal(lit)
},
span: fld.new_span(li.span)
}
}

pub fn noop_fold_meta_item<T: Folder>(mi: P<MetaItem>, fld: &mut T) -> P<MetaItem> {
mi.map(|Spanned { node, span }| {
Spanned {
node: match node {
MetaItemKind::Word(id) => MetaItemKind::Word(id),
MetaItemKind::List(id, mis) => {
MetaItemKind::List(id, mis.move_map(|e| fld.fold_meta_item(e)))
MetaItemKind::List(id, mis.move_map(|e| fld.fold_meta_list_item(e)))
}
MetaItemKind::NameValue(id, s) => MetaItemKind::NameValue(id, s),
},
Expand Down Expand Up @@ -577,13 +588,14 @@ pub fn noop_fold_opt_lifetime<T: Folder>(o_lt: Option<Lifetime>, fld: &mut T) ->
o_lt.map(|lt| fld.fold_lifetime(lt))
}

pub fn noop_fold_generics<T: Folder>(Generics { ty_params, lifetimes, where_clause }: Generics,
pub fn noop_fold_generics<T: Folder>(Generics {ty_params, lifetimes, where_clause, span}: Generics,
fld: &mut T)
-> Generics {
Generics {
ty_params: fld.fold_ty_params(ty_params),
lifetimes: fld.fold_lifetime_defs(lifetimes),
where_clause: fld.fold_where_clause(where_clause),
span: fld.new_span(span),
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,12 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
}
}

pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V,
_prefix: &'v Path,
item: &'v PathListItem) {
visitor.visit_id(item.node.id());
walk_opt_name(visitor, item.span, item.node.name());
walk_opt_name(visitor, item.span, item.node.rename());
pub fn walk_path_list_item<'v, V>(visitor: &mut V, _prefix: &'v Path, item: &'v PathListItem)
where V: Visitor<'v>,
{
visitor.visit_id(item.node.id);
visitor.visit_name(item.span, item.node.name);
walk_opt_name(visitor, item.span, item.node.rename);
}

pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
Expand Down
20 changes: 8 additions & 12 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,10 @@ impl<'a> LoweringContext<'a> {

fn lower_path_list_item(&mut self, path_list_ident: &PathListItem) -> hir::PathListItem {
Spanned {
node: match path_list_ident.node {
PathListItemKind::Ident { id, name, rename } => hir::PathListIdent {
id: id,
name: name.name,
rename: rename.map(|x| x.name),
},
PathListItemKind::Mod { id, rename } => hir::PathListMod {
id: id,
rename: rename.map(|x| x.name),
},
node: hir::PathListItem_ {
id: path_list_ident.node.id,
name: path_list_ident.node.name.name,
rename: path_list_ident.node.rename.map(|rename| rename.name),
},
span: path_list_ident.span,
}
Expand Down Expand Up @@ -466,6 +460,7 @@ impl<'a> LoweringContext<'a> {
ty_params: self.lower_ty_params(&g.ty_params),
lifetimes: self.lower_lifetime_defs(&g.lifetimes),
where_clause: self.lower_where_clause(&g.where_clause),
span: g.span,
}
}

Expand Down Expand Up @@ -643,6 +638,7 @@ impl<'a> LoweringContext<'a> {
let struct_def = self.lower_variant_data(struct_def);
hir::ItemStruct(struct_def, self.lower_generics(generics))
}
ItemKind::Union(..) => panic!("`union` is not yet implemented"),
ItemKind::DefaultImpl(unsafety, ref trait_ref) => {
hir::ItemDefaultImpl(self.lower_unsafety(unsafety),
self.lower_trait_ref(trait_ref))
Expand Down Expand Up @@ -809,8 +805,8 @@ impl<'a> LoweringContext<'a> {
}
}

fn lower_constness(&mut self, c: Constness) -> hir::Constness {
match c {
fn lower_constness(&mut self, c: Spanned<Constness>) -> hir::Constness {
match c.node {
Constness::Const => hir::Constness::Const,
Constness::NotConst => hir::Constness::NotConst,
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

pub use self::Code::*;

use hir as ast;
use hir::map::{self, Node};
use syntax::abi;
use hir::{Block, FnDecl};
use hir::intravisit::FnKind;
use syntax::abi;
use syntax::ast::{Attribute, Name, NodeId};
use hir as ast;
use syntax_pos::Span;
use hir::intravisit::FnKind;

/// An FnLikeNode is a Node that is like a fn, in that it has a decl
/// and a body (as well as a NodeId, a span, etc).
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
match view_path.node {
ViewPathList(_, ref paths) => {
for path in paths {
this.insert(path.node.id(), NodeItem(i));
this.insert(path.node.id, NodeItem(i));
}
}
_ => ()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
let def_data = match i.node {
ItemKind::DefaultImpl(..) | ItemKind::Impl(..) =>
DefPathData::Impl,
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..) |
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | ItemKind::Trait(..) |
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
DefPathData::TypeNs(i.ident.name.as_str()),
ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_str()),
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
});
}
}
ItemKind::Struct(ref struct_def, _) => {
ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => {
// If this is a tuple-like struct, register the constructor.
if !struct_def.is_struct() {
this.create_def(struct_def.id(),
Expand Down
75 changes: 8 additions & 67 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub use self::FunctionRetTy::*;
pub use self::ForeignItem_::*;
pub use self::Item_::*;
pub use self::Mutability::*;
pub use self::PathListItem_::*;
pub use self::PrimTy::*;
pub use self::Stmt_::*;
pub use self::TraitItem_::*;
Expand All @@ -36,7 +35,7 @@ use hir::def::Def;
use hir::def_id::DefId;
use util::nodemap::{NodeMap, FnvHashSet};

use syntax_pos::{BytePos, mk_sp, Span, ExpnId};
use syntax_pos::{mk_sp, Span, ExpnId, DUMMY_SP};
use syntax::codemap::{self, respan, Spanned};
use syntax::abi::Abi;
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, AsmDialect};
Expand Down Expand Up @@ -301,6 +300,7 @@ pub struct Generics {
pub lifetimes: HirVec<LifetimeDef>,
pub ty_params: HirVec<TyParam>,
pub where_clause: WhereClause,
pub span: Span,
}

impl Generics {
Expand All @@ -312,6 +312,7 @@ impl Generics {
id: DUMMY_NODE_ID,
predicates: HirVec::new(),
},
span: DUMMY_SP,
}
}

Expand All @@ -326,38 +327,6 @@ impl Generics {
pub fn is_parameterized(&self) -> bool {
self.is_lt_parameterized() || self.is_type_parameterized()
}

// Does return a span which includes lifetimes and type parameters,
// not where clause.
pub fn span(&self) -> Option<Span> {
if !self.is_parameterized() {
None
} else {
let mut span: Option<Span> = None;
for lifetime in self.lifetimes.iter() {
if let Some(ref mut span) = span {
let life_span = lifetime.lifetime.span;
span.hi = if span.hi > life_span.hi { span.hi } else { life_span.hi };
span.lo = if span.lo < life_span.lo { span.lo } else { life_span.lo };
} else {
span = Some(lifetime.lifetime.span.clone());
}
}
for ty_param in self.ty_params.iter() {
if let Some(ref mut span) = span {
span.lo = if span.lo < ty_param.span.lo { span.lo } else { ty_param.span.lo };
span.hi = if span.hi > ty_param.span.hi { span.hi } else { ty_param.span.hi };
} else {
span = Some(ty_param.span.clone());
}
}
if let Some(ref mut span) = span {
span.lo = span.lo - BytePos(1);
span.hi = span.hi + BytePos(1);
}
span
}
}
}

/// A `where` clause in a definition
Expand Down Expand Up @@ -1337,39 +1306,11 @@ pub struct Variant_ {
pub type Variant = Spanned<Variant_>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum PathListItem_ {
PathListIdent {
name: Name,
/// renamed in list, eg `use foo::{bar as baz};`
rename: Option<Name>,
id: NodeId,
},
PathListMod {
/// renamed in list, eg `use foo::{self as baz};`
rename: Option<Name>,
id: NodeId,
},
}

impl PathListItem_ {
pub fn id(&self) -> NodeId {
match *self {
PathListIdent { id, .. } | PathListMod { id, .. } => id,
}
}

pub fn name(&self) -> Option<Name> {
match *self {
PathListIdent { name, .. } => Some(name),
PathListMod { .. } => None,
}
}

pub fn rename(&self) -> Option<Name> {
match *self {
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename,
}
}
pub struct PathListItem_ {
pub name: Name,
/// renamed in list, eg `use foo::{bar as baz};`
pub rename: Option<Name>,
pub id: NodeId,
}

pub type PathListItem = Spanned<PathListItem_>;
Expand Down
Loading

0 comments on commit 71ee82a

Please sign in to comment.