Skip to content

Commit

Permalink
Unrolled build for rust-lang#126552
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#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 rust-lang#120639 lands.

Also, make `effects` an incomplete feature.

cc `@rust-lang/project-const-traits`
r? `@compiler-errors`
  • Loading branch information
rust-timer authored Jun 22, 2024
2 parents f944afe + 81da6a6 commit 7ba756a
Show file tree
Hide file tree
Showing 160 changed files with 1,858 additions and 310 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ declare_features! (
/// Allows `dyn* Trait` objects.
(incomplete, dyn_star, "1.65.0", Some(102425)),
/// Uses generic effect parameters for ~const bounds
(unstable, effects, "1.72.0", Some(102090)),
(incomplete, effects, "1.72.0", Some(102090)),
/// Allows exhaustive pattern matching on types that contain uninhabited types.
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
/// Allows explicit tail calls via `become` expression.
Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,17 +429,17 @@ pub fn check_intrinsic_type(

sym::ptr_guaranteed_cmp => (
1,
1,
0,
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
tcx.types.u8,
),

sym::const_allocate => {
(0, 1, vec![tcx.types.usize, tcx.types.usize], Ty::new_mut_ptr(tcx, tcx.types.u8))
(0, 0, vec![tcx.types.usize, tcx.types.usize], Ty::new_mut_ptr(tcx, tcx.types.u8))
}
sym::const_deallocate => (
0,
1,
0,
vec![Ty::new_mut_ptr(tcx, tcx.types.u8), tcx.types.usize, tcx.types.usize],
tcx.types.unit,
),
Expand Down Expand Up @@ -478,16 +478,16 @@ pub fn check_intrinsic_type(
| sym::frem_algebraic => (1, 0, vec![param(0), param(0)], param(0)),
sym::float_to_int_unchecked => (2, 0, vec![param(0)], param(1)),

sym::assume => (0, 1, vec![tcx.types.bool], tcx.types.unit),
sym::likely => (0, 1, vec![tcx.types.bool], tcx.types.bool),
sym::unlikely => (0, 1, vec![tcx.types.bool], tcx.types.bool),
sym::assume => (0, 0, vec![tcx.types.bool], tcx.types.unit),
sym::likely => (0, 0, vec![tcx.types.bool], tcx.types.bool),
sym::unlikely => (0, 0, vec![tcx.types.bool], tcx.types.bool),

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

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

sym::discriminant_value => {
let assoc_items = tcx.associated_item_def_ids(
Expand Down Expand Up @@ -566,20 +566,20 @@ pub fn check_intrinsic_type(

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

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

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

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

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

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

sym::simd_eq
| sym::simd_ne
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@
#![feature(const_mut_refs)]
#![feature(const_precise_live_drops)]
#![feature(const_ptr_write)]
#![feature(const_trait_impl)]
#![feature(const_try)]
#![feature(decl_macro)]
#![feature(dropck_eyepatch)]
Expand Down
4 changes: 1 addition & 3 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ use self::Ordering::*;
append_const_msg
)]
#[rustc_diagnostic_item = "PartialEq"]
#[const_trait]
pub trait PartialEq<Rhs: ?Sized = Self> {
/// This method tests for `self` and `other` values to be equal, and is used
/// by `==`.
Expand Down Expand Up @@ -1475,8 +1474,7 @@ mod impls {
macro_rules! partial_eq_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
impl const PartialEq for $t {
impl PartialEq for $t {
#[inline]
fn eq(&self, other: &$t) -> bool { (*self) == (*other) }
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const fn escape_ascii<const N: usize>(byte: u8) -> ([ascii::Char; N], Range<u8>)
const fn escape_unicode<const N: usize>(c: char) -> ([ascii::Char; N], Range<u8>) {
const { assert!(N >= 10 && N < u8::MAX as usize) };

let c = u32::from(c);
let c = c as u32;

// OR-ing `1` ensures that for `c == 0` the code computes that
// one digit should be printed.
Expand Down
5 changes: 4 additions & 1 deletion library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,10 @@ impl CStr {
#[inline]
#[must_use]
const fn as_non_null_ptr(&self) -> NonNull<c_char> {
NonNull::from(&self.inner).as_non_null_ptr()
// FIXME(effects) replace with `NonNull::from`
// SAFETY: a reference is never null
unsafe { NonNull::new_unchecked(&self.inner as *const [c_char] as *mut [c_char]) }
.as_non_null_ptr()
}

/// Returns the length of `self`. Like C's `strlen`, this does not include the nul terminator.
Expand Down
3 changes: 1 addition & 2 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
// Language features:
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(c_unwind))]
#![cfg_attr(bootstrap, feature(effects))]
#![feature(abi_unadjusted)]
#![feature(adt_const_params)]
#![feature(allow_internal_unsafe)]
Expand All @@ -214,13 +215,11 @@
#![feature(const_mut_refs)]
#![feature(const_precise_live_drops)]
#![feature(const_refs_to_cell)]
#![feature(const_trait_impl)]
#![feature(decl_macro)]
#![feature(deprecated_suggestion)]
#![feature(doc_cfg)]
#![feature(doc_cfg_hide)]
#![feature(doc_notable_trait)]
#![feature(effects)]
#![feature(extern_types)]
#![feature(f128)]
#![feature(f16)]
Expand Down
1 change: 0 additions & 1 deletion library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,6 @@ marker_impls! {
#[lang = "destruct"]
#[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)]
#[rustc_deny_explicit_impl(implement_via_object = false)]
#[const_trait]
pub trait Destruct {}

/// A marker for tuple types.
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use super::{IntErrorKind, ParseIntError};
reason = "implementation detail which may disappear or be replaced at any time",
issue = "none"
)]
#[const_trait]
pub unsafe trait ZeroablePrimitive: Sized + Copy + private::Sealed {
#[doc(hidden)]
type NonZeroInner: Sized + Copy;
Expand All @@ -47,7 +46,6 @@ macro_rules! impl_zeroable_primitive {
reason = "implementation detail which may disappear or be replaced at any time",
issue = "none"
)]
#[const_trait]
pub trait Sealed {}

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

#[unstable(
feature = "nonzero_internals",
reason = "implementation detail which may disappear or be replaced at any time",
issue = "none"
)]
unsafe impl const ZeroablePrimitive for $primitive {
unsafe impl ZeroablePrimitive for $primitive {
type NonZeroInner = private::$NonZeroInner;
}
)+
Expand Down
4 changes: 1 addition & 3 deletions library/core/src/ops/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
append_const_msg
)]
#[doc(alias = "+")]
#[const_trait]
pub trait Add<Rhs = Self> {
/// The resulting type after applying the `+` operator.
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -95,8 +94,7 @@ pub trait Add<Rhs = Self> {
macro_rules! add_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Add for $t {
impl Add for $t {
type Output = $t;

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl<'a> Context<'a> {
pub const fn ext(&mut self) -> &mut dyn Any {
// FIXME: this field makes Context extra-weird about unwind safety
// can we justify AssertUnwindSafe if we stabilize this? do we care?
match &mut *self.ext {
match &mut self.ext.0 {
ExtData::Some(data) => *data,
ExtData::None(unit) => unit,
}
Expand Down Expand Up @@ -356,7 +356,7 @@ impl<'a> ContextBuilder<'a> {
#[rustc_const_unstable(feature = "const_waker", issue = "102012")]
#[unstable(feature = "context_ext", issue = "123392")]
pub const fn from(cx: &'a mut Context<'_>) -> Self {
let ext = match &mut *cx.ext {
let ext = match &mut cx.ext.0 {
ExtData::Some(ext) => ExtData::Some(*ext),
ExtData::None(()) => ExtData::None(()),
};
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@
#![feature(cfi_encoding)]
#![feature(concat_idents)]
#![feature(const_mut_refs)]
#![feature(const_trait_impl)]
#![feature(decl_macro)]
#![feature(deprecated_suggestion)]
#![feature(doc_cfg)]
Expand Down
4 changes: 2 additions & 2 deletions src/doc/unstable-book/src/language-features/intrinsics.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ All intrinsic fallback bodies are automatically made cross-crate inlineable (lik
by the codegen backend, but not the MIR inliner.

```rust
#![feature(rustc_attrs, effects)]
#![feature(rustc_attrs)]
#![allow(internal_features)]

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

```rust
#![feature(rustc_attrs, effects)]
#![feature(rustc_attrs)]
#![allow(internal_features)]

#[rustc_intrinsic]
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/tests/fail/intrinsic_fallback_is_spec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(rustc_attrs, effects)]
#![feature(rustc_attrs)]

#[rustc_intrinsic]
#[rustc_nounwind]
Expand Down
10 changes: 0 additions & 10 deletions tests/crashes/120503.rs

This file was deleted.

20 changes: 0 additions & 20 deletions tests/crashes/121536.rs

This file was deleted.

1 change: 1 addition & 0 deletions tests/rustdoc/const-effect-param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#![crate_name = "foo"]
#![feature(effects, const_trait_impl)]
#![allow(incomplete_features)]

#[const_trait]
pub trait Tr {
Expand Down
1 change: 1 addition & 0 deletions tests/rustdoc/const-fn-effects.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![crate_name = "foo"]
#![feature(effects)]
#![allow(incomplete_features)]

// @has foo/fn.bar.html
// @has - '//pre[@class="rust item-decl"]' 'pub const fn bar() -> '
Expand Down
21 changes: 11 additions & 10 deletions tests/rustdoc/rfc-2632-const-trait-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// not remove this test.
//
// FIXME(effects) add `const_trait` to `Fn` so we use `~const`
// FIXME(effects) restore `const_trait` to `Destruct`
#![feature(const_trait_impl)]
#![crate_name = "foo"]

Expand All @@ -24,9 +25,9 @@ pub trait Tr<T> {
// @has - '//section[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Fn'
// @!has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const'
// @has - '//section[@id="method.a"]/h4[@class="code-header"]/div[@class="where"]' ': Fn'
fn a<A: /* ~const */ Fn() + ~const Destruct>()
fn a<A: /* ~const */ Fn() /* + ~const Destruct */>()
where
Option<A>: /* ~const */ Fn() + ~const Destruct,
Option<A>: /* ~const */ Fn() /* + ~const Destruct */,
{
}
}
Expand All @@ -36,13 +37,13 @@ pub trait Tr<T> {
// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/a[@class="trait"]' 'Fn'
// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where"]' '~const'
// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/div[@class="where"]' ': Fn'
impl<T: /* ~const */ Fn() + ~const Destruct> const Tr<T> for T
impl<T: /* ~const */ Fn() /* + ~const Destruct */> const Tr<T> for T
where
Option<T>: /* ~const */ Fn() + ~const Destruct,
Option<T>: /* ~const */ Fn() /* + ~const Destruct */,
{
fn a<A: /* ~const */ Fn() + ~const Destruct>()
fn a<A: /* ~const */ Fn() /* + ~const Destruct */>()
where
Option<A>: /* ~const */ Fn() + ~const Destruct,
Option<A>: /* ~const */ Fn() /* + ~const Destruct */,
{
}
}
Expand All @@ -51,9 +52,9 @@ where
// @has - '//pre[@class="rust item-decl"]/code/a[@class="trait"]' 'Fn'
// @!has - '//pre[@class="rust item-decl"]/code/div[@class="where"]' '~const'
// @has - '//pre[@class="rust item-decl"]/code/div[@class="where"]' ': Fn'
pub const fn foo<F: /* ~const */ Fn() + ~const Destruct>()
pub const fn foo<F: /* ~const */ Fn() /* + ~const Destruct */>()
where
Option<F>: /* ~const */ Fn() + ~const Destruct,
Option<F>: /* ~const */ Fn() /* + ~const Destruct */,
{
F::a()
}
Expand All @@ -63,9 +64,9 @@ impl<T> S<T> {
// @has - '//section[@id="method.foo"]/h4[@class="code-header"]/a[@class="trait"]' 'Fn'
// @!has - '//section[@id="method.foo"]/h4[@class="code-header"]/span[@class="where"]' '~const'
// @has - '//section[@id="method.foo"]/h4[@class="code-header"]/div[@class="where"]' ': Fn'
pub const fn foo<B, C: /* ~const */ Fn() + ~const Destruct>()
pub const fn foo<B, C: /* ~const */ Fn() /* + ~const Destruct */>()
where
B: /* ~const */ Fn() + ~const Destruct,
B: /* ~const */ Fn() /* + ~const Destruct */,
{
B::a()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/const_trait_fn-issue-88433.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ build-pass

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

#[const_trait]
trait Func<T> {
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/const-generics/const_trait_fn-issue-88433.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/const_trait_fn-issue-88433.rs:3:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion tests/ui/consts/auxiliary/closure-in-foreign-crate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![crate_type = "lib"]
#![feature(const_closures, const_trait_impl, effects)]
#![feature(const_closures, const_trait_impl, effects)] //~ WARN the feature `effects` is incomplete

pub const fn test() {
let cl = const || {};
Expand Down
Loading

0 comments on commit 7ba756a

Please sign in to comment.