Skip to content

Commit 0790996

Browse files
authored
Rollup merge of rust-lang#110394 - scottmcm:less-idx-new, r=WaffleLapkin
Various minor Idx-related tweaks Nothing particularly exciting here, but a couple of things I noticed as I was looking for more index conversions to simplify. cc rust-lang/compiler-team#606 r? `@WaffleLapkin`
2 parents a6c1fa5 + c98895d commit 0790996

File tree

17 files changed

+55
-52
lines changed

17 files changed

+55
-52
lines changed

compiler/rustc_abi/src/layout.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ pub trait LayoutCalculator {
461461
let all_indices = variants.indices();
462462
let needs_disc =
463463
|index: VariantIdx| index != largest_variant_index && !absent(&variants[index]);
464-
let niche_variants = all_indices.clone().find(|v| needs_disc(*v)).unwrap().index()
465-
..=all_indices.rev().find(|v| needs_disc(*v)).unwrap().index();
464+
let niche_variants = all_indices.clone().find(|v| needs_disc(*v)).unwrap()
465+
..=all_indices.rev().find(|v| needs_disc(*v)).unwrap();
466466

467467
let count = niche_variants.size_hint().1.unwrap() as u128;
468468

@@ -560,8 +560,7 @@ pub trait LayoutCalculator {
560560
tag: niche_scalar,
561561
tag_encoding: TagEncoding::Niche {
562562
untagged_variant: largest_variant_index,
563-
niche_variants: (VariantIdx::new(*niche_variants.start())
564-
..=VariantIdx::new(*niche_variants.end())),
563+
niche_variants,
565564
niche_start,
566565
},
567566
tag_field: 0,

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use bitflags::bitflags;
1111
use rustc_data_structures::intern::Interned;
1212
#[cfg(feature = "nightly")]
1313
use rustc_data_structures::stable_hasher::StableOrd;
14-
use rustc_index::vec::{Idx, IndexSlice, IndexVec};
14+
use rustc_index::vec::{IndexSlice, IndexVec};
1515
#[cfg(feature = "nightly")]
1616
use rustc_macros::HashStable_Generic;
1717
#[cfg(feature = "nightly")]

compiler/rustc_ast/src/node_id.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ rustc_index::newtype_index! {
99
///
1010
/// [`DefId`]: rustc_span::def_id::DefId
1111
#[debug_format = "NodeId({})"]
12-
pub struct NodeId {}
12+
pub struct NodeId {
13+
/// The [`NodeId`] used to represent the root of the crate.
14+
const CRATE_NODE_ID = 0;
15+
}
1316
}
1417

1518
rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId);
1619

17-
/// The [`NodeId`] used to represent the root of the crate.
18-
pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0);
19-
2020
/// When parsing and at the beginning of doing expansions, we initially give all AST nodes
2121
/// this dummy AST [`NodeId`]. Then, during a later phase of expansion, we renumber them
2222
/// to have small, positive IDs.

