diff options
| author | bors <bors@rust-lang.org> | 2018-07-27 20:27:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-07-27 20:27:40 +0000 |
| commit | 4f1e2357447ef7e8066c49560d66c3e18f25d982 (patch) | |
| tree | 5f064512f997d836e71e05fed4d41f3e8ebd2ee7 | |
| parent | 43e6e2ef6abd28d564fc7a5c0e2b1b8b766adb53 (diff) | |
| parent | 62f73dc87c34a99360ba4aacdffe6c8bc320d763 (diff) | |
| download | rust-4f1e2357447ef7e8066c49560d66c3e18f25d982.tar.gz rust-4f1e2357447ef7e8066c49560d66c3e18f25d982.zip | |
Auto merge of #52336 - ishitatsuyuki:dyn-rollup, r=Mark-Simulacrum
Rollup of bare_trait_objects PRs All deny attributes were moved into bootstrap so they can be disabled with a line of config. Warnings for external tools are allowed and it's up to the tool's maintainer to keep it warnings free. r? @Mark-Simulacrum cc @ljedrz @kennytm
112 files changed, 315 insertions, 345 deletions
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index f2b2f6f1eeb..7192cae8956 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -296,8 +296,10 @@ fn main() { cmd.arg("--color=always"); } - if env::var_os("RUSTC_DENY_WARNINGS").is_some() { + if env::var_os("RUSTC_DENY_WARNINGS").is_some() && env::var_os("RUSTC_EXTERNAL_TOOL").is_none() + { cmd.arg("-Dwarnings"); + cmd.arg("-Dbare_trait_objects"); } if verbose > 1 { diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index 39c5c832831..8838cdeed86 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -12,7 +12,7 @@ use compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, rustc_cargo_env, add_to_sysroot}; use builder::{RunConfig, Builder, ShouldRun, Step}; -use tool::{self, prepare_tool_cargo}; +use tool::{self, prepare_tool_cargo, SourceType}; use {Compiler, Mode}; use cache::{INTERNER, Interned}; use std::path::PathBuf; @@ -222,7 +222,8 @@ impl Step for Rustdoc { Mode::ToolRustc, target, "check", - "src/tools/rustdoc"); + "src/tools/rustdoc", + SourceType::InTree); let _folder = builder.fold_output(|| format!("stage{}-rustdoc", compiler.stage)); println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target); diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index f71cb119b77..fd3730ffc78 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -28,7 +28,7 @@ use build_helper::up_to_date; use util::symlink_dir; use builder::{Builder, Compiler, RunConfig, ShouldRun, Step}; -use tool::{self, prepare_tool_cargo, Tool}; +use tool::{self, prepare_tool_cargo, Tool, SourceType}; use compile; use cache::{INTERNER, Interned}; use config::Config; @@ -814,6 +814,7 @@ impl Step for Rustdoc { target, "doc", "src/tools/rustdoc", + SourceType::InTree, ); cargo.env("RUSTDOCFLAGS", "--document-private-items"); diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 639c96bc208..7c69197885c 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -30,7 +30,7 @@ use compile; use dist; use flags::Subcommand; use native; -use tool::{self, Tool}; +use tool::{self, Tool, SourceType}; use toolstate::ToolState; use util::{self, dylib_path, dylib_path_var}; use Crate as CargoCrate; @@ -222,17 +222,18 @@ impl Step for Cargo { compiler, target: self.host, }); - let mut cargo = builder.cargo(compiler, Mode::ToolRustc, self.host, "test"); - cargo - .arg("--manifest-path") - .arg(builder.src.join("src/tools/cargo/Cargo.toml")); + let mut cargo = tool::prepare_tool_cargo(builder, + compiler, + Mode::ToolRustc, + self.host, + "test", + "src/tools/cargo", + SourceType::Submodule); + if !builder.fail_fast { cargo.arg("--no-fail-fast"); } - // Don't build tests dynamically, just a pain to work with - cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); - // Don't run cross-compile tests, we may not have cross-compiled libstd libs // available. cargo.env("CFG_DISABLE_CROSS_TESTS", "1"); @@ -286,10 +287,8 @@ impl Step for Rls { Mode::ToolRustc, host, "test", - "src/tools/rls"); - - // Don't build tests dynamically, just a pain to work with - cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); + "src/tools/rls", + SourceType::Submodule); builder.add_rustc_lib_path(compiler, &mut cargo); @@ -341,10 +340,9 @@ impl Step for Rustfmt { Mode::ToolRustc, host, "test", - "src/tools/rustfmt"); + "src/tools/rustfmt", + SourceType::Submodule); - // Don't build tests dynamically, just a pain to work with - cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); let dir = testdir(builder, compiler.host); t!(fs::create_dir_all(&dir)); cargo.env("RUSTFMT_TEST_DIR", dir); @@ -392,13 +390,14 @@ impl Step for Miri { extra_features: Vec::new(), }); if let Some(miri) = miri { - let mut cargo = builder.cargo(compiler, Mode::ToolRustc, host, "test"); - cargo - .arg("--manifest-path") - .arg(builder.src.join("src/tools/miri/Cargo.toml")); + let mut cargo = tool::prepare_tool_cargo(builder, + compiler, + Mode::ToolRustc, + host, + "test", + "src/tools/miri", + SourceType::Submodule); - // Don't build tests dynamically, just a pain to work with - cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); // miri tests need to know about the stage sysroot cargo.env("MIRI_SYSROOT", builder.sysroot(compiler)); cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler)); @@ -450,13 +449,14 @@ impl Step for Clippy { extra_features: Vec::new(), }); if let Some(clippy) = clippy { - let mut cargo = builder.cargo(compiler, Mode::ToolRustc, host, "test"); - cargo - .arg("--manifest-path") - .arg(builder.src.join("src/tools/clippy/Cargo.toml")); + let mut cargo = tool::prepare_tool_cargo(builder, + compiler, + Mode::ToolRustc, + host, + "test", + "src/tools/clippy", + SourceType::Submodule); - // Don't build tests dynamically, just a pain to work with - cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); // clippy tests need to know about the stage sysroot cargo.env("SYSROOT", builder.sysroot(compiler)); cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler)); @@ -1739,7 +1739,8 @@ impl Step for CrateRustdoc { Mode::ToolRustc, target, test_kind.subcommand(), - "src/tools/rustdoc"); + "src/tools/rustdoc", + SourceType::InTree); if test_kind.subcommand() == "test" && !builder.fail_fast { cargo.arg("--no-fail-fast"); } diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 0969e5abe07..5e68b797b3d 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -76,13 +76,20 @@ impl Step for CleanTools { } #[derive(Debug, Clone, Hash, PartialEq, Eq)] +pub enum SourceType { + InTree, + Submodule, +} + +#[derive(Debug, Clone, Hash, PartialEq, Eq)] struct ToolBuild { compiler: Compiler, target: Interned<String>, tool: &'static str, path: &'static str, mode: Mode, - is_ext_tool: bool, + is_optional_tool: bool, + source_type: SourceType, extra_features: Vec<String>, } @@ -102,7 +109,7 @@ impl Step for ToolBuild { let target = self.target; let tool = self.tool; let path = self.path; - let is_ext_tool = self.is_ext_tool; + let is_optional_tool = self.is_optional_tool; match self.mode { Mode::ToolRustc => { @@ -115,7 +122,15 @@ impl Step for ToolBuild { _ => panic!("unexpected Mode for tool build") } - let mut cargo = prepare_tool_cargo(builder, compiler, self.mode, target, "build", path); + let mut cargo = prepare_tool_cargo( + builder, + compiler, + self.mode, + target, + "build", + path, + self.source_type, + ); cargo.arg("--features").arg(self.extra_features.join(" ")); let _folder = builder.fold_output(|| format!("stage{}-{}", compiler.stage, tool)); @@ -216,7 +231,7 @@ impl Step for ToolBuild { }); if !is_expected { - if !is_ext_tool { + if !is_optional_tool { exit(1); } else { return None; @@ -238,6 +253,7 @@ pub fn prepare_tool_cargo( target: Interned<String>, command: &'static str, path: &'static str, + source_type: SourceType, ) -> Command { let mut cargo = builder.cargo(compiler, mode, target, command); let dir = builder.src.join(path); @@ -247,6 +263,10 @@ pub fn prepare_tool_cargo( // stages and such and it's just easier if they're not dynamically linked. cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); + if source_type == SourceType::Submodule { + cargo.env("RUSTC_EXTERNAL_TOOL", "1"); + } + if let Some(dir) = builder.openssl_install_dir(target) { cargo.env("OPENSSL_STATIC", "1"); cargo.env("OPENSSL_DIR", dir); @@ -274,7 +294,8 @@ pub fn prepare_tool_cargo( } macro_rules! tool { - ($($name:ident, $path:expr, $tool_name:expr, $mode:expr $(,llvm_tools = $llvm:expr)*;)+) => { + ($($name:ident, $path:expr, $tool_name:expr, $mode:expr + $(,llvm_tools = $llvm:expr)* $(,is_external_tool = $external:expr)*;)+) => { #[derive(Copy, PartialEq, Eq, Clone)] pub enum Tool { $( @@ -351,7 +372,12 @@ macro_rules! tool { tool: $tool_name, mode: $mode, path: $path, - is_ext_tool: false, + is_optional_tool: false, + source_type: if false $(|| $external)* { + SourceType::Submodule + } else { + SourceType::InTree + }, extra_features: Vec::new(), }).expect("expected to build -- essential tool") } @@ -370,7 +396,8 @@ tool!( Compiletest, "src/tools/compiletest", "compiletest", Mode::ToolBootstrap, llvm_tools = true; BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::ToolBootstrap; RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::ToolBootstrap; - RustInstaller, "src/tools/rust-installer", "fabricate", Mode::ToolBootstrap; + RustInstaller, "src/tools/rust-installer", "fabricate", Mode::ToolBootstrap, + is_external_tool = true; RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes", Mode::ToolBootstrap; ); @@ -401,7 +428,8 @@ impl Step for RemoteTestServer { tool: "remote-test-server", mode: Mode::ToolStd, path: "src/tools/remote-test-server", - is_ext_tool: false, + is_optional_tool: false, + source_type: SourceType::InTree, extra_features: Vec::new(), }).expect("expected to build -- essential tool") } @@ -449,12 +477,15 @@ impl Step for Rustdoc { target: builder.config.build, }); - let mut cargo = prepare_tool_cargo(builder, - build_compiler, - Mode::ToolRustc, - target, - "build", - "src/tools/rustdoc"); + let mut cargo = prepare_tool_cargo( + builder, + build_compiler, + Mode::ToolRustc, + target, + "build", + "src/tools/rustdoc", + SourceType::InTree, + ); // Most tools don't get debuginfo, but rustdoc should. cargo.env("RUSTC_DEBUGINFO", builder.config.rust_debuginfo.to_string()) @@ -525,7 +556,8 @@ impl Step for Cargo { tool: "cargo", mode: Mode::ToolRustc, path: "src/tools/cargo", - is_ext_tool: false, + is_optional_tool: false, + source_type: SourceType::Submodule, extra_features: Vec::new(), }).expect("expected to build -- essential tool") } @@ -574,7 +606,8 @@ macro_rules! tool_extended { mode: Mode::ToolRustc, path: $path, extra_features: $sel.extra_features, - is_ext_tool: true, + is_optional_tool: true, + source_type: SourceType::Submodule, }) } } diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index 00e5dee256e..1cbb8e49bfa 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] - use std::fs::File; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 63cf01a0fac..ef619527e06 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -72,7 +72,6 @@ test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))] #![no_std] #![needs_allocator] -#![deny(bare_trait_objects)] #![deny(missing_debug_implementations)] #![cfg_attr(test, allow(deprecated))] // rand diff --git a/src/liballoc/tests/arc.rs b/src/liballoc/tests/arc.rs index 753873dd294..d90c22a3b18 100644 --- a/src/liballoc/tests/arc.rs +++ b/src/liballoc/tests/arc.rs @@ -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()); } diff --git a/src/liballoc/tests/btree/set.rs b/src/liballoc/tests/btree/set.rs index 6171b8ba624..0330bda5e32 100644 --- a/src/liballoc/tests/btree/set.rs +++ b/src/liballoc/tests/btree/set.rs @@ -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(); diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index 2c361598e89..91bc778ad4c 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -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()); } diff --git a/src/liballoc/tests/rc.rs b/src/liballoc/tests/rc.rs index baa0406acfc..9ec7c831444 100644 --- a/src/liballoc/tests/rc.rs +++ b/src/liballoc/tests/rc.rs @@ -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()); } diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs index 413b212281b..b3b20715511 100644 --- a/src/liballoc_jemalloc/lib.rs +++ b/src/liballoc_jemalloc/lib.rs @@ -10,7 +10,6 @@ #![no_std] #![allow(unused_attributes)] -#![deny(bare_trait_objects)] #![unstable(feature = "alloc_jemalloc", reason = "implementation detail of std, does not provide any public API", issue = "0")] diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index c6c0abefbab..64348e05de7 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -10,7 +10,6 @@ #![no_std] #![allow(unused_attributes)] -#![deny(bare_trait_objects)] #![unstable(feature = "alloc_system", reason = "this library is unlikely to be stabilized in its current \ form or name", diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 6f692923c85..0f4a5d16e17 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -30,7 +30,6 @@ #![cfg_attr(test, feature(test))] #![allow(deprecated)] -#![deny(bare_trait_objects)] extern crate alloc; extern crate rustc_data_structures; diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 94f23db1ccc..6b26093439e 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -120,7 +120,7 @@ impl<T: 'static + ?Sized > Any for T { /////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for Any { +impl fmt::Debug for dyn Any { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.pad("Any") } @@ -130,20 +130,20 @@ impl fmt::Debug for Any { // hence used with `unwrap`. May eventually no longer be needed if // dispatch works with upcasting. #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for Any + Send { +impl fmt::Debug for dyn Any + Send { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.pad("Any") } } #[stable(feature = "any_send_sync_methods", since = "1.28.0")] -impl fmt::Debug for Any + Send + Sync { +impl fmt::Debug for dyn Any + Send + Sync { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.pad("Any") } } -impl Any { +impl dyn Any { /// Returns `true` if the boxed type is the same as `T`. /// /// # Examples @@ -203,7 +203,7 @@ impl Any { pub fn downcast_ref<T: Any>(&self) -> Option<&T> { if self.is::<T>() { unsafe { - Some(&*(self as *const Any as *const T)) + Some(&*(self as *const dyn Any as *const T)) } } else { None @@ -240,7 +240,7 @@ impl Any { pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> { if self.is::<T>() { unsafe { - Some(&mut *(self as *mut Any as *mut T)) + Some(&mut *(self as *mut dyn Any as *mut T)) } } else { None @@ -248,7 +248,7 @@ impl Any { } } -impl Any+Send { +impl dyn Any+Send { /// Forwards to the method defined on the type `Any`. /// /// # Examples @@ -332,7 +332,7 @@ impl Any+Send { } } -impl Any+Send+Sync { +impl dyn Any+Send+Sync { /// Forwards to the method defined on the type `Any`. /// /// # Examples diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index b6087628ea6..137e9fe2c15 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -1532,7 +1532,7 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {} #[allow(unused)] fn assert_coerce_unsized(a: UnsafeCell<&i32>, b: Cell<&i32>, c: RefCell<&i32>) { - let _: UnsafeCell<&Send> = a; - let _: Cell<&Send> = b; - let _: RefCell<&Send> = c; + let _: UnsafeCell<&dyn Send> = a; + let _: Cell<&dyn Send> = b; + let _: RefCell<&dyn Send> = c; } diff --git a/src/libcore/fmt/builders.rs b/src/libcore/fmt/builders.rs index e8ea2e743da..3c5f934d4d8 100644 --- a/src/libcore/fmt/builders.rs +++ b/src/libcore/fmt/builders.rs @@ -11,7 +11,7 @@ use fmt; struct PadAdapter<'a> { - buf: &'a mut (fmt::Write + 'a), + buf: &'a mut (dyn fmt::Write + 'a), on_newline: bool, } @@ -107,7 +107,7 @@ pub fn debug_struct_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>, impl<'a, 'b: 'a> DebugStruct<'a, 'b> { /// Adds a new field to the generated struct output. #[stable(feature = "debug_builders", since = "1.2.0")] - pub fn field(&mut self, name: &str, value: &fmt::Debug) -> &mut DebugStruct<'a, 'b> { + pub fn field(&mut self, name: &str, value: &dyn fmt::Debug) -> &mut DebugStruct<'a, 'b> { self.result = self.result.and_then(|_| { let prefix = if self.has_fields { "," @@ -204,7 +204,7 @@ pub fn debug_tuple_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>, name: &str) -> D impl<'a, 'b: 'a> DebugTuple<'a, 'b> { /// Adds a new field to the generated tuple struct output. #[stable(feature = "debug_builders", since = "1.2.0")] - pub fn field(&mut self, value: &fmt::Debug) -> &mut DebugTuple<'a, 'b> { + pub fn field(&mut self, value: &dyn fmt::Debug) -> &mut DebugTuple<'a, 'b> { self.result = self.result.and_then(|_| { let (prefix, space) = if self.fields > 0 { (",", " ") @@ -258,7 +258,7 @@ struct DebugInner<'a, 'b: 'a> { } impl<'a, 'b: 'a> DebugInner<'a, 'b> { - fn entry(&mut self, entry: &fmt::Debug) { + fn entry(&mut self, entry: &dyn fmt::Debug) { self.result = self.result.and_then(|_| { if self.is_pretty() { let mut slot = None; @@ -340,7 +340,7 @@ pub fn debug_set_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugSet<'a, 'b impl<'a, 'b: 'a> DebugSet<'a, 'b> { /// Adds a new entry to the set output. #[stable(feature = "debug_builders", since = "1.2.0")] - pub fn entry(&mut self, entry: &fmt::Debug) -> &mut DebugSet<'a, 'b> { + pub fn entry(&mut self, entry: &dyn fmt::Debug) -> &mut DebugSet<'a, 'b> { self.inner.entry(entry); self } @@ -411,7 +411,7 @@ pub fn debug_list_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugList<'a, impl<'a, 'b: 'a> DebugList<'a, 'b> { /// Adds a new entry to the list output. #[stable(feature = "debug_builders", since = "1.2.0")] - pub fn entry(&mut self, entry: &fmt::Debug) -> &mut DebugList<'a, 'b> { + pub fn entry(&mut self, entry: &dyn fmt::Debug) -> &mut DebugList<'a, 'b> { self.inner.entry(entry); self } @@ -482,7 +482,7 @@ pub fn debug_map_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugMap<'a, 'b impl<'a, 'b: 'a> DebugMap<'a, 'b> { /// Adds a new entry to the map output. #[stable(feature = "debug_builders", since = "1.2.0")] - pub fn entry(&mut self, key: &fmt::Debug, value: &fmt::Debug) -> &mut DebugMap<'a, 'b> { + pub fn entry(&mut self, key: &dyn fmt::Debug, value: &dyn fmt::Debug) -> &mut DebugMap<'a, 'b> { self.result = self.result.and_then(|_| { if self.is_pretty() { let mut slot = None; diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index d91bf463383..928f95e3ba2 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -255,7 +255,7 @@ pub struct Formatter<'a> { width: Option<usize>, precision: Option<usize>, - buf: &'a mut (Write+'a), + buf: &'a mut (dyn Write+'a), curarg: slice::Iter<'a, ArgumentV1<'a>>, args: &'a [ArgumentV1<'a>], } @@ -272,7 +272,7 @@ struct Void { /// /// It was added after #45197 showed that one could share a `!Sync` /// object across threads by passing it into `format_args!`. - _oibit_remover: PhantomData<*mut Fn()>, + _oibit_remover: PhantomData<*mut dyn Fn()>, } /// This struct represents the generic "argument" which is taken by the Xprintf @@ -1020,7 +1020,7 @@ pub trait UpperExp { /// /// [`write!`]: ../../std/macro.write.html #[stable(feature = "rust1", since = "1.0.0")] -pub fn write(output: &mut Write, args: Arguments) -> Result { +pub fn write(output: &mut dyn Write, args: Arguments) -> Result { let mut formatter = Formatter { flags: 0, width: None, @@ -1062,7 +1062,7 @@ pub fn write(output: &mut Write, args: Arguments) -> Result { impl<'a> Formatter<'a> { fn wrap_buf<'b, 'c, F>(&'b mut self, wrap: F) -> Formatter<'c> - where 'b: 'c, F: FnOnce(&'b mut (Write+'b)) -> &'c mut (Write+'c) + where 'b: 'c, F: FnOnce(&'b mut (dyn Write+'b)) -> &'c mut (dyn Write+'c) { Formatter { // We want to change this @@ -1342,7 +1342,7 @@ impl<'a> Formatter<'a> { } fn write_formatted_parts(&mut self, formatted: &flt2dec::Formatted) -> Result { - fn write_bytes(buf: &mut Write, s: &[u8]) -> Result { + fn write_bytes(buf: &mut dyn Write, s: &[u8]) -> Result { buf.write_str(unsafe { str::from_utf8_unchecked(s) }) } diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index afc273d265b..48c6eb94144 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -18,7 +18,7 @@ use super::{Inspect, Map, Peekable, Scan, Skip, SkipWhile, StepBy, Take, TakeWhi use super::{Zip, Sum, Product}; use super::{ChainState, FromIterator, ZipImpl}; -fn _assert_is_object_safe(_: &Iterator<Item=()>) {} +fn _assert_is_object_safe(_: &dyn Iterator<Item=()>) {} /// An interface for dealing with iterators. /// diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs index 10f02ca2fdc..17cac5aa0a0 100644 --- a/src/libcore/panic.rs +++ b/src/libcore/panic.rs @@ -43,7 +43,7 @@ use fmt; #[stable(feature = "panic_hooks", since = "1.10.0")] #[derive(Debug)] pub struct PanicInfo<'a> { - payload: &'a (Any + Send), + payload: &'a (dyn Any + Send), message: Option<&'a fmt::Arguments<'a>>, location: Location<'a>, } @@ -64,7 +64,7 @@ impl<'a> PanicInfo<'a> { #[doc(hidden)] #[inline] - pub fn set_payload(&mut self, info: &'a (Any + Send)) { + pub fn set_payload(&mut self, info: &'a (dyn Any + Send)) { self.payload = info; } @@ -86,7 +86,7 @@ impl<'a> PanicInfo<'a> { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] - pub fn payload(&self) -> &(Any + Send) { + pub fn payload(&self) -> &(dyn Any + Send) { self.payload } @@ -270,6 +270,6 @@ impl<'a> fmt::Display for Location<'a> { #[unstable(feature = "std_internals", issue = "0")] #[doc(hidden)] pub unsafe trait BoxMeUp { - fn box_me_up(&mut self) -> *mut (Any + Send); - fn get(&mut self) -> &(Any + Send); + fn box_me_up(&mut self) -> *mut (dyn Any + Send); + fn get(&mut self) -> &(dyn Any + Send); } diff --git a/src/libcore/task/context.rs b/src/libcore/task/context.rs index c69d45248a5..1fc975cb178 100644 --- a/src/libcore/task/context.rs +++ b/src/libcore/task/context.rs @@ -21,7 +21,7 @@ use super::{Executor, Waker, LocalWaker}; /// when performing a single `poll` step on a task. pub struct Context<'a> { local_waker: &'a LocalWaker, - executor: &'a mut Executor, + executor: &'a mut dyn Executor, } impl<'a> fmt::Debug for Context<'a> { @@ -34,7 +34,7 @@ impl<'a> fmt::Debug for Context<'a> { impl<'a> Context<'a> { /// Create a new task `Context` with the provided `local_waker`, `waker`, and `executor`. #[inline] - pub fn new(local_waker: &'a LocalWaker, executor: &'a mut Executor) -> Context<'a> { + pub fn new(local_waker: &'a LocalWaker, executor: &'a mut dyn Executor) -> Context<'a> { Context { local_waker, executor, @@ -58,7 +58,7 @@ impl<'a> Context<'a> { /// This method is useful primarily if you want to explicitly handle /// spawn failures. #[inline] - pub fn executor(&mut self) -> &mut Executor { + pub fn executor(&mut self) -> &mut dyn Executor { self.executor } diff --git a/src/libcore/task/wake.rs b/src/libcore/task/wake.rs index 3b901c9aef0..321b432d3f4 100644 --- a/src/libcore/task/wake.rs +++ b/src/libcore/task/wake.rs @@ -23,7 +23,7 @@ use ptr::NonNull; /// trait, allowing notifications to get routed through it. #[repr(transparent)] pub struct Waker { - inner: NonNull<UnsafeWake>, + inner: NonNull<dyn UnsafeWake>, } impl Unpin for Waker {} @@ -41,7 +41,7 @@ impl Waker { /// use the `Waker::from` function instead which works with the safe /// `Arc` type and the safe `Wake` trait. #[inline] - pub unsafe fn new(inner: NonNull<UnsafeWake>) -> Self { + pub unsafe fn new(inner: NonNull<dyn UnsafeWake>) -> Self { Waker { inner: inner } } @@ -98,7 +98,7 @@ impl Drop for Waker { /// behavior. #[repr(transparent)] pub struct LocalWaker { - inner: NonNull<UnsafeWake>, + inner: NonNull<dyn UnsafeWake>, } impl Unpin for LocalWaker {} @@ -119,7 +119,7 @@ impl LocalWaker { /// For this function to be used safely, it must be sound to call `inner.wake_local()` /// on the current thread. #[inline] - pub unsafe fn new(inner: NonNull<UnsafeWake>) -> Self { + pub unsafe fn new(inner: NonNull<dyn UnsafeWake>) -> Self { LocalWaker { inner: inner } } diff --git a/src/libcore/tests/any.rs b/src/libcore/tests/any.rs index 2d3e81aa131..a80bf939530 100644 --- a/src/libcore/tests/any.rs +++ b/src/libcore/tests/any.rs @@ -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]>()); } diff --git a/src/libcore/tests/hash/mod.rs b/src/libcore/tests/hash/mod.rs index 8716421b424..85c9d41b65b 100644 --- a/src/libcore/tests/hash/mod.rs +++ b/src/libcore/tests/hash/mod.rs @@ -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); diff --git a/src/libcore/tests/intrinsics.rs b/src/libcore/tests/intrinsics.rs index 2b380abf63c..9f3cba26a62 100644 --- a/src/libcore/tests/intrinsics.rs +++ b/src/libcore/tests/intrinsics.rs @@ -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>()); diff --git a/src/libcore/tests/mem.rs b/src/libcore/tests/mem.rs index f55a1c81463..714f2babbdf 100644 --- a/src/libcore/tests/mem.rs +++ b/src/libcore/tests/mem.rs @@ -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 { diff --git a/src/libcore/tests/option.rs b/src/libcore/tests/option.rs index bc3e61a4f54..324ebf43565 100644 --- a/src/libcore/tests/option.rs +++ b/src/libcore/tests/option.rs @@ -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(); diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index 31bc1d67768..92160910d8f 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -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()); } } diff --git a/src/libcore/tests/result.rs b/src/libcore/tests/result.rs index d9927ce4487..0616252c82c 100644 --- a/src/libcore/tests/result.rs +++ b/src/libcore/tests/result.rs @@ -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(); diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 30a3bbdc58e..3aa09a91e07 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -14,8 +14,6 @@ //! Parsing does not happen at runtime: structures of `std::fmt::rt` are //! generated instead. -#![deny(bare_trait_objects)] - # -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", diff --git a/src/libpanic_abort/lib.rs b/src/libpanic_abort/lib.rs index 02ab28507d7..392bf17968f 100644 --- a/src/libpanic_abort/lib.rs +++ b/src/libpanic_abort/lib.rs @@ -21,7 +21,6 @@ issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")] #![panic_runtime] #![allow(unused_features)] -#![deny(bare_trait_objects)] #![feature(core_intrinsics)] #![feature(libc)] diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs index f8cd29fc086..5c320bb369e 100644 --- a/src/libpanic_unwind/lib.rs +++ b/src/libpanic_unwind/lib.rs @@ -22,7 +22,6 @@ //! More documentation about each implementation can be found in the respective //! module. -#![deny(bare_trait_objects)] #![no_std] #![unstable(feature = "panic_unwind", issue = "32837")] # for more. #![stable(feature = "proc_macro_lib", since = "1.15.0")] -#![deny(bare_trait_objects)] #![deny(missing_docs)] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", diff --git a/src/libprofiler_builtins/lib.rs b/src/libprofiler_builtins/lib.rs index 3d91505cd77..6d0d6d115b7 100644 --- a/src/libprofiler_builtins/lib.rs +++ b/src/libprofiler_builtins/lib.rs @@ -15,5 +15,4 @@ reason = "internal implementation detail of rustc right now", issue = "0")] #![allow(unused_features)] -#![deny(bare_trait_objects)] #![feature(staged_api)] diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index d709a4debd1..b6cb336648b 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -36,8 +36,6 @@ //! //! This API is completely unstable and subject to change. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_allocator/lib.rs b/src/librustc_allocator/lib.rs index 1227936ce96..b217d3665a2 100644 --- a/src/librustc_allocator/lib.rs +++ b/src/librustc_allocator/lib.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] #![feature(rustc_private)] #[macro_use] extern crate log; diff --git a/src/librustc_apfloat/lib.rs b/src/librustc_apfloat/lib.rs index c7cd958016d..08438805a70 100644 --- a/src/librustc_apfloat/lib.rs +++ b/src/librustc_apfloat/lib.rs @@ -40,8 +40,6 @@ //! //! This API is completely unstable and subject to change. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_asan/lib.rs b/src/librustc_asan/lib.rs index 7bd1e98f85d..0c78fd74a23 100644 --- a/src/librustc_asan/lib.rs +++ b/src/librustc_asan/lib.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] - #![sanitizer_runtime] #![feature(alloc_system)] #![feature(sanitizer_runtime)] diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index d583a32c431..a5a20af0e4e 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -13,7 +13,6 @@ html_root_url = "https://doc.rust-lang.org/nightly/")] #![allow(non_camel_case_types)] -#![deny(bare_trait_objects)] #![feature(from_ref)] #![feature(quote)] diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 8aa7902021f..90f96c9687b 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -23,7 +23,6 @@ #![feature(custom_attribute)] #![feature(fs_read_write)] #![allow(unused_attributes)] -#![deny(bare_trait_objects)] #![feature(libc)] #![feature(quote)] #![feature(range_contains)] diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index e9031007a4e..f59cf5832fc 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -20,7 +20,6 @@ #![feature(box_syntax)] #![feature(custom_attribute)] #![allow(unused_attributes)] -#![deny(bare_trait_objects)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index ef0d57c7b7c..a9e582e510e 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -16,8 +16,6 @@ //! //! This API is completely unstable and subject to change. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://www.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 000025c49a6..9e818641dec 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -14,8 +14,6 @@ //! //! This API is completely unstable and subject to change. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index c0f07645f49..67d2aa4d770 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_incremental/lib.rs b/src/librustc_incremental/lib.rs index 2ef88041d33..3839c133a6e 100644 --- a/src/librustc_incremental/lib.rs +++ b/src/librustc_incremental/lib.rs @@ -10,8 +10,6 @@ //! Support for serializing the dep-graph and reloading it. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 798c289ac2f..78a8c494f48 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -19,8 +19,6 @@ //! //! This API is completely unstable and subject to change. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index c60016cde0d..741758cb954 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -12,7 +12,6 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] #![allow(dead_code)] -#![deny(bare_trait_objects)] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", diff --git a/src/librustc_lsan/lib.rs b/src/librustc_lsan/lib.rs index 7bd1e98f85d..0c78fd74a23 100644 --- a/src/librustc_lsan/lib.rs +++ b/src/librustc_lsan/lib.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] - #![sanitizer_runtime] #![feature(alloc_system)] #![feature(sanitizer_runtime)] diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index d535c1ef903..5cba0387d17 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 382248c2d15..54730ecd75f 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -14,8 +14,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! */ -#![deny(bare_trait_objects)] - #![feature(slice_patterns)] #![feature(slice_sort_by_cached_key)] #![feature(from_ref)] diff --git a/src/librustc_msan/lib.rs b/src/librustc_msan/lib.rs index 7bd1e98f85d..0c78fd74a23 100644 --- a/src/librustc_msan/lib.rs +++ b/src/librustc_msan/lib.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] - #![sanitizer_runtime] #![feature(alloc_system)] #![feature(sanitizer_runtime)] diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index 15d7c0fdaa3..41f1e782965 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -14,8 +14,6 @@ //! //! This API is completely unstable and subject to change. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_platform_intrinsics/lib.rs b/src/librustc_platform_intrinsics/lib.rs index 92e83fd70fa..b57debdd994 100644 --- a/src/librustc_platform_intrinsics/lib.rs +++ b/src/librustc_platform_intrinsics/lib.rs @@ -9,7 +9,6 @@ // except according to those terms. #![allow(bad_style)] -#![deny(bare_trait_objects)] pub struct Intrinsic { pub inputs: &'static [&'static Type], diff --git a/src/librustc_plugin/lib.rs b/src/librustc_plugin/lib.rs index b2c492f204f..348aa6a7cef 100644 --- a/src/librustc_plugin/lib.rs +++ b/src/librustc_plugin/lib.rs @@ -60,8 +60,6 @@ //! See the [`plugin` feature](../unstable-book/language-features/plugin.html) of //! the Unstable Book for more examples. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 7b13c98b31d..405952065da 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 765016fdc4a..8130c4e8326 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index c84f194f023..a250d4a3598 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -13,7 +13,6 @@ html_root_url = "https://doc.rust-lang.org/nightly/")] #![feature(custom_attribute)] #![allow(unused_attributes)] -#![deny(bare_trait_objects)] #![recursion_limit="256"] diff --git a/src/librustc_target/lib.rs b/src/librustc_target/lib.rs index e611d26da56..8f491157439 100644 --- a/src/librustc_target/lib.rs +++ b/src/librustc_target/lib.rs @@ -21,8 +21,6 @@ //! one that doesn't; the one that doesn't might get decent parallel //! build speedups. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_traits/lib.rs b/src/librustc_traits/lib.rs index 2a4cacb5623..d17cf35f181 100644 --- a/src/librustc_traits/lib.rs +++ b/src/librustc_traits/lib.rs @@ -11,8 +11,6 @@ //! New recursive solver modeled on Chalk's recursive solver. Most of //! the guts are broken up into modules; see the comments in those modules. -#![deny(bare_trait_objects)] - #![feature(crate_in_paths)] #![feature(crate_visibility_modifier)] #![feature(extern_prelude)] diff --git a/src/librustc_tsan/lib.rs b/src/librustc_tsan/lib.rs index 7bd1e98f85d..0c78fd74a23 100644 --- a/src/librustc_tsan/lib.rs +++ b/src/librustc_tsan/lib.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] - #![sanitizer_runtime] #![feature(alloc_system)] #![feature(sanitizer_runtime)] diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index e343fb1a57b..6bf1ec8f697 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -70,7 +70,6 @@ This API is completely unstable and subject to change. html_root_url = "https://doc.rust-lang.org/nightly/")] #![allow(non_camel_case_types)] -#![deny(bare_trait_objects)] #![feature(box_patterns)] #![feature(box_syntax)] diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 98684b27973..c601f138d0a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 6e1b4589547..4b8dbaf4211 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -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 diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 5939d5341e3..6cf9b143373 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -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") } diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 5e93b20ea17..af7c0a04215 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -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> diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ade33c8dd7d..f137f4acf44 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -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<()> { diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index eb980a7369b..2966b9e9819 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -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()); diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 7c1bb69434d..a5f4b32b329 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -14,8 +14,6 @@ Core encoding and decoding interfaces. */ -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 1958915602f..29534696abc 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -138,7 +138,7 @@ pub trait Error: Debug + Display { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - fn cause(&self) -> Option<&Error> { None } + fn cause(&self) -> Option<&dyn Error> { None } /// Get the `TypeId` of `self` #[doc(hidden)] @@ -151,22 +151,22 @@ pub trait Error: Debug + Display { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, E: Error + 'a> From<E> for Box<Error + 'a> { - fn from(err: E) -> Box<Error + 'a> { +impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> { + fn from(err: E) -> Box<dyn Error + 'a> { Box::new(err) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<Error + Send + Sync + 'a> { - fn from(err: E) -> Box<Error + Send + Sync + 'a> { +impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync + 'a> { + fn from(err: E) -> Box<dyn Error + Send + Sync + 'a> { Box::new(err) } } #[stable(feature = "rust1", since = "1.0.0")] -impl From<String> for Box<Error + Send + Sync> { - fn from(err: String) -> Box<Error + Send + Sync> { +impl From<String> for Box<dyn Error + Send + Sync> { + fn from(err: String) -> Box<dyn Error + Send + Sync> { #[derive(Debug)] struct StringError(String); @@ -185,38 +185,38 @@ impl From<String> for Box<Error + Send + Sync> { } #[stable(feature = "string_box_error", since = "1.6.0")] -impl From<String> for Box<Error> { - fn from(str_err: String) -> Box<Error> { - let err1: Box<Error + Send + Sync> = From::from(str_err); - let err2: Box<Error> = err1; +impl From<String> for Box<dyn Error> { + fn from(str_err: String) -> Box<dyn Error> { + let err1: Box<dyn Error + Send + Sync> = From::from(str_err); + let err2: Box<dyn Error> = err1; err2 } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, 'b> From<&'b str> for Box<Error + Send + Sync + 'a> { - fn from(err: &'b str) -> Box<Error + Send + Sync + 'a> { +impl<'a, 'b> From<&'b str> for Box<dyn Error + Send + Sync + 'a> { + fn from(err: &'b str) -> Box<dyn Error + Send + Sync + 'a> { From::from(String::from(err)) } } #[stable(feature = "string_box_error", since = "1.6.0")] -impl<'a> From<&'a str> for Box<Error> { - fn from(err: &'a str) -> Box<Error> { +impl<'a> From<&'a str> for Box<dyn Error> { + fn from(err: &'a str) -> Box<dyn Error> { From::from(String::from(err)) } } #[stable(feature = "cow_box_error", since = "1.22.0")] -impl<'a, 'b> From<Cow<'b, str>> for Box<Error + Send + Sync + 'a> { - fn from(err: Cow<'b, str>) -> Box<Error + Send + Sync + 'a> { +impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a> { + fn from(err: Cow<'b, str>) -> Box<dyn Error + Send + Sync + 'a> { From::from(String::from(err)) } } #[stable(feature = "cow_box_error", since = "1.22.0")] -impl<'a> From<Cow<'a, str>> for Box<Error> { - fn from(err: Cow<'a, str>) -> Box<Error> { +impl<'a> From<Cow<'a, str>> for Box<dyn Error> { + fn from(err: Cow<'a, str>) -> Box<dyn Error> { From::from(String::from(err)) } } @@ -327,7 +327,7 @@ impl<T: Error> Error for Box<T> { Error::description(&**self) } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { Error::cause(&**self) } } @@ -368,7 +368,7 @@ impl Error for char::ParseCharError { } // copied from any.rs -impl Error + 'static { +impl dyn Error + 'static { /// Returns true if the boxed type is the same as `T` #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] @@ -390,7 +390,7 @@ impl Error + 'static { pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> { if self.is::<T>() { unsafe { - Some(&*(self as *const Error as *const T)) + Some(&*(self as *const dyn Error as *const T)) } } else { None @@ -404,7 +404,7 @@ impl Error + 'static { pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> { if self.is::<T>() { unsafe { - Some(&mut *(self as *mut Error as *mut T)) + Some(&mut *(self as *mut dyn Error as *mut T)) } } else { None @@ -412,60 +412,60 @@ impl Error + 'static { } } -impl Error + 'static + Send { +impl dyn Error + 'static + Send { /// Forwards to the method defined on the type `Any`. #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn is<T: Error + 'static>(&self) -> bool { - <Error + 'static>::is::<T>(self) + <dyn Error + 'static>::is::<T>(self) } /// Forwards to the method defined on the type `Any`. #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> { - <Error + 'static>::downcast_ref::<T>(self) + <dyn Error + 'static>::downcast_ref::<T>(self) } /// Forwards to the method defined on the type `Any`. #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> { - <Error + 'static>::downcast_mut::<T>(self) + <dyn Error + 'static>::downcast_mut::<T>(self) } } -impl Error + 'static + Send + Sync { +impl dyn Error + 'static + Send + Sync { /// Forwards to the method defined on the type `Any`. #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn is<T: Error + 'static>(&self) -> bool { - <Error + 'static>::is::<T>(self) + <dyn Error + 'static>::is::<T>(self) } /// Forwards to the method defined on the type `Any`. #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> { - <Error + 'static>::downcast_ref::<T>(self) + <dyn Error + 'static>::downcast_ref::<T>(self) } /// Forwards to the method defined on the type `Any`. #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> { - <Error + 'static>::downcast_mut::<T>(self) + <dyn Error + 'static>::downcast_mut::<T>(self) } } -impl Error { +impl dyn Error { #[inline] #[stable(feature = "error_downcast", since = "1.3.0")] /// Attempt to downcast the box to a concrete type. - pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Error>> { + pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error>> { if self.is::<T>() { unsafe { - let raw: *mut Error = Box::into_raw(self); + let raw: *mut dyn Error = Box::into_raw(self); Ok(Box::from_raw(raw as *mut T)) } } else { @@ -474,30 +474,30 @@ impl Error { } } -impl Error + Send { +impl dyn Error + Send { #[inline] #[stable(feature = "error_downcast", since = "1.3.0")] /// Attempt to downcast the box to a concrete type. pub fn downcast<T: Error + 'static>(self: Box<Self>) - -> Result<Box<T>, Box<Error + Send>> { - let err: Box<Error> = self; - <Error>::downcast(err).map_err(|s| unsafe { + -> Result<Box<T>, Box<dyn Error + Send>> { + let err: Box<dyn Error> = self; + <dyn Error>::downcast(err).map_err(|s| unsafe { // reapply the Send marker - transmute::<Box<Error>, Box<Error + Send>>(s) + transmute::<Box<dyn Error>, Box<dyn Error + Send>>(s) }) } } -impl Error + Send + Sync { +impl dyn Error + Send + Sync { #[inline] #[stable(feature = "error_downcast", since = "1.3.0")] /// Attempt to downcast the box to a concrete type. pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Self>> { - let err: Box<Error> = self; - <Error>::downcast(err).map_err(|s| unsafe { + let err: Box<dyn Error> = self; + <dyn Error>::downcast(err).map_err(|s| unsafe { // reapply the Send+Sync marker - transmute::<Box<Error>, Box<Error + Send + Sync>>(s) + transmute::<Box<dyn Error>, Box<dyn Error + Send + Sync>>(s) }) } } @@ -533,13 +533,13 @@ mod tests { #[test] fn downcasting() { let mut a = A; - let a = &mut a as &mut (Error + 'static); + let a = &mut a as &mut (dyn Error + 'static); assert_eq!(a.downcast_ref::<A>(), Some(&A)); assert_eq!(a.downcast_ref::<B>(), None); assert_eq!(a.downcast_mut::<A>(), Some(&mut A)); assert_eq!(a.downcast_mut::<B>(), None); - let a: Box<Error> = Box::new(A); + let a: Box<dyn Error> = Box::new(A); match a.downcast::<B>() { Ok(..) => panic!("expected error"), Err(e) => assert_eq!(*e.downcast::<A>().unwrap(), A), diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index b816f4b7850..754e2bbc412 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -891,7 +891,7 @@ impl Error for IntoStringError { "C string contained non-utf8 bytes" } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { Some(&self.error) } } diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index bdd675e6e2b..02a3ce8b9c4 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -83,7 +83,7 @@ enum Repr { #[derive(Debug)] struct Custom { kind: ErrorKind, - error: Box<error::Error+Send+Sync>, + error: Box<dyn error::Error+Send+Sync>, } /// A list specifying general categories of I/O error. @@ -250,12 +250,12 @@ impl Error { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn new<E>(kind: ErrorKind, error: E) -> Error - where E: Into<Box<error::Error+Send+Sync>> + where E: Into<Box<dyn error::Error+Send+Sync>> { Self::_new(kind, error.into()) } - fn _new(kind: ErrorKind, error: Box<error::Error+Send+Sync>) -> Error { + fn _new(kind: ErrorKind, error: Box<dyn error::Error+Send+Sync>) -> Error { Error { repr: Repr::Custom(Box::new(Custom { kind, @@ -373,7 +373,7 @@ impl Error { /// } /// ``` #[stable(feature = "io_error_inner", since = "1.3.0")] - pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { + pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { match self.repr { Repr::Os(..) => None, Repr::Simple(..) => None, @@ -444,7 +444,7 @@ impl Error { /// } /// ``` #[stable(feature = "io_error_inner", since = "1.3.0")] - pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { + pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { match self.repr { Repr::Os(..) => None, Repr::Simple(..) => None, @@ -478,7 +478,7 @@ impl Error { /// } /// ``` #[stable(feature = "io_error_inner", since = "1.3.0")] - pub fn into_inner(self) -> Option<Box<error::Error+Send+Sync>> { + pub fn into_inner(self) -> Option<Box<dyn error::Error+Send+Sync>> { match self.repr { Repr::Os(..) => None, Repr::Simple(..) => None, @@ -551,7 +551,7 @@ impl error::Error for Error { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match self.repr { Repr::Os(..) => None, Repr::Simple(..) => None, diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 2b4644bd013..85304874848 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1972,7 +1972,7 @@ impl<T: BufRead> BufRead for Take<T> { } } -fn read_one_byte(reader: &mut Read) -> Option<Result<u8>> { +fn read_one_byte(reader: &mut dyn Read) -> Option<Result<u8>> { let mut buf = [0]; loop { return match reader.read(&mut buf) { @@ -2081,7 +2081,7 @@ impl std_error::Error for CharsError { CharsError::Other(ref e) => std_error::Error::description(e), } } - fn cause(&self) -> Option<&std_error::Error> { + fn cause(&self) -> Option<&dyn std_error::Error> { match *self { CharsError::NotUtf8 => None, CharsError::Other(ref e) => e.cause(), diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index fce85a200ba..fffe8fc559b 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -21,7 +21,7 @@ use thread::LocalKey; /// Stdout used by print! and println! macros thread_local! { - static LOCAL_STDOUT: RefCell<Option<Box<Write + Send>>> = { + static LOCAL_STDOUT: RefCell<Option<Box<dyn Write + Send>>> = { RefCell::new(None) } } @@ -624,7 +624,7 @@ impl<'a> fmt::Debug for StderrLock<'a> { with a more general mechanism", issue = "0")] #[doc(hidden)] -pub fn set_panic(sink: Option<Box<Write + Send>>) -> Option<Box<Write + Send>> { +pub fn set_panic(sink: Option<Box<dyn Write + Send>>) -> Option<Box<dyn Write + Send>> { use panicking::LOCAL_STDERR; use mem; LOCAL_STDERR.with(move |slot| { @@ -648,7 +648,7 @@ pub fn set_panic(sink: Option<Box<Write + Send>>) -> Option<Box<Write + Send>> { with a more general mechanism", issue = "0")] #[doc(hidden)] -pub fn set_print(sink: Option<Box<Write + Send>>) -> Option<Box<Write + Send>> { +pub fn set_print(sink: Option<Box<dyn Write + Send>>) -> Option<Box<dyn Write + Send>> { use mem; LOCAL_STDOUT.with(move |slot| { mem::replace(&mut *slot.borrow_mut(), sink) @@ -670,7 +670,7 @@ pub fn set_print(sink: Option<Box<Write + Send>>) -> Option<Box<Write + Send>> { /// However, if the actual I/O causes an error, this function does panic. fn print_to<T>( args: fmt::Arguments, - local_s: &'static LocalKey<RefCell<Option<Box<Write+Send>>>>, + local_s: &'static LocalKey<RefCell<Option<Box<dyn Write+Send>>>>, global_s: fn() -> T, label: &str, ) diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 195310a26fe..33f741dbc38 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -223,7 +223,7 @@ mod tests { assert_eq!(copy(&mut r, &mut w).unwrap(), 4); let mut r = repeat(0).take(1 << 17); - assert_eq!(copy(&mut r as &mut Read, &mut w as &mut Write).unwrap(), 1 << 17); + assert_eq!(copy(&mut r as &mut dyn Read, &mut w as &mut dyn Write).unwrap(), 1 << 17); } #[test] diff --git a/src/libstd/net/parser.rs b/src/libstd/net/parser.rs index 008c5da171f..cf3e5354a31 100644 --- a/src/libstd/net/parser.rs +++ b/src/libstd/net/parser.rs @@ -58,7 +58,7 @@ impl<'a> Parser<'a> { } // Return result of first successful parser - fn read_or<T>(&mut self, parsers: &mut [Box<FnMut(&mut Parser) -> Option<T> + 'static>]) + fn read_or<T>(&mut self, parsers: &mut [Box<dyn FnMut(&mut Parser) -> Option<T> + 'static>]) -> Option<T> { for pf in parsers { if let Some(r) = self.read_atomically(|p: &mut Parser| pf(p)) { diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 6b4bbdddf32..75c7a3d9280 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -927,7 +927,7 @@ mod tests { use time::{Instant, Duration}; use thread; - fn each_ip(f: &mut FnMut(SocketAddr)) { + fn each_ip(f: &mut dyn FnMut(SocketAddr)) { f(next_test_ip4()); f(next_test_ip6()); } diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index d25e29999cb..0ebe3284b4f 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -826,7 +826,7 @@ mod tests { use time::{Instant, Duration}; use thread; - fn each_ip(f: &mut FnMut(SocketAddr, SocketAddr)) { + fn each_ip(f: &mut dyn FnMut(SocketAddr, SocketAddr)) { f(next_test_ip4(), next_test_ip4()); f(next_test_ip6(), next_test_ip6()); } diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 451420ae88a..b8c1c4f9e68 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -421,6 +421,6 @@ pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> { /// } /// ``` #[stable(feature = "resume_unwind", since = "1.9.0")] -pub fn resume_unwind(payload: Box<Any + Send>) -> ! { +pub fn resume_unwind(payload: Box<dyn Any + Send>) -> ! { panicking::update_count_then_panic(payload) } diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 46b6cf60705..283fd36af41 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -36,7 +36,7 @@ use sys_common::util; use thread; thread_local! { - pub static LOCAL_STDERR: RefCell<Option<Box<Write + Send>>> = { + pub static LOCAL_STDERR: RefCell<Option<Box<dyn Write + Send>>> = { RefCell::new(None) } } @@ -64,7 +64,7 @@ extern { #[derive(Copy, Clone)] enum Hook { Default, - Custom(*mut (Fn(&PanicInfo) + 'static + Sync + Send)), + Custom(*mut (dyn Fn(&PanicInfo) + 'static + Sync + Send)), } static HOOK_LOCK: RWLock = RWLock::new(); @@ -104,7 +104,7 @@ static mut HOOK: Hook = Hook::Default; /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] -pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) { +pub fn set_hook(hook: Box<dyn Fn(&PanicInfo) + 'static + Sync + Send>) { if thread::panicking() { panic!("cannot modify the panic hook from a panicking thread"); } @@ -149,7 +149,7 @@ pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) { /// panic!("Normal panic"); /// ``` #[stable(feature = "panic_hooks", since = "1.10.0")] -pub fn take_hook() -> Box<Fn(&PanicInfo) + 'static + Sync + Send> { +pub fn take_hook() -> Box<dyn Fn(&PanicInfo) + 'static + Sync + Send> { if thread::panicking() { panic!("cannot modify the panic hook from a panicking thread"); } @@ -197,7 +197,7 @@ fn default_hook(info: &PanicInfo) { let thread = thread_info::current_thread(); let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>"); - let write = |err: &mut ::io::Write| { + let write = |err: &mut dyn (::io::Write)| { let _ = writeln!(err, "thread '{}' panicked at '{}', {}", name, msg, location); @@ -248,7 +248,7 @@ pub fn update_panic_count(amt: isize) -> usize { pub use realstd::rt::update_panic_count; /// Invoke a closure, capturing the cause of an unwinding panic if one occurs. -pub unsafe fn try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<Any + Send>> { +pub unsafe fn try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> { #[allow(unions_with_drop_fields)] union Data<F, R> { f: F, @@ -369,12 +369,12 @@ fn continue_panic_fmt(info: &PanicInfo) -> ! { } unsafe impl<'a> BoxMeUp for PanicPayload<'a> { - fn box_me_up(&mut self) -> *mut (Any + Send) { + fn box_me_up(&mut self) -> *mut (dyn Any + Send) { let contents = mem::replace(self.fill(), String::new()); Box::into_raw(Box::new(contents)) } - fn get(&mut self) -> &(Any + Send) { + fn get(&mut self) -> &(dyn Any + Send) { self.fill() } } @@ -419,15 +419,15 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u3 } unsafe impl<A: Send + 'static> BoxMeUp for PanicPayload<A> { - fn box_me_up(&mut self) -> *mut (Any + Send) { + fn box_me_up(&mut self) -> *mut (dyn Any + Send) { let data = match self.inner.take() { - Some(a) => Box::new(a) as Box<Any + Send>, + Some(a) => Box::new(a) as Box<dyn Any + Send>, None => Box::new(()), }; Box::into_raw(data) } - fn get(&mut self) -> &(Any + Send) { + fn get(&mut self) -> &(dyn Any + Send) { match self.inner { Some(ref a) => a, None => &(), @@ -441,7 +441,7 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u3 /// Executes the primary logic for a panic, including checking for recursive /// panics, panic hooks, and finally dispatching to the panic runtime to either /// abort or unwind. -fn rust_panic_with_hook(payload: &mut BoxMeUp, +fn rust_panic_with_hook(payload: &mut dyn BoxMeUp, message: Option<&fmt::Arguments>, file_line_col: &(&str, u32, u32)) -> ! { let (file, line, col) = *file_line_col; @@ -496,17 +496,17 @@ fn rust_panic_with_hook(payload: &mut BoxMeUp, } /// Shim around rust_panic. Called by resume_unwind. -pub fn update_count_then_panic(msg: Box<Any + Send>) -> ! { +pub fn update_count_then_panic(msg: Box<dyn Any + Send>) -> ! { update_panic_count(1); - struct RewrapBox(Box<Any + Send>); + struct RewrapBox(Box<dyn Any + Send>); unsafe impl BoxMeUp for RewrapBox { - fn box_me_up(&mut self) -> *mut (Any + Send) { + fn box_me_up(&mut self) -> *mut (dyn Any + Send) { Box::into_raw(mem::replace(&mut self.0, Box::new(()))) } - fn get(&mut self) -> &(Any + Send) { + fn get(&mut self) -> &(dyn Any + Send) { &*self.0 } } @@ -517,9 +517,9 @@ pub fn update_count_then_panic(msg: Box<Any + Send>) -> ! { /// A private no-mangle function on which to slap yer breakpoints. #[no_mangle] #[allow(private_no_mangle_fns)] // yes we get it, but we like breakpoints -pub fn rust_panic(mut msg: &mut BoxMeUp) -> ! { +pub fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! { let code = unsafe { - let obj = &mut msg as *mut &mut BoxMeUp; + let obj = &mut msg as *mut &mut dyn BoxMeUp; __rust_start_panic(obj as usize) }; rtabort!("failed to initiate panic, error {}", code) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 00051d4487a..39692836866 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -813,13 +813,13 @@ impl fmt::Debug for Output { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let stdout_utf8 = str::from_utf8(&self.stdout); - let stdout_debug: &fmt::Debug = match stdout_utf8 { + let stdout_debug: &dyn fmt::Debug = match stdout_utf8 { Ok(ref str) => str, Err(_) => &self.stdout }; let stderr_utf8 = str::from_utf8(&self.stderr); - let stderr_debug: &fmt::Debug = match stderr_utf8 { + let stderr_debug: &dyn fmt::Debug = match stderr_utf8 { Ok(ref str) => str, Err(_) => &self.stderr }; diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index 8f945470b7e..9e957bd87d7 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -29,7 +29,7 @@ pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count}; // To reduce the generated code of the new `lang_start`, this function is doing // the real work. #[cfg(not(test))] -fn lang_start_internal(main: &(Fn() -> i32 + Sync + ::panic::RefUnwindSafe), +fn lang_start_internal(main: &(dyn Fn() -> i32 + Sync + ::panic::RefUnwindSafe), argc: isize, argv: *const *const u8) -> isize { use panic; use sys; diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index cbda5afadcd..02a96b01cca 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1638,7 +1638,7 @@ impl<T: Send> error::Error for SendError<T> { "sending on a closed channel" } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { None } } @@ -1681,7 +1681,7 @@ impl<T: Send> error::Error for TrySendError<T> { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { None } } @@ -1709,7 +1709,7 @@ impl error::Error for RecvError { "receiving on a closed channel" } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { None } } @@ -1742,7 +1742,7 @@ impl error::Error for TryRecvError { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { None } } @@ -1783,7 +1783,7 @@ impl error::Error for RecvTimeoutError { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { None } } diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index 9310dad9172..a7a284cfb79 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -93,7 +93,7 @@ pub struct Handle<'rx, T:Send+'rx> { next: *mut Handle<'static, ()>, prev: *mut Handle<'static, ()>, added: bool, - packet: &'rx (Packet+'rx), + packet: &'rx (dyn Packet+'rx), // due to our fun transmutes, we be sure to place this at the end. (nothing // previous relies on T) diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 443e2a6980d..10282ecb658 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -309,7 +309,7 @@ impl Once { #[cold] fn call_inner(&self, ignore_poisoning: bool, - init: &mut FnMut(bool)) { + init: &mut dyn FnMut(bool)) { let mut state = self.state.load(Ordering::SeqCst); 'outer: loop { diff --git a/src/libstd/sys/cloudabi/thread.rs b/src/libstd/sys/cloudabi/thread.rs index 5d66936b2a4..8cca47efd22 100644 --- a/src/libstd/sys/cloudabi/thread.rs +++ b/src/libstd/sys/cloudabi/thread.rs @@ -32,7 +32,7 @@ unsafe impl Send for Thread {} unsafe impl Sync for Thread {} impl Thread { - pub unsafe fn new<'a>(stack: usize, p: Box<FnBox() + 'a>) -> io::Result<Thread> { + pub unsafe fn new<'a>(stack: usize, p: Box<dyn FnBox() + 'a>) -> io::Result<Thread> { let p = box p; let mut native: libc::pthread_t = mem::zeroed(); let mut attr: libc::pthread_attr_t = mem::zeroed(); diff --git a/src/libstd/sys/redox/process.rs b/src/libstd/sys/redox/process.rs index d0b94e14f54..02bc467541e 100644 --- a/src/libstd/sys/redox/process.rs +++ b/src/libstd/sys/redox/process.rs @@ -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); } diff --git a/src/libstd/sys/redox/thread.rs b/src/libstd/sys/redox/thread.rs index 110d46ca3ab..f4177087d77 100644 --- a/src/libstd/sys/redox/thread.rs +++ b/src/libstd/sys/redox/thread.rs @@ -28,7 +28,7 @@ unsafe impl Send for Thread {} unsafe impl Sync for Thread {} impl Thread { - pub unsafe fn new<'a>(_stack: usize, p: Box<FnBox() + 'a>) -> io::Result<Thread> { + pub unsafe fn new<'a>(_stack: usize, p: Box<dyn FnBox() + 'a>) -> io::Result<Thread> { let p = box p; let id = cvt(syscall::clone(syscall::CLONE_VM | syscall::CLONE_FS | syscall::CLONE_FILES))?; diff --git a/src/libstd/sys/unix/process/process_common.rs b/src/libstd/sys/unix/process/process_common.rs index 6396bb3a49e..77f125f3c5b 100644 --- a/src/libstd/sys/unix/process/process_common.rs +++ b/src/libstd/sys/unix/process/process_common.rs @@ -52,7 +52,7 @@ pub struct Command { uid: Option<uid_t>, gid: Option<gid_t>, 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>, @@ -155,12 +155,12 @@ impl Command { self.gid } - pub fn get_closures(&mut self) -> &mut Vec<Box<FnMut() -> io::Result<()> + Send + Sync>> { + pub fn get_closures(&mut self) -> &mut Vec<Box<dyn FnMut() -> io::Result<()> + Send + Sync>> { &mut self.closures } 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); } diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 7fdecc9c0c0..e26306c045d 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -49,7 +49,7 @@ unsafe fn pthread_attr_setstacksize(_attr: *mut libc::pthread_attr_t, } impl Thread { - pub unsafe fn new<'a>(stack: usize, p: Box<FnBox() + 'a>) + pub unsafe fn new<'a>(stack: usize, p: Box<dyn FnBox() + 'a>) -> io::Result<Thread> { let p = box p; let mut native: libc::pthread_t = mem::zeroed(); diff --git a/src/libstd/sys/wasm/thread.rs b/src/libstd/sys/wasm/thread.rs index 728e678a2e8..8173a624211 100644 --- a/src/libstd/sys/wasm/thread.rs +++ b/src/libstd/sys/wasm/thread.rs @@ -19,7 +19,7 @@ pub struct Thread(Void); pub const DEFAULT_MIN_STACK_SIZE: usize = 4096; impl Thread { - pub unsafe fn new<'a>(_stack: usize, _p: Box<FnBox() + 'a>) + pub unsafe fn new<'a>(_stack: usize, _p: Box<dyn FnBox() + 'a>) -> io::Result<Thread> { unsupported() diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index b6f63303dc2..44ec872b244 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -28,7 +28,7 @@ pub struct Thread { } impl Thread { - pub unsafe fn new<'a>(stack: usize, p: Box<FnBox() + 'a>) + pub unsafe fn new<'a>(stack: usize, p: Box<dyn FnBox() + 'a>) -> io::Result<Thread> { let p = box p; diff --git a/src/libstd/sys_common/at_exit_imp.rs b/src/libstd/sys_common/at_exit_imp.rs index d268d9ad6f9..b28a4d2f8be 100644 --- a/src/libstd/sys_common/at_exit_imp.rs +++ b/src/libstd/sys_common/at_exit_imp.rs @@ -17,7 +17,7 @@ use ptr; use mem; use sys_common::mutex::Mutex; -type Queue = Vec<Box<FnBox()>>; +type Queue = Vec<Box<dyn FnBox()>>; // NB these are specifically not types from `std::sync` as they currently rely // on poisoning and this module needs to operate at a lower level than requiring @@ -68,7 +68,7 @@ pub fn cleanup() { } } -pub fn push(f: Box<FnBox()>) -> bool { +pub fn push(f: Box<dyn FnBox()>) -> bool { unsafe { let _guard = LOCK.lock(); if init() { diff --git a/src/libstd/sys_common/backtrace.rs b/src/libstd/sys_common/backtrace.rs index 2db47bd5947..77371782977 100644 --- a/src/libstd/sys_common/backtrace.rs +++ b/src/libstd/sys_common/backtrace.rs @@ -49,7 +49,7 @@ pub struct Frame { const MAX_NB_FRAMES: usize = 100; /// Prints the current backtrace. -pub fn print(w: &mut Write, format: PrintFormat) -> io::Result<()> { +pub fn print(w: &mut dyn Write, format: PrintFormat) -> io::Result<()> { static LOCK: Mutex = Mutex::new(); // Use a lock to prevent mixed output in multithreading context. @@ -62,7 +62,7 @@ pub fn print(w: &mut Write, format: PrintFormat) -> io::Result<()> { } } -fn _print(w: &mut Write, format: PrintFormat) -> io::Result<()> { +fn _print(w: &mut dyn Write, format: PrintFormat) -> io::Result<()> { let mut frames = [Frame { exact_position: ptr::null(), symbol_addr: ptr::null(), @@ -176,7 +176,7 @@ pub fn log_enabled() -> Option<PrintFormat> { /// /// These output functions should now be used everywhere to ensure consistency. /// You may want to also use `output_fileline`. -fn output(w: &mut Write, idx: usize, frame: Frame, +fn output(w: &mut dyn Write, idx: usize, frame: Frame, s: Option<&str>, format: PrintFormat) -> io::Result<()> { // Remove the `17: 0x0 - <unknown>` line. if format == PrintFormat::Short && frame.exact_position == ptr::null() { @@ -201,7 +201,7 @@ fn output(w: &mut Write, idx: usize, frame: Frame, /// /// See also `output`. #[allow(dead_code)] -fn output_fileline(w: &mut Write, +fn output_fileline(w: &mut dyn Write, file: &[u8], line: u32, format: PrintFormat) -> io::Result<()> { @@ -253,7 +253,7 @@ fn output_fileline(w: &mut Write, // Note that this demangler isn't quite as fancy as it could be. We have lots // of other information in our symbols like hashes, version, type information, // etc. Additionally, this doesn't handle glue symbols at all. -pub fn demangle(writer: &mut Write, mut s: &str, format: PrintFormat) -> io::Result<()> { +pub fn demangle(writer: &mut dyn Write, mut s: &str, format: PrintFormat) -> io::Result<()> { // During ThinLTO LLVM may import and rename internal symbols, so strip out // those endings first as they're one of the last manglings applied to // symbol names. diff --git a/src/libstd/sys_common/poison.rs b/src/libstd/sys_common/poison.rs index e74c40ae04b..1625efe4a2a 100644 --- a/src/libstd/sys_common/poison.rs +++ b/src/libstd/sys_common/poison.rs @@ -251,7 +251,7 @@ impl<T> Error for TryLockError<T> { } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { match *self { TryLockError::Poisoned(ref p) => Some(p), _ => None diff --git a/src/libstd/sys_common/thread.rs b/src/libstd/sys_common/thread.rs index da6f58ef6bb..86a5e2b8694 100644 --- a/src/libstd/sys_common/thread.rs +++ b/src/libstd/sys_common/thread.rs @@ -21,7 +21,7 @@ pub unsafe fn start_thread(main: *mut u8) { let _handler = stack_overflow::Handler::new(); // Finally, let's run some code. - Box::from_raw(main as *mut Box<FnBox()>)() + Box::from_raw(main as *mut Box<dyn FnBox()>)() } pub fn min_stack() -> usize { diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 90f054186d1..f7052e4834a 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -1175,7 +1175,7 @@ impl fmt::Debug for Thread { /// /// [`Result`]: ../../std/result/enum.Result.html #[stable(feature = "rust1", since = "1.0.0")] -pub type Result<T> = ::result::Result<T, Box<Any + Send + 'static>>; +pub type Result<T> = ::result::Result<T, Box<dyn Any + Send + 'static>>; // This packet is used to communicate the return value between the child thread // and the parent thread. Memory is shared through the `Arc` within and there's @@ -1438,7 +1438,7 @@ mod tests { rx.recv().unwrap(); } - fn avoid_copying_the_body<F>(spawnfn: F) where F: FnOnce(Box<Fn() + Send>) { + fn avoid_copying_the_body<F>(spawnfn: F) where F: FnOnce(Box<dyn Fn() + Send>) { let (tx, rx) = channel(); let x: Box<_> = box 1; @@ -1485,7 +1485,7 @@ mod tests { // (well, it would if the constant were 8000+ - I lowered it to be more // valgrind-friendly. try this at home, instead..!) const GENERATIONS: u32 = 16; - fn child_no(x: u32) -> Box<Fn() + Send> { + fn child_no(x: u32) -> Box<dyn Fn() + Send> { return Box::new(move|| { if x < GENERATIONS { thread::spawn(move|| child_no(x+1)()); @@ -1531,10 +1531,10 @@ mod tests { #[test] fn test_try_panic_message_any() { match thread::spawn(move|| { - panic!(box 413u16 as Box<Any + Send>); + panic!(box 413u16 as Box<dyn Any + Send>); }).join() { Err(e) => { - type T = Box<Any + Send>; + type T = Box<dyn Any + Send>; assert!(e.is::<T>()); let any = e.downcast::<T>().unwrap(); assert!(any.is::<u16>()); diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index d241ae1d442..60de94821bb 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -14,8 +14,6 @@ //! //! This API is completely unstable and subject to change. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/", diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index ff76e788b3c..f0d33835cd0 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -10,8 +10,6 @@ //! Syntax extensions in the Rust compiler. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index cc09a944e4c..61af70af47d 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -14,8 +14,6 @@ //! //! This API is completely unstable and subject to change. -#![deny(bare_trait_objects)] - #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index a012f4e776f..cf92ce27ee5 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -66,9 +66,9 @@ pub mod terminfo; mod win; /// Alias for stdout terminals. -pub type StdoutTerminal = Terminal<Output = Stdout> + Send; +pub type StdoutTerminal = dyn Terminal<Output = Stdout> + Send; /// Alias for stderr terminals. -pub type StderrTerminal = Terminal<Output = Stderr> + Send; +pub type StderrTerminal = dyn Terminal<Output = Stderr> + Send; #[cfg(not(windows))] /// Return a Terminal wrapping stdout, or None if a terminal couldn't be diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index c5e68eed407..51e0fa315f4 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -58,7 +58,7 @@ impl error::Error for Error { "failed to create TermInfo" } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { use self::Error::*; match self { &IoError(ref e) => Some(e), diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index 0cdea64db8b..d5e5df54733 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -164,7 +164,7 @@ pub static stringnames: &'static[&'static str] = &[ "cbt", "_", "cr", "csr", "tb "OTG3", "OTG1", "OTG4", "OTGR", "OTGL", "OTGU", "OTGD", "OTGH", "OTGV", "OTGC", "meml", "memu", "box1"]; -fn read_le_u16(r: &mut io::Read) -> io::Result<u16> { +fn read_le_u16(r: &mut dyn io::Read) -> io::Result<u16> { let mut b = [0; 2]; let mut amt = 0; while amt < b.len() { @@ -176,7 +176,7 @@ fn read_le_u16(r: &mut io::Read) -> io::Result<u16> { Ok((b[0] as u16) | ((b[1] as u16) << 8)) } -fn read_byte(r: &mut io::Read) -> io::Result<u8> { +fn read_byte(r: &mut dyn io::Read) -> io::Result<u8> { match r.bytes().next() { Some(s) => s, None => Err(io::Error::new(io::ErrorKind::Other, "end of file")), @@ -185,7 +185,7 @@ fn read_byte(r: &mut io::Read) -> io::Result<u8> { /// Parse a compiled terminfo entry, using long capability names if `longnames` /// is true -pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> { +pub fn parse(file: &mut dyn io::Read, longnames: bool) -> Result<TermInfo, String> { macro_rules! t( ($e:expr) => ( match $e { Ok(e) => e, diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 6b547dff912..76206e2c10d 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -27,8 +27,6 @@ // this crate, which relies on this attribute (rather than the value of `--crate-name` passed by // cargo) to detect this crate. -#![deny(bare_trait_objects)] - #![crate_name = "test"] #![unstable(feature = "test", issue = "27812")] #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", diff --git a/src/libunwind/lib.rs b/src/libunwind/lib.rs index ea5eee3cc7d..2b3c19c067e 100644 --- a/src/libunwind/lib.rs +++ b/src/libunwind/lib.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(bare_trait_objects)] - #![no_std] #![unstable(feature = "panic_unwind", issue = "32837")] diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index e9b853722c2..d77261f4959 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -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; } diff --git a/src/tools/compiletest/src/read2.rs b/src/tools/compiletest/src/read2.rs index 5bf898f5f1b..f056a041c13 100644 --- a/src/tools/compiletest/src/read2.rs +++ b/src/tools/compiletest/src/read2.rs @@ -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(); diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index ade7ae0a4ae..e72f90554d3 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -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)?; diff --git a/src/tools/remote-test-client/src/main.rs b/src/tools/remote-test-client/src/main.rs index 2f5275bb5be..011bf551140 100644 --- a/src/tools/remote-test-client/src/main.rs +++ b/src/tools/remote-test-client/src/main.rs @@ -177,7 +177,7 @@ fn start_qemu_emulator(target: &str, _ => panic!("cannot start emulator for: {}"< target), } - fn add_files(w: &mut Write, root: &Path, cur: &Path) { + fn add_files(w: &mut dyn Write, root: &Path, cur: &Path) { for entry in t!(cur.read_dir()) { let entry = t!(entry); let path = entry.path(); @@ -297,7 +297,7 @@ fn run(files: String, args: Vec<String>) { } } -fn send(path: &Path, dst: &mut Write) { +fn send(path: &Path, dst: &mut dyn Write) { t!(dst.write_all(path.file_name().unwrap().to_str().unwrap().as_bytes())); t!(dst.write_all(&[0])); let mut file = t!(File::open(&path)); diff --git a/src/tools/remote-test-server/src/main.rs b/src/tools/remote-test-server/src/main.rs index ae13acd58bb..5116f6662ff 100644 --- a/src/tools/remote-test-server/src/main.rs +++ b/src/tools/remote-test-server/src/main.rs @@ -270,7 +270,7 @@ fn recv<B: BufRead>(dir: &Path, io: &mut B) -> PathBuf { return dst } -fn my_copy(src: &mut Read, which: u8, dst: &Mutex<Write>) { +fn my_copy(src: &mut dyn Read, which: u8, dst: &Mutex<dyn Write>) { let mut b = [0; 1024]; loop { let n = t!(src.read(&mut b)); @@ -290,7 +290,7 @@ fn my_copy(src: &mut Read, which: u8, dst: &Mutex<Write>) { } } -fn read_u32(r: &mut Read) -> u32 { +fn read_u32(r: &mut dyn Read) -> u32 { let mut len = [0; 4]; t!(r.read_exact(&mut len)); ((len[0] as u32) << 24) | diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index c9bc1b9d849..f68ba0b095b 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -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"), diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index 46217a42009..bb041b39785 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -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()); |
