Skip to content

Commit 132a2a0

Browse files
authored
Merge pull request #18951 from Veykril/push-zpvunsvlpuxt
Add missing `#[rust_analyzer::rust_fixture]` annotations
2 parents 2ca2e56 + 24e1db2 commit 132a2a0

File tree

12 files changed

+149
-51
lines changed

12 files changed

+149
-51
lines changed

Diff for: crates/hir/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4855,6 +4855,7 @@ impl Type {
48554855
self.normalize_trait_assoc_type(db, &[], iterator_item.into())
48564856
}
48574857

4858+
/// Resolves the projection `<Self as IntoIterator>::IntoIter` and returns the resulting type
48584859
pub fn into_iterator_iter(self, db: &dyn HirDatabase) -> Option<Type> {
48594860
let trait_ = db.lang_item(self.env.krate, LangItem::IntoIterIntoIter).and_then(|it| {
48604861
let into_iter_fn = it.as_function()?;

Diff for: crates/ide-assists/src/handlers/destructure_tuple_binding.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,10 @@ fn main {
11281128
destructure_tuple_binding_impl(acc, ctx, false)
11291129
}
11301130

1131-
pub(crate) fn check_in_place_assist(ra_fixture_before: &str, ra_fixture_after: &str) {
1131+
pub(crate) fn check_in_place_assist(
1132+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
1133+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
1134+
) {
11321135
check_assist_by_label(
11331136
in_place_assist,
11341137
ra_fixture_before,
@@ -1138,7 +1141,10 @@ fn main {
11381141
);
11391142
}
11401143

1141-
pub(crate) fn check_sub_pattern_assist(ra_fixture_before: &str, ra_fixture_after: &str) {
1144+
pub(crate) fn check_sub_pattern_assist(
1145+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
1146+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
1147+
) {
11421148
check_assist_by_label(
11431149
assist,
11441150
ra_fixture_before,

Diff for: crates/ide-assists/src/handlers/remove_dbg.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ mod tests {
209209

210210
use super::*;
211211

212-
fn check(ra_fixture_before: &str, ra_fixture_after: &str) {
212+
fn check(
213+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
214+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
215+
) {
213216
check_assist(
214217
remove_dbg,
215218
&format!("fn main() {{\n{ra_fixture_before}\n}}"),

Diff for: crates/ide-assists/src/tests.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,20 @@ pub(crate) fn with_single_file(text: &str) -> (RootDatabase, EditionedFileId) {
7777
}
7878

7979
#[track_caller]
80-
pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) {
80+
pub(crate) fn check_assist(
81+
assist: Handler,
82+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
83+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
84+
) {
8185
let ra_fixture_after = trim_indent(ra_fixture_after);
8286
check(assist, ra_fixture_before, ExpectedResult::After(&ra_fixture_after), None);
8387
}
8488

8589
#[track_caller]
8690
pub(crate) fn check_assist_no_snippet_cap(
8791
assist: Handler,
88-
ra_fixture_before: &str,
89-
ra_fixture_after: &str,
92+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
93+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
9094
) {
9195
let ra_fixture_after = trim_indent(ra_fixture_after);
9296
check_with_config(
@@ -101,8 +105,8 @@ pub(crate) fn check_assist_no_snippet_cap(
101105
#[track_caller]
102106
pub(crate) fn check_assist_import_one(
103107
assist: Handler,
104-
ra_fixture_before: &str,
105-
ra_fixture_after: &str,
108+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
109+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
106110
) {
107111
let ra_fixture_after = trim_indent(ra_fixture_after);
108112
check_with_config(
@@ -118,8 +122,8 @@ pub(crate) fn check_assist_import_one(
118122
// so this is here to allow you choose.
119123
pub(crate) fn check_assist_by_label(
120124
assist: Handler,
121-
ra_fixture_before: &str,
122-
ra_fixture_after: &str,
125+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
126+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
123127
label: &str,
124128
) {
125129
let ra_fixture_after = trim_indent(ra_fixture_after);

Diff for: crates/ide-completion/src/completions/dot.rs

+44-16
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ pub(crate) fn complete_dot(
3232

3333
// Suggest .await syntax for types that implement Future trait
3434
if let Some(future_output) = receiver_ty.into_future_output(ctx.db) {
35+
let await_str = SmolStr::new_static("await");
3536
let mut item = CompletionItem::new(
3637
CompletionItemKind::Keyword,
3738
ctx.source_range(),
38-
SmolStr::new_static("await"),
39+
await_str.clone(),
3940
ctx.edition,
4041
);
4142
item.detail("expr.await");
@@ -58,17 +59,13 @@ pub(crate) fn complete_dot(
5859
acc,
5960
ctx,
6061
&future_output,
61-
|acc, field, ty| {
62-
acc.add_field(ctx, &dot_access, Some(SmolStr::new_static("await")), field, &ty)
63-
},
64-
|acc, field, ty| {
65-
acc.add_tuple_field(ctx, Some(SmolStr::new_static("await")), field, &ty)
66-
},
62+
|acc, field, ty| acc.add_field(ctx, &dot_access, Some(await_str.clone()), field, &ty),
63+
|acc, field, ty| acc.add_tuple_field(ctx, Some(await_str.clone()), field, &ty),
6764
is_field_access,
6865
is_method_access_with_parens,
6966
);
7067
complete_methods(ctx, &future_output, &traits_in_scope, |func| {
71-
acc.add_method(ctx, &dot_access, func, Some(SmolStr::new_static("await")), None)
68+
acc.add_method(ctx, &dot_access, func, Some(await_str.clone()), None)
7269
});
7370
}
7471

@@ -85,20 +82,23 @@ pub(crate) fn complete_dot(
8582
acc.add_method(ctx, dot_access, func, None, None)
8683
});
8784

85+
// FIXME:
8886
// Checking for the existence of `iter()` is complicated in our setup, because we need to substitute
8987
// its return type, so we instead check for `<&Self as IntoIterator>::IntoIter`.
88+
// Does <&receiver_ty as IntoIterator>::IntoIter` exist? Assume `iter` is valid
9089
let iter = receiver_ty
9190
.strip_references()
9291
.add_reference(hir::Mutability::Shared)
9392
.into_iterator_iter(ctx.db)
94-
.map(|ty| (ty, SmolStr::new_static("iter()")))
95-
.or_else(|| {
96-
receiver_ty
97-
.clone()
98-
.into_iterator_iter(ctx.db)
99-
.map(|ty| (ty, SmolStr::new_static("into_iter()")))
100-
});
101-
if let Some((iter, iter_sym)) = iter {
93+
.map(|ty| (ty, SmolStr::new_static("iter()")));
94+
// Does <receiver_ty as IntoIterator>::IntoIter` exist?
95+
let into_iter = || {
96+
receiver_ty
97+
.clone()
98+
.into_iterator_iter(ctx.db)
99+
.map(|ty| (ty, SmolStr::new_static("into_iter()")))
100+
};
101+
if let Some((iter, iter_sym)) = iter.or_else(into_iter) {
102102
// Skip iterators, e.g. complete `.iter().filter_map()`.
103103
let dot_access_kind = match &dot_access.kind {
104104
DotAccessKind::Field { receiver_is_ambiguous_float_literal: _ } => {
@@ -1437,5 +1437,33 @@ async fn bar() {
14371437
me into_future() (use core::future::IntoFuture) fn(self) -> <Self as IntoFuture>::IntoFuture
14381438
"#]],
14391439
);
1440+
check_edit(
1441+
"foo",
1442+
r#"
1443+
//- minicore: future
1444+
struct Foo;
1445+
impl Foo {
1446+
fn foo(self) {}
1447+
}
1448+
1449+
async fn foo() -> Foo { Foo }
1450+
1451+
async fn bar() {
1452+
foo().$0
1453+
}
1454+
"#,
1455+
r#"
1456+
struct Foo;
1457+
impl Foo {
1458+
fn foo(self) {}
1459+
}
1460+
1461+
async fn foo() -> Foo { Foo }
1462+
1463+
async fn bar() {
1464+
foo().await.foo();$0
1465+
}
1466+
"#,
1467+
);
14401468
}
14411469
}

Diff for: crates/ide-completion/src/tests.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ fn render_completion_list(completions: Vec<CompletionItem>) -> String {
220220
}
221221

222222
#[track_caller]
223-
pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
223+
pub(crate) fn check_edit(
224+
what: &str,
225+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
226+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
227+
) {
224228
check_edit_with_config(TEST_CONFIG, what, ra_fixture_before, ra_fixture_after)
225229
}
226230

Diff for: crates/ide-db/src/imports/insert_use/tests.rs

+24-8
Original file line numberDiff line numberDiff line change
@@ -1244,8 +1244,8 @@ use ::ext::foo::Foo;
12441244

12451245
fn check_with_config(
12461246
path: &str,
1247-
ra_fixture_before: &str,
1248-
ra_fixture_after: &str,
1247+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
1248+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
12491249
config: &InsertUseConfig,
12501250
) {
12511251
let (db, file_id, pos) = if ra_fixture_before.contains(CURSOR_MARKER) {
@@ -1277,8 +1277,8 @@ fn check_with_config(
12771277

12781278
fn check(
12791279
path: &str,
1280-
ra_fixture_before: &str,
1281-
ra_fixture_after: &str,
1280+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
1281+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
12821282
granularity: ImportGranularity,
12831283
) {
12841284
check_with_config(
@@ -1295,19 +1295,35 @@ fn check(
12951295
)
12961296
}
12971297

1298-
fn check_crate(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
1298+
fn check_crate(
1299+
path: &str,
1300+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
1301+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
1302+
) {
12991303
check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::Crate)
13001304
}
13011305

1302-
fn check_module(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
1306+
fn check_module(
1307+
path: &str,
1308+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
1309+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
1310+
) {
13031311
check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::Module)
13041312
}
13051313

1306-
fn check_none(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
1314+
fn check_none(
1315+
path: &str,
1316+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
1317+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
1318+
) {
13071319
check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::Item)
13081320
}
13091321

1310-
fn check_one(path: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
1322+
fn check_one(
1323+
path: &str,
1324+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
1325+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
1326+
) {
13111327
check(path, ra_fixture_before, ra_fixture_after, ImportGranularity::One)
13121328
}
13131329

Diff for: crates/ide-diagnostics/src/tests.rs

+29-10
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,41 @@ use crate::{DiagnosticsConfig, ExprFillDefaultMode, Severity};
1818
/// * the first diagnostic fix trigger range touches the input cursor position
1919
/// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied
2020
#[track_caller]
21-
pub(crate) fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
21+
pub(crate) fn check_fix(
22+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
23+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
24+
) {
2225
check_nth_fix(0, ra_fixture_before, ra_fixture_after);
2326
}
2427
/// Takes a multi-file input fixture with annotated cursor positions,
2528
/// and checks that:
2629
/// * a diagnostic is produced
2730
/// * every diagnostic fixes trigger range touches the input cursor position
2831
/// * that the contents of the file containing the cursor match `after` after each diagnostic fix is applied
29-
pub(crate) fn check_fixes(ra_fixture_before: &str, ra_fixtures_after: Vec<&str>) {
32+
pub(crate) fn check_fixes(
33+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
34+
ra_fixtures_after: Vec<&str>,
35+
) {
3036
for (i, ra_fixture_after) in ra_fixtures_after.iter().enumerate() {
3137
check_nth_fix(i, ra_fixture_before, ra_fixture_after)
3238
}
3339
}
3440

3541
#[track_caller]
36-
fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) {
42+
fn check_nth_fix(
43+
nth: usize,
44+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
45+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
46+
) {
3747
let mut config = DiagnosticsConfig::test_sample();
3848
config.expr_fill_default = ExprFillDefaultMode::Default;
3949
check_nth_fix_with_config(config, nth, ra_fixture_before, ra_fixture_after)
4050
}
4151

4252
#[track_caller]
4353
pub(crate) fn check_fix_with_disabled(
44-
ra_fixture_before: &str,
45-
ra_fixture_after: &str,
54+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
55+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
4656
disabled: impl Iterator<Item = String>,
4757
) {
4858
let mut config = DiagnosticsConfig::test_sample();
@@ -55,8 +65,8 @@ pub(crate) fn check_fix_with_disabled(
5565
fn check_nth_fix_with_config(
5666
config: DiagnosticsConfig,
5767
nth: usize,
58-
ra_fixture_before: &str,
59-
ra_fixture_after: &str,
68+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
69+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
6070
) {
6171
let after = trim_indent(ra_fixture_after);
6272

@@ -95,14 +105,20 @@ fn check_nth_fix_with_config(
95105
assert_eq_text!(&after, &actual);
96106
}
97107

98-
pub(crate) fn check_fixes_unordered(ra_fixture_before: &str, ra_fixtures_after: Vec<&str>) {
108+
pub(crate) fn check_fixes_unordered(
109+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
110+
ra_fixtures_after: Vec<&str>,
111+
) {
99112
for ra_fixture_after in ra_fixtures_after.iter() {
100113
check_has_fix(ra_fixture_before, ra_fixture_after)
101114
}
102115
}
103116

104117
#[track_caller]
105-
pub(crate) fn check_has_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
118+
pub(crate) fn check_has_fix(
119+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
120+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
121+
) {
106122
let after = trim_indent(ra_fixture_after);
107123

108124
let (db, file_position) = RootDatabase::with_position(ra_fixture_before);
@@ -145,7 +161,10 @@ pub(crate) fn check_has_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
145161
}
146162

147163
#[track_caller]
148-
pub(crate) fn check_has_single_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
164+
pub(crate) fn check_has_single_fix(
165+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
166+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
167+
) {
149168
let after = trim_indent(ra_fixture_after);
150169

151170
let (db, file_position) = RootDatabase::with_position(ra_fixture_before);

Diff for: crates/ide/src/join_lines.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,10 @@ mod tests {
307307

308308
use super::*;
309309

310-
fn check_join_lines(ra_fixture_before: &str, ra_fixture_after: &str) {
310+
fn check_join_lines(
311+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
312+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
313+
) {
311314
let config = JoinLinesConfig {
312315
join_else_if: true,
313316
remove_trailing_comma: true,
@@ -333,7 +336,10 @@ mod tests {
333336
assert_eq_text!(ra_fixture_after, &actual);
334337
}
335338

336-
fn check_join_lines_sel(ra_fixture_before: &str, ra_fixture_after: &str) {
339+
fn check_join_lines_sel(
340+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
341+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
342+
) {
337343
let config = JoinLinesConfig {
338344
join_else_if: true,
339345
remove_trailing_comma: true,

Diff for: crates/ide/src/rename.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,11 @@ mod tests {
456456
use super::{RangeInfo, RenameError};
457457

458458
#[track_caller]
459-
fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
459+
fn check(
460+
new_name: &str,
461+
#[rust_analyzer::rust_fixture] ra_fixture_before: &str,
462+
#[rust_analyzer::rust_fixture] ra_fixture_after: &str,
463+
) {
460464
let ra_fixture_after = &trim_indent(ra_fixture_after);
461465
let (analysis, position) = fixture::position(ra_fixture_before);
462466
if !ra_fixture_after.starts_with("error: ") {

0 commit comments

Comments
 (0)