Skip to content

Commit 8202b5a

Browse files
committed
Auto merge of #15366 - Veykril:eager-macro-inputs, r=Veykril
fix: Remove another faulty unwrap (expect) Like the other ones, this also results in a panic when writing out `include!` due to the missing tt
2 parents 7736b65 + bf56246 commit 8202b5a

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

crates/hir-expand/src/eager.rs

+22-20
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,35 @@ pub fn expand_eager_macro_input(
7979
return Ok(ExpandResult { value: None, err });
8080
};
8181

82-
let og_tmap = mbe::syntax_node_to_token_map(
83-
macro_call.value.token_tree().expect("macro_arg_text succeeded").syntax(),
84-
);
85-
8682
let (mut subtree, expanded_eager_input_token_map) =
8783
mbe::syntax_node_to_token_tree(&expanded_eager_input);
8884

89-
// The tokenmap and ids of subtree point into the expanded syntax node, but that is inaccessible from the outside
90-
// so we need to remap them to the original input of the eager macro.
91-
subtree.visit_ids(&|id| {
92-
// Note: we discard all token ids of braces and the like here, but that's not too bad and only a temporary fix
85+
let og_tmap = if let Some(tt) = macro_call.value.token_tree() {
86+
let og_tmap = mbe::syntax_node_to_token_map(tt.syntax());
87+
// The tokenmap and ids of subtree point into the expanded syntax node, but that is inaccessible from the outside
88+
// so we need to remap them to the original input of the eager macro.
89+
subtree.visit_ids(&|id| {
90+
// Note: we discard all token ids of braces and the like here, but that's not too bad and only a temporary fix
9391

94-
if let Some(range) =
95-
expanded_eager_input_token_map.first_range_by_token(id, syntax::SyntaxKind::TOMBSTONE)
96-
{
97-
// remap from expanded eager input to eager input expansion
98-
if let Some(og_range) = mapping.get(&range) {
99-
// remap from eager input expansion to original eager input
100-
if let Some(&og_range) = ws_mapping.get(og_range) {
101-
if let Some(og_token) = og_tmap.token_by_range(og_range) {
102-
return og_token;
92+
if let Some(range) = expanded_eager_input_token_map
93+
.first_range_by_token(id, syntax::SyntaxKind::TOMBSTONE)
94+
{
95+
// remap from expanded eager input to eager input expansion
96+
if let Some(og_range) = mapping.get(&range) {
97+
// remap from eager input expansion to original eager input
98+
if let Some(&og_range) = ws_mapping.get(og_range) {
99+
if let Some(og_token) = og_tmap.token_by_range(og_range) {
100+
return og_token;
101+
}
103102
}
104103
}
105104
}
106-
}
107-
tt::TokenId::UNSPECIFIED
108-
});
105+
tt::TokenId::UNSPECIFIED
106+
});
107+
og_tmap
108+
} else {
109+
Default::default()
110+
};
109111
subtree.delimiter = crate::tt::Delimiter::unspecified();
110112

111113
let loc = MacroCallLoc {

0 commit comments

Comments
 (0)