use crate::{AssistCtx, Assist};
-pub(crate) fn introduce_variable<'a>(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
+pub(crate) fn introduce_variable(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
let node = ctx.covering_node();
if !valid_covering_node(node) {
return None;
/// Check wether the node is a valid expression which can be extracted to a variable.
/// In general that's true for any expression, but in some cases that would produce invalid code.
fn valid_target_expr(node: &SyntaxNode) -> Option<&ast::Expr> {
- return match node.kind() {
+ match node.kind() {
PATH_EXPR => None,
BREAK_EXPR => ast::BreakExpr::cast(node).and_then(|e| e.expr()),
RETURN_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()),
LOOP_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()),
_ => ast::Expr::cast(node),
- };
+ }
}
/// Returns the syntax node which will follow the freshly introduced var
let lit = match child.flavor() {
LiteralFlavor::IntNumber { suffix } => {
let known_name = suffix
- .map(|s| Name::new(s))
+ .map(Name::new)
.and_then(|name| UncertainIntTy::from_name(&name));
Literal::Int(
}
LiteralFlavor::FloatNumber { suffix } => {
let known_name = suffix
- .map(|s| Name::new(s))
+ .map(Name::new)
.and_then(|name| UncertainFloatTy::from_name(&name));
Literal::Float(
}
ast::PatKind::PathPat(p) => {
let path = p.path().and_then(Path::from_ast);
- path.map(|path| Pat::Path(path)).unwrap_or(Pat::Missing)
+ path.map(Pat::Path).unwrap_or(Pat::Missing)
}
ast::PatKind::TuplePat(p) => {
let args = p.args().map(|p| self.collect_pat(p)).collect();
fn add_params_bindings(&mut self, scope: ScopeId, params: &[PatId]) {
let body = Arc::clone(&self.body);
params
- .into_iter()
+ .iter()
.for_each(|pat| self.add_bindings(&body, scope, *pat));
}
})
}
- pub fn scope_for_offset<'a>(&'a self, offset: TextUnit) -> Option<ScopeId> {
+ pub fn scope_for_offset(&self, offset: TextUnit) -> Option<ScopeId> {
self.scopes
.scope_for
.iter()
}
pub fn module(&self) -> Module {
- self.module_impl_blocks.module.clone()
+ self.module_impl_blocks.module
}
pub fn target_trait_ref(&self) -> Option<&TypeRef> {
_ => return PerNs::none(),
};
let module_res = item_map.resolve_path(db, module, path);
- module_res.map(|def| Resolution::Def(def))
+ module_res.map(Resolution::Def)
}
}
Ty::Tuple(ref tuple_args) => &**tuple_args,
_ => &[],
};
- let expectations_iter = expectations.into_iter().chain(repeat(&Ty::Unknown));
+ let expectations_iter = expectations.iter().chain(repeat(&Ty::Unknown));
let inner_tys = args
.iter()
let method_ty = self.insert_type_vars(method_ty);
let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty {
Ty::FnPtr(sig) => {
- if sig.input.len() > 0 {
+ if !sig.input.is_empty() {
(
sig.input[0].clone(),
- sig.input[1..].iter().cloned().collect(),
+ sig.input[1..].to_vec(),
sig.output.clone(),
)
} else {
Ty::FnDef { substs, sig, .. } => {
let ret_ty = sig.output.clone().subst(&substs);
- if sig.input.len() > 0 {
+ if !sig.input.is_empty() {
let mut arg_iter = sig.input.iter().map(|ty| ty.clone().subst(&substs));
let receiver_ty = arg_iter.next().unwrap();
(receiver_ty, arg_iter.collect(), ret_ty)
krate: Crate,
) -> Arc<CrateImplBlocks> {
let mut crate_impl_blocks = CrateImplBlocks {
- krate: krate.clone(),
+ krate,
impls: FxHashMap::default(),
impls_by_trait: FxHashMap::default(),
};
.ancestors()
.take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
.find_map(ast::FnDef::cast);
- match (self.module, self.function_syntax) {
- (Some(module), Some(fn_def)) => {
- let function = source_binder::function_from_module(self.db, module, fn_def);
- self.function = Some(function);
- }
- _ => (),
+ if let (Some(module), Some(fn_def)) = (self.module, self.function_syntax) {
+ let function = source_binder::function_from_module(self.db, module, fn_def);
+ self.function = Some(function);
}
let parent = match name_ref.syntax().parent() {
self.lookup
.as_ref()
.map(|it| it.as_str())
- .unwrap_or(self.label())
+ .unwrap_or_else(|| self.label())
}
pub fn insert_text_format(&self) -> InsertTextFormat {
- self.insert_text_format.clone()
+ self.insert_text_format
}
pub fn insert_text(&self) -> String {
match &self.insert_text {
let def = resolution
.as_ref()
.take_types()
- .or(resolution.as_ref().take_values());
+ .or_else(|| resolution.as_ref().take_values());
let def = match def {
None => return self,
Some(it) => it,
.and_then(hir::Path::from_ast)
{
let resolved = resolver.resolve_path(db, &path);
- match resolved.clone().take_types().or(resolved.take_values()) {
+ match resolved
+ .clone()
+ .take_types()
+ .or_else(|| resolved.take_values())
+ {
Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)),
Some(Resolution::LocalBinding(pat)) => {
let body = resolver.body().expect("no body for local binding");
if !self.libraries_added.is_empty() {
d.field("libraries_added", &self.libraries_added.len());
}
- if !self.crate_graph.is_some() {
+ if self.crate_graph.is_none() {
d.field("crate_graph", &self.crate_graph);
}
d.finish()
};
source_file_edits.push(edit);
- return Some(SourceChange {
+ Some(SourceChange {
label: "rename".to_string(),
source_file_edits,
file_system_edits,
cursor_position: None,
- });
+ })
}
fn rename_reference(
return None;
}
- return Some(SourceChange {
+ Some(SourceChange {
label: "rename".to_string(),
source_file_edits: edit,
file_system_edits: Vec::new(),
cursor_position: None,
- });
+ })
}
#[cfg(test)]
symbols.par_sort_by(cmp);
symbols.dedup_by(|s1, s2| cmp(s1, s2) == Ordering::Equal);
let names = symbols.iter().map(|it| it.name.as_str().to_lowercase());
- let map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap();
+ let map = fst::Map::from_iter(names.zip(0u64..)).unwrap();
SymbolIndex { symbols, map }
}
type Output = Vec<lsp_types::TextEdit>;
fn conv_with(self, line_index: &LineIndex) -> Vec<lsp_types::TextEdit> {
- self.as_atoms()
- .into_iter()
- .map_conv_with(line_index)
- .collect()
+ self.as_atoms().iter().map_conv_with(line_index).collect()
}
}
origin_selection_range: Some(target.range.conv_with(line_index)),
target_uri,
target_range,
- target_selection_range: target_selection_range,
+ target_selection_range,
};
Ok(res)
}
let edit = edit.source_file_edits.pop().unwrap();
let change: Vec<TextEdit> = edit.edit.conv_with(&line_index);
- return Ok(Some(change));
+ Ok(Some(change))
}
pub fn handle_document_symbol(
args: check_args,
env: FxHashMap::default(),
});
- return Ok(res);
+ Ok(res)
}
pub fn handle_decorations(
// Gather runnables
for runnable in world.analysis().runnables(file_id)? {
let title = match &runnable.kind {
- RunnableKind::Test { name: _ } | RunnableKind::TestMod { path: _ } => {
- Some("▶️Run Test")
- }
- RunnableKind::Bench { name: _ } => Some("Run Bench"),
+ RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => Some("▶️Run Test"),
+ RunnableKind::Bench { .. } => Some("Run Bench"),
_ => None,
};
}),
);
- return Ok(Some(lenses));
+ Ok(Some(lenses))
}
#[derive(Debug, Serialize, Deserialize)]
to_value(locations).unwrap(),
]),
};
- return Ok(CodeLens {
+ Ok(CodeLens {
range: code_lens.range,
command: Some(cmd),
data: None,
- });
- }
- None => {
- return Ok(CodeLens {
- range: code_lens.range,
- command: Some(Command {
- title: "Error".into(),
- ..Default::default()
- }),
- data: None,
- });
+ })
}
+ None => Ok(CodeLens {
+ range: code_lens.range,
+ command: Some(Command {
+ title: "Error".into(),
+ ..Default::default()
+ }),
+ data: None,
+ }),
}
}