Skip to content

Commit c520802

Browse files
committed
Auto merge of #70722 - Centril:rollup-ar4gn1x, r=Centril
Rollup of 7 pull requests Successful merges: - #70487 (Stabilize float::to_int_unchecked) - #70595 (Remove unused discriminant reads from MIR bodies) - #70691 (Improve docs in `AllocRef`) - #70694 (Use Self over specific type in return position) - #70700 (Expand on platform details of `include_xxx` macros) - #70708 (Fix typo in u8::to_ascii_uppercase and u8::to_ascii_lowercase) - #70716 (Unerase regions in infer_placeholder_type) Failed merges: r? @ghost
2 parents 537ccdf + 98cf9d9 commit c520802

File tree

17 files changed

+150
-65
lines changed

17 files changed

+150
-65
lines changed

src/libcore/alloc/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ impl fmt::Display for AllocErr {
3333
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
3434
#[unstable(feature = "allocator_api", issue = "32838")]
3535
pub enum AllocInit {
36-
/// The contents of the new memory are undefined.
37-
///
38-
/// Reading uninitialized memory is Undefined Behavior; it must be initialized before use.
36+
/// The contents of the new memory are uninitialized.
3937
Uninitialized,
4038
/// The new memory is guaranteed to be zeroed.
4139
Zeroed,
@@ -196,7 +194,11 @@ pub unsafe trait AllocRef {
196194
///
197195
/// # Safety
198196
///
199-
/// `memory` must be a memory block returned by this allocator.
197+
/// * `ptr` must be [*currently allocated*] via this allocator, and
198+
/// * `layout` must [*fit*] the `ptr`.
199+
///
200+
/// [*currently allocated*]: #currently-allocated-memory
201+
/// [*fit*]: #memory-fitting
200202
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout);
201203

202204
/// Attempts to extend the memory block.
@@ -237,7 +239,7 @@ pub unsafe trait AllocRef {
237239
// * `new_size must be strictly greater than `memory.size` or both are zero
238240
/// * `new_size` must be greater than or equal to `layout.size()`
239241
/// * `new_size`, when rounded up to the nearest multiple of `layout.align()`, must not overflow
240-
/// (i.e., the rounded value must be less than `usize::MAX`).
242+
/// (i.e., the rounded value must be less than or equal to `usize::MAX`).
241243
///
242244
/// [*currently allocated*]: #currently-allocated-memory
243245
/// [*fit*]: #memory-fitting

src/libcore/convert/num.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ mod private {
1313
/// Typically doesn’t need to be used directly.
1414
#[unstable(feature = "convert_float_to_int", issue = "67057")]
1515
pub trait FloatToInt<Int>: private::Sealed + Sized {
16-
#[unstable(feature = "float_approx_unchecked_to", issue = "67058")]
16+
#[unstable(feature = "convert_float_to_int", issue = "67057")]
1717
#[doc(hidden)]
18-
unsafe fn approx_unchecked(self) -> Int;
18+
unsafe fn to_int_unchecked(self) -> Int;
1919
}
2020

2121
macro_rules! impl_float_to_int {
@@ -27,8 +27,15 @@ macro_rules! impl_float_to_int {
2727
impl FloatToInt<$Int> for $Float {
2828
#[doc(hidden)]
2929
#[inline]
30-
unsafe fn approx_unchecked(self) -> $Int {
31-
crate::intrinsics::float_to_int_approx_unchecked(self)
30+
unsafe fn to_int_unchecked(self) -> $Int {
31+
#[cfg(bootstrap)]
32+
{
33+
crate::intrinsics::float_to_int_approx_unchecked(self)
34+
}
35+
#[cfg(not(bootstrap))]
36+
{
37+
crate::intrinsics::float_to_int_unchecked(self)
38+
}
3239
}
3340
}
3441
)+

src/libcore/intrinsics.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1582,8 +1582,16 @@ extern "rust-intrinsic" {
15821582
/// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
15831583
/// (<https://github.com/rust-lang/rust/issues/10184>)
15841584
/// This is under stabilization at <https://github.com/rust-lang/rust/issues/67058>
1585+
#[cfg(bootstrap)]
15851586
pub fn float_to_int_approx_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
15861587

1588+
/// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
1589+
/// (<https://github.com/rust-lang/rust/issues/10184>)
1590+
///
1591+
/// Stabilized as `f32::to_int_unchecked` and `f64::to_int_unchecked`.
1592+
#[cfg(not(bootstrap))]
1593+
pub fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
1594+
15871595
/// Returns the number of bits set in an integer type `T`
15881596
///
15891597
/// The stabilized versions of this intrinsic are available on the integer

src/libcore/macros/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,10 @@ pub(crate) mod builtin {
10701070

10711071
/// Includes a utf8-encoded file as a string.
10721072
///
1073-
/// The file is located relative to the current file. (similarly to how
1074-
/// modules are found)
1073+
/// The file is located relative to the current file (similarly to how
1074+
/// modules are found). The provided path is interpreted in a platform-specific
1075+
/// way at compile time. So, for instance, an invocation with a Windows path
1076+
/// containing backslashes `\` would not compile correctly on Unix.
10751077
///
10761078
/// This macro will yield an expression of type `&'static str` which is the
10771079
/// contents of the file.
@@ -1108,8 +1110,10 @@ pub(crate) mod builtin {
11081110

11091111
/// Includes a file as a reference to a byte array.
11101112
///
1111-
/// The file is located relative to the current file. (similarly to how
1112-
/// modules are found)
1113+
/// The file is located relative to the current file (similarly to how
1114+
/// modules are found). The provided path is interpreted in a platform-specific
1115+
/// way at compile time. So, for instance, an invocation with a Windows path
1116+
/// containing backslashes `\` would not compile correctly on Unix.
11131117
///
11141118
/// This macro will yield an expression of type `&'static [u8; N]` which is
11151119
/// the contents of the file.
@@ -1202,7 +1206,9 @@ pub(crate) mod builtin {
12021206
/// Parses a file as an expression or an item according to the context.
12031207
///
12041208
/// The file is located relative to the current file (similarly to how
1205-
/// modules are found).
1209+
/// modules are found). The provided path is interpreted in a platform-specific
1210+
/// way at compile time. So, for instance, an invocation with a Windows path
1211+
/// containing backslashes `\` would not compile correctly on Unix.
12061212
///
12071213
/// Using this macro is often a bad idea, because if the file is
12081214
/// parsed as an expression, it is going to be placed in the

src/libcore/num/f32.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,12 @@ impl f32 {
464464
/// assuming that the value is finite and fits in that type.
465465
///
466466
/// ```
467-
/// #![feature(float_approx_unchecked_to)]
468-
///
469467
/// let value = 4.6_f32;
470-
/// let rounded = unsafe { value.approx_unchecked_to::<u16>() };
468+
/// let rounded = unsafe { value.to_int_unchecked::<u16>() };
471469
/// assert_eq!(rounded, 4);
472470
///
473471
/// let value = -128.9_f32;
474-
/// let rounded = unsafe { value.approx_unchecked_to::<i8>() };
472+
/// let rounded = unsafe { value.to_int_unchecked::<i8>() };
475473
/// assert_eq!(rounded, std::i8::MIN);
476474
/// ```
477475
///
@@ -482,13 +480,13 @@ impl f32 {
482480
/// * Not be `NaN`
483481
/// * Not be infinite
484482
/// * Be representable in the return type `Int`, after truncating off its fractional part
485-
#[unstable(feature = "float_approx_unchecked_to", issue = "67058")]
483+
#[stable(feature = "float_approx_unchecked_to", since = "1.44.0")]
486484
#[inline]
487-
pub unsafe fn approx_unchecked_to<Int>(self) -> Int
485+
pub unsafe fn to_int_unchecked<Int>(self) -> Int
488486
where
489487
Self: FloatToInt<Int>,
490488
{
491-
FloatToInt::<Int>::approx_unchecked(self)
489+
FloatToInt::<Int>::to_int_unchecked(self)
492490
}
493491

494492
/// Raw transmutation to `u32`.

src/libcore/num/f64.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,12 @@ impl f64 {
478478
/// assuming that the value is finite and fits in that type.
479479
///
480480
/// ```
481-
/// #![feature(float_approx_unchecked_to)]
482-
///
483481
/// let value = 4.6_f32;
484-
/// let rounded = unsafe { value.approx_unchecked_to::<u16>() };
482+
/// let rounded = unsafe { value.to_int_unchecked::<u16>() };
485483
/// assert_eq!(rounded, 4);
486484
///
487485
/// let value = -128.9_f32;
488-
/// let rounded = unsafe { value.approx_unchecked_to::<i8>() };
486+
/// let rounded = unsafe { value.to_int_unchecked::<i8>() };
489487
/// assert_eq!(rounded, std::i8::MIN);
490488
/// ```
491489
///
@@ -496,13 +494,13 @@ impl f64 {
496494
/// * Not be `NaN`
497495
/// * Not be infinite
498496
/// * Be representable in the return type `Int`, after truncating off its fractional part
499-
#[unstable(feature = "float_approx_unchecked_to", issue = "67058")]
497+
#[stable(feature = "float_approx_unchecked_to", since = "1.44.0")]
500498
#[inline]
501-
pub unsafe fn approx_unchecked_to<Int>(self) -> Int
499+
pub unsafe fn to_int_unchecked<Int>(self) -> Int
502500
where
503501
Self: FloatToInt<Int>,
504502
{
505-
FloatToInt::<Int>::approx_unchecked(self)
503+
FloatToInt::<Int>::to_int_unchecked(self)
506504
}
507505

508506
/// Raw transmutation to `u64`.

src/libcore/num/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4376,7 +4376,7 @@ impl u8 {
43764376
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
43774377
#[inline]
43784378
pub fn to_ascii_uppercase(&self) -> u8 {
4379-
// Unset the fith bit if this is a lowercase letter
4379+
// Unset the fifth bit if this is a lowercase letter
43804380
*self & !((self.is_ascii_lowercase() as u8) << 5)
43814381
}
43824382

@@ -4399,7 +4399,7 @@ impl u8 {
43994399
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
44004400
#[inline]
44014401
pub fn to_ascii_lowercase(&self) -> u8 {
4402-
// Set the fith bit if this is an uppercase letter
4402+
// Set the fifth bit if this is an uppercase letter
44034403
*self | ((self.is_ascii_uppercase() as u8) << 5)
44044404
}
44054405

src/librustc_codegen_llvm/intrinsic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,13 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
543543
}
544544
}
545545

546-
"float_to_int_approx_unchecked" => {
546+
"float_to_int_unchecked" => {
547547
if float_type_width(arg_tys[0]).is_none() {
548548
span_invalid_monomorphization_error(
549549
tcx.sess,
550550
span,
551551
&format!(
552-
"invalid monomorphization of `float_to_int_approx_unchecked` \
552+
"invalid monomorphization of `float_to_int_unchecked` \
553553
intrinsic: expected basic float type, \
554554
found `{}`",
555555
arg_tys[0]
@@ -570,7 +570,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
570570
tcx.sess,
571571
span,
572572
&format!(
573-
"invalid monomorphization of `float_to_int_approx_unchecked` \
573+
"invalid monomorphization of `float_to_int_unchecked` \
574574
intrinsic: expected basic integer type, \
575575
found `{}`",
576576
ret_ty

src/librustc_mir/transform/simplify.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,22 @@ impl<'a, 'tcx> Visitor<'tcx> for DeclMarker<'a, 'tcx> {
368368
if location.statement_index != block.statements.len() {
369369
let stmt = &block.statements[location.statement_index];
370370

371-
if let StatementKind::Assign(box (p, Rvalue::Use(Operand::Constant(c)))) =
372-
&stmt.kind
373-
{
374-
match c.literal.val {
375-
// Keep assignments from unevaluated constants around, since the evaluation
376-
// may report errors, even if the use of the constant is dead code.
377-
ty::ConstKind::Unevaluated(..) => {}
378-
_ => {
379-
if !p.is_indirect() {
380-
trace!("skipping store of const value {:?} to {:?}", c, p);
381-
return;
371+
if let StatementKind::Assign(box (dest, rvalue)) = &stmt.kind {
372+
if !dest.is_indirect() && dest.local == *local {
373+
if let Rvalue::Use(Operand::Constant(c)) = rvalue {
374+
match c.literal.val {
375+
// Keep assignments from unevaluated constants around, since the
376+
// evaluation may report errors, even if the use of the constant
377+
// is dead code.
378+
ty::ConstKind::Unevaluated(..) => {}
379+
_ => {
380+
trace!("skipping store of const value {:?} to {:?}", c, dest);
381+
return;
382+
}
382383
}
384+
} else if let Rvalue::Discriminant(d) = rvalue {
385+
trace!("skipping store of discriminant value {:?} to {:?}", d, dest);
386+
return;
383387
}
384388
}
385389
}

src/librustc_typeck/check/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
275275
"fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" => {
276276
(1, vec![param(0), param(0)], param(0))
277277
}
278-
"float_to_int_approx_unchecked" => (2, vec![param(0)], param(1)),
278+
"float_to_int_unchecked" => (2, vec![param(0)], param(1)),
279279

280280
"assume" => (0, vec![tcx.types.bool], tcx.mk_unit()),
281281
"likely" => (0, vec![tcx.types.bool], tcx.types.bool),

src/librustc_typeck/collect/type_of.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,11 @@ fn infer_placeholder_type(
655655
}
656656
}
657657

658-
ty
658+
// Typeck doesn't expect erased regions to be returned from `type_of`.
659+
tcx.fold_regions(&ty, &mut false, |r, _| match r {
660+
ty::ReErased => tcx.lifetimes.re_static,
661+
_ => r,
662+
})
659663
}
660664

661665
fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) {

src/libstd/fs.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ impl OpenOptions {
734734
/// let file = options.read(true).open("foo.txt");
735735
/// ```
736736
#[stable(feature = "rust1", since = "1.0.0")]
737-
pub fn new() -> OpenOptions {
737+
pub fn new() -> Self {
738738
OpenOptions(fs_imp::OpenOptions::new())
739739
}
740740

@@ -751,7 +751,7 @@ impl OpenOptions {
751751
/// let file = OpenOptions::new().read(true).open("foo.txt");
752752
/// ```
753753
#[stable(feature = "rust1", since = "1.0.0")]
754-
pub fn read(&mut self, read: bool) -> &mut OpenOptions {
754+
pub fn read(&mut self, read: bool) -> &mut Self {
755755
self.0.read(read);
756756
self
757757
}
@@ -772,7 +772,7 @@ impl OpenOptions {
772772
/// let file = OpenOptions::new().write(true).open("foo.txt");
773773
/// ```
774774
#[stable(feature = "rust1", since = "1.0.0")]
775-
pub fn write(&mut self, write: bool) -> &mut OpenOptions {
775+
pub fn write(&mut self, write: bool) -> &mut Self {
776776
self.0.write(write);
777777
self
778778
}
@@ -819,7 +819,7 @@ impl OpenOptions {
819819
/// let file = OpenOptions::new().append(true).open("foo.txt");
820820
/// ```
821821
#[stable(feature = "rust1", since = "1.0.0")]
822-
pub fn append(&mut self, append: bool) -> &mut OpenOptions {
822+
pub fn append(&mut self, append: bool) -> &mut Self {
823823
self.0.append(append);
824824
self
825825
}
@@ -839,7 +839,7 @@ impl OpenOptions {
839839
/// let file = OpenOptions::new().write(true).truncate(true).open("foo.txt");
840840
/// ```
841841
#[stable(feature = "rust1", since = "1.0.0")]
842-
pub fn truncate(&mut self, truncate: bool) -> &mut OpenOptions {
842+
pub fn truncate(&mut self, truncate: bool) -> &mut Self {
843843
self.0.truncate(truncate);
844844
self
845845
}
@@ -860,7 +860,7 @@ impl OpenOptions {
860860
/// let file = OpenOptions::new().write(true).create(true).open("foo.txt");
861861
/// ```
862862
#[stable(feature = "rust1", since = "1.0.0")]
863-
pub fn create(&mut self, create: bool) -> &mut OpenOptions {
863+
pub fn create(&mut self, create: bool) -> &mut Self {
864864
self.0.create(create);
865865
self
866866
}
@@ -893,7 +893,7 @@ impl OpenOptions {
893893
/// .open("foo.txt");
894894
/// ```
895895
#[stable(feature = "expand_open_options2", since = "1.9.0")]
896-
pub fn create_new(&mut self, create_new: bool) -> &mut OpenOptions {
896+
pub fn create_new(&mut self, create_new: bool) -> &mut Self {
897897
self.0.create_new(create_new);
898898
self
899899
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fn map(x: Option<Box<()>>) -> Option<Box<()>> {
2+
match x {
3+
None => None,
4+
Some(x) => Some(x),
5+
}
6+
}
7+
8+
fn main() {
9+
map(None);
10+
}
11+
12+
// EMIT_MIR rustc.map.SimplifyLocals.diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
- // MIR for `map` before SimplifyLocals
2+
+ // MIR for `map` after SimplifyLocals
3+
4+
fn map(_1: std::option::Option<std::boxed::Box<()>>) -> std::option::Option<std::boxed::Box<()>> {
5+
debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:8: 1:9
6+
let mut _0: std::option::Option<std::boxed::Box<()>>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:31: 1:46
7+
let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
8+
let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15
9+
- let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:25: 4:26
10+
- let mut _5: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
11+
- let mut _6: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
12+
scope 1 {
13+
debug x => _3; // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15
14+
}
15+
16+
bb0: {
17+
_2 = discriminant(_1); // bb0[0]: scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
18+
switchInt(move _2) -> [0isize: bb2, otherwise: bb1]; // bb0[1]: scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13
19+
}
20+
21+
bb1: {
22+
_0 = move _1; // bb1[0]: scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27
23+
goto -> bb3; // bb1[1]: scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:2:5: 5:6
24+
}
25+
26+
bb2: {
27+
discriminant(_0) = 0; // bb2[0]: scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:17: 3:21
28+
goto -> bb3; // bb2[1]: scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:2:5: 5:6
29+
}
30+
31+
bb3: {
32+
- _5 = discriminant(_1); // bb3[0]: scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2
33+
- return; // bb3[1]: scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:2: 6:2
34+
+ return; // bb3[0]: scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:2: 6:2
35+
}
36+
}
37+

0 commit comments

Comments
 (0)