mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
removing unwraps
This commit is contained in:
parent
50c913c733
commit
4896ffb65c
3 changed files with 30 additions and 34 deletions
|
@ -5,7 +5,7 @@ exclude = ["crates/proc_macro_test/imp"]
|
|||
[profile.dev]
|
||||
# Disabling debug info speeds up builds a bunch,
|
||||
# and we don't rely on it for debugging that much.
|
||||
debug = 2
|
||||
debug = 0
|
||||
|
||||
[profile.dev.package]
|
||||
# These speed up local tests.
|
||||
|
|
|
@ -484,9 +484,6 @@ impl FunctionBody {
|
|||
}
|
||||
}
|
||||
|
||||
// selection: 36..67
|
||||
// resulting: 57..67
|
||||
|
||||
fn from_range(parent: ast::StmtList, selected: TextRange) -> FunctionBody {
|
||||
let full_body = parent.syntax().children_with_tokens();
|
||||
for st in parent.syntax().children_with_tokens() {
|
||||
|
@ -1468,33 +1465,32 @@ fn make_body(
|
|||
.map(|it| match it {
|
||||
syntax::NodeOrToken::Node(n) => {
|
||||
println!("Found node: {:?}", n);
|
||||
return syntax::NodeOrToken::try_from(rewrite_body_segment(
|
||||
ctx,
|
||||
&fun.params,
|
||||
&handler,
|
||||
&n,
|
||||
))
|
||||
.unwrap()
|
||||
let node_rewritten = rewrite_body_segment(ctx, &fun.params, &handler, &n);
|
||||
|
||||
syntax::NodeOrToken::Node(node_rewritten)
|
||||
}
|
||||
syntax::NodeOrToken::Token(t) => {
|
||||
println!("Found token: {:?}", t);
|
||||
return syntax::NodeOrToken::try_from(t).unwrap()
|
||||
syntax::NodeOrToken::Token(t)
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut tail_expr = match elements.pop() {
|
||||
Some(node) if node.as_node().is_some() => {
|
||||
ast::Expr::cast(node.as_node().unwrap().clone()).or_else(|| {
|
||||
elements.push(node);
|
||||
Some(element) => match element {
|
||||
syntax::NodeOrToken::Node(node) => {
|
||||
ast::Expr::cast(node.clone()).or_else(|| {
|
||||
elements.push(syntax::NodeOrToken::Node(node));
|
||||
None
|
||||
})
|
||||
}
|
||||
syntax::NodeOrToken::Token(token) if token.kind() == COMMENT => {
|
||||
elements.push(syntax::NodeOrToken::Token(token));
|
||||
None
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
Some(token) if token.as_token().is_some() && token.as_token().unwrap().kind() == COMMENT => {
|
||||
elements.push(token);
|
||||
None
|
||||
},
|
||||
_ => None,
|
||||
None => None,
|
||||
};
|
||||
|
||||
if tail_expr.is_none() {
|
||||
|
@ -1510,19 +1506,20 @@ fn make_body(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let body_indent = IndentLevel(1);
|
||||
let elements: Vec<SyntaxElement> = elements.into_iter().map(|stmt| {
|
||||
match stmt {
|
||||
let elements: Vec<SyntaxElement> = elements
|
||||
.into_iter()
|
||||
.map(|stmt| match stmt {
|
||||
syntax::NodeOrToken::Node(n) => {
|
||||
let ast_element = ast::Stmt::cast(n).unwrap();
|
||||
let indented = ast_element.dedent(old_indent).indent(body_indent);
|
||||
let ast_node = indented.syntax().clone_subtree();
|
||||
syntax::NodeOrToken::try_from(ast_node).unwrap()
|
||||
},
|
||||
syntax::NodeOrToken::Token(t) => syntax::NodeOrToken::try_from(t).unwrap()
|
||||
}
|
||||
}).collect::<Vec<SyntaxElement>>();
|
||||
}
|
||||
syntax::NodeOrToken::Token(t) => syntax::NodeOrToken::try_from(t).unwrap(),
|
||||
})
|
||||
.collect::<Vec<SyntaxElement>>();
|
||||
let tail_expr = tail_expr.map(|expr| expr.dedent(old_indent).indent(body_indent));
|
||||
|
||||
for element in &elements {
|
||||
|
@ -1531,8 +1528,6 @@ fn make_body(
|
|||
|
||||
make::block_expr_full(elements, tail_expr)
|
||||
|
||||
|
||||
|
||||
// make::block_expr(parent.statements().into_iter(), tail_expr)
|
||||
}
|
||||
};
|
||||
|
|
|
@ -335,14 +335,15 @@ pub fn block_expr_full(
|
|||
) -> ast::BlockExpr {
|
||||
let mut buf = "{\n".to_string();
|
||||
for stmt in stmts.into_iter() {
|
||||
|
||||
match stmt {
|
||||
rowan::NodeOrToken::Node(n) => {
|
||||
println!("Node: {:?}", n.text());
|
||||
format_to!(buf, " {}\n", n)
|
||||
},
|
||||
rowan::NodeOrToken::Token(t) if t.kind() == SyntaxKind::COMMENT => format_to!(buf, " {}\n", t),
|
||||
_ => ()
|
||||
}
|
||||
rowan::NodeOrToken::Token(t) if t.kind() == SyntaxKind::COMMENT => {
|
||||
format_to!(buf, " {}\n", t)
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
if let Some(tail_expr) = tail_expr {
|
||||
|
|
Loading…
Reference in a new issue