diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-10-16 19:18:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-16 19:18:30 +0200 |
| commit | 1817de609b0ffaab0cf32de6baae5944f6f6e7d6 (patch) | |
| tree | 6b686cf6926cfb90564eb8a179c45d3325a54e2d /tests | |
| parent | 0037048da8ed19feef7ee1437f123a88a7342b33 (diff) | |
| parent | 94ab726c7856cd7716d2a33db3e1915faed99008 (diff) | |
| download | rust-1817de609b0ffaab0cf32de6baae5944f6f6e7d6.tar.gz rust-1817de609b0ffaab0cf32de6baae5944f6f6e7d6.zip | |
Rollup merge of #130822 - bjoernager:non-null-from-ref, r=dtolnay
Add `from_ref` and `from_mut` constructors to `core::ptr::NonNull`. Relevant tracking issue: #130823 The `core::ptr::NonNull` type should have the convenience constructors `from_ref` and `from_mut` for parity with `core::ptr::from_ref` and `core::ptr::from_mut`. Although the type in question already implements `From<&T>` and `From<&mut T>`, these new functions also carry the ability to be used in constant expressions (due to not being behind a trait).
Diffstat (limited to 'tests')
6 files changed, 74 insertions, 62 deletions
diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir index 3aa483ed1ae..bd56ab67e00 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-abort.mir @@ -19,30 +19,30 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { debug i => _22; debug x => _23; } - scope 17 (inlined <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next) { + scope 18 (inlined <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next) { let mut _14: &mut std::slice::Iter<'_, T>; let mut _15: std::option::Option<&T>; let mut _19: (usize, bool); let mut _20: (usize, &T); - scope 18 { + scope 19 { let _18: usize; - scope 23 { + scope 24 { } } - scope 19 { - scope 20 { - scope 26 (inlined <Option<(usize, &T)> as FromResidual<Option<Infallible>>>::from_residual) { + scope 20 { + scope 21 { + scope 27 (inlined <Option<(usize, &T)> as FromResidual<Option<Infallible>>>::from_residual) { } } } - scope 21 { - scope 22 { + scope 22 { + scope 23 { } } - scope 24 (inlined <Option<&T> as Try>::branch) { + scope 25 (inlined <Option<&T> as Try>::branch) { let mut _16: isize; let _17: &T; - scope 25 { + scope 26 { } } } @@ -59,29 +59,31 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { let _9: *const T; scope 7 { } - scope 11 (inlined without_provenance::<T>) { + scope 12 (inlined without_provenance::<T>) { } - scope 12 (inlined NonNull::<T>::as_ptr) { + scope 13 (inlined NonNull::<T>::as_ptr) { } - scope 13 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { + scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { } } scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) { - let mut _4: *const [T]; + scope 9 (inlined NonNull::<[T]>::from_ref) { + let mut _4: *const [T]; + } } - scope 9 (inlined NonNull::<[T]>::cast::<T>) { + scope 10 (inlined NonNull::<[T]>::cast::<T>) { let mut _5: *const T; - scope 10 (inlined NonNull::<[T]>::as_ptr) { + scope 11 (inlined NonNull::<[T]>::as_ptr) { } } } } } - scope 14 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) { - scope 15 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) { + scope 15 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) { + scope 16 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) { } } - scope 16 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) { + scope 17 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) { } bb0: { diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir index 4cc0aa0ed78..57f09a4631b 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir @@ -34,29 +34,31 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { let _9: *const T; scope 7 { } - scope 11 (inlined without_provenance::<T>) { + scope 12 (inlined without_provenance::<T>) { } - scope 12 (inlined NonNull::<T>::as_ptr) { + scope 13 (inlined NonNull::<T>::as_ptr) { } - scope 13 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { + scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { } } scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) { - let mut _4: *const [T]; + scope 9 (inlined NonNull::<[T]>::from_ref) { + let mut _4: *const [T]; + } } - scope 9 (inlined NonNull::<[T]>::cast::<T>) { + scope 10 (inlined NonNull::<[T]>::cast::<T>) { let mut _5: *const T; - scope 10 (inlined NonNull::<[T]>::as_ptr) { + scope 11 (inlined NonNull::<[T]>::as_ptr) { } } } } } - scope 14 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) { - scope 15 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) { + scope 15 (inlined <std::slice::Iter<'_, T> as Iterator>::enumerate) { + scope 16 (inlined Enumerate::<std::slice::Iter<'_, T>>::new) { } } - scope 16 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) { + scope 17 (inlined <Enumerate<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) { } bb0: { diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir index 507afa63c68..4050304f469 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-abort.mir @@ -31,25 +31,27 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { let _9: *const T; scope 7 { } - scope 11 (inlined without_provenance::<T>) { + scope 12 (inlined without_provenance::<T>) { } - scope 12 (inlined NonNull::<T>::as_ptr) { + scope 13 (inlined NonNull::<T>::as_ptr) { } - scope 13 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { + scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { } } scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) { - let mut _4: *const [T]; + scope 9 (inlined NonNull::<[T]>::from_ref) { + let mut _4: *const [T]; + } } - scope 9 (inlined NonNull::<[T]>::cast::<T>) { + scope 10 (inlined NonNull::<[T]>::cast::<T>) { let mut _5: *const T; - scope 10 (inlined NonNull::<[T]>::as_ptr) { + scope 11 (inlined NonNull::<[T]>::as_ptr) { } } } } } - scope 14 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) { + scope 15 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) { } bb0: { diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir index a25f12edc28..2c3d7ab1e4a 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -31,25 +31,27 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { let _9: *const T; scope 7 { } - scope 11 (inlined without_provenance::<T>) { + scope 12 (inlined without_provenance::<T>) { } - scope 12 (inlined NonNull::<T>::as_ptr) { + scope 13 (inlined NonNull::<T>::as_ptr) { } - scope 13 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { + scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { } } scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) { - let mut _4: *const [T]; + scope 9 (inlined NonNull::<[T]>::from_ref) { + let mut _4: *const [T]; + } } - scope 9 (inlined NonNull::<[T]>::cast::<T>) { + scope 10 (inlined NonNull::<[T]>::cast::<T>) { let mut _5: *const T; - scope 10 (inlined NonNull::<[T]>::as_ptr) { + scope 11 (inlined NonNull::<[T]>::as_ptr) { } } } } } - scope 14 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) { + scope 15 (inlined <std::slice::Iter<'_, T> as IntoIterator>::into_iter) { } bb0: { diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir index 1b397a4e4cd..a6ccd435c40 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir @@ -18,7 +18,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 2 { debug x => _17; } - scope 17 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) { + scope 18 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) { let mut _14: &mut std::slice::Iter<'_, T>; } } @@ -34,29 +34,31 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { let _9: *const T; scope 7 { } - scope 11 (inlined without_provenance::<T>) { + scope 12 (inlined without_provenance::<T>) { } - scope 12 (inlined NonNull::<T>::as_ptr) { + scope 13 (inlined NonNull::<T>::as_ptr) { } - scope 13 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { + scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { } } scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) { - let mut _4: *const [T]; + scope 9 (inlined NonNull::<[T]>::from_ref) { + let mut _4: *const [T]; + } } - scope 9 (inlined NonNull::<[T]>::cast::<T>) { + scope 10 (inlined NonNull::<[T]>::cast::<T>) { let mut _5: *const T; - scope 10 (inlined NonNull::<[T]>::as_ptr) { + scope 11 (inlined NonNull::<[T]>::as_ptr) { } } } } } - scope 14 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) { - scope 15 (inlined Rev::<std::slice::Iter<'_, T>>::new) { + scope 15 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) { + scope 16 (inlined Rev::<std::slice::Iter<'_, T>>::new) { } } - scope 16 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) { + scope 17 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) { } bb0: { diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir index 77689dd9b51..df11c8e3b49 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir @@ -18,7 +18,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { scope 2 { debug x => _17; } - scope 17 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) { + scope 18 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) { let mut _14: &mut std::slice::Iter<'_, T>; } } @@ -34,29 +34,31 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { let _9: *const T; scope 7 { } - scope 11 (inlined without_provenance::<T>) { + scope 12 (inlined without_provenance::<T>) { } - scope 12 (inlined NonNull::<T>::as_ptr) { + scope 13 (inlined NonNull::<T>::as_ptr) { } - scope 13 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { + scope 14 (inlined std::ptr::mut_ptr::<impl *mut T>::add) { } } scope 8 (inlined <NonNull<[T]> as From<&[T]>>::from) { - let mut _4: *const [T]; + scope 9 (inlined NonNull::<[T]>::from_ref) { + let mut _4: *const [T]; + } } - scope 9 (inlined NonNull::<[T]>::cast::<T>) { + scope 10 (inlined NonNull::<[T]>::cast::<T>) { let mut _5: *const T; - scope 10 (inlined NonNull::<[T]>::as_ptr) { + scope 11 (inlined NonNull::<[T]>::as_ptr) { } } } } } - scope 14 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) { - scope 15 (inlined Rev::<std::slice::Iter<'_, T>>::new) { + scope 15 (inlined <std::slice::Iter<'_, T> as Iterator>::rev) { + scope 16 (inlined Rev::<std::slice::Iter<'_, T>>::new) { } } - scope 16 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) { + scope 17 (inlined <Rev<std::slice::Iter<'_, T>> as IntoIterator>::into_iter) { } bb0: { |
