Skip to content

Commit

Permalink
Add missing dyn
Browse files Browse the repository at this point in the history
  • Loading branch information
ishitatsuyuki committed Jul 25, 2018
1 parent 8646a17 commit 66c4dc9
Show file tree
Hide file tree
Showing 23 changed files with 69 additions and 65 deletions.
6 changes: 3 additions & 3 deletions src/liballoc/tests/arc.rs
Expand Up @@ -18,7 +18,7 @@ fn uninhabited() {
a = a.clone();
assert!(a.upgrade().is_none());

let mut a: Weak<Any> = a; // Unsizing
let mut a: Weak<dyn Any> = a; // Unsizing
a = a.clone();
assert!(a.upgrade().is_none());
}
Expand All @@ -39,7 +39,7 @@ fn slice() {
#[test]
fn trait_object() {
let a: Arc<u32> = Arc::new(4);
let a: Arc<Any> = a; // Unsizing
let a: Arc<dyn Any> = a; // Unsizing

// Exercise is_dangling() with a DST
let mut a = Arc::downgrade(&a);
Expand All @@ -49,7 +49,7 @@ fn trait_object() {
let mut b = Weak::<u32>::new();
b = b.clone();
assert!(b.upgrade().is_none());
let mut b: Weak<Any> = b; // Unsizing
let mut b: Weak<dyn Any> = b; // Unsizing
b = b.clone();
assert!(b.upgrade().is_none());
}
2 changes: 1 addition & 1 deletion src/liballoc/tests/btree/set.rs
Expand Up @@ -40,7 +40,7 @@ fn test_hash() {
}

fn check<F>(a: &[i32], b: &[i32], expected: &[i32], f: F)
where F: FnOnce(&BTreeSet<i32>, &BTreeSet<i32>, &mut FnMut(&i32) -> bool) -> bool
where F: FnOnce(&BTreeSet<i32>, &BTreeSet<i32>, &mut dyn FnMut(&i32) -> bool) -> bool
{
let mut set_a = BTreeSet::new();
let mut set_b = BTreeSet::new();
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/tests/lib.rs
Expand Up @@ -63,7 +63,7 @@ fn test_boxed_hasher() {
5u32.hash(&mut hasher_1);
assert_eq!(ordinary_hash, hasher_1.finish());

let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<Hasher>;
let mut hasher_2 = Box::new(DefaultHasher::new()) as Box<dyn Hasher>;
5u32.hash(&mut hasher_2);
assert_eq!(ordinary_hash, hasher_2.finish());
}
6 changes: 3 additions & 3 deletions src/liballoc/tests/rc.rs
Expand Up @@ -18,7 +18,7 @@ fn uninhabited() {
a = a.clone();
assert!(a.upgrade().is_none());

let mut a: Weak<Any> = a; // Unsizing
let mut a: Weak<dyn Any> = a; // Unsizing
a = a.clone();
assert!(a.upgrade().is_none());
}
Expand All @@ -39,7 +39,7 @@ fn slice() {
#[test]
fn trait_object() {
let a: Rc<u32> = Rc::new(4);
let a: Rc<Any> = a; // Unsizing
let a: Rc<dyn Any> = a; // Unsizing

// Exercise is_dangling() with a DST
let mut a = Rc::downgrade(&a);
Expand All @@ -49,7 +49,7 @@ fn trait_object() {
let mut b = Weak::<u32>::new();
b = b.clone();
assert!(b.upgrade().is_none());
let mut b: Weak<Any> = b; // Unsizing
let mut b: Weak<dyn Any> = b; // Unsizing
b = b.clone();
assert!(b.upgrade().is_none());
}
16 changes: 10 additions & 6 deletions src/libcore/tests/any.rs
Expand Up @@ -17,7 +17,7 @@ static TEST: &'static str = "Test";

#[test]
fn any_referenced() {
let (a, b, c) = (&5 as &Any, &TEST as &Any, &Test as &Any);
let (a, b, c) = (&5 as &dyn Any, &TEST as &dyn Any, &Test as &dyn Any);

assert!(a.is::<i32>());
assert!(!b.is::<i32>());
Expand All @@ -34,7 +34,11 @@ fn any_referenced() {

#[test]
fn any_owning() {
let (a, b, c) = (box 5_usize as Box<Any>, box TEST as Box<Any>, box Test as Box<Any>);
let (a, b, c) = (
box 5_usize as Box<dyn Any>,
box TEST as Box<dyn Any>,
box Test as Box<dyn Any>,
);

assert!(a.is::<usize>());
assert!(!b.is::<usize>());
Expand All @@ -51,7 +55,7 @@ fn any_owning() {

#[test]
fn any_downcast_ref() {
let a = &5_usize as &Any;
let a = &5_usize as &dyn Any;

match a.downcast_ref::<usize>() {
Some(&5) => {}
Expand All @@ -69,9 +73,9 @@ fn any_downcast_mut() {
let mut a = 5_usize;
let mut b: Box<_> = box 7_usize;

let a_r = &mut a as &mut Any;
let a_r = &mut a as &mut dyn Any;
let tmp: &mut usize = &mut *b;
let b_r = tmp as &mut Any;
let b_r = tmp as &mut dyn Any;

match a_r.downcast_mut::<usize>() {
Some(x) => {
Expand Down Expand Up @@ -113,7 +117,7 @@ fn any_downcast_mut() {
#[test]
fn any_fixed_vec() {
let test = [0_usize; 8];
let test = &test as &Any;
let test = &test as &dyn Any;
assert!(test.is::<[usize; 8]>());
assert!(!test.is::<[usize; 10]>());
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/tests/hash/mod.rs
Expand Up @@ -128,7 +128,7 @@ fn test_custom_state() {
fn test_indirect_hasher() {
let mut hasher = MyHasher { hash: 0 };
{
let mut indirect_hasher: &mut Hasher = &mut hasher;
let mut indirect_hasher: &mut dyn Hasher = &mut hasher;
5u32.hash(&mut indirect_hasher);
}
assert_eq!(hasher.hash, 5);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/tests/intrinsics.rs
Expand Up @@ -22,7 +22,7 @@ fn test_typeid_sized_types() {
#[test]
fn test_typeid_unsized_types() {
trait Z {}
struct X(str); struct Y(Z + 'static);
struct X(str); struct Y(dyn Z + 'static);

assert_eq!(TypeId::of::<X>(), TypeId::of::<X>());
assert_eq!(TypeId::of::<Y>(), TypeId::of::<Y>());
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/tests/mem.rs
Expand Up @@ -109,11 +109,11 @@ fn test_transmute() {
trait Foo { fn dummy(&self) { } }
impl Foo for isize {}

let a = box 100isize as Box<Foo>;
let a = box 100isize as Box<dyn Foo>;
unsafe {
let x: ::core::raw::TraitObject = transmute(a);
assert!(*(x.data as *const isize) == 100);
let _x: Box<Foo> = transmute(x);
let _x: Box<dyn Foo> = transmute(x);
}

unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/tests/option.rs
Expand Up @@ -240,7 +240,7 @@ fn test_collect() {
assert!(v == None);

// test that it does not take more elements than it needs
let mut functions: [Box<Fn() -> Option<()>>; 3] =
let mut functions: [Box<dyn Fn() -> Option<()>>; 3] =
[box || Some(()), box || None, box || panic!()];

let v: Option<Vec<()>> = functions.iter_mut().map(|f| (*f)()).collect();
Expand Down
20 changes: 10 additions & 10 deletions src/libcore/tests/ptr.rs
Expand Up @@ -84,16 +84,16 @@ fn test_is_null() {
assert!(nms.is_null());

// Pointers to unsized types -- trait objects
let ci: *const ToString = &3;
let ci: *const dyn ToString = &3;
assert!(!ci.is_null());

let mi: *mut ToString = &mut 3;
let mi: *mut dyn ToString = &mut 3;
assert!(!mi.is_null());

let nci: *const ToString = null::<isize>();
let nci: *const dyn ToString = null::<isize>();
assert!(nci.is_null());

let nmi: *mut ToString = null_mut::<isize>();
let nmi: *mut dyn ToString = null_mut::<isize>();
assert!(nmi.is_null());
}

Expand Down Expand Up @@ -140,16 +140,16 @@ fn test_as_ref() {
assert_eq!(nms.as_ref(), None);

// Pointers to unsized types -- trait objects
let ci: *const ToString = &3;
let ci: *const dyn ToString = &3;
assert!(ci.as_ref().is_some());

let mi: *mut ToString = &mut 3;
let mi: *mut dyn ToString = &mut 3;
assert!(mi.as_ref().is_some());

let nci: *const ToString = null::<isize>();
let nci: *const dyn ToString = null::<isize>();
assert!(nci.as_ref().is_none());

let nmi: *mut ToString = null_mut::<isize>();
let nmi: *mut dyn ToString = null_mut::<isize>();
assert!(nmi.as_ref().is_none());
}
}
Expand Down Expand Up @@ -182,10 +182,10 @@ fn test_as_mut() {
assert_eq!(nms.as_mut(), None);

// Pointers to unsized types -- trait objects
let mi: *mut ToString = &mut 3;
let mi: *mut dyn ToString = &mut 3;
assert!(mi.as_mut().is_some());

let nmi: *mut ToString = null_mut::<isize>();
let nmi: *mut dyn ToString = null_mut::<isize>();
assert!(nmi.as_mut().is_none());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/tests/result.rs
Expand Up @@ -81,7 +81,7 @@ fn test_collect() {
assert!(v == Err(2));

// test that it does not take more elements than it needs
let mut functions: [Box<Fn() -> Result<(), isize>>; 3] =
let mut functions: [Box<dyn Fn() -> Result<(), isize>>; 3] =
[box || Ok(()), box || Err(1), box || panic!()];

let v: Result<Vec<()>, isize> = functions.iter_mut().map(|f| (*f)()).collect();
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Expand Up @@ -375,7 +375,7 @@ impl fmt::Debug for Item {

let fake = MAX_DEF_ID.with(|m| m.borrow().get(&self.def_id.krate)
.map(|id| self.def_id >= *id).unwrap_or(false));
let def_id: &fmt::Debug = if fake { &"**FAKE**" } else { &self.def_id };
let def_id: &dyn fmt::Debug = if fake { &"**FAKE**" } else { &self.def_id };

fmt.debug_struct("Item")
.field("source", &self.source)
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Expand Up @@ -55,7 +55,7 @@ pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a> {
/// The stack of module NodeIds up till this point
pub mod_ids: RefCell<Vec<NodeId>>,
pub crate_name: Option<String>,
pub cstore: Rc<CrateStore>,
pub cstore: Rc<dyn CrateStore>,
pub populated_all_crate_impls: Cell<bool>,
// Note that external items for which `doc(hidden)` applies to are shown as
// non-reachable while local items aren't. This is because we're reusing
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/highlight.rs
Expand Up @@ -395,7 +395,7 @@ impl Class {

fn write_header(class: Option<&str>,
id: Option<&str>,
out: &mut Write)
out: &mut dyn Write)
-> io::Result<()> {
write!(out, "<pre ")?;
if let Some(id) = id {
Expand All @@ -404,6 +404,6 @@ fn write_header(class: Option<&str>,
write!(out, "class=\"rust {}\">\n", class.unwrap_or(""))
}

fn write_footer(out: &mut Write) -> io::Result<()> {
fn write_footer(out: &mut dyn Write) -> io::Result<()> {
write!(out, "</pre>\n")
}
4 changes: 2 additions & 2 deletions src/librustdoc/html/layout.rs
Expand Up @@ -32,7 +32,7 @@ pub struct Page<'a> {
}

pub fn render<T: fmt::Display, S: fmt::Display>(
dst: &mut io::Write, layout: &Layout, page: &Page, sidebar: &S, t: &T,
dst: &mut dyn io::Write, layout: &Layout, page: &Page, sidebar: &S, t: &T,
css_file_extension: bool, themes: &[PathBuf])
-> io::Result<()>
{
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
)
}

pub fn redirect(dst: &mut io::Write, url: &str) -> io::Result<()> {
pub fn redirect(dst: &mut dyn io::Write, url: &str) -> io::Result<()> {
// <script> triggers a redirect before refresh, so this is fine.
write!(dst,
r##"<!DOCTYPE html>
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Expand Up @@ -1822,7 +1822,7 @@ impl Context {
}

fn render_item(&self,
writer: &mut io::Write,
writer: &mut dyn io::Write,
it: &clean::Item,
pushname: bool)
-> io::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/test.rs
Expand Up @@ -249,7 +249,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
}
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}
struct Bomb(Arc<Mutex<Vec<u8>>>, Box<Write+Send>);
struct Bomb(Arc<Mutex<Vec<u8>>>, Box<dyn Write+Send>);
impl Drop for Bomb {
fn drop(&mut self) {
let _ = self.1.write_all(&self.0.lock().unwrap());
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/redox/process.rs
Expand Up @@ -51,7 +51,7 @@ pub struct Command {
uid: Option<u32>,
gid: Option<u32>,
saw_nul: bool,
closures: Vec<Box<FnMut() -> io::Result<()> + Send + Sync>>,
closures: Vec<Box<dyn FnMut() -> io::Result<()> + Send + Sync>>,
stdin: Option<Stdio>,
stdout: Option<Stdio>,
stderr: Option<Stdio>,
Expand Down Expand Up @@ -122,7 +122,7 @@ impl Command {
}

pub fn before_exec(&mut self,
f: Box<FnMut() -> io::Result<()> + Send + Sync>) {
f: Box<dyn FnMut() -> io::Result<()> + Send + Sync>) {
self.closures.push(f);
}

Expand Down
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/header.rs
Expand Up @@ -416,7 +416,7 @@ impl TestProps {
}
}

fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
if testfile.is_dir() {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/tools/compiletest/src/read2.rs
Expand Up @@ -21,7 +21,7 @@ mod imp {
pub fn read2(
out_pipe: ChildStdout,
err_pipe: ChildStderr,
data: &mut FnMut(bool, &mut Vec<u8>, bool),
data: &mut dyn FnMut(bool, &mut Vec<u8>, bool),
) -> io::Result<()> {
let mut buffer = Vec::new();
out_pipe.read_to_end(&mut buffer)?;
Expand All @@ -45,7 +45,7 @@ mod imp {
pub fn read2(
mut out_pipe: ChildStdout,
mut err_pipe: ChildStderr,
data: &mut FnMut(bool, &mut Vec<u8>, bool),
data: &mut dyn FnMut(bool, &mut Vec<u8>, bool),
) -> io::Result<()> {
unsafe {
libc::fcntl(out_pipe.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK);
Expand Down Expand Up @@ -133,7 +133,7 @@ mod imp {
pub fn read2(
out_pipe: ChildStdout,
err_pipe: ChildStderr,
data: &mut FnMut(bool, &mut Vec<u8>, bool),
data: &mut dyn FnMut(bool, &mut Vec<u8>, bool),
) -> io::Result<()> {
let mut out = Vec::new();
let mut err = Vec::new();
Expand Down

0 comments on commit 66c4dc9

Please sign in to comment.