mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
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*.
This commit is contained in:
parent
92ce768ea3
commit
c87b860d3d
2 changed files with 12 additions and 10 deletions
|
@ -69,10 +69,10 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
|
||||||
if ty.could_unify_with(ctx.sema.db, &candidate_ty) {
|
if ty.could_unify_with(ctx.sema.db, &candidate_ty) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(make::expr_unit())
|
Some(make::ext::expr_todo())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Some(make::expr_unit())
|
Some(make::ext::expr_todo())
|
||||||
};
|
};
|
||||||
let field =
|
let field =
|
||||||
make::record_expr_field(make::name_ref(&f.name(ctx.sema.db).to_string()), field_expr)
|
make::record_expr_field(make::name_ref(&f.name(ctx.sema.db).to_string()), field_expr)
|
||||||
|
@ -167,7 +167,7 @@ fn main() {
|
||||||
pub struct Foo { pub a: i32, pub b: i32 }
|
pub struct Foo { pub a: i32, pub b: i32 }
|
||||||
"#,
|
"#,
|
||||||
r#"
|
r#"
|
||||||
fn some(, b: () ) {}
|
fn some(, b: todo!() ) {}
|
||||||
fn items() {}
|
fn items() {}
|
||||||
fn here() {}
|
fn here() {}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ fn test_fn() {
|
||||||
struct TestStruct { one: i32, two: i64 }
|
struct TestStruct { one: i32, two: i64 }
|
||||||
|
|
||||||
fn test_fn() {
|
fn test_fn() {
|
||||||
let s = TestStruct { one: (), two: () };
|
let s = TestStruct { one: todo!(), two: todo!() };
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
@ -216,7 +216,7 @@ impl TestStruct {
|
||||||
struct TestStruct { one: i32 }
|
struct TestStruct { one: i32 }
|
||||||
|
|
||||||
impl TestStruct {
|
impl TestStruct {
|
||||||
fn test_fn() { let s = Self { one: () }; }
|
fn test_fn() { let s = Self { one: todo!() }; }
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
@ -264,7 +264,7 @@ fn test_fn() {
|
||||||
struct TestStruct { one: i32, two: i64 }
|
struct TestStruct { one: i32, two: i64 }
|
||||||
|
|
||||||
fn test_fn() {
|
fn test_fn() {
|
||||||
let s = TestStruct{ two: 2, one: () };
|
let s = TestStruct{ two: 2, one: todo!() };
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
@ -284,7 +284,7 @@ fn test_fn() {
|
||||||
struct TestStruct { r#type: u8 }
|
struct TestStruct { r#type: u8 }
|
||||||
|
|
||||||
fn test_fn() {
|
fn test_fn() {
|
||||||
TestStruct { r#type: () };
|
TestStruct { r#type: todo!() };
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
@ -335,8 +335,8 @@ struct S { a: (), b: () }
|
||||||
|
|
||||||
fn f() {
|
fn f() {
|
||||||
S {
|
S {
|
||||||
a: (),
|
a: todo!(),
|
||||||
b: (),
|
b: todo!(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
@ -395,7 +395,7 @@ fn f() {
|
||||||
let b = 1usize;
|
let b = 1usize;
|
||||||
S {
|
S {
|
||||||
a,
|
a,
|
||||||
b: (),
|
b: todo!(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
|
|
@ -282,6 +282,8 @@ fn check_todo(path: &Path, text: &str) {
|
||||||
"ide_db/src/helpers/generated_lints.rs",
|
"ide_db/src/helpers/generated_lints.rs",
|
||||||
"ide_assists/src/utils/gen_trait_fn_body.rs",
|
"ide_assists/src/utils/gen_trait_fn_body.rs",
|
||||||
"ide_assists/src/tests/generated.rs",
|
"ide_assists/src/tests/generated.rs",
|
||||||
|
// The tests for missing fields
|
||||||
|
"ide_diagnostics/src/handlers/missing_fields.rs",
|
||||||
];
|
];
|
||||||
if need_todo.iter().any(|p| path.ends_with(p)) {
|
if need_todo.iter().any(|p| path.ends_with(p)) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue