Skip to content

Commit a01b4cc

Browse files
committed
Auto merge of rust-lang#109442 - Nilstrieb:rollup-seb5xsa, r=Nilstrieb
Rollup of 10 pull requests Successful merges: - rust-lang#106434 (Document `Iterator::sum/product` for Option/Result) - rust-lang#108326 (Implement read_buf for a few more types) - rust-lang#108842 (Enforce non-lifetime-binders in supertrait preds are not object safe) - rust-lang#108896 (new solver: make all goal evaluation able to be automatically rerun ) - rust-lang#109124 (Add `dist.compression-profile` option to control compression speed) - rust-lang#109240 (Walk un-shifted nested `impl Trait` in trait when setting up default trait method assumptions) - rust-lang#109385 (fix typo) - rust-lang#109386 (add myself to mailmap) - rust-lang#109390 (Custom MIR: Support aggregate expressions) - rust-lang#109408 (not *all* retags might be explicit in Runtime MIR) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ef03fda + 925fbcd commit a01b4cc

File tree

55 files changed

+1234
-562
lines changed

Some content is hidden

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

55 files changed

+1234
-562
lines changed

.mailmap

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Alexander Ronald Altman <alexanderaltman@me.com>
2929
Alexandre Martin <martin.alex32@hotmail.fr>
3030
Alexis Beingessner <a.beingessner@gmail.com>
3131
Alfie John <alfie@alfie.wtf> Alfie John <alfiej@fastmail.fm>
32+
Alona Enraght-Moony <code@alona.page> <nixon.emoony@gmail.com>
33+
Alona Enraght-Moony <code@alona.page> <nixon@caminus.local>
3234
Amos Onn <amosonn@gmail.com>
3335
Ana-Maria Mihalache <mihalacheana.maria@yahoo.com>
3436
Anatoly Ikorsky <aikorsky@gmail.com>
@@ -415,7 +417,6 @@ Nicolas Abram <abramlujan@gmail.com>
415417
Nicole Mazzuca <npmazzuca@gmail.com>
416418
Nif Ward <nif.ward@gmail.com>
417419
Nika Layzell <nika@thelayzells.com> <michael@thelayzells.com>
418-
Nixon Enraght-Moony <nixon.emoony@gmail.com>
419420
NODA Kai <nodakai@gmail.com>
420421
oliver <16816606+o752d@users.noreply.github.com>
421422
Oliver Middleton <olliemail27@gmail.com> <ollie27@users.noreply.github.com>

compiler/rustc_hir_analysis/src/collect/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
605605
found: Option<ty::OpaqueHiddenType<'tcx>>,
606606

607607
/// In the presence of dead code, typeck may figure out a hidden type
608-
/// while borrowck will now. We collect these cases here and check at
608+
/// while borrowck will not. We collect these cases here and check at
609609
/// the end that we actually found a type that matches (modulo regions).
610610
typeck_types: Vec<ty::OpaqueHiddenType<'tcx>>,
611611
}

compiler/rustc_middle/src/mir/syntax.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ pub enum MirPhase {
7878
/// MIR, this is UB.
7979
/// - Retags: If `-Zmir-emit-retag` is enabled, analysis MIR has "implicit" retags in the same way
8080
/// that Rust itself has them. Where exactly these are is generally subject to change, and so we
81-
/// don't document this here. Runtime MIR has all retags explicit.
81+
/// don't document this here. Runtime MIR has most retags explicit (though implicit retags
82+
/// can still occur at `Rvalue::{Ref,AddrOf}`).
8283
/// - Generator bodies: In analysis MIR, locals may actually be behind a pointer that user code has
8384
/// access to. This occurs in generator bodies. Such locals do not behave like other locals,
8485
/// because they eg may be aliased in surprising ways. Runtime MIR has no such special locals -
@@ -1165,7 +1166,7 @@ pub enum AggregateKind<'tcx> {
11651166
Tuple,
11661167

11671168
/// The second field is the variant index. It's equal to 0 for struct
1168-
/// and union expressions. The fourth field is
1169+
/// and union expressions. The last field is the
11691170
/// active field number and is present only for union expressions
11701171
/// -- e.g., for a union expression `SomeUnion { c: .. }`, the
11711172
/// active field index would identity the field `c`

compiler/rustc_middle/src/traits/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,9 @@ pub enum ObjectSafetyViolation {
897897
/// (e.g., `trait Foo : Bar<Self>`).
898898
SupertraitSelf(SmallVec<[Span; 1]>),
899899

900+
// Supertrait has a non-lifetime `for<T>` binder.
901+
SupertraitNonLifetimeBinder(SmallVec<[Span; 1]>),
902+
900903
/// Method has something illegal.
901904
Method(Symbol, MethodViolationCode, Span),
902905

@@ -919,6 +922,9 @@ impl ObjectSafetyViolation {
919922
.into()
920923
}
921924
}
925+
ObjectSafetyViolation::SupertraitNonLifetimeBinder(_) => {
926+
format!("where clause cannot reference non-lifetime `for<...>` variables").into()
927+
}
922928
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod(_), _) => {
923929
format!("associated function `{}` has no `self` parameter", name).into()
924930
}
@@ -969,7 +975,9 @@ impl ObjectSafetyViolation {
969975

970976
pub fn solution(&self, err: &mut Diagnostic) {
971977
match self {
972-
ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf(_) => {}
978+
ObjectSafetyViolation::SizedSelf(_)
979+
| ObjectSafetyViolation::SupertraitSelf(_)
980+
| ObjectSafetyViolation::SupertraitNonLifetimeBinder(..) => {}
973981
ObjectSafetyViolation::Method(
974982
name,
975983
MethodViolationCode::StaticMethod(Some((add_self_sugg, make_sized_sugg))),
@@ -1023,7 +1031,8 @@ impl ObjectSafetyViolation {
10231031
// diagnostics use a `note` instead of a `span_label`.
10241032
match self {
10251033
ObjectSafetyViolation::SupertraitSelf(spans)
1026-
| ObjectSafetyViolation::SizedSelf(spans) => spans.clone(),
1034+
| ObjectSafetyViolation::SizedSelf(spans)
1035+
| ObjectSafetyViolation::SupertraitNonLifetimeBinder(spans) => spans.clone(),
10271036
ObjectSafetyViolation::AssocConst(_, span)
10281037
| ObjectSafetyViolation::GAT(_, span)
10291038
| ObjectSafetyViolation::Method(_, _, span)

compiler/rustc_middle/src/ty/fold.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ where
5151
// Region folder
5252

5353
impl<'tcx> TyCtxt<'tcx> {
54-
/// Folds the escaping and free regions in `value` using `f`, and
55-
/// sets `skipped_regions` to true if any late-bound region was found
56-
/// and skipped.
54+
/// Folds the escaping and free regions in `value` using `f`.
5755
pub fn fold_regions<T>(
5856
self,
5957
value: T,
@@ -64,17 +62,6 @@ impl<'tcx> TyCtxt<'tcx> {
6462
{
6563
value.fold_with(&mut RegionFolder::new(self, &mut f))
6664
}
67-
68-
pub fn super_fold_regions<T>(
69-
self,
70-
value: T,
71-
mut f: impl FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>,
72-
) -> T
73-
where
74-
T: TypeSuperFoldable<TyCtxt<'tcx>>,
75-
{
76-
value.super_fold_with(&mut RegionFolder::new(self, &mut f))
77-
}
7865
}
7966

8067
/// Folds over the substructure of a type, visiting its component

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

+22
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,28 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
166166
let cast_kind = mir_cast_kind(source_ty, expr.ty);
167167
Ok(Rvalue::Cast(cast_kind, source, expr.ty))
168168
},
169+
ExprKind::Tuple { fields } => Ok(
170+
Rvalue::Aggregate(
171+
Box::new(AggregateKind::Tuple),
172+
fields.iter().map(|e| self.parse_operand(*e)).collect::<Result<_, _>>()?
173+
)
174+
),
175+
ExprKind::Array { fields } => {
176+
let elem_ty = expr.ty.builtin_index().expect("ty must be an array");
177+
Ok(Rvalue::Aggregate(
178+
Box::new(AggregateKind::Array(elem_ty)),
179+
fields.iter().map(|e| self.parse_operand(*e)).collect::<Result<_, _>>()?
180+
))
181+
},
182+
ExprKind::Adt(box AdtExpr{ adt_def, variant_index, substs, fields, .. }) => {
183+
let is_union = adt_def.is_union();
184+
let active_field_index = is_union.then(|| fields[0].name.index());
185+
186+
Ok(Rvalue::Aggregate(
187+
Box::new(AggregateKind::Adt(adt_def.did(), *variant_index, substs, None, active_field_index)),
188+
fields.iter().map(|f| self.parse_operand(f.expr)).collect::<Result<_, _>>()?
189+
))
190+
},
169191
_ => self.parse_operand(expr_id).map(Rvalue::Use),
170192
)
171193
}

compiler/rustc_trait_selection/src/solve/assembly.rs

+20-27
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
224224
if goal.predicate.self_ty().is_ty_var() {
225225
return vec![Candidate {
226226
source: CandidateSource::BuiltinImpl,
227-
result: self.make_canonical_response(Certainty::AMBIGUOUS).unwrap(),
227+
result: self
228+
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
229+
.unwrap(),
228230
}];
229231
}
230232

@@ -261,37 +263,26 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
261263
let &ty::Alias(ty::Projection, projection_ty) = goal.predicate.self_ty().kind() else {
262264
return
263265
};
264-
self.probe(|this| {
265-
let normalized_ty = this.next_ty_infer();
266+
267+
self.probe(|ecx| {
268+
let normalized_ty = ecx.next_ty_infer();
266269
let normalizes_to_goal = goal.with(
267270
tcx,
268271
ty::Binder::dummy(ty::ProjectionPredicate {
269272
projection_ty,
270273
term: normalized_ty.into(),
271274
}),
272275
);
273-
let normalization_certainty = match this.evaluate_goal(normalizes_to_goal) {
274-
Ok((_, certainty)) => certainty,
275-
Err(NoSolution) => return,
276-
};
277-
let normalized_ty = this.resolve_vars_if_possible(normalized_ty);
278-
279-
// NOTE: Alternatively we could call `evaluate_goal` here and only have a `Normalized` candidate.
280-
// This doesn't work as long as we use `CandidateSource` in winnowing.
281-
let goal = goal.with(tcx, goal.predicate.with_self_ty(tcx, normalized_ty));
282-
let normalized_candidates = this.assemble_and_evaluate_candidates(goal);
283-
for mut normalized_candidate in normalized_candidates {
284-
normalized_candidate.result =
285-
normalized_candidate.result.unchecked_map(|mut response| {
286-
// FIXME: This currently hides overflow in the normalization step of the self type
287-
// which is probably wrong. Maybe `unify_and` should actually keep overflow as
288-
// we treat it as non-fatal anyways.
289-
response.certainty = response.certainty.unify_and(normalization_certainty);
290-
response
291-
});
292-
candidates.push(normalized_candidate);
276+
ecx.add_goal(normalizes_to_goal);
277+
if let Ok(_) = ecx.try_evaluate_added_goals() {
278+
let normalized_ty = ecx.resolve_vars_if_possible(normalized_ty);
279+
280+
// NOTE: Alternatively we could call `evaluate_goal` here and only have a `Normalized` candidate.
281+
// This doesn't work as long as we use `CandidateSource` in winnowing.
282+
let goal = goal.with(tcx, goal.predicate.with_self_ty(tcx, normalized_ty));
283+
candidates.extend(ecx.assemble_and_evaluate_candidates(goal));
293284
}
294-
})
285+
});
295286
}
296287

297288
fn assemble_impl_candidates<G: GoalKind<'tcx>>(
@@ -516,7 +507,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
516507
} else {
517508
Certainty::AMBIGUOUS
518509
};
519-
return self.make_canonical_response(certainty);
510+
return self.evaluate_added_goals_and_make_canonical_response(certainty);
520511
}
521512
}
522513

@@ -538,14 +529,16 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
538529
}
539530
}
540531

