Merge #5379
5379: Guard against infinite macro expansions r=matklad a=matklad closes #4463 bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
a50c64a4f1
@ -717,6 +717,11 @@ fn collect_macro_expansion(
|
||||
macro_call_id: MacroCallId,
|
||||
depth: usize,
|
||||
) {
|
||||
if depth > 100 {
|
||||
mark::hit!(macro_expansion_overflow);
|
||||
log::warn!("macro expansion is too deep");
|
||||
return;
|
||||
}
|
||||
let file_id: HirFileId = macro_call_id.as_file();
|
||||
let item_tree = self.db.item_tree(file_id);
|
||||
let mod_dir = self.mod_dirs[&module_id].clone();
|
||||
|
@ -660,3 +660,27 @@ fn expand_multiple_derive() {
|
||||
);
|
||||
assert_eq!(map.modules[map.root].scope.impls().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macro_expansion_overflow() {
|
||||
mark::check!(macro_expansion_overflow);
|
||||
compute_crate_def_map(
|
||||
"
|
||||
macro_rules! a {
|
||||
($e:expr; $($t:tt)*) => {
|
||||
b!($($t)*);
|
||||
};
|
||||
() => {};
|
||||
}
|
||||
|
||||
macro_rules! b {
|
||||
(static = $e:expr; $($t:tt)*) => {
|
||||
a!($e; $($t)*);
|
||||
};
|
||||
() => {};
|
||||
}
|
||||
|
||||
b! { static = #[] (); }
|
||||
",
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user