Skip to content

Commit fd7ef27

Browse files
authored
Merge pull request rust-lang#18805 from Veykril/push-pzurvxvoolxs
internal: Implement `<RaSpanServer as SourceFile>::eq`
2 parents 8bb0fab + 7468106 commit fd7ef27

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

src/tools/rust-analyzer/crates/hir-def/src/body/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fn your_stack_belongs_to_me() {
5252
cov_mark::check!(your_stack_belongs_to_me);
5353
lower(
5454
r#"
55+
#![recursion_limit = "32"]
5556
macro_rules! n_nuple {
5657
($e:tt) => ();
5758
($($rest:tt)*) => {{
@@ -68,6 +69,7 @@ fn your_stack_belongs_to_me2() {
6869
cov_mark::check!(overflow_but_not_me);
6970
lower(
7071
r#"
72+
#![recursion_limit = "32"]
7173
macro_rules! foo {
7274
() => {{ foo!(); foo!(); }}
7375
}
@@ -78,8 +80,6 @@ fn main() { foo!(); }
7880

7981
#[test]
8082
fn recursion_limit() {
81-
cov_mark::check!(your_stack_belongs_to_me);
82-
8383
lower(
8484
r#"
8585
#![recursion_limit = "2"]

src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1451,13 +1451,7 @@ impl DefCollector<'_> {
14511451
depth: usize,
14521452
container: ItemContainerId,
14531453
) {
1454-
let recursion_limit = self.def_map.recursion_limit() as usize;
1455-
let recursion_limit = Limit::new(if cfg!(test) {
1456-
// Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug
1457-
std::cmp::min(32, recursion_limit)
1458-
} else {
1459-
recursion_limit
1460-
});
1454+
let recursion_limit = Limit::new(self.def_map.recursion_limit() as usize);
14611455
if recursion_limit.check(depth).is_err() {
14621456
cov_mark::hit!(macro_expansion_overflow);
14631457
tracing::warn!("macro expansion is too deep");

src/tools/rust-analyzer/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212

1313
use intern::Symbol;
1414
use proc_macro::bridge::{self, server};
15-
use span::{Span, FIXUP_ERASED_FILE_AST_ID_MARKER};
15+
use span::{FileId, Span, FIXUP_ERASED_FILE_AST_ID_MARKER};
1616
use tt::{TextRange, TextSize};
1717

1818
use crate::server_impl::{
@@ -32,8 +32,10 @@ mod tt {
3232

3333
type TokenStream = crate::server_impl::TokenStream<Span>;
3434

35-
#[derive(Clone)]
36-
pub struct SourceFile;
35+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
36+
pub struct SourceFile {
37+
file_id: FileId,
38+
}
3739
pub struct FreeFunctions;
3840

3941
pub struct RaSpanServer {
@@ -291,9 +293,8 @@ impl server::TokenStream for RaSpanServer {
291293
}
292294

293295
impl server::SourceFile for RaSpanServer {
294-
fn eq(&mut self, _file1: &Self::SourceFile, _file2: &Self::SourceFile) -> bool {
295-
// FIXME
296-
true
296+
fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool {
297+
file1 == file2
297298
}
298299
fn path(&mut self, _file: &Self::SourceFile) -> String {
299300
// FIXME
@@ -308,9 +309,8 @@ impl server::Span for RaSpanServer {
308309
fn debug(&mut self, span: Self::Span) -> String {
309310
format!("{:?}", span)
310311
}
311-
fn source_file(&mut self, _span: Self::Span) -> Self::SourceFile {
312-
// FIXME stub, requires db
313-
SourceFile {}
312+
fn source_file(&mut self, span: Self::Span) -> Self::SourceFile {
313+
SourceFile { file_id: span.anchor.file_id.file_id() }
314314
}
315315
fn save_span(&mut self, _span: Self::Span) -> usize {
316316
// FIXME, quote is incompatible with third-party tools

0 commit comments

Comments
 (0)