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! {
#[custom_encodable]
#[debug_format = "AttrId({})]"]
pub struct AttrId {
}
pub struct AttrId {}
}
impl<S: Encoder> Encodable<S> for AttrId {

View File

@ -9,8 +9,7 @@ rustc_index::newtype_index! {
///
/// [`DefId`]: rustc_span::def_id::DefId
#[debug_format = "NodeId({})"]
pub struct NodeId {
}
pub struct 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! {
#[debug_format = "OutlivesConstraintIndex({})"]
pub struct OutlivesConstraintIndex {
}
pub struct OutlivesConstraintIndex {}
}
rustc_index::newtype_index! {
#[debug_format = "ConstraintSccIndex({})"]
pub struct ConstraintSccIndex {
}
pub struct ConstraintSccIndex {}
}

View File

@ -109,8 +109,7 @@ impl_visitable! {
rustc_index::newtype_index! {
#[debug_format = "bw{}"]
pub struct BorrowIndex {
}
pub struct BorrowIndex {}
}
/// `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! {
#[debug_format = "LocationIndex({})"]
pub struct LocationIndex {
}
pub struct LocationIndex {}
}
#[derive(Copy, Clone, Debug)]

View File

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

View File

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

View File

@ -22,7 +22,7 @@ struct PreOrderFrame<Iter> {
}
rustc_index::newtype_index! {
struct PreorderIndex { .. }
struct PreorderIndex {}
}
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
/// tree or hash map.
#[derive(HashStable_Generic)]
pub struct ItemLocalId { .. }
pub struct ItemLocalId {}
}
impl ItemLocalId {

View File

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

View File

@ -5,14 +5,12 @@ use rustc_middle::ty::error::TypeError;
rustc_index::newtype_index! {
#[debug_format = "ExpectedIdx({})"]
pub(crate) struct ExpectedIdx {
}
pub(crate) struct ExpectedIdx {}
}
rustc_index::newtype_index! {
#[debug_format = "ProvidedIdx({})"]
pub(crate) struct ProvidedIdx {
}
pub(crate) struct ProvidedIdx {}
}
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! {
#[debug_format = "id({})"]
pub struct PostOrderId {
}
pub struct PostOrderId {}
}
rustc_index::newtype_index! {
#[debug_format = "hidx({})"]
pub struct TrackedValueIndex {
}
pub struct TrackedValueIndex {}
}
/// Identifies a value whose drop state we need to track.

View File

@ -5,7 +5,7 @@ use crate as rustc_index;
rustc_macros::newtype_index! {
#[max = 0xFFFF_FFFA]
struct MyIdx { }
struct MyIdx {}
}
#[test]

View File

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

View File

@ -41,7 +41,7 @@ struct LintLevelSets {
rustc_index::newtype_index! {
#[custom_encodable] // we don't need encoding
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 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() {
Some(ident) => match &*ident.to_string() {
"custom_encodable" => {
@ -70,24 +62,20 @@ impl Parse for Newtype {
_ => true,
});
if body.lookahead1().peek(Token![..]) {
body.parse::<Token![..]>()?;
} else {
loop {
// We've parsed everything that the user provided, so we're done
if body.is_empty() {
break;
}
// Otherwise, we are parsing a user-defined constant
let const_attrs = body.call(Attribute::parse_outer)?;
body.parse::<Token![const]>()?;
let const_name: Ident = body.parse()?;
body.parse::<Token![=]>()?;
let const_val: Expr = body.parse()?;
try_comma()?;
consts.push(quote! { #(#const_attrs)* #vis const #const_name: #name = #name::from_u32(#const_val); });
loop {
// We've parsed everything that the user provided, so we're done
if body.is_empty() {
break;
}
// Otherwise, we are parsing a user-defined constant
let const_attrs = body.call(Attribute::parse_outer)?;
body.parse::<Token![const]>()?;
let const_name: Ident = body.parse()?;
body.parse::<Token![=]>()?;
let const_val: Expr = body.parse()?;
body.parse::<Token![;]>()?;
consts.push(quote! { #(#const_attrs)* #vis const #const_name: #name = #name::from_u32(#const_val); });
}
let debug_format =

View File

@ -148,8 +148,7 @@ rustc_index::newtype_index! {
/// * The subscope with `first_statement_index == 1` is scope of `c`,
/// and thus does not include EXPR_2, but covers the `...`.
#[derive(HashStable)]
pub struct FirstStatementIndex {
}
pub struct FirstStatementIndex {}
}
// 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)]
#[max = 0xFFFF_FFFF]
#[debug_format = "CounterValueReference({})"]
pub struct CounterValueReference {
}
pub struct CounterValueReference {}
}
impl CounterValueReference {
@ -59,8 +58,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)]
#[max = 0xFFFF_FFFF]
#[debug_format = "InjectedExpressionId({})"]
pub struct InjectedExpressionId {
}
pub struct InjectedExpressionId {}
}
rustc_index::newtype_index! {
@ -70,8 +68,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)]
#[max = 0xFFFF_FFFF]
#[debug_format = "InjectedExpressionIndex({})"]
pub struct InjectedExpressionIndex {
}
pub struct InjectedExpressionIndex {}
}
rustc_index::newtype_index! {
@ -81,8 +78,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)]
#[max = 0xFFFF_FFFF]
#[debug_format = "MappedExpressionIndex({})"]
pub struct MappedExpressionIndex {
}
pub struct MappedExpressionIndex {}
}
impl From<CounterValueReference> for ExpressionOperandId {

View File

@ -657,7 +657,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)]
#[debug_format = "_{}"]
pub struct Local {
const RETURN_PLACE = 0,
const RETURN_PLACE = 0;
}
}
@ -1149,7 +1149,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)]
#[debug_format = "bb{}"]
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
#[derive(HashStable)]
#[debug_format = "field[{}]"]
pub struct Field {
}
pub struct Field {}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@ -1760,7 +1759,7 @@ rustc_index::newtype_index! {
#[derive(HashStable)]
#[debug_format = "scope[{}]"]
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! {
#[derive(HashStable)]
#[debug_format = "promoted[{}]"]
pub struct Promoted {
}
pub struct Promoted {}
}
impl<'tcx> Debug for Constant<'tcx> {

View File

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

View File

@ -36,8 +36,7 @@ macro_rules! thir_with_elements {
newtype_index! {
#[derive(HashStable)]
#[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**.
#[derive(HashStable)]
#[debug_format = "'_#{}r"]
pub struct RegionVid {
}
pub struct RegionVid {}
}
impl Atom for RegionVid {
@ -1391,7 +1390,7 @@ impl Atom for RegionVid {
rustc_index::newtype_index! {
#[derive(HashStable)]
pub struct BoundVar { .. }
pub struct BoundVar {}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]

View File

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

View File

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

View File

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

View File

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

View File

@ -284,7 +284,7 @@ rustc_index::newtype_index! {
/// A node in the control-flow graph of CoverageGraph.
#[debug_format = "bcb{}"]
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! {
#[debug_format = "v({})"]
pub struct Variable {
}
pub struct Variable {}
}
rustc_index::newtype_index! {
#[debug_format = "ln({})"]
pub struct LiveNode {
}
pub struct LiveNode {}
}
#[derive(Copy, Clone, PartialEq, Debug)]

View File

@ -37,7 +37,7 @@ pub struct DepGraph<K: DepKind> {
}
rustc_index::newtype_index! {
pub struct DepNodeIndex { .. }
pub struct DepNodeIndex {}
}
impl DepNodeIndex {
@ -974,7 +974,7 @@ pub struct WorkProduct {
// Index type for `DepNodeData`'s edges.
rustc_index::newtype_index! {
struct EdgeIndex { .. }
struct EdgeIndex {}
}
/// `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.
rustc_index::newtype_index! {
#[max = 0x7FFF_FFFF]
pub struct SerializedDepNodeIndex {
}
pub struct SerializedDepNodeIndex {}
}
/// Data for use when recompiling the **current crate**.

View File

@ -12,8 +12,7 @@ use std::hash::{Hash, Hasher};
rustc_index::newtype_index! {
#[custom_encodable]
#[debug_format = "crate{}"]
pub struct CrateNum {
}
pub struct CrateNum {}
}
/// Item definitions in the currently-compiled crate would have the `CrateNum`
@ -199,7 +198,7 @@ rustc_index::newtype_index! {
pub struct DefIndex {
/// The crate root is always assigned index 0 by the AST Map code,
/// 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! {
/// A unique ID associated with a macro invocation and expansion.
#[custom_encodable]
pub struct ExpnIndex {
}
pub struct ExpnIndex {}
}
/// A unique ID associated with a macro invocation and expansion.
@ -85,8 +84,7 @@ rustc_index::newtype_index! {
#[custom_encodable]
#[no_ord_impl]
#[debug_format = "expn{}"]
pub struct LocalExpnId {
}
pub struct LocalExpnId {}
}
// To ensure correctness of incremental compilation,

View File

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

View File

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

View File

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