Skip to content

Commit

Permalink
Resolve target type of coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 7, 2023
1 parent fb9030d commit ba4a2f7
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 50 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
cause: Option<ObligationCause<'tcx>>,
) -> RelateResult<'tcx, Ty<'tcx>> {
let source = self.try_structurally_resolve_type(expr.span, expr_ty);
let target = self.try_structurally_resolve_type(
cause.as_ref().map_or(expr.span, |cause| cause.span),
target,
);
debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target);

let cause =
Expand Down Expand Up @@ -1097,8 +1101,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
where
E: AsCoercionSite,
{
let prev_ty = self.resolve_vars_with_obligations(prev_ty);
let new_ty = self.resolve_vars_with_obligations(new_ty);
let prev_ty = self.try_structurally_resolve_type(cause.span, prev_ty);
let new_ty = self.try_structurally_resolve_type(new.span, new_ty);
debug!(
"coercion::try_find_coercion_lub({:?}, {:?}, exprs={:?} exprs)",
prev_ty,
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/for/issue-20605.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ error: the type `&mut <dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIte
LL | for item in *things { *item = 0 }
| ^^^^^^^

error[E0614]: type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced
--> $DIR/issue-20605.rs:5:27
|
LL | for item in *things { *item = 0 }
| ^^^^^

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
--> $DIR/issue-20605.rs:5:9
|
Expand All @@ -66,6 +60,12 @@ LL | for item in *things { *item = 0 }
note: required by a bound in `None`
--> $SRC_DIR/core/src/option.rs:LL:COL

error[E0614]: type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced
--> $DIR/issue-20605.rs:5:27
|
LL | for item in *things { *item = 0 }
| ^^^^^

error: aborting due to 9 previous errors

Some errors have detailed explanations: E0277, E0614.
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/lazy-type-alias/coerce-behind-lazy.current.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/coerce-behind-lazy.rs:5:12
|
LL | #![feature(lazy_type_alias)]
| ^^^^^^^^^^^^^^^
|
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

11 changes: 11 additions & 0 deletions tests/ui/lazy-type-alias/coerce-behind-lazy.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/coerce-behind-lazy.rs:5:12
|
LL | #![feature(lazy_type_alias)]
| ^^^^^^^^^^^^^^^
|
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

16 changes: 16 additions & 0 deletions tests/ui/lazy-type-alias/coerce-behind-lazy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// check-pass
// revisions: current next
//[next] compile-flags: -Ztrait-solver=next

#![feature(lazy_type_alias)]
//~^ WARN the feature `lazy_type_alias` is incomplete

use std::any::Any;

type Coerce = Box<dyn Any>;

fn test() -> Coerce {
Box::new(1)
}

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/traits/new-solver/lazy-nested-obligations-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// compile-flags: -Ztrait-solver=next
// known-bug: #95863
// check-pass

pub trait With {
type F;
Expand Down
39 changes: 0 additions & 39 deletions tests/ui/traits/new-solver/lazy-nested-obligations-2.stderr

This file was deleted.

4 changes: 2 additions & 2 deletions tests/ui/traits/new-solver/more-object-bound.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `dyn Trait<A = A, B = B>: Trait` is not satisfied
--> $DIR/more-object-bound.rs:12:17
--> $DIR/more-object-bound.rs:12:5
|
LL | foo::<A, B, dyn Trait<A = A, B = B>>(x)
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Trait<A = A, B = B>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Trait<A = A, B = B>`
|
note: required by a bound in `foo`
--> $DIR/more-object-bound.rs:18:8
Expand Down

0 comments on commit ba4a2f7

Please sign in to comment.