8000 Rollup of 15 pull requests by jonas-schievink · Pull Request #78319 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 15 pull requests #78319

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

Merged
merged 40 commits into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
16e10bf
Revert "Allow dynamic linking for iOS/tvOS targets."
francesca64 Oct 7, 2020
b62b352
Check for exhaustion in RangeInclusive::contains
cuviper Oct 19, 2020
9fd79a3
make exhausted RangeInclusive::end_bound return Excluded(end)
cuviper Oct 19, 2020
a9470d0
Simplify assert terminator only if condition evaluates to expected value
tmiasko Oct 21, 2020
9202fbd
Check for exhaustion in SliceIndex for RangeInclusive
cuviper Oct 21, 2020
40ab18d
improve const infer error
lcnr Oct 22, 2020
9775ac6
Document inline-const in the Unstable Book
camelid Oct 22, 2020
09135e4
Add regression test for issue-77475
JohnTitor Oct 23, 2020
e1c524c
review
lcnr Oct 23, 2020
9b90e17
add `insert` and `insert_with` to `Option`
Canop Oct 1, 2020
e8df2a4
remove `option.insert_with`
Canop Oct 1, 2020
60a96ca
more tests in option.insert, code cleaning in option
Canop Oct 1, 2020
cc8b77a
fix naming unconsistency between function doc and prototype
Canop Oct 3, 2020
3955779
Update library/core/src/option.rs
Canop Oct 23, 2020
415a8e5
Update library/core/src/option.rs
Canop Oct 23, 2020
8000
216d0fe
add tracking issue number to option_insert feature gate
Canop Oct 23, 2020
efedcb2
Update description of Empty Enum for accuracy
Enet4 Oct 23, 2020
972d9e8
move `visit_predicate` into `TypeVisitor`
lcnr Oct 23, 2020
a0ce1e0
Always store Rustdoc theme when it's changed
nasso Oct 23, 2020
a7bc1a2
Make codegen coverage_context optional, and check
richkadel Oct 23, 2020
c3cbaf6
x.py test --test-args flag description enhancement
njasm Oct 22, 2020
929f80e
Add a spin loop hint for Arc::downgrade
nicbn Sep 12, 2020
6640a62
Revert "Set .llvmbc and .llvmcmd sections as allocatable"
tmandry Oct 23, 2020
f75a236
Update compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
richkadel Oct 23, 2020
f88d6e8
Loop instead of recursion
bugadani Oct 23, 2020
8e75669
Rollup merge of #76649 - nicbn:arc-spin-loop-hint, r=m-ou-se
jonas-schievink Oct 24, 2020
d7c635b
Rollup merge of #77392 - Canop:option_insert, r=m-ou-se
jonas-schievink Oct 24, 2020
fb92b70
Rollup merge of #77716 - francesca64:revert-ios-dynamic-linking, r=jo…
jonas-schievink Oct 24, 2020
d9acd7d
Rollup merge of #78109 - cuviper:exhausted-rangeinc, r=dtolnay
jonas-schievink Oct 24, 2020
86c07a4
Rollup merge of #78198 - tmiasko:assert, r=davidtwco
jonas-schievink Oct 24, 2020
6b2ed99
Rollup merge of #78243 - njasm:patch_test_args_description, r=jyn514
jonas-schievink Oct 24, 2020
77cd5b5
Rollup merge of #78249 - lcnr:ct-infer-origin, r=varkor
jonas-schievink Oct 24, 2020
20ba9ff
Rollup merge of #78250 - camelid:document-inline-const, r=spastorino
jonas-schievink Oct 24, 2020
27cb587
Rollup merge of #78264 - JohnTitor:macro-test, r=petrochenkov
jonas-schievink Oct 24, 2020
eaa9823
Rollup merge of #78274 - Enet4:patch-1, r=jonas-schievink
jonas-schievink Oct 24, 2020
b6ae1fa
Rollup merge of #78278 - lcnr:predicate-visit, r=matthewjasper
jonas-schievink Oct 24, 2020
2362659
Rollup merge of #78292 - bugadani:recursion, r=nagisa
jonas-schievink Oct 24, 2020
a07fc3d
Rollup merge of #78293 - nasso:master, r=GuillaumeGomez
jonas-schievink Oct 24, 2020
da48646
Rollup merge of #78300 - richkadel:coverage-cx, r=wesleywiser
jonas-schievink Oct 24, 2020
1ac137b
Rollup merge of #78307 - rust-lang:revert-77961-embed-bitcode, r=tmandry
jonas-schievink Oct 24, 2020
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
Prev Previous commit
Next Next commit
Check for exhaustion in SliceIndex for RangeInclusive
  • Loading branch information
cuviper committed Oct 21, 2020
commit 9202fbdbdbd60adb62839c3230738274e30f15fc
29 changes: 29 additions & 0 deletions library/alloc/tests/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,13 @@ mod slice_index {
message: "out of bounds";
}

in mod rangeinclusive_len {
data: "abcdef";
good: data[0..=5] == "abcdef";
bad: data[0..=6];
message: "out of bounds";
}

in mod range_len_len {
data: "abcdef";
good: data[6..6] == "";
Expand All @@ -544,6 +551,28 @@ mod slice_index {
}
}

panic_cases! {
in mod rangeinclusive_exhausted {
data: "abcdef";

good: data[0..=5] == "abcdef";
good: data[{
let mut iter = 0..=5;
iter.by_ref().count(); // exhaust it
iter
}] == "";

// 0..=6 is out of bounds before exhaustion, so it
// stands to reason that it still would be after.
bad: data[{
let mut iter = 0..=6;
iter.by_ref().count(); // exhaust it
iter
}];
message: "out of bounds";
}
}

