Skip to content

Commit a07149b

Browse files
committed
rustc: Prevent collisions in names of closures
This commit goes back to using `gensym` to generate unique tokens to put into the names of closures, allowing closures to be able to get demangled in backtraces. Closes #12400
1 parent 6298900 commit a07149b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/librustc/middle/trans/common.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ pub fn return_type_is_void(ccx: &CrateContext, ty: ty::t) -> bool {
103103
ty::type_is_nil(ty) || ty::type_is_bot(ty) || ty::type_is_empty(ccx.tcx, ty)
104104
}
105105

106+
/// Generates a unique symbol based off the name given. This is used to create
107+
/// unique symbols for things like closures.
106108
pub fn gensym_name(name: &str) -> PathElem {
107-
PathName(token::gensym(name))
109+
let num = token::gensym(name);
110+
// use one colon which will get translated to a period by the mangler, and
111+
// we're guaranteed that `num` is globally unique for this crate.
112+
PathName(token::gensym(format!("{}:{}", name, num)))
108113
}
109114

110115
pub struct tydesc_info {

0 commit comments

Comments
 (0)