Skip to content

Commit 68c5a02

Browse files
committed
Allow constraining opaque types during unsizing
1 parent fec98b3 commit 68c5a02

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

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

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

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