Skip to content

Commit 418b91a

Browse files
authored
Rollup merge of rust-lang#114594 - compiler-errors:new-solver-resolve-aliases, r=lcnr
Structurally normalize weak and inherent in new solver It seems pretty obvious to me that we should be normalizing weak and inherent aliases too, since they can always be normalized. This PR still leaves open the question of what to do with opaques, though 💀 **Also**, we need to structurally resolve the target of a coercion, for the UI test to work. r? `@lcnr`
2 parents 3cd0a10 + ba4a2f7 commit 418b91a

File tree

11 files changed

+58
-53
lines changed

11 files changed

+58
-53
lines changed

Diff for: compiler/rustc_hir_analysis/src/autoderef.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> {
7474
// we have some type like `&<Ty as Trait>::Assoc`, since users of
7575
// autoderef expect this type to have been structurally normalized.
7676
if self.infcx.next_trait_solver()
77-
&& let ty::Alias(ty::Projection, _) = ty.kind()
77+
&& let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _) = ty.kind()
7878
{
7979
let (normalized_ty, obligations) = self.structurally_normalize(ty)?;
8080
self.state.obligations.extend(obligations);

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10121012
cause: Option<ObligationCause<'tcx>>,
10131013
) -> RelateResult<'tcx, Ty<'tcx>> {
10141014
let source = self.try_structurally_resolve_type(expr.span, expr_ty);
1015+
let target = self.try_structurally_resolve_type(
1016+
cause.as_ref().map_or(expr.span, |cause| cause.span),
1017+
target,
1018+
);
10151019
debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target);
10161020

10171021
let cause =
@@ -1097,8 +1101,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10971101
where
10981102
E: AsCoercionSite,
10991103
{
1100-
let prev_ty = self.resolve_vars_with_obligations(prev_ty);
1101-
let new_ty = self.resolve_vars_with_obligations(new_ty);
1104+
let prev_ty = self.try_structurally_resolve_type(cause.span, prev_ty);
1105+
let new_ty = self.try_structurally_resolve_type(new.span, new_ty);
11021106
debug!(
11031107
"coercion::try_find_coercion_lub({:?}, {:?}, exprs={:?} exprs)",
11041108
prev_ty,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14741474
let ty = self.resolve_vars_with_obligations(ty);
14751475

14761476
if self.next_trait_solver()
1477-
&& let ty::Alias(ty::Projection, _) = ty.kind()
1477+
&& let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _) = ty.kind()
14781478
{
14791479
match self
14801480
.at(&self.misc(sp), self.param_env)

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ impl<'tcx> StructurallyNormalizeExt<'tcx> for At<'_, 'tcx> {
2222
assert!(!ty.is_ty_var(), "should have resolved vars before calling");
2323

2424
if self.infcx.next_trait_solver() {
25-
while let ty::Alias(ty::Projection, projection_ty) = *ty.kind() {
25+
while let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, projection_ty) =
26+
*ty.kind()
27+
{
2628
let new_infer_ty = self.infcx.next_ty_var(TypeVariableOrigin {
2729
kind: TypeVariableOriginKind::NormalizeProjectionType,
2830
span: self.cause.span,

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ 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[E0614]: type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced
38-
--> $DIR/issue-20605.rs:5:27
39-
|
40-
LL | for item in *things { *item = 0 }
41-
| ^^^^^
42-
4337
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
4438
--> $DIR/issue-20605.rs:5:9
4539
|
@@ -66,6 +60,12 @@ LL | for item in *things { *item = 0 }
6660
note: required by a bound in `None`
6761
--> $SRC_DIR/core/src/option.rs:LL:COL
6862

63+
error[E0614]: type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced
64+
--> $DIR/issue-20605.rs:5:27
65+
|
66+
LL | for item in *things { *item = 0 }
67+
| ^^^^^
68+
6969
error: aborting due to 9 previous errors
7070

7171
Some errors have detailed explanations: E0277, E0614.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/coerce-behind-lazy.rs:5:12
3+
|
4+
LL | #![feature(lazy_type_alias)]
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/coerce-behind-lazy.rs:5:12
3+
|
4+
LL | #![feature(lazy_type_alias)]
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

Diff for: tests/ui/lazy-type-alias/coerce-behind-lazy.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
// revisions: current next
3+
//[next] compile-flags: -Ztrait-solver=next
4+
5+
#![feature(lazy_type_alias)]
6+
//~^ WARN the feature `lazy_type_alias` is incomplete
7+
8+
use std::any::Any;
9+
10+
type Coerce = Box<dyn Any>;
11+
12+
fn test() -> Coerce {
13+
Box::new(1)
14+
}
15+
16+
fn main() {}

Diff for: tests/ui/traits/new-solver/lazy-nested-obligations-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// compile-flags: -Ztrait-solver=next
2-
// known-bug: #95863
2+
// check-pass
33

44
pub trait With {
55
type F;

Diff for: tests/ui/traits/new-solver/lazy-nested-obligations-2.stderr

-39
This file was deleted.

Diff for: tests/ui/traits/new-solver/more-object-bound.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `dyn Trait<A = A, B = B>: Trait` is not satisfied
2-
--> $DIR/more-object-bound.rs:12:17
2+
--> $DIR/more-object-bound.rs:12:5
33
|
44
LL | foo::<A, B, dyn Trait<A = A, B = B>>(x)
5-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Trait<A = A, B = B>`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Trait<A = A, B = B>`
66
|
77
note: required by a bound in `foo`
88
--> $DIR/more-object-bound.rs:18:8

0 commit comments

Comments
 (0)