Skip to content

Commit cf9ed0d

Browse files
committed
Auto merge of #101831 - compiler-errors:issue-75899, r=jackh726
Normalize struct field types in `confirm_builtin_unsize_candidate` Fixes #75899 --- edited to move the normalization into `confirm_builtin_unsize_candidate` instead of the coercion code.
2 parents df34db9 + 7893ca7 commit cf9ed0d

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -1039,9 +1039,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10391039
return Err(Unimplemented);
10401040
}
10411041

1042-
// Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`.
1043-
let source_tail = tail_field_ty.subst(tcx, substs_a);
1044-
let target_tail = tail_field_ty.subst(tcx, substs_b);
1042+
// Extract `TailField<T>` and `TailField<U>` from `Struct<T>` and `Struct<U>`,
1043+
// normalizing in the process, since `type_of` returns something directly from
1044+
// astconv (which means it's un-normalized).
1045+
let source_tail = normalize_with_depth_to(
1046+
self,
1047+
obligation.param_env,
1048+
obligation.cause.clone(),
1049+
obligation.recursion_depth + 1,
1050+
tail_field_ty.subst(tcx, substs_a),
1051+
&mut nested,
1052+
);
1053+
let target_tail = normalize_with_depth_to(
1054+
self,
1055+
obligation.param_env,
1056+
obligation.cause.clone(),
1057+
obligation.recursion_depth + 1,
1058+
tail_field_ty.subst(tcx, substs_b),
1059+
&mut nested,
1060+
);
10451061

10461062
// Check that the source struct with the target's
10471063
// unsizing parameters is equal to the target.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// check-pass
2+
3+
use std::fmt::Debug;
4+
use std::marker::PhantomData;
5+
6+
trait Foo {
7+
type Gat<'a>: ?Sized where Self: 'a;
8+
}
9+
10+
struct Bar<'a, T: Foo + 'a>(T::Gat<'a>);
11+
12+
struct Baz<T: ?Sized>(PhantomData<T>);
13+
14+
impl<T: ?Sized> Foo for Baz<T> {
15+
type Gat<'a> = T where Self: 'a;
16+
}
17+
18+
fn main() {
19+
let x = Bar::<'_, Baz<()>>(());
20+
let y: &Bar<'_, Baz<dyn Debug>> = &x;
21+
}

src/test/ui/unsized/issue-75899.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
3+
trait Trait {}
4+
impl<T> Trait for T {}
5+
6+
trait Noop {
7+
type Assoc: ?Sized;
8+
}
9+
impl<T: ?Sized> Noop for T {
10+
type Assoc = T;
11+
}
12+
13+
struct NoopNewtype<T: ?Sized + Noop>(T::Assoc);
14+
fn coerce_newtype<T: Trait>(x: &NoopNewtype<T>) -> &NoopNewtype<dyn Trait + '_> {
15+
x
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)