Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions crates/hir-ty/src/diagnostics/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,6 @@ impl<'db> ExprValidator<'db> {
}

for (id, expr) in body.exprs() {
if let Some((variant, missed_fields)) =
record_literal_missing_fields(db, self.infer, id, expr)
{
self.diagnostics.push(BodyValidationDiagnostic::RecordMissingFields {
record: Either::Left(id),
variant,
missed_fields,
});
}

match expr {
Expr::Match { expr, arms } => {
self.validate_match(id, *expr, arms);
Expand Down
8 changes: 8 additions & 0 deletions crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ pub enum InferenceDiagnostic {
#[type_visitable(ignore)]
variant: VariantId,
},
MissingFields {
#[type_visitable(ignore)]
expr: ExprId,
#[type_visitable(ignore)]
fields: Vec<LocalFieldId>,
#[type_visitable(ignore)]
variant: VariantId,
},
PrivateField {
#[type_visitable(ignore)]
expr: ExprId,
Expand Down
14 changes: 12 additions & 2 deletions crates/hir-ty/src/infer/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,11 @@ impl<'db> InferenceContext<'_, 'db> {
}
}
if !missing_mandatory_fields.is_empty() {
// FIXME: Emit an error: missing fields.
self.push_diagnostic(InferenceDiagnostic::MissingFields {
expr,
fields: missing_mandatory_fields,
variant,
});
}
}
RecordSpread::Expr(base_expr) => {
Expand Down Expand Up @@ -1182,7 +1186,13 @@ impl<'db> InferenceContext<'_, 'db> {
{
debug!(?remaining_fields);

// FIXME: Emit an error: missing fields.
let missing_fields = remaining_fields.values().copied().collect();

self.push_diagnostic(InferenceDiagnostic::MissingFields {
expr,
fields: missing_fields,
variant,
});
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions crates/hir/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,38 @@ impl<'db> AnyDiagnostic<'db> {
};
DuplicateField { field: expr_or_pat, variant: variant.into() }.into()
}
InferenceDiagnostic::MissingFields { expr, fields, variant } => {
let variant_data = variant.fields(db);
let missed_fields = fields
.iter()
.map(|&idx| {
(
variant_data.fields()[idx].name.clone(),
Field { parent: (*variant).into(), id: idx },
)
})
.collect();

let record = expr_syntax(*expr)?;
let file = record.file_id;
let root = record.file_syntax(db);
let Either::Left(ast::Expr::RecordExpr(record_expr)) = record.value.to_node(&root)
else {
never!("should always map to a `ast::RecordExpr`");
return None;
Comment thread
Twil3akine marked this conversation as resolved.
};

record_expr.record_expr_field_list()?;

let field_list_parent_path = record_expr.path().map(|path| AstPtr::new(&path));
MissingFields {
file,
field_list_parent: AstPtr::new(&Either::Left(record_expr)),
field_list_parent_path,
missed_fields,
}
.into()
}
&InferenceDiagnostic::MismatchedArgCount { call_expr, expected, found } => {
MismatchedArgCount { call_expr: expr_syntax(call_expr)?, expected, found }.into()
}
Expand Down
19 changes: 17 additions & 2 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ use hir_expand::{
proc_macro::ProcMacroKind,
};
use hir_ty::{
GenericPredicates, InferBodyId, InferenceResult, ParamEnvAndCrate, TyDefId,
TyLoweringDiagnostic, ValueTyDefId, all_super_traits, autoderef, check_orphan_rules,
GenericPredicates, InferBodyId, InferenceDiagnostic, InferenceResult, ParamEnvAndCrate,
TyDefId, TyLoweringDiagnostic, ValueTyDefId, all_super_traits, autoderef, check_orphan_rules,
consteval::try_const_usize,
db::{AnonConstId, InternedClosure, InternedClosureId, InternedCoroutineClosureId},
diagnostics::BodyValidationDiagnostic,
Expand Down Expand Up @@ -2191,7 +2191,12 @@ impl DefWithBody {
expr_store_diagnostics(db, acc, source_map);

let infer = InferenceResult::of(db, id);
let mut delayed_missing_fields_diagnostics = Vec::new();
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you delay this? I see no reason for that.

View changes since the review

for d in infer.diagnostics() {
if matches!(d, InferenceDiagnostic::MissingFields { .. }) {
delayed_missing_fields_diagnostics.push(d);
continue;
}
acc.extend(AnyDiagnostic::inference_diagnostic(
db,
id,
Expand Down Expand Up @@ -2352,6 +2357,16 @@ impl DefWithBody {
for diagnostic in BodyValidationDiagnostic::collect(db, id, style_lints) {
acc.extend(AnyDiagnostic::body_validation_diagnostic(db, diagnostic, source_map));
}
for d in delayed_missing_fields_diagnostics {
acc.extend(AnyDiagnostic::inference_diagnostic(
db,
id,
d,
source_map,
sig_source_map,
env,
));
}

for diag in hir_ty::diagnostics::incorrect_case(db, id.into()) {
acc.push(diag.into())
Expand Down
Loading