mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 14:01:51 +00:00
Allow constraining opaque types during unsizing
This commit is contained in:
parent
9889a6f5d3
commit
4dcb70b8cf
@ -1228,7 +1228,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
let InferOk { obligations, .. } = self
|
||||
.infcx
|
||||
.at(&obligation.cause, obligation.param_env)
|
||||
.eq(DefineOpaqueTypes::No, b, a)
|
||||
.eq(DefineOpaqueTypes::Yes, b, a)
|
||||
.map_err(|_| Unimplemented)?;
|
||||
|
||||
ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
|
||||
@ -1276,7 +1276,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
let InferOk { obligations, .. } = self
|
||||
.infcx
|
||||
.at(&obligation.cause, obligation.param_env)
|
||||
.eq(DefineOpaqueTypes::No, target, new_struct)
|
||||
.eq(DefineOpaqueTypes::Yes, target, new_struct)
|
||||
.map_err(|_| Unimplemented)?;
|
||||
nested.extend(obligations);
|
||||
|
||||
@ -1309,7 +1309,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
let InferOk { mut obligations, .. } = self
|
||||
.infcx
|
||||
.at(&obligation.cause, obligation.param_env)
|
||||
.eq(DefineOpaqueTypes::No, target, new_tuple)
|
||||
.eq(DefineOpaqueTypes::Yes, target, new_tuple)
|
||||
.map_err(|_| Unimplemented)?;
|
||||
|
||||
// Add a nested `T: Unsize<U>` predicate.
|
||||
|
@ -1,4 +1,6 @@
|
||||
//! Test that we do not allow unsizing `Foo<[Opaque; N]>` to `Foo<[Concrete]>`.
|
||||
//! Test that we allow unsizing `Foo<[Opaque; N]>` to `Foo<[Concrete]>`.
|
||||
|
||||
//@check-pass
|
||||
|
||||
struct Foo<T: ?Sized>(T);
|
||||
|
||||
@ -6,7 +8,6 @@ fn hello() -> Foo<[impl Sized; 2]> {
|
||||
if false {
|
||||
let x = hello();
|
||||
let _: &Foo<[i32]> = &x;
|
||||
//~^ ERROR: mismatched types
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/unsize_adt.rs:8:30
|
||||
|
|
||||
LL | fn hello() -> Foo<[impl Sized; 2]> {
|
||||
| ---------- the found opaque type
|
||||
...
|
||||
LL | let _: &Foo<[i32]> = &x;
|
||||
| ----------- ^^ expected `&Foo<[i32]>`, found `&Foo<[impl Sized; 2]>`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected reference `&Foo<[i32]>`
|
||||
found reference `&Foo<[impl Sized; 2]>`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
@ -1,10 +1,11 @@
|
||||
//! Test that we do not allow unsizing `[Opaque; N]` to `[Concrete]`.
|
||||
//! Test that we allow unsizing `[Opaque; N]` to `[Concrete]`.
|
||||
|
||||
//@check-pass
|
||||
|
||||
fn hello() -> [impl Sized; 2] {
|
||||
if false {
|
||||
let x = hello();
|
||||
let _: &[i32] = &x;
|
||||
//~^ ERROR: mismatched types
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/unsize_slice.rs:6:25
|
||||
|
|
||||
LL | fn hello() -> [impl Sized; 2] {
|
||||
| ---------- the found opaque type
|
||||
...
|
||||
LL | let _: &[i32] = &x;
|
||||
| ------ ^^ expected `&[i32]`, found `&[impl Sized; 2]`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected reference `&[i32]`
|
||||
found reference `&[impl Sized; 2]`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
@ -1,4 +1,6 @@
|
||||
//! Test that we do not allow unsizing `([Opaque; N],)` to `([Concrete],)`.
|
||||
//! Test that we allow unsizing `([Opaque; N],)` to `([Concrete],)`.
|
||||
|
||||
//@check-pass
|
||||
|
||||
#![feature(unsized_tuple_coercion)]
|
||||
|
||||
@ -6,7 +8,6 @@ fn hello() -> ([impl Sized; 2],) {
|
||||
if false {
|
||||
let x = hello();
|
||||
let _: &([i32],) = &x;
|
||||
//~^ ERROR: mismatched types
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/unsize_tuple.rs:8:28
|
||||
|
|
||||
LL | fn hello() -> ([impl Sized; 2],) {
|
||||
| ---------- the found opaque type
|
||||
...
|
||||
LL | let _: &([i32],) = &x;
|
||||
| --------- ^^ expected `&([i32],)`, found `&([impl Sized; 2],)`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected reference `&([i32],)`
|
||||
found reference `&([impl Sized; 2],)`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in New Issue
Block a user