let items = t.items(db);
if let Some(field_or_assoc_item) = items.iter().find_map(|assoc_item| {
if let Some(name) = assoc_item.name(db) {
- if link.to_string() == format!("{}::{}", canonical_path, name) {
+ if *link == format!("{}::{}", canonical_path, name) {
return Some(FieldOrAssocItem::AssocItem(*assoc_item));
}
}
let original_token = pick_best(file.token_at_offset(position.offset))?;
let token = sema.descend_into_macros(original_token.clone());
let parent = token.parent();
- if let Some(comment) = ast::Comment::cast(token.clone()) {
+ if let Some(comment) = ast::Comment::cast(token) {
let nav = def_for_doc_comment(&sema, position, &comment)?.try_to_nav(db)?;
return Some(RangeInfo::new(original_token.text_range(), vec![nav]));
}
// FIXME: reimplement this on the hir instead
// as of the time of this writing params in hir don't keep their names
- let fn_ast =
- fn_def.source(sema.db).ok_or(format_err!("Cannot rename non-param local to self"))?.value;
+ let fn_ast = fn_def
+ .source(sema.db)
+ .ok_or_else(|| format_err!("Cannot rename non-param local to self"))?
+ .value;
let first_param_range = fn_ast
.param_list()
// | VS Code | **Rust Analyzer: View Hir**
// |===
pub(crate) fn view_hir(db: &RootDatabase, position: FilePosition) -> String {
- body_hir(db, position).unwrap_or("Not inside a function body".to_string())
+ body_hir(db, position).unwrap_or_else(|| "Not inside a function body".to_string())
}
fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> {
for (file_id, search_range) in search_scope {
let text = sema.db.file_text(file_id);
let search_range =
- search_range.unwrap_or(TextRange::up_to(TextSize::of(text.as_str())));
+ search_range.unwrap_or_else(|| TextRange::up_to(TextSize::of(text.as_str())));
let tree = Lazy::new(|| sema.parse(file_id).syntax().clone());
impl BuildDataCollector {
pub(crate) fn add_config(&mut self, workspace_root: &AbsPath, config: BuildDataConfig) {
- self.configs.insert(workspace_root.to_path_buf().clone(), config);
+ self.configs.insert(workspace_root.to_path_buf(), config);
}
pub fn collect(&mut self, progress: &dyn Fn(String)) -> Result<BuildDataResult> {
.data
.checkOnSave_target
.clone()
- .or(self.data.cargo_target.clone()),
+ .or_else(|| self.data.cargo_target.clone()),
all_targets: self.data.checkOnSave_allTargets,
no_default_features: self
.data
.data
.checkOnSave_features
.clone()
- .unwrap_or(self.data.cargo_features.clone()),
+ .unwrap_or_else(|| self.data.cargo_features.clone()),
extra_args: self.data.checkOnSave_extraArgs.clone(),
},
};
fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json::Value {
for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) {
fn key(f: &str) -> &str {
- f.splitn(2, "_").next().unwrap()
+ f.splitn(2, '_').next().unwrap()
}
assert!(key(f1) <= key(f2), "wrong field order: {:?} {:?}", f1, f2);
}
let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };
- let doc_pos = lsp_types::TextDocumentPositionParams::new(id.clone(), position);
+ let doc_pos = lsp_types::TextDocumentPositionParams::new(id, position);
let goto_params = lsp_types::request::GotoImplementationParams {
- text_document_position_params: doc_pos.clone(),
+ text_document_position_params: doc_pos,
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
};