Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f77ead0

Browse files
committed
Auto merge of rust-lang#135835 - matthiaskrgr:rollup-pzaa7cn, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#132232 (CI: build FreeBSD artifacts on FreeBSD 13.4) - rust-lang#135625 ([cfg_match] Document the use of expressions.) - rust-lang#135750 (Add an example of using `carrying_mul_add` to write wider multiplication) - rust-lang#135793 (Ignore `mermaid.min.js`) - rust-lang#135810 (Add Kobzol on vacation) - rust-lang#135816 (Use `structurally_normalize` instead of manual `normalizes-to` goals in alias relate errors) - rust-lang#135821 (fix OsString::from_encoded_bytes_unchecked description) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cd805f0 + 1e3f266 commit f77ead0

35 files changed

+322
-134
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ __pycache__/
8383
node_modules
8484
package-lock.json
8585
package.json
86+
/src/doc/rustc-dev-guide/mermaid.min.js
8687

8788
## Rustdoc GUI tests
8889
tests/rustdoc-gui/src/**.lock

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
185185
CustomTypeOp::new(
186186
|ocx| {
187187
let structurally_normalize = |ty| {
188-
ocx.structurally_normalize(
188+
ocx.structurally_normalize_ty(
189189
&ObligationCause::misc(
190190
location.to_locations().span(body),
191191
body.source.def_id().expect_local(),
@@ -230,7 +230,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
230230
ConstraintCategory::Boring,
231231
CustomTypeOp::new(
232232
|ocx| {
233-
ocx.structurally_normalize(
233+
ocx.structurally_normalize_ty(
234234
&ObligationCause::misc(
235235
location.to_locations().span(body),
236236
body.source.def_id().expect_local(),

compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> {
8686
if self.infcx.next_trait_solver()
8787
&& let ty::Alias(..) = ty.kind()
8888
{
89-
let (normalized_ty, obligations) = self.structurally_normalize(ty)?;
89+
let (normalized_ty, obligations) = self.structurally_normalize_ty(ty)?;
9090
self.state.obligations.extend(obligations);
9191
(AutoderefKind::Builtin, normalized_ty)
9292
} else {
@@ -166,20 +166,20 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
166166
}
167167

168168
let (normalized_ty, obligations) =
169-
self.structurally_normalize(Ty::new_projection(tcx, trait_target_def_id, [ty]))?;
169+
self.structurally_normalize_ty(Ty::new_projection(tcx, trait_target_def_id, [ty]))?;
170170
debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations);
171171
self.state.obligations.extend(obligations);
172172

173173
Some(self.infcx.resolve_vars_if_possible(normalized_ty))
174174
}
175175

176176
#[instrument(level = "debug", skip(self), ret)]
177-
pub fn structurally_normalize(
177+
pub fn structurally_normalize_ty(
178178
&self,
179179
ty: Ty<'tcx>,
180180
) -> Option<(Ty<'tcx>, PredicateObligations<'tcx>)> {
181181
let ocx = ObligationCtxt::new(self.infcx);
182-
let Ok(normalized_ty) = ocx.structurally_normalize(
182+
let Ok(normalized_ty) = ocx.structurally_normalize_ty(
183183
&traits::ObligationCause::misc(self.span, self.body_id),
184184
self.param_env,
185185
ty,

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ fn orphan_check<'tcx>(
320320
}
321321

322322
let ty = if infcx.next_trait_solver() {
323-
ocx.structurally_normalize(
323+
ocx.structurally_normalize_ty(
324324
&cause,
325325
ty::ParamEnv::empty(),
326326
infcx.resolve_vars_if_possible(ty),

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11241124
if self.next_trait_solver()
11251125
&& let ty::Alias(..) = ty.kind()
11261126
{
1127-
ocx.structurally_normalize(&cause, self.param_env, ty)
1127+
ocx.structurally_normalize_ty(&cause, self.param_env, ty)
11281128
} else {
11291129
Ok(ty)
11301130
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14331433
// in a reentrant borrow, causing an ICE.
14341434
let result = self
14351435
.at(&self.misc(sp), self.param_env)
1436-
.structurally_normalize(ty, &mut **self.fulfillment_cx.borrow_mut());
1436+
.structurally_normalize_ty(ty, &mut **self.fulfillment_cx.borrow_mut());
14371437
match result {
14381438
Ok(normalized_ty) => normalized_ty,
14391439
Err(errors) => {

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -277,23 +277,7 @@ where
277277
param_env: I::ParamEnv,
278278
ty: I::Ty,
279279
) -> Result<I::Ty, NoSolution> {
280-
if let ty::Alias(..) = ty.kind() {
281-
let normalized_ty = self.next_ty_infer();
282-
let alias_relate_goal = Goal::new(
283-
self.cx(),
284-
param_env,
285-
ty::PredicateKind::AliasRelate(
286-
ty.into(),
287-
normalized_ty.into(),
288-
ty::AliasRelationDirection::Equate,
289-
),
290-
);
291-
self.add_goal(GoalSource::Misc, alias_relate_goal);
292-
self.try_evaluate_added_goals()?;
293-
Ok(self.resolve_vars_if_possible(normalized_ty))
294-
} else {
295-
Ok(ty)
296-
}
280+
self.structurally_normalize_term(param_env, ty.into()).map(|term| term.expect_ty())
297281
}
298282

299283
/// Normalize a const for when it is structurally matched on, or more likely
@@ -308,22 +292,34 @@ where
308292
param_env: I::ParamEnv,
309293
ct: I::Const,
310294
) -> Result<I::Const, NoSolution> {
311-
if let ty::ConstKind::Unevaluated(..) = ct.kind() {
312-
let normalized_ct = self.next_const_infer();
295+
self.structurally_normalize_term(param_env, ct.into()).map(|term| term.expect_const())
296+
}
297+
298+
/// Normalize a term for when it is structurally matched on.
299+
///
300+
/// This function is necessary in nearly all cases before matching on a ty/const.
301+
/// Not doing so is likely to be incomplete and therefore unsound during coherence.
302+
fn structurally_normalize_term(
303+
&mut self,
304+
param_env: I::ParamEnv,
305+
term: I::Term,
306+
) -> Result<I::Term, NoSolution> {
307+
if let Some(_) = term.to_alias_term() {
308+
let normalized_term = self.next_term_infer_of_kind(term);
313309
let alias_relate_goal = Goal::new(
314310
self.cx(),
315311
param_env,
316312
ty::PredicateKind::AliasRelate(
317-
ct.into(),
318-
normalized_ct.into(),
313+
term,
314+
normalized_term,
319315
ty::AliasRelationDirection::Equate,
320316
),
321317
);
322318
self.add_goal(GoalSource::Misc, alias_relate_goal);
323319
self.try_evaluate_added_goals()?;
324-
Ok(self.resolve_vars_if_possible(normalized_ct))
320+
Ok(self.resolve_vars_if_possible(normalized_term))
325321
} else {
326-
Ok(ct)
322+
Ok(term)
327323
}
328324
}
329325

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,20 +1338,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
13381338
let derive_better_type_error =
13391339
|alias_term: ty::AliasTerm<'tcx>, expected_term: ty::Term<'tcx>| {
13401340
let ocx = ObligationCtxt::new(self);
1341-
let normalized_term = match expected_term.unpack() {
1342-
ty::TermKind::Ty(_) => self.next_ty_var(DUMMY_SP).into(),
1343-
ty::TermKind::Const(_) => self.next_const_var(DUMMY_SP).into(),
1344-
};
1345-
ocx.register_obligation(Obligation::new(
1346-
self.tcx,
1347-
ObligationCause::dummy(),
1341+
1342+
let Ok(normalized_term) = ocx.structurally_normalize_term(
1343+
&ObligationCause::dummy(),
13481344
obligation.param_env,
1349-
ty::PredicateKind::NormalizesTo(ty::NormalizesTo {
1350-
alias: alias_term,
1351-
term: normalized_term,
1352-
}),
1353-
));
1354-
let _ = ocx.select_where_possible();
1345+
alias_term.to_term(self.tcx),
1346+
) else {
1347+
return None;
1348+
};
1349+
13551350
if let Err(terr) = ocx.eq(
13561351
&ObligationCause::dummy(),
13571352
obligation.param_env,

compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> {
709709
if matches!(ty.kind(), ty::Alias(..)) {
710710
let ocx = ObligationCtxt::new(infcx);
711711
ty = ocx
712-
.structurally_normalize(&ObligationCause::dummy(), param_env, ty)
712+
.structurally_normalize_ty(&ObligationCause::dummy(), param_env, ty)
713713
.map_err(|_| ())?;
714714
if !ocx.select_where_possible().is_empty() {
715715
return Err(());

compiler/rustc_trait_selection/src/traits/engine.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,15 @@ where
319319
self.infcx.at(cause, param_env).deeply_normalize(value, &mut **self.engine.borrow_mut())
320320
}
321321

322-
pub fn structurally_normalize(
322+
pub fn structurally_normalize_ty(
323323
&self,
324324
cause: &ObligationCause<'tcx>,
325325
param_env: ty::ParamEnv<'tcx>,
326326
value: Ty<'tcx>,
327327
) -> Result<Ty<'tcx>, Vec<E>> {
328328
self.infcx
329329
.at(cause, param_env)
330-
.structurally_normalize(value, &mut **self.engine.borrow_mut())
330+
.structurally_normalize_ty(value, &mut **self.engine.borrow_mut())
331331
}
332332

333333
pub fn structurally_normalize_const(
@@ -340,4 +340,15 @@ where
340340
.at(cause, param_env)
341341
.structurally_normalize_const(value, &mut **self.engine.borrow_mut())
342342
}
343+
344+
pub fn structurally_normalize_term(
345+
&self,
346+
cause: &ObligationCause<'tcx>,
347+
param_env: ty::ParamEnv<'tcx>,
348+
value: ty::Term<'tcx>,
349+
) -> Result<ty::Term<'tcx>, Vec<E>> {
350+
self.infcx
351+
.at(cause, param_env)
352+
.structurally_normalize_term(value, &mut **self.engine.borrow_mut())
353+
}
343354
}

0 commit comments

Comments
 (0)