mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-25 11:17:13 +00:00
hir-ty: test (the absence of) incremental trait solving
This commit is contained in:
parent
f7b7db8b8c
commit
210c71eac5
@ -1,5 +1,5 @@
|
||||
use base_db::SourceDatabase;
|
||||
use hir_def::ModuleDefId;
|
||||
use hir_def::{DefWithBodyId, ModuleDefId};
|
||||
use test_fixture::WithFixture;
|
||||
|
||||
use crate::{db::HirDatabase, test_db::TestDB};
|
||||
@ -359,3 +359,89 @@ impl SomeStruct {
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_struct_invalidates_trait_solve() {
|
||||
let (mut db, file_id) = TestDB::with_single_file(
|
||||
"
|
||||
//- /main.rs crate:main
|
||||
struct SomeStruct;
|
||||
|
||||
trait Trait<T> {
|
||||
fn method(&self) -> T;
|
||||
}
|
||||
impl Trait<u32> for SomeStruct {}
|
||||
|
||||
fn main() {
|
||||
let s = SomeStruct;
|
||||
s.method();
|
||||
s.$0
|
||||
}",
|
||||
);
|
||||
|
||||
{
|
||||
let events = db.log_executed(|| {
|
||||
let module = db.module_for_file(file_id.file_id(&db));
|
||||
let crate_def_map = module.def_map(&db);
|
||||
let mut defs: Vec<DefWithBodyId> = vec![];
|
||||
visit_module(&db, crate_def_map, module.local_id, &mut |it| {
|
||||
let def = match it {
|
||||
ModuleDefId::FunctionId(it) => it.into(),
|
||||
ModuleDefId::EnumVariantId(it) => it.into(),
|
||||
ModuleDefId::ConstId(it) => it.into(),
|
||||
ModuleDefId::StaticId(it) => it.into(),
|
||||
_ => return,
|
||||
};
|
||||
defs.push(def);
|
||||
});
|
||||
|
||||
for def in defs {
|
||||
let _inference_result = db.infer(def);
|
||||
}
|
||||
});
|
||||
assert!(format!("{events:?}").contains("trait_solve_shim"))
|
||||
}
|
||||
|
||||
let new_text = "
|
||||
//- /main.rs crate:main
|
||||
struct AnotherStruct;
|
||||
|
||||
struct SomeStruct;
|
||||
|
||||
trait Trait<T> {
|
||||
fn method(&self) -> T;
|
||||
}
|
||||
impl Trait<u32> for SomeStruct {}
|
||||
|
||||
fn main() {
|
||||
let s = SomeStruct;
|
||||
s.method();
|
||||
s.$0
|
||||
}";
|
||||
|
||||
db.set_file_text(file_id.file_id(&db), new_text);
|
||||
|
||||
{
|
||||
let events = db.log_executed(|| {
|
||||
let module = db.module_for_file(file_id.file_id(&db));
|
||||
let crate_def_map = module.def_map(&db);
|
||||
let mut defs: Vec<DefWithBodyId> = vec![];
|
||||
|
||||
visit_module(&db, crate_def_map, module.local_id, &mut |it| {
|
||||
let def = match it {
|
||||
ModuleDefId::FunctionId(it) => it.into(),
|
||||
ModuleDefId::EnumVariantId(it) => it.into(),
|
||||
ModuleDefId::ConstId(it) => it.into(),
|
||||
ModuleDefId::StaticId(it) => it.into(),
|
||||
_ => return,
|
||||
};
|
||||
defs.push(def);
|
||||
});
|
||||
|
||||
for def in defs {
|
||||
let _inference_result = db.infer(def);
|
||||
}
|
||||
});
|
||||
assert!(format!("{events:?}").contains("trait_solve_shim"))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user