|
8 | 8 | // option. This file may not be copied, modified, or distributed |
9 | 9 | // except according to those terms. |
10 | 10 |
|
| 11 | +use graphviz::IntoCow; |
11 | 12 | use middle::const_eval::ConstVal; |
12 | 13 | use middle::def_id::DefId; |
13 | 14 | use middle::subst::Substs; |
14 | 15 | use middle::ty::{self, AdtDef, ClosureSubsts, FnOutput, Region, Ty}; |
15 | 16 | use rustc_back::slice; |
16 | | -use rustc_data_structures::tuple_slice::TupleSlice; |
17 | 17 | use rustc_front::hir::InlineAsm; |
18 | | -use syntax::ast::{self, Name}; |
19 | | -use syntax::codemap::Span; |
20 | | -use graphviz::IntoCow; |
21 | 18 | use std::ascii; |
22 | | -use std::borrow::Cow; |
| 19 | +use std::borrow::{Cow}; |
23 | 20 | use std::fmt::{self, Debug, Formatter, Write}; |
24 | 21 | use std::{iter, u32}; |
25 | 22 | use std::ops::{Index, IndexMut}; |
| 23 | +use syntax::ast::{self, Name}; |
| 24 | +use syntax::codemap::Span; |
26 | 25 |
|
27 | 26 | /// Lowered representation of a single function. |
28 | 27 | #[derive(Clone, RustcEncodable, RustcDecodable)] |
@@ -335,29 +334,31 @@ impl<'tcx> CallKind<'tcx> { |
335 | 334 | } |
336 | 335 |
|
337 | 336 | impl<'tcx> Terminator<'tcx> { |
338 | | - pub fn successors(&self) -> &[BasicBlock] { |
| 337 | + pub fn successors(&self) -> Cow<[BasicBlock]> { |
339 | 338 | use self::Terminator::*; |
340 | 339 | match *self { |
341 | | - Goto { target: ref b } => slice::ref_slice(b), |
342 | | - If { targets: ref b, .. } => b.as_slice(), |
343 | | - Switch { targets: ref b, .. } => b, |
344 | | - SwitchInt { targets: ref b, .. } => b, |
345 | | - Resume => &[], |
346 | | - Return => &[], |
347 | | - Call { ref kind, .. } => kind.successors(), |
| 340 | + Goto { target: ref b } => slice::ref_slice(b).into_cow(), |
| 341 | + If { targets: (b1, b2), .. } => vec![b1, b2].into_cow(), |
| 342 | + Switch { targets: ref b, .. } => b[..].into_cow(), |
| 343 | + SwitchInt { targets: ref b, .. } => b[..].into_cow(), |
| 344 | + Resume => (&[]).into_cow(), |
| 345 | + Return => (&[]).into_cow(), |
| 346 | + Call { ref kind, .. } => kind.successors()[..].into_cow(), |
348 | 347 | } |
349 | 348 | } |
350 | 349 |
|
351 | | - pub fn successors_mut(&mut self) -> &mut [BasicBlock] { |
| 350 | + // FIXME: no mootable cow. I’m honestly not sure what a “cow” between `&mut [BasicBlock]` and |
| 351 | + // `Vec<&mut BasicBlock>` would look like in the first place. |
| 352 | + pub fn successors_mut(&mut self) -> Vec<&mut BasicBlock> { |
352 | 353 | use self::Terminator::*; |
353 | 354 | match *self { |
354 | | - Goto { target: ref mut b } => slice::mut_ref_slice(b), |
355 | | - If { targets: ref mut b, .. } => b.as_mut_slice(), |
356 | | - Switch { targets: ref mut b, .. } => b, |
357 | | - SwitchInt { targets: ref mut b, .. } => b, |
358 | | - Resume => &mut [], |
359 | | - Return => &mut [], |
360 | | - Call { ref mut kind, .. } => kind.successors_mut(), |
| 355 | + Goto { target: ref mut b } => vec![b], |
| 356 | + If { targets: (ref mut b1, ref mut b2), .. } => vec![b1, b2], |
| 357 | + Switch { targets: ref mut b, .. } => b.iter_mut().collect(), |
| 358 | + SwitchInt { targets: ref mut b, .. } => b.iter_mut().collect(), |
| 359 | + Resume => Vec::new(), |
| 360 | + Return => Vec::new(), |
| 361 | + Call { ref mut kind, .. } => kind.successors_mut().iter_mut().collect(), |
361 | 362 | } |
362 | 363 | } |
363 | 364 | } |
@@ -445,22 +446,22 @@ impl<'tcx> Terminator<'tcx> { |
445 | 446 | use self::Terminator::*; |
446 | 447 | match *self { |
447 | 448 | Return | Resume => vec![], |
448 | | - Goto { .. } => vec!["".into_cow()], |
449 | | - If { .. } => vec!["true".into_cow(), "false".into_cow()], |
| 449 | + Goto { .. } => vec!["".into()], |
| 450 | + If { .. } => vec!["true".into(), "false".into()], |
450 | 451 | Switch { ref adt_def, .. } => { |
451 | 452 | adt_def.variants |
452 | 453 | .iter() |
453 | | - .map(|variant| variant.name.to_string().into_cow()) |
| 454 | + .map(|variant| variant.name.to_string().into()) |
454 | 455 | .collect() |
455 | 456 | } |
456 | 457 | SwitchInt { ref values, .. } => { |
457 | 458 | values.iter() |
458 | 459 | .map(|const_val| { |
459 | 460 | let mut buf = String::new(); |
460 | 461 | fmt_const_val(&mut buf, const_val).unwrap(); |
461 | | - buf.into_cow() |
| 462 | + buf.into() |
462 | 463 | }) |
463 | | - .chain(iter::once(String::from("otherwise").into_cow())) |
| 464 | + .chain(iter::once(String::from("otherwise").into())) |
464 | 465 | .collect() |
465 | 466 | } |
466 | 467 | Call { ref kind, .. } => match *kind { |
|
0 commit comments