Skip to content

feat: add diagnostic for E0422#22393

Open
WeiTheShinobi wants to merge 4 commits into
rust-lang:masterfrom
WeiTheShinobi:e0422
Open

feat: add diagnostic for E0422#22393
WeiTheShinobi wants to merge 4 commits into
rust-lang:masterfrom
WeiTheShinobi:e0422

Conversation

@WeiTheShinobi
Copy link
Copy Markdown
Contributor

Related to #22140

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 17, 2026
Comment thread crates/hir-ty/src/infer/expr.rs Outdated
// Find the relevant variant
let (adt_ty, Some(variant)) = self.resolve_variant(expr.into(), path, false) else {
// FIXME: Emit an error.
self.push_diagnostic(InferenceDiagnostic::UnresolvedRecordExpr { expr });
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 17, 2026

Choose a reason for hiding this comment

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

I know there was a FIXME, but I think the error should go inside resolve_variant(), which will also fix it for patterns.

View changes since the review

@@ -0,0 +1,45 @@
use either::Either;
use syntax::{AstNode, ast::Expr};
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 17, 2026

Choose a reason for hiding this comment

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

By convention we don't use specific ast nodes, instead we refer to them as ast::Node.

View changes since the review

"cannot find struct, variant or union type in this scope".to_owned(),
crate::adjusted_display_range(ctx, d.expr, &|expr| match expr {
Either::Left(Expr::RecordExpr(it)) => it.path().map(|p| p.syntax().text_range()),
_ => None,
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 17, 2026

Choose a reason for hiding this comment

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

If you emit the error in resolve_variant(), you also need to account for ast::Pat::{RecordPat,TupleStructPat}.

View changes since the review

let (resolution, unresolved) = if value_ns {
let Some(res) = path_ctx.resolve_path_in_value_ns(HygieneId::ROOT) else {
drop(ctx);
self.push_diagnostic(InferenceDiagnostic::UnresolvedVariant { id: node });
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 May 20, 2026

Choose a reason for hiding this comment

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

Sorry about this, but IMO this is still not the right place. We should emit an error in resolve_path_in_X(), and I don't know if we should do it yet.

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also there are more cases in this method after resolution.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry about this, but IMO this is still not the right place. We should emit an error in resolve_path_in_X(), and I don't know if we should do it yet.

View changes since the review

I found that if I emit diagnostics in resolve_path_in_value_ns and resolve_path_in_type_ns, different call sites need different error code (for example, another resolve_path_in_type_ns call site need E0425 rather than E0422). I feel like there is no proper place for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First, the error codes are not set in stone. The code organization is more important. Second, we can pass this information from the outside.

But as I said, I am not sure we should do this yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants