Skip to content

Commit bacebdf

Browse files
committed
Allow constraining opaque types during unsizing
1 parent 921645c commit bacebdf

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
@@ -1267,7 +1267,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12671267
let InferOk { obligations, .. } = self
12681268
.infcx
12691269
.at(&obligation.cause, obligation.param_env)
1270-
.eq(DefineOpaqueTypes::No, b, a)
1270+
.eq(DefineOpaqueTypes::Yes, b, a)
12711271
.map_err(|_| Unimplemented)?;
12721272

12731273
ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
@@ -1315,7 +1315,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13151315
let InferOk { obligations, .. } = self
13161316
.infcx
13171317
.at(&obligation.cause, obligation.param_env)
1318-
.eq(DefineOpaqueTypes::No, target, new_struct)
1318+
.eq(DefineOpaqueTypes::Yes, target, new_struct)
13191319
.map_err(|_| Unimplemented)?;
13201320
nested.extend(obligations);
13211321

@@ -1348,7 +1348,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13481348
let InferOk { mut obligations, .. } = self
13491349
.infcx
13501350
.at(&obligation.cause, obligation.param_env)
1351-
.eq(DefineOpaqueTypes::No, target, new_tuple)
1351+
.eq(DefineOpaqueTypes::Yes, target, new_tuple)
13521352
.map_err(|_| Unimplemented)?;
13531353

13541354
// 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)