-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
check wf before const-evaluating #160237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
check wf before const-evaluating #160237
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1289,12 +1289,29 @@ where | |
| &mut self, | ||
| param_env: I::ParamEnv, | ||
| alias_const: ty::AliasConst<I>, | ||
| ) -> Result<Option<I::Const>, RerunNonErased> { | ||
| ) -> Result<(Option<I::Const>, Certainty), NoSolutionOrRerunNonErased> { | ||
| if self.typing_mode().is_erased_not_coherence() { | ||
| match self.opaque_accesses.rerun_always(RerunReason::EvaluateConst)? {} | ||
| } | ||
| let cx = self.cx(); | ||
| let certainty = if cx.features().generic_const_exprs() { | ||
| Certainty::Yes | ||
| } else { | ||
| let goal = Goal::new( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we definitely want a nice comment explaining why we do this :3 |
||
| cx, | ||
| param_env, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should prove this in an empty environment so that evaluating something with a |
||
| ty::ClauseKind::WellFormed(alias_const.to_const(cx, ty::IsRigid::Yes).into()), | ||
| ); | ||
| self.add_goal(GoalSource::AliasWellFormed, goal)?; | ||
| let certainty = self.try_evaluate_added_goals()?; | ||
|
|
||
| if matches!(certainty, Certainty::Maybe(_)) { | ||
| return Ok((None, certainty)); | ||
| } | ||
| certainty | ||
| }; | ||
|
|
||
| Ok(self.delegate.evaluate_const(param_env, alias_const)) | ||
| Ok((self.delegate.evaluate_const(param_env, alias_const), certainty)) | ||
| } | ||
|
|
||
| pub(super) fn evaluate_const_and_instantiate_projection_term( | ||
|
|
@@ -1305,11 +1322,11 @@ where | |
| alias_const: ty::AliasConst<I>, | ||
| ) -> QueryResultOrRerunNonErased<I> { | ||
| match self.evaluate_const(param_env, alias_const)? { | ||
| Some(evaluated) => { | ||
| (Some(evaluated), _) => { | ||
| self.eq(param_env, expected_term, evaluated.into())?; | ||
| self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) | ||
| } | ||
| None if self.cx().features().generic_const_args() => { | ||
| (None, certainty) if self.cx().features().generic_const_args() => { | ||
| // HACK(khyperia): calling `resolve_vars_if_possible` here shouldn't be necessary, | ||
| // `try_evaluate_const` calls `resolve_vars_if_possible` already. However, we want | ||
| // to check `has_non_region_infer` against the type with vars resolved (i.e. check | ||
|
|
@@ -1331,10 +1348,10 @@ where | |
| projection_term.to_term(self.cx(), ty::IsRigid::Yes), | ||
| expected_term, | ||
| )?; | ||
| self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) | ||
| self.evaluate_added_goals_and_make_canonical_response(certainty) | ||
| } | ||
| } | ||
| None => { | ||
| (None, _) => { | ||
| // Legacy behavior: always treat as ambiguous | ||
| self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //! Regression test for <https://github.com/rust-lang/rust/issues/156780>. | ||
| //@ compile-flags: -Znext-solver=globally | ||
| #![feature(min_generic_const_args)] | ||
| #![feature(generic_const_args)] | ||
| #![feature(generic_const_items)] | ||
| #![feature(macroless_generic_const_args)] | ||
|
|
||
| const ADD1<const N:usize>: usize = N + 1; | ||
| type const A<const N:usize>: usize = ADD1::<N>; | ||
| impl [(); A::<1f64>] {} //~ ERROR: type mismatch resolving `A<1f64> == _` [E0271] | ||
| //~| ERROR: cannot define inherent `impl` for primitive types [E0390] | ||
| //~^^ ERROR: the type `[(); A::<1f64>]` is not well-formed | ||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| error[E0271]: type mismatch resolving `A<1f64> == _` | ||
| --> $DIR/impl-block-type-const-type-mismatch.rs:10:1 | ||
| | | ||
| LL | impl [(); A::<1f64>] {} | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^ types differ | ||
|
|
||
| error: the type `[(); A::<1f64>]` is not well-formed | ||
| --> $DIR/impl-block-type-const-type-mismatch.rs:10:6 | ||
| | | ||
| LL | impl [(); A::<1f64>] {} | ||
| | ^^^^^^^^^^^^^^^ | ||
|
|
||
| error[E0390]: cannot define inherent `impl` for primitive types | ||
| --> $DIR/impl-block-type-const-type-mismatch.rs:10:1 | ||
| | | ||
| LL | impl [(); A::<1f64>] {} | ||
| | ^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: consider using an extension trait instead | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0271, E0390. | ||
| For more information about an error, try `rustc --explain E0271`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| //! Regression test for <https://github.com/rust-lang/rust/issues/154805>. | ||
| //@ compile-flags: -Znext-solver=globally | ||
| #![feature(min_generic_const_args)] | ||
| #![feature(generic_const_args)] | ||
| #![feature(generic_const_items)] | ||
|
|
||
| const ADD1<const N: usize>: usize = N + 1; | ||
| type const ONE: usize = ADD1::<core::direct_const_arg!(b"")>; //~ ERROR type mismatch resolving | ||
| //~| ERROR the constant `*b""` is not of type `usize` | ||
| //~| ERROR the constant `ADD1::<*b"">` is not of type `usize` | ||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| error[E0271]: type mismatch resolving `ADD1<*b""> == _` | ||
| --> $DIR/type-const-arg-type-mismatch-1.rs:8:1 | ||
| | | ||
| LL | type const ONE: usize = ADD1::<core::direct_const_arg!(b"")>; | ||
| | ^^^^^^^^^^^^^^^^^^^^^ types differ | ||
|
|
||
| error: the constant `*b""` is not of type `usize` | ||
| --> $DIR/type-const-arg-type-mismatch-1.rs:8:1 | ||
| | | ||
| LL | type const ONE: usize = ADD1::<core::direct_const_arg!(b"")>; | ||
| | ^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `[u8; 0]` | ||
| | | ||
| note: required by a const generic parameter in `ADD1` | ||
| --> $DIR/type-const-arg-type-mismatch-1.rs:7:12 | ||
| | | ||
| LL | const ADD1<const N: usize>: usize = N + 1; | ||
| | ^^^^^^^^^^^^^^ required by this const generic parameter in `ADD1` | ||
|
|
||
| error: the constant `ADD1::<*b"">` is not of type `usize` | ||
| --> $DIR/type-const-arg-type-mismatch-1.rs:8:1 | ||
| | | ||
| LL | type const ONE: usize = ADD1::<core::direct_const_arg!(b"")>; | ||
| | ^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found a different `usize` | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0271`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| //! Regression test for <https://github.com/rust-lang/rust/issues/154805>. | ||
| //@ compile-flags: -Znext-solver=globally | ||
| #![feature(min_generic_const_args)] | ||
| #![feature(macroless_generic_const_args)] | ||
| #![feature(generic_const_args)] | ||
| #![feature(generic_const_items)] | ||
|
|
||
| const ADD1<const N: usize>: usize = N + 1; | ||
| type const ONE: usize = ADD1::<b"">; //~ ERROR type mismatch resolving | ||
| //~| ERROR the constant `*b""` is not of type `usize` | ||
| //~| ERROR the constant `ADD1::<*b"">` is not of type `usize` | ||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| error[E0271]: type mismatch resolving `ADD1<*b""> == _` | ||
| --> $DIR/type-const-arg-type-mismatch-2.rs:9:1 | ||
| | | ||
| LL | type const ONE: usize = ADD1::<b"">; | ||
| | ^^^^^^^^^^^^^^^^^^^^^ types differ | ||
|
|
||
| error: the constant `*b""` is not of type `usize` | ||
| --> $DIR/type-const-arg-type-mismatch-2.rs:9:1 | ||
| | | ||
| LL | type const ONE: usize = ADD1::<b"">; | ||
| | ^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `[u8; 0]` | ||
| | | ||
| note: required by a const generic parameter in `ADD1` | ||
| --> $DIR/type-const-arg-type-mismatch-2.rs:8:12 | ||
| | | ||
| LL | const ADD1<const N: usize>: usize = N + 1; | ||
| | ^^^^^^^^^^^^^^ required by this const generic parameter in `ADD1` | ||
|
|
||
| error: the constant `ADD1::<*b"">` is not of type `usize` | ||
| --> $DIR/type-const-arg-type-mismatch-2.rs:9:1 | ||
| | | ||
| LL | type const ONE: usize = ADD1::<b"">; | ||
| | ^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found a different `usize` | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0271`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GCE is such a pain lol. It makes sense that this would be necessary though. One of the reasons GCE is a dead feature is because we can't do this change for it and we need to do this change if we're going to stabilize something 😅