Skip to content

Commit 500d8b2

Browse files
Handle bindings after @ in patterns
1 parent 6d0a765 commit 500d8b2

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

crates/ra_hir_def/src/body/scope.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,13 @@ impl ExprScopes {
8787
}
8888

8989
fn add_bindings(&mut self, body: &Body, scope: ScopeId, pat: PatId) {
90-
match &body[pat] {
91-
Pat::Bind { name, .. } => {
92-
// bind can have a sub pattern, but it's actually not allowed
93-
// to bind to things in there
94-
let entry = ScopeEntry { name: name.clone(), pat };
95-
self.scopes[scope].entries.push(entry)
96-
}
97-
p => p.walk_child_pats(|pat| self.add_bindings(body, scope, pat)),
90+
let pattern = &body[pat];
91+
if let Pat::Bind { name, .. } = pattern {
92+
let entry = ScopeEntry { name: name.clone(), pat };
93+
self.scopes[scope].entries.push(entry);
9894
}
95+
96+
pattern.walk_child_pats(|pat| self.add_bindings(body, scope, pat));
9997
}
10098

10199
fn add_params_bindings(&mut self, body: &Body, scope: ScopeId, params: &[PatId]) {
@@ -190,8 +188,8 @@ mod tests {
190188
}
191189
}
192190

193-
fn do_check(code: &str, expected: &[&str]) {
194-
let (off, code) = extract_offset(code);
191+
fn do_check(ra_fixture: &str, expected: &[&str]) {
192+
let (off, code) = extract_offset(ra_fixture);
195193
let code = {
196194
let mut buf = String::new();
197195
let off: usize = off.into();
@@ -300,6 +298,22 @@ mod tests {
300298
);
301299
}
302300

301+
#[test]
302+
fn test_bindings_after_at() {
303+
do_check(
304+
r"
305+
fn foo() {
306+
match Some(()) {
307+
opt @ Some(unit) => {
308+
<|>
309+
}
310+
_ => {}
311+
}
312+
}",
313+
&["opt", "unit"],
314+
);
315+
}
316+
303317
fn do_check_local_name(code: &str, expected_offset: u32) {
304318
let (off, code) = extract_offset(code);
305319

0 commit comments

Comments
 (0)