Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/consteval/tests.rs')
-rw-r--r--crates/hir-ty/src/consteval/tests.rs47
1 files changed, 27 insertions, 20 deletions
diff --git a/crates/hir-ty/src/consteval/tests.rs b/crates/hir-ty/src/consteval/tests.rs
index 1586846bbe..f1aa06d488 100644
--- a/crates/hir-ty/src/consteval/tests.rs
+++ b/crates/hir-ty/src/consteval/tests.rs
@@ -1,17 +1,23 @@
use base_db::RootQueryDb;
-use chalk_ir::Substitution;
use hir_def::db::DefDatabase;
use hir_expand::EditionedFileId;
use rustc_apfloat::{
Float,
ieee::{Half as f16, Quad as f128},
};
+use rustc_type_ir::inherent::IntoKind;
use test_fixture::WithFixture;
use test_utils::skip_slow_tests;
use crate::{
- Const, ConstScalar, Interner, MemoryMap, consteval::try_const_usize, db::HirDatabase,
- display::DisplayTarget, mir::pad16, setup_tracing, test_db::TestDB,
+ MemoryMap,
+ consteval::try_const_usize,
+ db::HirDatabase,
+ display::DisplayTarget,
+ mir::pad16,
+ next_solver::{Const, ConstBytes, ConstKind, DbInterner, GenericArgs},
+ setup_tracing,
+ test_db::TestDB,
};
use super::{
@@ -21,7 +27,7 @@ use super::{
mod intrinsics;
-fn simplify(e: ConstEvalError) -> ConstEvalError {
+fn simplify(e: ConstEvalError<'_>) -> ConstEvalError<'_> {
match e {
ConstEvalError::MirEvalError(MirEvalError::InFunction(e, _)) => {
simplify(ConstEvalError::MirEvalError(*e))
@@ -33,10 +39,10 @@ fn simplify(e: ConstEvalError) -> ConstEvalError {
#[track_caller]
fn check_fail(
#[rust_analyzer::rust_fixture] ra_fixture: &str,
- error: impl FnOnce(ConstEvalError) -> bool,
+ error: impl FnOnce(ConstEvalError<'_>) -> bool,
) {
let (db, file_id) = TestDB::with_single_file(ra_fixture);
- salsa::attach(&db, || match eval_goal(&db, file_id) {
+ crate::attach_db(&db, || match eval_goal(&db, file_id) {
Ok(_) => panic!("Expected fail, but it succeeded"),
Err(e) => {
assert!(error(simplify(e.clone())), "Actual error was: {}", pretty_print_err(e, &db))
@@ -79,7 +85,7 @@ fn check_answer(
check: impl FnOnce(&[u8], &MemoryMap<'_>),
) {
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
- salsa::attach(&db, || {
+ crate::attach_db(&db, || {
let file_id = *file_ids.last().unwrap();
let r = match eval_goal(&db, file_id) {
Ok(t) => t,
@@ -88,19 +94,17 @@ fn check_answer(
panic!("Error in evaluating goal: {err}");
}
};
- match &r.data(Interner).value {
- chalk_ir::ConstValue::Concrete(c) => match &c.interned {
- ConstScalar::Bytes(b, mm) => {
- check(b, mm);
- }
- x => panic!("Expected number but found {x:?}"),
- },
- _ => panic!("result of const eval wasn't a concrete const"),
+ match r.kind() {
+ ConstKind::Value(value) => {
+ let ConstBytes { memory, memory_map } = value.value.inner();
+ check(memory, memory_map);
+ }
+ _ => panic!("Expected number but found {r:?}"),
}
});
}
-fn pretty_print_err(e: ConstEvalError, db: &TestDB) -> String {
+fn pretty_print_err(e: ConstEvalError<'_>, db: &TestDB) -> String {
let mut err = String::new();
let span_formatter = |file, range| format!("{file:?} {range:?}");
let display_target =
@@ -117,8 +121,9 @@ fn pretty_print_err(e: ConstEvalError, db: &TestDB) -> String {
err
}
-fn eval_goal(db: &TestDB, file_id: EditionedFileId) -> Result<Const, ConstEvalError> {
+fn eval_goal(db: &TestDB, file_id: EditionedFileId) -> Result<Const<'_>, ConstEvalError<'_>> {
let _tracing = setup_tracing();
+ let interner = DbInterner::new_with(db, None, None);
let module_id = db.module_for_file(file_id.file_id(db));
let def_map = module_id.def_map(db);
let scope = &def_map[module_id.local_id].scope;
@@ -137,7 +142,7 @@ fn eval_goal(db: &TestDB, file_id: EditionedFileId) -> Result<Const, ConstEvalEr
_ => None,
})
.expect("No const named GOAL found in the test");
- db.const_eval(const_id.into(), Substitution::empty(Interner), None)
+ db.const_eval(const_id.into(), GenericArgs::new_from_iter(interner, []), None)
}
#[test]
@@ -2506,8 +2511,10 @@ fn enums() {
const GOAL: E = E::A;
"#,
);
- let r = eval_goal(&db, file_id).unwrap();
- assert_eq!(try_const_usize(&db, &r), Some(1));
+ crate::attach_db(&db, || {
+ let r = eval_goal(&db, file_id).unwrap();
+ assert_eq!(try_const_usize(&db, r), Some(1));
+ })
}
#[test]