mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-04 18:58:41 +00:00
Merge pull request #19975 from davidbarsky/davidbarsky/test-trait-solve-invalidation
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
hir-ty: test incremental trait solving
This commit is contained in:
commit
5b2c8bc9ae
1 changed files with 87 additions and 1 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue