Skip to content

Commit 3b65165

Browse files
committed
Auto merge of rust-lang#91064 - matthiaskrgr:rollup-2ijidpt, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#88361 (Makes docs for references a little less confusing) - rust-lang#90089 (Improve display of enum variants) - rust-lang#90956 (Add a regression test for rust-lang#87573) - rust-lang#90999 (fix CTFE/Miri simd_insert/extract on array-style repr(simd) types) - rust-lang#91026 (rustdoc doctest: detect `fn main` after an unexpected semicolon) - rust-lang#91035 (Put back removed empty line) - rust-lang#91044 (Turn all 0x1b_u8 into '\x1b' or b'\x1b') - rust-lang#91054 (rustdoc: Fix some unescaped HTML tags in docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a77da2d + 54bc333 commit 3b65165

File tree

21 files changed

+293
-129
lines changed

21 files changed

+293
-129
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+16-31
Original file line numberDiff line numberDiff line change
@@ -419,48 +419,33 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
419419
sym::simd_insert => {
420420
let index = u64::from(self.read_scalar(&args[1])?.to_u32()?);
421421
let elem = &args[2];
422-
let input = &args[0];
423-
let (len, e_ty) = input.layout.ty.simd_size_and_type(*self.tcx);
422+
let (input, input_len) = self.operand_to_simd(&args[0])?;
423+
let (dest, dest_len) = self.place_to_simd(dest)?;
424+
assert_eq!(input_len, dest_len, "Return vector length must match input length");
424425
assert!(
425-
index < len,
426-
"Index `{}` must be in bounds of vector type `{}`: `[0, {})`",
426+
index < dest_len,
427+
"Index `{}` must be in bounds of vector with length {}`",
427428
index,
428-
e_ty,
429-
len
430-
);
431-
assert_eq!(
432-
input.layout, dest.layout,
433-
"Return type `{}` must match vector type `{}`",
434-
dest.layout.ty, input.layout.ty
435-
);
436-
assert_eq!(
437-
elem.layout.ty, e_ty,
438-
"Scalar element type `{}` must match vector element type `{}`",
439-
elem.layout.ty, e_ty
429+
dest_len
440430
);
441431

442-
for i in 0..len {
443-
let place = self.place_index(dest, i)?;
444-
let value = if i == index { *elem } else { self.operand_index(input, i)? };
445-
self.copy_op(&value, &place)?;
432+
for i in 0..dest_len {
433+
let place = self.mplace_index(&dest, i)?;
434+
let value =
435+
if i == index { *elem } else { self.mplace_index(&input, i)?.into() };
436+
self.copy_op(&value, &place.into())?;
446437
}
447438
}
448439
sym::simd_extract => {
449440
let index = u64::from(self.read_scalar(&args[1])?.to_u32()?);
450-
let (len, e_ty) = args[0].layout.ty.simd_size_and_type(*self.tcx);
441+
let (input, input_len) = self.operand_to_simd(&args[0])?;
451442
assert!(
452-
index < len,
453-
"index `{}` is out-of-bounds of vector type `{}` with length `{}`",
443+
index < input_len,
444+
"index `{}` must be in bounds of vector with length `{}`",
454445
index,
455-
e_ty,
456-
len
457-
);
458-
assert_eq!(
459-
e_ty, dest.layout.ty,
460-
"Return type `{}` must match vector element type `{}`",
461-
dest.layout.ty, e_ty
446+
input_len
462447
);
463-
self.copy_op(&self.operand_index(&args[0], index)?, dest)?;
448+
self.copy_op(&self.mplace_index(&input, index)?.into(), dest)?;
464449
}
465450
sym::likely | sym::unlikely | sym::black_box => {
466451
// These just return their argument

compiler/rustc_const_eval/src/interpret/operand.rs

+12
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
437437
})
438438
}
439439

440+
/// Converts a repr(simd) operand into an operand where `place_index` accesses the SIMD elements.
441+
/// Also returns the number of elements.
442+
pub fn operand_to_simd(
443+
&self,
444+
base: &OpTy<'tcx, M::PointerTag>,
445+
) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, u64)> {
446+
// Basically we just transmute this place into an array following simd_size_and_type.
447+
// This only works in memory, but repr(simd) types should never be immediates anyway.
448+
assert!(base.layout.ty.is_simd());
449+
self.mplace_to_simd(&base.assert_mem_place())
450+
}
451+
440452
/// Read from a local. Will not actually access the local if reading from a ZST.
441453
/// Will not access memory, instead an indirect `Operand` is returned.
442454
///

