Skip to content

Commit e8ad0c0

Browse files
authored
Merge pull request #18906 from Veykril/push-upuxsyovskmt
feat: Re-implement rust string highlighting via tool attribute
2 parents 897f7e5 + bf669da commit e8ad0c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+386
-173
lines changed

crates/hir-def/src/body/scope.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ mod tests {
345345
}
346346
}
347347

348-
fn do_check(ra_fixture: &str, expected: &[&str]) {
348+
fn do_check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected: &[&str]) {
349349
let (offset, code) = extract_offset(ra_fixture);
350350
let code = {
351351
let mut buf = String::new();
@@ -509,7 +509,7 @@ fn foo() {
509509
);
510510
}
511511

512-
fn do_check_local_name(ra_fixture: &str, expected_offset: u32) {
512+
fn do_check_local_name(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected_offset: u32) {
513513
let (db, position) = TestDB::with_position(ra_fixture);
514514
let file_id = position.file_id;
515515
let offset = position.offset;

crates/hir-def/src/body/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{test_db::TestDB, ModuleDefId};
77

88
use super::*;
99

10-
fn lower(ra_fixture: &str) -> (TestDB, Arc<Body>, DefWithBodyId) {
10+
fn lower(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (TestDB, Arc<Body>, DefWithBodyId) {
1111
let db = TestDB::with_files(ra_fixture);
1212

1313
let krate = db.fetch_test_crate();
@@ -27,22 +27,22 @@ fn lower(ra_fixture: &str) -> (TestDB, Arc<Body>, DefWithBodyId) {
2727
(db, body, fn_def)
2828
}
2929

30-
fn def_map_at(ra_fixture: &str) -> String {
30+
fn def_map_at(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String {
3131
let (db, position) = TestDB::with_position(ra_fixture);
3232

3333
let module = db.module_at_position(position);
3434
module.def_map(&db).dump(&db)
3535
}
3636

37-
fn check_block_scopes_at(ra_fixture: &str, expect: Expect) {
37+
fn check_block_scopes_at(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
3838
let (db, position) = TestDB::with_position(ra_fixture);
3939

4040
let module = db.module_at_position(position);
4141
let actual = module.def_map(&db).dump_block_scopes(&db);
4242
expect.assert_eq(&actual);
4343
}
4444

45-
fn check_at(ra_fixture: &str, expect: Expect) {
45+
fn check_at(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
4646
let actual = def_map_at(ra_fixture);
4747
expect.assert_eq(&actual);
4848
}

crates/hir-def/src/find_path.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ mod tests {
665665
/// module the cursor is in.
666666
#[track_caller]
667667
fn check_found_path_(
668-
ra_fixture: &str,
668+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
669669
path: &str,
670670
prefer_prelude: bool,
671671
prefer_absolute: bool,
@@ -727,19 +727,35 @@ mod tests {
727727
expect.assert_eq(&res);
728728
}
729729

730-
fn check_found_path(ra_fixture: &str, path: &str, expect: Expect) {
730+
fn check_found_path(
731+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
732+
path: &str,
733+
expect: Expect,
734+
) {
731735
check_found_path_(ra_fixture, path, false, false, false, expect);
732736
}
733737

734-
fn check_found_path_prelude(ra_fixture: &str, path: &str, expect: Expect) {
738+
fn check_found_path_prelude(
739+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
740+
path: &str,
741+
expect: Expect,
742+
) {
735743
check_found_path_(ra_fixture, path, true, false, false, expect);
736744
}
737745

738-
fn check_found_path_absolute(ra_fixture: &str, path: &str, expect: Expect) {
746+
fn check_found_path_absolute(
747+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
748+
path: &str,
749+
expect: Expect,
750+
) {
739751
check_found_path_(ra_fixture, path, false, true, false, expect);
740752
}
741753

742-
fn check_found_path_prefer_no_std(ra_fixture: &str, path: &str, expect: Expect) {
754+
fn check_found_path_prefer_no_std(
755+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
756+
path: &str,
757+
expect: Expect,
758+
) {
743759
check_found_path_(ra_fixture, path, false, false, true, expect);
744760
}
745761

crates/hir-def/src/import_map.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,12 @@ mod tests {
509509
}
510510
}
511511

512-
fn check_search(ra_fixture: &str, crate_name: &str, query: Query, expect: Expect) {
512+
fn check_search(
513+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
514+
crate_name: &str,
515+
query: Query,
516+
expect: Expect,
517+
) {
513518
let db = TestDB::with_files(ra_fixture);
514519
let crate_graph = db.crate_graph();
515520
let krate = crate_graph
@@ -587,7 +592,7 @@ mod tests {
587592
))
588593
}
589594

590-
fn check(ra_fixture: &str, expect: Expect) {
595+
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
591596
let db = TestDB::with_files(ra_fixture);
592597
let crate_graph = db.crate_graph();
593598

crates/hir-def/src/item_tree/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use test_fixture::WithFixture;
44

55
use crate::{db::DefDatabase, test_db::TestDB};
66

7-
fn check(ra_fixture: &str, expect: Expect) {
7+
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
88
let (db, file_id) = TestDB::with_single_file(ra_fixture);
99
let item_tree = db.file_item_tree(file_id.into());
1010
let pretty = item_tree.pretty_print(&db, Edition::CURRENT);

crates/hir-def/src/macro_expansion_tests/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::{
4747
};
4848

4949
#[track_caller]
50-
fn check_errors(ra_fixture: &str, expect: Expect) {
50+
fn check_errors(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
5151
let db = TestDB::with_files(ra_fixture);
5252
let krate = db.fetch_test_crate();
5353
let def_map = db.crate_def_map(krate);
@@ -77,7 +77,7 @@ fn check_errors(ra_fixture: &str, expect: Expect) {
7777
}
7878

7979
#[track_caller]
80-
fn check(ra_fixture: &str, mut expect: Expect) {
80+
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, mut expect: Expect) {
8181
let extra_proc_macros = vec![(
8282
r#"
8383
#[proc_macro_attribute]

crates/hir-def/src/nameres/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ use triomphe::Arc;
1111

1212
use crate::{db::DefDatabase, nameres::DefMap, test_db::TestDB};
1313

14-
fn compute_crate_def_map(ra_fixture: &str) -> Arc<DefMap> {
14+
fn compute_crate_def_map(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> Arc<DefMap> {
1515
let db = TestDB::with_files(ra_fixture);
1616
let krate = db.fetch_test_crate();
1717
db.crate_def_map(krate)
1818
}
1919

20-
fn render_crate_def_map(ra_fixture: &str) -> String {
20+
fn render_crate_def_map(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String {
2121
let db = TestDB::with_files(ra_fixture);
2222
let krate = db.fetch_test_crate();
2323
db.crate_def_map(krate).dump(&db)
2424
}
2525

26-
fn check(ra_fixture: &str, expect: Expect) {
26+
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
2727
let actual = render_crate_def_map(ra_fixture);
2828
expect.assert_eq(&actual);
2929
}

crates/hir-expand/src/fixup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ mod tests {
532532
}
533533

534534
#[track_caller]
535-
fn check(ra_fixture: &str, mut expect: Expect) {
535+
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, mut expect: Expect) {
536536
let parsed = syntax::SourceFile::parse(ra_fixture, span::Edition::CURRENT);
537537
let span_map = SpanMap::RealSpanMap(Arc::new(RealSpanMap::absolute(EditionedFileId::new(
538538
FileId::from_raw(0),

crates/hir-ty/src/consteval/tests.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ fn simplify(e: ConstEvalError) -> ConstEvalError {
3131
}
3232

3333
#[track_caller]
34-
fn check_fail(ra_fixture: &str, error: impl FnOnce(ConstEvalError) -> bool) {
34+
fn check_fail(
35+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
36+
error: impl FnOnce(ConstEvalError) -> bool,
37+
) {
3538
let (db, file_id) = TestDB::with_single_file(ra_fixture);
3639
match eval_goal(&db, file_id) {
3740
Ok(_) => panic!("Expected fail, but it succeeded"),
@@ -42,7 +45,7 @@ fn check_fail(ra_fixture: &str, error: impl FnOnce(ConstEvalError) -> bool) {
4245
}
4346

4447
#[track_caller]
45-
fn check_number(ra_fixture: &str, answer: i128) {
48+
fn check_number(#[rust_analyzer::rust_fixture] ra_fixture: &str, answer: i128) {
4649
check_answer(ra_fixture, |b, _| {
4750
assert_eq!(
4851
b,
@@ -54,7 +57,7 @@ fn check_number(ra_fixture: &str, answer: i128) {
5457
}
5558

5659
#[track_caller]
57-
fn check_str(ra_fixture: &str, answer: &str) {
60+
fn check_str(#[rust_analyzer::rust_fixture] ra_fixture: &str, answer: &str) {
5861
check_answer(ra_fixture, |b, mm| {
5962
let addr = usize::from_le_bytes(b[0..b.len() / 2].try_into().unwrap());
6063
let size = usize::from_le_bytes(b[b.len() / 2..].try_into().unwrap());
@@ -71,7 +74,10 @@ fn check_str(ra_fixture: &str, answer: &str) {
7174
}
7275

7376
#[track_caller]
74-
fn check_answer(ra_fixture: &str, check: impl FnOnce(&[u8], &MemoryMap)) {
77+
fn check_answer(
78+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
79+
check: impl FnOnce(&[u8], &MemoryMap),
80+
) {
7581
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
7682
let file_id = *file_ids.last().unwrap();
7783
let r = match eval_goal(&db, file_id) {

crates/hir-ty/src/dyn_compatibility/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum DynCompatibilityViolationKind {
2626
}
2727

2828
fn check_dyn_compatibility<'a>(
29-
ra_fixture: &str,
29+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
3030
expected: impl IntoIterator<Item = (&'a str, Vec<DynCompatibilityViolationKind>)>,
3131
) {
3232
let mut expected: FxHashMap<_, _> =

crates/hir-ty/src/layout/tests.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ fn current_machine_data_layout() -> String {
2525
.unwrap()
2626
}
2727

28-
fn eval_goal(ra_fixture: &str, minicore: &str) -> Result<Arc<Layout>, LayoutError> {
28+
fn eval_goal(
29+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
30+
minicore: &str,
31+
) -> Result<Arc<Layout>, LayoutError> {
2932
let target_data_layout = current_machine_data_layout();
3033
let ra_fixture = format!(
3134
"//- target_data_layout: {target_data_layout}\n{minicore}//- /main.rs crate:test\n{ra_fixture}",
@@ -81,7 +84,10 @@ fn eval_goal(ra_fixture: &str, minicore: &str) -> Result<Arc<Layout>, LayoutErro
8184
}
8285

8386
/// A version of `eval_goal` for types that can not be expressed in ADTs, like closures and `impl Trait`
84-
fn eval_expr(ra_fixture: &str, minicore: &str) -> Result<Arc<Layout>, LayoutError> {
87+
fn eval_expr(
88+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
89+
minicore: &str,
90+
) -> Result<Arc<Layout>, LayoutError> {
8591
let target_data_layout = current_machine_data_layout();
8692
let ra_fixture = format!(
8793
"//- target_data_layout: {target_data_layout}\n{minicore}//- /main.rs crate:test\nfn main(){{let goal = {{{ra_fixture}}};}}",
@@ -114,21 +120,31 @@ fn eval_expr(ra_fixture: &str, minicore: &str) -> Result<Arc<Layout>, LayoutErro
114120
}
115121

116122
#[track_caller]
117-
fn check_size_and_align(ra_fixture: &str, minicore: &str, size: u64, align: u64) {
123+
fn check_size_and_align(
124+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
125+
minicore: &str,
126+
size: u64,
127+
align: u64,
128+
) {
118129
let l = eval_goal(ra_fixture, minicore).unwrap();
119130
assert_eq!(l.size.bytes(), size, "size mismatch");
120131
assert_eq!(l.align.abi.bytes(), align, "align mismatch");
121132
}
122133

123134
#[track_caller]
124-
fn check_size_and_align_expr(ra_fixture: &str, minicore: &str, size: u64, align: u64) {
135+
fn check_size_and_align_expr(
136+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
137+
minicore: &str,
138+
size: u64,
139+
align: u64,
140+
) {
125141
let l = eval_expr(ra_fixture, minicore).unwrap();
126142
assert_eq!(l.size.bytes(), size, "size mismatch");
127143
assert_eq!(l.align.abi.bytes(), align, "align mismatch");
128144
}
129145

130146
#[track_caller]
131-
fn check_fail(ra_fixture: &str, e: LayoutError) {
147+
fn check_fail(#[rust_analyzer::rust_fixture] ra_fixture: &str, e: LayoutError) {
132148
let r = eval_goal(ra_fixture, "");
133149
assert_eq!(r, Err(e));
134150
}

crates/hir-ty/src/mir/eval/tests.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ fn eval_main(db: &TestDB, file_id: EditionedFileId) -> Result<(String, String),
3737
Ok((output.stdout().into_owned(), output.stderr().into_owned()))
3838
}
3939

40-
fn check_pass(ra_fixture: &str) {
40+
fn check_pass(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
4141
check_pass_and_stdio(ra_fixture, "", "");
4242
}
4343

44-
fn check_pass_and_stdio(ra_fixture: &str, expected_stdout: &str, expected_stderr: &str) {
44+
fn check_pass_and_stdio(
45+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
46+
expected_stdout: &str,
47+
expected_stderr: &str,
48+
) {
4549
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
4650
let file_id = *file_ids.last().unwrap();
4751
let x = eval_main(&db, file_id);
@@ -73,7 +77,7 @@ fn check_pass_and_stdio(ra_fixture: &str, expected_stdout: &str, expected_stderr
7377
}
7478
}
7579

76-
fn check_panic(ra_fixture: &str, expected_panic: &str) {
80+
fn check_panic(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected_panic: &str) {
7781
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
7882
let file_id = *file_ids.last().unwrap();
7983
let e = eval_main(&db, file_id).unwrap_err();

crates/hir-ty/src/tests.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,32 @@ fn setup_tracing() -> Option<tracing::subscriber::DefaultGuard> {
6969
}
7070

7171
#[track_caller]
72-
fn check_types(ra_fixture: &str) {
72+
fn check_types(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
7373
check_impl(ra_fixture, false, true, false)
7474
}
7575

7676
#[track_caller]
77-
fn check_types_source_code(ra_fixture: &str) {
77+
fn check_types_source_code(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
7878
check_impl(ra_fixture, false, true, true)
7979
}
8080

8181
#[track_caller]
82-
fn check_no_mismatches(ra_fixture: &str) {
82+
fn check_no_mismatches(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
8383
check_impl(ra_fixture, true, false, false)
8484
}
8585

8686
#[track_caller]
87-
fn check(ra_fixture: &str) {
87+
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
8888
check_impl(ra_fixture, false, false, false)
8989
}
9090

9191
#[track_caller]
92-
fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_source: bool) {
92+
fn check_impl(
93+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
94+
allow_none: bool,
95+
only_types: bool,
96+
display_source: bool,
97+
) {
9398
let _tracing = setup_tracing();
9499
let (db, files) = TestDB::with_many_files(ra_fixture);
95100

@@ -282,7 +287,7 @@ fn pat_node(
282287
})
283288
}
284289

285-
fn infer(ra_fixture: &str) -> String {
290+
fn infer(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String {
286291
infer_with_mismatches(ra_fixture, false)
287292
}
288293

@@ -520,13 +525,13 @@ fn ellipsize(mut text: String, max_len: usize) -> String {
520525
text
521526
}
522527

523-
fn check_infer(ra_fixture: &str, expect: Expect) {
528+
fn check_infer(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
524529
let mut actual = infer(ra_fixture);
525530
actual.push('\n');
526531
expect.assert_eq(&actual);
527532
}
528533

529-
fn check_infer_with_mismatches(ra_fixture: &str, expect: Expect) {
534+
fn check_infer_with_mismatches(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
530535
let mut actual = infer_with_mismatches(ra_fixture, true);
531536
actual.push('\n');
532537
expect.assert_eq(&actual);

crates/hir-ty/src/tests/closure_captures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::test_db::TestDB;
1414

1515
use super::visit_module;
1616

17-
fn check_closure_captures(ra_fixture: &str, expect: Expect) {
17+
fn check_closure_captures(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
1818
let (db, file_id) = TestDB::with_single_file(ra_fixture);
1919
let module = db.module_for_file(file_id);
2020
let def_map = module.def_map(&db);

0 commit comments

Comments
 (0)