aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/diagnostics.rs')
-rw-r--r--crates/ra_ide/src/diagnostics.rs32
1 files changed, 17 insertions, 15 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index 897177d05..73c0b8275 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -78,8 +78,10 @@ pub(crate) fn diagnostics(
78 } else { 78 } else {
79 let mut field_list = d.ast(db); 79 let mut field_list = d.ast(db);
80 for f in d.missed_fields.iter() { 80 for f in d.missed_fields.iter() {
81 let field = 81 let field = make::record_expr_field(
82 make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit())); 82 make::name_ref(&f.to_string()),
83 Some(make::expr_unit()),
84 );
83 field_list = field_list.append_field(&field); 85 field_list = field_list.append_field(&field);
84 } 86 }
85 87
@@ -146,7 +148,7 @@ fn missing_struct_field_fix(
146) -> Option<Fix> { 148) -> Option<Fix> {
147 let record_expr = sema.ast(d); 149 let record_expr = sema.ast(d);
148 150
149 let record_lit = ast::RecordLit::cast(record_expr.syntax().parent()?.parent()?)?; 151 let record_lit = ast::RecordExpr::cast(record_expr.syntax().parent()?.parent()?)?;
150 let def_id = sema.resolve_variant(record_lit)?; 152 let def_id = sema.resolve_variant(record_lit)?;
151 let module; 153 let module;
152 let def_file_id; 154 let def_file_id;
@@ -155,21 +157,21 @@ fn missing_struct_field_fix(
155 module = s.module(sema.db); 157 module = s.module(sema.db);
156 let source = s.source(sema.db); 158 let source = s.source(sema.db);
157 def_file_id = source.file_id; 159 def_file_id = source.file_id;
158 let fields = source.value.field_def_list()?; 160 let fields = source.value.field_list()?;
159 record_field_def_list(fields)? 161 record_field_list(fields)?
160 } 162 }
161 VariantDef::Union(u) => { 163 VariantDef::Union(u) => {
162 module = u.module(sema.db); 164 module = u.module(sema.db);
163 let source = u.source(sema.db); 165 let source = u.source(sema.db);
164 def_file_id = source.file_id; 166 def_file_id = source.file_id;
165 source.value.record_field_def_list()? 167 source.value.record_field_list()?
166 } 168 }
167 VariantDef::EnumVariant(e) => { 169 VariantDef::EnumVariant(e) => {
168 module = e.module(sema.db); 170 module = e.module(sema.db);
169 let source = e.source(sema.db); 171 let source = e.source(sema.db);
170 def_file_id = source.file_id; 172 def_file_id = source.file_id;
171 let fields = source.value.field_def_list()?; 173 let fields = source.value.field_list()?;
172 record_field_def_list(fields)? 174 record_field_list(fields)?
173 } 175 }
174 }; 176 };
175 let def_file_id = def_file_id.original_file(sema.db); 177 let def_file_id = def_file_id.original_file(sema.db);
@@ -178,9 +180,9 @@ fn missing_struct_field_fix(
178 if new_field_type.is_unknown() { 180 if new_field_type.is_unknown() {
179 return None; 181 return None;
180 } 182 }
181 let new_field = make::record_field_def( 183 let new_field = make::record_field(
182 record_expr.field_name()?, 184 record_expr.field_name()?,
183 make::type_ref(&new_field_type.display_source_code(sema.db, module.into()).ok()?), 185 make::ty(&new_field_type.display_source_code(sema.db, module.into()).ok()?),
184 ); 186 );
185 187
186 let last_field = record_fields.fields().last()?; 188 let last_field = record_fields.fields().last()?;
@@ -205,10 +207,10 @@ fn missing_struct_field_fix(
205 let fix = Fix::new("Create field", source_change.into()); 207 let fix = Fix::new("Create field", source_change.into());
206 return Some(fix); 208 return Some(fix);
207 209
208 fn record_field_def_list(field_def_list: ast::FieldDefList) -> Option<ast::RecordFieldDefList> { 210 fn record_field_list(field_def_list: ast::FieldList) -> Option<ast::RecordFieldList> {
209 match field_def_list { 211 match field_def_list {
210 ast::FieldDefList::RecordFieldDefList(it) => Some(it), 212 ast::FieldList::RecordFieldList(it) => Some(it),
211 ast::FieldDefList::TupleFieldDefList(_) => None, 213 ast::FieldList::TupleFieldList(_) => None,
212 } 214 }
213 } 215 }
214} 216}
@@ -263,8 +265,8 @@ fn check_struct_shorthand_initialization(
263 file_id: FileId, 265 file_id: FileId,
264 node: &SyntaxNode, 266 node: &SyntaxNode,
265) -> Option<()> { 267) -> Option<()> {
266 let record_lit = ast::RecordLit::cast(node.clone())?; 268 let record_lit = ast::RecordExpr::cast(node.clone())?;
267 let record_field_list = record_lit.record_field_list()?; 269 let record_field_list = record_lit.record_expr_field_list()?;
268 for record_field in record_field_list.fields() { 270 for record_field in record_field_list.fields() {
269 if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) { 271 if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) {
270 let field_name = name_ref.syntax().text().to_string(); 272 let field_name = name_ref.syntax().text().to_string();