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 15 pull requests #74329

Closed
wants to merge 149 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
7527409
Constify most non-trait `Duration` methods as described in #72440
marmeladema May 21, 2020
40ee620
Added a lint for .map(|x| x)
theo-lw Jun 8, 2020
80bcbf5
Merge commit 'c2c07fa9d095931eb5684a42942a7b573a0c5238' into clippyup
flip1995 Jun 23, 2020
fb4f9a0
Fix pattern match of ExprKind::MethodCall
theo-lw Jun 23, 2020
583d644
Auto merge of #5694 - wangtheo:issue-5626, r=matthiaskrgr
bors Jun 23, 2020
7c1b3aa
Record span of `const` kw in GenericParamKind
ayazhafiz Jun 21, 2020
5987c7d
cmp_owned: avoid FP when PartialEq is not implemented symmetrically
ebroto Jun 9, 2020
b498e1d
cmp_owned: reverse operands if necessary
ebroto Jun 12, 2020
6bf5434
copy_on_clone - add machine applicability
tnielens Jun 23, 2020
a14eab3
Auto merge of #5745 - montrivo:copy_on_clone, r=phansch
bors Jun 24, 2020
46d3304
Auto merge of #5701 - ebroto:4874_cmp_owned_fp, r=flip1995
bors Jun 24, 2020
3e48aae
Clean up E0704 error explanation
GuillaumeGomez Jun 25, 2020
fa0f1d3
Change a noun to a verb to make the sentence complete
carols10cents Jun 25, 2020
88fec89
Auto merge of #5748 - carols10cents:tiny-docs-fix, r=flip1995
bors Jun 25, 2020
f5ce0e5
rustc_lint: only query `typeck_tables_of` when a lint needs it.
eddyb Jun 25, 2020
a671ea4
Rollup merge of #73597 - ayazhafiz:i/const-span, r=ecstatic-morse
Manishearth Jun 26, 2020
81810fa
Auto merge of #73756 - Manishearth:rollup-aehswb2, r=Manishearth
bors Jun 26, 2020
3c5ee33
Update tests
ecstatic-morse Jun 26, 2020
9448ed4
Obviate #[allow(improper_ctypes_definitions)]
Goirad Jun 29, 2020
dfecaef
typeck: adding type information to projection
Azhng Jun 24, 2020
1e861a2
Merge remote-tracking branch 'upstream/master' into rustup2
flip1995 Jun 30, 2020
ab649c9
Disable chrono integration test
flip1995 Jun 30, 2020
ccf7cb3
Auto merge of #5751 - flip1995:rustup, r=Manishearth,flip1995
bors Jun 30, 2020
814349f
Lint enabling the whole restriction group
ebroto Jun 26, 2020
c5d8f53
Move blanket_clippy_restriction_lints to "style"
ebroto Jun 27, 2020
d05d6ab
Auto merge of #5750 - ebroto:blanket_clippy_restriction_lints, r=Mani…
bors Jun 30, 2020
bff6c43
Require `or_patterns` to suggest nesting them
ebroto Jun 30, 2020
36b7983
Auto merge of #5758 - ebroto:5704_unnested_or_pats, r=flip1995
bors Jun 30, 2020
5b9c2ff
Fix multiple_crate_versions error
Jul 1, 2020
0860375
Auto merge of #5759 - mikerite:multiple_crate_versions_20200701, r=ma…
bors Jul 1, 2020
d347d0c
Deprecate regex_macro lint
phansch Jul 1, 2020
52cc5fc
Auto merge of #5760 - phansch:deprecate-regex-macro, r=Manishearth
bors Jul 1, 2020
590e07b
rustc_lint: avoid using TypeckTables::empty for LateContext.
eddyb Jun 26, 2020
bddb266
typeck: check for infer before type impls trait
davidtwco Jul 2, 2020
30c046e
Use 'tcx for references to AccessLevels wherever possible.
eddyb Jun 25, 2020
a7c58e6
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jul 3, 2020
c493090
Auto merge of #5763 - flip1995:rustup, r=Manishearth
bors Jul 3, 2020
754bfb1
Add configurable threshold for `type_repetition_in_bounds` lint
ThibsG Jun 28, 2020
d5a8f03
Take generic args into account for bounded type
ThibsG Jul 3, 2020
2d5930a
Don't lint for predicates generated in macros
ThibsG Jul 3, 2020
c3c4027
Added restriction lint: pattern-type-mismatch
phaylon Nov 4, 2019
55877d7
span_help_and_lint -> span_lint_and_help
phaylon Feb 9, 2020
346ee96
Adjusted expected STDERR
phaylon Feb 10, 2020
6447507
Fix rebase fallout
flip1995 Jun 8, 2020
92ecc53
Catching up with rustc changes
phaylon Jul 1, 2020
d617551
Expanded lint documentation
phaylon Jul 1, 2020
fff8e72
Auto merge of #5761 - ThibsG:TypeRepetitionThreshold, r=flip1995
bors Jul 3, 2020
aa4bee2
LateContext has only one lifetime parameter now
phaylon Jul 3, 2020
c0fd452
fmt fix
phaylon Jul 3, 2020
57cdf2d
Auto merge of #4841 - phaylon:pattern-type-mismatch, r=flip1995
bors Jul 3, 2020
bf48a2d
Lint for if let Some(x) = ... instead of Option::map_or
JarredAllen Mar 5, 2020
82f8d4d
Stop linting on macros and correctly use braces for constructs
JarredAllen Apr 25, 2020
b85796f
Properly parenthesize to avoid operator precedence errors
JarredAllen Apr 25, 2020
88c8afd
Handle ref, mut, &, and &mut on the option
JarredAllen May 10, 2020
f73b455
Refactoring
JarredAllen May 10, 2020
7c4de9d
Refactoring pt. 2
JarredAllen May 12, 2020
5e20475
Don't lint if contains a macro
JarredAllen May 31, 2020
5150277
Used clippy to clean itself
JarredAllen May 31, 2020
93f0f5d
Last few tweaks
JarredAllen Jun 12, 2020
ccb9998
Fix compile error from library change
JarredAllen Jun 25, 2020
6ce9812
Clean existing lint code to match new lint
JarredAllen Jun 25, 2020
6e2d55c
Update compile-test to follow new lint
JarredAllen Jun 27, 2020
1c32263
Formatted updates to lints
JarredAllen Jul 1, 2020
c8f700e
Fixed compile errors
JarredAllen Jul 4, 2020
3503247
Shrink ParamEnv to 16 bytes
Mark-Simulacrum Jul 3, 2020
c478b54
add as_ptr method to raw slices
RalfJung Jul 3, 2020
3b1d5e6
call the mut version as_mut_ptr and also add an as_ptr-like method to…
RalfJung Jul 3, 2020
90580c7
make unchecked slice indexing helper methods use raw pointers
RalfJung Jul 5, 2020
5f5c98b
add (unchecked) indexing methods to raw pointers and NonNull
RalfJung Jul 5, 2020
ac85692
Auto merge of #5301 - JarredAllen:option_if_let_else, r=flip1995
bors Jul 6, 2020
a6f1af7
Lint for x.powi(2) => x * x
thiagoarrais Apr 3, 2020
f627984
Lint (x * x + y * y).sqrt() => x.hypot(y)
thiagoarrais May 25, 2020
2e8a1be
new lint: match_like_matches_macro
robojumper Jul 5, 2020
0c8afa3
Lint x.log(b) / y.log(b) => x.log(y)
thiagoarrais Jun 1, 2020
1740dda
fix match_like_matches_macro in clippy
robojumper Jul 5, 2020
076ec87
Lint for to_radians and to_degrees
thiagoarrais Jun 10, 2020
f559682
Better copy for lint message
thiagoarrais Jun 15, 2020
db7bc6b
Place radian lints under suboptimal_flops
thiagoarrais Jun 15, 2020
6dc066f
Includes TODO comment for hypot lint
thiagoarrais Jun 17, 2020
6be9491
Reclassify powi(2) lint under suboptimal_flops
thiagoarrais Jun 22, 2020
3065201
Includes TODO for constants equivalent to π/180
thiagoarrais Jul 6, 2020
4705037
Auto merge of #73978 - Mark-Simulacrum:shrink-paramenv, r=nnethercote
bors Jul 6, 2020
245b006
Rollup merge of #73870 - sexxi-goose:projection-ty, r=nikomatsakis
Manishearth Jul 7, 2020
c41fcad
Auto merge of #74117 - Manishearth:rollup-ds7z0kx, r=Manishearth
bors Jul 7, 2020
5307cb5
Add a lint for `.repeat(1)`
giraffate Jul 4, 2020
e12a316
Auto merge of #5776 - flip1995:rustup, r=flip1995
bors Jul 8, 2020
37d75da
make match_like_matches_macro only apply to matches with a wildcard
robojumper Jul 8, 2020
db1c946
unnecessary_sort_by: avoid linting if key borrows
ebroto Jun 30, 2020
dac19e3
single_match_else - single expr/stmt else block corner case
tnielens Jul 6, 2020
45eea9a
Auto merge of #5771 - montrivo:bugfix/single-match-else, r=matthiaskrgr
bors Jul 9, 2020
c79c688
Fix a broken link in CONTRIBUTING.md
giraffate Jul 9, 2020
be88122
Auto merge of #5781 - giraffate:fix_a_broken_link, r=phansch
bors Jul 9, 2020
cf91c54
Avoid "whitelist"
tamird Jul 7, 2020
298a1fa
Move range_minus_one to pedantic
chrisduerr Jun 26, 2020
ba2a85d
Run update_lints
chrisduerr Jul 3, 2020
780a4c8
Fix typo
giraffate Jul 10, 2020
b3c7196
Fix test failures
chrisduerr Jul 10, 2020
afa4148
Fix tests a bit more
chrisduerr Jul 10, 2020
7d611d9
Auto merge of #5769 - robojumper:match_like_matches_macro, r=phansch
bors Jul 10, 2020
23d7b3f
Remove an unwrap in layout computation
erikdesjardins Jul 10, 2020
1eb0053
Stabilize `transmute` in constants and statics but not const fn
oli-obk Aug 30, 2019
1b3bc16
Fix out of bounds access by checking length equality BEFORE accessing…
matthiaskrgr Jul 11, 2020
b57ceb4
Rollup merge of #72920 - oli-obk:const_transmute, r=RalfJung
Manishearth Jul 11, 2020
905b5ad
don't mark linux kernel module targets as a unix environment
alex Jul 11, 2020
2c5f8ab
fix phrase in new_lint issue template
matthiaskrgr Jul 11, 2020
9a8b516
Sorting feature attributes in std
tesuji Jul 10, 2020
ff5e107
assign tracking issue
RalfJung Jul 12, 2020
1e05e09
Remove the useless indentation
tesuji Jul 10, 2020
0ff820c
Move constants to top file
tesuji Jul 12, 2020
90a7d24
Make is_valid_drive_letter function
tesuji Jul 10, 2020
27a966a
Make use of slice::strip_prefix and slice pattern
tesuji Jul 10, 2020
b1d6798
Rewrite parse_two_comps
tesuji Jul 10, 2020
0281a05
Prefer empty OsStr over unsafe cast from [u8]
tesuji Jul 10, 2020
e31898b
Reduce unsafe scope
tesuji Jul 12, 2020
083c2f6
pprust: support multiline comments within lines
davidtwco Jul 12, 2020
0e89f50
Clean up handling of style files in rustdoc
Cldfire Jul 12, 2020
8c45cf8
Add Ayu theme to rustdoc
Cldfire Jul 12, 2020
ed587f8
Update llvm-project to latest origin/rustc/10.0-2020-05-05 commit whi…
AdrianCX Jul 11, 2020
fa4a737
Auto merge of #5790 - flip1995:rustup, r=flip1995
bors Jul 13, 2020
75d43aa
Rollup merge of #5443 - thiagoarrais:issue-2040, r=flip1995
flip1995 Jul 13, 2020
019e281
Rollup merge of #5752 - chrisduerr:pedantic_ranges, r=flip1995
flip1995 Jul 13, 2020
32ef448
Rollup merge of #5756 - ebroto:5754_sort_by, r=flip1995
flip1995 Jul 13, 2020
26ede31
Rollup merge of #5784 - matthiaskrgr:ice_5780, r=phansch
flip1995 Jul 13, 2020
314b068
Rollup merge of #5786 - matthiaskrgr:new_lint_issue_templ, r=phansch
flip1995 Jul 13, 2020
4b87008
Auto merge of #5792 - flip1995:rollup-torc1we, r=flip1995
bors Jul 13, 2020
f2419b9
Refactoring to use `constant_context
giraffate Jul 13, 2020
d27e7d0
Clarify the description for rfind
lynoure Jul 13, 2020
ff796b6
Rename collapsable_if fix suggestion to "collapse nested if block"
bjorn3 Jun 19, 2020
b409103
Use `.is_some()` not `Some(_)`
giraffate Jul 13, 2020
c492ca4
Use `ArrayVec` in `SparseBitSet`.
nnethercote Jul 14, 2020
12df638
Auto merge of #5773 - giraffate:repeat_once, r=flip1995
bors Jul 14, 2020
2ca58e7
Auto merge of #5732 - bjorn3:patch-1, r=flip1995
bors Jul 14, 2020
0e9a20f
Remove unnecessary type hints from the Wake impl
yoshuawuyts Jul 14, 2020
f82ac4d
Merge commit '2ca58e7dda4a9eb142599638c59dc04d15961175' into clippyup
flip1995 Jul 14, 2020
7efdbb3
Rollup merge of #71237 - Cldfire:rustdoc-ayu-theme, r=GuilliaumeGomez
Manishearth Jul 14, 2020
6dda1d4
Rollup merge of #72481 - marmeladema:duration-consts-2, r=oli-obk
Manishearth Jul 14, 2020
ac01a53
Rollup merge of #73720 - GuillaumeGomez:cleanup-e0704, r=Dylan-DPC
Manishearth Jul 14, 2020
80a162e
Rollup merge of #73866 - Goirad:fix-entry-improper-ctypes, r=davidtwco
Manishearth Jul 14, 2020
0d2732a
Rollup merge of #73965 - davidtwco:issue-73886-non-primitive-slice-ca…
Manishearth Jul 14, 2020
7b0097e
Rollup merge of #73986 - RalfJung:raw-slice-as-ptr, r=sfackler
Manishearth Jul 14, 2020
a6cfdd8
Rollup merge of #74220 - lzutao:windows-path-com, r=LukasKalbertodt
Manishearth Jul 14, 2020
f87ef88
Rollup merge of #74227 - erikdesjardins:layun, r=estebank
Manishearth Jul 14, 2020
4a79b54
Rollup merge of #74239 - AdrianCX:master, r=cuviper
Manishearth Jul 14, 2020
6332dd8
Rollup merge of #74257 - alex:patch-1, r=joshtriplett
Manishearth Jul 14, 2020
ef5b047
Rollup merge of #74272 - davidtwco:issue-73626-multiline-mixed-commen…
Manishearth Jul 14, 2020
afffe05
Rollup merge of #74296 - Lynoure:rfind-doc-improvement, r=hanna-kruppe
Manishearth Jul 14, 2020
6261805
Rollup merge of #74310 - nnethercote:use-ArrayVec-in-SparseBitSet, r=…
Manishearth Jul 14, 2020
1d72e72
Rollup merge of #74316 - yoshuawuyts:no-wake-type-hints, r=Mark-Simul…
Manishearth Jul 14, 2020
4c2d7ee
Rollup merge of #74324 - flip1995:clippyup, r=Manishearth
Manishearth Jul 14, 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
12 changes: 9 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ dependencies = [
"nodrop",
]

[[package]]
name = "arrayvec"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"

[[package]]
name = "atty"
version = "0.2.14"
Expand Down Expand Up @@ -164,7 +170,7 @@ version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
dependencies = [
"arrayvec",
"arrayvec 0.4.7",
"constant_time_eq",
]

Expand Down Expand Up @@ -714,7 +720,7 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9"
dependencies = [
"arrayvec",
"arrayvec 0.4.7",
"cfg-if",
"crossbeam-utils 0.6.5",
"lazy_static",
Expand Down Expand Up @@ -3494,8 +3500,8 @@ dependencies = [
name = "rustc_index"
version = "0.0.0"
dependencies = [
"arrayvec 0.5.1",
"rustc_serialize",
"smallvec 1.4.0",
]

[[package]]
Expand Down
5 changes: 2 additions & 3 deletions src/liballoc/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {

// Wake by value, moving the Arc into the Wake::wake function
unsafe fn wake<W: Wake + Send + Sync + 'static>(waker: *const ()) {
let waker: Arc<W> = unsafe { Arc::from_raw(waker as *const W) };
let waker = unsafe { Arc::from_raw(waker as *const W) };
<W as Wake>::wake(waker);
}

// Wake by reference, wrap the waker in ManuallyDrop to avoid dropping it
unsafe fn wake_by_ref<W: Wake + Send + Sync + 'static>(waker: *const ()) {
let waker: ManuallyDrop<Arc<W>> =
unsafe { ManuallyDrop::new(Arc::from_raw(waker as *const W)) };
let waker = unsafe { ManuallyDrop::new(Arc::from_raw(waker as *const W)) };
<W as Wake>::wake_by_ref(&waker);
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
#![feature(custom_inner_attributes)]
#![feature(decl_macro)]
#![feature(doc_cfg)]
#![feature(duration_consts_2)]
#![feature(extern_types)]
#![feature(fundamental)]
#![feature(intrinsics)]
Expand Down Expand Up @@ -148,6 +149,7 @@
#![feature(associated_type_bounds)]
#![feature(const_type_id)]
#![feature(const_caller_location)]
#![feature(slice_ptr_get)]
#![feature(no_niche)] // rust-lang/rust#68303
#![feature(unsafe_block_in_unsafe_fn)]
#![deny(unsafe_op_in_unsafe_fn)]
Expand Down
50 changes: 50 additions & 0 deletions src/libcore/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;
use crate::cmp::Ordering::{self, Equal, Greater, Less};
use crate::intrinsics;
use crate::mem;
use crate::slice::SliceIndex;

#[lang = "const_ptr"]
impl<T: ?Sized> *const T {
Expand Down Expand Up @@ -826,6 +827,55 @@ impl<T> *const [T] {
// Only `std` can make this guarantee.
unsafe { Repr { rust: self }.raw }.len
}

/// Returns a raw pointer to the slice's buffer.
///
/// This is equivalent to casting `self` to `*const T`, but more type-safe.
///
/// # Examples
///
/// ```rust
/// #![feature(slice_ptr_get)]
/// use std::ptr;
///
/// let slice: *const [i8] = ptr::slice_from_raw_parts(ptr::null(), 3);
/// assert_eq!(slice.as_ptr(), 0 as *const i8);
/// ```
#[inline]
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")]
pub const fn as_ptr(self) -> *const T {
self as *const T
}

