Skip to content

Commit 04d1052

Browse files
authored
Rollup merge of rust-lang#139811 - yotamofek:pr/newtype_cleanups, r=oli-obk
Use `newtype_index!`-generated types more idiomatically Continuation of sorts of rust-lang#139674 Shouldn't affect anything, just makes some code simpler
2 parents 7dc3fec + 4b63362 commit 04d1052

File tree

20 files changed

+61
-87
lines changed

20 files changed

+61
-87
lines changed

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
448448

449449
generic_args.args.insert_many(
450450
0,
451-
(start.as_u32()..end.as_u32()).map(|i| {
452-
let id = NodeId::from_u32(i);
451+
(start..end).map(|id| {
453452
let l = self.lower_lifetime_anon_in_path(id, elided_lifetime_span);
454453
GenericArg::Lifetime(l)
455454
}),

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
338338
let num_components = sccs.num_sccs();
339339
let mut components = vec![FxIndexSet::default(); num_components];
340340

341-
for (reg_var_idx, scc_idx) in sccs.scc_indices().iter().enumerate() {
342-
let reg_var = ty::RegionVid::from_usize(reg_var_idx);
341+
for (reg_var, scc_idx) in sccs.scc_indices().iter_enumerated() {
343342
let origin = var_to_origin.get(&reg_var).unwrap_or(&RegionCtxt::Unknown);
344343
components[scc_idx.as_usize()].insert((reg_var, *origin));
345344
}

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::collections::hash_map::Entry;
33
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext};
44
use rustc_codegen_ssa::traits::*;
55
use rustc_data_structures::fx::FxHashMap;
6-
use rustc_index::Idx;
76
use rustc_index::bit_set::DenseBitSet;
87
use rustc_middle::mir::{Body, SourceScope};
98
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};
@@ -43,8 +42,7 @@ pub(crate) fn compute_mir_scopes<'ll, 'tcx>(
4342
let mut instantiated = DenseBitSet::new_empty(mir.source_scopes.len());
4443
let mut discriminators = FxHashMap::default();
4544
// Instantiate all scopes.
46-
for idx in 0..mir.source_scopes.len() {
47-
let scope = SourceScope::new(idx);
45+
for scope in mir.source_scopes.indices() {
4846
make_mir_scope(
4947
cx,
5048
instance,

compiler/rustc_hir/src/definitions.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,9 @@ impl DefPathTable {
4747
debug_assert_eq!(self.stable_crate_id, def_path_hash.stable_crate_id());
4848
let local_hash = def_path_hash.local_hash();
4949

50-
let index = {
51-
let index = DefIndex::from(self.index_to_key.len());
52-
debug!("DefPathTable::insert() - {:?} <-> {:?}", key, index);
53-
self.index_to_key.push(key);
54-
index
55-
};
50+
let index = self.index_to_key.push(key);
51+
debug!("DefPathTable::insert() - {key:?} <-> {index:?}");
52+
5653
self.def_path_hashes.push(local_hash);
5754
debug_assert!(self.def_path_hashes.len() == self.index_to_key.len());
5855

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
606606
// with placeholders, which imply nothing about outlives bounds, and then
607607
// prove below that the hidden types are well formed.
608608
let universe = infcx.create_next_universe();
609-
let mut idx = 0;
609+
let mut idx = ty::BoundVar::ZERO;
610610
let mapping: FxIndexMap<_, _> = collector
611611
.types
612612
.iter()
@@ -623,10 +623,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
623623
tcx,
624624
ty::Placeholder {
625625
universe,
626-
bound: ty::BoundTy {
627-
var: ty::BoundVar::from_usize(idx),
628-
kind: ty::BoundTyKind::Anon,
629-
},
626+
bound: ty::BoundTy { var: idx, kind: ty::BoundTyKind::Anon },
630627
},
631628
),
632629
)

compiler/rustc_infer/src/infer/region_constraints/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
618618
RegionVid::from(value_count)..RegionVid::from(self.storage.unification_table.len());
619619
(
620620
range.clone(),
621-
(range.start.index()..range.end.index())
622-
.map(|index| self.storage.var_infos[ty::RegionVid::from(index)].origin)
623-
.collect(),
621+
(range.start..range.end).map(|index| self.storage.var_infos[index].origin).collect(),
624622
)
625623
}
626624

compiler/rustc_infer/src/infer/snapshot/fudge.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ fn const_vars_since_snapshot<'tcx>(
3030
snapshot_var_len: usize,
3131
) -> (Range<ConstVid>, Vec<ConstVariableOrigin>) {
3232
let range = vars_since_snapshot(table, snapshot_var_len);
33+
let range = range.start.vid..range.end.vid;
3334

3435
(
35-
range.start.vid..range.end.vid,
36-
(range.start.index()..range.end.index())
37-
.map(|index| match table.probe_value(ConstVid::from_u32(index)) {
36+
range.clone(),
37+
range
38+
.map(|index| match table.probe_value(index) {
3839
ConstVariableValue::Known { value: _ } => {
3940
ConstVariableOrigin { param_def_id: None, span: rustc_span::DUMMY_SP }
4041
}

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,12 @@ fn write_mir_intro<'tcx>(
531531

532532
// construct a scope tree and write it out
533533
let mut scope_tree: FxHashMap<SourceScope, Vec<SourceScope>> = Default::default();
534-
for (index, scope_data) in body.source_scopes.iter().enumerate() {
534+
for (index, scope_data) in body.source_scopes.iter_enumerated() {
535535
if let Some(parent) = scope_data.parent_scope {
536-
scope_tree.entry(parent).or_default().push(SourceScope::new(index));
536+
scope_tree.entry(parent).or_default().push(index);
537537
} else {
538538
// Only the argument scope has no parent, because it's the root.
539-
assert_eq!(index, OUTERMOST_SOURCE_SCOPE.index());
539+
assert_eq!(index, OUTERMOST_SOURCE_SCOPE);
540540
}
541541
}
542542

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'tcx> TyCtxt<'tcx> {
278278
where
279279
T: TypeFoldable<TyCtxt<'tcx>>,
280280
{
281-
let shift_bv = |bv: ty::BoundVar| ty::BoundVar::from_usize(bv.as_usize() + bound_vars);
281+
let shift_bv = |bv: ty::BoundVar| bv + bound_vars;
282282
self.replace_escaping_bound_vars_uncached(
283283
value,
284284
FnMutDelegate {

compiler/rustc_middle/src/ty/visit.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,29 +231,23 @@ impl MaxUniverse {
231231
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for MaxUniverse {
232232
fn visit_ty(&mut self, t: Ty<'tcx>) {
233233
if let ty::Placeholder(placeholder) = t.kind() {
234-
self.max_universe = ty::UniverseIndex::from_u32(
235-
self.max_universe.as_u32().max(placeholder.universe.as_u32()),
236-
);
234+
self.max_universe = self.max_universe.max(placeholder.universe);
237235
}
238236

239237
t.super_visit_with(self)
240238
}
241239

242240
fn visit_const(&mut self, c: ty::consts::Const<'tcx>) {
243241
if let ty::ConstKind::Placeholder(placeholder) = c.kind() {
244-
self.max_universe = ty::UniverseIndex::from_u32(
245-
self.max_universe.as_u32().max(placeholder.universe.as_u32()),
246-
);
242+
self.max_universe = self.max_universe.max(placeholder.universe);
247243
}
248244

249245
c.super_visit_with(self)
250246
}
251247

252248
fn visit_region(&mut self, r: ty::Region<'tcx>) {
253249
if let ty::RePlaceholder(placeholder) = r.kind() {
254-
self.max_universe = ty::UniverseIndex::from_u32(
255-
self.max_universe.as_u32().max(placeholder.universe.as_u32()),
256-
);
250+
self.max_universe = self.max_universe.max(placeholder.universe);
257251
}
258252
}
259253
}

0 commit comments

Comments
 (0)