diff options
Diffstat (limited to 'crates/hir_def/src/nameres.rs')
-rw-r--r-- | crates/hir_def/src/nameres.rs | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 9e8e4e9ec..542f190a1 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs | |||
@@ -409,6 +409,31 @@ impl DefMap { | |||
409 | } | 409 | } |
410 | } | 410 | } |
411 | } | 411 | } |
412 | |||
413 | fn shrink_to_fit(&mut self) { | ||
414 | // Exhaustive match to require handling new fields. | ||
415 | let Self { | ||
416 | _c: _, | ||
417 | exported_proc_macros, | ||
418 | extern_prelude, | ||
419 | diagnostics, | ||
420 | modules, | ||
421 | block: _, | ||
422 | edition: _, | ||
423 | krate: _, | ||
424 | prelude: _, | ||
425 | root: _, | ||
426 | } = self; | ||
427 | |||
428 | extern_prelude.shrink_to_fit(); | ||
429 | exported_proc_macros.shrink_to_fit(); | ||
430 | diagnostics.shrink_to_fit(); | ||
431 | modules.shrink_to_fit(); | ||
432 | for (_, module) in modules.iter_mut() { | ||
433 | module.children.shrink_to_fit(); | ||
434 | module.scope.shrink_to_fit(); | ||
435 | } | ||
436 | } | ||
412 | } | 437 | } |
413 | 438 | ||
414 | impl ModuleData { | 439 | impl ModuleData { |
@@ -456,7 +481,7 @@ mod diagnostics { | |||
456 | 481 | ||
457 | UnresolvedProcMacro { ast: MacroCallKind }, | 482 | UnresolvedProcMacro { ast: MacroCallKind }, |
458 | 483 | ||
459 | UnresolvedMacroCall { ast: AstId<ast::MacroCall> }, | 484 | UnresolvedMacroCall { ast: AstId<ast::MacroCall>, path: ModPath }, |
460 | 485 | ||
461 | MacroError { ast: MacroCallKind, message: String }, | 486 | MacroError { ast: MacroCallKind, message: String }, |
462 | } | 487 | } |
@@ -521,8 +546,9 @@ mod diagnostics { | |||
521 | pub(super) fn unresolved_macro_call( | 546 | pub(super) fn unresolved_macro_call( |
522 | container: LocalModuleId, | 547 | container: LocalModuleId, |
523 | ast: AstId<ast::MacroCall>, | 548 | ast: AstId<ast::MacroCall>, |
549 | path: ModPath, | ||
524 | ) -> Self { | 550 | ) -> Self { |
525 | Self { in_module: container, kind: DiagnosticKind::UnresolvedMacroCall { ast } } | 551 | Self { in_module: container, kind: DiagnosticKind::UnresolvedMacroCall { ast, path } } |
526 | } | 552 | } |
527 | 553 | ||
528 | pub(super) fn add_to( | 554 | pub(super) fn add_to( |
@@ -588,12 +614,12 @@ mod diagnostics { | |||
588 | DiagnosticKind::UnresolvedProcMacro { ast } => { | 614 | DiagnosticKind::UnresolvedProcMacro { ast } => { |
589 | let mut precise_location = None; | 615 | let mut precise_location = None; |
590 | let (file, ast, name) = match ast { | 616 | let (file, ast, name) = match ast { |
591 | MacroCallKind::FnLike(ast) => { | 617 | MacroCallKind::FnLike { ast_id } => { |
592 | let node = ast.to_node(db.upcast()); | 618 | let node = ast_id.to_node(db.upcast()); |
593 | (ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None) | 619 | (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None) |
594 | } | 620 | } |
595 | MacroCallKind::Derive(ast, name) => { | 621 | MacroCallKind::Derive { ast_id, derive_name, .. } => { |
596 | let node = ast.to_node(db.upcast()); | 622 | let node = ast_id.to_node(db.upcast()); |
597 | 623 | ||
598 | // Compute the precise location of the macro name's token in the derive | 624 | // Compute the precise location of the macro name's token in the derive |
599 | // list. | 625 | // list. |
@@ -614,7 +640,7 @@ mod diagnostics { | |||
614 | }); | 640 | }); |
615 | for token in tokens { | 641 | for token in tokens { |
616 | if token.kind() == SyntaxKind::IDENT | 642 | if token.kind() == SyntaxKind::IDENT |
617 | && token.text() == name.as_str() | 643 | && token.text() == derive_name.as_str() |
618 | { | 644 | { |
619 | precise_location = Some(token.text_range()); | 645 | precise_location = Some(token.text_range()); |
620 | break 'outer; | 646 | break 'outer; |
@@ -623,9 +649,9 @@ mod diagnostics { | |||
623 | } | 649 | } |
624 | 650 | ||
625 | ( | 651 | ( |
626 | ast.file_id, | 652 | ast_id.file_id, |
627 | SyntaxNodePtr::from(AstPtr::new(&node)), | 653 | SyntaxNodePtr::from(AstPtr::new(&node)), |
628 | Some(name.clone()), | 654 | Some(derive_name.clone()), |
629 | ) | 655 | ) |
630 | } | 656 | } |
631 | }; | 657 | }; |
@@ -637,20 +663,24 @@ mod diagnostics { | |||
637 | }); | 663 | }); |
638 | } | 664 | } |
639 | 665 | ||
640 | DiagnosticKind::UnresolvedMacroCall { ast } => { | 666 | DiagnosticKind::UnresolvedMacroCall { ast, path } => { |
641 | let node = ast.to_node(db.upcast()); | 667 | let node = ast.to_node(db.upcast()); |
642 | sink.push(UnresolvedMacroCall { file: ast.file_id, node: AstPtr::new(&node) }); | 668 | sink.push(UnresolvedMacroCall { |
669 | file: ast.file_id, | ||
670 | node: AstPtr::new(&node), | ||
671 | path: path.clone(), | ||
672 | }); | ||
643 | } | 673 | } |
644 | 674 | ||
645 | DiagnosticKind::MacroError { ast, message } => { | 675 | DiagnosticKind::MacroError { ast, message } => { |
646 | let (file, ast) = match ast { | 676 | let (file, ast) = match ast { |
647 | MacroCallKind::FnLike(ast) => { | 677 | MacroCallKind::FnLike { ast_id, .. } => { |
648 | let node = ast.to_node(db.upcast()); | 678 | let node = ast_id.to_node(db.upcast()); |
649 | (ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) | 679 | (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) |
650 | } | 680 | } |
651 | MacroCallKind::Derive(ast, _) => { | 681 | MacroCallKind::Derive { ast_id, .. } => { |
652 | let node = ast.to_node(db.upcast()); | 682 | let node = ast_id.to_node(db.upcast()); |
653 | (ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) | 683 | (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) |
654 | } | 684 | } |
655 | }; | 685 | }; |
656 | sink.push(MacroError { file, node: ast, message: message.clone() }); | 686 | sink.push(MacroError { file, node: ast, message: message.clone() }); |