compiler/rustc_const_eval/src/interpret/place.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'tcx, Tag: Provenance> MPlaceTy<'tcx, Tag> {
200200
}
201201
} else {
202202
// Go through the layout. There are lots of types that support a length,
203-
// e.g., SIMD types.
203+
// e.g., SIMD types. (But not all repr(simd) types even have FieldsShape::Array!)
204204
match self.layout.fields {
205205
FieldsShape::Array { count, .. } => Ok(count),
206206
_ => bug!("len not supported on sized type {:?}", self.layout.ty),
@@ -533,6 +533,22 @@ where
533533
})
534534
}
535535

536+
/// Converts a repr(simd) place into a place where `place_index` accesses the SIMD elements.
537+
/// Also returns the number of elements.
538+
pub fn mplace_to_simd(
539+
&self,
540+
base: &MPlaceTy<'tcx, M::PointerTag>,
541+
) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, u64)> {
542+
// Basically we just transmute this place into an array following simd_size_and_type.
543+
// (Transmuting is okay since this is an in-memory place. We also double-check the size
544+
// stays the same.)
545+
let (len, e_ty) = base.layout.ty.simd_size_and_type(*self.tcx);
546+
let array = self.tcx.mk_array(e_ty, len);
547+
let layout = self.layout_of(array)?;
548+
assert_eq!(layout.size, base.layout.size);
549+
Ok((MPlaceTy { layout, ..*base }, len))
550+
}
551+
536552
/// Gets the place of a field inside the place, and also the field's type.
537553
/// Just a convenience function, but used quite a bit.
538554
/// This is the only projection that might have a side-effect: We cannot project
@@ -594,6 +610,16 @@ where
594610
})
595611
}
596612

