Skip to content

Commit c916ee8

Browse files
committed
Removed direct field usage of RangeInclusive in rustc itself.
1 parent fba903a commit c916ee8

File tree

13 files changed

+45
-48
lines changed

13 files changed

+45
-48
lines changed

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#![feature(untagged_unions)]
104104
#![feature(unwind_attributes)]
105105
#![feature(doc_alias)]
106+
#![feature(inclusive_range_methods)]
106107

107108
#![cfg_attr(not(stage0), feature(mmx_target_feature))]
108109
#![cfg_attr(not(stage0), feature(tbm_target_feature))]

src/libcore/ops/range.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
318318
/// # Examples
319319
///
320320
/// ```
321-
/// #![feature(inclusive_range_fields)]
321+
/// #![feature(inclusive_range_methods)]
322322
///
323323
/// assert_eq!((3..=5), std::ops::RangeInclusive::new(3, 5));
324324
/// assert_eq!(3 + 4 + 5, (3..=5).sum());

src/libcore/tests/ops.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@ fn test_full_range() {
5050

5151
#[test]
5252
fn test_range_inclusive() {
53-
let mut r = RangeInclusive { start: 1i8, end: 2 };
53+
let mut r = RangeInclusive::new(1i8, 2);
5454
assert_eq!(r.next(), Some(1));
5555
assert_eq!(r.next(), Some(2));
5656
assert_eq!(r.next(), None);
5757

58-
r = RangeInclusive { start: 127i8, end: 127 };
58+
r = RangeInclusive::new(127i8, 127);
5959
assert_eq!(r.next(), Some(127));
6060
assert_eq!(r.next(), None);
6161

62-
r = RangeInclusive { start: -128i8, end: -128 };
62+
r = RangeInclusive::new(-128i8, -128);
6363
assert_eq!(r.next_back(), Some(-128));
6464
assert_eq!(r.next_back(), None);
6565

6666
// degenerate
67-
r = RangeInclusive { start: 1, end: -1 };
67+
r = RangeInclusive::new(1, -1);
6868
assert_eq!(r.size_hint(), (0, Some(0)));
6969
assert_eq!(r.next(), None);
7070
}

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
#![feature(trusted_len)]
7070
#![feature(catch_expr)]
7171
#![feature(test)]
72-
#![feature(inclusive_range_fields)]
72+
#![feature(inclusive_range_methods)]
7373

7474
#![recursion_limit="512"]
7575

src/librustc/ty/layout.rs

+20-24
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use std::cmp;
1919
use std::fmt;
2020
use std::i128;
2121
use std::mem;
22-
use std::ops::RangeInclusive;
2322

2423
use ich::StableHashingContext;
2524
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
@@ -492,7 +491,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
492491
ty::TyFloat(FloatTy::F64) => scalar(F64),
493492
ty::TyFnPtr(_) => {
494493
let mut ptr = scalar_unit(Pointer);
495-
ptr.valid_range.start = 1;
494+
ptr.valid_range = 1..=*ptr.valid_range.end();
496495
tcx.intern_layout(LayoutDetails::scalar(self, ptr))
497496
}
498497

@@ -506,7 +505,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
506505
ty::TyRawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
507506
let mut data_ptr = scalar_unit(Pointer);
508507
if !ty.is_unsafe_ptr() {
509-
data_ptr.valid_range.start = 1;
508+
data_ptr.valid_range = 1..=*data_ptr.valid_range.end();
510509
}
511510

512511
let pointee = tcx.normalize_erasing_regions(param_env, pointee);
@@ -524,7 +523,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
524523
}
525524
ty::TyDynamic(..) => {
526525
let mut vtable = scalar_unit(Pointer);
527-
vtable.valid_range.start = 1;
526+
vtable.valid_range = 1..=*vtable.valid_range.end();
528527
vtable
529528
}
530529
_ => return Err(LayoutError::Unknown(unsized_part))
@@ -751,8 +750,8 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
751750
match st.abi {
752751
Abi::Scalar(ref mut scalar) |
753752
Abi::ScalarPair(ref mut scalar, _) => {
754-
if scalar.valid_range.start == 0 {
755-
scalar.valid_range.start = 1;
753+
if *scalar.valid_range.start() == 0 {
754+
scalar.valid_range = 1..=*scalar.valid_range.end();
756755
}
757756
}
758757
_ => {}
@@ -788,18 +787,15 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
788787
}
789788
}
790789
}
791-
if niche_variants.start > v {
792-
niche_variants.start = v;
793-
}
794-
niche_variants.end = v;
790+
niche_variants = *niche_variants.start().min(&v)..=v;
795791
}
796792

