mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 05:38:46 +00:00
Cleanup limits
This commit is contained in:
parent
8baa2b727d
commit
4c08fc9be3
1 changed files with 7 additions and 7 deletions
|
@ -36,6 +36,10 @@ use crate::{
|
|||
TraitLoc, TypeAliasLoc, UnionLoc,
|
||||
};
|
||||
|
||||
const GLOB_RECURSION_LIMIT: usize = 100;
|
||||
const EXPANSION_DEPTH_LIMIT: usize = 128;
|
||||
const FIXED_POINT_LIMIT: usize = 8192;
|
||||
|
||||
pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
|
||||
let crate_graph = db.crate_graph();
|
||||
|
||||
|
@ -217,7 +221,7 @@ impl DefCollector<'_> {
|
|||
ReachedFixedPoint::Yes => break,
|
||||
ReachedFixedPoint::No => i += 1,
|
||||
}
|
||||
if i == 10000 {
|
||||
if i == FIXED_POINT_LIMIT {
|
||||
log::error!("name resolution is stuck");
|
||||
break;
|
||||
}
|
||||
|
@ -587,7 +591,7 @@ impl DefCollector<'_> {
|
|||
import_type: ImportType,
|
||||
depth: usize,
|
||||
) {
|
||||
if depth > 100 {
|
||||
if depth > GLOB_RECURSION_LIMIT {
|
||||
// prevent stack overflows (but this shouldn't be possible)
|
||||
panic!("infinite recursion in glob imports!");
|
||||
}
|
||||
|
@ -679,10 +683,6 @@ impl DefCollector<'_> {
|
|||
self.unexpanded_attribute_macros = attribute_macros;
|
||||
|
||||
for (module_id, macro_call_id, depth) in resolved {
|
||||
if depth > 1024 {
|
||||
log::debug!("Max macro expansion depth reached");
|
||||
continue;
|
||||
}
|
||||
self.collect_macro_expansion(module_id, macro_call_id, depth);
|
||||
}
|
||||
|
||||
|
@ -719,7 +719,7 @@ impl DefCollector<'_> {
|
|||
macro_call_id: MacroCallId,
|
||||
depth: usize,
|
||||
) {
|
||||
if depth > 100 {
|
||||
if depth > EXPANSION_DEPTH_LIMIT {
|
||||
mark::hit!(macro_expansion_overflow);
|
||||
log::warn!("macro expansion is too deep");
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue