Skip to content

Commit 7017058

Browse files
committed
ast: add Defaultness to Item, making AssocItem an alias.
1 parent d41fc13 commit 7017058

File tree

13 files changed

+35
-44
lines changed

13 files changed

+35
-44
lines changed

src/librustc_ast_pretty/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,8 @@ impl<'a> State<'a> {
10161016
}
10171017

10181018
crate fn print_foreign_item(&mut self, item: &ast::ForeignItem) {
1019-
let ast::ForeignItem { id, span, ident, attrs, kind, vis, tokens: _ } = item;
1020-
self.print_nested_item_kind(*id, *span, *ident, attrs, ast::Defaultness::Final, kind, vis);
1019+
let ast::Item { id, span, ident, attrs, kind, vis, defaultness, tokens: _ } = item;
1020+
self.print_nested_item_kind(*id, *span, *ident, attrs, *defaultness, kind, vis);
10211021
}
10221022

10231023
fn print_nested_item_kind(

src/librustc_builtin_macros/global_asm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn expand_global_asm<'cx>(
3030
id: ast::DUMMY_NODE_ID,
3131
kind: ast::ItemKind::GlobalAsm(P(global_asm)),
3232
vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
33+
defaultness: ast::Defaultness::Final,
3334
span: cx.with_def_site_ctxt(sp),
3435
tokens: None,
3536
})]),

src/librustc_builtin_macros/test_harness.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,30 +162,21 @@ impl MutVisitor for EntryPointCleaner {
162162
// #[allow(dead_code)] to avoid printing warnings.
163163
let item = match entry::entry_point_type(&item, self.depth) {
164164
EntryPointType::MainNamed | EntryPointType::MainAttr | EntryPointType::Start => item
165-
.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
165+
.map(|ast::Item { id, ident, attrs, kind, vis, defaultness, span, tokens }| {
166166
let allow_ident = Ident::new(sym::allow, self.def_site);
167167
let dc_nested = attr::mk_nested_word_item(Ident::from_str_and_span(
168168
"dead_code",
169169
self.def_site,
170170
));
171171
let allow_dead_code_item = attr::mk_list_item(allow_ident, vec![dc_nested]);
172172
let allow_dead_code = attr::mk_attr_outer(allow_dead_code_item);
173+
let attrs = attrs
174+
.into_iter()
175+
.filter(|attr| !attr.check_name(sym::main) && !attr.check_name(sym::start))
176+
.chain(iter::once(allow_dead_code))
177+
.collect();
173178

174-
ast::Item {
175-
id,
176-
ident,
177-
attrs: attrs
178-
.into_iter()
179-
.filter(|attr| {
180-
!attr.check_name(sym::main) && !attr.check_name(sym::start)
181-
})
182-
.chain(iter::once(allow_dead_code))
183-
.collect(),
184-
kind,
185-
vis,
186-
span,
187-
tokens,
188-
}
179+
ast::Item { id, ident, attrs, kind, vis, defaultness, span, tokens }
189180
}),
190181
EntryPointType::None | EntryPointType::OtherMain => item,
191182
};
@@ -321,6 +312,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
321312
id: ast::DUMMY_NODE_ID,
322313
kind: main,
323314
vis: respan(sp, ast::VisibilityKind::Public),
315+
defaultness: ast::Defaultness::Final,
324316
span: sp,
325317
tokens: None,
326318
});

src/librustc_expand/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ impl<'a> ExtCtxt<'a> {
588588
id: ast::DUMMY_NODE_ID,
589589
kind,
590590
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
591+
defaultness: ast::Defaultness::Final,
591592
span,
592593
tokens: None,
593594
})

src/librustc_expand/expand.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
358358
ident: Ident::invalid(),
359359
id: ast::DUMMY_NODE_ID,
360360
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
361+
defaultness: ast::Defaultness::Final,
361362
tokens: None,
362363
})]);
363364

