diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-11-03 15:29:08 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-11-03 15:29:08 -0800 |
| commit | 3aaee490d3e7e6d242aa0c43e4034ad63739e092 (patch) | |
| tree | 9ba1020a7552e5a8da31707beaf1e0151b514781 /src/libsyntax | |
| parent | b8e2eb729410ae2727a85b6ebfebd278ff765805 (diff) | |
| parent | a87078a27d4e5434f937ed3810c9fbfa7ff1f793 (diff) | |
| download | rust-3aaee490d3e7e6d242aa0c43e4034ad63739e092.tar.gz rust-3aaee490d3e7e6d242aa0c43e4034ad63739e092.zip | |
rollup merge of #18318 : arielb1/transmute-cleanup
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 33 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 13 |
4 files changed, 23 insertions, 29 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a2c859cf9fd..1edcb35289a 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -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()) } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 8b0e1f32fd4..863f53be798 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -21,7 +21,6 @@ use ptr::P; use visit::Visitor; use visit; -use std::cell::Cell; use std::cmp; use std::u32; @@ -333,20 +332,20 @@ impl IdRange { } pub trait IdVisitingOperation { - fn visit_id(&self, node_id: NodeId); + fn visit_id(&mut self, node_id: NodeId); } /// A visitor that applies its operation to all of the node IDs /// in a visitable thing. pub struct IdVisitor<'a, O:'a> { - pub operation: &'a O, + pub operation: &'a mut O, pub pass_through_items: bool, pub visited_outermost: bool, } impl<'a, O: IdVisitingOperation> IdVisitor<'a, O> { - fn visit_generics_helper(&self, generics: &Generics) { + fn visit_generics_helper(&mut self, generics: &Generics) { for type_parameter in generics.ty_params.iter() { self.operation.visit_id(type_parameter.id) } @@ -540,7 +539,7 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> { } pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &InlinedItem, - operation: &O) { + operation: &mut O) { let mut id_visitor = IdVisitor { operation: operation, pass_through_items: true, @@ -551,23 +550,21 @@ pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &InlinedItem, } struct IdRangeComputingVisitor { - result: Cell<IdRange>, + result: IdRange, } impl IdVisitingOperation for IdRangeComputingVisitor { - fn visit_id(&self, id: NodeId) { - let mut id_range = self.result.get(); - id_range.add(id); - self.result.set(id_range) + fn visit_id(&mut self, id: NodeId) { + self.result.add(id); } } pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange { - let visitor = IdRangeComputingVisitor { - result: Cell::new(IdRange::max()) + let mut visitor = IdRangeComputingVisitor { + result: IdRange::max() }; - visit_ids_for_inlined_item(item, &visitor); - visitor.result.get() + visit_ids_for_inlined_item(item, &mut visitor); + visitor.result } pub fn compute_id_range_for_fn_body(fk: visit::FnKind, @@ -582,16 +579,16 @@ pub fn compute_id_range_for_fn_body(fk: visit::FnKind, * ignoring nested items. */ - let visitor = IdRangeComputingVisitor { - result: Cell::new(IdRange::max()) + let mut visitor = IdRangeComputingVisitor { + result: IdRange::max() }; let mut id_visitor = IdVisitor { - operation: &visitor, + operation: &mut visitor, pass_through_items: false, visited_outermost: false, }; id_visitor.visit_fn(fk, decl, body, sp, id); - visitor.result.get() + id_visitor.operation.result } pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index d56aa8da72a..615cd34ca14 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -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()) } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 386fd8ae5a6..4cfc95d4c3f 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -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 { |
