aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir/src/lib.rs3
-rw-r--r--crates/hir_expand/src/builtin_derive.rs2
-rw-r--r--crates/ide/src/join_lines.rs4
-rw-r--r--crates/ide/src/references.rs26
-rw-r--r--crates/ide/src/references/rename.rs3
-rw-r--r--crates/ide/src/typing.rs3
-rw-r--r--crates/ide_completion/src/completions/postfix/format_like.rs2
-rw-r--r--crates/ide_db/src/defs.rs2
-rw-r--r--crates/ide_db/src/search.rs16
-rw-r--r--crates/mbe/src/syntax_bridge.rs8
-rw-r--r--crates/proc_macro_api/src/version.rs4
-rw-r--r--crates/project_model/src/rustc_cfg.rs2
-rw-r--r--crates/rust-analyzer/src/handlers.rs20
-rw-r--r--crates/rust-analyzer/src/lsp_utils.rs4
14 files changed, 59 insertions, 40 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index eb1cd66fb..caa760d21 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -266,8 +266,7 @@ impl ModuleDef {
266 } 266 }
267 267
268 pub fn canonical_path(&self, db: &dyn HirDatabase) -> Option<String> { 268 pub fn canonical_path(&self, db: &dyn HirDatabase) -> Option<String> {
269 let mut segments = Vec::new(); 269 let mut segments = vec![self.name(db)?.to_string()];
270 segments.push(self.name(db)?.to_string());
271 for m in self.module(db)?.path_to_root(db) { 270 for m in self.module(db)?.path_to_root(db) {
272 segments.extend(m.name(db).map(|it| it.to_string())) 271 segments.extend(m.name(db).map(|it| it.to_string()))
273 } 272 }
diff --git a/crates/hir_expand/src/builtin_derive.rs b/crates/hir_expand/src/builtin_derive.rs
index dfdb9cf59..5e908b223 100644
--- a/crates/hir_expand/src/builtin_derive.rs
+++ b/crates/hir_expand/src/builtin_derive.rs
@@ -108,7 +108,7 @@ fn parse_adt(tt: &tt::Subtree) -> Result<BasicAdtInfo, mbe::ExpandError> {
108} 108}
109 109
110fn make_type_args(n: usize, bound: Vec<tt::TokenTree>) -> Vec<tt::TokenTree> { 110fn make_type_args(n: usize, bound: Vec<tt::TokenTree>) -> Vec<tt::TokenTree> {
111 let mut result = Vec::<tt::TokenTree>::new(); 111 let mut result = Vec::<tt::TokenTree>::with_capacity(n * 2);
112 result.push( 112 result.push(
113 tt::Leaf::Punct(tt::Punct { 113 tt::Leaf::Punct(tt::Punct {
114 char: '<', 114 char: '<',
diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs
index 20a920ddb..d571ed559 100644
--- a/crates/ide/src/join_lines.rs
+++ b/crates/ide/src/join_lines.rs
@@ -218,7 +218,7 @@ mod tests {
218 let result = join_lines(&file, range); 218 let result = join_lines(&file, range);
219 219
220 let actual = { 220 let actual = {
221 let mut actual = before.to_string(); 221 let mut actual = before;
222 result.apply(&mut actual); 222 result.apply(&mut actual);
223 actual 223 actual
224 }; 224 };
@@ -622,7 +622,7 @@ fn foo() {
622 let parse = SourceFile::parse(&before); 622 let parse = SourceFile::parse(&before);
623 let result = join_lines(&parse.tree(), sel); 623 let result = join_lines(&parse.tree(), sel);
624 let actual = { 624 let actual = {
625 let mut actual = before.to_string(); 625 let mut actual = before;
626 result.apply(&mut actual); 626 result.apply(&mut actual);
627 actual 627 actual
628 }; 628 };
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index fef70533d..ec7c7686d 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -29,7 +29,7 @@ use crate::{display::TryToNav, FilePosition, NavigationTarget};
29 29
30#[derive(Debug, Clone)] 30#[derive(Debug, Clone)]
31pub struct ReferenceSearchResult { 31pub struct ReferenceSearchResult {
32 pub declaration: Declaration, 32 pub declaration: Option<Declaration>,
33 pub references: FxHashMap<FileId, Vec<(TextRange, Option<ReferenceAccess>)>>, 33 pub references: FxHashMap<FileId, Vec<(TextRange, Option<ReferenceAccess>)>>,
34} 34}
35 35
@@ -91,10 +91,10 @@ pub(crate) fn find_all_refs(
91 _ => {} 91 _ => {}
92 } 92 }
93 } 93 }
94 let nav = def.try_to_nav(sema.db)?; 94 let declaration = def.try_to_nav(sema.db).map(|nav| {
95 let decl_range = nav.focus_or_full_range(); 95 let decl_range = nav.focus_or_full_range();
96 96 Declaration { nav, access: decl_access(&def, &syntax, decl_range) }
97 let declaration = Declaration { nav, access: decl_access(&def, &syntax, decl_range) }; 97 });
98 let references = usages 98 let references = usages
99 .into_iter() 99 .into_iter()
100 .map(|(file_id, refs)| { 100 .map(|(file_id, refs)| {
@@ -1004,8 +1004,7 @@ impl Foo {
1004 let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap(); 1004 let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap();
1005 1005
1006 let mut actual = String::new(); 1006 let mut actual = String::new();
1007 { 1007 if let Some(decl) = refs.declaration {
1008 let decl = refs.declaration;
1009 format_to!(actual, "{}", decl.nav.debug_render()); 1008 format_to!(actual, "{}", decl.nav.debug_render());
1010 if let Some(access) = decl.access { 1009 if let Some(access) = decl.access {
1011 format_to!(actual, " {:?}", access) 1010 format_to!(actual, " {:?}", access)
@@ -1258,4 +1257,17 @@ fn main() {
1258 "#]], 1257 "#]],
1259 ); 1258 );
1260 } 1259 }
1260
1261 #[test]
1262 fn test_primitives() {
1263 check(
1264 r#"
1265fn foo(_: bool) -> bo$0ol { true }
1266"#,
1267 expect![[r#"
1268 FileId(0) 10..14
1269 FileId(0) 19..23
1270 "#]],
1271 );
1272 }
1261} 1273}
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs
index 1e378279d..5340b638a 100644
--- a/crates/ide/src/references/rename.rs
+++ b/crates/ide/src/references/rename.rs
@@ -510,7 +510,8 @@ fn source_edit_from_def(
510 def: Definition, 510 def: Definition,
511 new_name: &str, 511 new_name: &str,
512) -> RenameResult<(FileId, TextEdit)> { 512) -> RenameResult<(FileId, TextEdit)> {
513 let nav = def.try_to_nav(sema.db).unwrap(); 513 let nav =
514 def.try_to_nav(sema.db).ok_or_else(|| format_err!("No references found at position"))?;
514 515
515 let mut replacement_text = String::new(); 516 let mut replacement_text = String::new();
516 let mut repl_range = nav.focus_or_full_range(); 517 let mut repl_range = nav.focus_or_full_range();
diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs
index e3c3aebac..a718faf63 100644
--- a/crates/ide/src/typing.rs
+++ b/crates/ide/src/typing.rs
@@ -145,9 +145,8 @@ mod tests {
145 use super::*; 145 use super::*;
146 146
147 fn do_type_char(char_typed: char, before: &str) -> Option<String> { 147 fn do_type_char(char_typed: char, before: &str) -> Option<String> {
148 let (offset, before) = extract_offset(before); 148 let (offset, mut before) = extract_offset(before);
149 let edit = TextEdit::insert(offset, char_typed.to_string()); 149 let edit = TextEdit::insert(offset, char_typed.to_string());
150 let mut before = before.to_string();
151 edit.apply(&mut before); 150 edit.apply(&mut before);
152 let parse = SourceFile::parse(&before); 151 let parse = SourceFile::parse(&before);
153 on_char_typed_inner(&parse.tree(), offset, char_typed).map(|it| { 152 on_char_typed_inner(&parse.tree(), offset, char_typed).map(|it| {
diff --git a/crates/ide_completion/src/completions/postfix/format_like.rs b/crates/ide_completion/src/completions/postfix/format_like.rs
index 3afc63021..cee4eec10 100644
--- a/crates/ide_completion/src/completions/postfix/format_like.rs
+++ b/crates/ide_completion/src/completions/postfix/format_like.rs
@@ -59,7 +59,7 @@ pub(crate) fn add_format_like_completions(
59/// Checks whether provided item is a string literal. 59/// Checks whether provided item is a string literal.
60fn string_literal_contents(item: &ast::String) -> Option<String> { 60fn string_literal_contents(item: &ast::String) -> Option<String> {
61 let item = item.text(); 61 let item = item.text();
62 if item.len() >= 2 && item.starts_with("\"") && item.ends_with("\"") { 62 if item.len() >= 2 && item.starts_with('\"') && item.ends_with('\"') {
63 return Some(item[1..item.len() - 1].to_owned()); 63 return Some(item[1..item.len() - 1].to_owned());
64 } 64 }
65 65
diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs
index ff612b7d0..f86e5ce93 100644
--- a/crates/ide_db/src/defs.rs
+++ b/crates/ide_db/src/defs.rs
@@ -70,7 +70,7 @@ impl Definition {
70 hir::ModuleDef::Static(it) => it.name(db)?, 70 hir::ModuleDef::Static(it) => it.name(db)?,
71 hir::ModuleDef::Trait(it) => it.name(db), 71 hir::ModuleDef::Trait(it) => it.name(db),
72 hir::ModuleDef::TypeAlias(it) => it.name(db), 72 hir::ModuleDef::TypeAlias(it) => it.name(db),
73 hir::ModuleDef::BuiltinType(_) => return None, 73 hir::ModuleDef::BuiltinType(it) => it.name(),
74 }, 74 },
75 Definition::SelfType(_) => return None, 75 Definition::SelfType(_) => return None,
76 Definition::Local(it) => it.name(db)?, 76 Definition::Local(it) => it.name(db)?,
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index fa18703e1..d00a8b6e7 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -6,7 +6,7 @@
6 6
7use std::{convert::TryInto, mem}; 7use std::{convert::TryInto, mem};
8 8
9use base_db::{FileId, FileRange, SourceDatabaseExt}; 9use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt};
10use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility}; 10use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility};
11use once_cell::unsync::Lazy; 11use once_cell::unsync::Lazy;
12use rustc_hash::FxHashMap; 12use rustc_hash::FxHashMap;
@@ -138,6 +138,20 @@ impl IntoIterator for SearchScope {
138impl Definition { 138impl Definition {
139 fn search_scope(&self, db: &RootDatabase) -> SearchScope { 139 fn search_scope(&self, db: &RootDatabase) -> SearchScope {
140 let _p = profile::span("search_scope"); 140 let _p = profile::span("search_scope");
141
142 if let Definition::ModuleDef(hir::ModuleDef::BuiltinType(_)) = self {
143 let mut res = FxHashMap::default();
144
145 let graph = db.crate_graph();
146 for krate in graph.iter() {
147 let root_file = graph[krate].root_file_id;
148 let source_root_id = db.file_source_root(root_file);
149 let source_root = db.source_root(source_root_id);
150 res.extend(source_root.iter().map(|id| (id, None)));
151 }
152 return SearchScope::new(res);
153 }
154
141 let module = match self.module(db) { 155 let module = match self.module(db) {
142 Some(it) => it, 156 Some(it) => it,
143 None => return SearchScope::empty(), 157 None => return SearchScope::empty(),
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs
index aacae1026..b715ebfc4 100644
--- a/crates/mbe/src/syntax_bridge.rs
+++ b/crates/mbe/src/syntax_bridge.rs
@@ -222,14 +222,10 @@ fn convert_doc_comment(token: &syntax::SyntaxToken) -> Option<Vec<tt::TokenTree>
222 let doc = comment.kind().doc?; 222 let doc = comment.kind().doc?;
223 223
224 // Make `doc="\" Comments\"" 224 // Make `doc="\" Comments\""
225 let mut meta_tkns = Vec::new(); 225 let meta_tkns = vec![mk_ident("doc"), mk_punct('='), mk_doc_literal(&comment)];
226 meta_tkns.push(mk_ident("doc"));
227 meta_tkns.push(mk_punct('='));
228 meta_tkns.push(mk_doc_literal(&comment));
229 226
230 // Make `#![]` 227 // Make `#![]`
231 let mut token_trees = Vec::new(); 228 let mut token_trees = vec![mk_punct('#')];
232 token_trees.push(mk_punct('#'));
233 if let ast::CommentPlacement::Inner = doc { 229 if let ast::CommentPlacement::Inner = doc {
234 token_trees.push(mk_punct('!')); 230 token_trees.push(mk_punct('!'));
235 } 231 }
diff --git a/crates/proc_macro_api/src/version.rs b/crates/proc_macro_api/src/version.rs
index 11a7fb59a..b903658fb 100644
--- a/crates/proc_macro_api/src/version.rs
+++ b/crates/proc_macro_api/src/version.rs
@@ -33,7 +33,7 @@ pub(crate) fn read_info(dylib_path: &Path) -> io::Result<RustCInfo> {
33 } 33 }
34 34
35 let version_part = items.next().ok_or(err!("no version string"))?; 35 let version_part = items.next().ok_or(err!("no version string"))?;
36 let mut version_parts = version_part.split("-"); 36 let mut version_parts = version_part.split('-');
37 let version = version_parts.next().ok_or(err!("no version"))?; 37 let version = version_parts.next().ok_or(err!("no version"))?;
38 let channel = version_parts.next().unwrap_or_default().to_string(); 38 let channel = version_parts.next().unwrap_or_default().to_string();
39 39
@@ -51,7 +51,7 @@ pub(crate) fn read_info(dylib_path: &Path) -> io::Result<RustCInfo> {
51 let date = date[0..date.len() - 2].to_string(); 51 let date = date[0..date.len() - 2].to_string();
52 52
53 let version_numbers = version 53 let version_numbers = version
54 .split(".") 54 .split('.')
55 .map(|it| it.parse::<usize>()) 55 .map(|it| it.parse::<usize>())
56 .collect::<Result<Vec<_>, _>>() 56 .collect::<Result<Vec<_>, _>>()
57 .map_err(|_| err!("version number error"))?; 57 .map_err(|_| err!("version number error"))?;
diff --git a/crates/project_model/src/rustc_cfg.rs b/crates/project_model/src/rustc_cfg.rs
index 4a7bd8ae3..312708575 100644
--- a/crates/project_model/src/rustc_cfg.rs
+++ b/crates/project_model/src/rustc_cfg.rs
@@ -6,7 +6,7 @@ use crate::{cfg_flag::CfgFlag, utf8_stdout};
6 6
7pub(crate) fn get(target: Option<&str>) -> Vec<CfgFlag> { 7pub(crate) fn get(target: Option<&str>) -> Vec<CfgFlag> {
8 let _p = profile::span("rustc_cfg::get"); 8 let _p = profile::span("rustc_cfg::get");
9 let mut res = Vec::new(); 9 let mut res = Vec::with_capacity(6 * 2 + 1);
10 10
11 // Some nightly-only cfgs, which are required for stdlib 11 // Some nightly-only cfgs, which are required for stdlib
12 res.push(CfgFlag::Atom("target_thread_local".into())); 12 res.push(CfgFlag::Atom("target_thread_local".into()));
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index ff1929d58..6fb7da79c 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -846,9 +846,9 @@ pub(crate) fn handle_references(
846 }; 846 };
847 847
848 let decl = if params.context.include_declaration { 848 let decl = if params.context.include_declaration {
849 Some(FileRange { 849 refs.declaration.map(|decl| FileRange {
850 file_id: refs.declaration.nav.file_id, 850 file_id: decl.nav.file_id,
851 range: refs.declaration.nav.focus_or_full_range(), 851 range: decl.nav.focus_or_full_range(),
852 }) 852 })
853 } else { 853 } else {
854 None 854 None
@@ -1153,14 +1153,12 @@ pub(crate) fn handle_document_highlight(
1153 Some(refs) => refs, 1153 Some(refs) => refs,
1154 }; 1154 };
1155 1155
1156 let decl = if refs.declaration.nav.file_id == position.file_id { 1156 let decl = refs.declaration.filter(|decl| decl.nav.file_id == position.file_id).map(|decl| {
1157 Some(DocumentHighlight { 1157 DocumentHighlight {
1158 range: to_proto::range(&line_index, refs.declaration.nav.focus_or_full_range()), 1158 range: to_proto::range(&line_index, decl.nav.focus_or_full_range()),
1159 kind: refs.declaration.access.map(to_proto::document_highlight_kind), 1159 kind: decl.access.map(to_proto::document_highlight_kind),
1160 }) 1160 }
1161 } else { 1161 });
1162 None
1163 };
1164 1162
1165 let file_refs = refs.references.get(&position.file_id).map_or(&[][..], Vec::as_slice); 1163 let file_refs = refs.references.get(&position.file_id).map_or(&[][..], Vec::as_slice);
1166 let mut res = Vec::with_capacity(file_refs.len() + 1); 1164 let mut res = Vec::with_capacity(file_refs.len() + 1);
diff --git a/crates/rust-analyzer/src/lsp_utils.rs b/crates/rust-analyzer/src/lsp_utils.rs
index 84f78b5b8..3ca7f8040 100644
--- a/crates/rust-analyzer/src/lsp_utils.rs
+++ b/crates/rust-analyzer/src/lsp_utils.rs
@@ -360,11 +360,11 @@ mod tests {
360 "Completion with disjoint edits is valid" 360 "Completion with disjoint edits is valid"
361 ); 361 );
362 assert!( 362 assert!(
363 !all_edits_are_disjoint(&completion_with_disjoint_edits, &[joint_edit.clone()]), 363 !all_edits_are_disjoint(&completion_with_disjoint_edits, &[joint_edit]),
364 "Completion with disjoint edits and joint extra edit is invalid" 364 "Completion with disjoint edits and joint extra edit is invalid"
365 ); 365 );
366 assert!( 366 assert!(
367 all_edits_are_disjoint(&completion_with_disjoint_edits, &[disjoint_edit_2.clone()]), 367 all_edits_are_disjoint(&completion_with_disjoint_edits, &[disjoint_edit_2]),
368 "Completion with disjoint edits and joint extra edit is valid" 368 "Completion with disjoint edits and joint extra edit is valid"
369 ); 369 );
370 } 370 }