]> git.proxmox.com Git - rustc.git/blame - src/tools/rust-analyzer/crates/hir-ty/src/tests/incremental.rs
New upstream version 1.72.1+dfsg1
[rustc.git] / src / tools / rust-analyzer / crates / hir-ty / src / tests / incremental.rs
CommitLineData
064997fb 1use base_db::{fixture::WithFixture, SourceDatabaseExt};
fe692bf9 2use triomphe::Arc;
064997fb
FG
3
4use crate::{db::HirDatabase, test_db::TestDB};
5
6use super::visit_module;
7
8#[test]
9fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
10 let (mut db, pos) = TestDB::with_position(
11 "
12 //- /lib.rs
13 fn foo() -> i32 {
14 $01 + 1
15 }
16 ",
17 );
18 {
19 let events = db.log_executed(|| {
20 let module = db.module_for_file(pos.file_id);
21 let crate_def_map = module.def_map(&db);
22 visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
23 db.infer(def);
24 });
25 });
9c376795 26 assert!(format!("{events:?}").contains("infer"))
064997fb
FG
27 }
28
29 let new_text = "
30 fn foo() -> i32 {
31 1
32 +
33 1
34 }
fe692bf9 35 ";
064997fb 36
fe692bf9 37 db.set_file_text(pos.file_id, Arc::from(new_text));
064997fb
FG
38
39 {
40 let events = db.log_executed(|| {
41 let module = db.module_for_file(pos.file_id);
42 let crate_def_map = module.def_map(&db);
43 visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
44 db.infer(def);
45 });
46 });
9c376795 47 assert!(!format!("{events:?}").contains("infer"), "{events:#?}")
064997fb
FG
48 }
49}