Skip to content

Commit 0e9e408

Browse files
committed
Auto merge of #72756 - RalfJung:rollup-tbjmtx2, r=RalfJung
Rollup of 9 pull requests Successful merges: - #67460 (Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes) - #71095 (impl From<[T; N]> for Box<[T]>) - #71500 (Make pointer offset methods/intrinsics const) - #71804 (linker: Support `-static-pie` and `-static -shared`) - #71862 (Implement RFC 2585: unsafe blocks in unsafe fn) - #72103 (borrowck `DefId` -> `LocalDefId`) - #72407 (Various minor improvements to Ipv6Addr::Display) - #72413 (impl Step for char (make Range*<char> iterable)) - #72439 (NVPTX support for new asm!) Failed merges: r? @ghost
2 parents 4bd32c9 + 3789455 commit 0e9e408

File tree

89 files changed

+1894
-473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1894
-473
lines changed

src/doc/unstable-book/src/library-features/asm.md

+11
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,17 @@ Here is the list of currently supported register classes:
468468
| ARM | `qreg` | `q[0-15]` | `w` |
469469
| ARM | `qreg_low8` | `q[0-7]` | `t` |
470470
| ARM | `qreg_low4` | `q[0-3]` | `x` |
471+
| NVPTX | `reg16` | None\* | `h` |
472+
| NVPTX | `reg32` | None\* | `r` |
473+
| NVPTX | `reg64` | None\* | `l` |
471474
| RISC-V | `reg` | `x1`, `x[5-7]`, `x[9-15]`, `x[16-31]` (non-RV32E) | `r` |
472475
| RISC-V | `freg` | `f[0-31]` | `f` |
473476

474477
> **Note**: On x86 we treat `reg_byte` differently from `reg` because the compiler can allocate `al` and `ah` separately whereas `reg` reserves the whole register.
475478
>
476479
> Note #2: On x86-64 the high byte registers (e.g. `ah`) are only available when used as an explicit register. Specifying the `reg_byte` register class for an operand will always allocate a low byte register.
480+
>
481+
> Note #3: NVPTX doesn't have a fixed register set, so named registers are not supported.
477482
478483
Additional register classes may be added in the future based on demand (e.g. MMX, x87, etc).
479484

@@ -495,6 +500,9 @@ Each register class has constraints on which value types they can be used with.
495500
| ARM | `sreg` | `vfp2` | `i32`, `f32` |
496501
| ARM | `dreg` | `vfp2` | `i64`, `f64`, `i8x8`, `i16x4`, `i32x2`, `i64x1`, `f32x2` |
497502
| ARM | `qreg` | `neon` | `i8x16`, `i16x8`, `i32x4`, `i64x2`, `f32x4` |
503+
| NVPTX | `reg16` | None | `i8`, `i16` |
504+
| NVPTX | `reg32` | None | `i8`, `i16`, `i32`, `f32` |
505+
| NVPTX | `reg64` | None | `i8`, `i16`, `i32`, `f32`, `i64`, `f64` |
498506
| RISC-V32 | `reg` | None | `i8`, `i16`, `i32`, `f32` |
499507
| RISC-V64 | `reg` | None | `i8`, `i16`, `i32`, `f32`, `i64`, `f64` |
500508
| RISC-V | `freg` | `f` | `f32` |
@@ -610,6 +618,9 @@ The supported modifiers are a subset of LLVM's (and GCC's) [asm template argumen
610618
| ARM | `dreg` | None | `d0` | `P` |
611619
| ARM | `qreg` | None | `q0` | `q` |
612620
| ARM | `qreg` | `e` / `f` | `d0` / `d1` | `e` / `f` |
621+
| NVPTX | `reg16` | None | `rs0` | None |
622+
| NVPTX | `reg32` | None | `r0` | None |
623+
| NVPTX | `reg64` | None | `rd0` | None |
613624
| RISC-V | `reg` | None | `x1` | None |
614625
| RISC-V | `freg` | None | `f0` | None |
615626

src/liballoc/boxed.rs

+19
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,25 @@ impl From<Box<str>> for Box<[u8]> {
865865
}
866866
}
867867

