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