panic_cases! {
in mod range_neg_width {
data: "abcdef";
Expand Down
14 changes: 14 additions & 0 deletions library/core/src/ops/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,20 @@ impl<Idx> RangeInclusive<Idx> {
}
}

impl RangeInclusive<usize> {
/// Converts to an exclusive `Range` for `SliceIndex` implementations.
/// The caller is responsible for dealing with `end == usize::MAX`.
#[inline]
pub(crate) fn into_slice_range(self) -> Range<usize> {
// If we're not exhausted, we want to simply slice `start..end + 1`.
// If we are exhausted, then slicing with `end + 1..end + 1` gives us an
// empty range that is still subject to bounds-checks for that endpoint.
let exclusive_end = self.end + 1;
let start = if self.exhausted { exclusive_end } else { self.start };
start..exclusive_end
}
}

#[stable(feature = "inclusive_range", since = "1.26.0")]
impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
16 changes: 6 additions & 10 deletions library/core/src/slice/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,44 +376,40 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeInclusive<usize> {

#[inline]
fn get(self, slice: &[T]) -> Option<&[T]> {
if *self.end() == usize::MAX { None } else { (*self.start()..self.end() + 1).get(slice) }
if *self.end() == usize::MAX { None } else { self.into_slice_range().get(slice) }
}

#[inline]
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]> {
if *self.end() == usize::MAX {
None
} else {
(*self.start()..self.end() + 1).get_mut(slice)
}
if *self.end() == usize::MAX { None } else { self.into_slice_range().get_mut(slice) }
}

#[inline]
unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T] {
// SAFETY: the caller has to uphold the safety contract for `get_unchecked`.
unsafe { (*self.start()..self.end() + 1).get_unchecked(slice) }
unsafe { self.into_slice_range().get_unchecked(slice) }
}

#[inline]
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T] {
// SAFETY: the caller has to uphold the safety contract for `get_unchecked_mut`.
unsafe { (*self.start()..self.end() + 1).get_unchecked_mut(slice) }
unsafe { self.into_slice_range().get_unchecked_mut(slice) }
}

#[inline]
fn index(self, slice: &[T]) -> &[T] {
if *self.end() == usize::MAX {
slice_end_index_overflow_fail();
}
(*self.start()..self.end() + 1).index(slice)
self.into_slice_range().index(slice)
}

#[inline]
fn index_mut(self, slice: &mut [T]) -> &mut [T] {
if *self.end() == usize::MAX {
slice_end_index_overflow_fail();
}
(*self.start()..self.end() + 1).index_mut(slice)
self.into_slice_range().index_mut(slice)
}
}

Expand Down
16 changes: 6 additions & 10 deletions library/core/src/str/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,39 +398,35 @@ unsafe impl SliceIndex<str> for ops::RangeInclusive<usize> {
type Output = str;
#[inline]
fn get(self, slice: &str) -> Option<&Self::Output> {
if *self.end() == usize::MAX { None } else { (*self.start()..self.end() + 1).get(slice) }
if *self.end() == usize::MAX { None } else { self.into_slice_range().get(slice) }
}
#[inline]
fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output> {
if *self.end() == usize::MAX {
None
} else {
(*self.start()..self.end() + 1).get_mut(slice)
}
if *self.end() == usize::MAX { None } else { self.into_slice_range().get_mut(slice) }
}
#[inline]
unsafe fn get_unchecked(self, slice: *const str) -> *const Self::Output {
// SAFETY: the caller must uphold the safety contract for `get_unchecked`.
unsafe { (*self.start()..self.end() + 1).get_unchecked(slice) }
unsafe { self.into_slice_range().get_unchecked(slice) }
}
#[inline]
unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut Self::Output {
// SAFETY: the caller must uphold the safety contract for `get_unchecked_mut`.
unsafe { (*self.start()..self.end() + 1).get_unchecked_mut(slice) }
unsafe { self.into_slice_range().get_unchecked_mut(slice) }
}
#[inline]
fn index(self, slice: &str) -> &Self::Output {
if *self.end() == usize::MAX {
str_index_overflow_fail();
}
(*self.start()..self.end() + 1).index(slice)
self.into_slice_range().index(slice)
}
#[inline]
fn index_mut(self, slice: &mut str) -> &mut Self::Output {
if *self.end() == usize::MAX {
str_index_overflow_fail();
}
(*self.start()..self.end() + 1).index_mut(slice)
self.into_slice_range().index_mut(slice)
}
}

Expand Down
30 changes: 30 additions & 0 deletions library/core/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,14 @@ mod slice_index {
message: "out of range";
}

in mod rangeinclusive_len {
data: [0, 1, 2, 3, 4, 5];

good: data[0..=5] == [0, 1, 2, 3, 4, 5];
bad: data[0..=6];
message: "out of range";
}

in mod range_len_len {
data: [0, 1, 2, 3, 4, 5];

Expand All @@ -1358,6 +1366,28 @@ mod slice_index {
}
}

panic_cases! {
in mod rangeinclusive_exhausted {
data: [0, 1, 2, 3, 4, 5];

good: data[0..=5] == [0, 1, 2, 3, 4, 5];
good: data[{
let mut iter = 0..=5;
iter.by_ref().count(); // exhaust it
iter
}] == [];

// 0..=6 is out of range before exhaustion, so it
// stands to reason that it still would be after.
bad: data[{
let mut iter = 0..=6;
iter.by_ref().count(); // exhaust it
iter
}];
message: "out of range";
}
}

panic_cases! {
in mod range_neg_width {
data: [0, 1, 2, 3, 4, 5];
Expand Down
0