868+
#[stable(feature = "box_from_array", since = "1.45.0")]
869+
impl<T, const N: usize> From<[T; N]> for Box<[T]>
870+
where
871+
[T; N]: LengthAtMost32,
872+
{
873+
/// Converts a `[T; N]` into a `Box<[T]>`
874+
///
875+
/// This conversion moves the array to newly heap-allocated memory.
876+
///
877+
/// # Examples
878+
/// ```rust
879+
/// let boxed: Box<[u8]> = Box::from([4, 2]);
880+
/// println!("{:?}", boxed);
881+
/// ```
882+
fn from(array: [T; N]) -> Box<[T]> {
883+
box array
884+
}
885+
}
886+
868887
#[stable(feature = "boxed_slice_try_from", since = "1.43.0")]
869888
impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]>
870889
where

src/libcore/intrinsics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,7 @@ extern "rust-intrinsic" {
13141314
/// The stabilized version of this intrinsic is
13151315
/// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
13161316
#[must_use = "returns a new pointer rather than modifying its argument"]
1317+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
13171318
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
13181319

13191320
/// Calculates the offset from a pointer, potentially wrapping.
@@ -1331,6 +1332,7 @@ extern "rust-intrinsic" {
13311332
/// The stabilized version of this intrinsic is
13321333
/// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
13331334
#[must_use = "returns a new pointer rather than modifying its argument"]
1335+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
13341336
pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
13351337

13361338
/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with

src/libcore/iter/range.rs

+73-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::char;
12
use crate::convert::TryFrom;
23
use crate::mem;
34
use crate::ops::{self, Add, Sub, Try};
@@ -400,6 +401,73 @@ step_integer_impls! {
400401
wider than usize: [u32 i32], [u64 i64], [u128 i128];
401402
}
402403

404+
#[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
405+
unsafe impl Step for char {
406+
#[inline]
407+
fn steps_between(&start: &char, &end: &char) -> Option<usize> {
408+
let start = start as u32;
409+
let end = end as u32;
410+
if start <= end {
411+
let count = end - start;
412+
if start < 0xD800 && 0xE000 <= end {
413+
usize::try_from(count - 0x800).ok()
414+
} else {
415+
usize::try_from(count).ok()
416+
}
417+
} else {
418+
None
419+
}
420+
}
421+
422+
#[inline]
423+
fn forward_checked(start: char, count: usize) -> Option<char> {
424+
let start = start as u32;
425+
let mut res = Step::forward_checked(start, count)?;
426+
if start < 0xD800 && 0xD800 <= res {
427+
res = Step::forward_checked(res, 0x800)?;
428+
}
429+
if res <= char::MAX as u32 {
430+
// SAFETY: res is a valid unicode scalar
431+
// (below 0x110000 and not in 0xD800..0xE000)
432+
Some(unsafe { char::from_u32_unchecked(res) })
433+
} else {
434+
None
435+
}
436+
}
437+
438+
#[inline]
439+
fn backward_checked(start: char, count: usize) -> Option<char> {
440+
let start = start as u32;
441+
let mut res = Step::backward_checked(start, count)?;
442+
if start >= 0xE000 && 0xE000 > res {
443+
res = Step::backward_checked(res, 0x800)?;
444+
}
445+
// SAFETY: res is a valid unicode scalar
446+
// (below 0x110000 and not in 0xD800..0xE000)
447+
Some(unsafe { char::from_u32_unchecked(res) })
448+
}
449+
450+
#[inline]
451+
unsafe fn forward_unchecked(start: char, count: usize) -> char {
452+
let start = start as u32;
453+
let mut res = Step::forward_unchecked(start, count);
454+
if start < 0xD800 && 0xD800 <= res {
455+
res = Step::forward_unchecked(res, 0x800);
456+
}
457+
char::from_u32_unchecked(res)
458+
}
459+
460+
#[inline]
461+
unsafe fn backward_unchecked(start: char, count: usize) -> char {
462+
let start = start as u32;
463+
let mut res = Step::backward_unchecked(start, count);
464+
if start >= 0xE000 && 0xE000 > res {
465+
res = Step::backward_unchecked(res, 0x800);
466+
}
467+
char::from_u32_unchecked(res)
468+
}
469+
}
470+
403471
macro_rules! range_exact_iter_impl {
404472
($($t:ty)*) => ($(
405473
#[stable(feature = "rust1", since = "1.0.0")]
@@ -582,7 +650,11 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
582650
}
583651
let is_iterating = self.start < self.end;
584652
Some(if is_iterating {
585-
let n = Step::forward(self.start.clone(), 1);
653+
// SAFETY: just checked precondition
654+
// We use the unchecked version here, because
655+
// otherwise `for _ in '\0'..=char::MAX`
656+
// does not successfully remove panicking code.
657+
let n = unsafe { Step::forward_unchecked(self.start.clone(), 1) };
586658
mem::replace(&mut self.start, n)
587659
} else {
588660
self.exhausted = true;

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#![feature(const_panic)]
8686
#![feature(const_fn_union)]
8787
#![feature(const_generics)]
88+
#![feature(const_ptr_offset)]
8889
#![feature(const_ptr_offset_from)]
8990
#![feature(const_result)]
9091
#![feature(const_slice_from_raw_parts)]

src/libcore/ptr/const_ptr.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ impl<T: ?Sized> *const T {
151151
/// ```
152152
#[stable(feature = "rust1", since = "1.0.0")]
153153
#[must_use = "returns a new pointer rather than modifying its argument"]
154+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
154155
#[inline]
155-
pub unsafe fn offset(self, count: isize) -> *const T
156+
pub const unsafe fn offset(self, count: isize) -> *const T
156157
where
157158
T: Sized,
158159
{
@@ -210,8 +211,9 @@ impl<T: ?Sized> *const T {
210211
/// ```
211212
#[stable(feature = "ptr_wrapping_offset", since = "1.16.0")]
212213
#[must_use = "returns a new pointer rather than modifying its argument"]
214+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
213215
#[inline]
214-
pub fn wrapping_offset(self, count: isize) -> *const T
216+
pub const fn wrapping_offset(self, count: isize) -> *const T
215217
where
216218
T: Sized,
217219
{
@@ -393,8 +395,9 @@ impl<T: ?Sized> *const T {
393395
/// ```
394396
#[stable(feature = "pointer_methods", since = "1.26.0")]
395397
#[must_use = "returns a new pointer rather than modifying its argument"]
398+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
396399
#[inline]
397-
pub unsafe fn add(self, count: usize) -> Self
400+
pub const unsafe fn add(self, count: usize) -> Self
398401
where
399402
T: Sized,
400403
{
@@ -455,8 +458,9 @@ impl<T: ?Sized> *const T {
455458
/// ```
456459
#[stable(feature = "pointer_methods", since = "1.26.0")]
457460
#[must_use = "returns a new pointer rather than modifying its argument"]
461+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
458462
#[inline]
459-
pub unsafe fn sub(self, count: usize) -> Self
463+
pub const unsafe fn sub(self, count: usize) -> Self
460464
where
461465
T: Sized,
462466
{
@@ -511,8 +515,9 @@ impl<T: ?Sized> *const T {
511515
/// ```
512516
#[stable(feature = "pointer_methods", since = "1.26.0")]
513517
#[must_use = "returns a new pointer rather than modifying its argument"]
518+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
514519
#[inline]
515-
pub fn wrapping_add(self, count: usize) -> Self
520+
pub const fn wrapping_add(self, count: usize) -> Self
516521
where
517522
T: Sized,
518523
{
@@ -567,8 +572,9 @@ impl<T: ?Sized> *const T {
567572
/// ```
568573
#[stable(feature = "pointer_methods", since = "1.26.0")]
569574
#[must_use = "returns a new pointer rather than modifying its argument"]
575+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
570576
#[inline]
571-
pub fn wrapping_sub(self, count: usize) -> Self
577+
pub const fn wrapping_sub(self, count: usize) -> Self
572578
where
573579
T: Sized,
574580
{

src/libcore/ptr/mut_ptr.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ impl<T: ?Sized> *mut T {
145145
/// ```
146146
#[stable(feature = "rust1", since = "1.0.0")]
147147
#[must_use = "returns a new pointer rather than modifying its argument"]
148+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
148149
#[inline]
149-
pub unsafe fn offset(self, count: isize) -> *mut T
150+
pub const unsafe fn offset(self, count: isize) -> *mut T
150151
where
151152
T: Sized,
152153
{
@@ -203,8 +204,9 @@ impl<T: ?Sized> *mut T {
203204
/// ```
204205
#[stable(feature = "ptr_wrapping_offset", since = "1.16.0")]
205206
#[must_use = "returns a new pointer rather than modifying its argument"]
207+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
206208
#[inline]
207-
pub fn wrapping_offset(self, count: isize) -> *mut T
209+
pub const fn wrapping_offset(self, count: isize) -> *mut T
208210
where
209211
T: Sized,
210212
{
@@ -439,8 +441,9 @@ impl<T: ?Sized> *mut T {
439441
/// ```
440442
#[stable(feature = "pointer_methods", since = "1.26.0")]
441443
#[must_use = "returns a new pointer rather than modifying its argument"]
444+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
442445
#[inline]
443-
pub unsafe fn add(self, count: usize) -> Self
446+
pub const unsafe fn add(self, count: usize) -> Self
444447
where
445448
T: Sized,
446449
{
@@ -501,8 +504,9 @@ impl<T: ?Sized> *mut T {
501504
/// ```
502505
#[stable(feature = "pointer_methods", since = "1.26.0")]
503506
#[must_use = "returns a new pointer rather than modifying its argument"]
507+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
504508
#[inline]
505-
pub unsafe fn sub(self, count: usize) -> Self
509+
pub const unsafe fn sub(self, count: usize) -> Self
506510
where
507511
T: Sized,
508512
{
@@ -557,8 +561,9 @@ impl<T: ?Sized> *mut T {
557561
/// ```
558562
#[stable(feature = "pointer_methods", since = "1.26.0")]
559563
#[must_use = "returns a new pointer rather than modifying its argument"]
564+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
560565
#[inline]
561-
pub fn wrapping_add(self, count: usize) -> Self
566+
pub const fn wrapping_add(self, count: usize) -> Self
562567
where
563568
T: Sized,
564569
{
@@ -613,8 +618,9 @@ impl<T: ?Sized> *mut T {
613618
/// ```
614619
#[stable(feature = "pointer_methods", since = "1.26.0")]
615620
#[must_use = "returns a new pointer rather than modifying its argument"]
621+
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
616622
#[inline]
617-
pub fn wrapping_sub(self, count: usize) -> Self
623+
pub const fn wrapping_sub(self, count: usize) -> Self
618624
where
619625
T: Sized,
620626
{

src/libcore/tests/iter.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,18 @@ fn test_range() {
19561956
);
19571957
}
19581958

1959+
#[test]
1960+
fn test_char_range() {
1961+
use std::char;
1962+
assert!(('\0'..=char::MAX).eq((0..=char::MAX as u32).filter_map(char::from_u32)));
1963+
assert!(('\0'..=char::MAX).rev().eq((0..=char::MAX as u32).filter_map(char::from_u32).rev()));
1964+
1965+
assert_eq!(('\u{D7FF}'..='\u{E000}').count(), 2);
1966+
assert_eq!(('\u{D7FF}'..='\u{E000}').size_hint(), (2, Some(2)));
1967+
assert_eq!(('\u{D7FF}'..'\u{E000}').count(), 1);
1968+
assert_eq!(('\u{D7FF}'..'\u{E000}').size_hint(), (1, Some(1)));
1969+
}
1970+
19591971
#[test]
19601972
fn test_range_exhaustion() {
19611973
let mut r = 10..10;

src/librustc_codegen_llvm/asm.rs

+8
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
254254
]);
255255
}
256256
InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => {}
257+
InlineAsmArch::Nvptx64 => {}
257258
}
258259
}
259260
if !options.contains(InlineAsmOptions::NOMEM) {
@@ -410,6 +411,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass) -> String {
410411
| InlineAsmRegClass::Arm(ArmInlineAsmRegClass::qreg_low4) => "x",
411412
InlineAsmRegClass::Arm(ArmInlineAsmRegClass::dreg)
412413
| InlineAsmRegClass::Arm(ArmInlineAsmRegClass::qreg) => "w",
414+
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg16) => "h",
415+
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg32) => "r",
416+
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg64) => "l",
413417
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => "r",
414418
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => "f",
415419
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg) => "r",
@@ -452,6 +456,7 @@ fn modifier_to_llvm(
452456
modifier
453457
}
454458
}
459+
InlineAsmRegClass::Nvptx(_) => None,
455460
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg)
456461
| InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => None,
457462
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg)
@@ -502,6 +507,9 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll
502507
| InlineAsmRegClass::Arm(ArmInlineAsmRegClass::qreg_low4) => {
503508
cx.type_vector(cx.type_i64(), 2)
504509
}
510+
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg16) => cx.type_i16(),
511+
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg32) => cx.type_i32(),
512+
InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg64) => cx.type_i64(),
505513
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => cx.type_i32(),
506514
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => cx.type_f32(),
507515
InlineAsmRegClass::X86(X86InlineAsmRegClass::reg)

0 commit comments

Comments
 (0)