Skip to content

Commit 69e4545

Browse files
committed
Auto merge of #119110 - matthiaskrgr:rollup-vr6ha8x, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #119087 (Update books) - #119091 (Use alias-eq in structural normalization) - #119098 (Adjust the ignore-compare-mode-next-solver for hangs) - #119100 (Add the function body span to StableMIR) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 32f5db9 + 739364b commit 69e4545

27 files changed

+83
-71
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14981498
let ty = self.resolve_vars_with_obligations(ty);
14991499

15001500
if self.next_trait_solver()
1501-
&& let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _) = ty.kind()
1501+
&& let ty::Alias(..) = ty.kind()
15021502
{
15031503
match self
15041504
.at(&self.misc(sp), self.param_env)

compiler/rustc_smir/src/rustc_smir/convert/mir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl<'tcx> Stable<'tcx> for mir::Body<'tcx> {
3737
self.arg_count,
3838
self.var_debug_info.iter().map(|info| info.stable(tables)).collect(),
3939
self.spread_arg.stable(tables),
40+
self.span.stable(tables),
4041
)
4142
}
4243
}

compiler/rustc_trait_selection/src/traits/structural_normalize.rs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
33
use rustc_infer::traits::{FulfillmentError, TraitEngine};
44
use rustc_middle::ty::{self, Ty};
55

6-
use crate::traits::{query::evaluate_obligation::InferCtxtExt, NormalizeExt, Obligation};
6+
use crate::traits::{NormalizeExt, Obligation};
77

88
pub trait StructurallyNormalizeExt<'tcx> {
99
fn structurally_normalize(
@@ -16,42 +16,43 @@ pub trait StructurallyNormalizeExt<'tcx> {
1616
impl<'tcx> StructurallyNormalizeExt<'tcx> for At<'_, 'tcx> {
1717
fn structurally_normalize(
1818
&self,
19-
mut ty: Ty<'tcx>,
19+
ty: Ty<'tcx>,
2020
fulfill_cx: &mut dyn TraitEngine<'tcx>,
2121
) -> Result<Ty<'tcx>, Vec<FulfillmentError<'tcx>>> {
2222
assert!(!ty.is_ty_var(), "should have resolved vars before calling");
2323

2424
if self.infcx.next_trait_solver() {
25-
// FIXME(-Znext-solver): correctly handle
26-
// overflow here.
27-
for _ in 0..256 {
28-
let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, alias) = *ty.kind() else {
29-
break;
30-
};
31-
32-
let new_infer_ty = self.infcx.next_ty_var(TypeVariableOrigin {
33-
kind: TypeVariableOriginKind::NormalizeProjectionType,
34-
span: self.cause.span,
35-
});
36-
let obligation = Obligation::new(
37-
self.infcx.tcx,
38-
self.cause.clone(),
39-
self.param_env,
40-
ty::NormalizesTo { alias, term: new_infer_ty.into() },
41-
);
42-
if self.infcx.predicate_may_hold(&obligation) {
43-
fulfill_cx.register_predicate_obligation(self.infcx, obligation);
44-
let errors = fulfill_cx.select_where_possible(self.infcx);
45-
if !errors.is_empty() {
46-
return Err(errors);
47-
}
48-
ty = self.infcx.resolve_vars_if_possible(new_infer_ty);
49-
} else {
50-
break;
51-
}
25+
// FIXME(-Znext-solver): Should we resolve opaques here?
26+
let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _) = *ty.kind() else {
27+
return Ok(ty);
28+
};
29+
30+
let new_infer_ty = self.infcx.next_ty_var(TypeVariableOrigin {
31+
kind: TypeVariableOriginKind::NormalizeProjectionType,
32+
span: self.cause.span,
33+
});
34+
35+
// We simply emit an `alias-eq` goal here, since that will take care of
36+
// normalizing the LHS of the projection until it is a rigid projection
37+
// (or a not-yet-defined opaque in scope).
38+
let obligation = Obligation::new(
39+
self.infcx.tcx,
40+
self.cause.clone(),
41+
self.param_env,
42+
ty::PredicateKind::AliasRelate(
43+
ty.into(),
44+
new_infer_ty.into(),
45+
ty::AliasRelationDirection::Equate,
46+
),
47+
);
48+
49+
fulfill_cx.register_predicate_obligation(self.infcx, obligation);
50+
let errors = fulfill_cx.select_where_possible(self.infcx);
51+
if !errors.is_empty() {
52+
return Err(errors);
5253
}
5354

54-
Ok(ty)
55+
Ok(self.infcx.resolve_vars_if_possible(new_infer_ty))
5556
} else {
5657
Ok(self.normalize(ty).into_value_registering_obligations(self.infcx, fulfill_cx))
5758
}

compiler/stable_mir/src/mir/body.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub struct Body {
2727
///
2828
/// This is used for the "rust-call" ABI such as closures.
2929
pub(super) spread_arg: Option<Local>,
30+
31+
/// The span that covers the entire function body.
32+
pub span: Span,
3033
}
3134

3235
pub type BasicBlockIdx = usize;
@@ -42,14 +45,15 @@ impl Body {
4245
arg_count: usize,
4346
var_debug_info: Vec<VarDebugInfo>,
4447
spread_arg: Option<Local>,
48+
span: Span,
4549
) -> Self {
4650
// If locals doesn't contain enough entries, it can lead to panics in
4751
// `ret_local`, `arg_locals`, and `inner_locals`.
4852
assert!(
4953
locals.len() > arg_count,
5054
"A Body must contain at least a local for the return value and each of the function's arguments"
5155
);
52-
Self { blocks, locals, arg_count, var_debug_info, spread_arg }
56+
Self { blocks, locals, arg_count, var_debug_info, spread_arg, span }
5357
}
5458

5559
/// Return local that holds this function's return value.

compiler/stable_mir/src/mir/visit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub trait MirVisitor {
133133
}
134134

135135
fn super_body(&mut self, body: &Body) {
136-
let Body { blocks, locals: _, arg_count, var_debug_info, spread_arg: _ } = body;
136+
let Body { blocks, locals: _, arg_count, var_debug_info, spread_arg: _, span } = body;
137137

138138
for bb in blocks {
139139
self.visit_basic_block(bb);
@@ -153,6 +153,8 @@ pub trait MirVisitor {
153153
for info in var_debug_info.iter() {
154154
self.visit_var_debug_info(info);
155155
}
156+
157+
self.visit_span(span)
156158
}
157159

158160
fn super_basic_block(&mut self, bb: &BasicBlock) {

src/doc/embedded-book

src/doc/reference

0 commit comments

Comments
 (0)