diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-02 20:20:24 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-02 20:20:24 +0100 |
commit | 7faec1c30046769d4ae490e15cf5405bcfbdeef8 (patch) | |
tree | 6d268b721027a5350928a6c5a0ec227b5fde8ebc /crates/ra_hir/src/source_binder.rs | |
parent | a8397deab914240aca8f015fb3736689919c0a5b (diff) | |
parent | e94587e3153b52684fd3f6b82c8e7efc09ff5c8d (diff) |
Merge #1752
1752: Always wrap blocks into block expressions r=flodiebold a=matklad
This way, things like function bodies are expressions, and we don't have to single them out
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 43aec201a..e5f4d11a6 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -462,8 +462,8 @@ fn scope_for( | |||
462 | node: &SyntaxNode, | 462 | node: &SyntaxNode, |
463 | ) -> Option<ScopeId> { | 463 | ) -> Option<ScopeId> { |
464 | node.ancestors() | 464 | node.ancestors() |
465 | .map(|it| SyntaxNodePtr::new(&it)) | 465 | .filter_map(ast::Expr::cast) |
466 | .filter_map(|ptr| source_map.syntax_expr(ptr)) | 466 | .filter_map(|it| source_map.node_expr(&it)) |
467 | .find_map(|it| scopes.scope_for(it)) | 467 | .find_map(|it| scopes.scope_for(it)) |
468 | } | 468 | } |
469 | 469 | ||
@@ -475,7 +475,10 @@ fn scope_for_offset( | |||
475 | scopes | 475 | scopes |
476 | .scope_by_expr() | 476 | .scope_by_expr() |
477 | .iter() | 477 | .iter() |
478 | .filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope))) | 478 | .filter_map(|(id, scope)| { |
479 | let ast_ptr = source_map.expr_syntax(*id)?.a()?; | ||
480 | Some((ast_ptr.syntax_node_ptr(), scope)) | ||
481 | }) | ||
479 | // find containing scope | 482 | // find containing scope |
480 | .min_by_key(|(ptr, _scope)| { | 483 | .min_by_key(|(ptr, _scope)| { |
481 | (!(ptr.range().start() <= offset && offset <= ptr.range().end()), ptr.range().len()) | 484 | (!(ptr.range().start() <= offset && offset <= ptr.range().end()), ptr.range().len()) |
@@ -495,7 +498,10 @@ fn adjust( | |||
495 | let child_scopes = scopes | 498 | let child_scopes = scopes |
496 | .scope_by_expr() | 499 | .scope_by_expr() |
497 | .iter() | 500 | .iter() |
498 | .filter_map(|(id, scope)| Some((source_map.expr_syntax(*id)?, scope))) | 501 | .filter_map(|(id, scope)| { |
502 | let ast_ptr = source_map.expr_syntax(*id)?.a()?; | ||
503 | Some((ast_ptr.syntax_node_ptr(), scope)) | ||
504 | }) | ||
499 | .map(|(ptr, scope)| (ptr.range(), scope)) | 505 | .map(|(ptr, scope)| (ptr.range(), scope)) |
500 | .filter(|(range, _)| range.start() <= offset && range.is_subrange(&r) && *range != r); | 506 | .filter(|(range, _)| range.start() <= offset && range.is_subrange(&r) && *range != r); |
501 | 507 | ||