797-
if niche_variants.start > niche_variants.end {
793+
if niche_variants.start() > niche_variants.end() {
798794
dataful_variant = None;
799795
}
800796

801797
if let Some(i) = dataful_variant {
802-
let count = (niche_variants.end - niche_variants.start + 1) as u128;
798+
let count = (niche_variants.end() - niche_variants.start() + 1) as u128;
803799
for (field_index, &field) in variants[i].iter().enumerate() {
804800
let (offset, niche, niche_start) =
805801
match self.find_niche(field, count)? {
@@ -1659,22 +1655,22 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
16591655
let max_value = !0u128 >> (128 - bits);
16601656

16611657
// Find out how many values are outside the valid range.
1662-
let niches = if v.start <= v.end {
1663-
v.start + (max_value - v.end)
1658+
let niches = if v.start() <= v.end() {
1659+
v.start() + (max_value - v.end())
16641660
} else {
1665-
v.start - v.end - 1
1661+
v.start() - v.end() - 1
16661662
};
16671663

16681664
// Give up if we can't fit `count` consecutive niches.
16691665
if count > niches {
16701666
return None;
16711667
}
16721668

1673-
let niche_start = v.end.wrapping_add(1) & max_value;
1674-
let niche_end = v.end.wrapping_add(count) & max_value;
1669+
let niche_start = v.end().wrapping_add(1) & max_value;
1670+
let niche_end = v.end().wrapping_add(count) & max_value;
16751671
Some((offset, Scalar {
16761672
value,
1677-
valid_range: v.start..=niche_end
1673+
valid_range: *v.start()..=niche_end
16781674
}, niche_start))
16791675
};
16801676

@@ -1744,14 +1740,14 @@ impl<'a> HashStable<StableHashingContext<'a>> for Variants {
17441740
}
17451741
NicheFilling {
17461742
dataful_variant,
1747-
niche_variants: RangeInclusive { start, end },
1743+
ref niche_variants,
17481744
ref niche,
17491745
niche_start,
17501746
ref variants,
17511747
} => {
17521748
dataful_variant.hash_stable(hcx, hasher);
1753-
start.hash_stable(hcx, hasher);
1754-
end.hash_stable(hcx, hasher);
1749+
niche_variants.start().hash_stable(hcx, hasher);
1750+
niche_variants.end().hash_stable(hcx, hasher);
17551751
niche.hash_stable(hcx, hasher);
17561752
niche_start.hash_stable(hcx, hasher);
17571753
variants.hash_stable(hcx, hasher);
@@ -1814,10 +1810,10 @@ impl<'a> HashStable<StableHashingContext<'a>> for Scalar {
18141810
fn hash_stable<W: StableHasherResult>(&self,
18151811
hcx: &mut StableHashingContext<'a>,
18161812
hasher: &mut StableHasher<W>) {
1817-
let Scalar { value, valid_range: RangeInclusive { start, end } } = *self;
1813+
let Scalar { value, ref valid_range } = *self;
18181814
value.hash_stable(hcx, hasher);
1819-
start.hash_stable(hcx, hasher);
1820-
end.hash_stable(hcx, hasher);
1815+
valid_range.start().hash_stable(hcx, hasher);
1816+
valid_range.end().hash_stable(hcx, hasher);
18211817
}
18221818
}
18231819

src/librustc_mir/interpret/eval_context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,8 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
917917
niche_start,
918918
..
919919
} => {
920-
let variants_start = niche_variants.start as u128;
921-
let variants_end = niche_variants.end as u128;
920+
let variants_start = *niche_variants.start() as u128;
921+
let variants_end = *niche_variants.end() as u128;
922922
match raw_discr {
923923
PrimVal::Ptr(_) => {
924924
assert!(niche_start == 0);
@@ -984,7 +984,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
984984
if variant_index != dataful_variant {
985985
let (niche_dest, niche) =
986986
self.place_field(dest, mir::Field::new(0), layout)?;
987-
let niche_value = ((variant_index - niche_variants.start) as u128)
987+
let niche_value = ((variant_index - niche_variants.start()) as u128)
988988
.wrapping_add(niche_start);
989989
self.write_primval(niche_dest, PrimVal::Bytes(niche_value), niche.ty)?;
990990
}

src/librustc_mir/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
3131
#![feature(range_contains)]
3232
#![feature(rustc_diagnostic_macros)]
3333
#![feature(nonzero)]
34-
#![feature(inclusive_range_fields)]
34+
#![feature(inclusive_range_methods)]
3535
#![feature(crate_visibility_modifier)]
3636
#![feature(never_type)]
3737
#![cfg_attr(stage0, feature(try_trait))]

src/librustc_target/abi/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,8 @@ impl Scalar {
555555
let bits = self.value.size(cx).bits();
556556
assert!(bits <= 128);
557557
let mask = !0u128 >> (128 - bits);
558-
let start = self.valid_range.start;
559-
let end = self.valid_range.end;
558+
let start = *self.valid_range.start();
559+
let end = *self.valid_range.end();
560560
assert_eq!(start, start & mask);
561561
assert_eq!(end, end & mask);
562562
start..(end.wrapping_add(1) & mask)

src/librustc_target/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#![feature(const_fn)]
3030
#![feature(fs_read_write)]
3131
#![feature(inclusive_range)]
32-
#![feature(inclusive_range_fields)]
32+
#![feature(inclusive_range_methods)]
3333
#![feature(slice_patterns)]
3434

3535
#[macro_use]

src/librustc_trans/abi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ impl<'a, 'tcx> FnTypeExt<'a, 'tcx> for FnType<'tcx, Ty<'tcx>> {
388388
return;
389389
}
390390

391-
if scalar.valid_range.start < scalar.valid_range.end {
392-
if scalar.valid_range.start > 0 {
391+
if scalar.valid_range.start() < scalar.valid_range.end() {
392+
if *scalar.valid_range.start() > 0 {
393393
attrs.set(ArgAttribute::NonNull);
394394
}
395395
}

src/librustc_trans/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
12361236
self.layout,
12371237
self.layout.fields.offset(0),
12381238
self.layout.field(cx, 0).size);
1239-
name.push_str(&adt.variants[niche_variants.start].name.as_str());
1239+
name.push_str(&adt.variants[*niche_variants.start()].name.as_str());
12401240

12411241
// Create the (singleton) list of descriptions of union members.
12421242
vec![

src/librustc_trans/mir/place.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
9999
bx.range_metadata(load, range);
100100
}
101101
}
102-
layout::Pointer if vr.start < vr.end && !vr.contains(&0) => {
102+
layout::Pointer if vr.start() < vr.end() && !vr.contains(&0) => {
103103
bx.nonnull_metadata(load);
104104
}
105105
_ => {}
@@ -287,7 +287,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
287287
..
288288
} => {
289289
let niche_llty = discr.layout.immediate_llvm_type(bx.cx);
290-
if niche_variants.start == niche_variants.end {
290+
if niche_variants.start() == niche_variants.end() {
291291
// FIXME(eddyb) Check the actual primitive type here.
292292
let niche_llval = if niche_start == 0 {
293293
// HACK(eddyb) Using `C_null` as it works on all types.
@@ -296,13 +296,13 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
296296
C_uint_big(niche_llty, niche_start)
297297
};
298298
bx.select(bx.icmp(llvm::IntEQ, lldiscr, niche_llval),
299-
C_uint(cast_to, niche_variants.start as u64),
299+
C_uint(cast_to, *niche_variants.start() as u64),
300300
C_uint(cast_to, dataful_variant as u64))
301301
} else {
302302
// Rebase from niche values to discriminant values.
303-
let delta = niche_start.wrapping_sub(niche_variants.start as u128);
303+
let delta = niche_start.wrapping_sub(*niche_variants.start() as u128);
304304
let lldiscr = bx.sub(lldiscr, C_uint_big(niche_llty, delta));
305-
let lldiscr_max = C_uint(niche_llty, niche_variants.end as u64);
305+
let lldiscr_max = C_uint(niche_llty, *niche_variants.end() as u64);
306306
bx.select(bx.icmp(llvm::IntULE, lldiscr, lldiscr_max),
307307
bx.intcast(lldiscr, cast_to, false),
308308
C_uint(cast_to, dataful_variant as u64))
@@ -352,7 +352,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
352352

353353
let niche = self.project_field(bx, 0);
354354
let niche_llty = niche.layout.immediate_llvm_type(bx.cx);
355-
let niche_value = ((variant_index - niche_variants.start) as u128)
355+
let niche_value = ((variant_index - *niche_variants.start()) as u128)
356356
.wrapping_add(niche_start);
357357
// FIXME(eddyb) Check the actual primitive type here.
358358
let niche_llval = if niche_value == 0 {

src/librustc_trans/mir/rvalue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,15 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
301301
if let layout::Int(_, s) = scalar.value {
302302
signed = s;
303303

304-
if scalar.valid_range.end > scalar.valid_range.start {
304+
if scalar.valid_range.end() > scalar.valid_range.start() {
305305
// We want `table[e as usize]` to not
306306
// have bound checks, and this is the most
307307
// convenient place to put the `assume`.
308308

309309
base::call_assume(&bx, bx.icmp(
310310
llvm::IntULE,
311311
llval,
312-
C_uint_big(ll_t_in, scalar.valid_range.end)
312+
C_uint_big(ll_t_in, *scalar.valid_range.end())
313313
));
314314
}
315315
}

0 commit comments

Comments
 (0)