1
Fork 0

A few small cleanups for newtype_index

Remove the `..` from the body, only a few invocations used it and it's
inconsistent with rust syntax.

Use `;` instead of `,` between consts. As the Rust syntax gods inteded.
This commit is contained in:
Nilstrieb 2022-12-18 21:47:28 +01:00
parent d679764fb6
commit 8bfd6450c7
35 changed files with 68 additions and 115 deletions

View file

@ -2556,8 +2556,7 @@ pub enum AttrStyle {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[custom_encodable] #[custom_encodable]
#[debug_format = "AttrId({})]"] #[debug_format = "AttrId({})]"]
pub struct AttrId { pub struct AttrId {}
}
} }
impl<S: Encoder> Encodable<S> for AttrId { impl<S: Encoder> Encodable<S> for AttrId {

View file

@ -9,8 +9,7 @@ rustc_index::newtype_index! {
/// ///
/// [`DefId`]: rustc_span::def_id::DefId /// [`DefId`]: rustc_span::def_id::DefId
#[debug_format = "NodeId({})"] #[debug_format = "NodeId({})"]
pub struct NodeId { pub struct NodeId {}
}
} }
rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId); rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId);

View file

@ -116,12 +116,10 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "OutlivesConstraintIndex({})"] #[debug_format = "OutlivesConstraintIndex({})"]
pub struct OutlivesConstraintIndex { pub struct OutlivesConstraintIndex {}
}
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "ConstraintSccIndex({})"] #[debug_format = "ConstraintSccIndex({})"]
pub struct ConstraintSccIndex { pub struct ConstraintSccIndex {}
}
} }

View file

@ -109,8 +109,7 @@ impl_visitable! {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "bw{}"] #[debug_format = "bw{}"]
pub struct BorrowIndex { pub struct BorrowIndex {}
}
} }
/// `Borrows` stores the data used in the analyses that track the flow /// `Borrows` stores the data used in the analyses that track the flow

View file

@ -21,8 +21,7 @@ pub struct LocationTable {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "LocationIndex({})"] #[debug_format = "LocationIndex({})"]
pub struct LocationIndex { pub struct LocationIndex {}
}
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]

View file

@ -56,8 +56,7 @@ pub(crate) struct NllMemberConstraint<'tcx> {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "MemberConstraintIndex({})"] #[debug_format = "MemberConstraintIndex({})"]
pub(crate) struct NllMemberConstraintIndex { pub(crate) struct NllMemberConstraintIndex {}
}
} }
impl Default for MemberConstraintSet<'_, ty::RegionVid> { impl Default for MemberConstraintSet<'_, ty::RegionVid> {

View file

@ -46,7 +46,7 @@ struct Appearance {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
pub struct AppearanceIndex { .. } pub struct AppearanceIndex {}
} }
impl vll::LinkElem for Appearance { impl vll::LinkElem for Appearance {

View file

@ -22,7 +22,7 @@ struct PreOrderFrame<Iter> {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
struct PreorderIndex { .. } struct PreorderIndex {}
} }
pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> { pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {

View file

@ -138,7 +138,7 @@ rustc_index::newtype_index! {
/// an "item-like" to something else can be implemented by a `Vec` instead of a /// an "item-like" to something else can be implemented by a `Vec` instead of a
/// tree or hash map. /// tree or hash map.
#[derive(HashStable_Generic)] #[derive(HashStable_Generic)]
pub struct ItemLocalId { .. } pub struct ItemLocalId {}
} }
impl ItemLocalId { impl ItemLocalId {

View file

@ -199,9 +199,9 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[custom_encodable] #[custom_encodable]
pub struct RegionId { pub struct RegionId {}
}
} }
struct ConnectedRegion { struct ConnectedRegion {
idents: SmallVec<[Symbol; 8]>, idents: SmallVec<[Symbol; 8]>,
impl_blocks: FxHashSet<usize>, impl_blocks: FxHashSet<usize>,

View file

@ -5,14 +5,12 @@ use rustc_middle::ty::error::TypeError;
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "ExpectedIdx({})"] #[debug_format = "ExpectedIdx({})"]
pub(crate) struct ExpectedIdx { pub(crate) struct ExpectedIdx {}
}
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "ProvidedIdx({})"] #[debug_format = "ProvidedIdx({})"]
pub(crate) struct ProvidedIdx { pub(crate) struct ProvidedIdx {}
}
} }
impl ExpectedIdx { impl ExpectedIdx {

View file

@ -97,14 +97,12 @@ fn for_each_consumable<'tcx>(hir: Map<'tcx>, place: TrackedValue, mut f: impl Fn
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "id({})"] #[debug_format = "id({})"]
pub struct PostOrderId { pub struct PostOrderId {}
}
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "hidx({})"] #[debug_format = "hidx({})"]
pub struct TrackedValueIndex { pub struct TrackedValueIndex {}
}
} }
/// Identifies a value whose drop state we need to track. /// Identifies a value whose drop state we need to track.

