|
1 | | -use super::format_args; |
2 | 1 | use super::mappings::Emission; |
3 | 2 | use crate::generated::{self}; |
4 | 3 | use crate::rust_analyzer::FileSemanticInformation; |
@@ -461,9 +460,6 @@ impl<'db> Translator<'db> { |
461 | 460 | )); |
462 | 461 | } |
463 | 462 | } else if self.semantics.is_some() { |
464 | | - if self.reconstruct_format_args_expansion(mcall, label) { |
465 | | - return; |
466 | | - } |
467 | 463 | // let's not spam warnings if we don't have semantics, we already emitted one |
468 | 464 | let range = self.text_range_for_node(mcall); |
469 | 465 | self.emit_parse_error( |
@@ -785,67 +781,6 @@ impl<'db> Translator<'db> { |
785 | 781 | result |
786 | 782 | } |
787 | 783 |
|
788 | | - /// Reconstructs and emits the expansion of a format-family macro (`format!`, |
789 | | - /// `println!`, `write!`, `panic!`, ...). |
790 | | - /// |
791 | | - /// On `rustc <1.94` sysroots these macros no longer resolve, so `expand_macro_call` |
792 | | - /// returns `None` and we get a bare unexpanded `MacroCall` with no flow through it. |
793 | | - /// We rebuild the token tree of the real expansion ourselves (see |
794 | | - /// [`super::format_args`]), parse it, and register the result as the macro |
795 | | - /// expansion. Locations of the synthesized nodes are routed through the expansion |
796 | | - /// span map via `builtin_derive_span_map`. |
797 | | - /// |
798 | | - /// Returns `true` when the macro was recognized and an expansion was emitted. |
799 | | - fn reconstruct_format_args_expansion( |
800 | | - &mut self, |
801 | | - mcall: &ast::MacroCall, |
802 | | - label: Label<generated::MacroCall>, |
803 | | - ) -> bool { |
804 | | - self.try_reconstruct_format_args_expansion(mcall, label) |
805 | | - .is_some() |
806 | | - } |
807 | | - |
808 | | - /// Attempts to reconstruct and emit a format-family macro expansion. |
809 | | - fn try_reconstruct_format_args_expansion( |
810 | | - &mut self, |
811 | | - mcall: &ast::MacroCall, |
812 | | - label: Label<generated::MacroCall>, |
813 | | - ) -> Option<()> { |
814 | | - let name = mcall.path()?.segment()?.name_ref()?.text().to_string(); |
815 | | - let wrap = format_args::Wrap::for_macro(&name)?; |
816 | | - let tt_node = mcall.token_tree()?; |
817 | | - let semantics = self.semantics?; |
818 | | - let db = semantics.db; |
819 | | - let file_id = semantics.hir_file_for(mcall.syntax()); |
820 | | - let span_map = file_id.span_map(db); |
821 | | - let call_site = span_map.span_for_range(mcall.syntax().text_range()); |
822 | | - let input = syntax_node_to_token_tree( |
823 | | - tt_node.syntax(), |
824 | | - span_map, |
825 | | - call_site, |
826 | | - DocCommentDesugarMode::ProcMacro, |
827 | | - ); |
828 | | - let output = format_args::reconstruct(wrap, &input, call_site)?; |
829 | | - |
830 | | - let edition = self.file_id.map(|f| f.edition(db))?; |
831 | | - let (parsed, output_span_map) = |
832 | | - token_tree_to_syntax_node(&output, TopEntryPoint::Expr, &mut |_| edition); |
833 | | - let root = parsed.syntax_node(); |
834 | | - let expr = ast::Expr::cast(root.clone()) |
835 | | - .or_else(|| root.descendants().find_map(ast::Expr::cast))?; |
836 | | - // Sanity check: the parsed expression must contain the reconstructed |
837 | | - // `FormatArgsExpr` (either directly, or wrapped in the callee above). |
838 | | - expr.syntax() |
839 | | - .descendants() |
840 | | - .find_map(ast::FormatArgsExpr::cast)?; |
841 | | - let previous = self.builtin_derive_span_map.replace(output_span_map); |
842 | | - let emitted = self.emit_expr(&expr); |
843 | | - self.builtin_derive_span_map = previous; |
844 | | - let value = emitted?; |
845 | | - generated::MacroCall::emit_macro_call_expansion(label, value.into(), &mut self.trap.writer); |
846 | | - Some(()) |
847 | | - } |
848 | | - |
849 | 784 | pub(crate) fn emit_derive_expansion( |
850 | 785 | &mut self, |
851 | 786 | node: &(impl Into<ast::Adt> + Clone), |
|
0 commit comments