Skip to content

Commit

Permalink
Rollup merge of #123922 - TDecking:base_n_magic_removal, r=jieyouxu
Browse files Browse the repository at this point in the history
Remove magic constants when using `base_n`.

Some use cases of `base_n` use number literals instead of the predefined constants. The latter are more descriptive so it might be better to use those instead.
  • Loading branch information
jieyouxu authored Apr 15, 2024
2 parents b1d1e08 + e5cf30c commit 1870e2d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
/// <https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html>).
fn to_disambiguator(num: u64) -> String {
if let Some(num) = num.checked_sub(1) {
format!("s{}_", base_n::encode(num as u128, 62))
format!("s{}_", base_n::encode(num as u128, base_n::ALPHANUMERIC_ONLY))
} else {
"s_".to_string()
}
Expand All @@ -746,7 +746,7 @@ fn to_disambiguator(num: u64) -> String {
/// <https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangle.seq-id>).
fn to_seq_id(num: usize) -> String {
if let Some(num) = num.checked_sub(1) {
base_n::encode(num as u128, 36).to_uppercase()
base_n::encode(num as u128, base_n::CASE_INSENSITIVE).to_uppercase()
} else {
"".to_string()
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
/// e.g. `1` becomes `"0_"`, `62` becomes `"Z_"`, etc.
pub(crate) fn push_integer_62(x: u64, output: &mut String) {
if let Some(x) = x.checked_sub(1) {
base_n::push_str(x as u128, 62, output);
base_n::push_str(x as u128, base_n::ALPHANUMERIC_ONLY, output);
}
output.push('_');
}
Expand Down

0 comments on commit 1870e2d

Please sign in to comment.