Skip to content

Commit 4dcb70b

Browse files
committed
Allow constraining opaque types during unsizing
1 parent 9889a6f commit 4dcb70b

File tree

7 files changed

+12
-60
lines changed

7 files changed

+12
-60
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12281228
let InferOk { obligations, .. } = self
12291229
.infcx
12301230
.at(&obligation.cause, obligation.param_env)
1231-
.eq(DefineOpaqueTypes::No, b, a)
1231+
.eq(DefineOpaqueTypes::Yes, b, a)
12321232
.map_err(|_| Unimplemented)?;
12331233

12341234
ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
@@ -1276,7 +1276,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12761276
let InferOk { obligations, .. } = self
12771277
.infcx
12781278
.at(&obligation.cause, obligation.param_env)
1279-
.eq(DefineOpaqueTypes::No, target, new_struct)
1279+
.eq(DefineOpaqueTypes::Yes, target, new_struct)
12801280
.map_err(|_| Unimplemented)?;
12811281
nested.extend(obligations);
12821282

@@ -1309,7 +1309,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13091309
let InferOk { mut obligations, .. } = self
13101310
.infcx
13111311
.at(&obligation.cause, obligation.param_env)
1312-
.eq(DefineOpaqueTypes::No, target, new_tuple)
1312+
.eq(DefineOpaqueTypes::Yes, target, new_tuple)
13131313
.map_err(|_| Unimplemented)?;
13141314

13151315
// Add a nested `T: Unsize<U>` predicate.

tests/ui/impl-trait/unsize_adt.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
//! Test that we do not allow unsizing `Foo<[Opaque; N]>` to `Foo<[Concrete]>`.
1+
//! Test that we allow unsizing `Foo<[Opaque; N]>` to `Foo<[Concrete]>`.
2+
3+
//@check-pass
24

35
struct Foo<T: ?Sized>(T);
46

57
fn hello() -> Foo<[impl Sized; 2]> {
68
if false {
79
let x = hello();
810
let _: &Foo<[i32]> = &x;
9-
//~^ ERROR: mismatched types
1011
}
1112
todo!()
1213
}

tests/ui/impl-trait/unsize_adt.stderr

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/ui/impl-trait/unsize_slice.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
//! Test that we do not allow unsizing `[Opaque; N]` to `[Concrete]`.
1+
//! Test that we allow unsizing `[Opaque; N]` to `[Concrete]`.
2+
3+
//@check-pass
24

35
fn hello() -> [impl Sized; 2] {
46
if false {
57
let x = hello();
68
let _: &[i32] = &x;
7-
//~^ ERROR: mismatched types
89
}
910
todo!()
1011
}

tests/ui/impl-trait/unsize_slice.stderr

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/ui/impl-trait/unsize_tuple.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
//! Test that we do not allow unsizing `([Opaque; N],)` to `([Concrete],)`.
1+
//! Test that we allow unsizing `([Opaque; N],)` to `([Concrete],)`.
2+
3+
//@check-pass
24

35
#![feature(unsized_tuple_coercion)]
46

57
fn hello() -> ([impl Sized; 2],) {
68
if false {
79
let x = hello();
810
let _: &([i32],) = &x;
9-
//~^ ERROR: mismatched types
1011
}
1112
todo!()
1213
}

tests/ui/impl-trait/unsize_tuple.stderr

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)