Skip to content

Commit 6b20098

Browse files
authored
Rollup merge of rust-lang#120378 - lcnr:normalize-ast, r=compiler-errors
always normalize `LoweredTy` in the new solver I currently expect us to stop using alias bound candidates of normalizable aliases due to rust-lang/trait-system-refactor-initiative#77 by landing rust-lang#119744. At this point it mostly doesn't matter whether we eagerly normalize (and replace with infer vars in case of ambiguity). cc rust-lang#113473 previous attempt The infer var replacement for ambiguous projections can in very rare cases: - weaken inference rust-lang/trait-system-refactor-initiative#81 - strengthen inference rust-lang/trait-system-refactor-initiative#7 I do not expect this impact on inference to significantly affect real crates. r? `@compiler-errors`
2 parents 8fe3ffa + 7b6ac8b commit 6b20098

16 files changed

+60
-36
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,14 @@ pub struct LoweredTy<'tcx> {
369369

370370
impl<'tcx> LoweredTy<'tcx> {
371371
pub fn from_raw(fcx: &FnCtxt<'_, 'tcx>, span: Span, raw: Ty<'tcx>) -> LoweredTy<'tcx> {
372-
LoweredTy { raw, normalized: fcx.normalize(span, raw) }
372+
// FIXME(-Znext-solver): We're still figuring out how to best handle
373+
// normalization and this doesn't feel too great. We should look at this
374+
// code again before stabilizing it.
375+
let normalized = if fcx.next_trait_solver() {
376+
fcx.try_structurally_resolve_type(span, raw)
377+
} else {
378+
fcx.normalize(span, raw)
379+
};
380+
LoweredTy { raw, normalized }
373381
}
374382
}

tests/ui/for/issue-20605.next.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,11 @@ error: the type `&mut <dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIte
3434
LL | for item in *things { *item = 0 }
3535
| ^^^^^^^
3636

37-
error[E0277]: the size for values of type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be known at compilation time
38-
--> $DIR/issue-20605.rs:5:9
37+
error: the type `Option<<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item>` is not well-formed
38+
--> $DIR/issue-20605.rs:5:17
3939
|
4040
LL | for item in *things { *item = 0 }
41-
| ^^^^ doesn't have a size known at compile-time
42-
|
43-
= help: the trait `Sized` is not implemented for `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item`
44-
= note: all local variables must have a statically known size
45-
= help: unsized locals are gated as an unstable feature
41+
| ^^^^^^^
4642

4743
error[E0277]: the size for values of type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be known at compilation time
4844
--> $DIR/issue-20605.rs:5:5
@@ -54,11 +50,15 @@ LL | for item in *things { *item = 0 }
5450
note: required by a bound in `None`
5551
--> $SRC_DIR/core/src/option.rs:LL:COL
5652

57-
error: the type `Option<<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item>` is not well-formed
58-
--> $DIR/issue-20605.rs:5:17
53+
error[E0277]: the size for values of type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be known at compilation time
54+
--> $DIR/issue-20605.rs:5:9
5955
|
6056
LL | for item in *things { *item = 0 }
61-
| ^^^^^^^
57+
| ^^^^ doesn't have a size known at compile-time
58+
|
59+
= help: the trait `Sized` is not implemented for `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item`
60+
= note: all local variables must have a statically known size
61+
= help: unsized locals are gated as an unstable feature
6262

6363
error[E0614]: type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced
6464
--> $DIR/issue-20605.rs:5:27

tests/ui/traits/next-solver/tait-eq-proj-2.rs tests/ui/traits/next-solver/alias-relate/tait-eq-proj-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#![feature(type_alias_impl_trait)]
55

6-
// Similar to tests/ui/traits/next-solver/tait-eq-proj.rs
6+
// Similar to tests/ui/traits/next-solver/alias-relate/tait-eq-proj.rs
77
// but check the alias-sub relation in the other direction.
88

99
type Tait = impl Iterator<Item = impl Sized>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile-flags: -Znext-solver
2+
// check-pass
3+
4+
trait Mirror {
5+
type Assoc;
6+
}
7+
impl<T> Mirror for T {
8+
type Assoc = T;
9+
}
10+
11+
struct Foo;
12+
impl Foo {
13+
fn new() -> Self { Foo }
14+
}
15+
16+
fn main() {
17+
<Foo as Mirror>::Assoc::new();
18+
}

tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn test<T: Foo1<Assoc1 = <T as Foo2>::Assoc2> + Foo2<Assoc2 = <T as Foo1>::Assoc
1616
//~^ ERROR overflow evaluating the requirement `<T as Foo1>::Assoc1 == _`
1717
//~| ERROR overflow evaluating the requirement `<T as Foo1>::Assoc1 == _`
1818
//~| ERROR overflow evaluating the requirement `<T as Foo1>::Assoc1 == _`
19+
//~| ERROR overflow evaluating the requirement `<T as Foo1>::Assoc1 == _`
1920
//~| ERROR overflow evaluating the requirement `<T as Foo1>::Assoc1: Bar`
2021
}
2122

tests/ui/traits/next-solver/overflow/recursive-self-normalization-2.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1 == _`
2+
--> $DIR/recursive-self-normalization-2.rs:15:17
3+
|
4+
LL | needs_bar::<T::Assoc1>();
5+
| ^^^^^^^^^
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`)
8+
19
error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1: Bar`
210
--> $DIR/recursive-self-normalization-2.rs:15:17
311
|
@@ -35,7 +43,8 @@ LL | needs_bar::<T::Assoc1>();
3543
| ^^^^^^^^^
3644
|
3745
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`)
46+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3847

39-
error: aborting due to 4 previous errors
48+
error: aborting due to 5 previous errors
4049

4150
For more information about this error, try `rustc --explain E0275`.

tests/ui/traits/next-solver/overflow/recursive-self-normalization.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn test<T: Foo<Assoc = <T as Foo>::Assoc>>() {
1212
//~^ ERROR overflow evaluating the requirement `<T as Foo>::Assoc == _`
1313
//~| ERROR overflow evaluating the requirement `<T as Foo>::Assoc == _`
1414
//~| ERROR overflow evaluating the requirement `<T as Foo>::Assoc == _`
15+
//~| ERROR overflow evaluating the requirement `<T as Foo>::Assoc == _`
1516
//~| ERROR overflow evaluating the requirement `<T as Foo>::Assoc: Bar`
1617
}
1718

tests/ui/traits/next-solver/overflow/recursive-self-normalization.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc == _`
2+
--> $DIR/recursive-self-normalization.rs:11:17
3+
|
4+
LL | needs_bar::<T::Assoc>();
5+
| ^^^^^^^^
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`)
8+
19
error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc: Bar`
210
--> $DIR/recursive-self-normalization.rs:11:17
311
|
@@ -35,7 +43,8 @@ LL | needs_bar::<T::Assoc>();
3543
| ^^^^^^^^
3644
|
3745
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`)
46+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3847

39-
error: aborting due to 4 previous errors
48+
error: aborting due to 5 previous errors
4049

4150
For more information about this error, try `rustc --explain E0275`.

tests/ui/traits/next-solver/temporary-ambiguity.rs

-22
This file was deleted.

0 commit comments

Comments
 (0)