Skip to content

Commit ea140ef

Browse files
Do not remove the original token when descending into derives
This caused rename to remove both, because it couldn't rename the derive-expanded one. I spent some time trying to create a test for this, before giving up. But I checked manually that this works.
1 parent 47845d6 commit ea140ef

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

crates/hir/src/semantics.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,29 +1241,27 @@ impl<'db> SemanticsImpl<'db> {
12411241
adt,
12421242
))
12431243
})?;
1244-
let mut res = None;
12451244
for (_, derive_attr, derives) in derives {
12461245
// as there may be multiple derives registering the same helper
12471246
// name, we gotta make sure to call this for all of them!
12481247
// FIXME: We need to call `f` for all of them as well though!
1249-
res = res.or(process_expansion_for_token(
1250-
ctx,
1251-
&mut stack,
1252-
derive_attr,
1253-
));
1248+
process_expansion_for_token(ctx, &mut stack, derive_attr);
12541249
for derive in derives.into_iter().flatten() {
1255-
res = res
1256-
.or(process_expansion_for_token(ctx, &mut stack, derive));
1250+
process_expansion_for_token(ctx, &mut stack, derive);
12571251
}
12581252
}
12591253
// remove all tokens that are within the derives expansion
12601254
filter_duplicates(tokens, adt.syntax().text_range());
1261-
Some(res)
1255+
Some(())
12621256
});
12631257
// if we found derives, we can early exit. There is no way we can be in any
12641258
// macro call at this point given we are not in a token tree
1265-
if let Some(res) = res {
1266-
return res;
1259+
if let Some(()) = res {
1260+
// Note: derives do not remap the original token. Furthermore, we want
1261+
// the original token to be before the derives in the list, because if they
1262+
// upmap to the same token and we deduplicate them (e.g. in rename), we
1263+
// want the original token to remain, not the derive.
1264+
return None;
12671265
}
12681266
}
12691267
// Then check for token trees, that means we are either in a function-like macro or

0 commit comments

Comments
 (0)