Skip to content

Commit 71ee82a

Browse files
authored
Auto merge of #36066 - jseyfried:rollup, r=Manishearth
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
2 parents addb753 + 02f081c commit 71ee82a

File tree

104 files changed

+1297
-855
lines changed

Some content is hidden

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

104 files changed

+1297
-855
lines changed

src/librustc/hir/check_attr.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use session::Session;
1212

1313
use syntax::ast;
14-
use syntax::attr::AttrMetaMethods;
1514
use syntax::visit;
1615
use syntax::visit::Visitor;
1716

@@ -52,18 +51,22 @@ impl<'a> CheckAttrVisitor<'a> {
5251
return;
5352
}
5453
};
54+
5555
for word in words {
56-
let word: &str = &word.name();
57-
let message = match word {
56+
let name = match word.name() {
57+
Some(word) => word,
58+
None => continue,
59+
};
60+
61+
let message = match &*name {
5862
"C" => {
5963
if target != Target::Struct && target != Target::Enum {
60-
"attribute should be applied to struct or enum"
64+
"attribute should be applied to struct or enum"
6165
} else {
6266
continue
6367
}
6468
}
65-
"packed" |
66-
"simd" => {
69+
"packed" | "simd" => {
6770
if target != Target::Struct {
6871
"attribute should be applied to struct"
6972
} else {
@@ -74,13 +77,14 @@ impl<'a> CheckAttrVisitor<'a> {
7477
"i32" | "u32" | "i64" | "u64" |
7578
"isize" | "usize" => {
7679
if target != Target::Enum {
77-
"attribute should be applied to enum"
80+
"attribute should be applied to enum"
7881
} else {
7982
continue
8083
}
8184
}
8285
_ => continue,
8386
};
87+
8488
span_err!(self.sess, attr.span, E0517, "{}", message);
8589
}
8690
}

src/librustc/hir/fold.rs

+26-14
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
//! and returns a piece of the same type.
1313
1414
use hir::*;
15-
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
16-
use syntax::ast::MetaItemKind;
15+
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_};
16+
use syntax::ast::{NestedMetaItem, NestedMetaItemKind, MetaItem, MetaItemKind};
1717
use hir;
1818
use syntax_pos::Span;
1919
use syntax::codemap::{respan, Spanned};
@@ -38,6 +38,10 @@ pub trait Folder : Sized {
3838
noop_fold_meta_items(meta_items, self)
3939
}
4040

41+
fn fold_meta_list_item(&mut self, list_item: NestedMetaItem) -> NestedMetaItem {
42+
noop_fold_meta_list_item(list_item, self)
43+
}
44+
4145
fn fold_meta_item(&mut self, meta_item: P<MetaItem>) -> P<MetaItem> {
4246
noop_fold_meta_item(meta_item, self)
4347
}
@@ -271,16 +275,10 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
271275
ViewPathList(fld.fold_path(path),
272276
path_list_idents.move_map(|path_list_ident| {
273277
Spanned {
274-
node: match path_list_ident.node {
275-
PathListIdent { id, name, rename } => PathListIdent {
276-
id: fld.new_id(id),
277-
name: name,
278-
rename: rename,
279-
},
280-
PathListMod { id, rename } => PathListMod {
281-
id: fld.new_id(id),
282-
rename: rename,
283-
},
278+
node: PathListItem_ {
279+
id: fld.new_id(path_list_ident.node.id),
280+
name: path_list_ident.node.name,
281+
rename: path_list_ident.node.rename,
284282
},
285283
span: fld.new_span(path_list_ident.span),
286284
}
@@ -486,13 +484,26 @@ pub fn noop_fold_attribute<T: Folder>(at: Attribute, fld: &mut T) -> Option<Attr
486484
})
487485
}
488486

487+
pub fn noop_fold_meta_list_item<T: Folder>(li: NestedMetaItem, fld: &mut T)
488+
-> NestedMetaItem {
489+
Spanned {
490+
node: match li.node {
491+
NestedMetaItemKind::MetaItem(mi) => {
492+
NestedMetaItemKind::MetaItem(fld.fold_meta_item(mi))
493+
},
494+
NestedMetaItemKind::Literal(lit) => NestedMetaItemKind::Literal(lit)
495+
},
496+
span: fld.new_span(li.span)
497+
}
498+
}
499+
489500
pub fn noop_fold_meta_item<T: Folder>(mi: P<MetaItem>, fld: &mut T) -> P<MetaItem> {
490501
mi.map(|Spanned { node, span }| {
491502
Spanned {
492503
node: match node {
493504
MetaItemKind::Word(id) => MetaItemKind::Word(id),
494505
MetaItemKind::List(id, mis) => {
495-
MetaItemKind::List(id, mis.move_map(|e| fld.fold_meta_item(e)))
506+
MetaItemKind::List(id, mis.move_map(|e| fld.fold_meta_list_item(e)))
496507
}
497508
MetaItemKind::NameValue(id, s) => MetaItemKind::NameValue(id, s),
498509
},
@@ -577,13 +588,14 @@ pub fn noop_fold_opt_lifetime<T: Folder>(o_lt: Option<Lifetime>, fld: &mut T) ->
577588
o_lt.map(|lt| fld.fold_lifetime(lt))
578589
}
579590

580-
pub fn noop_fold_generics<T: Folder>(Generics { ty_params, lifetimes, where_clause }: Generics,
591+
pub fn noop_fold_generics<T: Folder>(Generics {ty_params, lifetimes, where_clause, span}: Generics,
581592
fld: &mut T)
582593
-> Generics {
583594
Generics {
584595
ty_params: fld.fold_ty_params(ty_params),
585596
lifetimes: fld.fold_lifetime_defs(lifetimes),
586597
where_clause: fld.fold_where_clause(where_clause),
598+
span: fld.new_span(span),
587599
}
588600
}
589601

src/librustc/hir/intravisit.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,12 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
444444
}
445445
}
446446

447-
pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V,
448-
_prefix: &'v Path,
449-
item: &'v PathListItem) {
450-
visitor.visit_id(item.node.id());
451-
walk_opt_name(visitor, item.span, item.node.name());
452-
walk_opt_name(visitor, item.span, item.node.rename());
447+
pub fn walk_path_list_item<'v, V>(visitor: &mut V, _prefix: &'v Path, item: &'v PathListItem)
448+
where V: Visitor<'v>,
449+
{
450+
visitor.visit_id(item.node.id);
451+
visitor.visit_name(item.span, item.node.name);
452+
walk_opt_name(visitor, item.span, item.node.rename);
453453
}
454454

455455
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,

src/librustc/hir/lowering.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,10 @@ impl<'a> LoweringContext<'a> {
218218

219219
fn lower_path_list_item(&mut self, path_list_ident: &PathListItem) -> hir::PathListItem {
220220
Spanned {
221-
node: match path_list_ident.node {
222-
PathListItemKind::Ident { id, name, rename } => hir::PathListIdent {
223-
id: id,
224-
name: name.name,
225-
rename: rename.map(|x| x.name),
226-
},
227-
PathListItemKind::Mod { id, rename } => hir::PathListMod {
228-
id: id,
229-
rename: rename.map(|x| x.name),
230-
},
221+
node: hir::PathListItem_ {
222+
id: path_list_ident.node.id,
223+
name: path_list_ident.node.name.name,
224+
rename: path_list_ident.node.rename.map(|rename| rename.name),
231225
},
232226
span: path_list_ident.span,
233227
}
@@ -466,6 +460,7 @@ impl<'a> LoweringContext<'a> {
466460
ty_params: self.lower_ty_params(&g.ty_params),
467461
lifetimes: self.lower_lifetime_defs(&g.lifetimes),
468462
where_clause: self.lower_where_clause(&g.where_clause),
463+
span: g.span,
469464
}
470465
}
471466

@@ -643,6 +638,7 @@ impl<'a> LoweringContext<'a> {
643638
let struct_def = self.lower_variant_data(struct_def);
644639
hir::ItemStruct(struct_def, self.lower_generics(generics))
645640
}
641+
ItemKind::Union(..) => panic!("`union` is not yet implemented"),
646642
ItemKind::DefaultImpl(unsafety, ref trait_ref) => {
647643
hir::ItemDefaultImpl(self.lower_unsafety(unsafety),
648644
self.lower_trait_ref(trait_ref))
@@ -809,8 +805,8 @@ impl<'a> LoweringContext<'a> {
809805
}
810806
}
811807

812-
fn lower_constness(&mut self, c: Constness) -> hir::Constness {
813-
match c {
808+
fn lower_constness(&mut self, c: Spanned<Constness>) -> hir::Constness {
809+
match c.node {
814810
Constness::Const => hir::Constness::Const,
815811
Constness::NotConst => hir::Constness::NotConst,
816812
}

src/librustc/hir/map/blocks.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
2424
pub use self::Code::*;
2525

26+
use hir as ast;
2627
use hir::map::{self, Node};
27-
use syntax::abi;
2828
use hir::{Block, FnDecl};
29+
use hir::intravisit::FnKind;
30+
use syntax::abi;
2931
use syntax::ast::{Attribute, Name, NodeId};
30-
use hir as ast;
3132
use syntax_pos::Span;
32-
use hir::intravisit::FnKind;
3333

3434
/// An FnLikeNode is a Node that is like a fn, in that it has a decl
3535
/// and a body (as well as a NodeId, a span, etc).

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
120120
match view_path.node {
121121
ViewPathList(_, ref paths) => {
122122
for path in paths {
123-
this.insert(path.node.id(), NodeItem(i));
123+
this.insert(path.node.id, NodeItem(i));
124124
}
125125
}
126126
_ => ()

src/librustc/hir/map/def_collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
133133
let def_data = match i.node {
134134
ItemKind::DefaultImpl(..) | ItemKind::Impl(..) =>
135135
DefPathData::Impl,
136-
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Trait(..) |
136+
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | ItemKind::Trait(..) |
137137
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
138138
DefPathData::TypeNs(i.ident.name.as_str()),
139139
ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_str()),
@@ -164,7 +164,7 @@ impl<'ast> visit::Visitor for DefCollector<'ast> {
164164
});
165165
}
166166
}
167-
ItemKind::Struct(ref struct_def, _) => {
167+
ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => {
168168
// If this is a tuple-like struct, register the constructor.
169169
if !struct_def.is_struct() {
170170
this.create_def(struct_def.id(),

src/librustc/hir/mod.rs

+8-67
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub use self::FunctionRetTy::*;
2020
pub use self::ForeignItem_::*;
2121
pub use self::Item_::*;
2222
pub use self::Mutability::*;
23-
pub use self::PathListItem_::*;
2423
pub use self::PrimTy::*;
2524
pub use self::Stmt_::*;
2625
pub use self::TraitItem_::*;
@@ -36,7 +35,7 @@ use hir::def::Def;
3635
use hir::def_id::DefId;
3736
use util::nodemap::{NodeMap, FnvHashSet};
3837

39-
use syntax_pos::{BytePos, mk_sp, Span, ExpnId};
38+
use syntax_pos::{mk_sp, Span, ExpnId, DUMMY_SP};
4039
use syntax::codemap::{self, respan, Spanned};
4140
use syntax::abi::Abi;
4241
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, AsmDialect};
@@ -301,6 +300,7 @@ pub struct Generics {
301300
pub lifetimes: HirVec<LifetimeDef>,
302301
pub ty_params: HirVec<TyParam>,
303302
pub where_clause: WhereClause,
303+
pub span: Span,
304304
}
305305

306306
impl Generics {
@@ -312,6 +312,7 @@ impl Generics {
312312
id: DUMMY_NODE_ID,
313313
predicates: HirVec::new(),
314314
},
315+
span: DUMMY_SP,
315316
}
316317
}
317318

@@ -326,38 +327,6 @@ impl Generics {
326327
pub fn is_parameterized(&self) -> bool {
327328
self.is_lt_parameterized() || self.is_type_parameterized()
328329
}
329-
330-
// Does return a span which includes lifetimes and type parameters,
331-
// not where clause.
332-
pub fn span(&self) -> Option<Span> {
333-
if !self.is_parameterized() {
334-
None
335-
} else {
336-
let mut span: Option<Span> = None;
337-
for lifetime in self.lifetimes.iter() {
338-
if let Some(ref mut span) = span {
339-
let life_span = lifetime.lifetime.span;
340-
span.hi = if span.hi > life_span.hi { span.hi } else { life_span.hi };
341-
span.lo = if span.lo < life_span.lo { span.lo } else { life_span.lo };
342-
} else {
343-
span = Some(lifetime.lifetime.span.clone());
344-
}
345-
}
346-
for ty_param in self.ty_params.iter() {
347-
if let Some(ref mut span) = span {
348-
span.lo = if span.lo < ty_param.span.lo { span.lo } else { ty_param.span.lo };
349-
span.hi = if span.hi > ty_param.span.hi { span.hi } else { ty_param.span.hi };
350-
} else {
351-
span = Some(ty_param.span.clone());
352-
}
353-
}
354-
if let Some(ref mut span) = span {
355-
span.lo = span.lo - BytePos(1);
356-
span.hi = span.hi + BytePos(1);
357-
}
358-
span
359-
}
360-
}
361330
}
362331

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

13391308
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
1340-
pub enum PathListItem_ {
1341-
PathListIdent {
1342-
name: Name,
1343-
/// renamed in list, eg `use foo::{bar as baz};`
1344-
rename: Option<Name>,
1345-
id: NodeId,
1346-
},
1347-
PathListMod {
1348-
/// renamed in list, eg `use foo::{self as baz};`
1349-
rename: Option<Name>,
1350-
id: NodeId,
1351-
},
1352-
}
1353-
1354-
impl PathListItem_ {
1355-
pub fn id(&self) -> NodeId {
1356-
match *self {
1357-
PathListIdent { id, .. } | PathListMod { id, .. } => id,
1358-
}
1359-
}
1360-
1361-
pub fn name(&self) -> Option<Name> {
1362-
match *self {
1363-
PathListIdent { name, .. } => Some(name),
1364-
PathListMod { .. } => None,
1365-
}
1366-
}
1367-
1368-
pub fn rename(&self) -> Option<Name> {
1369-
match *self {
1370-
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename,
1371-
}
1372-
}
1309+
pub struct PathListItem_ {
1310+
pub name: Name,
1311+
/// renamed in list, eg `use foo::{bar as baz};`
1312+
pub rename: Option<Name>,
1313+
pub id: NodeId,
13731314
}
13741315

13751316
pub type PathListItem = Spanned<PathListItem_>;

0 commit comments

Comments
 (0)