diff options
| author | Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> | 2022-01-07 14:13:34 +0100 |
|---|---|---|
| committer | Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> | 2022-01-07 14:13:34 +0100 |
| commit | b60a29ca9428e95c995f12ab8eff6160957188fe (patch) | |
| tree | 4277f771073f55c945196b93229528d4cf61158f | |
| parent | 0a4239a8153a17dda816678dfd870e1e5d10a101 (diff) | |
| download | rust-b60a29ca9428e95c995f12ab8eff6160957188fe.tar.gz rust-b60a29ca9428e95c995f12ab8eff6160957188fe.zip | |
feat(diagnostics): use default expression instead of todo! when missing fields
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
| -rw-r--r-- | crates/ide_diagnostics/src/handlers/missing_fields.rs | 3 | ||||
| -rw-r--r-- | crates/ide_diagnostics/src/lib.rs | 2 | ||||
| -rw-r--r-- | crates/ide_diagnostics/src/tests.rs | 2 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/config.rs | 10 | ||||
| -rw-r--r-- | crates/syntax/src/ast/make.rs | 2 | ||||
| -rw-r--r-- | editors/code/package.json | 6 |
6 files changed, 12 insertions, 13 deletions
diff --git a/crates/ide_diagnostics/src/handlers/missing_fields.rs b/crates/ide_diagnostics/src/handlers/missing_fields.rs index 8aca6ab3752..186bfc3d584 100644 --- a/crates/ide_diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide_diagnostics/src/handlers/missing_fields.rs @@ -73,7 +73,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass let generate_fill_expr = |ty: &Type| match ctx.config.expr_fill_default { crate::ExprFillDefaultMode::Todo => Some(make::ext::expr_todo()), - crate::ExprFillDefaultMode::DefaultImpl => { + crate::ExprFillDefaultMode::Default => { let default_constr = get_default_constructor(ctx, d, ty); match default_constr { Some(default_constr) => Some(default_constr), @@ -159,7 +159,6 @@ fn get_default_constructor( if let AssocItem::Function(func) = assoc_item { if func.name(ctx.sema.db) == known::new && func.assoc_fn_params(ctx.sema.db).is_empty() - && func.self_param(ctx.sema.db).is_none() { return Some(()); } diff --git a/crates/ide_diagnostics/src/lib.rs b/crates/ide_diagnostics/src/lib.rs index f4c613840e3..86d76751ad6 100644 --- a/crates/ide_diagnostics/src/lib.rs +++ b/crates/ide_diagnostics/src/lib.rs @@ -132,7 +132,7 @@ pub enum Severity { #[derive(Clone, Debug, PartialEq, Eq)] pub enum ExprFillDefaultMode { Todo, - DefaultImpl, + Default, } impl Default for ExprFillDefaultMode { fn default() -> Self { diff --git a/crates/ide_diagnostics/src/tests.rs b/crates/ide_diagnostics/src/tests.rs index 479a121c681..7d06e9d36ff 100644 --- a/crates/ide_diagnostics/src/tests.rs +++ b/crates/ide_diagnostics/src/tests.rs @@ -37,7 +37,7 @@ fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) { let (db, file_position) = RootDatabase::with_position(ra_fixture_before); let mut conf = DiagnosticsConfig::default(); - conf.expr_fill_default = ExprFillDefaultMode::DefaultImpl; + conf.expr_fill_default = ExprFillDefaultMode::Default; let diagnostic = super::diagnostics(&db, &conf, &AssistResolveStrategy::All, file_position.file_id) .pop() diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 86fcff01ba9..6be889df67a 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -698,7 +698,7 @@ impl Config { disabled: self.data.diagnostics_disabled.clone(), expr_fill_default: match self.data.assist_exprFillDefault { ExprFillDefaultDef::Todo => ExprFillDefaultMode::Todo, - ExprFillDefaultDef::DefaultImpl => ExprFillDefaultMode::DefaultImpl, + ExprFillDefaultDef::Default => ExprFillDefaultMode::Default, }, } } @@ -1070,8 +1070,8 @@ enum ManifestOrProjectJson { pub enum ExprFillDefaultDef { #[serde(alias = "todo")] Todo, - #[serde(alias = "defaultImpl")] - DefaultImpl, + #[serde(alias = "default")] + Default, } #[derive(Deserialize, Debug, Clone)] @@ -1270,9 +1270,9 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json }, "ExprFillDefaultDef" => set! { "type": "string", - "enum": ["todo", "defaultImpl"], + "enum": ["todo", "default"], "enumDescriptions": [ - "Fill missing elements with 'todo' macro", + "Fill missing expressions with the 'todo' macro", "Fill missing expressions with reasonable defaults, `new` or `default` constructors." ], }, diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index 12d5b7decc6..35750209754 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs @@ -76,7 +76,7 @@ pub mod ext { expr_from_text(r#""""#) } pub fn empty_char() -> ast::Expr { - expr_from_text("''") + expr_from_text("'\x00'") } pub fn default_bool() -> ast::Expr { expr_from_text("false") diff --git a/editors/code/package.json b/editors/code/package.json index 6bc62fc9d7f..c81fd0b3d2d 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -384,11 +384,11 @@ "type": "string", "enum": [ "todo", - "defaultImpl" + "default" ], "enumDescriptions": [ - "Fill missing elements with 'todo' macro", - "Fill missing elements with T::default()" + "Fill missing expressions with the 'todo' macro", + "Fill missing expressions with reasonable defaults, `new` or `default` constructors." ] }, "rust-analyzer.assist.importGranularity": { |
