Merge #4969
4969: Handle bindings after @ in patterns r=flodiebold a=jonas-schievink This is unstable, behind the `bindings_after_at` feature gate, but the semantics are fairly clear, and this is used at lot in rustc. Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
f9dffade9d
@ -87,15 +87,13 @@ fn new_scope(&mut self, parent: ScopeId) -> ScopeId {
|
||||
}
|
||||
|
||||
fn add_bindings(&mut self, body: &Body, scope: ScopeId, pat: PatId) {
|
||||
match &body[pat] {
|
||||
Pat::Bind { name, .. } => {
|
||||
// bind can have a sub pattern, but it's actually not allowed
|
||||
// to bind to things in there
|
||||
let entry = ScopeEntry { name: name.clone(), pat };
|
||||
self.scopes[scope].entries.push(entry)
|
||||
}
|
||||
p => p.walk_child_pats(|pat| self.add_bindings(body, scope, pat)),
|
||||
let pattern = &body[pat];
|
||||
if let Pat::Bind { name, .. } = pattern {
|
||||
let entry = ScopeEntry { name: name.clone(), pat };
|
||||
self.scopes[scope].entries.push(entry);
|
||||
}
|
||||
|
||||
pattern.walk_child_pats(|pat| self.add_bindings(body, scope, pat));
|
||||
}
|
||||
|
||||
fn add_params_bindings(&mut self, body: &Body, scope: ScopeId, params: &[PatId]) {
|
||||
@ -190,8 +188,8 @@ fn find_function(db: &TestDB, file_id: FileId) -> FunctionId {
|
||||
}
|
||||
}
|
||||
|
||||
fn do_check(code: &str, expected: &[&str]) {
|
||||
let (off, code) = extract_offset(code);
|
||||
fn do_check(ra_fixture: &str, expected: &[&str]) {
|
||||
let (off, code) = extract_offset(ra_fixture);
|
||||
let code = {
|
||||
let mut buf = String::new();
|
||||
let off: usize = off.into();
|
||||
@ -300,6 +298,22 @@ fn foo(x: String) {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bindings_after_at() {
|
||||
do_check(
|
||||
r"
|
||||
fn foo() {
|
||||
match Some(()) {
|
||||
opt @ Some(unit) => {
|
||||
<|>
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}",
|
||||
&["opt", "unit"],
|
||||
);
|
||||
}
|
||||
|
||||
fn do_check_local_name(code: &str, expected_offset: u32) {
|
||||
let (off, code) = extract_offset(code);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user