Skip to content

Commit f5d1857

Browse files
committed
Auto merge of #133415 - matthiaskrgr:rollup-n1ivyd5, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #133300 (inject_panic_runtime(): Avoid double negation for 'any non rlib') - #133301 (Add code example for `wrapping_neg` method for signed integers) - #133371 (remove is_trivially_const_drop) - #133389 (Stabilize `const_float_methods`) - #133398 (rustdoc: do not call to_string, it's already impl Display) - #133405 (tidy: Distinguish between two different meanings of "style file") r? `@ghost` `@rustbot` modify labels: rollup
2 parents ab3cf26 + 3ccacef commit f5d1857

File tree

15 files changed

+90
-111
lines changed

15 files changed

+90
-111
lines changed

Diff for: compiler/rustc_const_eval/src/check_consts/qualifs.rs

-5
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@ impl Qualif for NeedsNonConstDrop {
170170

171171
#[instrument(level = "trace", skip(cx), ret)]
172172
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
173-
// Avoid selecting for simple cases, such as builtin types.
174-
if ty::util::is_trivially_const_drop(ty) {
175-
return false;
176-
}
177-
178173
// If this doesn't need drop at all, then don't select `~const Destruct`.
179174
if !ty.needs_drop(cx.tcx, cx.typing_env) {
180175
return false;

Diff for: compiler/rustc_metadata/src/creader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
724724
fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
725725
// If we're only compiling an rlib, then there's no need to select a
726726
// panic runtime, so we just skip this section entirely.
727-
let any_non_rlib = self.tcx.crate_types().iter().any(|ct| *ct != CrateType::Rlib);
728-
if !any_non_rlib {
727+
let only_rlib = self.tcx.crate_types().iter().all(|ct| *ct == CrateType::Rlib);
728+
if only_rlib {
729729
info!("panic runtime injection skipped, only generating rlib");
730730
return;
731731
}

Diff for: compiler/rustc_middle/src/ty/util.rs

-39
Original file line numberDiff line numberDiff line change
@@ -1672,45 +1672,6 @@ pub fn needs_drop_components_with_async<'tcx>(
16721672
}
16731673
}
16741674

1675-
pub fn is_trivially_const_drop(ty: Ty<'_>) -> bool {
1676-
match *ty.kind() {
1677-
ty::Bool
1678-
| ty::Char
1679-
| ty::Int(_)
1680-
| ty::Uint(_)
1681-
| ty::Float(_)
1682-
| ty::Infer(ty::IntVar(_))
1683-
| ty::Infer(ty::FloatVar(_))
1684-
| ty::Str
1685-
| ty::RawPtr(_, _)
1686-
| ty::Ref(..)
1687-
| ty::FnDef(..)
1688-
| ty::FnPtr(..)
1689-
| ty::Never
1690-
| ty::Foreign(_) => true,
1691-
1692-
ty::Alias(..)
1693-
| ty::Dynamic(..)
1694-
| ty::Error(_)
1695-
| ty::Bound(..)
1696-
| ty::Param(_)
1697-
| ty::Placeholder(_)
1698-
| ty::Infer(_) => false,
1699-
1700-
// Not trivial because they have components, and instead of looking inside,
1701-
// we'll just perform trait selection.
1702-
ty::Closure(..)
1703-
| ty::CoroutineClosure(..)
1704-
| ty::Coroutine(..)
1705-
| ty::CoroutineWitness(..)
1706-
| ty::Adt(..) => false,
1707-
1708-
ty::Array(ty, _) | ty::Slice(ty) | ty::Pat(ty, _) => is_trivially_const_drop(ty),
1709-
1710-
ty::Tuple(tys) => tys.iter().all(|ty| is_trivially_const_drop(ty)),
1711-
}
1712-
}
1713-
17141675
/// Does the equivalent of
17151676
/// ```ignore (illustrative)
17161677
/// let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();

Diff for: library/core/src/intrinsics/mod.rs

+40-8
Original file line numberDiff line numberDiff line change
@@ -4267,7 +4267,11 @@ pub const fn minnumf16(_x: f16, _y: f16) -> f16 {
42674267
/// The stabilized version of this intrinsic is
42684268
/// [`f32::min`]
42694269
#[rustc_nounwind]
4270-
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_float_methods", issue = "130843"))]
4270+
#[cfg_attr(
4271+
bootstrap,
4272+
rustc_const_stable(feature = "const_float_methods", since = "CURRENT_RUSTC_VERSION")
4273+
)]
4274+
#[cfg_attr(not(bootstrap), rustc_intrinsic_const_stable_indirect)]
42714275
#[rustc_intrinsic]
42724276
#[rustc_intrinsic_must_be_overridden]
42734277
pub const fn minnumf32(_x: f32, _y: f32) -> f32 {
@@ -4284,7 +4288,11 @@ pub const fn minnumf32(_x: f32, _y: f32) -> f32 {
42844288
/// The stabilized version of this intrinsic is
42854289
/// [`f64::min`]
42864290
#[rustc_nounwind]
4287-
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_float_methods", issue = "130843"))]
4291+
#[cfg_attr(
4292+
bootstrap,
4293+
rustc_const_stable(feature = "const_float_methods", since = "CURRENT_RUSTC_VERSION")
4294+
)]
4295+
#[cfg_attr(not(bootstrap), rustc_intrinsic_const_stable_indirect)]
42884296
#[rustc_intrinsic]
42894297
#[rustc_intrinsic_must_be_overridden]
42904298
pub const fn minnumf64(_x: f64, _y: f64) -> f64 {
@@ -4335,7 +4343,11 @@ pub const fn maxnumf16(_x: f16, _y: f16) -> f16 {
43354343
/// The stabilized version of this intrinsic is
43364344
/// [`f32::max`]
43374345
#[rustc_nounwind]
4338-
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_float_methods", issue = "130843"))]
4346+
#[cfg_attr(
4347+
bootstrap,
4348+
rustc_const_stable(feature = "const_float_methods", since = "CURRENT_RUSTC_VERSION")
4349+
)]
4350+
#[cfg_attr(not(bootstrap), rustc_intrinsic_const_stable_indirect)]
43394351
#[rustc_intrinsic]
43404352
#[rustc_intrinsic_must_be_overridden]
43414353
pub const fn maxnumf32(_x: f32, _y: f32) -> f32 {
@@ -4352,7 +4364,11 @@ pub const fn maxnumf32(_x: f32, _y: f32) -> f32 {
43524364
/// The stabilized version of this intrinsic is
43534365
/// [`f64::max`]
43544366
#[rustc_nounwind]
4355-
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_float_methods", issue = "130843"))]
4367+
#[cfg_attr(
4368+
bootstrap,
4369+
rustc_const_stable(feature = "const_float_methods", since = "CURRENT_RUSTC_VERSION")
4370+
)]
4371+
#[cfg_attr(not(bootstrap), rustc_intrinsic_const_stable_indirect)]
43564372
#[rustc_intrinsic]
43574373
#[rustc_intrinsic_must_be_overridden]
43584374
pub const fn maxnumf64(_x: f64, _y: f64) -> f64 {
@@ -4393,7 +4409,11 @@ pub const unsafe fn fabsf16(_x: f16) -> f16 {
43934409
/// The stabilized version of this intrinsic is
43944410
/// [`f32::abs`](../../std/primitive.f32.html#method.abs)
43954411
#[rustc_nounwind]
4396-
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_float_methods", issue = "130843"))]
4412+
#[cfg_attr(
4413+
bootstrap,
4414+
rustc_const_stable(feature = "const_float_methods", since = "CURRENT_RUSTC_VERSION")
4415+
)]
4416+
#[cfg_attr(not(bootstrap), rustc_intrinsic_const_stable_indirect)]
43974417
#[rustc_intrinsic]
43984418
#[rustc_intrinsic_must_be_overridden]
43994419
pub const unsafe fn fabsf32(_x: f32) -> f32 {
@@ -4405,7 +4425,11 @@ pub const unsafe fn fabsf32(_x: f32) -> f32 {
44054425
/// The stabilized version of this intrinsic is
44064426
/// [`f64::abs`](../../std/primitive.f64.html#method.abs)
44074427
#[rustc_nounwind]
4408-
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_float_methods", issue = "130843"))]
4428+
#[cfg_attr(
4429+
bootstrap,
4430+
rustc_const_stable(feature = "const_float_methods", since = "CURRENT_RUSTC_VERSION")
4431+
)]
4432+
#[cfg_attr(not(bootstrap), rustc_intrinsic_const_stable_indirect)]
44094433
#[rustc_intrinsic]
44104434
#[rustc_intrinsic_must_be_overridden]
44114435
pub const unsafe fn fabsf64(_x: f64) -> f64 {
@@ -4441,7 +4465,11 @@ pub const unsafe fn copysignf16(_x: f16, _y: f16) -> f16 {
44414465
/// The stabilized version of this intrinsic is
44424466
/// [`f32::copysign`](../../std/primitive.f32.html#method.copysign)
44434467
#[rustc_nounwind]
4444-
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_float_methods", issue = "130843"))]
4468+
#[cfg_attr(
4469+
bootstrap,
4470+
rustc_const_stable(feature = "const_float_methods", since = "CURRENT_RUSTC_VERSION")
4471+
)]
4472+
#[cfg_attr(not(bootstrap), rustc_intrinsic_const_stable_indirect)]
44454473
#[rustc_intrinsic]
44464474
#[rustc_intrinsic_must_be_overridden]
44474475
pub const unsafe fn copysignf32(_x: f32, _y: f32) -> f32 {
@@ -4452,7 +4480,11 @@ pub const unsafe fn copysignf32(_x: f32, _y: f32) -> f32 {
44524480
/// The stabilized version of this intrinsic is
44534481
/// [`f64::copysign`](../../std/primitive.f64.html#method.copysign)
44544482
#[rustc_nounwind]
4455-
#[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_float_methods", issue = "130843"))]
4483+
#[cfg_attr(
4484+
bootstrap,
4485+
rustc_const_stable(feature = "const_float_methods", since = "CURRENT_RUSTC_VERSION")
4486+
)]
4487+
#[cfg_attr(not(bootstrap), rustc_intrinsic_const_stable_indirect)]
44564488
#[rustc_intrinsic]
44574489
#[rustc_intrinsic_must_be_overridden]
44584490
pub const unsafe fn copysignf64(_x: f64, _y: f64) -> f64 {

Diff for: library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
#![feature(const_black_box)]
119119
#![feature(const_eq_ignore_ascii_case)]
120120
#![feature(const_eval_select)]
121-
#![feature(const_float_methods)]
122121
#![feature(const_heap)]
123122
#![feature(const_nonnull_new)]
124123
#![feature(const_ptr_sub_ptr)]

Diff for: library/core/src/num/f128.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl f128 {
334334
#[inline]
335335
#[must_use]
336336
#[unstable(feature = "f128", issue = "116909")]
337-
#[rustc_allow_const_fn_unstable(const_float_methods)] // for `abs`
337+
#[rustc_const_unstable(feature = "f128", issue = "116909")]
338338
pub const fn is_finite(self) -> bool {
339339
// There's no need to handle NaN separately: if self is NaN,
340340
// the comparison is not true, exactly as desired.
@@ -612,7 +612,6 @@ impl f128 {
612612
/// ```
613613
#[inline]
614614
#[unstable(feature = "f128", issue = "116909")]
615-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
616615
#[must_use = "this returns the result of the operation, without modifying the original"]
617616
pub const fn recip(self) -> Self {
618617
1.0 / self
@@ -633,7 +632,6 @@ impl f128 {
633632
/// ```
634633
#[inline]
635634
#[unstable(feature = "f128", issue = "116909")]
636-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
637635
#[must_use = "this returns the result of the operation, without modifying the original"]
638636
pub const fn to_degrees(self) -> Self {
639637
// Use a literal for better precision.
@@ -657,7 +655,6 @@ impl f128 {
657655
/// ```
658656
#[inline]
659657
#[unstable(feature = "f128", issue = "116909")]
660-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
661658
#[must_use = "this returns the result of the operation, without modifying the original"]
662659
pub const fn to_radians(self) -> f128 {
663660
// Use a literal for better precision.
@@ -686,7 +683,7 @@ impl f128 {
686683
/// ```
687684
#[inline]
688685
#[unstable(feature = "f128", issue = "116909")]
689-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
686+
#[rustc_const_unstable(feature = "f128", issue = "116909")]
690687
#[must_use = "this returns the result of the comparison, without modifying either input"]
691688
pub const fn max(self, other: f128) -> f128 {
692689
intrinsics::maxnumf128(self, other)
@@ -712,7 +709,7 @@ impl f128 {
712709
/// ```
713710
#[inline]
714711
#[unstable(feature = "f128", issue = "116909")]
715-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
712+
#[rustc_const_unstable(feature = "f128", issue = "116909")]
716713
#[must_use = "this returns the result of the comparison, without modifying either input"]
717714
pub const fn min(self, other: f128) -> f128 {
718715
intrinsics::minnumf128(self, other)
@@ -1251,7 +1248,6 @@ impl f128 {
12511248
/// ```
12521249
#[inline]
12531250
#[unstable(feature = "f128", issue = "116909")]
1254-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
12551251
#[must_use = "method returns a new number and does not mutate the original value"]
12561252
pub const fn clamp(mut self, min: f128, max: f128) -> f128 {
12571253
const_assert!(
@@ -1292,7 +1288,7 @@ impl f128 {
12921288
/// ```
12931289
#[inline]
12941290
#[unstable(feature = "f128", issue = "116909")]
1295-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
1291+
#[rustc_const_unstable(feature = "f128", issue = "116909")]
12961292
#[must_use = "method returns a new number and does not mutate the original value"]
12971293
pub const fn abs(self) -> Self {
12981294
// FIXME(f16_f128): replace with `intrinsics::fabsf128` when available
@@ -1322,7 +1318,7 @@ impl f128 {
13221318
/// ```
13231319
#[inline]
13241320
#[unstable(feature = "f128", issue = "116909")]
1325-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
1321+
#[rustc_const_unstable(feature = "f128", issue = "116909")]
13261322
#[must_use = "method returns a new number and does not mutate the original value"]
13271323
pub const fn signum(self) -> f128 {
13281324
if self.is_nan() { Self::NAN } else { 1.0_f128.copysign(self) }
@@ -1360,7 +1356,7 @@ impl f128 {
13601356
/// ```
13611357
#[inline]
13621358
#[unstable(feature = "f128", issue = "116909")]
1363-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
1359+
#[rustc_const_unstable(feature = "f128", issue = "116909")]
13641360
#[must_use = "method returns a new number and does not mutate the original value"]
13651361
pub const fn copysign(self, sign: f128) -> f128 {
13661362
// SAFETY: this is actually a safe intrinsic

Diff for: library/core/src/num/f16.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl f16 {
326326
#[inline]
327327
#[must_use]
328328
#[unstable(feature = "f16", issue = "116909")]
329-
#[rustc_allow_const_fn_unstable(const_float_methods)] // for `abs`
329+
#[rustc_const_unstable(feature = "f16", issue = "116909")]
330330
pub const fn is_finite(self) -> bool {
331331
// There's no need to handle NaN separately: if self is NaN,
332332
// the comparison is not true, exactly as desired.
@@ -605,7 +605,6 @@ impl f16 {
605605
/// ```
606606
#[inline]
607607
#[unstable(feature = "f16", issue = "116909")]
608-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
609608
#[must_use = "this returns the result of the operation, without modifying the original"]
610609
pub const fn recip(self) -> Self {
611610
1.0 / self
@@ -626,7 +625,6 @@ impl f16 {
626625
/// ```
627626
#[inline]
628627
#[unstable(feature = "f16", issue = "116909")]
629-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
630628
#[must_use = "this returns the result of the operation, without modifying the original"]
631629
pub const fn to_degrees(self) -> Self {
632630
// Use a literal for better precision.
@@ -650,7 +648,6 @@ impl f16 {
650648
/// ```
651649
#[inline]
652650
#[unstable(feature = "f16", issue = "116909")]
653-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
654651
#[must_use = "this returns the result of the operation, without modifying the original"]
655652
pub const fn to_radians(self) -> f16 {
656653
// Use a literal for better precision.
@@ -677,7 +674,7 @@ impl f16 {
677674
/// ```
678675
#[inline]
679676
#[unstable(feature = "f16", issue = "116909")]
680-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
677+
#[rustc_const_unstable(feature = "f16", issue = "116909")]
681678
#[must_use = "this returns the result of the comparison, without modifying either input"]
682679
pub const fn max(self, other: f16) -> f16 {
683680
intrinsics::maxnumf16(self, other)
@@ -702,7 +699,7 @@ impl f16 {
702699
/// ```
703700
#[inline]
704701
#[unstable(feature = "f16", issue = "116909")]
705-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
702+
#[rustc_const_unstable(feature = "f16", issue = "116909")]
706703
#[must_use = "this returns the result of the comparison, without modifying either input"]
707704
pub const fn min(self, other: f16) -> f16 {
708705
intrinsics::minnumf16(self, other)
@@ -1228,7 +1225,6 @@ impl f16 {
12281225
/// ```
12291226
#[inline]
12301227
#[unstable(feature = "f16", issue = "116909")]
1231-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
12321228
#[must_use = "method returns a new number and does not mutate the original value"]
12331229
pub const fn clamp(mut self, min: f16, max: f16) -> f16 {
12341230
const_assert!(
@@ -1269,7 +1265,7 @@ impl f16 {
12691265
/// ```
12701266
#[inline]
12711267
#[unstable(feature = "f16", issue = "116909")]
1272-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
1268+
#[rustc_const_unstable(feature = "f16", issue = "116909")]
12731269
#[must_use = "method returns a new number and does not mutate the original value"]
12741270
pub const fn abs(self) -> Self {
12751271
// FIXME(f16_f128): replace with `intrinsics::fabsf16` when available
@@ -1298,7 +1294,7 @@ impl f16 {
12981294
/// ```
12991295
#[inline]
13001296
#[unstable(feature = "f16", issue = "116909")]
1301-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
1297+
#[rustc_const_unstable(feature = "f16", issue = "116909")]
13021298
#[must_use = "method returns a new number and does not mutate the original value"]
13031299
pub const fn signum(self) -> f16 {
13041300
if self.is_nan() { Self::NAN } else { 1.0_f16.copysign(self) }
@@ -1336,7 +1332,7 @@ impl f16 {
13361332
/// ```
13371333
#[inline]
13381334
#[unstable(feature = "f16", issue = "116909")]
1339-
#[rustc_const_unstable(feature = "const_float_methods", issue = "130843")]
1335+
#[rustc_const_unstable(feature = "f16", issue = "116909")]
13401336
#[must_use = "method returns a new number and does not mutate the original value"]
13411337
pub const fn copysign(self, sign: f16) -> f16 {
13421338
// SAFETY: this is actually a safe intrinsic

0 commit comments

Comments
 (0)