View file

@ -358,14 +358,12 @@ impl<'tcx> SccUniverse<'tcx> {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "LeakCheckNode({})"] #[debug_format = "LeakCheckNode({})"]
struct LeakCheckNode { struct LeakCheckNode {}
}
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "LeakCheckScc({})"] #[debug_format = "LeakCheckScc({})"]
struct LeakCheckScc { struct LeakCheckScc {}
}
} }
/// Represents the graph of constraints. For each `R1: R2` constraint we create /// Represents the graph of constraints. For each `R1: R2` constraint we create

View file

@ -41,7 +41,7 @@ struct LintLevelSets {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[custom_encodable] // we don't need encoding #[custom_encodable] // we don't need encoding
struct LintStackIndex { struct LintStackIndex {
const COMMAND_LINE = 0, const COMMAND_LINE = 0;
} }
} }

View file

@ -25,14 +25,6 @@ impl Parse for Newtype {
let mut encodable = true; let mut encodable = true;
let mut ord = true; let mut ord = true;
// Parse an optional trailing comma
let try_comma = || -> Result<()> {
if body.lookahead1().peek(Token![,]) {
body.parse::<Token![,]>()?;
}
Ok(())
};
attrs.retain(|attr| match attr.path.get_ident() { attrs.retain(|attr| match attr.path.get_ident() {
Some(ident) => match &*ident.to_string() { Some(ident) => match &*ident.to_string() {
"custom_encodable" => { "custom_encodable" => {
@ -70,9 +62,6 @@ impl Parse for Newtype {
_ => true, _ => true,
}); });
if body.lookahead1().peek(Token![..]) {
body.parse::<Token![..]>()?;
} else {
loop { loop {
// We've parsed everything that the user provided, so we're done // We've parsed everything that the user provided, so we're done
if body.is_empty() { if body.is_empty() {
@ -85,10 +74,9 @@ impl Parse for Newtype {
let const_name: Ident = body.parse()?; let const_name: Ident = body.parse()?;
body.parse::<Token![=]>()?; body.parse::<Token![=]>()?;
let const_val: Expr = body.parse()?; let const_val: Expr = body.parse()?;
try_comma()?; body.parse::<Token![;]>()?;
consts.push(quote! { #(#const_attrs)* #vis const #const_name: #name = #name::from_u32(#const_val); }); consts.push(quote! { #(#const_attrs)* #vis const #const_name: #name = #name::from_u32(#const_val); });
} }
}
let debug_format = let debug_format =
debug_format.unwrap_or_else(|| Lit::Str(LitStr::new("{}", Span::call_site()))); debug_format.unwrap_or_else(|| Lit::Str(LitStr::new("{}", Span::call_site())));

View file

@ -148,8 +148,7 @@ rustc_index::newtype_index! {
/// * The subscope with `first_statement_index == 1` is scope of `c`, /// * The subscope with `first_statement_index == 1` is scope of `c`,
/// and thus does not include EXPR_2, but covers the `...`. /// and thus does not include EXPR_2, but covers the `...`.
#[derive(HashStable)] #[derive(HashStable)]
pub struct FirstStatementIndex { pub struct FirstStatementIndex {}
}
} }
// compilation error if size of `ScopeData` is not the same as a `u32` // compilation error if size of `ScopeData` is not the same as a `u32`

View file

@ -35,8 +35,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[max = 0xFFFF_FFFF] #[max = 0xFFFF_FFFF]
#[debug_format = "CounterValueReference({})"] #[debug_format = "CounterValueReference({})"]
pub struct CounterValueReference { pub struct CounterValueReference {}
}
} }
impl CounterValueReference { impl CounterValueReference {
@ -59,8 +58,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[max = 0xFFFF_FFFF] #[max = 0xFFFF_FFFF]
#[debug_format = "InjectedExpressionId({})"] #[debug_format = "InjectedExpressionId({})"]
pub struct InjectedExpressionId { pub struct InjectedExpressionId {}
}
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
@ -70,8 +68,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[max = 0xFFFF_FFFF] #[max = 0xFFFF_FFFF]
#[debug_format = "InjectedExpressionIndex({})"] #[debug_format = "InjectedExpressionIndex({})"]
pub struct InjectedExpressionIndex { pub struct InjectedExpressionIndex {}
}
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
@ -81,8 +78,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[max = 0xFFFF_FFFF] #[max = 0xFFFF_FFFF]
#[debug_format = "MappedExpressionIndex({})"] #[debug_format = "MappedExpressionIndex({})"]
pub struct MappedExpressionIndex { pub struct MappedExpressionIndex {}
}
} }
impl From<CounterValueReference> for ExpressionOperandId { impl From<CounterValueReference> for ExpressionOperandId {

View file

@ -657,7 +657,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[debug_format = "_{}"] #[debug_format = "_{}"]
pub struct Local { pub struct Local {
const RETURN_PLACE = 0, const RETURN_PLACE = 0;
} }
} }
@ -1149,7 +1149,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[debug_format = "bb{}"] #[debug_format = "bb{}"]
pub struct BasicBlock { pub struct BasicBlock {
const START_BLOCK = 0, const START_BLOCK = 0;
} }
} }
@ -1532,8 +1532,7 @@ rustc_index::newtype_index! {
/// [mir-datatypes]: https://rustc-dev-guide.rust-lang.org/mir/index.html#mir-data-types /// [mir-datatypes]: https://rustc-dev-guide.rust-lang.org/mir/index.html#mir-data-types
#[derive(HashStable)] #[derive(HashStable)]
#[debug_format = "field[{}]"] #[debug_format = "field[{}]"]
pub struct Field { pub struct Field {}
}
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@ -1760,7 +1759,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[debug_format = "scope[{}]"] #[debug_format = "scope[{}]"]
pub struct SourceScope { pub struct SourceScope {
const OUTERMOST_SOURCE_SCOPE = 0, const OUTERMOST_SOURCE_SCOPE = 0;
} }
} }
@ -2757,8 +2756,7 @@ impl<'tcx> TypeVisitable<'tcx> for UserTypeProjection {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[debug_format = "promoted[{}]"] #[debug_format = "promoted[{}]"]
pub struct Promoted { pub struct Promoted {}
}
} }
impl<'tcx> Debug for Constant<'tcx> { impl<'tcx> Debug for Constant<'tcx> {

View file

@ -132,8 +132,7 @@ pub struct UnsafetyCheckResult {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[debug_format = "_{}"] #[debug_format = "_{}"]
pub struct GeneratorSavedLocal { pub struct GeneratorSavedLocal {}
}
} }
/// The layout of generator state. /// The layout of generator state.

View file

@ -36,8 +36,7 @@ macro_rules! thir_with_elements {
newtype_index! { newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[debug_format = $format] #[debug_format = $format]
pub struct $id { pub struct $id {}
}
} }
)* )*

View file

@ -1379,8 +1379,7 @@ rustc_index::newtype_index! {
/// A **region** (lifetime) **v**ariable **ID**. /// A **region** (lifetime) **v**ariable **ID**.
#[derive(HashStable)] #[derive(HashStable)]
#[debug_format = "'_#{}r"] #[debug_format = "'_#{}r"]
pub struct RegionVid { pub struct RegionVid {}
}
} }
impl Atom for RegionVid { impl Atom for RegionVid {
@ -1391,7 +1390,7 @@ impl Atom for RegionVid {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
pub struct BoundVar { .. } pub struct BoundVar {}
} }
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]

View file

@ -611,7 +611,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]
#[debug_format = "UserType({})"] #[debug_format = "UserType({})"]
pub struct UserTypeAnnotationIndex { pub struct UserTypeAnnotationIndex {
const START_INDEX = 0, const START_INDEX = 0;
} }
} }

