diff options
Diffstat (limited to 'crates')
62 files changed, 2267 insertions, 1151 deletions
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index 0132565e4..69ceba735 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs | |||
@@ -34,19 +34,13 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { | |||
34 | 34 | ||
35 | fn with_position(ra_fixture: &str) -> (Self, FilePosition) { | 35 | fn with_position(ra_fixture: &str) -> (Self, FilePosition) { |
36 | let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); | 36 | let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); |
37 | let offset = match range_or_offset { | 37 | let offset = range_or_offset.expect_offset(); |
38 | RangeOrOffset::Range(_) => panic!("Expected a cursor position, got a range instead"), | ||
39 | RangeOrOffset::Offset(it) => it, | ||
40 | }; | ||
41 | (db, FilePosition { file_id, offset }) | 38 | (db, FilePosition { file_id, offset }) |
42 | } | 39 | } |
43 | 40 | ||
44 | fn with_range(ra_fixture: &str) -> (Self, FileRange) { | 41 | fn with_range(ra_fixture: &str) -> (Self, FileRange) { |
45 | let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); | 42 | let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); |
46 | let range = match range_or_offset { | 43 | let range = range_or_offset.expect_range(); |
47 | RangeOrOffset::Range(it) => it, | ||
48 | RangeOrOffset::Offset(_) => panic!("Expected a cursor range, got a position instead"), | ||
49 | }; | ||
50 | (db, FileRange { file_id, range }) | 44 | (db, FileRange { file_id, range }) |
51 | } | 45 | } |
52 | 46 | ||
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index 64ccd11ee..23cb0c839 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs | |||
@@ -147,7 +147,7 @@ impl CrateDisplayName { | |||
147 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | 147 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
148 | pub struct ProcMacroId(pub u32); | 148 | pub struct ProcMacroId(pub u32); |
149 | 149 | ||
150 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | 150 | #[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)] |
151 | pub enum ProcMacroKind { | 151 | pub enum ProcMacroKind { |
152 | CustomDerive, | 152 | CustomDerive, |
153 | FuncLike, | 153 | FuncLike, |
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 22ec7c6ac..2cdbd172a 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs | |||
@@ -227,3 +227,27 @@ impl Diagnostic for MacroError { | |||
227 | true | 227 | true |
228 | } | 228 | } |
229 | } | 229 | } |
230 | |||
231 | #[derive(Debug)] | ||
232 | pub struct UnimplementedBuiltinMacro { | ||
233 | pub file: HirFileId, | ||
234 | pub node: SyntaxNodePtr, | ||
235 | } | ||
236 | |||
237 | impl Diagnostic for UnimplementedBuiltinMacro { | ||
238 | fn code(&self) -> DiagnosticCode { | ||
239 | DiagnosticCode("unimplemented-builtin-macro") | ||
240 | } | ||
241 | |||
242 | fn message(&self) -> String { | ||
243 | "unimplemented built-in macro".to_string() | ||
244 | } | ||
245 | |||
246 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
247 | InFile::new(self.file, self.node.clone()) | ||
248 | } | ||
249 | |||
250 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
251 | self | ||
252 | } | ||
253 | } | ||
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index c5cf803fd..72f0d9b5f 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs | |||
@@ -427,10 +427,6 @@ impl HirDisplay for Trait { | |||
427 | write!(f, "trait {}", data.name)?; | 427 | write!(f, "trait {}", data.name)?; |
428 | let def_id = GenericDefId::TraitId(self.id); | 428 | let def_id = GenericDefId::TraitId(self.id); |
429 | write_generic_params(def_id, f)?; | 429 | write_generic_params(def_id, f)?; |
430 | if !data.bounds.is_empty() { | ||
431 | write!(f, ": ")?; | ||
432 | f.write_joined(&*data.bounds, " + ")?; | ||
433 | } | ||
434 | write_where_clause(def_id, f)?; | 430 | write_where_clause(def_id, f)?; |
435 | Ok(()) | 431 | Ok(()) |
436 | } | 432 | } |
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 01b2de515..d3ef29db4 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -36,8 +36,8 @@ use std::{iter, sync::Arc}; | |||
36 | use arrayvec::ArrayVec; | 36 | use arrayvec::ArrayVec; |
37 | use base_db::{CrateDisplayName, CrateId, Edition, FileId}; | 37 | use base_db::{CrateDisplayName, CrateId, Edition, FileId}; |
38 | use diagnostics::{ | 38 | use diagnostics::{ |
39 | InactiveCode, MacroError, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall, | 39 | InactiveCode, MacroError, UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, |
40 | UnresolvedModule, UnresolvedProcMacro, | 40 | UnresolvedMacroCall, UnresolvedModule, UnresolvedProcMacro, |
41 | }; | 41 | }; |
42 | use either::Either; | 42 | use either::Either; |
43 | use hir_def::{ | 43 | use hir_def::{ |
@@ -565,6 +565,14 @@ impl Module { | |||
565 | }; | 565 | }; |
566 | sink.push(MacroError { file, node: ast, message: message.clone() }); | 566 | sink.push(MacroError { file, node: ast, message: message.clone() }); |
567 | } | 567 | } |
568 | |||
569 | DefDiagnosticKind::UnimplementedBuiltinMacro { ast } => { | ||
570 | let node = ast.to_node(db.upcast()); | ||
571 | // Must have a name, otherwise we wouldn't emit it. | ||
572 | let name = node.name().expect("unimplemented builtin macro with no name"); | ||
573 | let ptr = SyntaxNodePtr::from(AstPtr::new(&name)); | ||
574 | sink.push(UnimplementedBuiltinMacro { file: ast.file_id, node: ptr }); | ||
575 | } | ||
568 | } | 576 | } |
569 | } | 577 | } |
570 | for decl in self.declarations(db) { | 578 | for decl in self.declarations(db) { |
@@ -1282,10 +1290,16 @@ impl BuiltinType { | |||
1282 | 1290 | ||
1283 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 1291 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
1284 | pub enum MacroKind { | 1292 | pub enum MacroKind { |
1293 | /// `macro_rules!` or Macros 2.0 macro. | ||
1285 | Declarative, | 1294 | Declarative, |
1286 | ProcMacro, | 1295 | /// A built-in or custom derive. |
1287 | Derive, | 1296 | Derive, |
1297 | /// A built-in function-like macro. | ||
1288 | BuiltIn, | 1298 | BuiltIn, |
1299 | /// A procedural attribute macro. | ||
1300 | Attr, | ||
1301 | /// A function-like procedural macro. | ||
1302 | ProcMacro, | ||
1289 | } | 1303 | } |
1290 | 1304 | ||
1291 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 1305 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -1315,11 +1329,13 @@ impl MacroDef { | |||
1315 | pub fn kind(&self) -> MacroKind { | 1329 | pub fn kind(&self) -> MacroKind { |
1316 | match self.id.kind { | 1330 | match self.id.kind { |
1317 | MacroDefKind::Declarative(_) => MacroKind::Declarative, | 1331 | MacroDefKind::Declarative(_) => MacroKind::Declarative, |
1318 | MacroDefKind::BuiltIn(_, _) => MacroKind::BuiltIn, | 1332 | MacroDefKind::BuiltIn(_, _) | MacroDefKind::BuiltInEager(_, _) => MacroKind::BuiltIn, |
1319 | MacroDefKind::BuiltInDerive(_, _) => MacroKind::Derive, | 1333 | MacroDefKind::BuiltInDerive(_, _) => MacroKind::Derive, |
1320 | MacroDefKind::BuiltInEager(_, _) => MacroKind::BuiltIn, | 1334 | MacroDefKind::ProcMacro(_, base_db::ProcMacroKind::CustomDerive, _) => { |
1321 | // FIXME might be a derive | 1335 | MacroKind::Derive |
1322 | MacroDefKind::ProcMacro(_, _) => MacroKind::ProcMacro, | 1336 | } |
1337 | MacroDefKind::ProcMacro(_, base_db::ProcMacroKind::Attr, _) => MacroKind::Attr, | ||
1338 | MacroDefKind::ProcMacro(_, base_db::ProcMacroKind::FuncLike, _) => MacroKind::ProcMacro, | ||
1323 | } | 1339 | } |
1324 | } | 1340 | } |
1325 | } | 1341 | } |
diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index 8bcac60ef..d2bb381be 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs | |||
@@ -22,6 +22,7 @@ pub struct FunctionData { | |||
22 | pub name: Name, | 22 | pub name: Name, |
23 | pub params: Vec<Interned<TypeRef>>, | 23 | pub params: Vec<Interned<TypeRef>>, |
24 | pub ret_type: Interned<TypeRef>, | 24 | pub ret_type: Interned<TypeRef>, |
25 | pub async_ret_type: Option<Interned<TypeRef>>, | ||
25 | pub attrs: Attrs, | 26 | pub attrs: Attrs, |
26 | pub visibility: RawVisibility, | 27 | pub visibility: RawVisibility, |
27 | pub abi: Option<Interned<str>>, | 28 | pub abi: Option<Interned<str>>, |
@@ -63,6 +64,7 @@ impl FunctionData { | |||
63 | }) | 64 | }) |
64 | .collect(), | 65 | .collect(), |
65 | ret_type: func.ret_type.clone(), | 66 | ret_type: func.ret_type.clone(), |
67 | async_ret_type: func.async_ret_type.clone(), | ||
66 | attrs: item_tree.attrs(db, krate, ModItem::from(loc.id.value).into()), | 68 | attrs: item_tree.attrs(db, krate, ModItem::from(loc.id.value).into()), |
67 | visibility: item_tree[func.visibility].clone(), | 69 | visibility: item_tree[func.visibility].clone(), |
68 | abi: func.abi.clone(), | 70 | abi: func.abi.clone(), |
@@ -141,7 +143,6 @@ pub struct TraitData { | |||
141 | pub is_auto: bool, | 143 | pub is_auto: bool, |
142 | pub is_unsafe: bool, | 144 | pub is_unsafe: bool, |
143 | pub visibility: RawVisibility, | 145 | pub visibility: RawVisibility, |
144 | pub bounds: Box<[Interned<TypeBound>]>, | ||
145 | } | 146 | } |
146 | 147 | ||
147 | impl TraitData { | 148 | impl TraitData { |
@@ -155,7 +156,6 @@ impl TraitData { | |||
155 | let module_id = tr_loc.container; | 156 | let module_id = tr_loc.container; |
156 | let container = AssocContainerId::TraitId(tr); | 157 | let container = AssocContainerId::TraitId(tr); |
157 | let visibility = item_tree[tr_def.visibility].clone(); | 158 | let visibility = item_tree[tr_def.visibility].clone(); |
158 | let bounds = tr_def.bounds.clone(); | ||
159 | let mut expander = Expander::new(db, tr_loc.id.file_id(), module_id); | 159 | let mut expander = Expander::new(db, tr_loc.id.file_id(), module_id); |
160 | 160 | ||
161 | let items = collect_items( | 161 | let items = collect_items( |
@@ -168,7 +168,7 @@ impl TraitData { | |||
168 | 100, | 168 | 100, |
169 | ); | 169 | ); |
170 | 170 | ||
171 | Arc::new(TraitData { name, items, is_auto, is_unsafe, visibility, bounds }) | 171 | Arc::new(TraitData { name, items, is_auto, is_unsafe, visibility }) |
172 | } | 172 | } |
173 | 173 | ||
174 | pub fn associated_types(&self) -> impl Iterator<Item = TypeAliasId> + '_ { | 174 | pub fn associated_types(&self) -> impl Iterator<Item = TypeAliasId> + '_ { |
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index f84c4cf2b..227337a8d 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -580,6 +580,7 @@ pub struct Function { | |||
580 | pub abi: Option<Interned<str>>, | 580 | pub abi: Option<Interned<str>>, |
581 | pub params: IdRange<Param>, | 581 | pub params: IdRange<Param>, |
582 | pub ret_type: Interned<TypeRef>, | 582 | pub ret_type: Interned<TypeRef>, |
583 | pub async_ret_type: Option<Interned<TypeRef>>, | ||
583 | pub ast_id: FileAstId<ast::Fn>, | 584 | pub ast_id: FileAstId<ast::Fn>, |
584 | pub(crate) flags: FnFlags, | 585 | pub(crate) flags: FnFlags, |
585 | } | 586 | } |
@@ -661,7 +662,6 @@ pub struct Trait { | |||
661 | pub generic_params: Interned<GenericParams>, | 662 | pub generic_params: Interned<GenericParams>, |
662 | pub is_auto: bool, | 663 | pub is_auto: bool, |
663 | pub is_unsafe: bool, | 664 | pub is_unsafe: bool, |
664 | pub bounds: Box<[Interned<TypeBound>]>, | ||
665 | pub items: Box<[AssocItem]>, | 665 | pub items: Box<[AssocItem]>, |
666 | pub ast_id: FileAstId<ast::Trait>, | 666 | pub ast_id: FileAstId<ast::Trait>, |
667 | } | 667 | } |
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 40f3428b7..6208facd5 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -356,12 +356,13 @@ impl<'a> Ctx<'a> { | |||
356 | _ => TypeRef::unit(), | 356 | _ => TypeRef::unit(), |
357 | }; | 357 | }; |
358 | 358 | ||
359 | let ret_type = if func.async_token().is_some() { | 359 | let (ret_type, async_ret_type) = if func.async_token().is_some() { |
360 | let async_ret_type = ret_type.clone(); | ||
360 | let future_impl = desugar_future_path(ret_type); | 361 | let future_impl = desugar_future_path(ret_type); |
361 | let ty_bound = Interned::new(TypeBound::Path(future_impl)); | 362 | let ty_bound = Interned::new(TypeBound::Path(future_impl)); |
362 | TypeRef::ImplTrait(vec![ty_bound]) | 363 | (TypeRef::ImplTrait(vec![ty_bound]), Some(async_ret_type)) |
363 | } else { | 364 | } else { |
364 | ret_type | 365 | (ret_type, None) |
365 | }; | 366 | }; |
366 | 367 | ||
367 | let abi = func.abi().map(lower_abi); | 368 | let abi = func.abi().map(lower_abi); |
@@ -395,6 +396,7 @@ impl<'a> Ctx<'a> { | |||
395 | abi, | 396 | abi, |
396 | params, | 397 | params, |
397 | ret_type: Interned::new(ret_type), | 398 | ret_type: Interned::new(ret_type), |
399 | async_ret_type: async_ret_type.map(Interned::new), | ||
398 | ast_id, | 400 | ast_id, |
399 | flags, | 401 | flags, |
400 | }; | 402 | }; |
@@ -474,7 +476,6 @@ impl<'a> Ctx<'a> { | |||
474 | self.lower_generic_params_and_inner_items(GenericsOwner::Trait(trait_def), trait_def); | 476 | self.lower_generic_params_and_inner_items(GenericsOwner::Trait(trait_def), trait_def); |
475 | let is_auto = trait_def.auto_token().is_some(); | 477 | let is_auto = trait_def.auto_token().is_some(); |
476 | let is_unsafe = trait_def.unsafe_token().is_some(); | 478 | let is_unsafe = trait_def.unsafe_token().is_some(); |
477 | let bounds = self.lower_type_bounds(trait_def); | ||
478 | let items = trait_def.assoc_item_list().map(|list| { | 479 | let items = trait_def.assoc_item_list().map(|list| { |
479 | let db = self.db; | 480 | let db = self.db; |
480 | self.with_inherited_visibility(visibility, |this| { | 481 | self.with_inherited_visibility(visibility, |this| { |
@@ -497,7 +498,6 @@ impl<'a> Ctx<'a> { | |||
497 | generic_params, | 498 | generic_params, |
498 | is_auto, | 499 | is_auto, |
499 | is_unsafe, | 500 | is_unsafe, |
500 | bounds: bounds.into(), | ||
501 | items: items.unwrap_or_default(), | 501 | items: items.unwrap_or_default(), |
502 | ast_id, | 502 | ast_id, |
503 | }; | 503 | }; |
diff --git a/crates/hir_def/src/item_tree/pretty.rs b/crates/hir_def/src/item_tree/pretty.rs index 53631ab19..cc9944a22 100644 --- a/crates/hir_def/src/item_tree/pretty.rs +++ b/crates/hir_def/src/item_tree/pretty.rs | |||
@@ -235,6 +235,7 @@ impl<'a> Printer<'a> { | |||
235 | abi, | 235 | abi, |
236 | params, | 236 | params, |
237 | ret_type, | 237 | ret_type, |
238 | async_ret_type: _, | ||
238 | ast_id: _, | 239 | ast_id: _, |
239 | flags, | 240 | flags, |
240 | } = &self.tree[it]; | 241 | } = &self.tree[it]; |
@@ -345,7 +346,6 @@ impl<'a> Printer<'a> { | |||
345 | visibility, | 346 | visibility, |
346 | is_auto, | 347 | is_auto, |
347 | is_unsafe, | 348 | is_unsafe, |
348 | bounds, | ||
349 | items, | 349 | items, |
350 | generic_params, | 350 | generic_params, |
351 | ast_id: _, | 351 | ast_id: _, |
@@ -359,10 +359,6 @@ impl<'a> Printer<'a> { | |||
359 | } | 359 | } |
360 | w!(self, "trait {}", name); | 360 | w!(self, "trait {}", name); |
361 | self.print_generic_params(generic_params); | 361 | self.print_generic_params(generic_params); |
362 | if !bounds.is_empty() { | ||
363 | w!(self, ": "); | ||
364 | self.print_type_bounds(bounds); | ||
365 | } | ||
366 | self.print_where_clause_and_opening_brace(generic_params); | 362 | self.print_where_clause_and_opening_brace(generic_params); |
367 | self.indented(|this| { | 363 | self.indented(|this| { |
368 | for item in &**items { | 364 | for item in &**items { |
diff --git a/crates/hir_def/src/item_tree/tests.rs b/crates/hir_def/src/item_tree/tests.rs index 20773aa69..b362add5c 100644 --- a/crates/hir_def/src/item_tree/tests.rs +++ b/crates/hir_def/src/item_tree/tests.rs | |||
@@ -180,7 +180,7 @@ trait Tr: SuperTrait + 'lifetime { | |||
180 | _: (), | 180 | _: (), |
181 | ) -> (); | 181 | ) -> (); |
182 | 182 | ||
183 | pub(self) trait Tr<Self>: SuperTrait + 'lifetime | 183 | pub(self) trait Tr<Self> |
184 | where | 184 | where |
185 | Self: SuperTrait, | 185 | Self: SuperTrait, |
186 | Self: 'lifetime | 186 | Self: 'lifetime |
@@ -350,7 +350,7 @@ trait Tr<'a, T: 'a>: Super {} | |||
350 | pub(self) union Union<'a, T, const U: u8> { | 350 | pub(self) union Union<'a, T, const U: u8> { |
351 | } | 351 | } |
352 | 352 | ||
353 | pub(self) trait Tr<'a, Self, T>: Super | 353 | pub(self) trait Tr<'a, Self, T> |
354 | where | 354 | where |
355 | Self: Super, | 355 | Self: Super, |
356 | T: 'a | 356 | T: 'a |
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 716dcf1f7..7f9fdb379 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -477,16 +477,21 @@ impl DefCollector<'_> { | |||
477 | /// going out of sync with what the build system sees (since we resolve using VFS state, but | 477 | /// going out of sync with what the build system sees (since we resolve using VFS state, but |
478 | /// Cargo builds only on-disk files). We could and probably should add diagnostics for that. | 478 | /// Cargo builds only on-disk files). We could and probably should add diagnostics for that. |
479 | fn export_proc_macro(&mut self, def: ProcMacroDef, ast_id: AstId<ast::Fn>) { | 479 | fn export_proc_macro(&mut self, def: ProcMacroDef, ast_id: AstId<ast::Fn>) { |
480 | let kind = def.kind.to_basedb_kind(); | ||
480 | self.exports_proc_macros = true; | 481 | self.exports_proc_macros = true; |
481 | let macro_def = match self.proc_macros.iter().find(|(n, _)| n == &def.name) { | 482 | let macro_def = match self.proc_macros.iter().find(|(n, _)| n == &def.name) { |
482 | Some((_, expander)) => MacroDefId { | 483 | Some((_, expander)) => MacroDefId { |
483 | krate: self.def_map.krate, | 484 | krate: self.def_map.krate, |
484 | kind: MacroDefKind::ProcMacro(*expander, ast_id), | 485 | kind: MacroDefKind::ProcMacro(*expander, kind, ast_id), |
485 | local_inner: false, | 486 | local_inner: false, |
486 | }, | 487 | }, |
487 | None => MacroDefId { | 488 | None => MacroDefId { |
488 | krate: self.def_map.krate, | 489 | krate: self.def_map.krate, |
489 | kind: MacroDefKind::ProcMacro(ProcMacroExpander::dummy(self.def_map.krate), ast_id), | 490 | kind: MacroDefKind::ProcMacro( |
491 | ProcMacroExpander::dummy(self.def_map.krate), | ||
492 | kind, | ||
493 | ast_id, | ||
494 | ), | ||
490 | local_inner: false, | 495 | local_inner: false, |
491 | }, | 496 | }, |
492 | }; | 497 | }; |
@@ -1674,14 +1679,22 @@ impl ModCollector<'_, '_> { | |||
1674 | None => &mac.name, | 1679 | None => &mac.name, |
1675 | }; | 1680 | }; |
1676 | let krate = self.def_collector.def_map.krate; | 1681 | let krate = self.def_collector.def_map.krate; |
1677 | if let Some(macro_id) = find_builtin_macro(name, krate, ast_id) { | 1682 | match find_builtin_macro(name, krate, ast_id) { |
1678 | self.def_collector.define_macro_rules( | 1683 | Some(macro_id) => { |
1679 | self.module_id, | 1684 | self.def_collector.define_macro_rules( |
1680 | mac.name.clone(), | 1685 | self.module_id, |
1681 | macro_id, | 1686 | mac.name.clone(), |
1682 | is_export, | 1687 | macro_id, |
1683 | ); | 1688 | is_export, |
1684 | return; | 1689 | ); |
1690 | return; | ||
1691 | } | ||
1692 | None => { | ||
1693 | self.def_collector | ||
1694 | .def_map | ||
1695 | .diagnostics | ||
1696 | .push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, ast_id)); | ||
1697 | } | ||
1685 | } | 1698 | } |
1686 | } | 1699 | } |
1687 | 1700 | ||
@@ -1710,15 +1723,23 @@ impl ModCollector<'_, '_> { | |||
1710 | let macro_id = find_builtin_macro(&mac.name, krate, ast_id) | 1723 | let macro_id = find_builtin_macro(&mac.name, krate, ast_id) |
1711 | .or_else(|| find_builtin_derive(&mac.name, krate, ast_id)); | 1724 | .or_else(|| find_builtin_derive(&mac.name, krate, ast_id)); |
1712 | 1725 | ||
1713 | if let Some(macro_id) = macro_id { | 1726 | match macro_id { |
1714 | self.def_collector.define_macro_def( | 1727 | Some(macro_id) => { |
1715 | self.module_id, | 1728 | self.def_collector.define_macro_def( |
1716 | mac.name.clone(), | 1729 | self.module_id, |
1717 | macro_id, | 1730 | mac.name.clone(), |
1718 | &self.item_tree[mac.visibility], | 1731 | macro_id, |
1719 | ); | 1732 | &self.item_tree[mac.visibility], |
1733 | ); | ||
1734 | return; | ||
1735 | } | ||
1736 | None => { | ||
1737 | self.def_collector | ||
1738 | .def_map | ||
1739 | .diagnostics | ||
1740 | .push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, ast_id)); | ||
1741 | } | ||
1720 | } | 1742 | } |
1721 | return; | ||
1722 | } | 1743 | } |
1723 | 1744 | ||
1724 | // Case 2: normal `macro` | 1745 | // Case 2: normal `macro` |
diff --git a/crates/hir_def/src/nameres/diagnostics.rs b/crates/hir_def/src/nameres/diagnostics.rs index 57c36c3c6..95061f601 100644 --- a/crates/hir_def/src/nameres/diagnostics.rs +++ b/crates/hir_def/src/nameres/diagnostics.rs | |||
@@ -27,6 +27,8 @@ pub enum DefDiagnosticKind { | |||
27 | UnresolvedMacroCall { ast: AstId<ast::MacroCall>, path: ModPath }, | 27 | UnresolvedMacroCall { ast: AstId<ast::MacroCall>, path: ModPath }, |
28 | 28 | ||
29 | MacroError { ast: MacroCallKind, message: String }, | 29 | MacroError { ast: MacroCallKind, message: String }, |
30 | |||
31 | UnimplementedBuiltinMacro { ast: AstId<ast::Macro> }, | ||
30 | } | 32 | } |
31 | 33 | ||
32 | #[derive(Debug, PartialEq, Eq)] | 34 | #[derive(Debug, PartialEq, Eq)] |
@@ -93,4 +95,11 @@ impl DefDiagnostic { | |||
93 | ) -> Self { | 95 | ) -> Self { |
94 | Self { in_module: container, kind: DefDiagnosticKind::UnresolvedMacroCall { ast, path } } | 96 | Self { in_module: container, kind: DefDiagnosticKind::UnresolvedMacroCall { ast, path } } |
95 | } | 97 | } |
98 | |||
99 | pub(super) fn unimplemented_builtin_macro( | ||
100 | container: LocalModuleId, | ||
101 | ast: AstId<ast::Macro>, | ||
102 | ) -> Self { | ||
103 | Self { in_module: container, kind: DefDiagnosticKind::UnimplementedBuiltinMacro { ast } } | ||
104 | } | ||
96 | } | 105 | } |
diff --git a/crates/hir_def/src/nameres/proc_macro.rs b/crates/hir_def/src/nameres/proc_macro.rs index 156598f19..3f095d623 100644 --- a/crates/hir_def/src/nameres/proc_macro.rs +++ b/crates/hir_def/src/nameres/proc_macro.rs | |||
@@ -18,6 +18,16 @@ pub(super) enum ProcMacroKind { | |||
18 | Attr, | 18 | Attr, |
19 | } | 19 | } |
20 | 20 | ||
21 | impl ProcMacroKind { | ||
22 | pub(super) fn to_basedb_kind(&self) -> base_db::ProcMacroKind { | ||
23 | match self { | ||
24 | ProcMacroKind::CustomDerive { .. } => base_db::ProcMacroKind::CustomDerive, | ||
25 | ProcMacroKind::FnLike => base_db::ProcMacroKind::FuncLike, | ||
26 | ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | |||
21 | impl Attrs { | 31 | impl Attrs { |
22 | #[rustfmt::skip] | 32 | #[rustfmt::skip] |
23 | pub(super) fn parse_proc_macro_decl(&self, func_name: &Name) -> Option<ProcMacroDef> { | 33 | pub(super) fn parse_proc_macro_decl(&self, func_name: &Name) -> Option<ProcMacroDef> { |
diff --git a/crates/hir_def/src/nameres/tests/incremental.rs b/crates/hir_def/src/nameres/tests/incremental.rs index d884a6eb4..7bf152e26 100644 --- a/crates/hir_def/src/nameres/tests/incremental.rs +++ b/crates/hir_def/src/nameres/tests/incremental.rs | |||
@@ -1,6 +1,8 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use base_db::SourceDatabaseExt; | 3 | use base_db::{salsa::SweepStrategy, SourceDatabaseExt}; |
4 | |||
5 | use crate::{AdtId, ModuleDefId}; | ||
4 | 6 | ||
5 | use super::*; | 7 | use super::*; |
6 | 8 | ||
@@ -163,3 +165,73 @@ m!(Z); | |||
163 | assert_eq!(n_reparsed_macros, 0); | 165 | assert_eq!(n_reparsed_macros, 0); |
164 | } | 166 | } |
165 | } | 167 | } |
168 | |||
169 | #[test] | ||
170 | fn item_tree_prevents_reparsing() { | ||
171 | // The `ItemTree` is used by both name resolution and the various queries in `adt.rs` and | ||
172 | // `data.rs`. After computing the `ItemTree` and deleting the parse tree, we should be able to | ||
173 | // run those other queries without triggering a reparse. | ||
174 | |||
175 | let (db, pos) = TestDB::with_position( | ||
176 | r#" | ||
177 | pub struct S; | ||
178 | pub union U {} | ||
179 | pub enum E { | ||
180 | Variant, | ||
181 | } | ||
182 | pub fn f(_: S) { $0 } | ||
183 | pub trait Tr {} | ||
184 | impl Tr for () {} | ||
185 | pub const C: u8 = 0; | ||
186 | pub static ST: u8 = 0; | ||
187 | pub type Ty = (); | ||
188 | "#, | ||
189 | ); | ||
190 | let krate = db.test_crate(); | ||
191 | { | ||
192 | let events = db.log_executed(|| { | ||
193 | db.file_item_tree(pos.file_id.into()); | ||
194 | }); | ||
195 | let n_calculated_item_trees = events.iter().filter(|it| it.contains("item_tree")).count(); | ||
196 | assert_eq!(n_calculated_item_trees, 1); | ||
197 | let n_parsed_files = events.iter().filter(|it| it.contains("parse(")).count(); | ||
198 | assert_eq!(n_parsed_files, 1); | ||
199 | } | ||
200 | |||
201 | // Delete the parse tree. | ||
202 | let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); | ||
203 | base_db::ParseQuery.in_db(&db).sweep(sweep); | ||
204 | |||
205 | { | ||
206 | let events = db.log_executed(|| { | ||
207 | let crate_def_map = db.crate_def_map(krate); | ||
208 | let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); | ||
209 | assert_eq!(module_data.scope.resolutions().count(), 8); | ||
210 | assert_eq!(module_data.scope.impls().count(), 1); | ||
211 | |||
212 | for imp in module_data.scope.impls() { | ||
213 | db.impl_data(imp); | ||
214 | } | ||
215 | |||
216 | for (_, res) in module_data.scope.resolutions() { | ||
217 | match res.values.or(res.types).unwrap().0 { | ||
218 | ModuleDefId::FunctionId(f) => drop(db.function_data(f)), | ||
219 | ModuleDefId::AdtId(adt) => match adt { | ||
220 | AdtId::StructId(it) => drop(db.struct_data(it)), | ||
221 | AdtId::UnionId(it) => drop(db.union_data(it)), | ||
222 | AdtId::EnumId(it) => drop(db.enum_data(it)), | ||
223 | }, | ||
224 | ModuleDefId::ConstId(it) => drop(db.const_data(it)), | ||
225 | ModuleDefId::StaticId(it) => drop(db.static_data(it)), | ||
226 | ModuleDefId::TraitId(it) => drop(db.trait_data(it)), | ||
227 | ModuleDefId::TypeAliasId(it) => drop(db.type_alias_data(it)), | ||
228 | ModuleDefId::EnumVariantId(_) | ||
229 | | ModuleDefId::ModuleId(_) | ||
230 | | ModuleDefId::BuiltinType(_) => unreachable!(), | ||
231 | } | ||
232 | } | ||
233 | }); | ||
234 | let n_reparsed_files = events.iter().filter(|it| it.contains("parse(")).count(); | ||
235 | assert_eq!(n_reparsed_files, 0); | ||
236 | } | ||
237 | } | ||
diff --git a/crates/hir_def/src/test_db.rs b/crates/hir_def/src/test_db.rs index a9c1e13e2..e840fe5e8 100644 --- a/crates/hir_def/src/test_db.rs +++ b/crates/hir_def/src/test_db.rs | |||
@@ -298,6 +298,13 @@ impl TestDB { | |||
298 | DefDiagnosticKind::MacroError { ast, message } => { | 298 | DefDiagnosticKind::MacroError { ast, message } => { |
299 | (ast.to_node(self.upcast()), message.as_str()) | 299 | (ast.to_node(self.upcast()), message.as_str()) |
300 | } | 300 | } |
301 | DefDiagnosticKind::UnimplementedBuiltinMacro { ast } => { | ||
302 | let node = ast.to_node(self.upcast()); | ||
303 | ( | ||
304 | InFile::new(ast.file_id, node.syntax().clone()), | ||
305 | "UnimplementedBuiltinMacro", | ||
306 | ) | ||
307 | } | ||
301 | }; | 308 | }; |
302 | 309 | ||
303 | let frange = node.as_ref().original_file_range(self); | 310 | let frange = node.as_ref().original_file_range(self); |
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index 94d7aecb6..0b310ba2f 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs | |||
@@ -8,7 +8,6 @@ use base_db::{AnchoredPath, Edition, FileId}; | |||
8 | use cfg::CfgExpr; | 8 | use cfg::CfgExpr; |
9 | use either::Either; | 9 | use either::Either; |
10 | use mbe::{parse_exprs_with_sep, parse_to_token_tree, ExpandResult}; | 10 | use mbe::{parse_exprs_with_sep, parse_to_token_tree, ExpandResult}; |
11 | use parser::FragmentKind; | ||
12 | use syntax::ast::{self, AstToken}; | 11 | use syntax::ast::{self, AstToken}; |
13 | 12 | ||
14 | macro_rules! register_builtin { | 13 | macro_rules! register_builtin { |
@@ -47,7 +46,7 @@ macro_rules! register_builtin { | |||
47 | let expander = match *self { | 46 | let expander = match *self { |
48 | $( EagerExpander::$e_kind => $e_expand, )* | 47 | $( EagerExpander::$e_kind => $e_expand, )* |
49 | }; | 48 | }; |
50 | expander(db,arg_id,tt) | 49 | expander(db, arg_id, tt) |
51 | } | 50 | } |
52 | } | 51 | } |
53 | 52 | ||
@@ -64,14 +63,13 @@ macro_rules! register_builtin { | |||
64 | #[derive(Debug)] | 63 | #[derive(Debug)] |
65 | pub struct ExpandedEager { | 64 | pub struct ExpandedEager { |
66 | pub(crate) subtree: tt::Subtree, | 65 | pub(crate) subtree: tt::Subtree, |
67 | pub(crate) fragment: FragmentKind, | ||
68 | /// The included file ID of the include macro. | 66 | /// The included file ID of the include macro. |
69 | pub(crate) included_file: Option<FileId>, | 67 | pub(crate) included_file: Option<FileId>, |
70 | } | 68 | } |
71 | 69 | ||
72 | impl ExpandedEager { | 70 | impl ExpandedEager { |
73 | fn new(subtree: tt::Subtree, fragment: FragmentKind) -> Self { | 71 | fn new(subtree: tt::Subtree) -> Self { |
74 | ExpandedEager { subtree, fragment, included_file: None } | 72 | ExpandedEager { subtree, included_file: None } |
75 | } | 73 | } |
76 | } | 74 | } |
77 | 75 | ||
@@ -340,7 +338,7 @@ fn compile_error_expand( | |||
340 | _ => mbe::ExpandError::BindingError("`compile_error!` argument must be a string".into()), | 338 | _ => mbe::ExpandError::BindingError("`compile_error!` argument must be a string".into()), |
341 | }; | 339 | }; |
342 | 340 | ||
343 | ExpandResult { value: Some(ExpandedEager::new(quote! {}, FragmentKind::Items)), err: Some(err) } | 341 | ExpandResult { value: Some(ExpandedEager::new(quote! {})), err: Some(err) } |
344 | } | 342 | } |
345 | 343 | ||
346 | fn concat_expand( | 344 | fn concat_expand( |
@@ -371,7 +369,7 @@ fn concat_expand( | |||
371 | } | 369 | } |
372 | } | 370 | } |
373 | } | 371 | } |
374 | ExpandResult { value: Some(ExpandedEager::new(quote!(#text), FragmentKind::Expr)), err } | 372 | ExpandResult { value: Some(ExpandedEager::new(quote!(#text))), err } |
375 | } | 373 | } |
376 | 374 | ||
377 | fn concat_idents_expand( | 375 | fn concat_idents_expand( |
@@ -393,7 +391,7 @@ fn concat_idents_expand( | |||
393 | } | 391 | } |
394 | } | 392 | } |
395 | let ident = tt::Ident { text: ident.into(), id: tt::TokenId::unspecified() }; | 393 | let ident = tt::Ident { text: ident.into(), id: tt::TokenId::unspecified() }; |
396 | ExpandResult { value: Some(ExpandedEager::new(quote!(#ident), FragmentKind::Expr)), err } | 394 | ExpandResult { value: Some(ExpandedEager::new(quote!(#ident))), err } |
397 | } | 395 | } |
398 | 396 | ||
399 | fn relative_file( | 397 | fn relative_file( |
@@ -442,14 +440,7 @@ fn include_expand( | |||
442 | 440 | ||
443 | match res { | 441 | match res { |
444 | Ok((subtree, file_id)) => { | 442 | Ok((subtree, file_id)) => { |
445 | // FIXME: | 443 | ExpandResult::ok(Some(ExpandedEager { subtree, included_file: Some(file_id) })) |
446 | // Handle include as expression | ||
447 | |||
448 | ExpandResult::ok(Some(ExpandedEager { | ||
449 | subtree, | ||
450 | fragment: FragmentKind::Items, | ||
451 | included_file: Some(file_id), | ||
452 | })) | ||
453 | } | 444 | } |
454 | Err(e) => ExpandResult::only_err(e), | 445 | Err(e) => ExpandResult::only_err(e), |
455 | } | 446 | } |
@@ -472,7 +463,7 @@ fn include_bytes_expand( | |||
472 | id: tt::TokenId::unspecified(), | 463 | id: tt::TokenId::unspecified(), |
473 | }))], | 464 | }))], |
474 | }; | 465 | }; |
475 | ExpandResult::ok(Some(ExpandedEager::new(res, FragmentKind::Expr))) | 466 | ExpandResult::ok(Some(ExpandedEager::new(res))) |
476 | } | 467 | } |
477 | 468 | ||
478 | fn include_str_expand( | 469 | fn include_str_expand( |
@@ -492,14 +483,14 @@ fn include_str_expand( | |||
492 | let file_id = match relative_file(db, arg_id.into(), &path, true) { | 483 | let file_id = match relative_file(db, arg_id.into(), &path, true) { |
493 | Ok(file_id) => file_id, | 484 | Ok(file_id) => file_id, |
494 | Err(_) => { | 485 | Err(_) => { |
495 | return ExpandResult::ok(Some(ExpandedEager::new(quote!(""), FragmentKind::Expr))); | 486 | return ExpandResult::ok(Some(ExpandedEager::new(quote!("")))); |
496 | } | 487 | } |
497 | }; | 488 | }; |
498 | 489 | ||
499 | let text = db.file_text(file_id); | 490 | let text = db.file_text(file_id); |
500 | let text = &*text; | 491 | let text = &*text; |
501 | 492 | ||
502 | ExpandResult::ok(Some(ExpandedEager::new(quote!(#text), FragmentKind::Expr))) | 493 | ExpandResult::ok(Some(ExpandedEager::new(quote!(#text)))) |
503 | } | 494 | } |
504 | 495 | ||
505 | fn get_env_inner(db: &dyn AstDatabase, arg_id: MacroCallId, key: &str) -> Option<String> { | 496 | fn get_env_inner(db: &dyn AstDatabase, arg_id: MacroCallId, key: &str) -> Option<String> { |
@@ -535,7 +526,7 @@ fn env_expand( | |||
535 | }); | 526 | }); |
536 | let expanded = quote! { #s }; | 527 | let expanded = quote! { #s }; |
537 | 528 | ||
538 | ExpandResult { value: Some(ExpandedEager::new(expanded, FragmentKind::Expr)), err } | 529 | ExpandResult { value: Some(ExpandedEager::new(expanded)), err } |
539 | } | 530 | } |
540 | 531 | ||
541 | fn option_env_expand( | 532 | fn option_env_expand( |
@@ -553,7 +544,7 @@ fn option_env_expand( | |||
553 | Some(s) => quote! { std::option::Some(#s) }, | 544 | Some(s) => quote! { std::option::Some(#s) }, |
554 | }; | 545 | }; |
555 | 546 | ||
556 | ExpandResult::ok(Some(ExpandedEager::new(expanded, FragmentKind::Expr))) | 547 | ExpandResult::ok(Some(ExpandedEager::new(expanded))) |
557 | } | 548 | } |
558 | 549 | ||
559 | #[cfg(test)] | 550 | #[cfg(test)] |
@@ -565,6 +556,7 @@ mod tests { | |||
565 | }; | 556 | }; |
566 | use base_db::{fixture::WithFixture, SourceDatabase}; | 557 | use base_db::{fixture::WithFixture, SourceDatabase}; |
567 | use expect_test::{expect, Expect}; | 558 | use expect_test::{expect, Expect}; |
559 | use parser::FragmentKind; | ||
568 | use std::sync::Arc; | 560 | use std::sync::Arc; |
569 | use syntax::ast::NameOwner; | 561 | use syntax::ast::NameOwner; |
570 | 562 | ||
@@ -617,6 +609,7 @@ mod tests { | |||
617 | local_inner: false, | 609 | local_inner: false, |
618 | }; | 610 | }; |
619 | 611 | ||
612 | let fragment = crate::to_fragment_kind(¯o_call); | ||
620 | let args = macro_call.token_tree().unwrap(); | 613 | let args = macro_call.token_tree().unwrap(); |
621 | let parsed_args = mbe::ast_to_token_tree(&args).0; | 614 | let parsed_args = mbe::ast_to_token_tree(&args).0; |
622 | let call_id = AstId::new(file_id.into(), ast_id_map.ast_id(¯o_call)); | 615 | let call_id = AstId::new(file_id.into(), ast_id_map.ast_id(¯o_call)); |
@@ -639,7 +632,7 @@ mod tests { | |||
639 | arg_or_expansion: Arc::new(expanded.subtree), | 632 | arg_or_expansion: Arc::new(expanded.subtree), |
640 | included_file: expanded.included_file, | 633 | included_file: expanded.included_file, |
641 | }), | 634 | }), |
642 | kind: MacroCallKind::FnLike { ast_id: call_id, fragment: expanded.fragment }, | 635 | kind: MacroCallKind::FnLike { ast_id: call_id, fragment }, |
643 | }; | 636 | }; |
644 | 637 | ||
645 | let id: MacroCallId = db.intern_macro(loc).into(); | 638 | let id: MacroCallId = db.intern_macro(loc).into(); |
diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs index 1464320ba..14af628a1 100644 --- a/crates/hir_expand/src/eager.rs +++ b/crates/hir_expand/src/eager.rs | |||
@@ -113,6 +113,7 @@ pub fn expand_eager_macro( | |||
113 | 113 | ||
114 | let ast_map = db.ast_id_map(macro_call.file_id); | 114 | let ast_map = db.ast_id_map(macro_call.file_id); |
115 | let call_id = InFile::new(macro_call.file_id, ast_map.ast_id(¯o_call.value)); | 115 | let call_id = InFile::new(macro_call.file_id, ast_map.ast_id(¯o_call.value)); |
116 | let fragment = crate::to_fragment_kind(¯o_call.value); | ||
116 | 117 | ||
117 | // Note: | 118 | // Note: |
118 | // When `lazy_expand` is called, its *parent* file must be already exists. | 119 | // When `lazy_expand` is called, its *parent* file must be already exists. |
@@ -152,7 +153,7 @@ pub fn expand_eager_macro( | |||
152 | arg_or_expansion: Arc::new(expanded.subtree), | 153 | arg_or_expansion: Arc::new(expanded.subtree), |
153 | included_file: expanded.included_file, | 154 | included_file: expanded.included_file, |
154 | }), | 155 | }), |
155 | kind: MacroCallKind::FnLike { ast_id: call_id, fragment: expanded.fragment }, | 156 | kind: MacroCallKind::FnLike { ast_id: call_id, fragment }, |
156 | }; | 157 | }; |
157 | 158 | ||
158 | Ok(db.intern_macro(loc)) | 159 | Ok(db.intern_macro(loc)) |
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs index 10d37234e..90d8ae240 100644 --- a/crates/hir_expand/src/lib.rs +++ b/crates/hir_expand/src/lib.rs | |||
@@ -15,6 +15,7 @@ pub mod quote; | |||
15 | pub mod eager; | 15 | pub mod eager; |
16 | mod input; | 16 | mod input; |
17 | 17 | ||
18 | use base_db::ProcMacroKind; | ||
18 | use either::Either; | 19 | use either::Either; |
19 | 20 | ||
20 | pub use mbe::{ExpandError, ExpandResult}; | 21 | pub use mbe::{ExpandError, ExpandResult}; |
@@ -207,7 +208,7 @@ impl MacroDefId { | |||
207 | MacroDefKind::BuiltIn(_, id) => id, | 208 | MacroDefKind::BuiltIn(_, id) => id, |
208 | MacroDefKind::BuiltInDerive(_, id) => id, | 209 | MacroDefKind::BuiltInDerive(_, id) => id, |
209 | MacroDefKind::BuiltInEager(_, id) => id, | 210 | MacroDefKind::BuiltInEager(_, id) => id, |
210 | MacroDefKind::ProcMacro(_, id) => return Either::Right(*id), | 211 | MacroDefKind::ProcMacro(.., id) => return Either::Right(*id), |
211 | }; | 212 | }; |
212 | Either::Left(*id) | 213 | Either::Left(*id) |
213 | } | 214 | } |
@@ -224,7 +225,7 @@ pub enum MacroDefKind { | |||
224 | // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander | 225 | // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander |
225 | BuiltInDerive(BuiltinDeriveExpander, AstId<ast::Macro>), | 226 | BuiltInDerive(BuiltinDeriveExpander, AstId<ast::Macro>), |
226 | BuiltInEager(EagerExpander, AstId<ast::Macro>), | 227 | BuiltInEager(EagerExpander, AstId<ast::Macro>), |
227 | ProcMacro(ProcMacroExpander, AstId<ast::Fn>), | 228 | ProcMacro(ProcMacroExpander, ProcMacroKind, AstId<ast::Fn>), |
228 | } | 229 | } |
229 | 230 | ||
230 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 231 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml index a9994082a..c3d02424d 100644 --- a/crates/hir_ty/Cargo.toml +++ b/crates/hir_ty/Cargo.toml | |||
@@ -18,9 +18,9 @@ ena = "0.14.0" | |||
18 | log = "0.4.8" | 18 | log = "0.4.8" |
19 | rustc-hash = "1.1.0" | 19 | rustc-hash = "1.1.0" |
20 | scoped-tls = "1" | 20 | scoped-tls = "1" |
21 | chalk-solve = { version = "0.67", default-features = false } | 21 | chalk-solve = { version = "0.68", default-features = false } |
22 | chalk-ir = "0.67" | 22 | chalk-ir = "0.68" |
23 | chalk-recursive = "0.67" | 23 | chalk-recursive = "0.68" |
24 | la-arena = { version = "0.2.0", path = "../../lib/arena" } | 24 | la-arena = { version = "0.2.0", path = "../../lib/arena" } |
25 | 25 | ||
26 | stdx = { path = "../stdx", version = "0.0.0" } | 26 | stdx = { path = "../stdx", version = "0.0.0" } |
diff --git a/crates/hir_ty/src/chalk_db.rs b/crates/hir_ty/src/chalk_db.rs index b108fd559..4e042bf42 100644 --- a/crates/hir_ty/src/chalk_db.rs +++ b/crates/hir_ty/src/chalk_db.rs | |||
@@ -383,7 +383,7 @@ pub(crate) fn associated_ty_data_query( | |||
383 | // Lower bounds -- we could/should maybe move this to a separate query in `lower` | 383 | // Lower bounds -- we could/should maybe move this to a separate query in `lower` |
384 | let type_alias_data = db.type_alias_data(type_alias); | 384 | let type_alias_data = db.type_alias_data(type_alias); |
385 | let generic_params = generics(db.upcast(), type_alias.into()); | 385 | let generic_params = generics(db.upcast(), type_alias.into()); |
386 | let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); | 386 | // let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); |
387 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); | 387 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); |
388 | let ctx = crate::TyLoweringContext::new(db, &resolver) | 388 | let ctx = crate::TyLoweringContext::new(db, &resolver) |
389 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); | 389 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); |
@@ -396,8 +396,10 @@ pub(crate) fn associated_ty_data_query( | |||
396 | .filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty)) | 396 | .filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty)) |
397 | .collect(); | 397 | .collect(); |
398 | 398 | ||
399 | let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars); | 399 | // FIXME: Re-enable where clauses on associated types when an upstream chalk bug is fixed. |
400 | let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses }; | 400 | // (rust-analyzer#9052) |
401 | // let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars); | ||
402 | let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses: vec![] }; | ||
401 | let datum = AssociatedTyDatum { | 403 | let datum = AssociatedTyDatum { |
402 | trait_id: to_chalk_trait_id(trait_), | 404 | trait_id: to_chalk_trait_id(trait_), |
403 | id, | 405 | id, |
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 8cefd80f3..7a4268819 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -558,7 +558,13 @@ impl<'a> InferenceContext<'a> { | |||
558 | 558 | ||
559 | self.infer_pat(*pat, &ty, BindingMode::default()); | 559 | self.infer_pat(*pat, &ty, BindingMode::default()); |
560 | } | 560 | } |
561 | let return_ty = self.make_ty_with_mode(&data.ret_type, ImplTraitLoweringMode::Disallowed); // FIXME implement RPIT | 561 | let error_ty = &TypeRef::Error; |
562 | let return_ty = if data.is_async() { | ||
563 | data.async_ret_type.as_deref().unwrap_or(error_ty) | ||
564 | } else { | ||
565 | &*data.ret_type | ||
566 | }; | ||
567 | let return_ty = self.make_ty_with_mode(return_ty, ImplTraitLoweringMode::Disallowed); // FIXME implement RPIT | ||
562 | self.return_ty = return_ty; | 568 | self.return_ty = return_ty; |
563 | } | 569 | } |
564 | 570 | ||
diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs index cc819373c..9d726b024 100644 --- a/crates/hir_ty/src/tests.rs +++ b/crates/hir_ty/src/tests.rs | |||
@@ -7,6 +7,7 @@ mod traits; | |||
7 | mod method_resolution; | 7 | mod method_resolution; |
8 | mod macros; | 8 | mod macros; |
9 | mod display_source_code; | 9 | mod display_source_code; |
10 | mod incremental; | ||
10 | 11 | ||
11 | use std::{env, sync::Arc}; | 12 | use std::{env, sync::Arc}; |
12 | 13 | ||
@@ -317,50 +318,6 @@ fn ellipsize(mut text: String, max_len: usize) -> String { | |||
317 | text | 318 | text |
318 | } | 319 | } |
319 | 320 | ||
320 | #[test] | ||
321 | fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | ||
322 | let (mut db, pos) = TestDB::with_position( | ||
323 | " | ||
324 | //- /lib.rs | ||
325 | fn foo() -> i32 { | ||
326 | $01 + 1 | ||
327 | } | ||
328 | ", | ||
329 | ); | ||
330 | { | ||
331 | let events = db.log_executed(|| { | ||
332 | let module = db.module_for_file(pos.file_id); | ||
333 | let crate_def_map = module.def_map(&db); | ||
334 | visit_module(&db, &crate_def_map, module.local_id, &mut |def| { | ||
335 | db.infer(def); | ||
336 | }); | ||
337 | }); | ||
338 | assert!(format!("{:?}", events).contains("infer")) | ||
339 | } | ||
340 | |||
341 | let new_text = " | ||
342 | fn foo() -> i32 { | ||
343 | 1 | ||
344 | + | ||
345 | 1 | ||
346 | } | ||
347 | " | ||
348 | .to_string(); | ||
349 | |||
350 | db.set_file_text(pos.file_id, Arc::new(new_text)); | ||
351 | |||
352 | { | ||
353 | let events = db.log_executed(|| { | ||
354 | let module = db.module_for_file(pos.file_id); | ||
355 | let crate_def_map = module.def_map(&db); | ||
356 | visit_module(&db, &crate_def_map, module.local_id, &mut |def| { | ||
357 | db.infer(def); | ||
358 | }); | ||
359 | }); | ||
360 | assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) | ||
361 | } | ||
362 | } | ||
363 | |||
364 | fn check_infer(ra_fixture: &str, expect: Expect) { | 321 | fn check_infer(ra_fixture: &str, expect: Expect) { |
365 | let mut actual = infer(ra_fixture); | 322 | let mut actual = infer(ra_fixture); |
366 | actual.push('\n'); | 323 | actual.push('\n'); |
diff --git a/crates/hir_ty/src/tests/incremental.rs b/crates/hir_ty/src/tests/incremental.rs new file mode 100644 index 000000000..3e08e83e8 --- /dev/null +++ b/crates/hir_ty/src/tests/incremental.rs | |||
@@ -0,0 +1,51 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use base_db::{fixture::WithFixture, SourceDatabaseExt}; | ||
4 | |||
5 | use crate::{db::HirDatabase, test_db::TestDB}; | ||
6 | |||
7 | use super::visit_module; | ||
8 | |||
9 | #[test] | ||
10 | fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | ||
11 | let (mut db, pos) = TestDB::with_position( | ||
12 | " | ||
13 | //- /lib.rs | ||
14 | fn foo() -> i32 { | ||
15 | $01 + 1 | ||
16 | } | ||
17 | ", | ||
18 | ); | ||
19 | { | ||
20 | let events = db.log_executed(|| { | ||
21 | let module = db.module_for_file(pos.file_id); | ||
22 | let crate_def_map = module.def_map(&db); | ||
23 | visit_module(&db, &crate_def_map, module.local_id, &mut |def| { | ||
24 | db.infer(def); | ||
25 | }); | ||
26 | }); | ||
27 | assert!(format!("{:?}", events).contains("infer")) | ||
28 | } | ||
29 | |||
30 | let new_text = " | ||
31 | fn foo() -> i32 { | ||
32 | 1 | ||
33 | + | ||
34 | 1 | ||
35 | } | ||
36 | " | ||
37 | .to_string(); | ||
38 | |||
39 | db.set_file_text(pos.file_id, Arc::new(new_text)); | ||
40 | |||
41 | { | ||
42 | let events = db.log_executed(|| { | ||
43 | let module = db.module_for_file(pos.file_id); | ||
44 | let crate_def_map = module.def_map(&db); | ||
45 | visit_module(&db, &crate_def_map, module.local_id, &mut |def| { | ||
46 | db.infer(def); | ||
47 | }); | ||
48 | }); | ||
49 | assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) | ||
50 | } | ||
51 | } | ||
diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index 6588aa46c..7647bb08b 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs | |||
@@ -752,6 +752,24 @@ fn bar() -> u32 {0} | |||
752 | } | 752 | } |
753 | 753 | ||
754 | #[test] | 754 | #[test] |
755 | fn infer_builtin_macros_include_expression() { | ||
756 | check_types( | ||
757 | r#" | ||
758 | //- /main.rs | ||
759 | #[rustc_builtin_macro] | ||
760 | macro_rules! include {() => {}} | ||
761 | fn main() { | ||
762 | let i = include!("bla.rs"); | ||
763 | i; | ||
764 | //^ i32 | ||
765 | } | ||
766 | //- /bla.rs | ||
767 | 0 | ||
768 | "#, | ||
769 | ) | ||
770 | } | ||
771 | |||
772 | #[test] | ||
755 | fn infer_builtin_macros_include_child_mod() { | 773 | fn infer_builtin_macros_include_child_mod() { |
756 | check_types( | 774 | check_types( |
757 | r#" | 775 | r#" |
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 6ad96bfe3..49add4ab9 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -161,7 +161,7 @@ mod result { | |||
161 | } | 161 | } |
162 | 162 | ||
163 | #[test] | 163 | #[test] |
164 | fn infer_tryv2() { | 164 | fn infer_try_trait_v2() { |
165 | check_types( | 165 | check_types( |
166 | r#" | 166 | r#" |
167 | //- /main.rs crate:main deps:core | 167 | //- /main.rs crate:main deps:core |
@@ -172,26 +172,41 @@ fn test() { | |||
172 | } //^ i32 | 172 | } //^ i32 |
173 | 173 | ||
174 | //- /core.rs crate:core | 174 | //- /core.rs crate:core |
175 | #[prelude_import] use ops::*; | ||
176 | mod ops { | 175 | mod ops { |
177 | trait Try { | 176 | mod try_trait { |
178 | type Output; | 177 | pub trait Try: FromResidual { |
179 | type Residual; | 178 | type Output; |
179 | type Residual; | ||
180 | } | ||
181 | pub trait FromResidual<R = <Self as Try>::Residual> {} | ||
180 | } | 182 | } |
183 | |||
184 | pub use self::try_trait::FromResidual; | ||
185 | pub use self::try_trait::Try; | ||
186 | } | ||
187 | |||
188 | mov convert { | ||
189 | pub trait From<T> {} | ||
190 | impl<T> From<T> for T {} | ||
181 | } | 191 | } |
182 | 192 | ||
183 | #[prelude_import] use result::*; | 193 | #[prelude_import] use result::*; |
184 | mod result { | 194 | mod result { |
185 | enum Infallible {} | 195 | use crate::convert::From; |
186 | enum Result<O, E> { | 196 | use crate::ops::{Try, FromResidual}; |
197 | |||
198 | pub enum Infallible {} | ||
199 | pub enum Result<O, E> { | ||
187 | Ok(O), | 200 | Ok(O), |
188 | Err(E) | 201 | Err(E) |
189 | } | 202 | } |
190 | 203 | ||
191 | impl<O, E> crate::ops::Try for Result<O, E> { | 204 | impl<O, E> Try for Result<O, E> { |
192 | type Output = O; | 205 | type Output = O; |
193 | type Error = Result<Infallible, E>; | 206 | type Error = Result<Infallible, E>; |
194 | } | 207 | } |
208 | |||
209 | impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {} | ||
195 | } | 210 | } |
196 | "#, | 211 | "#, |
197 | ); | 212 | ); |
@@ -3660,3 +3675,52 @@ impl foo::Foo for u32 { | |||
3660 | "#]], | 3675 | "#]], |
3661 | ); | 3676 | ); |
3662 | } | 3677 | } |
3678 | |||
3679 | #[test] | ||
3680 | fn infer_async_ret_type() { | ||
3681 | check_types( | ||
3682 | r#" | ||
3683 | //- /main.rs crate:main deps:core | ||
3684 | |||
3685 | enum Result<T, E> { | ||
3686 | Ok(T), | ||
3687 | Err(E), | ||
3688 | } | ||
3689 | |||
3690 | use Result::*; | ||
3691 | |||
3692 | |||
3693 | struct Fooey; | ||
3694 | |||
3695 | impl Fooey { | ||
3696 | fn collect<B: Convert>(self) -> B { | ||
3697 | B::new() | ||
3698 | } | ||
3699 | } | ||
3700 | |||
3701 | trait Convert { | ||
3702 | fn new() -> Self; | ||
3703 | } | ||
3704 | impl Convert for u32 { | ||
3705 | fn new() -> Self { | ||
3706 | 0 | ||
3707 | } | ||
3708 | } | ||
3709 | |||
3710 | async fn get_accounts() -> Result<u32, ()> { | ||
3711 | let ret = Fooey.collect(); | ||
3712 | // ^ u32 | ||
3713 | Ok(ret) | ||
3714 | } | ||
3715 | |||
3716 | //- /core.rs crate:core | ||
3717 | #[prelude_import] use future::*; | ||
3718 | mod future { | ||
3719 | #[lang = "future_trait"] | ||
3720 | trait Future { | ||
3721 | type Output; | ||
3722 | } | ||
3723 | } | ||
3724 | "#, | ||
3725 | ); | ||
3726 | } | ||
diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index b0c4ed60a..8d68dce05 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs | |||
@@ -58,7 +58,7 @@ pub(crate) fn annotations( | |||
58 | } | 58 | } |
59 | 59 | ||
60 | let action = runnable.action(); | 60 | let action = runnable.action(); |
61 | let range = runnable.nav.full_range; | 61 | let range = runnable.nav.focus_or_full_range(); |
62 | 62 | ||
63 | if config.run { | 63 | if config.run { |
64 | annotations.push(Annotation { | 64 | annotations.push(Annotation { |
@@ -224,7 +224,7 @@ fn main() { | |||
224 | expect![[r#" | 224 | expect![[r#" |
225 | [ | 225 | [ |
226 | Annotation { | 226 | Annotation { |
227 | range: 50..85, | 227 | range: 53..57, |
228 | kind: Runnable { | 228 | kind: Runnable { |
229 | debug: false, | 229 | debug: false, |
230 | runnable: Runnable { | 230 | runnable: Runnable { |
@@ -243,7 +243,7 @@ fn main() { | |||
243 | }, | 243 | }, |
244 | }, | 244 | }, |
245 | Annotation { | 245 | Annotation { |
246 | range: 50..85, | 246 | range: 53..57, |
247 | kind: Runnable { | 247 | kind: Runnable { |
248 | debug: true, | 248 | debug: true, |
249 | runnable: Runnable { | 249 | runnable: Runnable { |
@@ -328,7 +328,7 @@ fn main() { | |||
328 | expect![[r#" | 328 | expect![[r#" |
329 | [ | 329 | [ |
330 | Annotation { | 330 | Annotation { |
331 | range: 14..48, | 331 | range: 17..21, |
332 | kind: Runnable { | 332 | kind: Runnable { |
333 | debug: false, | 333 | debug: false, |
334 | runnable: Runnable { | 334 | runnable: Runnable { |
@@ -347,7 +347,7 @@ fn main() { | |||
347 | }, | 347 | }, |
348 | }, | 348 | }, |
349 | Annotation { | 349 | Annotation { |
350 | range: 14..48, | 350 | range: 17..21, |
351 | kind: Runnable { | 351 | kind: Runnable { |
352 | debug: true, | 352 | debug: true, |
353 | runnable: Runnable { | 353 | runnable: Runnable { |
@@ -436,7 +436,7 @@ fn main() { | |||
436 | expect![[r#" | 436 | expect![[r#" |
437 | [ | 437 | [ |
438 | Annotation { | 438 | Annotation { |
439 | range: 66..100, | 439 | range: 69..73, |
440 | kind: Runnable { | 440 | kind: Runnable { |
441 | debug: false, | 441 | debug: false, |
442 | runnable: Runnable { | 442 | runnable: Runnable { |
@@ -455,7 +455,7 @@ fn main() { | |||
455 | }, | 455 | }, |
456 | }, | 456 | }, |
457 | Annotation { | 457 | Annotation { |
458 | range: 66..100, | 458 | range: 69..73, |
459 | kind: Runnable { | 459 | kind: Runnable { |
460 | debug: true, | 460 | debug: true, |
461 | runnable: Runnable { | 461 | runnable: Runnable { |
@@ -597,7 +597,7 @@ fn main() {} | |||
597 | expect![[r#" | 597 | expect![[r#" |
598 | [ | 598 | [ |
599 | Annotation { | 599 | Annotation { |
600 | range: 0..12, | 600 | range: 3..7, |
601 | kind: Runnable { | 601 | kind: Runnable { |
602 | debug: false, | 602 | debug: false, |
603 | runnable: Runnable { | 603 | runnable: Runnable { |
@@ -616,7 +616,7 @@ fn main() {} | |||
616 | }, | 616 | }, |
617 | }, | 617 | }, |
618 | Annotation { | 618 | Annotation { |
619 | range: 0..12, | 619 | range: 3..7, |
620 | kind: Runnable { | 620 | kind: Runnable { |
621 | debug: true, | 621 | debug: true, |
622 | runnable: Runnable { | 622 | runnable: Runnable { |
@@ -670,7 +670,7 @@ fn main() { | |||
670 | expect![[r#" | 670 | expect![[r#" |
671 | [ | 671 | [ |
672 | Annotation { | 672 | Annotation { |
673 | range: 58..95, | 673 | range: 61..65, |
674 | kind: Runnable { | 674 | kind: Runnable { |
675 | debug: false, | 675 | debug: false, |
676 | runnable: Runnable { | 676 | runnable: Runnable { |
@@ -689,7 +689,7 @@ fn main() { | |||
689 | }, | 689 | }, |
690 | }, | 690 | }, |
691 | Annotation { | 691 | Annotation { |
692 | range: 58..95, | 692 | range: 61..65, |
693 | kind: Runnable { | 693 | kind: Runnable { |
694 | debug: true, | 694 | debug: true, |
695 | runnable: Runnable { | 695 | runnable: Runnable { |
@@ -812,7 +812,7 @@ mod tests { | |||
812 | expect![[r#" | 812 | expect![[r#" |
813 | [ | 813 | [ |
814 | Annotation { | 814 | Annotation { |
815 | range: 0..12, | 815 | range: 3..7, |
816 | kind: Runnable { | 816 | kind: Runnable { |
817 | debug: false, | 817 | debug: false, |
818 | runnable: Runnable { | 818 | runnable: Runnable { |
@@ -831,7 +831,7 @@ mod tests { | |||
831 | }, | 831 | }, |
832 | }, | 832 | }, |
833 | Annotation { | 833 | Annotation { |
834 | range: 0..12, | 834 | range: 3..7, |
835 | kind: Runnable { | 835 | kind: Runnable { |
836 | debug: true, | 836 | debug: true, |
837 | runnable: Runnable { | 837 | runnable: Runnable { |
@@ -850,7 +850,7 @@ mod tests { | |||
850 | }, | 850 | }, |
851 | }, | 851 | }, |
852 | Annotation { | 852 | Annotation { |
853 | range: 14..64, | 853 | range: 18..23, |
854 | kind: Runnable { | 854 | kind: Runnable { |
855 | debug: false, | 855 | debug: false, |
856 | runnable: Runnable { | 856 | runnable: Runnable { |
@@ -871,7 +871,7 @@ mod tests { | |||
871 | }, | 871 | }, |
872 | }, | 872 | }, |
873 | Annotation { | 873 | Annotation { |
874 | range: 14..64, | 874 | range: 18..23, |
875 | kind: Runnable { | 875 | kind: Runnable { |
876 | debug: true, | 876 | debug: true, |
877 | runnable: Runnable { | 877 | runnable: Runnable { |
@@ -892,7 +892,7 @@ mod tests { | |||
892 | }, | 892 | }, |
893 | }, | 893 | }, |
894 | Annotation { | 894 | Annotation { |
895 | range: 30..62, | 895 | range: 45..57, |
896 | kind: Runnable { | 896 | kind: Runnable { |
897 | debug: false, | 897 | debug: false, |
898 | runnable: Runnable { | 898 | runnable: Runnable { |
@@ -918,7 +918,7 @@ mod tests { | |||
918 | }, | 918 | }, |
919 | }, | 919 | }, |
920 | Annotation { | 920 | Annotation { |
921 | range: 30..62, | 921 | range: 45..57, |
922 | kind: Runnable { | 922 | kind: Runnable { |
923 | debug: true, | 923 | debug: true, |
924 | runnable: Runnable { | 924 | runnable: Runnable { |
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 6cf5810fa..d5c954b8b 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -182,6 +182,11 @@ pub(crate) fn diagnostics( | |||
182 | res.borrow_mut() | 182 | res.borrow_mut() |
183 | .push(Diagnostic::error(display_range, d.message()).with_code(Some(d.code()))); | 183 | .push(Diagnostic::error(display_range, d.message()).with_code(Some(d.code()))); |
184 | }) | 184 | }) |
185 | .on::<hir::diagnostics::UnimplementedBuiltinMacro, _>(|d| { | ||
186 | let display_range = sema.diagnostics_display_range(d.display_source()).range; | ||
187 | res.borrow_mut() | ||
188 | .push(Diagnostic::hint(display_range, d.message()).with_code(Some(d.code()))); | ||
189 | }) | ||
185 | // Only collect experimental diagnostics when they're enabled. | 190 | // Only collect experimental diagnostics when they're enabled. |
186 | .filter(|diag| !(diag.is_experimental() && config.disable_experimental)) | 191 | .filter(|diag| !(diag.is_experimental() && config.disable_experimental)) |
187 | .filter(|diag| !config.disabled.contains(diag.code().as_str())); | 192 | .filter(|diag| !config.disabled.contains(diag.code().as_str())); |
diff --git a/crates/ide/src/fixture.rs b/crates/ide/src/fixture.rs index cc6641ba1..6780af617 100644 --- a/crates/ide/src/fixture.rs +++ b/crates/ide/src/fixture.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Utilities for creating `Analysis` instances for tests. | 1 | //! Utilities for creating `Analysis` instances for tests. |
2 | use ide_db::base_db::fixture::ChangeFixture; | 2 | use ide_db::base_db::fixture::ChangeFixture; |
3 | use syntax::{TextRange, TextSize}; | 3 | use syntax::{TextRange, TextSize}; |
4 | use test_utils::{extract_annotations, RangeOrOffset}; | 4 | use test_utils::extract_annotations; |
5 | 5 | ||
6 | use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange}; | 6 | use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange}; |
7 | 7 | ||
@@ -27,10 +27,7 @@ pub(crate) fn position(ra_fixture: &str) -> (Analysis, FilePosition) { | |||
27 | let change_fixture = ChangeFixture::parse(ra_fixture); | 27 | let change_fixture = ChangeFixture::parse(ra_fixture); |
28 | host.db.apply_change(change_fixture.change); | 28 | host.db.apply_change(change_fixture.change); |
29 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); | 29 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); |
30 | let offset = match range_or_offset { | 30 | let offset = range_or_offset.expect_offset(); |
31 | RangeOrOffset::Range(_) => panic!(), | ||
32 | RangeOrOffset::Offset(it) => it, | ||
33 | }; | ||
34 | (host.analysis(), FilePosition { file_id, offset }) | 31 | (host.analysis(), FilePosition { file_id, offset }) |
35 | } | 32 | } |
36 | 33 | ||
@@ -40,10 +37,7 @@ pub(crate) fn range(ra_fixture: &str) -> (Analysis, FileRange) { | |||
40 | let change_fixture = ChangeFixture::parse(ra_fixture); | 37 | let change_fixture = ChangeFixture::parse(ra_fixture); |
41 | host.db.apply_change(change_fixture.change); | 38 | host.db.apply_change(change_fixture.change); |
42 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); | 39 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); |
43 | let range = match range_or_offset { | 40 | let range = range_or_offset.expect_range(); |
44 | RangeOrOffset::Range(it) => it, | ||
45 | RangeOrOffset::Offset(_) => panic!(), | ||
46 | }; | ||
47 | (host.analysis(), FileRange { file_id, range }) | 41 | (host.analysis(), FileRange { file_id, range }) |
48 | } | 42 | } |
49 | 43 | ||
@@ -53,10 +47,7 @@ pub(crate) fn annotations(ra_fixture: &str) -> (Analysis, FilePosition, Vec<(Fil | |||
53 | let change_fixture = ChangeFixture::parse(ra_fixture); | 47 | let change_fixture = ChangeFixture::parse(ra_fixture); |
54 | host.db.apply_change(change_fixture.change); | 48 | host.db.apply_change(change_fixture.change); |
55 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); | 49 | let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)"); |
56 | let offset = match range_or_offset { | 50 | let offset = range_or_offset.expect_offset(); |
57 | RangeOrOffset::Range(_) => panic!(), | ||
58 | RangeOrOffset::Offset(it) => it, | ||
59 | }; | ||
60 | 51 | ||
61 | let annotations = change_fixture | 52 | let annotations = change_fixture |
62 | .files | 53 | .files |
diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index b893c1c54..c5015a345 100755 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs | |||
@@ -19,6 +19,7 @@ pub enum FoldKind { | |||
19 | Statics, | 19 | Statics, |
20 | Array, | 20 | Array, |
21 | WhereClause, | 21 | WhereClause, |
22 | ReturnType, | ||
22 | } | 23 | } |
23 | 24 | ||
24 | #[derive(Debug)] | 25 | #[derive(Debug)] |
@@ -131,6 +132,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> { | |||
131 | COMMENT => Some(FoldKind::Comment), | 132 | COMMENT => Some(FoldKind::Comment), |
132 | ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), | 133 | ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), |
133 | ARRAY_EXPR => Some(FoldKind::Array), | 134 | ARRAY_EXPR => Some(FoldKind::Array), |
135 | RET_TYPE => Some(FoldKind::ReturnType), | ||
134 | ASSOC_ITEM_LIST | 136 | ASSOC_ITEM_LIST |
135 | | RECORD_FIELD_LIST | 137 | | RECORD_FIELD_LIST |
136 | | RECORD_PAT_FIELD_LIST | 138 | | RECORD_PAT_FIELD_LIST |
@@ -300,6 +302,7 @@ mod tests { | |||
300 | FoldKind::Statics => "statics", | 302 | FoldKind::Statics => "statics", |
301 | FoldKind::Array => "array", | 303 | FoldKind::Array => "array", |
302 | FoldKind::WhereClause => "whereclause", | 304 | FoldKind::WhereClause => "whereclause", |
305 | FoldKind::ReturnType => "returntype", | ||
303 | }; | 306 | }; |
304 | assert_eq!(kind, &attr.unwrap()); | 307 | assert_eq!(kind, &attr.unwrap()); |
305 | } | 308 | } |
@@ -560,4 +563,18 @@ where | |||
560 | "#, | 563 | "#, |
561 | ) | 564 | ) |
562 | } | 565 | } |
566 | |||
567 | #[test] | ||
568 | fn fold_return_type() { | ||
569 | check( | ||
570 | r#" | ||
571 | fn foo()<fold returntype>-> ( | ||
572 | bool, | ||
573 | bool, | ||
574 | )</fold> { (true, true) } | ||
575 | |||
576 | fn bar() -> (bool, bool) { (true, true) } | ||
577 | "#, | ||
578 | ) | ||
579 | } | ||
563 | } | 580 | } |
diff --git a/crates/ide_completion/Cargo.toml b/crates/ide_completion/Cargo.toml index 6bd8a5500..ba81c9e04 100644 --- a/crates/ide_completion/Cargo.toml +++ b/crates/ide_completion/Cargo.toml | |||
@@ -15,6 +15,7 @@ itertools = "0.10.0" | |||
15 | log = "0.4.8" | 15 | log = "0.4.8" |
16 | rustc-hash = "1.1.0" | 16 | rustc-hash = "1.1.0" |
17 | either = "1.6.1" | 17 | either = "1.6.1" |
18 | once_cell = "1.7" | ||
18 | 19 | ||
19 | stdx = { path = "../stdx", version = "0.0.0" } | 20 | stdx = { path = "../stdx", version = "0.0.0" } |
20 | syntax = { path = "../syntax", version = "0.0.0" } | 21 | syntax = { path = "../syntax", version = "0.0.0" } |
diff --git a/crates/ide_completion/src/completions.rs b/crates/ide_completion/src/completions.rs index 78154bf3e..151bf3783 100644 --- a/crates/ide_completion/src/completions.rs +++ b/crates/ide_completion/src/completions.rs | |||
@@ -18,7 +18,7 @@ pub(crate) mod unqualified_path; | |||
18 | 18 | ||
19 | use std::iter; | 19 | use std::iter; |
20 | 20 | ||
21 | use hir::{known, ModPath, ScopeDef, Type}; | 21 | use hir::known; |
22 | use ide_db::SymbolKind; | 22 | use ide_db::SymbolKind; |
23 | 23 | ||
24 | use crate::{ | 24 | use crate::{ |
@@ -69,12 +69,17 @@ impl Completions { | |||
69 | items.into_iter().for_each(|item| self.add(item.into())) | 69 | items.into_iter().for_each(|item| self.add(item.into())) |
70 | } | 70 | } |
71 | 71 | ||
72 | pub(crate) fn add_field(&mut self, ctx: &CompletionContext, field: hir::Field, ty: &Type) { | 72 | pub(crate) fn add_field(&mut self, ctx: &CompletionContext, field: hir::Field, ty: &hir::Type) { |
73 | let item = render_field(RenderContext::new(ctx), field, ty); | 73 | let item = render_field(RenderContext::new(ctx), field, ty); |
74 | self.add(item); | 74 | self.add(item); |
75 | } | 75 | } |
76 | 76 | ||
77 | pub(crate) fn add_tuple_field(&mut self, ctx: &CompletionContext, field: usize, ty: &Type) { | 77 | pub(crate) fn add_tuple_field( |
78 | &mut self, | ||
79 | ctx: &CompletionContext, | ||
80 | field: usize, | ||
81 | ty: &hir::Type, | ||
82 | ) { | ||
78 | let item = render_tuple_field(RenderContext::new(ctx), field, ty); | 83 | let item = render_tuple_field(RenderContext::new(ctx), field, ty); |
79 | self.add(item); | 84 | self.add(item); |
80 | } | 85 | } |
@@ -89,8 +94,8 @@ impl Completions { | |||
89 | pub(crate) fn add_resolution( | 94 | pub(crate) fn add_resolution( |
90 | &mut self, | 95 | &mut self, |
91 | ctx: &CompletionContext, | 96 | ctx: &CompletionContext, |
92 | local_name: String, | 97 | local_name: hir::Name, |
93 | resolution: &ScopeDef, | 98 | resolution: &hir::ScopeDef, |
94 | ) { | 99 | ) { |
95 | if let Some(item) = render_resolution(RenderContext::new(ctx), local_name, resolution) { | 100 | if let Some(item) = render_resolution(RenderContext::new(ctx), local_name, resolution) { |
96 | self.add(item); | 101 | self.add(item); |
@@ -100,7 +105,7 @@ impl Completions { | |||
100 | pub(crate) fn add_macro( | 105 | pub(crate) fn add_macro( |
101 | &mut self, | 106 | &mut self, |
102 | ctx: &CompletionContext, | 107 | ctx: &CompletionContext, |
103 | name: Option<String>, | 108 | name: Option<hir::Name>, |
104 | macro_: hir::MacroDef, | 109 | macro_: hir::MacroDef, |
105 | ) { | 110 | ) { |
106 | let name = match name { | 111 | let name = match name { |
@@ -116,7 +121,7 @@ impl Completions { | |||
116 | &mut self, | 121 | &mut self, |
117 | ctx: &CompletionContext, | 122 | ctx: &CompletionContext, |
118 | func: hir::Function, | 123 | func: hir::Function, |
119 | local_name: Option<String>, | 124 | local_name: Option<hir::Name>, |
120 | ) { | 125 | ) { |
121 | if let Some(item) = render_fn(RenderContext::new(ctx), None, local_name, func) { | 126 | if let Some(item) = render_fn(RenderContext::new(ctx), None, local_name, func) { |
122 | self.add(item) | 127 | self.add(item) |
@@ -127,7 +132,7 @@ impl Completions { | |||
127 | &mut self, | 132 | &mut self, |
128 | ctx: &CompletionContext, | 133 | ctx: &CompletionContext, |
129 | func: hir::Function, | 134 | func: hir::Function, |
130 | local_name: Option<String>, | 135 | local_name: Option<hir::Name>, |
131 | ) { | 136 | ) { |
132 | if let Some(item) = render_method(RenderContext::new(ctx), None, local_name, func) { | 137 | if let Some(item) = render_method(RenderContext::new(ctx), None, local_name, func) { |
133 | self.add(item) | 138 | self.add(item) |
@@ -149,7 +154,7 @@ impl Completions { | |||
149 | &mut self, | 154 | &mut self, |
150 | ctx: &CompletionContext, | 155 | ctx: &CompletionContext, |
151 | variant: hir::Variant, | 156 | variant: hir::Variant, |
152 | path: ModPath, | 157 | path: hir::ModPath, |
153 | ) { | 158 | ) { |
154 | if let Some(item) = render_variant_pat(RenderContext::new(ctx), variant, None, Some(path)) { | 159 | if let Some(item) = render_variant_pat(RenderContext::new(ctx), variant, None, Some(path)) { |
155 | self.add(item); | 160 | self.add(item); |
@@ -183,7 +188,7 @@ impl Completions { | |||
183 | &mut self, | 188 | &mut self, |
184 | ctx: &CompletionContext, | 189 | ctx: &CompletionContext, |
185 | variant: hir::Variant, | 190 | variant: hir::Variant, |
186 | path: ModPath, | 191 | path: hir::ModPath, |
187 | ) { | 192 | ) { |
188 | let item = render_variant(RenderContext::new(ctx), None, None, variant, Some(path)); | 193 | let item = render_variant(RenderContext::new(ctx), None, None, variant, Some(path)); |
189 | self.add(item); | 194 | self.add(item); |
@@ -193,7 +198,7 @@ impl Completions { | |||
193 | &mut self, | 198 | &mut self, |
194 | ctx: &CompletionContext, | 199 | ctx: &CompletionContext, |
195 | variant: hir::Variant, | 200 | variant: hir::Variant, |
196 | local_name: Option<String>, | 201 | local_name: Option<hir::Name>, |
197 | ) { | 202 | ) { |
198 | let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None); | 203 | let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None); |
199 | self.add(item); | 204 | self.add(item); |
diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs index b1505c74b..76d926157 100644 --- a/crates/ide_completion/src/completions/attribute.rs +++ b/crates/ide_completion/src/completions/attribute.rs | |||
@@ -3,9 +3,9 @@ | |||
3 | //! This module uses a bit of static metadata to provide completions | 3 | //! This module uses a bit of static metadata to provide completions |
4 | //! for built-in attributes. | 4 | //! for built-in attributes. |
5 | 5 | ||
6 | use itertools::Itertools; | 6 | use once_cell::sync::Lazy; |
7 | use rustc_hash::FxHashSet; | 7 | use rustc_hash::{FxHashMap, FxHashSet}; |
8 | use syntax::{ast, AstNode, T}; | 8 | use syntax::{ast, AstNode, NodeOrToken, SyntaxKind, T}; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | context::CompletionContext, | 11 | context::CompletionContext, |
@@ -14,33 +14,40 @@ use crate::{ | |||
14 | Completions, | 14 | Completions, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { | 17 | mod derive; |
18 | if ctx.mod_declaration_under_caret.is_some() { | 18 | mod lint; |
19 | return None; | 19 | pub(crate) use self::lint::LintCompletion; |
20 | } | ||
21 | 20 | ||
21 | pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { | ||
22 | let attribute = ctx.attribute_under_caret.as_ref()?; | 22 | let attribute = ctx.attribute_under_caret.as_ref()?; |
23 | match (attribute.path(), attribute.token_tree()) { | 23 | match (attribute.path().and_then(|p| p.as_single_name_ref()), attribute.token_tree()) { |
24 | (Some(path), Some(token_tree)) => { | 24 | (Some(path), Some(token_tree)) => match path.text().as_str() { |
25 | let path = path.syntax().text(); | 25 | "derive" => derive::complete_derive(acc, ctx, token_tree), |
26 | if path == "derive" { | 26 | "feature" => lint::complete_lint(acc, ctx, token_tree, FEATURES), |
27 | complete_derive(acc, ctx, token_tree) | 27 | "allow" | "warn" | "deny" | "forbid" => { |
28 | } else if path == "feature" { | 28 | lint::complete_lint(acc, ctx, token_tree.clone(), lint::DEFAULT_LINT_COMPLETIONS); |
29 | complete_lint(acc, ctx, token_tree, FEATURES) | 29 | lint::complete_lint(acc, ctx, token_tree, CLIPPY_LINTS); |
30 | } else if path == "allow" || path == "warn" || path == "deny" || path == "forbid" { | ||
31 | complete_lint(acc, ctx, token_tree.clone(), DEFAULT_LINT_COMPLETIONS); | ||
32 | complete_lint(acc, ctx, token_tree, CLIPPY_LINTS); | ||
33 | } | 30 | } |
34 | } | 31 | _ => (), |
35 | (_, Some(_token_tree)) => {} | 32 | }, |
36 | _ => complete_attribute_start(acc, ctx, attribute), | 33 | (None, Some(_)) => (), |
34 | _ => complete_new_attribute(acc, ctx, attribute), | ||
37 | } | 35 | } |
38 | Some(()) | 36 | Some(()) |
39 | } | 37 | } |
40 | 38 | ||
41 | fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attribute: &ast::Attr) { | 39 | fn complete_new_attribute(acc: &mut Completions, ctx: &CompletionContext, attribute: &ast::Attr) { |
40 | let attribute_annotated_item_kind = attribute.syntax().parent().map(|it| it.kind()); | ||
41 | let attributes = attribute_annotated_item_kind.and_then(|kind| { | ||
42 | if ast::Expr::can_cast(kind) { | ||
43 | Some(EXPR_ATTRIBUTES) | ||
44 | } else { | ||
45 | KIND_TO_ATTRIBUTES.get(&kind).copied() | ||
46 | } | ||
47 | }); | ||
42 | let is_inner = attribute.kind() == ast::AttrKind::Inner; | 48 | let is_inner = attribute.kind() == ast::AttrKind::Inner; |
43 | for attr_completion in ATTRIBUTES.iter().filter(|compl| is_inner || !compl.prefer_inner) { | 49 | |
50 | let add_completion = |attr_completion: &AttrCompletion| { | ||
44 | let mut item = CompletionItem::new( | 51 | let mut item = CompletionItem::new( |
45 | CompletionKind::Attribute, | 52 | CompletionKind::Attribute, |
46 | ctx.source_range(), | 53 | ctx.source_range(), |
@@ -56,9 +63,19 @@ fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attr | |||
56 | item.insert_snippet(cap, snippet); | 63 | item.insert_snippet(cap, snippet); |
57 | } | 64 | } |
58 | 65 | ||
59 | if attribute.kind() == ast::AttrKind::Inner || !attr_completion.prefer_inner { | 66 | if is_inner || !attr_completion.prefer_inner { |
60 | acc.add(item.build()); | 67 | acc.add(item.build()); |
61 | } | 68 | } |
69 | }; | ||
70 | |||
71 | match attributes { | ||
72 | Some(applicable) => applicable | ||
73 | .iter() | ||
74 | .flat_map(|name| ATTRIBUTES.binary_search_by(|attr| attr.key().cmp(name)).ok()) | ||
75 | .flat_map(|idx| ATTRIBUTES.get(idx)) | ||
76 | .for_each(add_completion), | ||
77 | None if is_inner => ATTRIBUTES.iter().for_each(add_completion), | ||
78 | None => ATTRIBUTES.iter().filter(|compl| !compl.prefer_inner).for_each(add_completion), | ||
62 | } | 79 | } |
63 | } | 80 | } |
64 | 81 | ||
@@ -70,6 +87,10 @@ struct AttrCompletion { | |||
70 | } | 87 | } |
71 | 88 | ||
72 | impl AttrCompletion { | 89 | impl AttrCompletion { |
90 | fn key(&self) -> &'static str { | ||
91 | self.lookup.unwrap_or(self.label) | ||
92 | } | ||
93 | |||
73 | const fn prefer_inner(self) -> AttrCompletion { | 94 | const fn prefer_inner(self) -> AttrCompletion { |
74 | AttrCompletion { prefer_inner: true, ..self } | 95 | AttrCompletion { prefer_inner: true, ..self } |
75 | } | 96 | } |
@@ -83,30 +104,122 @@ const fn attr( | |||
83 | AttrCompletion { label, lookup, snippet, prefer_inner: false } | 104 | AttrCompletion { label, lookup, snippet, prefer_inner: false } |
84 | } | 105 | } |
85 | 106 | ||
107 | macro_rules! attrs { | ||
108 | // attributes applicable to all items | ||
109 | [@ { item $($tt:tt)* } {$($acc:tt)*}] => { | ||
110 | attrs!(@ { $($tt)* } { $($acc)*, "deprecated", "doc", "dochidden", "docalias", "must_use", "no_mangle" }) | ||
111 | }; | ||
112 | // attributes applicable to all adts | ||
113 | [@ { adt $($tt:tt)* } {$($acc:tt)*}] => { | ||
114 | attrs!(@ { $($tt)* } { $($acc)*, "derive", "repr" }) | ||
115 | }; | ||
116 | // attributes applicable to all linkable things aka functions/statics | ||
117 | [@ { linkable $($tt:tt)* } {$($acc:tt)*}] => { | ||
118 | attrs!(@ { $($tt)* } { $($acc)*, "export_name", "link_name", "link_section" }) | ||
119 | }; | ||
120 | // error fallback for nicer error message | ||
121 | [@ { $ty:ident $($tt:tt)* } {$($acc:tt)*}] => { | ||
122 | compile_error!(concat!("unknown attr subtype ", stringify!($ty))) | ||
123 | }; | ||
124 | // general push down accumulation | ||
125 | [@ { $lit:literal $($tt:tt)*} {$($acc:tt)*}] => { | ||
126 | attrs!(@ { $($tt)* } { $($acc)*, $lit }) | ||
127 | }; | ||
128 | [@ {$($tt:tt)+} {$($tt2:tt)*}] => { | ||
129 | compile_error!(concat!("Unexpected input ", stringify!($($tt)+))) | ||
130 | }; | ||
131 | // final output construction | ||
132 | [@ {} {$($tt:tt)*}] => { &[$($tt)*] as _ }; | ||
133 | // starting matcher | ||
134 | [$($tt:tt),*] => { | ||
135 | attrs!(@ { $($tt)* } { "allow", "cfg", "cfg_attr", "deny", "forbid", "warn" }) | ||
136 | }; | ||
137 | } | ||
138 | |||
139 | #[rustfmt::skip] | ||
140 | static KIND_TO_ATTRIBUTES: Lazy<FxHashMap<SyntaxKind, &[&str]>> = Lazy::new(|| { | ||
141 | use SyntaxKind::*; | ||
142 | std::array::IntoIter::new([ | ||
143 | ( | ||
144 | SOURCE_FILE, | ||
145 | attrs!( | ||
146 | item, | ||
147 | "crate_name", "feature", "no_implicit_prelude", "no_main", "no_std", | ||
148 | "recursion_limit", "type_length_limit", "windows_subsystem" | ||
149 | ), | ||
150 | ), | ||
151 | (MODULE, attrs!(item, "no_implicit_prelude", "path")), | ||
152 | (ITEM_LIST, attrs!(item, "no_implicit_prelude")), | ||
153 | (MACRO_RULES, attrs!(item, "macro_export", "macro_use")), | ||
154 | (MACRO_DEF, attrs!(item)), | ||
155 | (EXTERN_CRATE, attrs!(item, "macro_use", "no_link")), | ||
156 | (USE, attrs!(item)), | ||
157 | (TYPE_ALIAS, attrs!(item)), | ||
158 | (STRUCT, attrs!(item, adt, "non_exhaustive")), | ||
159 | (ENUM, attrs!(item, adt, "non_exhaustive")), | ||
160 | (UNION, attrs!(item, adt)), | ||
161 | (CONST, attrs!(item)), | ||
162 | ( | ||
163 | FN, | ||
164 | attrs!( | ||
165 | item, linkable, | ||
166 | "cold", "ignore", "inline", "must_use", "panic_handler", "proc_macro", | ||
167 | "proc_macro_derive", "proc_macro_attribute", "should_panic", "target_feature", | ||
168 | "test", "track_caller" | ||
169 | ), | ||
170 | ), | ||
171 | (STATIC, attrs!(item, linkable, "global_allocator", "used")), | ||
172 | (TRAIT, attrs!(item, "must_use")), | ||
173 | (IMPL, attrs!(item, "automatically_derived")), | ||
174 | (ASSOC_ITEM_LIST, attrs!(item)), | ||
175 | (EXTERN_BLOCK, attrs!(item, "link")), | ||
176 | (EXTERN_ITEM_LIST, attrs!(item, "link")), | ||
177 | (MACRO_CALL, attrs!()), | ||
178 | (SELF_PARAM, attrs!()), | ||
179 | (PARAM, attrs!()), | ||
180 | (RECORD_FIELD, attrs!()), | ||
181 | (VARIANT, attrs!("non_exhaustive")), | ||
182 | (TYPE_PARAM, attrs!()), | ||
183 | (CONST_PARAM, attrs!()), | ||
184 | (LIFETIME_PARAM, attrs!()), | ||
185 | (LET_STMT, attrs!()), | ||
186 | (EXPR_STMT, attrs!()), | ||
187 | (LITERAL, attrs!()), | ||
188 | (RECORD_EXPR_FIELD_LIST, attrs!()), | ||
189 | (RECORD_EXPR_FIELD, attrs!()), | ||
190 | (MATCH_ARM_LIST, attrs!()), | ||
191 | (MATCH_ARM, attrs!()), | ||
192 | (IDENT_PAT, attrs!()), | ||
193 | (RECORD_PAT_FIELD, attrs!()), | ||
194 | ]) | ||
195 | .collect() | ||
196 | }); | ||
197 | const EXPR_ATTRIBUTES: &[&str] = attrs!(); | ||
198 | |||
86 | /// https://doc.rust-lang.org/reference/attributes.html#built-in-attributes-index | 199 | /// https://doc.rust-lang.org/reference/attributes.html#built-in-attributes-index |
200 | // Keep these sorted for the binary search! | ||
87 | const ATTRIBUTES: &[AttrCompletion] = &[ | 201 | const ATTRIBUTES: &[AttrCompletion] = &[ |
88 | attr("allow(…)", Some("allow"), Some("allow(${0:lint})")), | 202 | attr("allow(…)", Some("allow"), Some("allow(${0:lint})")), |
89 | attr("automatically_derived", None, None), | 203 | attr("automatically_derived", None, None), |
90 | attr("cfg_attr(…)", Some("cfg_attr"), Some("cfg_attr(${1:predicate}, ${0:attr})")), | ||
91 | attr("cfg(…)", Some("cfg"), Some("cfg(${0:predicate})")), | 204 | attr("cfg(…)", Some("cfg"), Some("cfg(${0:predicate})")), |
205 | attr("cfg_attr(…)", Some("cfg_attr"), Some("cfg_attr(${1:predicate}, ${0:attr})")), | ||
92 | attr("cold", None, None), | 206 | attr("cold", None, None), |
93 | attr(r#"crate_name = """#, Some("crate_name"), Some(r#"crate_name = "${0:crate_name}""#)) | 207 | attr(r#"crate_name = """#, Some("crate_name"), Some(r#"crate_name = "${0:crate_name}""#)) |
94 | .prefer_inner(), | 208 | .prefer_inner(), |
95 | attr("deny(…)", Some("deny"), Some("deny(${0:lint})")), | 209 | attr("deny(…)", Some("deny"), Some("deny(${0:lint})")), |
96 | attr(r#"deprecated"#, Some("deprecated"), Some(r#"deprecated"#)), | 210 | attr(r#"deprecated"#, Some("deprecated"), Some(r#"deprecated"#)), |
97 | attr("derive(…)", Some("derive"), Some(r#"derive(${0:Debug})"#)), | 211 | attr("derive(…)", Some("derive"), Some(r#"derive(${0:Debug})"#)), |
212 | attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)), | ||
213 | attr(r#"doc(alias = "…")"#, Some("docalias"), Some(r#"doc(alias = "${0:docs}")"#)), | ||
214 | attr(r#"doc(hidden)"#, Some("dochidden"), Some(r#"doc(hidden)"#)), | ||
98 | attr( | 215 | attr( |
99 | r#"export_name = "…""#, | 216 | r#"export_name = "…""#, |
100 | Some("export_name"), | 217 | Some("export_name"), |
101 | Some(r#"export_name = "${0:exported_symbol_name}""#), | 218 | Some(r#"export_name = "${0:exported_symbol_name}""#), |
102 | ), | 219 | ), |
103 | attr(r#"doc(alias = "…")"#, Some("docalias"), Some(r#"doc(alias = "${0:docs}")"#)), | ||
104 | attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)), | ||
105 | attr(r#"doc(hidden)"#, Some("dochidden"), Some(r#"doc(hidden)"#)), | ||
106 | attr("feature(…)", Some("feature"), Some("feature(${0:flag})")).prefer_inner(), | 220 | attr("feature(…)", Some("feature"), Some("feature(${0:flag})")).prefer_inner(), |
107 | attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")), | 221 | attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")), |
108 | // FIXME: resolve through macro resolution? | 222 | attr("global_allocator", None, None), |
109 | attr("global_allocator", None, None).prefer_inner(), | ||
110 | attr(r#"ignore = "…""#, Some("ignore"), Some(r#"ignore = "${0:reason}""#)), | 223 | attr(r#"ignore = "…""#, Some("ignore"), Some(r#"ignore = "${0:reason}""#)), |
111 | attr("inline", Some("inline"), Some("inline")), | 224 | attr("inline", Some("inline"), Some("inline")), |
112 | attr("link", None, None), | 225 | attr("link", None, None), |
@@ -119,13 +232,13 @@ const ATTRIBUTES: &[AttrCompletion] = &[ | |||
119 | attr("macro_export", None, None), | 232 | attr("macro_export", None, None), |
120 | attr("macro_use", None, None), | 233 | attr("macro_use", None, None), |
121 | attr(r#"must_use"#, Some("must_use"), Some(r#"must_use"#)), | 234 | attr(r#"must_use"#, Some("must_use"), Some(r#"must_use"#)), |
122 | attr("no_link", None, None).prefer_inner(), | ||
123 | attr("no_implicit_prelude", None, None).prefer_inner(), | 235 | attr("no_implicit_prelude", None, None).prefer_inner(), |
236 | attr("no_link", None, None).prefer_inner(), | ||
124 | attr("no_main", None, None).prefer_inner(), | 237 | attr("no_main", None, None).prefer_inner(), |
125 | attr("no_mangle", None, None), | 238 | attr("no_mangle", None, None), |
126 | attr("no_std", None, None).prefer_inner(), | 239 | attr("no_std", None, None).prefer_inner(), |
127 | attr("non_exhaustive", None, None), | 240 | attr("non_exhaustive", None, None), |
128 | attr("panic_handler", None, None).prefer_inner(), | 241 | attr("panic_handler", None, None), |
129 | attr(r#"path = "…""#, Some("path"), Some(r#"path ="${0:path}""#)), | 242 | attr(r#"path = "…""#, Some("path"), Some(r#"path ="${0:path}""#)), |
130 | attr("proc_macro", None, None), | 243 | attr("proc_macro", None, None), |
131 | attr("proc_macro_attribute", None, None), | 244 | attr("proc_macro_attribute", None, None), |
@@ -153,412 +266,518 @@ const ATTRIBUTES: &[AttrCompletion] = &[ | |||
153 | .prefer_inner(), | 266 | .prefer_inner(), |
154 | ]; | 267 | ]; |
155 | 268 | ||
156 | fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) { | 269 | fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Option<FxHashSet<String>> { |
157 | if let Ok(existing_derives) = parse_comma_sep_input(derive_input) { | 270 | let (l_paren, r_paren) = derive_input.l_paren_token().zip(derive_input.r_paren_token())?; |
158 | for derive_completion in DEFAULT_DERIVE_COMPLETIONS | 271 | let mut input_derives = FxHashSet::default(); |
159 | .iter() | 272 | let mut tokens = derive_input |
160 | .filter(|completion| !existing_derives.contains(completion.label)) | 273 | .syntax() |
161 | { | 274 | .children_with_tokens() |
162 | let mut components = vec![derive_completion.label]; | 275 | .filter_map(NodeOrToken::into_token) |
163 | components.extend( | 276 | .skip_while(|token| token != &l_paren) |
164 | derive_completion | 277 | .skip(1) |
165 | .dependencies | 278 | .take_while(|token| token != &r_paren) |
166 | .iter() | 279 | .peekable(); |
167 | .filter(|&&dependency| !existing_derives.contains(dependency)), | 280 | let mut input = String::new(); |
168 | ); | 281 | while tokens.peek().is_some() { |
169 | let lookup = components.join(", "); | 282 | for token in tokens.by_ref().take_while(|t| t.kind() != T![,]) { |
170 | let label = components.iter().rev().join(", "); | 283 | input.push_str(token.text()); |
171 | let mut item = | ||
172 | CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label); | ||
173 | item.lookup_by(lookup).kind(CompletionItemKind::Attribute); | ||
174 | item.add_to(acc); | ||
175 | } | ||
176 | |||
177 | for custom_derive_name in get_derive_names_in_scope(ctx).difference(&existing_derives) { | ||
178 | let mut item = CompletionItem::new( | ||
179 | CompletionKind::Attribute, | ||
180 | ctx.source_range(), | ||
181 | custom_derive_name, | ||
182 | ); | ||
183 | item.kind(CompletionItemKind::Attribute); | ||
184 | item.add_to(acc); | ||
185 | } | 284 | } |
186 | } | ||
187 | } | ||
188 | 285 | ||
189 | fn complete_lint( | 286 | if !input.is_empty() { |
190 | acc: &mut Completions, | 287 | input_derives.insert(input.trim().to_owned()); |
191 | ctx: &CompletionContext, | ||
192 | derive_input: ast::TokenTree, | ||
193 | lints_completions: &[LintCompletion], | ||
194 | ) { | ||
195 | if let Ok(existing_lints) = parse_comma_sep_input(derive_input) { | ||
196 | for lint_completion in lints_completions | ||
197 | .into_iter() | ||
198 | .filter(|completion| !existing_lints.contains(completion.label)) | ||
199 | { | ||
200 | let mut item = CompletionItem::new( | ||
201 | CompletionKind::Attribute, | ||
202 | ctx.source_range(), | ||
203 | lint_completion.label, | ||
204 | ); | ||
205 | item.kind(CompletionItemKind::Attribute).detail(lint_completion.description); | ||
206 | item.add_to(acc) | ||
207 | } | 288 | } |
208 | } | ||
209 | } | ||
210 | 289 | ||
211 | fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Result<FxHashSet<String>, ()> { | 290 | input.clear(); |
212 | match (derive_input.left_delimiter_token(), derive_input.right_delimiter_token()) { | ||
213 | (Some(left_paren), Some(right_paren)) | ||
214 | if left_paren.kind() == T!['('] && right_paren.kind() == T![')'] => | ||
215 | { | ||
216 | let mut input_derives = FxHashSet::default(); | ||
217 | let mut current_derive = String::new(); | ||
218 | for token in derive_input | ||
219 | .syntax() | ||
220 | .children_with_tokens() | ||
221 | .filter_map(|token| token.into_token()) | ||
222 | .skip_while(|token| token != &left_paren) | ||
223 | .skip(1) | ||
224 | .take_while(|token| token != &right_paren) | ||
225 | { | ||
226 | if T![,] == token.kind() { | ||
227 | if !current_derive.is_empty() { | ||
228 | input_derives.insert(current_derive); | ||
229 | current_derive = String::new(); | ||
230 | } | ||
231 | } else { | ||
232 | current_derive.push_str(token.text().trim()); | ||
233 | } | ||
234 | } | ||
235 | |||
236 | if !current_derive.is_empty() { | ||
237 | input_derives.insert(current_derive); | ||
238 | } | ||
239 | Ok(input_derives) | ||
240 | } | ||
241 | _ => Err(()), | ||
242 | } | 291 | } |
243 | } | ||
244 | |||
245 | fn get_derive_names_in_scope(ctx: &CompletionContext) -> FxHashSet<String> { | ||
246 | let mut result = FxHashSet::default(); | ||
247 | ctx.scope.process_all_names(&mut |name, scope_def| { | ||
248 | if let hir::ScopeDef::MacroDef(mac) = scope_def { | ||
249 | // FIXME kind() doesn't check whether proc-macro is a derive | ||
250 | if mac.kind() == hir::MacroKind::Derive || mac.kind() == hir::MacroKind::ProcMacro { | ||
251 | result.insert(name.to_string()); | ||
252 | } | ||
253 | } | ||
254 | }); | ||
255 | result | ||
256 | } | ||
257 | |||
258 | struct DeriveCompletion { | ||
259 | label: &'static str, | ||
260 | dependencies: &'static [&'static str], | ||
261 | } | ||
262 | |||
263 | /// Standard Rust derives and the information about their dependencies | ||
264 | /// (the dependencies are needed so that the main derive don't break the compilation when added) | ||
265 | const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[ | ||
266 | DeriveCompletion { label: "Clone", dependencies: &[] }, | ||
267 | DeriveCompletion { label: "Copy", dependencies: &["Clone"] }, | ||
268 | DeriveCompletion { label: "Debug", dependencies: &[] }, | ||
269 | DeriveCompletion { label: "Default", dependencies: &[] }, | ||
270 | DeriveCompletion { label: "Hash", dependencies: &[] }, | ||
271 | DeriveCompletion { label: "PartialEq", dependencies: &[] }, | ||
272 | DeriveCompletion { label: "Eq", dependencies: &["PartialEq"] }, | ||
273 | DeriveCompletion { label: "PartialOrd", dependencies: &["PartialEq"] }, | ||
274 | DeriveCompletion { label: "Ord", dependencies: &["PartialOrd", "Eq", "PartialEq"] }, | ||
275 | ]; | ||
276 | 292 | ||
277 | pub(crate) struct LintCompletion { | 293 | Some(input_derives) |
278 | pub(crate) label: &'static str, | ||
279 | pub(crate) description: &'static str, | ||
280 | } | 294 | } |
281 | 295 | ||
282 | #[rustfmt::skip] | ||
283 | const DEFAULT_LINT_COMPLETIONS: &[LintCompletion] = &[ | ||
284 | LintCompletion { label: "absolute_paths_not_starting_with_crate", description: r#"fully qualified paths that start with a module name instead of `crate`, `self`, or an extern crate name"# }, | ||
285 | LintCompletion { label: "anonymous_parameters", description: r#"detects anonymous parameters"# }, | ||
286 | LintCompletion { label: "box_pointers", description: r#"use of owned (Box type) heap memory"# }, | ||
287 | LintCompletion { label: "deprecated_in_future", description: r#"detects use of items that will be deprecated in a future version"# }, | ||
288 | LintCompletion { label: "elided_lifetimes_in_paths", description: r#"hidden lifetime parameters in types are deprecated"# }, | ||
289 | LintCompletion { label: "explicit_outlives_requirements", description: r#"outlives requirements can be inferred"# }, | ||
290 | LintCompletion { label: "indirect_structural_match", description: r#"pattern with const indirectly referencing non-structural-match type"# }, | ||
291 | LintCompletion { label: "keyword_idents", description: r#"detects edition keywords being used as an identifier"# }, | ||
292 | LintCompletion { label: "macro_use_extern_crate", description: r#"the `#[macro_use]` attribute is now deprecated in favor of using macros via the module system"# }, | ||
293 | LintCompletion { label: "meta_variable_misuse", description: r#"possible meta-variable misuse at macro definition"# }, | ||
294 | LintCompletion { label: "missing_copy_implementations", description: r#"detects potentially-forgotten implementations of `Copy`"# }, | ||
295 | LintCompletion { label: "missing_crate_level_docs", description: r#"detects crates with no crate-level documentation"# }, | ||
296 | LintCompletion { label: "missing_debug_implementations", description: r#"detects missing implementations of Debug"# }, | ||
297 | LintCompletion { label: "missing_docs", description: r#"detects missing documentation for public members"# }, | ||
298 | LintCompletion { label: "missing_doc_code_examples", description: r#"detects publicly-exported items without code samples in their documentation"# }, | ||
299 | LintCompletion { label: "non_ascii_idents", description: r#"detects non-ASCII identifiers"# }, | ||
300 | LintCompletion { label: "private_doc_tests", description: r#"detects code samples in docs of private items not documented by rustdoc"# }, | ||
301 | LintCompletion { label: "single_use_lifetimes", description: r#"detects lifetime parameters that are only used once"# }, | ||
302 | LintCompletion { label: "trivial_casts", description: r#"detects trivial casts which could be removed"# }, | ||
303 | LintCompletion { label: "trivial_numeric_casts", description: r#"detects trivial casts of numeric types which could be removed"# }, | ||
304 | LintCompletion { label: "unaligned_references", description: r#"detects unaligned references to fields of packed structs"# }, | ||
305 | LintCompletion { label: "unreachable_pub", description: r#"`pub` items not reachable from crate root"# }, | ||
306 | LintCompletion { label: "unsafe_code", description: r#"usage of `unsafe` code"# }, | ||
307 | LintCompletion { label: "unsafe_op_in_unsafe_fn", description: r#"unsafe operations in unsafe functions without an explicit unsafe block are deprecated"# }, | ||
308 | LintCompletion { label: "unstable_features", description: r#"enabling unstable features (deprecated. do not use)"# }, | ||
309 | LintCompletion { label: "unused_crate_dependencies", description: r#"crate dependencies that are never used"# }, | ||
310 | LintCompletion { label: "unused_extern_crates", description: r#"extern crates that are never used"# }, | ||
311 | LintCompletion { label: "unused_import_braces", description: r#"unnecessary braces around an imported item"# }, | ||
312 | LintCompletion { label: "unused_lifetimes", description: r#"detects lifetime parameters that are never used"# }, | ||
313 | LintCompletion { label: "unused_qualifications", description: r#"detects unnecessarily qualified names"# }, | ||
314 | LintCompletion { label: "unused_results", description: r#"unused result of an expression in a statement"# }, | ||
315 | LintCompletion { label: "variant_size_differences", description: r#"detects enums with widely varying variant sizes"# }, | ||
316 | LintCompletion { label: "array_into_iter", description: r#"detects calling `into_iter` on arrays"# }, | ||
317 | LintCompletion { label: "asm_sub_register", description: r#"using only a subset of a register for inline asm inputs"# }, | ||
318 | LintCompletion { label: "bare_trait_objects", description: r#"suggest using `dyn Trait` for trait objects"# }, | ||
319 | LintCompletion { label: "bindings_with_variant_name", description: r#"detects pattern bindings with the same name as one of the matched variants"# }, | ||
320 | LintCompletion { label: "cenum_impl_drop_cast", description: r#"a C-like enum implementing Drop is cast"# }, | ||
321 | LintCompletion { label: "clashing_extern_declarations", description: r#"detects when an extern fn has been declared with the same name but different types"# }, | ||
322 | LintCompletion { label: "coherence_leak_check", description: r#"distinct impls distinguished only by the leak-check code"# }, | ||
323 | LintCompletion { label: "confusable_idents", description: r#"detects visually confusable pairs between identifiers"# }, | ||
324 | LintCompletion { label: "dead_code", description: r#"detect unused, unexported items"# }, | ||
325 | LintCompletion { label: "deprecated", description: r#"detects use of deprecated items"# }, | ||
326 | LintCompletion { label: "ellipsis_inclusive_range_patterns", description: r#"`...` range patterns are deprecated"# }, | ||
327 | LintCompletion { label: "exported_private_dependencies", description: r#"public interface leaks type from a private dependency"# }, | ||
328 | LintCompletion { label: "illegal_floating_point_literal_pattern", description: r#"floating-point literals cannot be used in patterns"# }, | ||
329 | LintCompletion { label: "improper_ctypes", description: r#"proper use of libc types in foreign modules"# }, | ||
330 | LintCompletion { label: "improper_ctypes_definitions", description: r#"proper use of libc types in foreign item definitions"# }, | ||
331 | LintCompletion { label: "incomplete_features", description: r#"incomplete features that may function improperly in some or all cases"# }, | ||
332 | LintCompletion { label: "inline_no_sanitize", description: r#"detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`"# }, | ||
333 | LintCompletion { label: "intra_doc_link_resolution_failure", description: r#"failures in resolving intra-doc link targets"# }, | ||
334 | LintCompletion { label: "invalid_codeblock_attributes", description: r#"codeblock attribute looks a lot like a known one"# }, | ||
335 | LintCompletion { label: "invalid_value", description: r#"an invalid value is being created (such as a NULL reference)"# }, | ||
336 | LintCompletion { label: "irrefutable_let_patterns", description: r#"detects irrefutable patterns in if-let and while-let statements"# }, | ||
337 | LintCompletion { label: "late_bound_lifetime_arguments", description: r#"detects generic lifetime arguments in path segments with late bound lifetime parameters"# }, | ||
338 | LintCompletion { label: "mixed_script_confusables", description: r#"detects Unicode scripts whose mixed script confusables codepoints are solely used"# }, | ||
339 | LintCompletion { label: "mutable_borrow_reservation_conflict", description: r#"reservation of a two-phased borrow conflicts with other shared borrows"# }, | ||
340 | LintCompletion { label: "non_camel_case_types", description: r#"types, variants, traits and type parameters should have camel case names"# }, | ||
341 | LintCompletion { label: "non_shorthand_field_patterns", description: r#"using `Struct { x: x }` instead of `Struct { x }` in a pattern"# }, | ||
342 | LintCompletion { label: "non_snake_case", description: r#"variables, methods, functions, lifetime parameters and modules should have snake case names"# }, | ||
343 | LintCompletion { label: "non_upper_case_globals", description: r#"static constants should have uppercase identifiers"# }, | ||
344 | LintCompletion { label: "no_mangle_generic_items", description: r#"generic items must be mangled"# }, | ||
345 | LintCompletion { label: "overlapping_patterns", description: r#"detects overlapping patterns"# }, | ||
346 | LintCompletion { label: "path_statements", description: r#"path statements with no effect"# }, | ||
347 | LintCompletion { label: "private_in_public", description: r#"detect private items in public interfaces not caught by the old implementation"# }, | ||
348 | LintCompletion { label: "proc_macro_derive_resolution_fallback", description: r#"detects proc macro derives using inaccessible names from parent modules"# }, | ||
349 | LintCompletion { label: "redundant_semicolons", description: r#"detects unnecessary trailing semicolons"# }, | ||
350 | LintCompletion { label: "renamed_and_removed_lints", description: r#"lints that have been renamed or removed"# }, | ||
351 | LintCompletion { label: "safe_packed_borrows", description: r#"safe borrows of fields of packed structs were erroneously allowed"# }, | ||
352 | LintCompletion { label: "stable_features", description: r#"stable features found in `#[feature]` directive"# }, | ||
353 | LintCompletion { label: "trivial_bounds", description: r#"these bounds don't depend on an type parameters"# }, | ||
354 | LintCompletion { label: "type_alias_bounds", description: r#"bounds in type aliases are not enforced"# }, | ||
355 | LintCompletion { label: "tyvar_behind_raw_pointer", description: r#"raw pointer to an inference variable"# }, | ||
356 | LintCompletion { label: "uncommon_codepoints", description: r#"detects uncommon Unicode codepoints in identifiers"# }, | ||
357 | LintCompletion { label: "unconditional_recursion", description: r#"functions that cannot return without calling themselves"# }, | ||
358 | LintCompletion { label: "unknown_lints", description: r#"unrecognized lint attribute"# }, | ||
359 | LintCompletion { label: "unnameable_test_items", description: r#"detects an item that cannot be named being marked as `#[test_case]`"# }, | ||
360 | LintCompletion { label: "unreachable_code", description: r#"detects unreachable code paths"# }, | ||
361 | LintCompletion { label: "unreachable_patterns", description: r#"detects unreachable patterns"# }, | ||
362 | LintCompletion { label: "unstable_name_collisions", description: r#"detects name collision with an existing but unstable method"# }, | ||
363 | LintCompletion { label: "unused_allocation", description: r#"detects unnecessary allocations that can be eliminated"# }, | ||
364 | LintCompletion { label: "unused_assignments", description: r#"detect assignments that will never be read"# }, | ||
365 | LintCompletion { label: "unused_attributes", description: r#"detects attributes that were not used by the compiler"# }, | ||
366 | LintCompletion { label: "unused_braces", description: r#"unnecessary braces around an expression"# }, | ||
367 | LintCompletion { label: "unused_comparisons", description: r#"comparisons made useless by limits of the types involved"# }, | ||
368 | LintCompletion { label: "unused_doc_comments", description: r#"detects doc comments that aren't used by rustdoc"# }, | ||
369 | LintCompletion { label: "unused_features", description: r#"unused features found in crate-level `#[feature]` directives"# }, | ||
370 | LintCompletion { label: "unused_imports", description: r#"imports that are never used"# }, | ||
371 | LintCompletion { label: "unused_labels", description: r#"detects labels that are never used"# }, | ||
372 | LintCompletion { label: "unused_macros", description: r#"detects macros that were not used"# }, | ||
373 | LintCompletion { label: "unused_must_use", description: r#"unused result of a type flagged as `#[must_use]`"# }, | ||
374 | LintCompletion { label: "unused_mut", description: r#"detect mut variables which don't need to be mutable"# }, | ||
375 | LintCompletion { label: "unused_parens", description: r#"`if`, `match`, `while` and `return` do not need parentheses"# }, | ||
376 | LintCompletion { label: "unused_unsafe", description: r#"unnecessary use of an `unsafe` block"# }, | ||
377 | LintCompletion { label: "unused_variables", description: r#"detect variables which are not used in any way"# }, | ||
378 | LintCompletion { label: "warnings", description: r#"mass-change the level for lints which produce warnings"# }, | ||
379 | LintCompletion { label: "where_clauses_object_safety", description: r#"checks the object safety of where clauses"# }, | ||
380 | LintCompletion { label: "while_true", description: r#"suggest using `loop { }` instead of `while true { }`"# }, | ||
381 | LintCompletion { label: "ambiguous_associated_items", description: r#"ambiguous associated items"# }, | ||
382 | LintCompletion { label: "arithmetic_overflow", description: r#"arithmetic operation overflows"# }, | ||
383 | LintCompletion { label: "conflicting_repr_hints", description: r#"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice"# }, | ||
384 | LintCompletion { label: "const_err", description: r#"constant evaluation detected erroneous expression"# }, | ||
385 | LintCompletion { label: "ill_formed_attribute_input", description: r#"ill-formed attribute inputs that were previously accepted and used in practice"# }, | ||
386 | LintCompletion { label: "incomplete_include", description: r#"trailing content in included file"# }, | ||
387 | LintCompletion { label: "invalid_type_param_default", description: r#"type parameter default erroneously allowed in invalid location"# }, | ||
388 | LintCompletion { label: "macro_expanded_macro_exports_accessed_by_absolute_paths", description: r#"macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths"# }, | ||
389 | LintCompletion { label: "missing_fragment_specifier", description: r#"detects missing fragment specifiers in unused `macro_rules!` patterns"# }, | ||
390 | LintCompletion { label: "mutable_transmutes", description: r#"mutating transmuted &mut T from &T may cause undefined behavior"# }, | ||
391 | LintCompletion { label: "no_mangle_const_items", description: r#"const items will not have their symbols exported"# }, | ||
392 | LintCompletion { label: "order_dependent_trait_objects", description: r#"trait-object types were treated as different depending on marker-trait order"# }, | ||
393 | LintCompletion { label: "overflowing_literals", description: r#"literal out of range for its type"# }, | ||
394 | LintCompletion { label: "patterns_in_fns_without_body", description: r#"patterns in functions without body were erroneously allowed"# }, | ||
395 | LintCompletion { label: "pub_use_of_private_extern_crate", description: r#"detect public re-exports of private extern crates"# }, | ||
396 | LintCompletion { label: "soft_unstable", description: r#"a feature gate that doesn't break dependent crates"# }, | ||
397 | LintCompletion { label: "unconditional_panic", description: r#"operation will cause a panic at runtime"# }, | ||
398 | LintCompletion { label: "unknown_crate_types", description: r#"unknown crate type found in `#[crate_type]` directive"# }, | ||
399 | ]; | ||
400 | |||
401 | #[cfg(test)] | 296 | #[cfg(test)] |
402 | mod tests { | 297 | mod tests { |
298 | use super::*; | ||
299 | |||
403 | use expect_test::{expect, Expect}; | 300 | use expect_test::{expect, Expect}; |
404 | 301 | ||
405 | use crate::{test_utils::completion_list, CompletionKind}; | 302 | use crate::{test_utils::completion_list, CompletionKind}; |
406 | 303 | ||
304 | #[test] | ||
305 | fn attributes_are_sorted() { | ||
306 | let mut attrs = ATTRIBUTES.iter().map(|attr| attr.key()); | ||
307 | let mut prev = attrs.next().unwrap(); | ||
308 | |||
309 | attrs.for_each(|next| { | ||
310 | assert!( | ||
311 | prev < next, | ||
312 | r#"ATTRIBUTES array is not sorted, "{}" should come after "{}""#, | ||
313 | prev, | ||
314 | next | ||
315 | ); | ||
316 | prev = next; | ||
317 | }); | ||
318 | } | ||
319 | |||
407 | fn check(ra_fixture: &str, expect: Expect) { | 320 | fn check(ra_fixture: &str, expect: Expect) { |
408 | let actual = completion_list(ra_fixture, CompletionKind::Attribute); | 321 | let actual = completion_list(ra_fixture, CompletionKind::Attribute); |
409 | expect.assert_eq(&actual); | 322 | expect.assert_eq(&actual); |
410 | } | 323 | } |
411 | 324 | ||
412 | #[test] | 325 | #[test] |
413 | fn empty_derive_completion() { | 326 | fn test_attribute_completion_inside_nested_attr() { |
327 | check(r#"#[cfg($0)]"#, expect![[]]) | ||
328 | } | ||
329 | |||
330 | #[test] | ||
331 | fn test_attribute_completion_with_existing_attr() { | ||
414 | check( | 332 | check( |
415 | r#" | 333 | r#"#[no_mangle] #[$0] mcall!();"#, |
416 | #[derive($0)] | ||
417 | struct Test {} | ||
418 | "#, | ||
419 | expect![[r#" | 334 | expect![[r#" |
420 | at Clone | 335 | at allow(…) |
421 | at Clone, Copy | 336 | at cfg(…) |
422 | at Debug | 337 | at cfg_attr(…) |
423 | at Default | 338 | at deny(…) |
424 | at Hash | 339 | at forbid(…) |
425 | at PartialEq | 340 | at warn(…) |
426 | at PartialEq, Eq | 341 | "#]], |
427 | at PartialEq, PartialOrd | 342 | ) |
428 | at PartialEq, Eq, PartialOrd, Ord | 343 | } |
344 | |||
345 | #[test] | ||
346 | fn complete_attribute_on_source_file() { | ||
347 | check( | ||
348 | r#"#![$0]"#, | ||
349 | expect![[r#" | ||
350 | at allow(…) | ||
351 | at cfg(…) | ||
352 | at cfg_attr(…) | ||
353 | at deny(…) | ||
354 | at forbid(…) | ||
355 | at warn(…) | ||
356 | at deprecated | ||
357 | at doc = "…" | ||
358 | at doc(hidden) | ||
359 | at doc(alias = "…") | ||
360 | at must_use | ||
361 | at no_mangle | ||
362 | at crate_name = "" | ||
363 | at feature(…) | ||
364 | at no_implicit_prelude | ||
365 | at no_main | ||
366 | at no_std | ||
367 | at recursion_limit = … | ||
368 | at type_length_limit = … | ||
369 | at windows_subsystem = "…" | ||
429 | "#]], | 370 | "#]], |
430 | ); | 371 | ); |
431 | } | 372 | } |
432 | 373 | ||
433 | #[test] | 374 | #[test] |
434 | fn no_completion_for_incorrect_derive() { | 375 | fn complete_attribute_on_module() { |
435 | check( | 376 | check( |
436 | r#" | 377 | r#"#[$0] mod foo;"#, |
437 | #[derive{$0)] | 378 | expect![[r#" |
438 | struct Test {} | 379 | at allow(…) |
439 | "#, | 380 | at cfg(…) |
440 | expect![[r#""#]], | 381 | at cfg_attr(…) |
441 | ) | 382 | at deny(…) |
383 | at forbid(…) | ||
384 | at warn(…) | ||
385 | at deprecated | ||
386 | at doc = "…" | ||
387 | at doc(hidden) | ||
388 | at doc(alias = "…") | ||
389 | at must_use | ||
390 | at no_mangle | ||
391 | at path = "…" | ||
392 | "#]], | ||
393 | ); | ||
394 | check( | ||
395 | r#"mod foo {#![$0]}"#, | ||
396 | expect![[r#" | ||
397 | at allow(…) | ||
398 | at cfg(…) | ||
399 | at cfg_attr(…) | ||
400 | at deny(…) | ||
401 | at forbid(…) | ||
402 | at warn(…) | ||
403 | at deprecated | ||
404 | at doc = "…" | ||
405 | at doc(hidden) | ||
406 | at doc(alias = "…") | ||
407 | at must_use | ||
408 | at no_mangle | ||
409 | at no_implicit_prelude | ||
410 | "#]], | ||
411 | ); | ||
442 | } | 412 | } |
443 | 413 | ||
444 | #[test] | 414 | #[test] |
445 | fn derive_with_input_completion() { | 415 | fn complete_attribute_on_macro_rules() { |
446 | check( | 416 | check( |
447 | r#" | 417 | r#"#[$0] macro_rules! foo {}"#, |
448 | #[derive(serde::Serialize, PartialEq, $0)] | ||
449 | struct Test {} | ||
450 | "#, | ||
451 | expect![[r#" | 418 | expect![[r#" |
452 | at Clone | 419 | at allow(…) |
453 | at Clone, Copy | 420 | at cfg(…) |
454 | at Debug | 421 | at cfg_attr(…) |
455 | at Default | 422 | at deny(…) |
456 | at Hash | 423 | at forbid(…) |
457 | at Eq | 424 | at warn(…) |
458 | at PartialOrd | 425 | at deprecated |
459 | at Eq, PartialOrd, Ord | 426 | at doc = "…" |
427 | at doc(hidden) | ||
428 | at doc(alias = "…") | ||
429 | at must_use | ||
430 | at no_mangle | ||
431 | at macro_export | ||
432 | at macro_use | ||
460 | "#]], | 433 | "#]], |
461 | ) | 434 | ); |
462 | } | 435 | } |
463 | 436 | ||
464 | #[test] | 437 | #[test] |
465 | fn test_attribute_completion() { | 438 | fn complete_attribute_on_macro_def() { |
466 | check( | 439 | check( |
467 | r#"#[$0]"#, | 440 | r#"#[$0] macro foo {}"#, |
468 | expect![[r#" | 441 | expect![[r#" |
469 | at allow(…) | 442 | at allow(…) |
470 | at automatically_derived | 443 | at cfg(…) |
471 | at cfg_attr(…) | 444 | at cfg_attr(…) |
445 | at deny(…) | ||
446 | at forbid(…) | ||
447 | at warn(…) | ||
448 | at deprecated | ||
449 | at doc = "…" | ||
450 | at doc(hidden) | ||
451 | at doc(alias = "…") | ||
452 | at must_use | ||
453 | at no_mangle | ||
454 | "#]], | ||
455 | ); | ||
456 | } | ||
457 | |||
458 | #[test] | ||
459 | fn complete_attribute_on_extern_crate() { | ||
460 | check( | ||
461 | r#"#[$0] extern crate foo;"#, | ||
462 | expect![[r#" | ||
463 | at allow(…) | ||
472 | at cfg(…) | 464 | at cfg(…) |
473 | at cold | 465 | at cfg_attr(…) |
474 | at deny(…) | 466 | at deny(…) |
467 | at forbid(…) | ||
468 | at warn(…) | ||
475 | at deprecated | 469 | at deprecated |
476 | at derive(…) | 470 | at doc = "…" |
477 | at export_name = "…" | 471 | at doc(hidden) |
478 | at doc(alias = "…") | 472 | at doc(alias = "…") |
473 | at must_use | ||
474 | at no_mangle | ||
475 | at macro_use | ||
476 | "#]], | ||
477 | ); | ||
478 | } | ||
479 | |||
480 | #[test] | ||
481 | fn complete_attribute_on_use() { | ||
482 | check( | ||
483 | r#"#[$0] use foo;"#, | ||
484 | expect![[r#" | ||
485 | at allow(…) | ||
486 | at cfg(…) | ||
487 | at cfg_attr(…) | ||
488 | at deny(…) | ||
489 | at forbid(…) | ||
490 | at warn(…) | ||
491 | at deprecated | ||
479 | at doc = "…" | 492 | at doc = "…" |
480 | at doc(hidden) | 493 | at doc(hidden) |
494 | at doc(alias = "…") | ||
495 | at must_use | ||
496 | at no_mangle | ||
497 | "#]], | ||
498 | ); | ||
499 | } | ||
500 | |||
501 | #[test] | ||
502 | fn complete_attribute_on_type_alias() { | ||
503 | check( | ||
504 | r#"#[$0] type foo = ();"#, | ||
505 | expect![[r#" | ||
506 | at allow(…) | ||
507 | at cfg(…) | ||
508 | at cfg_attr(…) | ||
509 | at deny(…) | ||
481 | at forbid(…) | 510 | at forbid(…) |
482 | at ignore = "…" | 511 | at warn(…) |
483 | at inline | 512 | at deprecated |
484 | at link | 513 | at doc = "…" |
485 | at link_name = "…" | 514 | at doc(hidden) |
486 | at link_section = "…" | 515 | at doc(alias = "…") |
487 | at macro_export | 516 | at must_use |
488 | at macro_use | 517 | at no_mangle |
518 | "#]], | ||
519 | ); | ||
520 | } | ||
521 | |||
522 | #[test] | ||
523 | fn complete_attribute_on_struct() { | ||
524 | check( | ||
525 | r#"#[$0] struct Foo;"#, | ||
526 | expect![[r#" | ||
527 | at allow(…) | ||
528 | at cfg(…) | ||
529 | at cfg_attr(…) | ||
530 | at deny(…) | ||
531 | at forbid(…) | ||
532 | at warn(…) | ||
533 | at deprecated | ||
534 | at doc = "…" | ||
535 | at doc(hidden) | ||
536 | at doc(alias = "…") | ||
489 | at must_use | 537 | at must_use |
490 | at no_mangle | 538 | at no_mangle |
539 | at derive(…) | ||
540 | at repr(…) | ||
491 | at non_exhaustive | 541 | at non_exhaustive |
492 | at path = "…" | 542 | "#]], |
493 | at proc_macro | 543 | ); |
494 | at proc_macro_attribute | 544 | } |
495 | at proc_macro_derive(…) | 545 | |
546 | #[test] | ||
547 | fn complete_attribute_on_enum() { | ||
548 | check( | ||
549 | r#"#[$0] enum Foo {}"#, | ||
550 | expect![[r#" | ||
551 | at allow(…) | ||
552 | at cfg(…) | ||
553 | at cfg_attr(…) | ||
554 | at deny(…) | ||
555 | at forbid(…) | ||
556 | at warn(…) | ||
557 | at deprecated | ||
558 | at doc = "…" | ||
559 | at doc(hidden) | ||
560 | at doc(alias = "…") | ||
561 | at must_use | ||
562 | at no_mangle | ||
563 | at derive(…) | ||
496 | at repr(…) | 564 | at repr(…) |
497 | at should_panic | 565 | at non_exhaustive |
498 | at target_feature = "…" | 566 | "#]], |
499 | at test | 567 | ); |
500 | at track_caller | 568 | } |
501 | at used | 569 | |
570 | #[test] | ||
571 | fn complete_attribute_on_const() { | ||
572 | check( | ||
573 | r#"#[$0] const FOO: () = ();"#, | ||
574 | expect![[r#" | ||
575 | at allow(…) | ||
576 | at cfg(…) | ||
577 | at cfg_attr(…) | ||
578 | at deny(…) | ||
579 | at forbid(…) | ||
502 | at warn(…) | 580 | at warn(…) |
581 | at deprecated | ||
582 | at doc = "…" | ||
583 | at doc(hidden) | ||
584 | at doc(alias = "…") | ||
585 | at must_use | ||
586 | at no_mangle | ||
503 | "#]], | 587 | "#]], |
504 | ) | 588 | ); |
505 | } | 589 | } |
506 | 590 | ||
507 | #[test] | 591 | #[test] |
508 | fn test_attribute_completion_inside_nested_attr() { | 592 | fn complete_attribute_on_static() { |
509 | check(r#"#[cfg($0)]"#, expect![[]]) | 593 | check( |
594 | r#"#[$0] static FOO: () = ()"#, | ||
595 | expect![[r#" | ||
596 | at allow(…) | ||
597 | at cfg(…) | ||
598 | at cfg_attr(…) | ||
599 | at deny(…) | ||
600 | at forbid(…) | ||
601 | at warn(…) | ||
602 | at deprecated | ||
603 | at doc = "…" | ||
604 | at doc(hidden) | ||
605 | at doc(alias = "…") | ||
606 | at must_use | ||
607 | at no_mangle | ||
608 | at export_name = "…" | ||
609 | at link_name = "…" | ||
610 | at link_section = "…" | ||
611 | at global_allocator | ||
612 | at used | ||
613 | "#]], | ||
614 | ); | ||
510 | } | 615 | } |
511 | 616 | ||
512 | #[test] | 617 | #[test] |
513 | fn test_inner_attribute_completion() { | 618 | fn complete_attribute_on_trait() { |
514 | check( | 619 | check( |
515 | r"#![$0]", | 620 | r#"#[$0] trait Foo {}"#, |
516 | expect![[r#" | 621 | expect![[r#" |
517 | at allow(…) | 622 | at allow(…) |
518 | at automatically_derived | 623 | at cfg(…) |
519 | at cfg_attr(…) | 624 | at cfg_attr(…) |
625 | at deny(…) | ||
626 | at forbid(…) | ||
627 | at warn(…) | ||
628 | at deprecated | ||
629 | at doc = "…" | ||
630 | at doc(hidden) | ||
631 | at doc(alias = "…") | ||
632 | at must_use | ||
633 | at no_mangle | ||
634 | at must_use | ||
635 | "#]], | ||
636 | ); | ||
637 | } | ||
638 | |||
639 | #[test] | ||
640 | fn complete_attribute_on_impl() { | ||
641 | check( | ||
642 | r#"#[$0] impl () {}"#, | ||
643 | expect![[r#" | ||
644 | at allow(…) | ||
520 | at cfg(…) | 645 | at cfg(…) |
521 | at cold | 646 | at cfg_attr(…) |
522 | at crate_name = "" | ||
523 | at deny(…) | 647 | at deny(…) |
648 | at forbid(…) | ||
649 | at warn(…) | ||
524 | at deprecated | 650 | at deprecated |
525 | at derive(…) | 651 | at doc = "…" |
526 | at export_name = "…" | 652 | at doc(hidden) |
653 | at doc(alias = "…") | ||
654 | at must_use | ||
655 | at no_mangle | ||
656 | at automatically_derived | ||
657 | "#]], | ||
658 | ); | ||
659 | check( | ||
660 | r#"impl () {#![$0]}"#, | ||
661 | expect![[r#" | ||
662 | at allow(…) | ||
663 | at cfg(…) | ||
664 | at cfg_attr(…) | ||
665 | at deny(…) | ||
666 | at forbid(…) | ||
667 | at warn(…) | ||
668 | at deprecated | ||
669 | at doc = "…" | ||
670 | at doc(hidden) | ||
527 | at doc(alias = "…") | 671 | at doc(alias = "…") |
672 | at must_use | ||
673 | at no_mangle | ||
674 | "#]], | ||
675 | ); | ||
676 | } | ||
677 | |||
678 | #[test] | ||
679 | fn complete_attribute_on_extern_block() { | ||
680 | check( | ||
681 | r#"#[$0] extern {}"#, | ||
682 | expect![[r#" | ||
683 | at allow(…) | ||
684 | at cfg(…) | ||
685 | at cfg_attr(…) | ||
686 | at deny(…) | ||
687 | at forbid(…) | ||
688 | at warn(…) | ||
689 | at deprecated | ||
528 | at doc = "…" | 690 | at doc = "…" |
529 | at doc(hidden) | 691 | at doc(hidden) |
530 | at feature(…) | 692 | at doc(alias = "…") |
693 | at must_use | ||
694 | at no_mangle | ||
695 | at link | ||
696 | "#]], | ||
697 | ); | ||
698 | check( | ||
699 | r#"extern {#![$0]}"#, | ||
700 | expect![[r#" | ||
701 | at allow(…) | ||
702 | at cfg(…) | ||
703 | at cfg_attr(…) | ||
704 | at deny(…) | ||
531 | at forbid(…) | 705 | at forbid(…) |
532 | at global_allocator | 706 | at warn(…) |
533 | at ignore = "…" | 707 | at deprecated |
534 | at inline | 708 | at doc = "…" |
709 | at doc(hidden) | ||
710 | at doc(alias = "…") | ||
711 | at must_use | ||
712 | at no_mangle | ||
535 | at link | 713 | at link |
714 | "#]], | ||
715 | ); | ||
716 | } | ||
717 | |||
718 | #[test] | ||
719 | fn complete_attribute_on_variant() { | ||
720 | check( | ||
721 | r#"enum Foo { #[$0] Bar }"#, | ||
722 | expect![[r#" | ||
723 | at allow(…) | ||
724 | at cfg(…) | ||
725 | at cfg_attr(…) | ||
726 | at deny(…) | ||
727 | at forbid(…) | ||
728 | at warn(…) | ||
729 | at non_exhaustive | ||
730 | "#]], | ||
731 | ); | ||
732 | } | ||
733 | |||
734 | #[test] | ||
735 | fn complete_attribute_on_fn() { | ||
736 | check( | ||
737 | r#"#[$0] fn main() {}"#, | ||
738 | expect![[r#" | ||
739 | at allow(…) | ||
740 | at cfg(…) | ||
741 | at cfg_attr(…) | ||
742 | at deny(…) | ||
743 | at forbid(…) | ||
744 | at warn(…) | ||
745 | at deprecated | ||
746 | at doc = "…" | ||
747 | at doc(hidden) | ||
748 | at doc(alias = "…") | ||
749 | at must_use | ||
750 | at no_mangle | ||
751 | at export_name = "…" | ||
536 | at link_name = "…" | 752 | at link_name = "…" |
537 | at link_section = "…" | 753 | at link_section = "…" |
538 | at macro_export | 754 | at cold |
539 | at macro_use | 755 | at ignore = "…" |
756 | at inline | ||
540 | at must_use | 757 | at must_use |
541 | at no_link | ||
542 | at no_implicit_prelude | ||
543 | at no_main | ||
544 | at no_mangle | ||
545 | at no_std | ||
546 | at non_exhaustive | ||
547 | at panic_handler | 758 | at panic_handler |
548 | at path = "…" | ||
549 | at proc_macro | 759 | at proc_macro |
550 | at proc_macro_attribute | ||
551 | at proc_macro_derive(…) | 760 | at proc_macro_derive(…) |
552 | at recursion_limit = … | 761 | at proc_macro_attribute |
553 | at repr(…) | ||
554 | at should_panic | 762 | at should_panic |
555 | at target_feature = "…" | 763 | at target_feature = "…" |
556 | at test | 764 | at test |
557 | at track_caller | 765 | at track_caller |
558 | at type_length_limit = … | 766 | "#]], |
559 | at used | 767 | ); |
768 | } | ||
769 | |||
770 | #[test] | ||
771 | fn complete_attribute_on_expr() { | ||
772 | check( | ||
773 | r#"fn main() { #[$0] foo() }"#, | ||
774 | expect![[r#" | ||
775 | at allow(…) | ||
776 | at cfg(…) | ||
777 | at cfg_attr(…) | ||
778 | at deny(…) | ||
779 | at forbid(…) | ||
560 | at warn(…) | 780 | at warn(…) |
561 | at windows_subsystem = "…" | ||
562 | "#]], | 781 | "#]], |
563 | ); | 782 | ); |
564 | } | 783 | } |
diff --git a/crates/ide_completion/src/completions/attribute/derive.rs b/crates/ide_completion/src/completions/attribute/derive.rs new file mode 100644 index 000000000..0bc3eab98 --- /dev/null +++ b/crates/ide_completion/src/completions/attribute/derive.rs | |||
@@ -0,0 +1,147 @@ | |||
1 | //! Completion for derives | ||
2 | use itertools::Itertools; | ||
3 | use rustc_hash::FxHashSet; | ||
4 | use syntax::ast; | ||
5 | |||
6 | use crate::{ | ||
7 | context::CompletionContext, | ||
8 | item::{CompletionItem, CompletionItemKind, CompletionKind}, | ||
9 | Completions, | ||
10 | }; | ||
11 | |||
12 | pub(super) fn complete_derive( | ||
13 | acc: &mut Completions, | ||
14 | ctx: &CompletionContext, | ||
15 | derive_input: ast::TokenTree, | ||
16 | ) { | ||
17 | if let Some(existing_derives) = super::parse_comma_sep_input(derive_input) { | ||
18 | for derive_completion in DEFAULT_DERIVE_COMPLETIONS | ||
19 | .iter() | ||
20 | .filter(|completion| !existing_derives.contains(completion.label)) | ||
21 | { | ||
22 | let mut components = vec![derive_completion.label]; | ||
23 | components.extend( | ||
24 | derive_completion | ||
25 | .dependencies | ||
26 | .iter() | ||
27 | .filter(|&&dependency| !existing_derives.contains(dependency)), | ||
28 | ); | ||
29 | let lookup = components.join(", "); | ||
30 | let label = components.iter().rev().join(", "); | ||
31 | let mut item = | ||
32 | CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label); | ||
33 | item.lookup_by(lookup).kind(CompletionItemKind::Attribute); | ||
34 | item.add_to(acc); | ||
35 | } | ||
36 | |||
37 | for custom_derive_name in get_derive_names_in_scope(ctx).difference(&existing_derives) { | ||
38 | let mut item = CompletionItem::new( | ||
39 | CompletionKind::Attribute, | ||
40 | ctx.source_range(), | ||
41 | custom_derive_name, | ||
42 | ); | ||
43 | item.kind(CompletionItemKind::Attribute); | ||
44 | item.add_to(acc); | ||
45 | } | ||
46 | } | ||
47 | } | ||
48 | |||
49 | fn get_derive_names_in_scope(ctx: &CompletionContext) -> FxHashSet<String> { | ||
50 | let mut result = FxHashSet::default(); | ||
51 | ctx.scope.process_all_names(&mut |name, scope_def| { | ||
52 | if let hir::ScopeDef::MacroDef(mac) = scope_def { | ||
53 | if mac.kind() == hir::MacroKind::Derive { | ||
54 | result.insert(name.to_string()); | ||
55 | } | ||
56 | } | ||
57 | }); | ||
58 | result | ||
59 | } | ||
60 | |||
61 | struct DeriveCompletion { | ||
62 | label: &'static str, | ||
63 | dependencies: &'static [&'static str], | ||
64 | } | ||
65 | |||
66 | /// Standard Rust derives and the information about their dependencies | ||
67 | /// (the dependencies are needed so that the main derive don't break the compilation when added) | ||
68 | const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[ | ||
69 | DeriveCompletion { label: "Clone", dependencies: &[] }, | ||
70 | DeriveCompletion { label: "Copy", dependencies: &["Clone"] }, | ||
71 | DeriveCompletion { label: "Debug", dependencies: &[] }, | ||
72 | DeriveCompletion { label: "Default", dependencies: &[] }, | ||
73 | DeriveCompletion { label: "Hash", dependencies: &[] }, | ||
74 | DeriveCompletion { label: "PartialEq", dependencies: &[] }, | ||
75 | DeriveCompletion { label: "Eq", dependencies: &["PartialEq"] }, | ||
76 | DeriveCompletion { label: "PartialOrd", dependencies: &["PartialEq"] }, | ||
77 | DeriveCompletion { label: "Ord", dependencies: &["PartialOrd", "Eq", "PartialEq"] }, | ||
78 | ]; | ||
79 | |||
80 | #[cfg(test)] | ||
81 | mod tests { | ||
82 | use expect_test::{expect, Expect}; | ||
83 | |||
84 | use crate::{test_utils::completion_list, CompletionKind}; | ||
85 | |||
86 | fn check(ra_fixture: &str, expect: Expect) { | ||
87 | let actual = completion_list(ra_fixture, CompletionKind::Attribute); | ||
88 | expect.assert_eq(&actual); | ||
89 | } | ||
90 | |||
91 | #[test] | ||
92 | fn no_completion_for_incorrect_derive() { | ||
93 | check(r#"#[derive{$0)] struct Test;"#, expect![[]]) | ||
94 | } | ||
95 | |||
96 | #[test] | ||
97 | fn empty_derive() { | ||
98 | check( | ||
99 | r#"#[derive($0)] struct Test;"#, | ||
100 | expect![[r#" | ||
101 | at Clone | ||
102 | at Clone, Copy | ||
103 | at Debug | ||
104 | at Default | ||
105 | at Hash | ||
106 | at PartialEq | ||
107 | at PartialEq, Eq | ||
108 | at PartialEq, PartialOrd | ||
109 | at PartialEq, Eq, PartialOrd, Ord | ||
110 | "#]], | ||
111 | ); | ||
112 | } | ||
113 | |||
114 | #[test] | ||
115 | fn derive_with_input() { | ||
116 | check( | ||
117 | r#"#[derive(serde::Serialize, PartialEq, $0)] struct Test;"#, | ||
118 | expect![[r#" | ||
119 | at Clone | ||
120 | at Clone, Copy | ||
121 | at Debug | ||
122 | at Default | ||
123 | at Hash | ||
124 | at Eq | ||
125 | at PartialOrd | ||
126 | at Eq, PartialOrd, Ord | ||
127 | "#]], | ||
128 | ) | ||
129 | } | ||
130 | |||
131 | #[test] | ||
132 | fn derive_with_input2() { | ||
133 | check( | ||
134 | r#"#[derive($0 serde::Serialize, PartialEq)] struct Test;"#, | ||
135 | expect![[r#" | ||
136 | at Clone | ||
137 | at Clone, Copy | ||
138 | at Debug | ||
139 | at Default | ||
140 | at Hash | ||
141 | at Eq | ||
142 | at PartialOrd | ||
143 | at Eq, PartialOrd, Ord | ||
144 | "#]], | ||
145 | ) | ||
146 | } | ||
147 | } | ||
diff --git a/crates/ide_completion/src/completions/attribute/lint.rs b/crates/ide_completion/src/completions/attribute/lint.rs new file mode 100644 index 000000000..403630dce --- /dev/null +++ b/crates/ide_completion/src/completions/attribute/lint.rs | |||
@@ -0,0 +1,187 @@ | |||
1 | //! Completion for lints | ||
2 | use syntax::ast; | ||
3 | |||
4 | use crate::{ | ||
5 | context::CompletionContext, | ||
6 | item::{CompletionItem, CompletionItemKind, CompletionKind}, | ||
7 | Completions, | ||
8 | }; | ||
9 | |||
10 | pub(super) fn complete_lint( | ||
11 | acc: &mut Completions, | ||
12 | ctx: &CompletionContext, | ||
13 | derive_input: ast::TokenTree, | ||
14 | lints_completions: &[LintCompletion], | ||
15 | ) { | ||
16 | if let Some(existing_lints) = super::parse_comma_sep_input(derive_input) { | ||
17 | for lint_completion in lints_completions | ||
18 | .into_iter() | ||
19 | .filter(|completion| !existing_lints.contains(completion.label)) | ||
20 | { | ||
21 | let mut item = CompletionItem::new( | ||
22 | CompletionKind::Attribute, | ||
23 | ctx.source_range(), | ||
24 | lint_completion.label, | ||
25 | ); | ||
26 | item.kind(CompletionItemKind::Attribute).detail(lint_completion.description); | ||
27 | item.add_to(acc) | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | |||
32 | pub(crate) struct LintCompletion { | ||
33 | pub(crate) label: &'static str, | ||
34 | pub(crate) description: &'static str, | ||
35 | } | ||
36 | |||
37 | #[rustfmt::skip] | ||
38 | pub(super) const DEFAULT_LINT_COMPLETIONS: &[LintCompletion] = &[ | ||
39 | LintCompletion { label: "absolute_paths_not_starting_with_crate", description: r#"fully qualified paths that start with a module name instead of `crate`, `self`, or an extern crate name"# }, | ||
40 | LintCompletion { label: "anonymous_parameters", description: r#"detects anonymous parameters"# }, | ||
41 | LintCompletion { label: "box_pointers", description: r#"use of owned (Box type) heap memory"# }, | ||
42 | LintCompletion { label: "deprecated_in_future", description: r#"detects use of items that will be deprecated in a future version"# }, | ||
43 | LintCompletion { label: "elided_lifetimes_in_paths", description: r#"hidden lifetime parameters in types are deprecated"# }, | ||
44 | LintCompletion { label: "explicit_outlives_requirements", description: r#"outlives requirements can be inferred"# }, | ||
45 | LintCompletion { label: "indirect_structural_match", description: r#"pattern with const indirectly referencing non-structural-match type"# }, | ||
46 | LintCompletion { label: "keyword_idents", description: r#"detects edition keywords being used as an identifier"# }, | ||
47 | LintCompletion { label: "macro_use_extern_crate", description: r#"the `#[macro_use]` attribute is now deprecated in favor of using macros via the module system"# }, | ||
48 | LintCompletion { label: "meta_variable_misuse", description: r#"possible meta-variable misuse at macro definition"# }, | ||
49 | LintCompletion { label: "missing_copy_implementations", description: r#"detects potentially-forgotten implementations of `Copy`"# }, | ||
50 | LintCompletion { label: "missing_crate_level_docs", description: r#"detects crates with no crate-level documentation"# }, | ||
51 | LintCompletion { label: "missing_debug_implementations", description: r#"detects missing implementations of Debug"# }, | ||
52 | LintCompletion { label: "missing_docs", description: r#"detects missing documentation for public members"# }, | ||
53 | LintCompletion { label: "missing_doc_code_examples", description: r#"detects publicly-exported items without code samples in their documentation"# }, | ||
54 | LintCompletion { label: "non_ascii_idents", description: r#"detects non-ASCII identifiers"# }, | ||
55 | LintCompletion { label: "private_doc_tests", description: r#"detects code samples in docs of private items not documented by rustdoc"# }, | ||
56 | LintCompletion { label: "single_use_lifetimes", description: r#"detects lifetime parameters that are only used once"# }, | ||
57 | LintCompletion { label: "trivial_casts", description: r#"detects trivial casts which could be removed"# }, | ||
58 | LintCompletion { label: "trivial_numeric_casts", description: r#"detects trivial casts of numeric types which could be removed"# }, | ||
59 | LintCompletion { label: "unaligned_references", description: r#"detects unaligned references to fields of packed structs"# }, | ||
60 | LintCompletion { label: "unreachable_pub", description: r#"`pub` items not reachable from crate root"# }, | ||
61 | LintCompletion { label: "unsafe_code", description: r#"usage of `unsafe` code"# }, | ||
62 | LintCompletion { label: "unsafe_op_in_unsafe_fn", description: r#"unsafe operations in unsafe functions without an explicit unsafe block are deprecated"# }, | ||
63 | LintCompletion { label: "unstable_features", description: r#"enabling unstable features (deprecated. do not use)"# }, | ||
64 | LintCompletion { label: "unused_crate_dependencies", description: r#"crate dependencies that are never used"# }, | ||
65 | LintCompletion { label: "unused_extern_crates", description: r#"extern crates that are never used"# }, | ||
66 | LintCompletion { label: "unused_import_braces", description: r#"unnecessary braces around an imported item"# }, | ||
67 | LintCompletion { label: "unused_lifetimes", description: r#"detects lifetime parameters that are never used"# }, | ||
68 | LintCompletion { label: "unused_qualifications", description: r#"detects unnecessarily qualified names"# }, | ||
69 | LintCompletion { label: "unused_results", description: r#"unused result of an expression in a statement"# }, | ||
70 | LintCompletion { label: "variant_size_differences", description: r#"detects enums with widely varying variant sizes"# }, | ||
71 | LintCompletion { label: "array_into_iter", description: r#"detects calling `into_iter` on arrays"# }, | ||
72 | LintCompletion { label: "asm_sub_register", description: r#"using only a subset of a register for inline asm inputs"# }, | ||
73 | LintCompletion { label: "bare_trait_objects", description: r#"suggest using `dyn Trait` for trait objects"# }, | ||
74 | LintCompletion { label: "bindings_with_variant_name", description: r#"detects pattern bindings with the same name as one of the matched variants"# }, | ||
75 | LintCompletion { label: "cenum_impl_drop_cast", description: r#"a C-like enum implementing Drop is cast"# }, | ||
76 | LintCompletion { label: "clashing_extern_declarations", description: r#"detects when an extern fn has been declared with the same name but different types"# }, | ||
77 | LintCompletion { label: "coherence_leak_check", description: r#"distinct impls distinguished only by the leak-check code"# }, | ||
78 | LintCompletion { label: "confusable_idents", description: r#"detects visually confusable pairs between identifiers"# }, | ||
79 | LintCompletion { label: "dead_code", description: r#"detect unused, unexported items"# }, | ||
80 | LintCompletion { label: "deprecated", description: r#"detects use of deprecated items"# }, | ||
81 | LintCompletion { label: "ellipsis_inclusive_range_patterns", description: r#"`...` range patterns are deprecated"# }, | ||
82 | LintCompletion { label: "exported_private_dependencies", description: r#"public interface leaks type from a private dependency"# }, | ||
83 | LintCompletion { label: "illegal_floating_point_literal_pattern", description: r#"floating-point literals cannot be used in patterns"# }, | ||
84 | LintCompletion { label: "improper_ctypes", description: r#"proper use of libc types in foreign modules"# }, | ||
85 | LintCompletion { label: "improper_ctypes_definitions", description: r#"proper use of libc types in foreign item definitions"# }, | ||
86 | LintCompletion { label: "incomplete_features", description: r#"incomplete features that may function improperly in some or all cases"# }, | ||
87 | LintCompletion { label: "inline_no_sanitize", description: r#"detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`"# }, | ||
88 | LintCompletion { label: "intra_doc_link_resolution_failure", description: r#"failures in resolving intra-doc link targets"# }, | ||
89 | LintCompletion { label: "invalid_codeblock_attributes", description: r#"codeblock attribute looks a lot like a known one"# }, | ||
90 | LintCompletion { label: "invalid_value", description: r#"an invalid value is being created (such as a NULL reference)"# }, | ||
91 | LintCompletion { label: "irrefutable_let_patterns", description: r#"detects irrefutable patterns in if-let and while-let statements"# }, | ||
92 | LintCompletion { label: "late_bound_lifetime_arguments", description: r#"detects generic lifetime arguments in path segments with late bound lifetime parameters"# }, | ||
93 | LintCompletion { label: "mixed_script_confusables", description: r#"detects Unicode scripts whose mixed script confusables codepoints are solely used"# }, | ||
94 | LintCompletion { label: "mutable_borrow_reservation_conflict", description: r#"reservation of a two-phased borrow conflicts with other shared borrows"# }, | ||
95 | LintCompletion { label: "non_camel_case_types", description: r#"types, variants, traits and type parameters should have camel case names"# }, | ||
96 | LintCompletion { label: "non_shorthand_field_patterns", description: r#"using `Struct { x: x }` instead of `Struct { x }` in a pattern"# }, | ||
97 | LintCompletion { label: "non_snake_case", description: r#"variables, methods, functions, lifetime parameters and modules should have snake case names"# }, | ||
98 | LintCompletion { label: "non_upper_case_globals", description: r#"static constants should have uppercase identifiers"# }, | ||
99 | LintCompletion { label: "no_mangle_generic_items", description: r#"generic items must be mangled"# }, | ||
100 | LintCompletion { label: "overlapping_patterns", description: r#"detects overlapping patterns"# }, | ||
101 | LintCompletion { label: "path_statements", description: r#"path statements with no effect"# }, | ||
102 | LintCompletion { label: "private_in_public", description: r#"detect private items in public interfaces not caught by the old implementation"# }, | ||
103 | LintCompletion { label: "proc_macro_derive_resolution_fallback", description: r#"detects proc macro derives using inaccessible names from parent modules"# }, | ||
104 | LintCompletion { label: "redundant_semicolons", description: r#"detects unnecessary trailing semicolons"# }, | ||
105 | LintCompletion { label: "renamed_and_removed_lints", description: r#"lints that have been renamed or removed"# }, | ||
106 | LintCompletion { label: "safe_packed_borrows", description: r#"safe borrows of fields of packed structs were erroneously allowed"# }, | ||
107 | LintCompletion { label: "stable_features", description: r#"stable features found in `#[feature]` directive"# }, | ||
108 | LintCompletion { label: "trivial_bounds", description: r#"these bounds don't depend on an type parameters"# }, | ||
109 | LintCompletion { label: "type_alias_bounds", description: r#"bounds in type aliases are not enforced"# }, | ||
110 | LintCompletion { label: "tyvar_behind_raw_pointer", description: r#"raw pointer to an inference variable"# }, | ||
111 | LintCompletion { label: "uncommon_codepoints", description: r#"detects uncommon Unicode codepoints in identifiers"# }, | ||
112 | LintCompletion { label: "unconditional_recursion", description: r#"functions that cannot return without calling themselves"# }, | ||
113 | LintCompletion { label: "unknown_lints", description: r#"unrecognized lint attribute"# }, | ||
114 | LintCompletion { label: "unnameable_test_items", description: r#"detects an item that cannot be named being marked as `#[test_case]`"# }, | ||
115 | LintCompletion { label: "unreachable_code", description: r#"detects unreachable code paths"# }, | ||
116 | LintCompletion { label: "unreachable_patterns", description: r#"detects unreachable patterns"# }, | ||
117 | LintCompletion { label: "unstable_name_collisions", description: r#"detects name collision with an existing but unstable method"# }, | ||
118 | LintCompletion { label: "unused_allocation", description: r#"detects unnecessary allocations that can be eliminated"# }, | ||
119 | LintCompletion { label: "unused_assignments", description: r#"detect assignments that will never be read"# }, | ||
120 | LintCompletion { label: "unused_attributes", description: r#"detects attributes that were not used by the compiler"# }, | ||
121 | LintCompletion { label: "unused_braces", description: r#"unnecessary braces around an expression"# }, | ||
122 | LintCompletion { label: "unused_comparisons", description: r#"comparisons made useless by limits of the types involved"# }, | ||
123 | LintCompletion { label: "unused_doc_comments", description: r#"detects doc comments that aren't used by rustdoc"# }, | ||
124 | LintCompletion { label: "unused_features", description: r#"unused features found in crate-level `#[feature]` directives"# }, | ||
125 | LintCompletion { label: "unused_imports", description: r#"imports that are never used"# }, | ||
126 | LintCompletion { label: "unused_labels", description: r#"detects labels that are never used"# }, | ||
127 | LintCompletion { label: "unused_macros", description: r#"detects macros that were not used"# }, | ||
128 | LintCompletion { label: "unused_must_use", description: r#"unused result of a type flagged as `#[must_use]`"# }, | ||
129 | LintCompletion { label: "unused_mut", description: r#"detect mut variables which don't need to be mutable"# }, | ||
130 | LintCompletion { label: "unused_parens", description: r#"`if`, `match`, `while` and `return` do not need parentheses"# }, | ||
131 | LintCompletion { label: "unused_unsafe", description: r#"unnecessary use of an `unsafe` block"# }, | ||
132 | LintCompletion { label: "unused_variables", description: r#"detect variables which are not used in any way"# }, | ||
133 | LintCompletion { label: "warnings", description: r#"mass-change the level for lints which produce warnings"# }, | ||
134 | LintCompletion { label: "where_clauses_object_safety", description: r#"checks the object safety of where clauses"# }, | ||
135 | LintCompletion { label: "while_true", description: r#"suggest using `loop { }` instead of `while true { }`"# }, | ||
136 | LintCompletion { label: "ambiguous_associated_items", description: r#"ambiguous associated items"# }, | ||
137 | LintCompletion { label: "arithmetic_overflow", description: r#"arithmetic operation overflows"# }, | ||
138 | LintCompletion { label: "conflicting_repr_hints", description: r#"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice"# }, | ||
139 | LintCompletion { label: "const_err", description: r#"constant evaluation detected erroneous expression"# }, | ||
140 | LintCompletion { label: "ill_formed_attribute_input", description: r#"ill-formed attribute inputs that were previously accepted and used in practice"# }, | ||
141 | LintCompletion { label: "incomplete_include", description: r#"trailing content in included file"# }, | ||
142 | LintCompletion { label: "invalid_type_param_default", description: r#"type parameter default erroneously allowed in invalid location"# }, | ||
143 | LintCompletion { label: "macro_expanded_macro_exports_accessed_by_absolute_paths", description: r#"macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths"# }, | ||
144 | LintCompletion { label: "missing_fragment_specifier", description: r#"detects missing fragment specifiers in unused `macro_rules!` patterns"# }, | ||
145 | LintCompletion { label: "mutable_transmutes", description: r#"mutating transmuted &mut T from &T may cause undefined behavior"# }, | ||
146 | LintCompletion { label: "no_mangle_const_items", description: r#"const items will not have their symbols exported"# }, | ||
147 | LintCompletion { label: "order_dependent_trait_objects", description: r#"trait-object types were treated as different depending on marker-trait order"# }, | ||
148 | LintCompletion { label: "overflowing_literals", description: r#"literal out of range for its type"# }, | ||
149 | LintCompletion { label: "patterns_in_fns_without_body", description: r#"patterns in functions without body were erroneously allowed"# }, | ||
150 | LintCompletion { label: "pub_use_of_private_extern_crate", description: r#"detect public re-exports of private extern crates"# }, | ||
151 | LintCompletion { label: "soft_unstable", description: r#"a feature gate that doesn't break dependent crates"# }, | ||
152 | LintCompletion { label: "unconditional_panic", description: r#"operation will cause a panic at runtime"# }, | ||
153 | LintCompletion { label: "unknown_crate_types", description: r#"unknown crate type found in `#[crate_type]` directive"# }, | ||
154 | ]; | ||
155 | |||
156 | #[cfg(test)] | ||
157 | mod tests { | ||
158 | |||
159 | use crate::test_utils::check_edit; | ||
160 | |||
161 | #[test] | ||
162 | fn check_empty() { | ||
163 | check_edit( | ||
164 | "deprecated", | ||
165 | r#"#[allow($0)] struct Test;"#, | ||
166 | r#"#[allow(deprecated)] struct Test;"#, | ||
167 | ) | ||
168 | } | ||
169 | |||
170 | #[test] | ||
171 | fn check_with_existing() { | ||
172 | check_edit( | ||
173 | "deprecated", | ||
174 | r#"#[allow(keyword_idents, $0)] struct Test;"#, | ||
175 | r#"#[allow(keyword_idents, deprecated)] struct Test;"#, | ||
176 | ) | ||
177 | } | ||
178 | |||
179 | #[test] | ||
180 | fn check_qualified() { | ||
181 | check_edit( | ||
182 | "deprecated", | ||
183 | r#"#[allow(keyword_idents, $0)] struct Test;"#, | ||
184 | r#"#[allow(keyword_idents, deprecated)] struct Test;"#, | ||
185 | ) | ||
186 | } | ||
187 | } | ||
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index be9cfbded..df27e7a84 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs | |||
@@ -110,7 +110,11 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) | |||
110 | if !ctx.config.enable_imports_on_the_fly { | 110 | if !ctx.config.enable_imports_on_the_fly { |
111 | return None; | 111 | return None; |
112 | } | 112 | } |
113 | if ctx.use_item_syntax.is_some() || ctx.is_path_disallowed() { | 113 | if ctx.use_item_syntax.is_some() |
114 | || ctx.is_path_disallowed() | ||
115 | || ctx.expects_item() | ||
116 | || ctx.expects_assoc_item() | ||
117 | { | ||
114 | return None; | 118 | return None; |
115 | } | 119 | } |
116 | let potential_import_name = { | 120 | let potential_import_name = { |
diff --git a/crates/ide_completion/src/completions/fn_param.rs b/crates/ide_completion/src/completions/fn_param.rs index 0ea558489..cb90e8a3e 100644 --- a/crates/ide_completion/src/completions/fn_param.rs +++ b/crates/ide_completion/src/completions/fn_param.rs | |||
@@ -128,4 +128,19 @@ fn outer(text: String) { | |||
128 | "#]], | 128 | "#]], |
129 | ) | 129 | ) |
130 | } | 130 | } |
131 | |||