541-
fn discard_reservation_impl(&self, mut candidate: Candidate<'tcx>) -> Candidate<'tcx> {
532+
fn discard_reservation_impl(&mut self, mut candidate: Candidate<'tcx>) -> Candidate<'tcx> {
542533
if let CandidateSource::Impl(def_id) = candidate.source {
543534
if let ty::ImplPolarity::Reservation = self.tcx().impl_polarity(def_id) {
544535
debug!("Selected reservation impl");
545536
// We assemble all candidates inside of a probe so by
546537
// making a new canonical response here our result will
547538
// have no constraints.
548-
candidate.result = self.make_canonical_response(Certainty::AMBIGUOUS).unwrap();
539+
candidate.result = self
540+
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
541+
.unwrap();
549542
}
550543
}
551544

compiler/rustc_trait_selection/src/solve/canonical/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
4848
/// - `external_constraints`: additional constraints which aren't expressable
4949
/// using simple unification of inference variables.
5050
#[instrument(level = "debug", skip(self))]
51-
pub(super) fn make_canonical_response(&self, certainty: Certainty) -> QueryResult<'tcx> {
51+
pub(super) fn evaluate_added_goals_and_make_canonical_response(
52+
&mut self,
53+
certainty: Certainty,
54+
) -> QueryResult<'tcx> {
55+
let goals_certainty = self.try_evaluate_added_goals()?;
56+
let certainty = certainty.unify_and(goals_certainty);
57+
5258
let external_constraints = self.compute_external_query_constraints()?;
5359

5460
let response = Response { var_values: self.var_values, external_constraints, certainty };
@@ -209,7 +215,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
209215
// FIXME: To deal with #105787 I also expect us to emit nested obligations here at
210216
// some point. We can figure out how to deal with this once we actually have
211217
// an ICE.
212-
let nested_goals = self.eq(param_env, orig, response)?;
218+
let nested_goals = self.eq_and_get_goals(param_env, orig, response)?;
213219
assert!(nested_goals.is_empty(), "{nested_goals:?}");
214220
}
215221

0 commit comments

Comments
 (0)