mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
reformat the world
This commit is contained in:
parent
5cb1d41a30
commit
12e3b4c70b
129 changed files with 727 additions and 2509 deletions
|
@ -74,17 +74,11 @@ impl ExprScopes {
|
|||
}
|
||||
|
||||
fn root_scope(&mut self) -> ScopeId {
|
||||
self.scopes.alloc(ScopeData {
|
||||
parent: None,
|
||||
entries: vec![],
|
||||
})
|
||||
self.scopes.alloc(ScopeData { parent: None, entries: vec![] })
|
||||
}
|
||||
|
||||
fn new_scope(&mut self, parent: ScopeId) -> ScopeId {
|
||||
self.scopes.alloc(ScopeData {
|
||||
parent: Some(parent),
|
||||
entries: vec![],
|
||||
})
|
||||
self.scopes.alloc(ScopeData { parent: Some(parent), entries: vec![] })
|
||||
}
|
||||
|
||||
fn add_bindings(&mut self, body: &Body, scope: ScopeId, pat: PatId) {
|
||||
|
@ -92,10 +86,7 @@ impl ExprScopes {
|
|||
Pat::Bind { name, .. } => {
|
||||
// bind can have a subpattern, but it's actually not allowed
|
||||
// to bind to things in there
|
||||
let entry = ScopeEntry {
|
||||
name: name.clone(),
|
||||
pat,
|
||||
};
|
||||
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)),
|
||||
|
@ -104,9 +95,7 @@ impl ExprScopes {
|
|||
|
||||
fn add_params_bindings(&mut self, scope: ScopeId, params: &[PatId]) {
|
||||
let body = Arc::clone(&self.body);
|
||||
params
|
||||
.iter()
|
||||
.for_each(|pat| self.add_bindings(&body, scope, *pat));
|
||||
params.iter().for_each(|pat| self.add_bindings(&body, scope, *pat));
|
||||
}
|
||||
|
||||
fn set_scope(&mut self, node: ExprId, scope: ScopeId) {
|
||||
|
@ -142,9 +131,7 @@ impl ScopeEntryWithSyntax {
|
|||
|
||||
impl ScopesWithSyntaxMapping {
|
||||
fn scope_chain<'a>(&'a self, node: &SyntaxNode) -> impl Iterator<Item = ScopeId> + 'a {
|
||||
generate(self.scope_for(node), move |&scope| {
|
||||
self.scopes.scopes[scope].parent
|
||||
})
|
||||
generate(self.scope_for(node), move |&scope| self.scopes.scopes[scope].parent)
|
||||
}
|
||||
|
||||
pub fn scope_for_offset(&self, offset: TextUnit) -> Option<ScopeId> {
|
||||
|
@ -154,10 +141,7 @@ impl ScopesWithSyntaxMapping {
|
|||
.filter_map(|(id, scope)| Some((self.syntax_mapping.expr_syntax(*id)?, scope)))
|
||||
// find containing scope
|
||||
.min_by_key(|(ptr, _scope)| {
|
||||
(
|
||||
!(ptr.range().start() <= offset && offset <= ptr.range().end()),
|
||||
ptr.range().len(),
|
||||
)
|
||||
(!(ptr.range().start() <= offset && offset <= ptr.range().end()), ptr.range().len())
|
||||
})
|
||||
.map(|(ptr, scope)| self.adjust(ptr, *scope, offset))
|
||||
}
|
||||
|
@ -251,9 +235,7 @@ fn compute_block_scopes(
|
|||
) {
|
||||
for stmt in statements {
|
||||
match stmt {
|
||||
Statement::Let {
|
||||
pat, initializer, ..
|
||||
} => {
|
||||
Statement::Let { pat, initializer, .. } => {
|
||||
if let Some(expr) = initializer {
|
||||
scopes.set_scope(*expr, scope);
|
||||
compute_expr_scopes(*expr, body, scopes, scope);
|
||||
|
@ -278,21 +260,13 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
|
|||
Expr::Block { statements, tail } => {
|
||||
compute_block_scopes(&statements, *tail, body, scopes, scope);
|
||||
}
|
||||
Expr::For {
|
||||
iterable,
|
||||
pat,
|
||||
body: body_expr,
|
||||
} => {
|
||||
Expr::For { iterable, pat, body: body_expr } => {
|
||||
compute_expr_scopes(*iterable, body, scopes, scope);
|
||||
let scope = scopes.new_scope(scope);
|
||||
scopes.add_bindings(body, scope, *pat);
|
||||
compute_expr_scopes(*body_expr, body, scopes, scope);
|
||||
}
|
||||
Expr::Lambda {
|
||||
args,
|
||||
body: body_expr,
|
||||
..
|
||||
} => {
|
||||
Expr::Lambda { args, body: body_expr, .. } => {
|
||||
let scope = scopes.new_scope(scope);
|
||||
scopes.add_params_bindings(scope, &args);
|
||||
compute_expr_scopes(*body_expr, body, scopes, scope);
|
||||
|
@ -341,9 +315,7 @@ mod tests {
|
|||
let file = SourceFile::parse(&code);
|
||||
let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
|
||||
let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
|
||||
let irrelevant_function = Function {
|
||||
id: crate::ids::FunctionId::from_raw(0.into()),
|
||||
};
|
||||
let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
|
||||
let body_hir = expr::collect_fn_body_syntax(irrelevant_function, fn_def);
|
||||
let scopes = ExprScopes::new(Arc::clone(body_hir.body()));
|
||||
let scopes = ScopesWithSyntaxMapping {
|
||||
|
@ -444,9 +416,7 @@ mod tests {
|
|||
let fn_def: &ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
|
||||
let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
|
||||
|
||||
let irrelevant_function = Function {
|
||||
id: crate::ids::FunctionId::from_raw(0.into()),
|
||||
};
|
||||
let irrelevant_function = Function { id: crate::ids::FunctionId::from_raw(0.into()) };
|
||||
let body_hir = expr::collect_fn_body_syntax(irrelevant_function, fn_def);
|
||||
let scopes = ExprScopes::new(Arc::clone(body_hir.body()));
|
||||
let scopes = ScopesWithSyntaxMapping {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue