Skip to content

Commit 11a263d

Browse files
committed
Auto merge of rust-lang#15819 - wasd96040501:feat/skip_tt_count_limit, r=lnicola
feat: skip checking token tree count for include! macro call fix rust-lang#15335 rust-lang#15648
2 parents 99e94d2 + b76f2c8 commit 11a263d

File tree

1 file changed

+28
-8
lines changed
  • crates/hir-expand/src

1 file changed

+28
-8
lines changed

crates/hir-expand/src/db.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ use syntax::{
1212
use triomphe::Arc;
1313

1414
use crate::{
15-
ast_id_map::AstIdMap, builtin_attr_macro::pseudo_derive_attr_expansion,
16-
builtin_fn_macro::EagerExpander, fixup, hygiene::HygieneFrame, tt, AstId, BuiltinAttrExpander,
17-
BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo, ExpandError, ExpandResult,
18-
ExpandTo, HirFileId, HirFileIdRepr, MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId,
19-
MacroDefKind, MacroFile, ProcMacroExpander,
15+
ast_id_map::AstIdMap,
16+
builtin_attr_macro::pseudo_derive_attr_expansion,
17+
builtin_fn_macro::EagerExpander,
18+
fixup,
19+
hygiene::HygieneFrame,
20+
name::{name, AsName},
21+
tt, AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo,
22+
ExpandError, ExpandResult, ExpandTo, HirFileId, HirFileIdRepr, MacroCallId, MacroCallKind,
23+
MacroCallLoc, MacroDefId, MacroDefKind, MacroFile, ProcMacroExpander,
2024
};
2125

2226
/// Total limit on the number of tokens produced by any macro invocation.
@@ -614,9 +618,25 @@ fn macro_expand(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<Arc<tt
614618
err = error.clone().or(err);
615619
}
616620

617-
// Set a hard limit for the expanded tt
618-
if let Err(value) = check_tt_count(&tt) {
619-
return value;
621+
// Skip checking token tree limit for include! macro call
622+
let skip_check_tt_count = match loc.kind {
623+
MacroCallKind::FnLike { ast_id, expand_to: _ } => {
624+
if let Some(name_ref) =
625+
ast_id.to_node(db).path().and_then(|p| p.segment()).and_then(|s| s.name_ref())
626+
{
627+
name_ref.as_name() == name!(include)
628+
} else {
629+
false
630+
}
631+
}
632+
_ => false,
633+
};
634+
635+
if !skip_check_tt_count {
636+
// Set a hard limit for the expanded tt
637+
if let Err(value) = check_tt_count(&tt) {
638+
return value;
639+
}
620640
}
621641

622642
ExpandResult { value: Arc::new(tt), err }

0 commit comments

Comments
 (0)