View file

@ -372,7 +372,7 @@ struct CFG<'tcx> {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
struct ScopeId { .. } struct ScopeId {}
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -185,7 +185,7 @@ pub(crate) enum BreakableTarget {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
struct DropIdx { .. } struct DropIdx {}
} }
const ROOT_NODE: DropIdx = DropIdx::from_u32(0); const ROOT_NODE: DropIdx = DropIdx::from_u32(0);

View file

@ -15,8 +15,7 @@ mod abs_domain;
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "mp{}"] #[debug_format = "mp{}"]
pub struct MovePathIndex { pub struct MovePathIndex {}
}
} }
impl polonius_engine::Atom for MovePathIndex { impl polonius_engine::Atom for MovePathIndex {
@ -27,14 +26,12 @@ impl polonius_engine::Atom for MovePathIndex {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "mo{}"] #[debug_format = "mo{}"]
pub struct MoveOutIndex { pub struct MoveOutIndex {}
}
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "in{}"] #[debug_format = "in{}"]
pub struct InitIndex { pub struct InitIndex {}
}
} }
impl MoveOutIndex { impl MoveOutIndex {

View file

@ -284,7 +284,7 @@ rustc_index::newtype_index! {
/// A node in the control-flow graph of CoverageGraph. /// A node in the control-flow graph of CoverageGraph.
#[debug_format = "bcb{}"] #[debug_format = "bcb{}"]
pub(super) struct BasicCoverageBlock { pub(super) struct BasicCoverageBlock {
const START_BCB = 0, const START_BCB = 0;
} }
} }

View file

@ -109,14 +109,12 @@ mod rwu_table;
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "v({})"] #[debug_format = "v({})"]
pub struct Variable { pub struct Variable {}
}
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[debug_format = "ln({})"] #[debug_format = "ln({})"]
pub struct LiveNode { pub struct LiveNode {}
}
} }
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(Copy, Clone, PartialEq, Debug)]

