Skip to content

Commit 9abfcb4

Browse files
committed
Auto merge of rust-lang#132053 - matthiaskrgr:rollup-u5ds6i3, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#131707 (Run most `core::num` tests in const context too) - rust-lang#132002 (abi/compatibility: also test Option-like types) - rust-lang#132026 (analyse: remove unused uncanonicalized field) - rust-lang#132031 (Optimize `Rc<T>::default`) - rust-lang#132040 (relnotes: fix stabilizations of `assume_init`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e1f3068 + b44a0fa commit 9abfcb4

File tree

13 files changed

+605
-562
lines changed

13 files changed

+605
-562
lines changed

RELEASES.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ Stabilized APIs
6868
- [`impl Default for std::collections::vec_deque::Iter`](https://doc.rust-lang.org/nightly/std/collections/vec_deque/struct.Iter.html#impl-Default-for-Iter%3C'_,+T%3E)
6969
- [`impl Default for std::collections::vec_deque::IterMut`](https://doc.rust-lang.org/nightly/std/collections/vec_deque/struct.IterMut.html#impl-Default-for-IterMut%3C'_,+T%3E)
7070
- [`Rc<T>::new_uninit`](https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.new_uninit)
71-
- [`Rc<T>::assume_init`](https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.assume_init)
71+
- [`Rc<MaybeUninit<T>>::assume_init`](https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.assume_init)
7272
- [`Rc<[T]>::new_uninit_slice`](https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.new_uninit_slice)
7373
- [`Rc<[MaybeUninit<T>]>::assume_init`](https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.assume_init-1)
7474
- [`Arc<T>::new_uninit`](https://doc.rust-lang.org/nightly/std/sync/struct.Arc.html#method.new_uninit)
75-
- [`Arc<T>::assume_init`](https://doc.rust-lang.org/nightly/std/sync/struct.Arc.html#method.assume_init)
75+
- [`Arc<MaybeUninit<T>>::assume_init`](https://doc.rust-lang.org/nightly/std/sync/struct.Arc.html#method.assume_init)
7676
- [`Arc<[T]>::new_uninit_slice`](https://doc.rust-lang.org/nightly/std/sync/struct.Arc.html#method.new_uninit_slice)
7777
- [`Arc<[MaybeUninit<T>]>::assume_init`](https://doc.rust-lang.org/nightly/std/sync/struct.Arc.html#method.assume_init-1)
7878
- [`Box<T>::new_uninit`](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.new_uninit)
79-
- [`Box<T>::assume_init`](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.assume_init)
79+
- [`Box<MaybeUninit<T>>::assume_init`](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.assume_init)
8080
- [`Box<[T]>::new_uninit_slice`](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.new_uninit_slice)
8181
- [`Box<[MaybeUninit<T>]>::assume_init`](https://doc.rust-lang.org/nightly/std/boxed/struct.Box.html#method.assume_init-1)
8282
- [`core::arch::x86_64::_bextri_u64`](https://doc.rust-lang.org/stable/core/arch/x86_64/fn._bextri_u64.html)

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ where
170170
//
171171
// We don't do so for `NormalizesTo` goals as we erased the expected term and
172172
// bailing with overflow here would prevent us from detecting a type-mismatch,
173-
// causing a coherence error in diesel, see #131969. We still bail with verflow
173+
// causing a coherence error in diesel, see #131969. We still bail with overflow
174174
// when later returning from the parent AliasRelate goal.
175175
if !self.is_normalizes_to_goal {
176176
let num_non_region_vars =

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ where
291291
search_graph,
292292
nested_goals: NestedGoals::new(),
293293
tainted: Ok(()),
294-
inspect: canonical_goal_evaluation.new_goal_evaluation_step(var_values, input),
294+
inspect: canonical_goal_evaluation.new_goal_evaluation_step(var_values),
295295
};
296296

297297
for &(key, ty) in &input.predefined_opaques_in_body.opaque_types {

compiler/rustc_next_trait_solver/src/solve/inspect/build.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_type_ir::{self as ty, Interner};
1313
use crate::delegate::SolverDelegate;
1414
use crate::solve::eval_ctxt::canonical;
1515
use crate::solve::{
16-
CanonicalInput, Certainty, GenerateProofTree, Goal, GoalEvaluationKind, GoalSource, QueryInput,
16+
CanonicalInput, Certainty, GenerateProofTree, Goal, GoalEvaluationKind, GoalSource,
1717
QueryResult, inspect,
1818
};
1919

@@ -119,6 +119,9 @@ impl<I: Interner> WipCanonicalGoalEvaluation<I> {
119119
}
120120
}
121121

122+
/// This only exists during proof tree building and does not have
123+
/// a corresponding struct in `inspect`. We need this to track a
124+
/// bunch of metadata about the current evaluation.
122125
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
123126
struct WipCanonicalGoalEvaluationStep<I: Interner> {
124127
/// Unlike `EvalCtxt::var_values`, we append a new
@@ -128,7 +131,6 @@ struct WipCanonicalGoalEvaluationStep<I: Interner> {
128131
/// This is necessary as we otherwise don't unify these
129132
/// vars when instantiating multiple `CanonicalState`.
130133
var_values: Vec<I::GenericArg>,
131-
instantiated_goal: QueryInput<I, I::Predicate>,
132134
probe_depth: usize,
133135
evaluation: WipProbe<I>,
134136
}
@@ -145,16 +147,12 @@ impl<I: Interner> WipCanonicalGoalEvaluationStep<I> {
145147
current
146148
}
147149

148-
fn finalize(self) -> inspect::CanonicalGoalEvaluationStep<I> {
150+
fn finalize(self) -> inspect::Probe<I> {
149151
let evaluation = self.evaluation.finalize();
150152
match evaluation.kind {
151-
inspect::ProbeKind::Root { .. } => (),
153+
inspect::ProbeKind::Root { .. } => evaluation,
152154
_ => unreachable!("unexpected root evaluation: {evaluation:?}"),
153155
}
154-
inspect::CanonicalGoalEvaluationStep {
155-
instantiated_goal: self.instantiated_goal,
156-
evaluation,
157-
}
158156
}
159157
}
160158

@@ -328,11 +326,9 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
328326
pub(crate) fn new_goal_evaluation_step(
329327
&mut self,
330328
var_values: ty::CanonicalVarValues<I>,
331-
instantiated_goal: QueryInput<I, I::Predicate>,
332329
) -> ProofTreeBuilder<D> {
333330
self.nested(|| WipCanonicalGoalEvaluationStep {
334331
var_values: var_values.var_values.to_vec(),
335-
instantiated_goal,
336332
evaluation: WipProbe {
337333
initial_num_var_values: var_values.len(),
338334
steps: vec![],

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
344344
};
345345

346346
let mut nested_goals = vec![];
347-
self.candidates_recur(&mut candidates, &mut nested_goals, &last_eval_step.evaluation);
347+
self.candidates_recur(&mut candidates, &mut nested_goals, &last_eval_step);
348348

349349
candidates
350350
}

compiler/rustc_type_ir/src/solve/inspect.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ use std::hash::Hash;
2323
use derive_where::derive_where;
2424
use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic};
2525

26-
use crate::solve::{
27-
CandidateSource, CanonicalInput, Certainty, Goal, GoalSource, QueryInput, QueryResult,
28-
};
26+
use crate::solve::{CandidateSource, CanonicalInput, Certainty, Goal, GoalSource, QueryResult};
2927
use crate::{Canonical, CanonicalVarValues, Interner};
3028

3129
/// Some `data` together with information about how they relate to the input
@@ -69,15 +67,10 @@ pub struct CanonicalGoalEvaluation<I: Interner> {
6967
#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)]
7068
pub enum CanonicalGoalEvaluationKind<I: Interner> {
7169
Overflow,
72-
Evaluation { final_revision: CanonicalGoalEvaluationStep<I> },
73-
}
74-
75-
#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)]
76-
pub struct CanonicalGoalEvaluationStep<I: Interner> {
77-
pub instantiated_goal: QueryInput<I, I::Predicate>,
78-
79-
/// The actual evaluation of the goal, always `ProbeKind::Root`.
80-
pub evaluation: Probe<I>,
70+
Evaluation {
71+
/// This is always `ProbeKind::Root`.
72+
final_revision: Probe<I>,
73+
},
8174
}
8275

8376
/// A self-contained computation during trait solving. This either

library/alloc/src/rc.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,16 @@ impl<T: Default> Default for Rc<T> {
23122312
/// ```
23132313
#[inline]
23142314
fn default() -> Rc<T> {
2315-
Rc::new(Default::default())
2315+
unsafe {
2316+
Self::from_inner(
2317+
Box::leak(Box::write(Box::new_uninit(), RcInner {
2318+
strong: Cell::new(1),
2319+
weak: Cell::new(1),
2320+
value: T::default(),
2321+
}))
2322+
.into(),
2323+
)
2324+
}
23162325
}
23172326
}
23182327

library/alloc/src/sync.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -3447,13 +3447,16 @@ impl<T: Default> Default for Arc<T> {
34473447
/// assert_eq!(*x, 0);
34483448
/// ```
34493449
fn default() -> Arc<T> {
3450-
let x = Box::into_raw(Box::write(Box::new_uninit(), ArcInner {
3451-
strong: atomic::AtomicUsize::new(1),
3452-
weak: atomic::AtomicUsize::new(1),
3453-
data: T::default(),
3454-
}));
3455-
// SAFETY: `Box::into_raw` consumes the `Box` and never returns null
3456-
unsafe { Self::from_inner(NonNull::new_unchecked(x)) }
3450+
unsafe {
3451+
Self::from_inner(
3452+
Box::leak(Box::write(Box::new_uninit(), ArcInner {
3453+
strong: atomic::AtomicUsize::new(1),
3454+
weak: atomic::AtomicUsize::new(1),
3455+
data: T::default(),
3456+
}))
3457+
.into(),
3458+
)
3459+
}
34573460
}
34583461
}
34593462

library/core/tests/lib.rs

+35
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
#![feature(clone_to_uninit)]
1818
#![feature(const_align_of_val_raw)]
1919
#![feature(const_align_offset)]
20+
#![feature(const_bigint_helper_methods)]
2021
#![feature(const_black_box)]
22+
#![feature(const_eval_select)]
2123
#![feature(const_hash)]
2224
#![feature(const_heap)]
2325
#![feature(const_likely)]
2426
#![feature(const_nonnull_new)]
27+
#![feature(const_num_midpoint)]
2528
#![feature(const_option_ext)]
2629
#![feature(const_pin_2)]
2730
#![feature(const_pointer_is_aligned)]
@@ -46,6 +49,7 @@
4649
#![feature(get_many_mut)]
4750
#![feature(hasher_prefixfree_extras)]
4851
#![feature(hashmap_internals)]
52+
#![feature(inline_const_pat)]
4953
#![feature(int_roundings)]
5054
#![feature(ip)]
5155
#![feature(ip_from)]
@@ -104,6 +108,37 @@
104108
#![deny(fuzzy_provenance_casts)]
105109
#![deny(unsafe_op_in_unsafe_fn)]
106110

111+
/// Version of `assert_matches` that ignores fancy runtime printing in const context and uses structural equality.
112+
macro_rules! assert_eq_const_safe {
113+
($left:expr, $right:expr$(, $($arg:tt)+)?) => {
114+
{
115+
fn runtime() {
116+
assert_eq!($left, $right, $($arg)*);
117+
}
118+
const fn compiletime() {
119+
assert!(matches!($left, const { $right }));
120+
}
121+
core::intrinsics::const_eval_select((), compiletime, runtime)
122+
}
123+
};
124+
}
125+
126+
/// Creates a test for runtime and a test for constant-time.
127+
macro_rules! test_runtime_and_compiletime {
128+
($(
129+
$(#[$attr:meta])*
130+
fn $test:ident() $block:block
131+
)*) => {
132+
$(
133+
$(#[$attr])*
134+
#[test]
135+
fn $test() $block
136+
$(#[$attr])*
137+
const _: () = $block;
138+
)*
139+
}
140+
}
141+
107142
mod alloc;
108143
mod any;
109144
mod array;

0 commit comments

Comments
 (0)