compiler/rustc_borrowck/src/diagnostics/var_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use crate::region_infer::RegionInferenceContext;
55
use crate::Upvar;
6-
use rustc_index::vec::{Idx, IndexSlice};
6+
use rustc_index::vec::IndexSlice;
77
use rustc_middle::mir::{Body, Local};
88
use rustc_middle::ty::{RegionVid, TyCtxt};
99
use rustc_span::source_map::Span;
@@ -117,7 +117,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
117117
argument_index: usize,
118118
) -> (Option<Symbol>, Span) {
119119
let implicit_inputs = self.universal_regions().defining_ty.implicit_inputs();
120-
let argument_local = Local::new(implicit_inputs + argument_index + 1);
120+
let argument_local = Local::from_usize(implicit_inputs + argument_index + 1);
121121
debug!("get_argument_name_and_span_for_region: argument_local={argument_local:?}");
122122

123123
let argument_name = local_names[argument_local];

compiler/rustc_borrowck/src/facts.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::location::{LocationIndex, LocationTable};
44
use crate::BorrowIndex;
55
use polonius_engine::AllFacts as PoloniusFacts;
66
use polonius_engine::Atom;
7-
use rustc_index::vec::Idx;
87
use rustc_middle::mir::Local;
98
use rustc_middle::ty::{RegionVid, TyCtxt};
109
use rustc_mir_dataflow::move_paths::MovePathIndex;
@@ -93,13 +92,13 @@ impl AllFactsExt for AllFacts {
9392

9493
impl Atom for BorrowIndex {
9594
fn index(self) -> usize {
96-
Idx::index(self)
95+
self.as_usize()
9796
}
9897
}
9998

10099
impl Atom for LocationIndex {
101100
fn index(self) -> usize {
102-
Idx::index(self)
101+
self.as_usize()
103102
}
104103
}
105104

compiler/rustc_borrowck/src/location.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![deny(rustc::untranslatable_diagnostic)]
22
#![deny(rustc::diagnostic_outside_of_impl)]
3-
use rustc_index::vec::{Idx, IndexVec};
3+
use rustc_index::vec::IndexVec;
44
use rustc_middle::mir::{BasicBlock, Body, Location};
55

66
/// Maps between a MIR Location, which identifies a particular
@@ -50,19 +50,19 @@ impl LocationTable {
5050
}
5151

5252
pub fn all_points(&self) -> impl Iterator<Item = LocationIndex> {
53-
(0..self.num_points).map(LocationIndex::new)
53+
(0..self.num_points).map(LocationIndex::from_usize)
5454
}
5555

5656
pub fn start_index(&self, location: Location) -> LocationIndex {
5757
let Location { block, statement_index } = location;
5858
let start_index = self.statements_before_block[block];
59-
LocationIndex::new(start_index + statement_index * 2)
59+
LocationIndex::from_usize(start_index + statement_index * 2)
6060
}
6161

6262
pub fn mid_index(&self, location: Location) -> LocationIndex {
6363
let Location { block, statement_index } = location;
6464
let start_index = self.statements_before_block[block];
65-
LocationIndex::new(start_index + statement_index * 2 + 1)
65+
LocationIndex::from_usize(start_index + statement_index * 2 + 1)
6666
}
6767

6868
pub fn to_location(&self, index: LocationIndex) -> RichLocation {

compiler/rustc_borrowck/src/nll.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_hir::def_id::LocalDefId;
77
use rustc_index::vec::IndexSlice;
88
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
99
use rustc_middle::mir::{
10-
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
11-
Promoted,
10+
Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, Promoted,
11+
START_BLOCK,
1212
};
1313
use rustc_middle::ty::{self, OpaqueHiddenType, TyCtxt};
1414
use rustc_span::symbol::sym;
@@ -94,8 +94,8 @@ fn populate_polonius_move_facts(
9494
}
9595
}
9696

97-
let fn_entry_start = location_table
98-
.start_index(Location { block: BasicBlock::from_u32(0u32), statement_index: 0 });
97+
let fn_entry_start =
98+
location_table.start_index(Location { block: START_BLOCK, statement_index: 0 });
9999

100100
// initialized_at
101101
for init in move_data.inits.iter() {

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
88
//! contain revealed `impl Trait` values).
99
10-
use rustc_index::vec::Idx;
1110
use rustc_infer::infer::LateBoundRegionConversionTime;
1211
use rustc_middle::mir::*;
1312
use rustc_middle::ty::{self, Ty};
@@ -83,7 +82,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
8382
}
8483

8584
// In MIR, argument N is stored in local N+1.
86-
let local = Local::new(argument_index + 1);
85+
let local = Local::from_usize(argument_index + 1);
8786

8887
let mir_input_ty = body.local_decls[local].ty;
8988

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_hir as hir;
1919
use rustc_hir::def_id::{DefId, LocalDefId};
2020
use rustc_hir::lang_items::LangItem;
2121
use rustc_hir::BodyOwnerKind;
22-
use rustc_index::vec::{Idx, IndexVec};
22+
use rustc_index::vec::IndexVec;
2323
use rustc_infer::infer::NllRegionVariableOrigin;
2424
use rustc_middle::ty::fold::TypeFoldable;
2525
use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt};
@@ -289,7 +289,7 @@ impl<'tcx> UniversalRegions<'tcx> {
289289
/// Returns an iterator over all the RegionVids corresponding to
290290
/// universally quantified free regions.
291291
pub fn universal_regions(&self) -> impl Iterator<Item = RegionVid> {
292-
(FIRST_GLOBAL_INDEX..self.num_universals).map(RegionVid::new)
292+
(FIRST_GLOBAL_INDEX..self.num_universals).map(RegionVid::from_usize)
293293
}
294294

295295
/// Returns `true` if `r` is classified as an local region.

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::MemFlags;
1212
use rustc_ast as ast;
1313
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1414
use rustc_hir::lang_items::LangItem;
15-
use rustc_index::vec::Idx;
1615
use rustc_middle::mir::{self, AssertKind, SwitchTargets};
1716
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement};
1817
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
@@ -369,7 +368,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
369368
if self.fn_abi.c_variadic {
370369
// The `VaList` "spoofed" argument is just after all the real arguments.
371370
let va_list_arg_idx = self.fn_abi.args.len();
372-
match self.locals[mir::Local::new(1 + va_list_arg_idx)] {
371+
match self.locals[mir::Local::from_usize(1 + va_list_arg_idx)] {
373372
LocalRef::Place(va_list) => {
374373
bx.va_end(va_list.llval);
375374
}

0 commit comments

Comments
 (0)