Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve syntax of newtype_index #105880

Merged
merged 6 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2554,10 +2554,9 @@ pub enum AttrStyle {
}

rustc_index::newtype_index! {
pub struct AttrId {
ENCODABLE = custom
DEBUG_FORMAT = "AttrId({})"
}
#[custom_encodable]
#[debug_format = "AttrId({})]"]
pub struct AttrId {}
Noratrieb marked this conversation as resolved.
Show resolved Hide resolved
}

impl<S: Encoder> Encodable<S> for AttrId {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_ast/src/node_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ rustc_index::newtype_index! {
/// This is later turned into [`DefId`] and `HirId` for the HIR.
///
/// [`DefId`]: rustc_span::def_id::DefId
pub struct NodeId {
DEBUG_FORMAT = "NodeId({})"
}
#[debug_format = "NodeId({})"]
pub struct NodeId {}
}

rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId);
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_borrowck/src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,11 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
}

rustc_index::newtype_index! {
pub struct OutlivesConstraintIndex {
DEBUG_FORMAT = "OutlivesConstraintIndex({})"
}
#[debug_format = "OutlivesConstraintIndex({})"]
pub struct OutlivesConstraintIndex {}
}

rustc_index::newtype_index! {
pub struct ConstraintSccIndex {
DEBUG_FORMAT = "ConstraintSccIndex({})"
}
#[debug_format = "ConstraintSccIndex({})"]
pub struct ConstraintSccIndex {}
}
5 changes: 2 additions & 3 deletions compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ impl_visitable! {
}

rustc_index::newtype_index! {
pub struct BorrowIndex {
DEBUG_FORMAT = "bw{}"
}
#[debug_format = "bw{}"]
pub struct BorrowIndex {}
}

/// `Borrows` stores the data used in the analyses that track the flow
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_borrowck/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ pub struct LocationTable {
}

rustc_index::newtype_index! {
pub struct LocationIndex {
DEBUG_FORMAT = "LocationIndex({})"
}
#[debug_format = "LocationIndex({})"]
pub struct LocationIndex {}
}

#[derive(Copy, Clone, Debug)]
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_borrowck/src/member_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ pub(crate) struct NllMemberConstraint<'tcx> {
}

rustc_index::newtype_index! {
pub(crate) struct NllMemberConstraintIndex {
DEBUG_FORMAT = "MemberConstraintIndex({})"
}
#[debug_format = "MemberConstraintIndex({})"]
pub(crate) struct NllMemberConstraintIndex {}
}

impl Default for MemberConstraintSet<'_, ty::RegionVid> {
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_borrowck/src/region_infer/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ impl RegionValueElements {
rustc_index::newtype_index! {
/// A single integer representing a `Location` in the MIR control-flow
/// graph. Constructed efficiently from `RegionValueElements`.
pub struct PointIndex { DEBUG_FORMAT = "PointIndex({})" }
#[debug_format = "PointIndex({})"]
pub struct PointIndex {}
}

rustc_index::newtype_index! {
/// A single integer representing a `ty::Placeholder`.
pub struct PlaceholderIndex { DEBUG_FORMAT = "PlaceholderIndex({})" }
#[debug_format = "PlaceholderIndex({})"]
pub struct PlaceholderIndex {}
}

/// An individual element in a region value -- the value of a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Appearance {
}

rustc_index::newtype_index! {
pub struct AppearanceIndex { .. }
pub struct AppearanceIndex {}
}

impl vll::LinkElem for Appearance {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/graph/dominators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
// entire graph when there are many connected regions.

rustc_index::newtype_index! {
pub struct RegionId {
ENCODABLE = custom
}
#[custom_encodable]
pub struct RegionId {}
}

struct ConnectedRegion {
idents: SmallVec<[Symbol; 8]>,
impl_blocks: FxHashSet<usize>,
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ use rustc_index::vec::IndexVec;
use rustc_middle::ty::error::TypeError;

rustc_index::newtype_index! {
pub(crate) struct ExpectedIdx {
DEBUG_FORMAT = "ExpectedIdx({})",
}
#[debug_format = "ExpectedIdx({})"]
pub(crate) struct ExpectedIdx {}
}

rustc_index::newtype_index! {
pub(crate) struct ProvidedIdx {
DEBUG_FORMAT = "ProvidedIdx({})",
}
#[debug_format = "ProvidedIdx({})"]
pub(crate) struct ProvidedIdx {}
}

impl ExpectedIdx {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ fn for_each_consumable<'tcx>(hir: Map<'tcx>, place: TrackedValue, mut f: impl Fn
}

rustc_index::newtype_index! {
pub struct PostOrderId {
DEBUG_FORMAT = "id({})",
}
#[debug_format = "id({})"]
pub struct PostOrderId {}
}

rustc_index::newtype_index! {
pub struct TrackedValueIndex {
DEBUG_FORMAT = "hidx({})",
}
#[debug_format = "hidx({})"]
pub struct TrackedValueIndex {}
}

/// Identifies a value whose drop state we need to track.
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_index/src/vec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// Allows the macro invocation below to work
use crate as rustc_index;

rustc_macros::newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA });
rustc_macros::newtype_index! {
#[max = 0xFFFF_FFFA]
struct MyIdx {}
}

#[test]
fn index_size_is_optimized() {
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_infer/src/infer/region_constraints/leak_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,13 @@ impl<'tcx> SccUniverse<'tcx> {
}

rustc_index::newtype_index! {
struct LeakCheckNode {
DEBUG_FORMAT = "LeakCheckNode({})"
}
#[debug_format = "LeakCheckNode({})"]
struct LeakCheckNode {}
}

rustc_index::newtype_index! {
struct LeakCheckScc {
DEBUG_FORMAT = "LeakCheckScc({})"
}
#[debug_format = "LeakCheckScc({})"]
struct LeakCheckScc {}
}

/// Represents the graph of constraints. For each `R1: R2` constraint we create
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ 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,
const COMMAND_LINE = 0;
}
}

Expand Down
Loading