Skip to content

Commit b60a29c

Browse files
committed
feat(diagnostics): use default expression instead of todo! when missing fields
Signed-off-by: Benjamin Coenen <[email protected]>
1 parent 0a4239a commit b60a29c

File tree

6 files changed

+12
-13
lines changed

6 files changed

+12
-13
lines changed

crates/ide_diagnostics/src/handlers/missing_fields.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
7373

7474
let generate_fill_expr = |ty: &Type| match ctx.config.expr_fill_default {
7575
crate::ExprFillDefaultMode::Todo => Some(make::ext::expr_todo()),
76-
crate::ExprFillDefaultMode::DefaultImpl => {
76+
crate::ExprFillDefaultMode::Default => {
7777
let default_constr = get_default_constructor(ctx, d, ty);
7878
match default_constr {
7979
Some(default_constr) => Some(default_constr),
@@ -159,7 +159,6 @@ fn get_default_constructor(
159159
if let AssocItem::Function(func) = assoc_item {
160160
if func.name(ctx.sema.db) == known::new
161161
&& func.assoc_fn_params(ctx.sema.db).is_empty()
162-
&& func.self_param(ctx.sema.db).is_none()
163162
{
164163
return Some(());
165164
}

crates/ide_diagnostics/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub enum Severity {
132132
#[derive(Clone, Debug, PartialEq, Eq)]
133133
pub enum ExprFillDefaultMode {
134134
Todo,
135-
DefaultImpl,
135+
Default,
136136
}
137137
impl Default for ExprFillDefaultMode {
138138
fn default() -> Self {

crates/ide_diagnostics/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) {
3737

3838
let (db, file_position) = RootDatabase::with_position(ra_fixture_before);
3939
let mut conf = DiagnosticsConfig::default();
40-
conf.expr_fill_default = ExprFillDefaultMode::DefaultImpl;
40+
conf.expr_fill_default = ExprFillDefaultMode::Default;
4141
let diagnostic =
4242
super::diagnostics(&db, &conf, &AssistResolveStrategy::All, file_position.file_id)
4343
.pop()

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ impl Config {
698698
disabled: self.data.diagnostics_disabled.clone(),
699699
expr_fill_default: match self.data.assist_exprFillDefault {
700700
ExprFillDefaultDef::Todo => ExprFillDefaultMode::Todo,
701-
ExprFillDefaultDef::DefaultImpl => ExprFillDefaultMode::DefaultImpl,
701+
ExprFillDefaultDef::Default => ExprFillDefaultMode::Default,
702702
},
703703
}
704704
}
@@ -1070,8 +1070,8 @@ enum ManifestOrProjectJson {
10701070
pub enum ExprFillDefaultDef {
10711071
#[serde(alias = "todo")]
10721072
Todo,
1073-
#[serde(alias = "defaultImpl")]
1074-
DefaultImpl,
1073+
#[serde(alias = "default")]
1074+
Default,
10751075
}
10761076

10771077
#[derive(Deserialize, Debug, Clone)]
@@ -1270,9 +1270,9 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
12701270
},
12711271
"ExprFillDefaultDef" => set! {
12721272
"type": "string",
1273-
"enum": ["todo", "defaultImpl"],
1273+
"enum": ["todo", "default"],
12741274
"enumDescriptions": [
1275-
"Fill missing elements with 'todo' macro",
1275+
"Fill missing expressions with the 'todo' macro",
12761276
"Fill missing expressions with reasonable defaults, `new` or `default` constructors."
12771277
],
12781278
},

crates/syntax/src/ast/make.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub mod ext {
7676
expr_from_text(r#""""#)
7777
}
7878
pub fn empty_char() -> ast::Expr {
79-
expr_from_text("''")
79+
expr_from_text("'\x00'")
8080
}
8181
pub fn default_bool() -> ast::Expr {
8282
expr_from_text("false")

editors/code/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@
384384
"type": "string",
385385
"enum": [
386386
"todo",
387-
"defaultImpl"
387+
"default"
388388
],
389389
"enumDescriptions": [
390-
"Fill missing elements with 'todo' macro",
391-
"Fill missing elements with T::default()"
390+
"Fill missing expressions with the 'todo' macro",
391+
"Fill missing expressions with reasonable defaults, `new` or `default` constructors."
392392
]
393393
},
394394
"rust-analyzer.assist.importGranularity": {

0 commit comments

Comments
 (0)