-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: add diagnostic for E0422 #22393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| use either::Either; | ||
| use syntax::{AstNode, ast::Expr}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By convention we don't |
||
|
|
||
| use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext}; | ||
|
|
||
| // Diagnostic: unresolved-record-expr | ||
| // | ||
| // This diagnostic is triggered if the struct, variant, or union type referred to by a record expression does not exist in the current scope. | ||
| pub(crate) fn unresolved_record_expr( | ||
| ctx: &DiagnosticsContext<'_, '_>, | ||
| d: &hir::UnresolvedRecordExpr, | ||
| ) -> Diagnostic { | ||
| Diagnostic::new( | ||
| DiagnosticCode::RustcHardError("E0422"), | ||
| "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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you emit the error in |
||
| }), | ||
| ) | ||
| .stable() | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::tests::check_diagnostics; | ||
|
|
||
| #[test] | ||
| fn unresolved_record_expr() { | ||
| check_diagnostics( | ||
| r#" | ||
| struct Exist { | ||
| x: i32, | ||
| y: i32, | ||
| } | ||
|
|
||
| fn main() { | ||
| let _ = Exist { x: 1, y: 2 }; | ||
| let _ = DoesNotExist { x: 1, y: 2 }; | ||
| // ^^^^^^^^^^^^ error: cannot find struct, variant or union type in this scope | ||
| } | ||
| "#, | ||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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