From b8fdfcc22730ea5ee055eb25fe7ae57541ff7f3f Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 31 Dec 2024 12:59:20 +0100 Subject: [PATCH 1/2] Remove recursion_limit special casing in tests --- src/tools/rust-analyzer/crates/hir-def/src/body/tests.rs | 4 ++-- .../rust-analyzer/crates/hir-def/src/nameres/collector.rs | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body/tests.rs b/src/tools/rust-analyzer/crates/hir-def/src/body/tests.rs index 13ba4db60649f..7e15a9f2d618c 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/body/tests.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/body/tests.rs @@ -52,6 +52,7 @@ fn your_stack_belongs_to_me() { cov_mark::check!(your_stack_belongs_to_me); lower( r#" +#![recursion_limit = "32"] macro_rules! n_nuple { ($e:tt) => (); ($($rest:tt)*) => {{ @@ -68,6 +69,7 @@ fn your_stack_belongs_to_me2() { cov_mark::check!(overflow_but_not_me); lower( r#" +#![recursion_limit = "32"] macro_rules! foo { () => {{ foo!(); foo!(); }} } @@ -78,8 +80,6 @@ fn main() { foo!(); } #[test] fn recursion_limit() { - cov_mark::check!(your_stack_belongs_to_me); - lower( r#" #![recursion_limit = "2"] diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs index 5d19b849a7353..6474bb7e5e0f1 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs @@ -1451,13 +1451,7 @@ impl DefCollector<'_> { depth: usize, container: ItemContainerId, ) { - let recursion_limit = self.def_map.recursion_limit() as usize; - let recursion_limit = Limit::new(if cfg!(test) { - // Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug - std::cmp::min(32, recursion_limit) - } else { - recursion_limit - }); + let recursion_limit = Limit::new(self.def_map.recursion_limit() as usize); if recursion_limit.check(depth).is_err() { cov_mark::hit!(macro_expansion_overflow); tracing::warn!("macro expansion is too deep"); From 7468106726797f59e8762336bb6aeccdebaaaa57 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 31 Dec 2024 12:59:20 +0100 Subject: [PATCH 2/2] Implement `::eq` --- .../src/server_impl/rust_analyzer_span.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs index 1b535d2a1ccc0..58eed6499be1d 100644 --- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs +++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs @@ -12,7 +12,7 @@ use std::{ use intern::Symbol; use proc_macro::bridge::{self, server}; -use span::{Span, FIXUP_ERASED_FILE_AST_ID_MARKER}; +use span::{FileId, Span, FIXUP_ERASED_FILE_AST_ID_MARKER}; use tt::{TextRange, TextSize}; use crate::server_impl::{ @@ -32,8 +32,10 @@ mod tt { type TokenStream = crate::server_impl::TokenStream; -#[derive(Clone)] -pub struct SourceFile; +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +pub struct SourceFile { + file_id: FileId, +} pub struct FreeFunctions; pub struct RaSpanServer { @@ -291,9 +293,8 @@ impl server::TokenStream for RaSpanServer { } impl server::SourceFile for RaSpanServer { - fn eq(&mut self, _file1: &Self::SourceFile, _file2: &Self::SourceFile) -> bool { - // FIXME - true + fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool { + file1 == file2 } fn path(&mut self, _file: &Self::SourceFile) -> String { // FIXME @@ -308,9 +309,8 @@ impl server::Span for RaSpanServer { fn debug(&mut self, span: Self::Span) -> String { format!("{:?}", span) } - fn source_file(&mut self, _span: Self::Span) -> Self::SourceFile { - // FIXME stub, requires db - SourceFile {} + fn source_file(&mut self, span: Self::Span) -> Self::SourceFile { + SourceFile { file_id: span.anchor.file_id.file_id() } } fn save_span(&mut self, _span: Self::Span) -> usize { // FIXME, quote is incompatible with third-party tools