Skip to content

Commit c87b860

Browse files
committed
Use todo!() instead of () for missing fields
The generated code with `()` doesn't compile in most of the cases. To signal the developer there's something to do, fill in `todo!()`. Because the file *missing_fields.rs* contains the string `todo!()` it needs an exception for the test *check_todo*.
1 parent 92ce768 commit c87b860

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

crates/ide_diagnostics/src/handlers/missing_fields.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
6969
if ty.could_unify_with(ctx.sema.db, &candidate_ty) {
7070
None
7171
} else {
72-
Some(make::expr_unit())
72+
Some(make::ext::expr_todo())
7373
}
7474
} else {
75-
Some(make::expr_unit())
75+
Some(make::ext::expr_todo())
7676
};
7777
let field =
7878
make::record_expr_field(make::name_ref(&f.name(ctx.sema.db).to_string()), field_expr)
@@ -167,7 +167,7 @@ fn main() {
167167
pub struct Foo { pub a: i32, pub b: i32 }
168168
"#,
169169
r#"
170-
fn some(, b: () ) {}
170+
fn some(, b: todo!() ) {}
171171
fn items() {}
172172
fn here() {}
173173
@@ -196,7 +196,7 @@ fn test_fn() {
196196
struct TestStruct { one: i32, two: i64 }
197197
198198
fn test_fn() {
199-
let s = TestStruct { one: (), two: () };
199+
let s = TestStruct { one: todo!(), two: todo!() };
200200
}
201201
"#,
202202
);
@@ -216,7 +216,7 @@ impl TestStruct {
216216
struct TestStruct { one: i32 }
217217
218218
impl TestStruct {
219-
fn test_fn() { let s = Self { one: () }; }
219+
fn test_fn() { let s = Self { one: todo!() }; }
220220
}
221221
"#,
222222
);
@@ -264,7 +264,7 @@ fn test_fn() {
264264
struct TestStruct { one: i32, two: i64 }
265265
266266
fn test_fn() {
267-
let s = TestStruct{ two: 2, one: () };
267+
let s = TestStruct{ two: 2, one: todo!() };
268268
}
269269
",
270270
);
@@ -284,7 +284,7 @@ fn test_fn() {
284284
struct TestStruct { r#type: u8 }
285285
286286
fn test_fn() {
287-
TestStruct { r#type: () };
287+
TestStruct { r#type: todo!() };
288288
}
289289
",
290290
);
@@ -335,8 +335,8 @@ struct S { a: (), b: () }
335335
336336
fn f() {
337337
S {
338-
a: (),
339-
b: (),
338+
a: todo!(),
339+
b: todo!(),
340340
};
341341
}
342342
"#,
@@ -395,7 +395,7 @@ fn f() {
395395
let b = 1usize;
396396
S {
397397
a,
398-
b: (),
398+
b: todo!(),
399399
};
400400
}
401401
"#,

crates/rust-analyzer/tests/slow-tests/tidy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ fn check_todo(path: &Path, text: &str) {
282282
"ide_db/src/helpers/generated_lints.rs",
283283
"ide_assists/src/utils/gen_trait_fn_body.rs",
284284
"ide_assists/src/tests/generated.rs",
285+
// The tests for missing fields
286+
"ide_diagnostics/src/handlers/missing_fields.rs",
285287
];
286288
if need_todo.iter().any(|p| path.ends_with(p)) {
287289
return;

0 commit comments

Comments
 (0)