Skip to content

Commit ba4a2f7

Browse files
Resolve target type of coercion
1 parent fb9030d commit ba4a2f7

8 files changed

+53
-50
lines changed

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: 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)