mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Support signed integers and char
in v0 mangling
This commit is contained in:
parent
1d2726726f
commit
6b52603a49
@ -4,6 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{CrateNum, DefId};
|
use rustc_hir::def_id::{CrateNum, DefId};
|
||||||
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
||||||
|
use rustc_middle::mir::interpret::sign_extend;
|
||||||
use rustc_middle::ty::print::{Print, Printer};
|
use rustc_middle::ty::print::{Print, Printer};
|
||||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
|
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
|
||||||
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
|
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
|
||||||
@ -527,17 +528,30 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
|
|||||||
}
|
}
|
||||||
let start = self.out.len();
|
let start = self.out.len();
|
||||||
|
|
||||||
match ct.ty.kind() {
|
let mut neg = false;
|
||||||
ty::Uint(_) => {}
|
let val = match ct.ty.kind() {
|
||||||
ty::Bool => {}
|
ty::Uint(_) | ty::Bool | ty::Char => {
|
||||||
|
ct.try_eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty)
|
||||||
|
}
|
||||||
|
ty::Int(_) => {
|
||||||
|
let param_env = ty::ParamEnv::reveal_all();
|
||||||
|
ct.try_eval_bits(self.tcx, param_env, ct.ty).and_then(|b| {
|
||||||
|
let sz = self.tcx.layout_of(param_env.and(ct.ty)).ok()?.size;
|
||||||
|
let val = sign_extend(b, sz) as i128;
|
||||||
|
if val < 0 {
|
||||||
|
neg = true;
|
||||||
|
}
|
||||||
|
Some(val.wrapping_abs() as u128)
|
||||||
|
})
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
bug!("symbol_names: unsupported constant of type `{}` ({:?})", ct.ty, ct);
|
bug!("symbol_names: unsupported constant of type `{}` ({:?})", ct.ty, ct);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
self = ct.ty.print(self)?;
|
self = ct.ty.print(self)?;
|
||||||
|
|
||||||
if let Some(bits) = ct.try_eval_bits(self.tcx, ty::ParamEnv::reveal_all(), ct.ty) {
|
if let Some(bits) = val {
|
||||||
let _ = write!(self.out, "{:x}_", bits);
|
let _ = write!(self.out, "{}{:x}_", if neg { "n" } else { "" }, bits);
|
||||||
} else {
|
} else {
|
||||||
// NOTE(eddyb) despite having the path, we need to
|
// NOTE(eddyb) despite having the path, we need to
|
||||||
// encode a placeholder, as the path could refer
|
// encode a placeholder, as the path could refer
|
||||||
|
87
src/test/ui/symbol-names/const-generics.rs
Normal file
87
src/test/ui/symbol-names/const-generics.rs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
// check-pass
|
||||||
|
// revisions: legacy v0
|
||||||
|
//[legacy]compile-flags: -Z symbol-mangling-version=legacy --crate-type=lib
|
||||||
|
//[v0]compile-flags: -Z symbol-mangling-version=v0 --crate-type=lib
|
||||||
|
|
||||||
|
#![feature(min_const_generics)]
|
||||||
|
|
||||||
|
// `char`
|
||||||
|
pub struct Char<const F: char>;
|
||||||
|
|
||||||
|
impl Char<'A'> {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const F: char> Char<F> {
|
||||||
|
pub fn bar() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// `i8`
|
||||||
|
pub struct I8<const F: i8>;
|
||||||
|
|
||||||
|
impl I8<{std::i8::MIN}> {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl I8<{std::i8::MAX}> {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const F: i8> I8<F> {
|
||||||
|
pub fn bar() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// `i16`
|
||||||
|
pub struct I16<const F: i16>;
|
||||||
|
|
||||||
|
impl I16<{std::i16::MIN}> {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const F: i16> I16<F> {
|
||||||
|
pub fn bar() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// `i32`
|
||||||
|
pub struct I32<const F: i32>;
|
||||||
|
|
||||||
|
impl I32<{std::i32::MIN}> {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const F: i32> I32<F> {
|
||||||
|
pub fn bar() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// `i64`
|
||||||
|
pub struct I64<const F: i64>;
|
||||||
|
|
||||||
|
impl I64<{std::i64::MIN}> {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const F: i64> I64<F> {
|
||||||
|
pub fn bar() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// `i128`
|
||||||
|
pub struct I128<const F: i128>;
|
||||||
|
|
||||||
|
impl I128<{std::i128::MIN}> {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const F: i128> I128<F> {
|
||||||
|
pub fn bar() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// `isize`
|
||||||
|
pub struct ISize<const F: isize>;
|
||||||
|
|
||||||
|
impl ISize<3> {
|
||||||
|
pub fn foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const F: isize> ISize<F> {
|
||||||
|
pub fn bar() {}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user