Clean-up transmutes in libsyntax
This commit is contained in:
parent
2790505c19
commit
fbb90c3458
@ -119,7 +119,7 @@ impl Name {
|
||||
pub fn as_str<'a>(&'a self) -> &'a str {
|
||||
unsafe {
|
||||
// FIXME #12938: can't use copy_lifetime since &str isn't a &T
|
||||
::std::mem::transmute(token::get_name(*self).get())
|
||||
::std::mem::transmute::<&str,&str>(token::get_name(*self).get())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -668,12 +668,12 @@ impl InternedString {
|
||||
|
||||
impl BytesContainer for InternedString {
|
||||
fn container_as_bytes<'a>(&'a self) -> &'a [u8] {
|
||||
// FIXME(pcwalton): This is a workaround for the incorrect signature
|
||||
// FIXME #12938: This is a workaround for the incorrect signature
|
||||
// of `BytesContainer`, which is itself a workaround for the lack of
|
||||
// DST.
|
||||
unsafe {
|
||||
let this = self.get();
|
||||
mem::transmute(this.container_as_bytes())
|
||||
mem::transmute::<&[u8],&[u8]>(this.container_as_bytes())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,17 +169,14 @@ pub fn to_string(f: |&mut State| -> IoResult<()>) -> String {
|
||||
let mut s = rust_printer(box MemWriter::new());
|
||||
f(&mut s).unwrap();
|
||||
eof(&mut s.s).unwrap();
|
||||
unsafe {
|
||||
let wr = unsafe {
|
||||
// FIXME(pcwalton): A nasty function to extract the string from an `io::Writer`
|
||||
// that we "know" to be a `MemWriter` that works around the lack of checked
|
||||
// downcasts.
|
||||
let obj: TraitObject = mem::transmute_copy(&s.s.out);
|
||||
let wr: Box<MemWriter> = mem::transmute(obj.data);
|
||||
let result =
|
||||
String::from_utf8(wr.get_ref().as_slice().to_vec()).unwrap();
|
||||
mem::forget(wr);
|
||||
result.to_string()
|
||||
}
|
||||
let obj: &TraitObject = mem::transmute(&s.s.out);
|
||||
mem::transmute::<*mut (), &MemWriter>(obj.data)
|
||||
};
|
||||
String::from_utf8(wr.get_ref().to_vec()).unwrap()
|
||||
}
|
||||
|
||||
pub fn binop_to_string(op: BinOpToken) -> &'static str {
|
||||
|
Loading…
x
Reference in New Issue
Block a user