Auto merge of #15819 - wasd96040501:feat/skip_tt_count_limit, r=lnicola

feat: skip checking token tree count for include! macro call

fix #15335 #15648
This commit is contained in:
bors 2023-11-02 10:48:51 +00:00
commit 11a263d5ee

View File

@ -12,11 +12,15 @@ use syntax::{
use triomphe::Arc; use triomphe::Arc;
use crate::{ use crate::{
ast_id_map::AstIdMap, builtin_attr_macro::pseudo_derive_attr_expansion, ast_id_map::AstIdMap,
builtin_fn_macro::EagerExpander, fixup, hygiene::HygieneFrame, tt, AstId, BuiltinAttrExpander, builtin_attr_macro::pseudo_derive_attr_expansion,
BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo, ExpandError, ExpandResult, builtin_fn_macro::EagerExpander,
ExpandTo, HirFileId, HirFileIdRepr, MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId, fixup,
MacroDefKind, MacroFile, ProcMacroExpander, hygiene::HygieneFrame,
name::{name, AsName},
tt, AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo,
ExpandError, ExpandResult, ExpandTo, HirFileId, HirFileIdRepr, MacroCallId, MacroCallKind,
MacroCallLoc, MacroDefId, MacroDefKind, MacroFile, ProcMacroExpander,
}; };
/// Total limit on the number of tokens produced by any macro invocation. /// 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
err = error.clone().or(err); err = error.clone().or(err);
} }
// Set a hard limit for the expanded tt // Skip checking token tree limit for include! macro call
if let Err(value) = check_tt_count(&tt) { let skip_check_tt_count = match loc.kind {
return value; MacroCallKind::FnLike { ast_id, expand_to: _ } => {
if let Some(name_ref) =
ast_id.to_node(db).path().and_then(|p| p.segment()).and_then(|s| s.name_ref())
{
name_ref.as_name() == name!(include)
} else {
false
}
}
_ => false,
};
if !skip_check_tt_count {
// Set a hard limit for the expanded tt
if let Err(value) = check_tt_count(&tt) {
return value;
}
} }
ExpandResult { value: Arc::new(tt), err } ExpandResult { value: Arc::new(tt), err }