Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch up libsyntax breaking changes #36066

Merged
merged 24 commits into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
28ed8b1
Fix #[derive] for empty tuple structs/variants
petrochenkov Aug 15, 2016
f6e06a8
Split `AstBuilder::pat_enum` into `pat_tuple_struct` and `pat_path`
petrochenkov Aug 15, 2016
5948182
Add Span field for Generics structs
GuillaumeGomez Aug 10, 2016
98ce875
Refactor away variant `ast::PathListItemKind::Mod`
jseyfried Aug 12, 2016
c4d577b
Refactor away variant `hir::PathListItem_::Mod`
jseyfried Aug 12, 2016
9d99fe9
Fix fallout in `rustdoc`.
jseyfried Aug 12, 2016
8250a26
Implement RFC#1559: allow all literals in attributes.
SergioBenitez Aug 20, 2016
4eb08bb
Refactor away `AttrNestedMetaItemMethods`.
jseyfried Aug 23, 2016
e264828
Refactor away `AttributeMethods`.
jseyfried Aug 23, 2016
bfb01bb
Refactor away `AttrMetaMethods`.
jseyfried Aug 23, 2016
469753f
Fix fallout in tests.
jseyfried Aug 24, 2016
1e9e798
Move E0379 check from typeck to ast validation
KiChjang Aug 7, 2016
aa5c4bb
Change Constness to Spanned<Constness>
KiChjang Aug 10, 2016
e46b09a
Add UI test for E0379
KiChjang Aug 12, 2016
b833e8d
Rollup merge of #35591 - GuillaumeGomez:generics_span, r=jntrmr
jseyfried Aug 28, 2016
37f3017
Rollup merge of #35618 - jseyfried:ast_view_path_refactor, r=eddyb
jseyfried Aug 28, 2016
bd38e89
Rollup merge of #35480 - KiChjang:e0379-bonus, r=nikomatsakis
jseyfried Aug 28, 2016
413ecde
Rollup merge of #35728 - petrochenkov:empderive, r=manishearth
jseyfried Aug 28, 2016
6303640
Rollup merge of #35850 - SergioBenitez:master, r=nrc
jseyfried Aug 28, 2016
c14ff28
Rollup merge of #35917 - jseyfried:remove_attr_ext_traits, r=nrc
jseyfried Aug 28, 2016
4fe94e0
Future proof the AST for `union`.
jseyfried Aug 29, 2016
663caa9
Remove inherent methods `Annotatable::attrs` and `Annotatable::fold_a…
jseyfried Aug 28, 2016
cdde06e
Fix merge conflicts.
jseyfried Aug 28, 2016
02f081c
Future proof `libsyntax_ext` for `union`.
jseyfried Aug 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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