/// Returns a raw pointer to an element or subslice, without doing bounds
/// checking.
///
/// Calling this method with an out-of-bounds index or when `self` is not dereferencable
/// is *[undefined behavior]* even if the resulting pointer is not used.
///
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
///
/// # Examples
///
/// ```
/// #![feature(slice_ptr_get)]
///
/// let x = &[1, 2, 4] as *const [i32];
///
/// unsafe {
/// assert_eq!(x.get_unchecked(1), x.as_ptr().add(1));
/// }
/// ```
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[inline]
pub unsafe fn get_unchecked<I>(self, index: I) -> *const I::Output
where
I: SliceIndex<[T]>,
{
// SAFETY: the caller ensures that `self` is dereferencable and `index` in-bounds.
unsafe { index.get_unchecked(self) }
}
}

// Equality for pointers
Expand Down
51 changes: 50 additions & 1 deletion src/libcore/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;
use crate::cmp::Ordering::{self, Equal, Greater, Less};
use crate::intrinsics;
use crate::slice::SliceIndex;

#[lang = "mut_ptr"]
impl<T: ?Sized> *mut T {
Expand Down Expand Up @@ -1014,7 +1015,6 @@ impl<T> *mut [T] {
///
/// ```rust
/// #![feature(slice_ptr_len)]
///
/// use std::ptr;
///
/// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
Expand All @@ -1028,6 +1028,55 @@ impl<T> *mut [T] {
// Only `std` can make this guarantee.
unsafe { Repr { rust_mut: self }.raw }.len
}

/// Returns a raw pointer to the slice's buffer.
///
/// This is equivalent to casting `self` to `*mut T`, but more type-safe.
///
/// # Examples
///
/// ```rust
/// #![feature(slice_ptr_get)]
/// use std::ptr;
///
/// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
/// assert_eq!(slice.as_mut_ptr(), 0 as *mut i8);
/// ```
#[inline]
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")]
pub const fn as_mut_ptr(self) -> *mut T {
self as *mut T
}

/// Returns a raw pointer to an element or subslice, without doing bounds
/// checking.
///
/// Calling this method with an out-of-bounds index or when `self` is not dereferencable
/// is *[undefined behavior]* even if the resulting pointer is not used.
///
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
///
/// # Examples
///
/// ```
/// #![feature(slice_ptr_get)]
///
/// let x = &mut [1, 2, 4] as *mut [i32];
///
/// unsafe {
/// assert_eq!(x.get_unchecked_mut(1), x.as_mut_ptr().add(1));
/// }
/// ```
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[inline]
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> *mut I::Output
where
I: SliceIndex<[T]>,
{
// SAFETY: the caller ensures that `self` is dereferencable and `index` in-bounds.
unsafe { index.get_unchecked_mut(self) }
}
}

// Equality for pointers
Expand Down
53 changes: 52 additions & 1 deletion src/libcore/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::marker::Unsize;
use crate::mem;
use crate::ops::{CoerceUnsized, DispatchFromDyn};
use crate::ptr::Unique;
use crate::slice::SliceIndex;

/// `*mut T` but non-zero and covariant.
///
Expand Down Expand Up @@ -192,7 +193,6 @@ impl<T> NonNull<[T]> {
///
/// ```rust
/// #![feature(slice_ptr_len, nonnull_slice_from_raw_parts)]
///
/// use std::ptr::NonNull;
///
/// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3);
Expand All @@ -204,6 +204,57 @@ impl<T> NonNull<[T]> {
pub const fn len(self) -> usize {
self.as_ptr().len()
}

/// Returns a non-null pointer to the slice's buffer.
///
/// # Examples
///
/// ```rust
/// #![feature(slice_ptr_get, nonnull_slice_from_raw_parts)]
/// use std::ptr::NonNull;
///
/// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3);
/// assert_eq!(slice.as_non_null_ptr(), NonNull::new(1 as *mut i8).unwrap());
/// ```
#[inline]
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")]
pub const fn as_non_null_ptr(self) -> NonNull<T> {
// SAFETY: We know `self` is non-null.
unsafe { NonNull::new_unchecked(self.as_ptr().as_mut_ptr()) }
}

/// Returns a raw pointer to an element or subslice, without doing bounds
/// checking.
///
/// Calling this method with an out-of-bounds index or when `self` is not dereferencable
/// is *[undefined behavior]* even if the resulting pointer is not used.
///
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
///
/// # Examples
///
/// ```
/// #![feature(slice_ptr_get, nonnull_slice_from_raw_parts)]
/// use std::ptr::NonNull;
///
/// let x = &mut [1, 2, 4];
/// let x = NonNull::slice_from_raw_parts(NonNull::new(x.as_mut_ptr()).unwrap(), x.len());
///
/// unsafe {
/// assert_eq!(x.get_unchecked_mut(1).as_ptr(), x.as_non_null_ptr().as_ptr().add(1));
/// }
/// ```
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[inline]
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> NonNull<I::Output>
where
I: SliceIndex<[T]>,
{
// SAFETY: the caller ensures that `self` is dereferencable and `index` in-bounds.
// As a consequence, the resulting pointer cannot be NULL.
unsafe { NonNull::new_unchecked(self.as_ptr().get_unchecked_mut(index)) }
}
}

#[stable(feature = "nonnull", since = "1.25.0")]
Expand Down
Loading