Skip to content

Commit dc9a08f

Browse files
authored
Rollup merge of #126552 - fee1-dead-contrib:rmfx, r=compiler-errors
Remove use of const traits (and `feature(effects)`) from stdlib The current uses are already unsound because they are using non-const impls in const contexts. We can reintroduce them by reverting the commit in this PR, after #120639 lands. Also, make `effects` an incomplete feature. cc `@rust-lang/project-const-traits` r? `@compiler-errors`
2 parents 162120b + 81da6a6 commit dc9a08f

File tree

160 files changed

+1858
-310
lines changed

Some content is hidden

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

160 files changed

+1858
-310
lines changed

compiler/rustc_feature/src/unstable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ declare_features! (
449449
/// Allows `dyn* Trait` objects.
450450
(incomplete, dyn_star, "1.65.0", Some(102425)),
451451
/// Uses generic effect parameters for ~const bounds
452-
(unstable, effects, "1.72.0", Some(102090)),
452+
(incomplete, effects, "1.72.0", Some(102090)),
453453
/// Allows exhaustive pattern matching on types that contain uninhabited types.
454454
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
455455
/// Allows explicit tail calls via `become` expression.

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -429,17 +429,17 @@ pub fn check_intrinsic_type(
429429

430430
sym::ptr_guaranteed_cmp => (
431431
1,
432-
1,
432+
0,
433433
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
434434
tcx.types.u8,
435435
),
436436

437437
sym::const_allocate => {
438-
(0, 1, vec![tcx.types.usize, tcx.types.usize], Ty::new_mut_ptr(tcx, tcx.types.u8))
438+
(0, 0, vec![tcx.types.usize, tcx.types.usize], Ty::new_mut_ptr(tcx, tcx.types.u8))
439439
}
440440
sym::const_deallocate => (
441441
0,
442-
1,
442+
0,
443443
vec![Ty::new_mut_ptr(tcx, tcx.types.u8), tcx.types.usize, tcx.types.usize],
444444
tcx.types.unit,
445445
),
@@ -478,16 +478,16 @@ pub fn check_intrinsic_type(
478478
| sym::frem_algebraic => (1, 0, vec![param(0), param(0)], param(0)),
479479
sym::float_to_int_unchecked => (2, 0, vec![param(0)], param(1)),
480480

481-
sym::assume => (0, 1, vec![tcx.types.bool], tcx.types.unit),
482-
sym::likely => (0, 1, vec![tcx.types.bool], tcx.types.bool),
483-
sym::unlikely => (0, 1, vec![tcx.types.bool], tcx.types.bool),
481+
sym::assume => (0, 0, vec![tcx.types.bool], tcx.types.unit),
482+
sym::likely => (0, 0, vec![tcx.types.bool], tcx.types.bool),
483+
sym::unlikely => (0, 0, vec![tcx.types.bool], tcx.types.bool),
484484

485485
sym::read_via_copy => (1, 0, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
486486
sym::write_via_move => {
487487
(1, 0, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], tcx.types.unit)
488488
}
489489

490-
sym::typed_swap => (1, 1, vec![Ty::new_mut_ptr(tcx, param(0)); 2], tcx.types.unit),
490+
sym::typed_swap => (1, 0, vec![Ty::new_mut_ptr(tcx, param(0)); 2], tcx.types.unit),
491491

492492
sym::discriminant_value => {
493493
let assoc_items = tcx.associated_item_def_ids(
@@ -566,20 +566,20 @@ pub fn check_intrinsic_type(
566566

567567
sym::black_box => (1, 0, vec![param(0)], param(0)),
568568

569-
sym::is_val_statically_known => (1, 1, vec![param(0)], tcx.types.bool),
569+
sym::is_val_statically_known => (1, 0, vec![param(0)], tcx.types.bool),
570570

571-
sym::const_eval_select => (4, 1, vec![param(0), param(1), param(2)], param(3)),
571+
sym::const_eval_select => (4, 0, vec![param(0), param(1), param(2)], param(3)),
572572

573573
sym::vtable_size | sym::vtable_align => {
574574
(0, 0, vec![Ty::new_imm_ptr(tcx, tcx.types.unit)], tcx.types.usize)
575575
}
576576

577577
// This type check is not particularly useful, but the `where` bounds
578578
// on the definition in `core` do the heavy lifting for checking it.
579-
sym::aggregate_raw_ptr => (3, 1, vec![param(1), param(2)], param(0)),
580-
sym::ptr_metadata => (2, 1, vec![Ty::new_imm_ptr(tcx, param(0))], param(1)),
579+
sym::aggregate_raw_ptr => (3, 0, vec![param(1), param(2)], param(0)),
580+
sym::ptr_metadata => (2, 0, vec![Ty::new_imm_ptr(tcx, param(0))], param(1)),
581581

582-
sym::ub_checks => (0, 1, Vec::new(), tcx.types.bool),
582+
sym::ub_checks => (0, 0, Vec::new(), tcx.types.bool),
583583

584584
sym::simd_eq
585585
| sym::simd_ne

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@
175175
#![feature(const_mut_refs)]
176176
#![feature(const_precise_live_drops)]
177177
#![feature(const_ptr_write)]
178-
#![feature(const_trait_impl)]
179178
#![feature(const_try)]
180179
#![feature(decl_macro)]
181180
#![feature(dropck_eyepatch)]

library/core/src/cmp.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ use self::Ordering::*;
245245
append_const_msg
246246
)]
247247
#[rustc_diagnostic_item = "PartialEq"]
248-
#[const_trait]
249248
pub trait PartialEq<Rhs: ?Sized = Self> {
250249
/// This method tests for `self` and `other` values to be equal, and is used
251250
/// by `==`.
@@ -1475,8 +1474,7 @@ mod impls {
14751474
macro_rules! partial_eq_impl {
14761475
($($t:ty)*) => ($(
14771476
#[stable(feature = "rust1", since = "1.0.0")]
1478-
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
1479-
impl const PartialEq for $t {
1477+
impl PartialEq for $t {
14801478
#[inline]
14811479
fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
14821480
#[inline]

library/core/src/escape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const fn escape_ascii<const N: usize>(byte: u8) -> ([ascii::Char; N], Range<u8>)
6060
const fn escape_unicode<const N: usize>(c: char) -> ([ascii::Char; N], Range<u8>) {
6161
const { assert!(N >= 10 && N < u8::MAX as usize) };
6262

63-
let c = u32::from(c);
63+
let c = c as u32;
6464

6565
// OR-ing `1` ensures that for `c == 0` the code computes that
6666
// one digit should be printed.

library/core/src/ffi/c_str.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,10 @@ impl CStr {
515515
#[inline]
516516
#[must_use]
517517
const fn as_non_null_ptr(&self) -> NonNull<c_char> {
518-
NonNull::from(&self.inner).as_non_null_ptr()
518+
// FIXME(effects) replace with `NonNull::from`
519+
// SAFETY: a reference is never null
520+
unsafe { NonNull::new_unchecked(&self.inner as *const [c_char] as *mut [c_char]) }
521+
.as_non_null_ptr()
519522
}
520523

521524
/// Returns the length of `self`. Like C's `strlen`, this does not include the nul terminator.

library/core/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
// Language features:
201201
// tidy-alphabetical-start
202202
#![cfg_attr(bootstrap, feature(c_unwind))]
203+
#![cfg_attr(bootstrap, feature(effects))]
203204
#![feature(abi_unadjusted)]
204205
#![feature(adt_const_params)]
205206
#![feature(allow_internal_unsafe)]
@@ -214,13 +215,11 @@
214215
#![feature(const_mut_refs)]
215216
#![feature(const_precise_live_drops)]
216217
#![feature(const_refs_to_cell)]
217-
#![feature(const_trait_impl)]
218218
#![feature(decl_macro)]
219219
#![feature(deprecated_suggestion)]
220220
#![feature(doc_cfg)]
221221
#![feature(doc_cfg_hide)]
222222
#![feature(doc_notable_trait)]
223-
#![feature(effects)]
224223
#![feature(extern_types)]
225224
#![feature(f128)]
226225
#![feature(f16)]

library/core/src/marker.rs

-1
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,6 @@ marker_impls! {
944944
#[lang = "destruct"]
945945
#[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)]
946946
#[rustc_deny_explicit_impl(implement_via_object = false)]
947-
#[const_trait]
948947
pub trait Destruct {}
949948

950949
/// A marker for tuple types.

library/core/src/num/nonzero.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use super::{IntErrorKind, ParseIntError};
3333
reason = "implementation detail which may disappear or be replaced at any time",
3434
issue = "none"
3535
)]
36-
#[const_trait]
3736
pub unsafe trait ZeroablePrimitive: Sized + Copy + private::Sealed {
3837
#[doc(hidden)]
3938
type NonZeroInner: Sized + Copy;
@@ -47,7 +46,6 @@ macro_rules! impl_zeroable_primitive {
4746
reason = "implementation detail which may disappear or be replaced at any time",
4847
issue = "none"
4948
)]
50-
#[const_trait]
5149
pub trait Sealed {}
5250

5351
$(
@@ -70,14 +68,14 @@ macro_rules! impl_zeroable_primitive {
7068
reason = "implementation detail which may disappear or be replaced at any time",
7169
issue = "none"
7270
)]
73-
impl const private::Sealed for $primitive {}
71+
impl private::Sealed for $primitive {}
7472

7573
#[unstable(
7674
feature = "nonzero_internals",
7775
reason = "implementation detail which may disappear or be replaced at any time",
7876
issue = "none"
7977
)]
80-
unsafe impl const ZeroablePrimitive for $primitive {
78+
unsafe impl ZeroablePrimitive for $primitive {
8179
type NonZeroInner = private::$NonZeroInner;
8280
}
8381
)+

library/core/src/ops/arith.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
append_const_msg
7474
)]
7575
#[doc(alias = "+")]
76-
#[const_trait]
7776
pub trait Add<Rhs = Self> {
7877
/// The resulting type after applying the `+` operator.
7978
#[stable(feature = "rust1", since = "1.0.0")]
@@ -95,8 +94,7 @@ pub trait Add<Rhs = Self> {
9594
macro_rules! add_impl {
9695
($($t:ty)*) => ($(
9796
#[stable(feature = "rust1", since = "1.0.0")]
98-
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
99-
impl const Add for $t {
97+
impl Add for $t {
10098
type Output = $t;
10199

102100
#[inline]

library/core/src/task/wake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl<'a> Context<'a> {
282282
pub const fn ext(&mut self) -> &mut dyn Any {
283283
// FIXME: this field makes Context extra-weird about unwind safety
284284
// can we justify AssertUnwindSafe if we stabilize this? do we care?
285-
match &mut *self.ext {
285+
match &mut self.ext.0 {
286286
ExtData::Some(data) => *data,
287287
ExtData::None(unit) => unit,
288288
}
@@ -356,7 +356,7 @@ impl<'a> ContextBuilder<'a> {
356356
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
357357
#[unstable(feature = "context_ext", issue = "123392")]
358358
pub const fn from(cx: &'a mut Context<'_>) -> Self {
359-
let ext = match &mut *cx.ext {
359+
let ext = match &mut cx.ext.0 {
360360
ExtData::Some(ext) => ExtData::Some(*ext),
361361
ExtData::None(()) => ExtData::None(()),
362362
};

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@
284284
#![feature(cfi_encoding)]
285285
#![feature(concat_idents)]
286286
#![feature(const_mut_refs)]
287-
#![feature(const_trait_impl)]
288287
#![feature(decl_macro)]
289288
#![feature(deprecated_suggestion)]
290289
#![feature(doc_cfg)]

src/doc/unstable-book/src/language-features/intrinsics.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ All intrinsic fallback bodies are automatically made cross-crate inlineable (lik
1818
by the codegen backend, but not the MIR inliner.
1919

2020
```rust
21-
#![feature(rustc_attrs, effects)]
21+
#![feature(rustc_attrs)]
2222
#![allow(internal_features)]
2323

2424
#[rustc_intrinsic]
@@ -28,7 +28,7 @@ const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
2828
Since these are just regular functions, it is perfectly ok to create the intrinsic twice:
2929

3030
```rust
31-
#![feature(rustc_attrs, effects)]
31+
#![feature(rustc_attrs)]
3232
#![allow(internal_features)]
3333

3434
#[rustc_intrinsic]

src/tools/miri/tests/fail/intrinsic_fallback_is_spec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(rustc_attrs, effects)]
1+
#![feature(rustc_attrs)]
22

33
#[rustc_intrinsic]
44
#[rustc_nounwind]

tests/crashes/120503.rs

-10
This file was deleted.

tests/crashes/121536.rs

-20
This file was deleted.

tests/rustdoc/const-effect-param.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![crate_name = "foo"]
44
#![feature(effects, const_trait_impl)]
5+
#![allow(incomplete_features)]
56

67
#[const_trait]
78
pub trait Tr {

tests/rustdoc/const-fn-effects.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![crate_name = "foo"]
22
#![feature(effects)]
3+
#![allow(incomplete_features)]
34

45
// @has foo/fn.bar.html
56
// @has - '//pre[@class="rust item-decl"]' 'pub const fn bar() -> '

tests/rustdoc/rfc-2632-const-trait-impl.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// not remove this test.
88
//
99
// FIXME(effects) add `const_trait` to `Fn` so we use `~const`
10+
// FIXME(effects) restore `const_trait` to `Destruct`
1011
#![feature(const_trait_impl)]
1112
#![crate_name = "foo"]
1213

@@ -24,9 +25,9 @@ pub trait Tr<T> {
2425
// @has - '//section[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Fn'
2526
// @!has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const'
2627
// @has - '//section[@id="method.a"]/h4[@class="code-header"]/div[@class="where"]' ': Fn'
27-
fn a<A: /* ~const */ Fn() + ~const Destruct>()
28+
fn a<A: /* ~const */ Fn() /* + ~const Destruct */>()
2829
where
29-
Option<A>: /* ~const */ Fn() + ~const Destruct,
30+
Option<A>: /* ~const */ Fn() /* + ~const Destruct */,
3031
{
3132
}
3233
}
@@ -36,13 +37,13 @@ pub trait Tr<T> {
3637
// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/a[@class="trait"]' 'Fn'
3738
// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where"]' '~const'
3839
// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/div[@class="where"]' ': Fn'
39-
impl<T: /* ~const */ Fn() + ~const Destruct> const Tr<T> for T
40+
impl<T: /* ~const */ Fn() /* + ~const Destruct */> const Tr<T> for T
4041
where
41-
Option<T>: /* ~const */ Fn() + ~const Destruct,
42+
Option<T>: /* ~const */ Fn() /* + ~const Destruct */,
4243
{
43-
fn a<A: /* ~const */ Fn() + ~const Destruct>()
44+
fn a<A: /* ~const */ Fn() /* + ~const Destruct */>()
4445
where
45-
Option<A>: /* ~const */ Fn() + ~const Destruct,
46+
Option<A>: /* ~const */ Fn() /* + ~const Destruct */,
4647
{
4748
}
4849
}
@@ -51,9 +52,9 @@ where
5152
// @has - '//pre[@class="rust item-decl"]/code/a[@class="trait"]' 'Fn'
5253
// @!has - '//pre[@class="rust item-decl"]/code/div[@class="where"]' '~const'
5354
// @has - '//pre[@class="rust item-decl"]/code/div[@class="where"]' ': Fn'
54-
pub const fn foo<F: /* ~const */ Fn() + ~const Destruct>()
55+
pub const fn foo<F: /* ~const */ Fn() /* + ~const Destruct */>()
5556
where
56-
Option<F>: /* ~const */ Fn() + ~const Destruct,
57+
Option<F>: /* ~const */ Fn() /* + ~const Destruct */,
5758
{
5859
F::a()
5960
}
@@ -63,9 +64,9 @@ impl<T> S<T> {
6364
// @has - '//section[@id="method.foo"]/h4[@class="code-header"]/a[@class="trait"]' 'Fn'
6465
// @!has - '//section[@id="method.foo"]/h4[@class="code-header"]/span[@class="where"]' '~const'
6566
// @has - '//section[@id="method.foo"]/h4[@class="code-header"]/div[@class="where"]' ': Fn'
66-
pub const fn foo<B, C: /* ~const */ Fn() + ~const Destruct>()
67+
pub const fn foo<B, C: /* ~const */ Fn() /* + ~const Destruct */>()
6768
where
68-
B: /* ~const */ Fn() + ~const Destruct,
69+
B: /* ~const */ Fn() /* + ~const Destruct */,
6970
{
7071
B::a()
7172
}

tests/ui/const-generics/const_trait_fn-issue-88433.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ build-pass
22

3-
#![feature(const_trait_impl, effects)]
3+
#![feature(const_trait_impl, effects)] //~ WARN the feature `effects` is incomplete
44

55
#[const_trait]
66
trait Func<T> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/const_trait_fn-issue-88433.rs:3:30
3+
|
4+
LL | #![feature(const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

tests/ui/consts/auxiliary/closure-in-foreign-crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![crate_type = "lib"]
2-
#![feature(const_closures, const_trait_impl, effects)]
2+
#![feature(const_closures, const_trait_impl, effects)] //~ WARN the feature `effects` is incomplete
33

44
pub const fn test() {
55
let cl = const || {};

0 commit comments

Comments
 (0)