Make #[custom_encodable]
an attribute for newtype_index
Makes the syntax a little more rusty.
This commit is contained in:
parent
b4d739ef12
commit
88d5f7f4ce
@ -2554,8 +2554,8 @@ pub enum AttrStyle {
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[custom_encodable]
|
||||
pub struct AttrId {
|
||||
ENCODABLE = custom
|
||||
DEBUG_FORMAT = "AttrId({})"
|
||||
}
|
||||
}
|
||||
|
@ -198,8 +198,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
|
||||
// entire graph when there are many connected regions.
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[custom_encodable]
|
||||
pub struct RegionId {
|
||||
ENCODABLE = custom
|
||||
}
|
||||
}
|
||||
struct ConnectedRegion {
|
||||
|
@ -39,8 +39,8 @@ struct LintLevelSets {
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[custom_encodable] // we don't need encoding
|
||||
struct LintStackIndex {
|
||||
ENCODABLE = custom, // we don't need encoding
|
||||
const COMMAND_LINE = 0,
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ use syn::*;
|
||||
mod kw {
|
||||
syn::custom_keyword!(DEBUG_FORMAT);
|
||||
syn::custom_keyword!(MAX);
|
||||
syn::custom_keyword!(ENCODABLE);
|
||||
syn::custom_keyword!(custom);
|
||||
syn::custom_keyword!(ORD_IMPL);
|
||||
}
|
||||
@ -27,7 +26,7 @@ struct Newtype(TokenStream);
|
||||
|
||||
impl Parse for Newtype {
|
||||
fn parse(input: ParseStream<'_>) -> Result<Self> {
|
||||
let attrs = input.call(Attribute::parse_outer)?;
|
||||
let mut attrs = input.call(Attribute::parse_outer)?;
|
||||
let vis: Visibility = input.parse()?;
|
||||
input.parse::<Token![struct]>()?;
|
||||
let name: Ident = input.parse()?;
|
||||
@ -51,6 +50,17 @@ impl Parse for Newtype {
|
||||
Ok(())
|
||||
};
|
||||
|
||||
attrs.retain(|attr| match attr.path.get_ident() {
|
||||
Some(ident) => match &*ident.to_string() {
|
||||
"custom_encodable" => {
|
||||
encodable = false;
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
},
|
||||
_ => true,
|
||||
});
|
||||
|
||||
if body.lookahead1().peek(Token![..]) {
|
||||
body.parse::<Token![..]>()?;
|
||||
} else {
|
||||
@ -81,14 +91,6 @@ impl Parse for Newtype {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if body.lookahead1().peek(kw::ENCODABLE) {
|
||||
body.parse::<kw::ENCODABLE>()?;
|
||||
body.parse::<Token![=]>()?;
|
||||
body.parse::<kw::custom>()?;
|
||||
try_comma()?;
|
||||
encodable = false;
|
||||
continue;
|
||||
}
|
||||
if body.lookahead1().peek(kw::ORD_IMPL) {
|
||||
body.parse::<kw::ORD_IMPL>()?;
|
||||
body.parse::<Token![=]>()?;
|
||||
|
@ -10,8 +10,8 @@ use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
#[custom_encodable]
|
||||
pub struct CrateNum {
|
||||
ENCODABLE = custom
|
||||
DEBUG_FORMAT = "crate{}"
|
||||
}
|
||||
}
|
||||
@ -194,9 +194,8 @@ rustc_index::newtype_index! {
|
||||
/// A DefIndex is an index into the hir-map for a crate, identifying a
|
||||
/// particular definition. It should really be considered an interned
|
||||
/// shorthand for a particular DefPath.
|
||||
#[custom_encodable] // (only encodable in metadata)
|
||||
pub struct DefIndex {
|
||||
ENCODABLE = custom // (only encodable in metadata)
|
||||
|
||||
DEBUG_FORMAT = "DefIndex({})",
|
||||
/// The crate root is always assigned index 0 by the AST Map code,
|
||||
/// thanks to `NodeCollector::new`.
|
||||
|
@ -61,8 +61,8 @@ pub struct SyntaxContextData {
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
/// A unique ID associated with a macro invocation and expansion.
|
||||
#[custom_encodable]
|
||||
pub struct ExpnIndex {
|
||||
ENCODABLE = custom
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,8 +82,8 @@ impl fmt::Debug for ExpnId {
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
/// A unique ID associated with a macro invocation and expansion.
|
||||
#[custom_encodable]
|
||||
pub struct LocalExpnId {
|
||||
ENCODABLE = custom
|
||||
ORD_IMPL = custom
|
||||
DEBUG_FORMAT = "expn{}"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user