Skip to content

Commit c932ca5

Browse files
committed
Add crate_limits query to SourceDatabase
This allows fetching crate limits like `recursion_limit`. The implementation is currently dummy and just returns the defaults. Future work: Use this query instead of the hardcoded constant. Future work: Actually implement this query by parsing `#![recursion_limit = N]` attribute.
1 parent 93036aa commit c932ca5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

crates/base_db/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ pub trait SourceDatabase: FileLoader + std::fmt::Debug {
6969
/// The crate graph.
7070
#[salsa::input]
7171
fn crate_graph(&self) -> Arc<CrateGraph>;
72+
73+
#[salsa::transparent]
74+
fn crate_limits(&self, crate_id: CrateId) -> CrateLimits;
75+
}
76+
77+
pub struct CrateLimits {
78+
/// The maximum depth for potentially infinitely-recursive compile-time operations like macro expansion or auto-dereference.
79+
pub recursion_limit: u32,
80+
}
81+
82+
fn crate_limits(_db: &dyn SourceDatabase, _crate_id: CrateId) -> CrateLimits {
83+
CrateLimits {
84+
// 128 is the default in rustc.
85+
recursion_limit: 128,
86+
}
7287
}
7388

7489
fn parse_query(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {

0 commit comments

Comments
 (0)