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

Rollup of 10 pull requests #103562

Merged
merged 20 commits into from
Oct 26, 2022
Merged
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
cfcb0a2
Use a faster allocation size check in slice::from_raw_parts
saethlin Oct 20, 2022
74d4eef
Workaround unstable stmt_expr_attributes for method receiver expressi…
cjgillot Oct 23, 2022
8bc43f9
Allow specifying multiple alternative suggestions
Xiretza Oct 17, 2022
f54c336
fix #103425, remove extra type error after missing semicolon error
chenyukang Oct 21, 2022
0fca075
suggest type annotation for local statement initialed by ref expression
SparrowLii Oct 12, 2022
919673e
rustc_middle: Rearrange resolver outputs structures slightly
petrochenkov Oct 25, 2022
5378c82
Use &self instead of &mut self for cast methods
jachris Oct 25, 2022
726bf18
Name impl trait in region bound suggestion
compiler-errors Oct 22, 2022
43e1745
Remove `rustc_driver::set_sigpipe_handler()`
Enselic Oct 24, 2022
5064648
Pinning tests for some macro_rules things discussed in the lang meeting
scottmcm Oct 25, 2022
bf6bfcd
Rollup merge of #102951 - SparrowLii:type_annotation, r=estebank
Dylan-DPC Oct 26, 2022
f2c2e58
Rollup merge of #103209 - Xiretza:multiple-suggestions, r=davidtwco
Dylan-DPC Oct 26, 2022
8ed3a80
Rollup merge of #103287 - saethlin:faster-len-check, r=thomcc
Dylan-DPC Oct 26, 2022
7858287
Rollup merge of #103416 - compiler-errors:rpit-named, r=cjgillot
Dylan-DPC Oct 26, 2022
c9a04cd
Rollup merge of #103430 - cjgillot:receiver-attrs, r=petrochenkov
Dylan-DPC Oct 26, 2022
742741f
Rollup merge of #103444 - chenyukang:yukang/fix-103425-extra-diag, r=…
Dylan-DPC Oct 26, 2022
c956351
Rollup merge of #103520 - petrochenkov:resout, r=cjgillot
Dylan-DPC Oct 26, 2022
39e0e2c
Rollup merge of #103533 - jachris:cast-without-mut, r=oli-obk
Dylan-DPC Oct 26, 2022
d159124
Rollup merge of #103536 - Enselic:remove-set_sigpipe_handler, r=tmiasko
Dylan-DPC Oct 26, 2022
703fb66
Rollup merge of #103542 - scottmcm:invalid-macro-patterns, r=compiler…
Dylan-DPC Oct 26, 2022
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
10 changes: 10 additions & 0 deletions library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
@@ -2229,6 +2229,16 @@ pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
!ptr.is_null() && ptr.is_aligned()
}

/// Checks whether an allocation of `len` instances of `T` exceeds
/// the maximum allowed allocation size.
pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
let max_len = const {
let size = crate::mem::size_of::<T>();
if size == 0 { usize::MAX } else { isize::MAX as usize / size }
};
len <= max_len
}

/// Checks whether the regions of memory starting at `src` and `dst` of size
/// `count * size_of::<T>()` do *not* overlap.
pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -192,6 +192,7 @@
#![feature(extern_types)]
#![feature(fundamental)]
#![feature(if_let_guard)]
#![feature(inline_const)]
#![feature(intra_doc_pointers)]
#![feature(intrinsics)]
#![feature(lang_items)]
10 changes: 5 additions & 5 deletions library/core/src/slice/raw.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Free functions to create `&[T]` and `&mut [T]`.

use crate::array;
use crate::intrinsics::{assert_unsafe_precondition, is_aligned_and_not_null};
use crate::intrinsics::{
assert_unsafe_precondition, is_aligned_and_not_null, is_valid_allocation_size,
};
use crate::ops::Range;
use crate::ptr;

@@ -91,8 +93,7 @@ pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T]
// SAFETY: the caller must uphold the safety contract for `from_raw_parts`.
unsafe {
assert_unsafe_precondition!([T](data: *const T, len: usize) =>
is_aligned_and_not_null(data)
&& crate::mem::size_of::<T>().saturating_mul(len) <= isize::MAX as usize
is_aligned_and_not_null(data) && is_valid_allocation_size::<T>(len)
);
&*ptr::slice_from_raw_parts(data, len)
}
@@ -135,8 +136,7 @@ pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a m
// SAFETY: the caller must uphold the safety contract for `from_raw_parts_mut`.
unsafe {
assert_unsafe_precondition!([T](data: *mut T, len: usize) =>
is_aligned_and_not_null(data)
&& crate::mem::size_of::<T>().saturating_mul(len) <= isize::MAX as usize
is_aligned_and_not_null(data) && is_valid_allocation_size::<T>(len)
);
&mut *ptr::slice_from_raw_parts_mut(data, len)
}