Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir-def/src/expr_store/lower.rs7
-rw-r--r--crates/ide-diagnostics/src/handlers/pattern_arg_in_extern_fn.rs18
2 files changed, 22 insertions, 3 deletions
diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs
index 7fd635c89a..ef88188572 100644
--- a/crates/hir-def/src/expr_store/lower.rs
+++ b/crates/hir-def/src/expr_store/lower.rs
@@ -2570,9 +2570,9 @@ impl<'db> ExprCollector<'db> {
}
fn collect_extern_fn_param(&mut self, pat: Option<ast::Pat>) -> PatId {
- // `extern` functions cannot have pattern-matched parameters, and furthermore, the identifiers
- // in their parameters are always interpreted as bindings, even if in a normal function they
- // won't be, because they would refer to a path pattern.
+ // parameters of functions in `extern` blocks can only be simple identifiers and wildcards.
+ // Furthermore, the identifiers in their parameters are always interpreted as bindings, even
+ // if in a normal function they won't be, because they would refer to a path pattern.
let Some(pat) = pat else { return self.missing_pat() };
match &pat {
@@ -2588,6 +2588,7 @@ impl<'db> ExprCollector<'db> {
self.add_definition_to_binding(binding, pat);
pat
}
+ ast::Pat::WildcardPat(_) => self.alloc_pat(Pat::Wild, AstPtr::new(&pat)),
_ => {
self.store.diagnostics.push(ExpressionStoreDiagnostics::PatternArgInExternFn {
node: self.expander.in_file(AstPtr::new(&pat)),
diff --git a/crates/ide-diagnostics/src/handlers/pattern_arg_in_extern_fn.rs b/crates/ide-diagnostics/src/handlers/pattern_arg_in_extern_fn.rs
index 459ec175b1..8a54834361 100644
--- a/crates/ide-diagnostics/src/handlers/pattern_arg_in_extern_fn.rs
+++ b/crates/ide-diagnostics/src/handlers/pattern_arg_in_extern_fn.rs
@@ -21,6 +21,24 @@ mod tests {
use crate::tests::check_diagnostics;
#[test]
+ fn ident_pattern_allowed() {
+ check_diagnostics(
+ r#"
+unsafe extern { fn foo(a: i32); }
+ "#,
+ );
+ }
+
+ #[test]
+ fn wildcard_pattern_allowed() {
+ check_diagnostics(
+ r#"
+unsafe extern { fn foo(_: i32); }
+ "#,
+ );
+ }
+
+ #[test]
fn tuple_pattern() {
check_diagnostics(
r#"