Add missing dyn

This commit is contained in:
Tatsuyuki Ishi 2018-07-13 14:25:22 +09:00
parent 8646a17143
commit 66c4dc9769
23 changed files with 69 additions and 65 deletions

View File

@ -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());
}
@ -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);
@ -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());
}

View File

@ -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();

View File

@ -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());
}

View File

@ -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());
}
@ -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);
@ -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());
}

View File

@ -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>());
@ -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>());
@ -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) => {}
@ -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) => {
@ -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]>());
}

View File

@ -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);

View File

@ -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>());

View File

@ -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 {

View File

@ -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();

View File

@ -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());
}
@ -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());
}
}
@ -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());
}
}

View File

@ -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();

View File

@ -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)

View File

@ -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

View File

@ -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 {
@ -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")
}

View File

@ -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<()>
{
@ -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>

View File

@ -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<()> {

View File

@ -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());

View File

@ -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>,
@ -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);
}

View File

@ -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;
}

View File

@ -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)?;
@ -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);
@ -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();

View File

@ -44,18 +44,18 @@ impl OutputFormat {
}
trait Formatter {
fn header(&self, output: &mut Write) -> Result<(), Box<Error>>;
fn title(&self, output: &mut Write) -> Result<(), Box<Error>>;
fn error_code_block(&self, output: &mut Write, info: &ErrorMetadata,
err_code: &str) -> Result<(), Box<Error>>;
fn footer(&self, output: &mut Write) -> Result<(), Box<Error>>;
fn header(&self, output: &mut dyn Write) -> Result<(), Box<dyn Error>>;
fn title(&self, output: &mut dyn Write) -> Result<(), Box<dyn Error>>;
fn error_code_block(&self, output: &mut dyn Write, info: &ErrorMetadata,
err_code: &str) -> Result<(), Box<dyn Error>>;
fn footer(&self, output: &mut dyn Write) -> Result<(), Box<dyn Error>>;
}
struct HTMLFormatter;
struct MarkdownFormatter;
impl Formatter for HTMLFormatter {
fn header(&self, output: &mut Write) -> Result<(), Box<Error>> {
fn header(&self, output: &mut dyn Write) -> Result<(), Box<dyn Error>> {
write!(output, r##"<!DOCTYPE html>
<html>
<head>
@ -75,13 +75,13 @@ impl Formatter for HTMLFormatter {
Ok(())
}
fn title(&self, output: &mut Write) -> Result<(), Box<Error>> {
fn title(&self, output: &mut dyn Write) -> Result<(), Box<dyn Error>> {
write!(output, "<h1>Rust Compiler Error Index</h1>\n")?;
Ok(())
}
fn error_code_block(&self, output: &mut Write, info: &ErrorMetadata,
err_code: &str) -> Result<(), Box<Error>> {
fn error_code_block(&self, output: &mut dyn Write, info: &ErrorMetadata,
err_code: &str) -> Result<(), Box<dyn Error>> {
// Enclose each error in a div so they can be shown/hidden en masse.
let desc_desc = match info.description {
Some(_) => "error-described",
@ -108,7 +108,7 @@ impl Formatter for HTMLFormatter {
Ok(())
}
fn footer(&self, output: &mut Write) -> Result<(), Box<Error>> {
fn footer(&self, output: &mut dyn Write) -> Result<(), Box<dyn Error>> {
write!(output, r##"<script>
function onEach(arr, func) {{
if (arr && arr.length > 0 && func) {{
@ -174,17 +174,17 @@ onEach(document.getElementsByClassName('rust-example-rendered'), function(e) {{
impl Formatter for MarkdownFormatter {
#[allow(unused_variables)]
fn header(&self, output: &mut Write) -> Result<(), Box<Error>> {
fn header(&self, output: &mut dyn Write) -> Result<(), Box<dyn Error>> {
Ok(())
}
fn title(&self, output: &mut Write) -> Result<(), Box<Error>> {
fn title(&self, output: &mut dyn Write) -> Result<(), Box<dyn Error>> {
write!(output, "# Rust Compiler Error Index\n")?;
Ok(())
}
fn error_code_block(&self, output: &mut Write, info: &ErrorMetadata,
err_code: &str) -> Result<(), Box<Error>> {
fn error_code_block(&self, output: &mut dyn Write, info: &ErrorMetadata,
err_code: &str) -> Result<(), Box<dyn Error>> {
Ok(match info.description {
Some(ref desc) => write!(output, "## {}\n{}\n", err_code, desc)?,
None => (),
@ -192,13 +192,13 @@ impl Formatter for MarkdownFormatter {
}
#[allow(unused_variables)]
fn footer(&self, output: &mut Write) -> Result<(), Box<Error>> {
fn footer(&self, output: &mut dyn Write) -> Result<(), Box<dyn Error>> {
Ok(())
}
}
/// Load all the metadata files from `metadata_dir` into an in-memory map.
fn load_all_errors(metadata_dir: &Path) -> Result<ErrorMetadataMap, Box<Error>> {
fn load_all_errors(metadata_dir: &Path) -> Result<ErrorMetadataMap, Box<dyn Error>> {
let mut all_errors = BTreeMap::new();
for entry in read_dir(metadata_dir)? {
@ -219,7 +219,7 @@ fn load_all_errors(metadata_dir: &Path) -> Result<ErrorMetadataMap, Box<Error>>
/// Output an HTML page for the errors in `err_map` to `output_path`.
fn render_error_page<T: Formatter>(err_map: &ErrorMetadataMap, output_path: &Path,
formatter: T) -> Result<(), Box<Error>> {
formatter: T) -> Result<(), Box<dyn Error>> {
let mut output_file = File::create(output_path)?;
formatter.header(&mut output_file)?;
@ -232,7 +232,7 @@ fn render_error_page<T: Formatter>(err_map: &ErrorMetadataMap, output_path: &Pat
formatter.footer(&mut output_file)
}
fn main_with_result(format: OutputFormat, dst: &Path) -> Result<(), Box<Error>> {
fn main_with_result(format: OutputFormat, dst: &Path) -> Result<(), Box<dyn Error>> {
let build_arch = env::var("CFG_BUILD")?;
let metadata_dir = get_metadata_dir(&build_arch);
let err_map = load_all_errors(&metadata_dir)?;

View File

@ -334,7 +334,7 @@ fn get_and_check_lib_features(base_src_path: &Path,
}
fn map_lib_features(base_src_path: &Path,
mf: &mut FnMut(Result<(&str, Feature), &str>, &Path, usize)) {
mf: &mut dyn FnMut(Result<(&str, Feature), &str>, &Path, usize)) {
let mut contents = String::new();
super::walk(base_src_path,
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),

View File

@ -82,13 +82,13 @@ fn filter_dirs(path: &Path) -> bool {
skip.iter().any(|p| path.ends_with(p))
}
fn walk_many(paths: &[&Path], skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) {
fn walk_many(paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
for path in paths {
walk(path, skip, f);
}
}
fn walk(path: &Path, skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) {
fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
for entry in t!(fs::read_dir(path), path) {
let entry = t!(entry);
let kind = t!(entry.file_type());