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

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-1
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)

Diff for: compiler/rustc_smir/src/rustc_smir/convert/mir.rs

+1
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
}

Diff for: compiler/rustc_trait_selection/src/traits/structural_normalize.rs

+31-30
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
}

Diff for: compiler/stable_mir/src/mir/body.rs

+5-1
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.

Diff for: compiler/stable_mir/src/mir/visit.rs

+3-1
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) {

Diff for: src/doc/embedded-book

Diff for: src/doc/reference

Diff for: tests/ui/issues/issue-22638.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// build-fail
22
// normalize-stderr-test: "<\{closure@.+`" -> "$$CLOSURE`"
33
// normalize-stderr-test: ".nll/" -> "/"
4+
// ignore-compare-mode-next-solver (hangs)
45

56
#![allow(unused)]
67

Diff for: tests/ui/issues/issue-22638.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: reached the recursion limit while instantiating `A::matches::$CLOSURE`
2-
--> $DIR/issue-22638.rs:56:9
2+
--> $DIR/issue-22638.rs:57:9
33
|
44
LL | a.matches(f)
55
| ^^^^^^^^^^^^
66
|
77
note: `A::matches` defined here
8-
--> $DIR/issue-22638.rs:15:5
8+
--> $DIR/issue-22638.rs:16:5
99
|
1010
LL | pub fn matches<F: Fn()>(&self, f: &F) {
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Diff for: tests/ui/issues/issue-67552.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// build-fail
22
// compile-flags: -Copt-level=0
33
// normalize-stderr-test: ".nll/" -> "/"
4-
// ignore-compare-mode-next-solver (hangs)
54

65
fn main() {
76
rec(Empty);

Diff for: tests/ui/issues/issue-67552.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: reached the recursion limit while instantiating `rec::<&mut &mut &mut &mut &mut ...>`
2-
--> $DIR/issue-67552.rs:30:9
2+
--> $DIR/issue-67552.rs:29:9
33
|
44
LL | rec(identity(&mut it))
55
| ^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: `rec` defined here
8-
--> $DIR/issue-67552.rs:23:1
8+
--> $DIR/issue-67552.rs:22:1
99
|
1010
LL | / fn rec<T>(mut it: T)
1111
LL | | where

Diff for: tests/ui/recursion/issue-95134.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// compile-flags: -Copt-level=0
44
// dont-check-failure-status
55
// dont-check-compiler-stderr
6-
// ignore-compare-mode-next-solver (hangs)
76

87
pub fn encode_num<Writer: ExampleWriter>(n: u32, mut writer: Writer) -> Result<(), Writer::Error> {
98
if n > 15 {

Diff for: tests/ui/traits/next-solver/alias-bound-unsound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() {
2323
let x = String::from("hello, world");
2424
drop(<() as Foo>::copy_me(&x));
2525
//~^ ERROR overflow evaluating the requirement `<() as Foo>::Item: Sized`
26-
//~| ERROR overflow evaluating the requirement `<() as Foo>::Item normalizes-to _`
26+
//~| ERROR overflow evaluating the requirement `<() as Foo>::Item == _`
2727
//~| ERROR overflow evaluating the requirement `<() as Foo>::Item well-formed`
2828
//~| ERROR overflow evaluating the requirement `String <: <() as Foo>::Item`
2929
//~| ERROR overflow evaluating the requirement `&<() as Foo>::Item well-formed`

Diff for: tests/ui/traits/next-solver/alias-bound-unsound.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | drop(<() as Foo>::copy_me(&x));
1919
|
2020
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`)
2121

22-
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item normalizes-to _`
22+
error[E0275]: overflow evaluating the requirement `<() as Foo>::Item == _`
2323
--> $DIR/alias-bound-unsound.rs:24:10
2424
|
2525
LL | drop(<() as Foo>::copy_me(&x));
@@ -59,7 +59,6 @@ LL | drop(<() as Foo>::copy_me(&x));
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^
6060
|
6161
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`alias_bound_unsound`)
62-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
6362

6463
error: aborting due to 7 previous errors
6564

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags: -Znext-solver
2+
// check-pass
3+
4+
trait Trait {
5+
type Assoc;
6+
}
7+
8+
fn call<T: Trait>(_: <T as Trait>::Assoc, _: T) {}
9+
10+
fn foo<T: Trait>(rigid: <T as Trait>::Assoc, t: T) {
11+
// Check that we can coerce `<?0 as Trait>::Assoc` to `<T as Trait>::Assoc`.
12+
call::<_ /* ?0 */>(rigid, t);
13+
}
14+
15+
fn main() {}

Diff for: tests/ui/traits/next-solver/object-unsafety.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub fn copy_any<T>(t: &T) -> T {
1313
//~^ ERROR the type `&<dyn Setup<From = T> as Setup>::From` is not well-formed
1414
//~| ERROR the trait bound `dyn Setup<From = T>: Setup` is not satisfied
1515
//~| ERROR mismatched types
16-
//~| ERROR mismatched types
1716
//~| ERROR the type `<dyn Setup<From = T> as Setup>::From` is not well-formed
1817
//~| ERROR the size for values of type `<dyn Setup<From = T> as Setup>::From` cannot be known at compilation time
1918

Diff for: tests/ui/traits/next-solver/object-unsafety.stderr

+1-15
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ note: function defined here
3636
LL | fn copy<U: Setup + ?Sized>(from: &U::From) -> U::From {
3737
| ^^^^ --------------
3838

39-
error[E0308]: mismatched types
40-
--> $DIR/object-unsafety.rs:12:5
41-
|
42-
LL | pub fn copy_any<T>(t: &T) -> T {
43-
| - - expected `T` because of return type
44-
| |
45-
| expected this type parameter
46-
LL | copy::<dyn Setup<From=T>>(t)
47-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ
48-
|
49-
= note: expected type parameter `T`
50-
found associated type `<dyn Setup<From = T> as Setup>::From`
51-
= note: you might be missing a type parameter or trait bound
52-
5339
error: the type `<dyn Setup<From = T> as Setup>::From` is not well-formed
5440
--> $DIR/object-unsafety.rs:12:5
5541
|
@@ -72,7 +58,7 @@ help: consider further restricting the associated type
7258
LL | pub fn copy_any<T>(t: &T) -> T where <dyn Setup<From = T> as Setup>::From: Sized {
7359
| +++++++++++++++++++++++++++++++++++++++++++++++++
7460

75-
error: aborting due to 6 previous errors
61+
error: aborting due to 5 previous errors
7662

7763
Some errors have detailed explanations: E0277, E0308.
7864
For more information about an error, try `rustc --explain E0277`.

Diff for: tests/ui/type-alias-impl-trait/self-referential-3.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-compare-mode-next-solver (hangs)
2+
13
#![feature(type_alias_impl_trait)]
24

35
type Bar<'a, 'b> = impl PartialEq<Bar<'a, 'b>> + std::fmt::Debug;

Diff for: tests/ui/type-alias-impl-trait/self-referential-3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: can't compare `&i32` with `Bar<'a, 'b>`
2-
--> $DIR/self-referential-3.rs:5:31
2+
--> $DIR/self-referential-3.rs:7:31
33
|
44
LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
55
| ^^^^^^^^^^^ no implementation for `&i32 == Bar<'a, 'b>`

Diff for: tests/ui/type-alias-impl-trait/self-referential-4.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-compare-mode-next-solver (hangs)
2+
13
#![feature(type_alias_impl_trait)]
24

35
type Bar<'a, 'b> = impl PartialEq<Bar<'b, 'static>> + std::fmt::Debug;

Diff for: tests/ui/type-alias-impl-trait/self-referential-4.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: can't compare `&i32` with `Bar<'b, 'static>`
2-
--> $DIR/self-referential-4.rs:5:31
2+
--> $DIR/self-referential-4.rs:7:31
33
|
44
LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
55
| ^^^^^^^^^^^ no implementation for `&i32 == Bar<'b, 'static>`
@@ -10,7 +10,7 @@ LL | i
1010
= help: the trait `PartialEq` is implemented for `i32`
1111

1212
error[E0277]: can't compare `&i32` with `Foo<'static, 'b>`
13-
--> $DIR/self-referential-4.rs:11:31
13+
--> $DIR/self-referential-4.rs:13:31
1414
|
1515
LL | fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> {
1616
| ^^^^^^^^^^^ no implementation for `&i32 == Foo<'static, 'b>`
@@ -21,7 +21,7 @@ LL | i
2121
= help: the trait `PartialEq` is implemented for `i32`
2222

2323
error[E0277]: can't compare `&i32` with `Moo<'static, 'a>`
24-
--> $DIR/self-referential-4.rs:17:31
24+
--> $DIR/self-referential-4.rs:19:31
2525
|
2626
LL | fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> {
2727
| ^^^^^^^^^^^ no implementation for `&i32 == Moo<'static, 'a>`

Diff for: tests/ui/type-alias-impl-trait/self-referential.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-compare-mode-next-solver (hangs)
2+
13
#![feature(type_alias_impl_trait)]
24

35
type Bar<'a, 'b> = impl PartialEq<Bar<'b, 'a>> + std::fmt::Debug;

Diff for: tests/ui/type-alias-impl-trait/self-referential.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: can't compare `&i32` with `Bar<'b, 'a>`
2-
--> $DIR/self-referential.rs:5:31
2+
--> $DIR/self-referential.rs:7:31
33
|
44
LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
55
| ^^^^^^^^^^^ no implementation for `&i32 == Bar<'b, 'a>`
@@ -11,7 +11,7 @@ LL | i
1111
= help: the trait `PartialEq` is implemented for `i32`
1212

1313
error[E0277]: can't compare `&i32` with `(i32, Foo<'a, 'b>::{opaque#0})`
14-
--> $DIR/self-referential.rs:12:31
14+
--> $DIR/self-referential.rs:14:31
1515
|
1616
LL | fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> {
1717
| ^^^^^^^^^^^ no implementation for `&i32 == (i32, Foo<'a, 'b>::{opaque#0})`
@@ -23,7 +23,7 @@ LL | (42, i)
2323
= help: the trait `PartialEq` is implemented for `i32`
2424

2525
error[E0277]: can't compare `&i32` with `(i32, Moo<'b, 'a>::{opaque#0})`
26-
--> $DIR/self-referential.rs:19:31
26+
--> $DIR/self-referential.rs:21:31
2727
|
2828
LL | fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> {
2929
| ^^^^^^^^^^^ no implementation for `&i32 == (i32, Moo<'b, 'a>::{opaque#0})`

0 commit comments

Comments
 (0)