Skip to content

Commit 730d04c

Browse files
authored
Merge pull request #22559 from github/paldepind-remove-rust-toolchain-workarounds
Rust: remove pre-1.94 format macro fallback
2 parents 693d930 + 9a1e69f commit 730d04c

14 files changed

Lines changed: 0 additions & 520 deletions

File tree

‎rust/extractor/src/translate.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mod base;
2-
mod format_args;
32
mod generated;
43
mod mappings;
54

‎rust/extractor/src/translate/base.rs‎

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use super::format_args;
21
use super::mappings::Emission;
32
use crate::generated::{self};
43
use crate::rust_analyzer::FileSemanticInformation;
@@ -461,9 +460,6 @@ impl<'db> Translator<'db> {
461460
));
462461
}
463462
} else if self.semantics.is_some() {
464-
if self.reconstruct_format_args_expansion(mcall, label) {
465-
return;
466-
}
467463
// let's not spam warnings if we don't have semantics, we already emitted one
468464
let range = self.text_range_for_node(mcall);
469465
self.emit_parse_error(
@@ -785,67 +781,6 @@ impl<'db> Translator<'db> {
785781
result
786782
}
787783

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-
849784
pub(crate) fn emit_derive_expansion(
850785
&mut self,
851786
node: &(impl Into<ast::Adt> + Clone),

‎rust/extractor/src/translate/format_args.rs‎

Lines changed: 0 additions & 163 deletions
This file was deleted.

‎rust/ql/test/.gitignore‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ target/
33
# these are all generated, see `rust/extractor/src/qltest.rs` for details
44
Cargo.toml
55
/*/**/rust-toolchain.toml
6-
# but this one is committed on purpose: it pins a pre-1.94 toolchain to exercise
7-
# the extractor's `FormatArgsExpr` reconstruction fallback.
8-
!/library-tests/format-macros-legacy/rust-toolchain.toml
96
lib.rs
107
.proc_macro/
118
.lib/
12-

‎rust/ql/test/library-tests/format-macros-legacy/Cargo.lock‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎rust/ql/test/library-tests/format-macros-legacy/FormatArgs.expected‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎rust/ql/test/library-tests/format-macros-legacy/FormatArgs.ql‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎rust/ql/test/library-tests/format-macros-legacy/LogInjection.expected‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎rust/ql/test/library-tests/format-macros-legacy/LogInjection.qlref‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)