diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index ba76b9c8dd5a0..252573e770c47 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -184,7 +184,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let unsize = self.commit_if_ok(|_| self.coerce_unsized(a, b)); match unsize { Ok(_) => { - debug!("coerce: unsize successful"); + debug!("coerce: unsize successful: {:?}", unsize); return unsize; } Err(TypeError::ObjectUnsafeCoercion(did)) => { @@ -603,6 +603,15 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { continue; } }; + + + let InferOk { value: trait_pred2, obligations: obls } = + self.normalize_associated_types_in_as_infer_ok(self.cause.span, trait_pred); + + debug!("coerce_unsized: normalized {:?} to {:?}; obls: {:?}", trait_pred, trait_pred2, obls); + let trait_pred = trait_pred2; + // coercion.obligations.extend(obls); + match selcx.select(&obligation.with(trait_pred)) { // Uncertain or unimplemented. Ok(None) => { diff --git a/src/test/ui/coercion/coerce-normalization.rs b/src/test/ui/coercion/coerce-normalization.rs new file mode 100644 index 0000000000000..3cddd1e880685 --- /dev/null +++ b/src/test/ui/coercion/coerce-normalization.rs @@ -0,0 +1,29 @@ +// check-pass + +trait Trait {} + +impl Trait for T0 {} + +impl Id for T1 { + type Assoc = T1; +} + +trait Id { + type Assoc: ?Sized; +} + +struct NewType(T2::Assoc); + +fn coerce_newtype_slice<'a, T3, const N: usize>(array: &'a NewType<[T3; N]>) -> &'a NewType<[T3]> { + array +} + +fn coerce_newtype_trait(tr: &NewType) -> &NewType { + tr +} + +fn main() { + let nt = NewType::<[i32; 1]>([0]); + coerce_newtype_slice(&nt); + coerce_newtype_trait(&nt); +}