src/librustc_expand/placeholders.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn placeholder(
2626
let ident = ast::Ident::invalid();
2727
let attrs = Vec::new();
2828
let vis = vis.unwrap_or_else(|| dummy_spanned(ast::VisibilityKind::Inherited));
29+
let defaultness = ast::Defaultness::Final;
2930
let span = DUMMY_SP;
3031
let expr_placeholder = || {
3132
P(ast::Expr {
@@ -46,6 +47,7 @@ pub fn placeholder(
4647
span,
4748
ident,
4849
vis,
50+
defaultness,
4951
attrs,
5052
kind: ast::ItemKind::Mac(mac_placeholder()),
5153
tokens: None,
@@ -76,6 +78,7 @@ pub fn placeholder(
7678
span,
7779
ident,
7880
vis,
81+
defaultness,
7982
attrs,
8083
kind: ast::ForeignItemKind::Macro(mac_placeholder()),
8184
tokens: None,

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ impl CStore {
464464
legacy: def.legacy,
465465
}),
466466
vis: source_map::respan(local_span.shrink_to_lo(), ast::VisibilityKind::Inherited),
467+
defaultness: ast::Defaultness::Final,
467468
tokens: None,
468469
},
469470
data.root.edition,

src/librustc_parse/parser/item.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'a> Parser<'a> {
8585
let vis = self.parse_visibility(FollowedByType::No)?;
8686

8787
if let Some((ident, kind)) = self.parse_item_kind(&mut attrs, macros_allowed, lo, &vis)? {
88-
return Ok(Some(P(self.mk_item(lo, ident, kind, vis, attrs))));
88+
return Ok(Some(P(self.mk_item(lo, ident, kind, vis, Defaultness::Final, attrs))));
8989
}
9090

9191
// FAILURE TO PARSE ITEM
@@ -866,7 +866,7 @@ impl<'a> Parser<'a> {
866866
let lo = self.token.span;
867867
let vis = self.parse_visibility(FollowedByType::No)?;
868868
let (ident, kind) = self.parse_assoc_item_kind(at_end, &mut attrs, |_| true, &vis)?;
869-
let item = self.mk_item(lo, ident, kind, vis, attrs);
869+
let item = self.mk_item(lo, ident, kind, vis, Defaultness::Final, attrs);
870870
self.error_on_foreign_const(&item);
871871
Ok(P(item))
872872
}
@@ -1420,10 +1420,11 @@ impl<'a> Parser<'a> {
14201420
ident: Ident,
14211421
kind: K,
14221422
vis: Visibility,
1423+
defaultness: Defaultness,
14231424
attrs: Vec<Attribute>,
14241425
) -> Item<K> {
14251426
let span = lo.to(self.prev_span);
1426-
Item { ident, attrs, id: DUMMY_NODE_ID, kind, vis, span, tokens: None }
1427+
Item { ident, attrs, id: DUMMY_NODE_ID, kind, vis, defaultness, span, tokens: None }
14271428
}
14281429
}
14291430

src/libsyntax/ast.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,16 +2411,19 @@ impl VariantData {
24112411
}
24122412
}
24132413

2414-
/// An item.
2415-
///
2416-
/// The name might be a dummy name in case of anonymous items.
2414+
/// An item definition.
24172415
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
24182416
pub struct Item<K = ItemKind> {
24192417
pub attrs: Vec<Attribute>,
24202418
pub id: NodeId,
24212419
pub span: Span,
24222420
pub vis: Visibility,
2421+
/// The name of the item.
2422+
/// It might be a dummy name in case of anonymous items.
24232423
pub ident: Ident,
2424+
/// The `default`ness of this item.
2425+
/// This should only occur in syntactically well-formed code in associated contexts.
2426+
pub defaultness: Defaultness,
24242427

24252428
pub kind: K,
24262429

@@ -2613,19 +2616,7 @@ pub type ForeignItemKind = AssocItemKind;
26132616

26142617
/// Represents associated items.
26152618
/// These include items in `impl` and `trait` definitions.
2616-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
2617-
pub struct AssocItem {
2618-
pub attrs: Vec<Attribute>,
2619-
pub id: NodeId,
2620-
pub span: Span,
2621-
pub vis: Visibility,
2622-
pub ident: Ident,
2623-
2624-
pub defaultness: Defaultness,
2625-
pub kind: AssocItemKind,
2626-
/// See `Item::tokens` for what this is.
2627-
pub tokens: Option<TokenStream>,
2628-
}
2619+
pub type AssocItem = Item<AssocItemKind>;
26292620

26302621
/// Represents non-free item kinds.
26312622
///

src/libsyntax/attr/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,6 @@ macro_rules! derive_has_attrs {
722722
}
723723

724724
derive_has_attrs! {
725-
Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::AssocItem, ast::Arm,
725+
Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::Arm,
726726
ast::Field, ast::FieldPat, ast::Variant, ast::Param, GenericParam
727727
}

0 commit comments

Comments
 (0)