Skip to content

Commit 88d5f7f

Browse files
committed
Make #[custom_encodable] an attribute for newtype_index
Makes the syntax a little more rusty.
1 parent b4d739e commit 88d5f7f

File tree

6 files changed

+19
-18
lines changed

6 files changed

+19
-18
lines changed

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2554,8 +2554,8 @@ pub enum AttrStyle {
25542554
}
25552555

25562556
rustc_index::newtype_index! {
2557+
#[custom_encodable]
25572558
pub struct AttrId {
2558-
ENCODABLE = custom
25592559
DEBUG_FORMAT = "AttrId({})"
25602560
}
25612561
}

compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
198198
// entire graph when there are many connected regions.
199199

200200
rustc_index::newtype_index! {
201+
#[custom_encodable]
201202
pub struct RegionId {
202-
ENCODABLE = custom
203203
}
204204
}
205205
struct ConnectedRegion {

compiler/rustc_lint/src/levels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct LintLevelSets {
3939
}
4040

4141
rustc_index::newtype_index! {
42+
#[custom_encodable] // we don't need encoding
4243
struct LintStackIndex {
43-
ENCODABLE = custom, // we don't need encoding
4444
const COMMAND_LINE = 0,
4545
}
4646
}

compiler/rustc_macros/src/newtype.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use syn::*;
66
mod kw {
77
syn::custom_keyword!(DEBUG_FORMAT);
88
syn::custom_keyword!(MAX);
9-
syn::custom_keyword!(ENCODABLE);
109
syn::custom_keyword!(custom);
1110
syn::custom_keyword!(ORD_IMPL);
1211
}
@@ -27,7 +26,7 @@ struct Newtype(TokenStream);
2726

2827
impl Parse for Newtype {
2928
fn parse(input: ParseStream<'_>) -> Result<Self> {
30-
let attrs = input.call(Attribute::parse_outer)?;
29+
let mut attrs = input.call(Attribute::parse_outer)?;
3130
let vis: Visibility = input.parse()?;
3231
input.parse::<Token![struct]>()?;
3332
let name: Ident = input.parse()?;
@@ -51,6 +50,17 @@ impl Parse for Newtype {
5150
Ok(())
5251
};
5352

53+
attrs.retain(|attr| match attr.path.get_ident() {
54+
Some(ident) => match &*ident.to_string() {
55+
"custom_encodable" => {
56+
encodable = false;
57+
false
58+
}
59+
_ => true,
60+
},
61+
_ => true,
62+
});
63+
5464
if body.lookahead1().peek(Token![..]) {
5565
body.parse::<Token![..]>()?;
5666
} else {
@@ -81,14 +91,6 @@ impl Parse for Newtype {
8191
}
8292
continue;
8393
}
84-
if body.lookahead1().peek(kw::ENCODABLE) {
85-
body.parse::<kw::ENCODABLE>()?;
86-
body.parse::<Token![=]>()?;
87-
body.parse::<kw::custom>()?;
88-
try_comma()?;
89-
encodable = false;
90-
continue;
91-
}
9294
if body.lookahead1().peek(kw::ORD_IMPL) {
9395
body.parse::<kw::ORD_IMPL>()?;
9496
body.parse::<Token![=]>()?;

compiler/rustc_span/src/def_id.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use std::fmt;
1010
use std::hash::{Hash, Hasher};
1111

1212
rustc_index::newtype_index! {
13+
#[custom_encodable]
1314
pub struct CrateNum {
14-
ENCODABLE = custom
1515
DEBUG_FORMAT = "crate{}"
1616
}
1717
}
@@ -194,9 +194,8 @@ rustc_index::newtype_index! {
194194
/// A DefIndex is an index into the hir-map for a crate, identifying a
195195
/// particular definition. It should really be considered an interned
196196
/// shorthand for a particular DefPath.
197+
#[custom_encodable] // (only encodable in metadata)
197198
pub struct DefIndex {
198-
ENCODABLE = custom // (only encodable in metadata)
199-
200199
DEBUG_FORMAT = "DefIndex({})",
201200
/// The crate root is always assigned index 0 by the AST Map code,
202201
/// thanks to `NodeCollector::new`.

compiler/rustc_span/src/hygiene.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ pub struct SyntaxContextData {
6161

6262
rustc_index::newtype_index! {
6363
/// A unique ID associated with a macro invocation and expansion.
64+
#[custom_encodable]
6465
pub struct ExpnIndex {
65-
ENCODABLE = custom
6666
}
6767
}
6868

@@ -82,8 +82,8 @@ impl fmt::Debug for ExpnId {
8282

8383
rustc_index::newtype_index! {
8484
/// A unique ID associated with a macro invocation and expansion.
85+
#[custom_encodable]
8586
pub struct LocalExpnId {
86-
ENCODABLE = custom
8787
ORD_IMPL = custom
8888
DEBUG_FORMAT = "expn{}"
8989
}

0 commit comments

Comments
 (0)