613+
/// Converts a repr(simd) place into a place where `place_index` accesses the SIMD elements.
614+
/// Also returns the number of elements.
615+
pub fn place_to_simd(
616+
&mut self,
617+
base: &PlaceTy<'tcx, M::PointerTag>,
618+
) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, u64)> {
619+
let mplace = self.force_allocation(base)?;
620+
self.mplace_to_simd(&mplace)
621+
}
622+
597623
/// Computes a place. You should only use this if you intend to write into this
598624
/// place; for reading, a more efficient alternative is `eval_place_for_read`.
599625
pub fn eval_place(

compiler/rustc_middle/src/ty/sty.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1805,17 +1805,22 @@ impl<'tcx> TyS<'tcx> {
18051805
pub fn simd_size_and_type(&self, tcx: TyCtxt<'tcx>) -> (u64, Ty<'tcx>) {
18061806
match self.kind() {
18071807
Adt(def, substs) => {
1808+
assert!(def.repr.simd(), "`simd_size_and_type` called on non-SIMD type");
18081809
let variant = def.non_enum_variant();
18091810
let f0_ty = variant.fields[0].ty(tcx, substs);
18101811

18111812
match f0_ty.kind() {
1813+
// If the first field is an array, we assume it is the only field and its
1814+
// elements are the SIMD components.
18121815
Array(f0_elem_ty, f0_len) => {
18131816
// FIXME(repr_simd): https://github.com/rust-lang/rust/pull/78863#discussion_r522784112
18141817
// The way we evaluate the `N` in `[T; N]` here only works since we use
18151818
// `simd_size_and_type` post-monomorphization. It will probably start to ICE
18161819
// if we use it in generic code. See the `simd-array-trait` ui test.
18171820
(f0_len.eval_usize(tcx, ParamEnv::empty()) as u64, f0_elem_ty)
18181821
}
1822+
// Otherwise, the fields of this Adt are the SIMD components (and we assume they
1823+
// all have the same type).
18191824
_ => (variant.fields.len() as u64, f0_ty),
18201825
}
18211826
}

library/core/src/char/methods.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ impl char {
12501250
/// let percent = '%';
12511251
/// let space = ' ';
12521252
/// let lf = '\n';
1253-
/// let esc: char = 0x1b_u8.into();
1253+
/// let esc = '\x1b';
12541254
///
12551255
/// assert!(uppercase_a.is_ascii_alphabetic());
12561256
/// assert!(uppercase_g.is_ascii_alphabetic());
@@ -1284,7 +1284,7 @@ impl char {
12841284
/// let percent = '%';
12851285
/// let space = ' ';
12861286
/// let lf = '\n';
1287-
/// let esc: char = 0x1b_u8.into();
1287+
/// let esc = '\x1b';
12881288
///
12891289
/// assert!(uppercase_a.is_ascii_uppercase());
12901290
/// assert!(uppercase_g.is_ascii_uppercase());
@@ -1318,7 +1318,7 @@ impl char {
13181318
/// let percent = '%';
13191319
/// let space = ' ';
13201320
/// let lf = '\n';
1321-
/// let esc: char = 0x1b_u8.into();
1321+
/// let esc = '\x1b';
13221322
///
13231323
/// assert!(!uppercase_a.is_ascii_lowercase());
13241324
/// assert!(!uppercase_g.is_ascii_lowercase());
@@ -1355,7 +1355,7 @@ impl char {
13551355
/// let percent = '%';
13561356
/// let space = ' ';
13571357
/// let lf = '\n';
1358-
/// let esc: char = 0x1b_u8.into();
1358+
/// let esc = '\x1b';
13591359
///
13601360
/// assert!(uppercase_a.is_ascii_alphanumeric());
13611361
/// assert!(uppercase_g.is_ascii_alphanumeric());
@@ -1389,7 +1389,7 @@ impl char {
13891389
/// let percent = '%';
13901390
/// let space = ' ';
13911391
/// let lf = '\n';
1392-
/// let esc: char = 0x1b_u8.into();
1392+
/// let esc = '\x1b';
13931393
///
13941394
/// assert!(!uppercase_a.is_ascii_digit());
13951395
/// assert!(!uppercase_g.is_ascii_digit());
@@ -1426,7 +1426,7 @@ impl char {
14261426
/// let percent = '%';
14271427
/// let space = ' ';
14281428
/// let lf = '\n';
1429-
/// let esc: char = 0x1b_u8.into();
1429+
/// let esc = '\x1b';
14301430
///
14311431
/// assert!(uppercase_a.is_ascii_hexdigit());
14321432
/// assert!(!uppercase_g.is_ascii_hexdigit());
@@ -1464,7 +1464,7 @@ impl char {
14641464
/// let percent = '%';
14651465
/// let space = ' ';
14661466
/// let lf = '\n';
1467-
/// let esc: char = 0x1b_u8.into();
1467+
/// let esc = '\x1b';
14681468
///
14691469
/// assert!(!uppercase_a.is_ascii_punctuation());
14701470
/// assert!(!uppercase_g.is_ascii_punctuation());
@@ -1498,7 +1498,7 @@ impl char {
14981498
/// let percent = '%';
14991499
/// let space = ' ';
15001500
/// let lf = '\n';
1501-
/// let esc: char = 0x1b_u8.into();
1501+
/// let esc = '\x1b';
15021502
///
15031503
/// assert!(uppercase_a.is_ascii_graphic());
15041504
/// assert!(uppercase_g.is_ascii_graphic());
@@ -1549,7 +1549,7 @@ impl char {
15491549
/// let percent = '%';
15501550
/// let space = ' ';
15511551
/// let lf = '\n';
1552-
/// let esc: char = 0x1b_u8.into();
1552+
/// let esc = '\x1b';
15531553
///
15541554
/// assert!(!uppercase_a.is_ascii_whitespace());
15551555
/// assert!(!uppercase_g.is_ascii_whitespace());
@@ -1585,7 +1585,7 @@ impl char {
15851585
/// let percent = '%';
15861586
/// let space = ' ';
15871587
/// let lf = '\n';
1588-
/// let esc: char = 0x1b_u8.into();
1588+
/// let esc = '\x1b';
15891589
///
15901590
/// assert!(!uppercase_a.is_ascii_control());
15911591
/// assert!(!uppercase_g.is_ascii_control());

library/core/src/num/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl u8 {
428428
/// let percent = b'%';
429429
/// let space = b' ';
430430
/// let lf = b'\n';
431-
/// let esc = 0x1b_u8;
431+
/// let esc = b'\x1b';
432432
///
433433
/// assert!(uppercase_a.is_ascii_alphabetic());
434434
/// assert!(uppercase_g.is_ascii_alphabetic());
@@ -462,7 +462,7 @@ impl u8 {
462462
/// let percent = b'%';
463463
/// let space = b' ';
464464
/// let lf = b'\n';
465-
/// let esc = 0x1b_u8;
465+
/// let esc = b'\x1b';
466466
///
467467
/// assert!(uppercase_a.is_ascii_uppercase());
468468
/// assert!(uppercase_g.is_ascii_uppercase());
@@ -496,7 +496,7 @@ impl u8 {
496496
/// let percent = b'%';
497497
/// let space = b' ';
498498
/// let lf = b'\n';
499-
/// let esc = 0x1b_u8;
499+
/// let esc = b'\x1b';
500500
///
501501
/// assert!(!uppercase_a.is_ascii_lowercase());
502502
/// assert!(!uppercase_g.is_ascii_lowercase());
@@ -533,7 +533,7 @@ impl u8 {
533533
/// let percent = b'%';
534534
/// let space = b' ';
535535
/// let lf = b'\n';
536-
/// let esc = 0x1b_u8;
536+
/// let esc = b'\x1b';
537537
///
538538
/// assert!(uppercase_a.is_ascii_alphanumeric());
539539
/// assert!(uppercase_g.is_ascii_alphanumeric());
@@ -567,7 +567,7 @@ impl u8 {
567567
/// let percent = b'%';
568568
/// let space = b' ';
569569
/// let lf = b'\n';
570-
/// let esc = 0x1b_u8;
570+
/// let esc = b'\x1b';
571571
///
572572
/// assert!(!uppercase_a.is_ascii_digit());
573573
/// assert!(!uppercase_g.is_ascii_digit());
@@ -604,7 +604,7 @@ impl u8 {
604604
/// let percent = b'%';
605605
/// let space = b' ';
606606
/// let lf = b'\n';
607-
/// let esc = 0x1b_u8;
607+
/// let esc = b'\x1b';
608608
///
609609
/// assert!(uppercase_a.is_ascii_hexdigit());
610610
/// assert!(!uppercase_g.is_ascii_hexdigit());
@@ -642,7 +642,7 @@ impl u8 {
642642
/// let percent = b'%';
643643
/// let space = b' ';
644644
/// let lf = b'\n';
645-
/// let esc = 0x1b_u8;
645+
/// let esc = b'\x1b';
646646
///
647647
/// assert!(!uppercase_a.is_ascii_punctuation());
648648
/// assert!(!uppercase_g.is_ascii_punctuation());
@@ -676,7 +676,7 @@ impl u8 {
676676
/// let percent = b'%';
677677
/// let space = b' ';
678678
/// let lf = b'\n';
679-
/// let esc = 0x1b_u8;
679+
/// let esc = b'\x1b';
680680
///
681681
/// assert!(uppercase_a.is_ascii_graphic());
682682
/// assert!(uppercase_g.is_ascii_graphic());
@@ -727,7 +727,7 @@ impl u8 {
727727
/// let percent = b'%';
728728
/// let space = b' ';
729729
/// let lf = b'\n';
730-
/// let esc = 0x1b_u8;
730+
/// let esc = b'\x1b';
731731
///
732732
/// assert!(!uppercase_a.is_ascii_whitespace());
733733
/// assert!(!uppercase_g.is_ascii_whitespace());
@@ -763,7 +763,7 @@ impl u8 {
763763
/// let percent = b'%';
764764
/// let space = b' ';
765765
/// let lf = b'\n';
766-
/// let esc = 0x1b_u8;
766+
/// let esc = b'\x1b';
767767
///
768768
/// assert!(!uppercase_a.is_ascii_control());
769769
/// assert!(!uppercase_g.is_ascii_control());

library/core/src/primitive_docs.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1104,11 +1104,10 @@ mod prim_usize {}
11041104
/// * [`Clone`] \(Note that this will not defer to `T`'s `Clone` implementation if it exists!)
11051105
/// * [`Deref`]
11061106
/// * [`Borrow`]
1107-
/// * [`Pointer`]
1107+
/// * [`fmt::Pointer`]
11081108
///
11091109
/// [`Deref`]: ops::Deref
11101110
/// [`Borrow`]: borrow::Borrow
1111-
/// [`Pointer`]: fmt::Pointer
11121111
///
11131112
/// `&mut T` references get all of the above except `Copy` and `Clone` (to prevent creating
11141113
/// multiple simultaneous mutable borrows), plus the following, regardless of the type of its
@@ -1124,7 +1123,7 @@ mod prim_usize {}
11241123
/// The following traits are implemented on `&T` references if the underlying `T` also implements
11251124
/// that trait:
11261125
///
1127-
/// * All the traits in [`std::fmt`] except [`Pointer`] and [`fmt::Write`]
1126+
/// * All the traits in [`std::fmt`] except [`fmt::Pointer`] (which is implemented regardless of the type of its referent) and [`fmt::Write`]
11281127
/// * [`PartialOrd`]
11291128
/// * [`Ord`]
11301129
/// * [`PartialEq`]
@@ -1133,9 +1132,9 @@ mod prim_usize {}
11331132
/// * [`Fn`] \(in addition, `&T` references get [`FnMut`] and [`FnOnce`] if `T: Fn`)
11341133
/// * [`Hash`]
11351134
/// * [`ToSocketAddrs`]
1135+
/// * [`Send`] \(`&T` references also require <code>T: [Sync]</code>)
11361136
///
11371137
/// [`std::fmt`]: fmt
1138-
/// ['Pointer`]: fmt::Pointer
11391138
/// [`Hash`]: hash::Hash
11401139
#[doc = concat!("[`ToSocketAddrs`]: ", include_str!("../primitive_docs/net_tosocketaddrs.md"))]
11411140
///
@@ -1150,7 +1149,6 @@ mod prim_usize {}
11501149
/// * [`ExactSizeIterator`]
11511150
/// * [`FusedIterator`]
11521151
/// * [`TrustedLen`]
1153-
/// * [`Send`] \(note that `&T` references only get `Send` if <code>T: [Sync]</code>)
11541152
/// * [`io::Write`]
11551153
/// * [`Read`]
11561154
/// * [`Seek`]

0 commit comments

Comments
 (0)