-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #77303 - lcnr:const-evaluatable-TooGeneric, r=oli-obk…
…,varkor const evaluatable: improve `TooGeneric` handling Instead of emitting an error in `fulfill`, we now correctly stall on inference variables. As `const_eval_resolve` returns `ErrorHandled::TooGeneric` when encountering generic parameters on which we actually do want to error, we check for inference variables and eagerly emit an error if they don't exist, returning `ErrorHandled::Reported` instead. Also contains a small bugfix for `ConstEquate` where we previously only stalled on type variables. This is probably a leftover from when we did not yet support stalling on const inference variables. r? @oli-obk cc @varkor @eddyb
- Loading branch information
Showing
8 changed files
with
199 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 20 additions & 24 deletions
44
src/test/ui/const-generics/const_evaluatable_checked/cross_crate_predicate.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,50 @@ | ||
error: constant expression depends on a generic parameter | ||
error: unconstrained generic constant | ||
--> $DIR/cross_crate_predicate.rs:7:13 | ||
| | ||
LL | let _ = const_evaluatable_lib::test1::<T>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
::: $DIR/auxiliary/const_evaluatable_lib.rs:6:10 | ||
| | ||
LL | [u8; std::mem::size_of::<T>() - 1]: Sized, | ||
| ---------------------------- required by this bound in `test1` | ||
help: consider adding a `where` bound for this expression | ||
--> $DIR/auxiliary/const_evaluatable_lib.rs:6:10 | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
LL | [u8; std::mem::size_of::<T>() - 1]: Sized, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: constant expression depends on a generic parameter | ||
error: unconstrained generic constant | ||
--> $DIR/cross_crate_predicate.rs:7:13 | ||
| | ||
LL | let _ = const_evaluatable_lib::test1::<T>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
::: $DIR/auxiliary/const_evaluatable_lib.rs:4:27 | ||
| | ||
LL | pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1] | ||
| ---------------------------- required by this bound in `test1` | ||
help: consider adding a `where` bound for this expression | ||
--> $DIR/auxiliary/const_evaluatable_lib.rs:4:27 | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
LL | pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: constant expression depends on a generic parameter | ||
error: unconstrained generic constant | ||
--> $DIR/cross_crate_predicate.rs:7:13 | ||
| | ||
LL | let _ = const_evaluatable_lib::test1::<T>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
::: $DIR/auxiliary/const_evaluatable_lib.rs:6:10 | ||
| | ||
LL | [u8; std::mem::size_of::<T>() - 1]: Sized, | ||
| ---------------------------- required by this bound in `test1` | ||
help: consider adding a `where` bound for this expression | ||
--> $DIR/auxiliary/const_evaluatable_lib.rs:6:10 | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
LL | [u8; std::mem::size_of::<T>() - 1]: Sized, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: constant expression depends on a generic parameter | ||
error: unconstrained generic constant | ||
--> $DIR/cross_crate_predicate.rs:7:13 | ||
| | ||
LL | let _ = const_evaluatable_lib::test1::<T>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
::: $DIR/auxiliary/const_evaluatable_lib.rs:4:27 | ||
| | ||
LL | pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1] | ||
| ---------------------------- required by this bound in `test1` | ||
help: consider adding a `where` bound for this expression | ||
--> $DIR/auxiliary/const_evaluatable_lib.rs:4:27 | ||
| | ||
= note: this may fail depending on what value the parameter takes | ||
LL | pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
24 changes: 24 additions & 0 deletions
24
src/test/ui/const-generics/const_evaluatable_checked/infer-too-generic.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// run-pass | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::{mem, ptr}; | ||
|
||
fn split_first<T, const N: usize>(arr: [T; N]) -> (T, [T; N - 1]) | ||
where | ||
[T; N - 1]: Sized, | ||
{ | ||
let arr = mem::ManuallyDrop::new(arr); | ||
unsafe { | ||
let head = ptr::read(&arr[0]); | ||
let tail = ptr::read(&arr[1..] as *const [T] as *const [T; N - 1]); | ||
(head, tail) | ||
} | ||
} | ||
|
||
fn main() { | ||
let arr = [0, 1, 2, 3, 4]; | ||
let (head, tail) = split_first(arr); | ||
assert_eq!(head, 0); | ||
assert_eq!(tail, [1, 2, 3, 4]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters