mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 12:18:33 +00:00
Allow defining opaque types when checking const equality bounds
This commit is contained in:
parent
29fba9f994
commit
0183d92df0
@ -572,7 +572,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
|||||||
if let Ok(new_obligations) = infcx
|
if let Ok(new_obligations) = infcx
|
||||||
.at(&obligation.cause, obligation.param_env)
|
.at(&obligation.cause, obligation.param_env)
|
||||||
.trace(c1, c2)
|
.trace(c1, c2)
|
||||||
.eq(DefineOpaqueTypes::No, a.args, b.args)
|
// Can define opaque types as this is only reachable with
|
||||||
|
// `generic_const_exprs`
|
||||||
|
.eq(DefineOpaqueTypes::Yes, a.args, b.args)
|
||||||
{
|
{
|
||||||
return ProcessResult::Changed(mk_pending(
|
return ProcessResult::Changed(mk_pending(
|
||||||
new_obligations.into_obligations(),
|
new_obligations.into_obligations(),
|
||||||
@ -583,7 +585,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
|||||||
(_, _) => {
|
(_, _) => {
|
||||||
if let Ok(new_obligations) = infcx
|
if let Ok(new_obligations) = infcx
|
||||||
.at(&obligation.cause, obligation.param_env)
|
.at(&obligation.cause, obligation.param_env)
|
||||||
.eq(DefineOpaqueTypes::No, c1, c2)
|
// Can define opaque types as this is only reachable with
|
||||||
|
// `generic_const_exprs`
|
||||||
|
.eq(DefineOpaqueTypes::Yes, c1, c2)
|
||||||
{
|
{
|
||||||
return ProcessResult::Changed(mk_pending(
|
return ProcessResult::Changed(mk_pending(
|
||||||
new_obligations.into_obligations(),
|
new_obligations.into_obligations(),
|
||||||
@ -624,7 +628,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
|||||||
match (evaluate(c1), evaluate(c2)) {
|
match (evaluate(c1), evaluate(c2)) {
|
||||||
(Ok(c1), Ok(c2)) => {
|
(Ok(c1), Ok(c2)) => {
|
||||||
match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
|
match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
|
||||||
DefineOpaqueTypes::No,
|
// Can define opaque types as this is only reachable with
|
||||||
|
// `generic_const_exprs`
|
||||||
|
DefineOpaqueTypes::Yes,
|
||||||
c1,
|
c1,
|
||||||
c2,
|
c2,
|
||||||
) {
|
) {
|
||||||
|
@ -906,7 +906,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
.infcx
|
.infcx
|
||||||
.at(&obligation.cause, obligation.param_env)
|
.at(&obligation.cause, obligation.param_env)
|
||||||
.trace(c1, c2)
|
.trace(c1, c2)
|
||||||
.eq(DefineOpaqueTypes::No, a.args, b.args)
|
// Can define opaque types as this is only reachable with
|
||||||
|
// `generic_const_exprs`
|
||||||
|
.eq(DefineOpaqueTypes::Yes, a.args, b.args)
|
||||||
{
|
{
|
||||||
return self.evaluate_predicates_recursively(
|
return self.evaluate_predicates_recursively(
|
||||||
previous_stack,
|
previous_stack,
|
||||||
@ -919,7 +921,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
if let Ok(InferOk { obligations, value: () }) = self
|
if let Ok(InferOk { obligations, value: () }) = self
|
||||||
.infcx
|
.infcx
|
||||||
.at(&obligation.cause, obligation.param_env)
|
.at(&obligation.cause, obligation.param_env)
|
||||||
.eq(DefineOpaqueTypes::No, c1, c2)
|
// Can define opaque types as this is only reachable with
|
||||||
|
// `generic_const_exprs`
|
||||||
|
.eq(DefineOpaqueTypes::Yes, c1, c2)
|
||||||
{
|
{
|
||||||
return self.evaluate_predicates_recursively(
|
return self.evaluate_predicates_recursively(
|
||||||
previous_stack,
|
previous_stack,
|
||||||
@ -949,7 +953,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
match (evaluate(c1), evaluate(c2)) {
|
match (evaluate(c1), evaluate(c2)) {
|
||||||
(Ok(c1), Ok(c2)) => {
|
(Ok(c1), Ok(c2)) => {
|
||||||
match self.infcx.at(&obligation.cause, obligation.param_env).eq(
|
match self.infcx.at(&obligation.cause, obligation.param_env).eq(
|
||||||
DefineOpaqueTypes::No,
|
// Can define opaque types as this is only reachable with
|
||||||
|
// `generic_const_exprs`
|
||||||
|
DefineOpaqueTypes::Yes,
|
||||||
c1,
|
c1,
|
||||||
c2,
|
c2,
|
||||||
) {
|
) {
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
type Foo = impl Sized;
|
type Foo = impl Sized;
|
||||||
//~^ ERROR: cycle detected
|
|
||||||
|
|
||||||
fn with_bound<const N: usize>() -> Foo
|
fn with_bound<const N: usize>() -> Foo
|
||||||
where
|
where
|
||||||
[u8; (N / 2) as usize]: Sized,
|
[u8; (N / 2) as usize]: Sized,
|
||||||
{
|
{
|
||||||
let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
|
let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
|
||||||
//~^ ERROR: mismatched types
|
//~^ ERROR mismatched types
|
||||||
|
//~| ERROR non-primitive cast: `usize` as `Foo`
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/opaque_type.rs:11:17
|
--> $DIR/opaque_type.rs:10:17
|
||||||
|
|
|
|
||||||
LL | type Foo = impl Sized;
|
LL | type Foo = impl Sized;
|
||||||
| ---------- the found opaque type
|
| ---------- the found opaque type
|
||||||
@ -11,7 +11,7 @@ LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
|
|||||||
found opaque type `Foo`
|
found opaque type `Foo`
|
||||||
|
|
||||||
error[E0605]: non-primitive cast: `usize` as `Foo`
|
error[E0605]: non-primitive cast: `usize` as `Foo`
|
||||||
--> $DIR/opaque_type.rs:11:17
|
--> $DIR/opaque_type.rs:10:17
|
||||||
|
|
|
|
||||||
LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
|
LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
|
||||||
| ^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
|
| ^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
|
||||||
|
Loading…
Reference in New Issue
Block a user