View file

@ -37,7 +37,7 @@ pub struct DepGraph<K: DepKind> {
} }
rustc_index::newtype_index! { rustc_index::newtype_index! {
pub struct DepNodeIndex { .. } pub struct DepNodeIndex {}
} }
impl DepNodeIndex { impl DepNodeIndex {
@ -974,7 +974,7 @@ pub struct WorkProduct {
// Index type for `DepNodeData`'s edges. // Index type for `DepNodeData`'s edges.
rustc_index::newtype_index! { rustc_index::newtype_index! {
struct EdgeIndex { .. } struct EdgeIndex {}
} }
/// `CurrentDepGraph` stores the dependency graph for the current session. It /// `CurrentDepGraph` stores the dependency graph for the current session. It

View file

@ -28,8 +28,7 @@ use smallvec::SmallVec;
// and use those bits to encode which index type it contains. // and use those bits to encode which index type it contains.
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[max = 0x7FFF_FFFF] #[max = 0x7FFF_FFFF]
pub struct SerializedDepNodeIndex { pub struct SerializedDepNodeIndex {}
}
} }
/// Data for use when recompiling the **current crate**. /// Data for use when recompiling the **current crate**.

View file

@ -12,8 +12,7 @@ use std::hash::{Hash, Hasher};
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[custom_encodable] #[custom_encodable]
#[debug_format = "crate{}"] #[debug_format = "crate{}"]
pub struct CrateNum { pub struct CrateNum {}
}
} }
/// Item definitions in the currently-compiled crate would have the `CrateNum` /// Item definitions in the currently-compiled crate would have the `CrateNum`
@ -199,7 +198,7 @@ rustc_index::newtype_index! {
pub struct DefIndex { pub struct 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`.
const CRATE_DEF_INDEX = 0, const CRATE_DEF_INDEX = 0;
} }
} }

View file

@ -62,8 +62,7 @@ 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] #[custom_encodable]
pub struct ExpnIndex { pub struct ExpnIndex {}
}
} }
/// A unique ID associated with a macro invocation and expansion. /// A unique ID associated with a macro invocation and expansion.
@ -85,8 +84,7 @@ rustc_index::newtype_index! {
#[custom_encodable] #[custom_encodable]
#[no_ord_impl] #[no_ord_impl]
#[debug_format = "expn{}"] #[debug_format = "expn{}"]
pub struct LocalExpnId { pub struct LocalExpnId {}
}
} }
// To ensure correctness of incremental compilation, // To ensure correctness of incremental compilation,

View file

@ -1801,7 +1801,7 @@ impl fmt::Display for MacroRulesNormalizedIdent {
pub struct Symbol(SymbolIndex); pub struct Symbol(SymbolIndex);
rustc_index::newtype_index! { rustc_index::newtype_index! {
struct SymbolIndex { .. } struct SymbolIndex {}
} }
impl Symbol { impl Symbol {

View file

@ -21,8 +21,7 @@ impl ToJson for Endian {
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[derive(HashStable_Generic)] #[derive(HashStable_Generic)]
pub struct VariantIdx { pub struct VariantIdx {}
}
} }
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)] #[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]

View file

@ -303,7 +303,7 @@ rustc_index::newtype_index! {
#[derive(HashStable_Generic)] #[derive(HashStable_Generic)]
#[debug_format = "DebruijnIndex({})"] #[debug_format = "DebruijnIndex({})"]
pub struct DebruijnIndex { pub struct DebruijnIndex {
const INNERMOST = 0, const INNERMOST = 0;
} }
} }
@ -500,8 +500,7 @@ pub struct FloatVarValue(pub FloatTy);
rustc_index::newtype_index! { rustc_index::newtype_index! {
/// A **ty**pe **v**ariable **ID**. /// A **ty**pe **v**ariable **ID**.
#[debug_format = "_#{}t"] #[debug_format = "_#{}t"]
pub struct TyVid { pub struct TyVid {}
}
} }
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**. /// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
@ -789,8 +788,7 @@ rustc_index::newtype_index! {
/// use for checking generic functions. /// use for checking generic functions.
#[derive(HashStable_Generic)] #[derive(HashStable_Generic)]
#[debug_format = "U{}"] #[debug_format = "U{}"]
pub struct UniverseIndex { pub struct UniverseIndex {}
}
} }
impl UniverseIndex { impl UniverseIndex {