From 0603a731f40015849e82d4f00c90899bb01898ec Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Fri, 20 Jul 2018 14:12:57 +0100 Subject: [PATCH 01/27] Add test case for #50865 regression. --- .../auxiliary/lib.rs | 24 +++++++++++++++++++ .../issue-50865-private-impl-trait/main.rs | 20 ++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/test/run-pass/issue-50865-private-impl-trait/auxiliary/lib.rs create mode 100644 src/test/run-pass/issue-50865-private-impl-trait/main.rs diff --git a/src/test/run-pass/issue-50865-private-impl-trait/auxiliary/lib.rs b/src/test/run-pass/issue-50865-private-impl-trait/auxiliary/lib.rs new file mode 100644 index 0000000000000..bf4f13360be16 --- /dev/null +++ b/src/test/run-pass/issue-50865-private-impl-trait/auxiliary/lib.rs @@ -0,0 +1,24 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "lib"] + +pub fn bar

( // Error won't happen if "bar" is not generic + _baz: P, +) { + hide_foo()(); +} + +fn hide_foo() -> impl Fn() { // Error won't happen if "iterate" hasn't impl Trait or has generics + foo +} + +fn foo() { // Error won't happen if "foo" isn't used in "iterate" or has generics +} diff --git a/src/test/run-pass/issue-50865-private-impl-trait/main.rs b/src/test/run-pass/issue-50865-private-impl-trait/main.rs new file mode 100644 index 0000000000000..7e92e1079812c --- /dev/null +++ b/src/test/run-pass/issue-50865-private-impl-trait/main.rs @@ -0,0 +1,20 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:lib.rs + +// Regression test for #50865. +// FIXME: explain. + +extern crate lib; + +fn main() { + lib::bar(()); // Error won't happen if bar is called from same crate +} From f285876b435e29e309659197790b82ad880650a0 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Fri, 10 Aug 2018 10:32:52 +0100 Subject: [PATCH 02/27] Logging for rustc_privacy. --- src/librustc_privacy/Cargo.toml | 1 + src/librustc_privacy/lib.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/librustc_privacy/Cargo.toml b/src/librustc_privacy/Cargo.toml index 62eab40f3ec9a..b7af9ec809e54 100644 --- a/src/librustc_privacy/Cargo.toml +++ b/src/librustc_privacy/Cargo.toml @@ -9,6 +9,7 @@ path = "lib.rs" crate-type = ["dylib"] [dependencies] +log = { version = "0.4", features = ["release_max_level_info", "std"] } rustc = { path = "../librustc" } rustc_typeck = { path = "../librustc_typeck" } syntax = { path = "../libsyntax" } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index ab383287773a1..d2b6d0bb967cf 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -18,6 +18,7 @@ #![recursion_limit="256"] +#[macro_use] extern crate log; #[macro_use] extern crate rustc; #[macro_use] extern crate syntax; extern crate rustc_typeck; @@ -147,6 +148,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { } fn visit_item(&mut self, item: &'tcx hir::Item) { + debug!("Walked item {:?}", item); let inherited_item_level = match item.node { // Impls inherit level from their types and traits hir::ItemKind::Impl(..) => { @@ -164,6 +166,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) | hir::ItemKind::Existential(..) | hir::ItemKind::Ty(..) | hir::ItemKind::Union(..) | hir::ItemKind::Use(..) => { + if let hir::ItemKind::Fn(ref _decl, ref _header, ref _generics, ref _body) = item.node { + debug!("Walked function"); + } if item.vis.node.is_pub() { self.prev_level } else { None } } }; @@ -171,6 +176,8 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { // Update level of the item itself let item_level = self.update(item.id, inherited_item_level); + debug!("believed to be: {:?}", item_level); + // Update levels of nested things match item.node { hir::ItemKind::Enum(ref def, _) => { @@ -1737,6 +1744,8 @@ fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } visitor.update(ast::CRATE_NODE_ID, Some(AccessLevel::Public)); + debug!("access levels after embargo: {:?}", &visitor.access_levels); + { let mut visitor = ObsoleteVisiblePrivateTypesVisitor { tcx, @@ -1766,6 +1775,8 @@ fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, krate.visit_all_item_likes(&mut DeepVisitor::new(&mut visitor)); } + debug!("final access levels: {:?}", &visitor.access_levels); + Lrc::new(visitor.access_levels) } From 8a72954d7a900736ce85f05cfa8c0df1c013acaa Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 13 Aug 2018 21:15:42 +0200 Subject: [PATCH 03/27] Window Mutex: make sure we properly initialize the SRWLock --- src/libstd/sys/windows/mutex.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstd/sys/windows/mutex.rs b/src/libstd/sys/windows/mutex.rs index 9bf9f749d4df2..58f24eb132351 100644 --- a/src/libstd/sys/windows/mutex.rs +++ b/src/libstd/sys/windows/mutex.rs @@ -58,6 +58,8 @@ pub unsafe fn raw(m: &Mutex) -> c::PSRWLOCK { impl Mutex { pub const fn new() -> Mutex { Mutex { + // This works because SRWLOCK_INIT is a NULL pointer, so we are also properly + // initializing an SRWLOCK here. lock: AtomicUsize::new(0), held: UnsafeCell::new(false), } From b7a49e7c9e720039f3d2c54a38be73126d052d09 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 14 Aug 2018 12:52:37 +0200 Subject: [PATCH 04/27] fixed wording --- src/libstd/sys/windows/mutex.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/windows/mutex.rs b/src/libstd/sys/windows/mutex.rs index 58f24eb132351..b0e7331e2b651 100644 --- a/src/libstd/sys/windows/mutex.rs +++ b/src/libstd/sys/windows/mutex.rs @@ -58,7 +58,7 @@ pub unsafe fn raw(m: &Mutex) -> c::PSRWLOCK { impl Mutex { pub const fn new() -> Mutex { Mutex { - // This works because SRWLOCK_INIT is a NULL pointer, so we are also properly + // This works because SRWLOCK_INIT is 0 (wrapped in a struct), so we are also properly // initializing an SRWLOCK here. lock: AtomicUsize::new(0), held: UnsafeCell::new(false), From 00b260691fc85020c2b58d263665fe4808b72ac1 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Mon, 20 Aug 2018 22:39:47 +0100 Subject: [PATCH 05/27] Mark impl Trait Functions as reachable. (Fixes #50865) --- src/Cargo.lock | 1 + src/librustc/middle/privacy.rs | 2 ++ src/librustc/middle/reachable.rs | 2 ++ src/librustc_privacy/lib.rs | 16 +++++++++++----- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 8299dea1c4b0e..4b76080e500ab 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -2237,6 +2237,7 @@ dependencies = [ name = "rustc_privacy" version = "0.0.0" dependencies = [ + "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_data_structures 0.0.0", "rustc_typeck 0.0.0", diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index e2de0b6bd013d..c7e093380fac3 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -21,6 +21,8 @@ use syntax::ast::NodeId; // Accessibility levels, sorted in ascending order #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum AccessLevel { + // Superset of Reachable used to mark impl Trait items. + // ReachableFromImplTrait, // Exported items + items participating in various kinds of public interfaces, // but not directly nameable. For example, if function `fn f() -> T {...}` is // public, then type `T` is reachable. Its values can be obtained by other crates diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index a504697008ef4..e05b4e79f2e81 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -446,6 +446,8 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> // Step 2: Mark all symbols that the symbols on the worklist touch. reachable_context.propagate(); + debug!("Inline reachability shows: {:?}", reachable_context.reachable_symbols); + // Return the set of reachable symbols. ReachableSet(Lrc::new(reachable_context.reachable_symbols)) } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index d2b6d0bb967cf..fea0e3a7435eb 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -159,16 +159,22 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { hir::ItemKind::ForeignMod(..) => { self.prev_level } + // Impl trait return types mark their parent function. + // It (and its children) are revisited if the change applies. + hir::ItemKind::Existential(ref ty_data) => { + if let Some(impl_trait_fn) = ty_data.impl_trait_fn { + if let Some(node_id) = self.tcx.hir.as_local_node_id(impl_trait_fn) { + self.update(node_id, Some(AccessLevel::Reachable)); + } + } + if item.vis.node.is_pub() { self.prev_level } else { None } + } // Other `pub` items inherit levels from parents hir::ItemKind::Const(..) | hir::ItemKind::Enum(..) | hir::ItemKind::ExternCrate(..) | hir::ItemKind::GlobalAsm(..) | hir::ItemKind::Fn(..) | hir::ItemKind::Mod(..) | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) | - hir::ItemKind::Existential(..) | hir::ItemKind::Ty(..) | hir::ItemKind::Union(..) | hir::ItemKind::Use(..) => { - if let hir::ItemKind::Fn(ref _decl, ref _header, ref _generics, ref _body) = item.node { - debug!("Walked function"); - } if item.vis.node.is_pub() { self.prev_level } else { None } } }; @@ -176,7 +182,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { // Update level of the item itself let item_level = self.update(item.id, inherited_item_level); - debug!("believed to be: {:?}", item_level); + debug!("Its privacy is believed to be: {:?}", item_level); // Update levels of nested things match item.node { From 81684bf1aafa6e83e796c2581e4c7fe518a90fda Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Tue, 21 Aug 2018 00:11:59 +0100 Subject: [PATCH 06/27] New AccessLevel and accompanying propagation. --- src/librustc/ich/impls_ty.rs | 1 + src/librustc/middle/privacy.rs | 5 +++-- src/librustc_privacy/lib.rs | 14 ++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index a3600c0480017..365434062a303 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -1086,6 +1086,7 @@ impl_stable_hash_for!(enum traits::Reveal { }); impl_stable_hash_for!(enum ::middle::privacy::AccessLevel { + ReachableFromImplTrait, Reachable, Exported, Public diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index c7e093380fac3..39ddaca8925e0 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -22,7 +22,7 @@ use syntax::ast::NodeId; #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum AccessLevel { // Superset of Reachable used to mark impl Trait items. - // ReachableFromImplTrait, + ReachableFromImplTrait, // Exported items + items participating in various kinds of public interfaces, // but not directly nameable. For example, if function `fn f() -> T {...}` is // public, then type `T` is reachable. Its values can be obtained by other crates @@ -42,7 +42,8 @@ pub struct AccessLevels { impl AccessLevels { pub fn is_reachable(&self, id: Id) -> bool { - self.map.contains_key(&id) + // self.map.contains_key(&id) + self.map.get(&id) >= Some(&AccessLevel::Reachable) } pub fn is_exported(&self, id: Id) -> bool { self.map.get(&id) >= Some(&AccessLevel::Exported) diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index fea0e3a7435eb..b6b56cad83906 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -84,6 +84,7 @@ struct EmbargoVisitor<'a, 'tcx: 'a> { } struct ReachEverythingInTheInterfaceVisitor<'b, 'a: 'b, 'tcx: 'a> { + access_level: Option, item_def_id: DefId, ev: &'b mut EmbargoVisitor<'a, 'tcx>, } @@ -134,6 +135,7 @@ impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> { fn reach<'b>(&'b mut self, item_id: ast::NodeId) -> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> { ReachEverythingInTheInterfaceVisitor { + access_level: self.prev_level.map(|l| l.min(AccessLevel::Reachable)), item_def_id: self.tcx.hir.local_def_id(item_id), ev: self, } @@ -164,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { hir::ItemKind::Existential(ref ty_data) => { if let Some(impl_trait_fn) = ty_data.impl_trait_fn { if let Some(node_id) = self.tcx.hir.as_local_node_id(impl_trait_fn) { - self.update(node_id, Some(AccessLevel::Reachable)); + self.update(node_id, Some(AccessLevel::ReachableFromImplTrait)); } } if item.vis.node.is_pub() { self.prev_level } else { None } @@ -240,6 +242,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { hir::ItemKind::ExternCrate(..) => {} } + let orig_level = self.prev_level; + self.prev_level = item_level; + // Mark all items in interfaces of reachable items as reachable match item.node { // The interface is empty @@ -337,9 +342,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { } } - let orig_level = self.prev_level; - self.prev_level = item_level; - intravisit::walk_item(self, item); self.prev_level = orig_level; @@ -475,7 +477,7 @@ impl<'b, 'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> { fn check_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>) { if let Some(node_id) = self.ev.tcx.hir.as_local_node_id(trait_ref.def_id) { let item = self.ev.tcx.hir.expect_item(node_id); - self.ev.update(item.id, Some(AccessLevel::Reachable)); + self.ev.update(item.id, self.access_level); } } } @@ -496,7 +498,7 @@ impl<'b, 'a, 'tcx> TypeVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'b if let Some(def_id) = ty_def_id { if let Some(node_id) = self.ev.tcx.hir.as_local_node_id(def_id) { - self.ev.update(node_id, Some(AccessLevel::Reachable)); + self.ev.update(node_id, self.access_level); } } From 54b096a79913ad23b320d1f878046ae31e460061 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Tue, 21 Aug 2018 01:16:29 +0100 Subject: [PATCH 07/27] Fixes for code review. --- src/librustc/middle/privacy.rs | 1 - .../issue-50865-private-impl-trait/auxiliary/lib.rs | 2 +- src/test/run-pass/issue-50865-private-impl-trait/main.rs | 9 +++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 39ddaca8925e0..70fed9af92128 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -42,7 +42,6 @@ pub struct AccessLevels { impl AccessLevels { pub fn is_reachable(&self, id: Id) -> bool { - // self.map.contains_key(&id) self.map.get(&id) >= Some(&AccessLevel::Reachable) } pub fn is_exported(&self, id: Id) -> bool { diff --git a/src/test/run-pass/issue-50865-private-impl-trait/auxiliary/lib.rs b/src/test/run-pass/issue-50865-private-impl-trait/auxiliary/lib.rs index bf4f13360be16..306256d53d38c 100644 --- a/src/test/run-pass/issue-50865-private-impl-trait/auxiliary/lib.rs +++ b/src/test/run-pass/issue-50865-private-impl-trait/auxiliary/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // diff --git a/src/test/run-pass/issue-50865-private-impl-trait/main.rs b/src/test/run-pass/issue-50865-private-impl-trait/main.rs index 7e92e1079812c..c58e36c65425f 100644 --- a/src/test/run-pass/issue-50865-private-impl-trait/main.rs +++ b/src/test/run-pass/issue-50865-private-impl-trait/main.rs @@ -1,4 +1,4 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -11,7 +11,12 @@ // aux-build:lib.rs // Regression test for #50865. -// FIXME: explain. +// When using generics or specifying the type directly, this example +// codegens `foo` internally. However, when using a private `impl Trait` +// function which references another private item, `foo` (in this case) +// wouldn't be codegenned until main.rs used `bar`, as with impl Trait +// it is not cast to `fn()` automatically to satisfy e.g. +// `fn foo() -> fn() { ... }`. extern crate lib; From 3536359ad8b02933018a7b26f0ad6c3ed6f0c50e Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Tue, 21 Aug 2018 01:50:20 +0100 Subject: [PATCH 08/27] Further fixes. --- src/librustc_privacy/lib.rs | 4 ++-- src/test/run-pass/issue-50865-private-impl-trait/main.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index b6b56cad83906..f6b843bbac52b 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -150,7 +150,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { } fn visit_item(&mut self, item: &'tcx hir::Item) { - debug!("Walked item {:?}", item); + debug!("visit_item({:?})", item); let inherited_item_level = match item.node { // Impls inherit level from their types and traits hir::ItemKind::Impl(..) => { @@ -184,7 +184,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { // Update level of the item itself let item_level = self.update(item.id, inherited_item_level); - debug!("Its privacy is believed to be: {:?}", item_level); + debug!("item_level = {:?}", item_level); // Update levels of nested things match item.node { diff --git a/src/test/run-pass/issue-50865-private-impl-trait/main.rs b/src/test/run-pass/issue-50865-private-impl-trait/main.rs index c58e36c65425f..bc347edf8a765 100644 --- a/src/test/run-pass/issue-50865-private-impl-trait/main.rs +++ b/src/test/run-pass/issue-50865-private-impl-trait/main.rs @@ -16,7 +16,7 @@ // function which references another private item, `foo` (in this case) // wouldn't be codegenned until main.rs used `bar`, as with impl Trait // it is not cast to `fn()` automatically to satisfy e.g. -// `fn foo() -> fn() { ... }`. +// `fn foo() -> fn() { ... }`. extern crate lib; From 17eb64a8b88849282fb9f8b09452b7f2878ca82d Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Tue, 21 Aug 2018 16:29:08 +0530 Subject: [PATCH 09/27] add macro check for lint --- src/librustc_lint/builtin.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index e6aa7c0d16c6a..aa010af9758bc 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -283,7 +283,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode { declare_lint! { pub MISSING_DOCS, Allow, - "detects missing documentation for public members" + "detects missing documentation for public members", + report_in_external_macro: true } pub struct MissingDoc { From a6201f9a2b5c855a6747a8cecdf2f4830ac63f6e Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Wed, 22 Aug 2018 01:13:24 +0530 Subject: [PATCH 10/27] add testcase to existing macro testcase --- src/test/ui/lint/lints-in-foreign-macros.rs | 1 + .../ui/lint/lints-in-foreign-macros.stderr | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/test/ui/lint/lints-in-foreign-macros.rs b/src/test/ui/lint/lints-in-foreign-macros.rs index 0f9003877cc06..34c15b15378de 100644 --- a/src/test/ui/lint/lints-in-foreign-macros.rs +++ b/src/test/ui/lint/lints-in-foreign-macros.rs @@ -12,6 +12,7 @@ // compile-pass #![warn(unused_imports)] +#![warn(missing_docs)] //~ WARN: missing documentation for crate [missing_docs] #[macro_use] extern crate lints_in_foreign_macros; diff --git a/src/test/ui/lint/lints-in-foreign-macros.stderr b/src/test/ui/lint/lints-in-foreign-macros.stderr index e9f6d3d381541..e2df883cd4a73 100644 --- a/src/test/ui/lint/lints-in-foreign-macros.stderr +++ b/src/test/ui/lint/lints-in-foreign-macros.stderr @@ -1,5 +1,5 @@ warning: unused import: `std::string::ToString` - --> $DIR/lints-in-foreign-macros.rs:20:16 + --> $DIR/lints-in-foreign-macros.rs:21:16 | LL | () => {use std::string::ToString;} //~ WARN: unused import | ^^^^^^^^^^^^^^^^^^^^^ @@ -14,14 +14,32 @@ LL | #![warn(unused_imports)] | ^^^^^^^^^^^^^^ warning: unused import: `std::string::ToString` - --> $DIR/lints-in-foreign-macros.rs:25:18 + --> $DIR/lints-in-foreign-macros.rs:26:18 | LL | mod c { baz!(use std::string::ToString;); } //~ WARN: unused import | ^^^^^^^^^^^^^^^^^^^^^ warning: unused import: `std::string::ToString` - --> $DIR/lints-in-foreign-macros.rs:26:19 + --> $DIR/lints-in-foreign-macros.rs:27:19 | LL | mod d { baz2!(use std::string::ToString;); } //~ WARN: unused import | ^^^^^^^^^^^^^^^^^^^^^ +warning: missing documentation for crate + --> $DIR/lints-in-foreign-macros.rs:14:1 + | +LL | / #![warn(unused_imports)] +LL | | #![warn(missing_docs)] //~ WARN: missing documentation for crate [missing_docs] +LL | | +LL | | #[macro_use] +... | +LL | | +LL | | fn main() {} + | |____________^ + | +note: lint level defined here + --> $DIR/lints-in-foreign-macros.rs:15:9 + | +LL | #![warn(missing_docs)] //~ WARN: missing documentation for crate [missing_docs] + | ^^^^^^^^^^^^ + From 11f3918ca2c7913f7976a42539646dc28e86ffcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 22 Aug 2018 08:06:39 +0200 Subject: [PATCH 11/27] docs: std::string::String.repeat(): slightly rephrase to be more in-line with other descriptions. add ticks around a few keywords in other descriptions. --- src/liballoc/str.rs | 2 +- src/liballoc/string.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 870bf971cd3f6..c451a051c74dc 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -513,7 +513,7 @@ impl str { unsafe { String::from_utf8_unchecked(slice.into_vec()) } } - /// Create a [`String`] by repeating a string `n` times. + /// Creates a new [`String`] by repeating a string `n` times. /// /// [`String`]: string/struct.String.html /// diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index eabda7123dec0..aa821abb34cdf 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -752,7 +752,7 @@ impl String { self.vec } - /// Extracts a string slice containing the entire string. + /// Extracts a string slice containing the entire `String`. /// /// # Examples /// @@ -1454,8 +1454,8 @@ impl String { self.vec.clear() } - /// Creates a draining iterator that removes the specified range in the string - /// and yields the removed chars. + /// Creates a draining iterator that removes the specified range in the `String` + /// and yields the removed `chars`. /// /// Note: The element range is removed even if the iterator is not /// consumed until the end. From f07245c041384649e0caeca4555540be94620d80 Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Wed, 22 Aug 2018 09:18:34 +0100 Subject: [PATCH 12/27] Update RELEASES.md --- RELEASES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 088d361b7ea6a..ac7fd5c873756 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -39,6 +39,8 @@ Misc will demote `deny` and `forbid` lints to `warn`. - [`rustc` and `rustdoc` will now have the exit code of `1` if compilation fails, and `101` if there is a panic.][52197] +- [Added a preview of clippy has been made available through rustup][51122] + Install with `rustup component add clippy-preview` Compatibility Notes ------------------- @@ -64,6 +66,7 @@ Compatibility Notes [51619]: https://github.com/rust-lang/rust/pull/51619/ [51656]: https://github.com/rust-lang/rust/pull/51656/ [51178]: https://github.com/rust-lang/rust/pull/51178/ +[51122]: https://github.com/rust-lang/rust/pull/51122 [50494]: https://github.com/rust-lang/rust/pull/50494/ [cargo/5614]: https://github.com/rust-lang/cargo/pull/5614/ [cargo/5723]: https://github.com/rust-lang/cargo/pull/5723/ From c9c4f5ef784069319a36cf75d15dfaa604196071 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 22 Aug 2018 12:15:29 +0100 Subject: [PATCH 13/27] Fix a grammatical mistake in "expected generic arguments" errors --- src/librustc_typeck/astconv.rs | 2 +- .../ui/generic/generic-impl-more-params-with-defaults.stderr | 2 +- .../ui/generic/generic-type-more-params-with-defaults.stderr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index ccdb751bc4eed..3f88bf829a82e 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -371,7 +371,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { quantifier, bound, kind, - if required != 1 { "s" } else { "" }, + if bound != 1 { "s" } else { "" }, ) }; diff --git a/src/test/ui/generic/generic-impl-more-params-with-defaults.stderr b/src/test/ui/generic/generic-impl-more-params-with-defaults.stderr index b614da88ba164..6b54baefb1dd3 100644 --- a/src/test/ui/generic/generic-impl-more-params-with-defaults.stderr +++ b/src/test/ui/generic/generic-impl-more-params-with-defaults.stderr @@ -2,7 +2,7 @@ error[E0244]: wrong number of type arguments: expected at most 2, found 3 --> $DIR/generic-impl-more-params-with-defaults.rs:23:5 | LL | Vec::::new(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected at most 2 type argument + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected at most 2 type arguments error: aborting due to previous error diff --git a/src/test/ui/generic/generic-type-more-params-with-defaults.stderr b/src/test/ui/generic/generic-type-more-params-with-defaults.stderr index f226921816d09..684a22ce45c92 100644 --- a/src/test/ui/generic/generic-type-more-params-with-defaults.stderr +++ b/src/test/ui/generic/generic-type-more-params-with-defaults.stderr @@ -2,7 +2,7 @@ error[E0244]: wrong number of type arguments: expected at most 2, found 3 --> $DIR/generic-type-more-params-with-defaults.rs:19:12 | LL | let _: Vec; - | ^^^^^^^^^^^^^^^^^^^^^^ expected at most 2 type argument + | ^^^^^^^^^^^^^^^^^^^^^^ expected at most 2 type arguments error: aborting due to previous error From 276253e66a4df8495a7ab6bb08d8d4f24e1d2d90 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 22 Aug 2018 21:17:58 +0200 Subject: [PATCH 14/27] update nomicon and book --- src/doc/book | 2 +- src/doc/nomicon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/book b/src/doc/book index 88cdde350fd3a..16c9dee7666c2 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 88cdde350fd3a90c93f3bac8b4f168f105d28060 +Subproject commit 16c9dee7666c2b2766fd98d89003e028679d1207 diff --git a/src/doc/nomicon b/src/doc/nomicon index 790e96b87f4b5..ae42ad7aa4d79 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit 790e96b87f4b5817cac310e73a524d25c3d076d8 +Subproject commit ae42ad7aa4d7907cca941371c9eee8de8c2ee40d From 200c6d9fb58ceafd8a6f3742382f9fce122bb157 Mon Sep 17 00:00:00 2001 From: Aaron Power Date: Wed, 22 Aug 2018 21:18:31 +0100 Subject: [PATCH 15/27] Update RELEASES.md --- RELEASES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index ac7fd5c873756..7e727e0d41bb3 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -39,8 +39,8 @@ Misc will demote `deny` and `forbid` lints to `warn`. - [`rustc` and `rustdoc` will now have the exit code of `1` if compilation fails, and `101` if there is a panic.][52197] -- [Added a preview of clippy has been made available through rustup][51122] - Install with `rustup component add clippy-preview` +- [A preview of clippy has been made available through rustup.][51122] + You can install the preview with `rustup component add clippy-preview` Compatibility Notes ------------------- From 8fbcb9c53c208f5482959474b44605935d797ccf Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Thu, 23 Aug 2018 01:56:39 +0530 Subject: [PATCH 16/27] add warning for missing docs --- src/test/ui/lint/lints-in-foreign-macros.rs | 3 ++- src/test/ui/lint/lints-in-foreign-macros.stderr | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/ui/lint/lints-in-foreign-macros.rs b/src/test/ui/lint/lints-in-foreign-macros.rs index 34c15b15378de..2ad1cfe71682c 100644 --- a/src/test/ui/lint/lints-in-foreign-macros.rs +++ b/src/test/ui/lint/lints-in-foreign-macros.rs @@ -12,7 +12,7 @@ // compile-pass #![warn(unused_imports)] -#![warn(missing_docs)] //~ WARN: missing documentation for crate [missing_docs] +#![warn(missing_docs)] #[macro_use] extern crate lints_in_foreign_macros; @@ -25,5 +25,6 @@ mod a { foo!(); } mod b { bar!(); } mod c { baz!(use std::string::ToString;); } //~ WARN: unused import mod d { baz2!(use std::string::ToString;); } //~ WARN: unused import +mod e { baz!(pub fn undocumented() {}); }//~ WARN: missing documentation for a function fn main() {} diff --git a/src/test/ui/lint/lints-in-foreign-macros.stderr b/src/test/ui/lint/lints-in-foreign-macros.stderr index e2df883cd4a73..4a75e1d907dc8 100644 --- a/src/test/ui/lint/lints-in-foreign-macros.stderr +++ b/src/test/ui/lint/lints-in-foreign-macros.stderr @@ -29,17 +29,17 @@ warning: missing documentation for crate --> $DIR/lints-in-foreign-macros.rs:14:1 | LL | / #![warn(unused_imports)] -LL | | #![warn(missing_docs)] //~ WARN: missing documentation for crate [missing_docs] +LL | | #![warn(missing_docs)] LL | | LL | | #[macro_use] ... | LL | | -LL | | fn main() {} +LL | | fn main() {} //~ WARN: missing documentation for crate [missing_docs] | |____________^ | note: lint level defined here --> $DIR/lints-in-foreign-macros.rs:15:9 | -LL | #![warn(missing_docs)] //~ WARN: missing documentation for crate [missing_docs] +LL | #![warn(missing_docs)] | ^^^^^^^^^^^^ From a15b61780b24a2311a3e42a3437b3418921a3ed3 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 22 Aug 2018 15:18:45 -0700 Subject: [PATCH 17/27] tidy: Stop requiring a license header Previously approved in rust-lang/rust#43498 ; update tidy to match. --- src/tools/tidy/src/style.rs | 53 ------------------------------------- 1 file changed, 53 deletions(-) diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index f2f35f0f58602..6b431ccda0883 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -17,7 +17,6 @@ //! * No trailing whitespace //! * No CR characters //! * No `TODO` or `XXX` directives -//! * A valid license header is at the top //! * No unexplained ` ```ignore ` or ` ```rust,ignore ` doc tests //! //! A number of these checks can be opted-out of with various directives like @@ -28,16 +27,6 @@ use std::io::prelude::*; use std::path::Path; const COLS: usize = 100; -const LICENSE: &'static str = "\ -Copyright The Rust Project Developers. See the COPYRIGHT -file at the top-level directory of this distribution and at -http://rust-lang.org/COPYRIGHT. - -Licensed under the Apache License, Version 2.0 or the MIT license -, at your -option. This file may not be copied, modified, or distributed -except according to those terms."; const UNEXPLAINED_IGNORE_DOCTEST_INFO: &str = r#"unexplained "```ignore" doctest; try one: @@ -168,9 +157,6 @@ pub fn check(path: &Path, bad: &mut bool) { trailing_new_lines = 0; } } - if !licenseck(file, &contents) { - tidy_error!(bad, "{}: incorrect license", file.display()); - } match trailing_new_lines { 0 => tidy_error!(bad, "{}: missing trailing newline", file.display()), 1 | 2 => {} @@ -178,42 +164,3 @@ pub fn check(path: &Path, bad: &mut bool) { }; }) } - -fn licenseck(file: &Path, contents: &str) -> bool { - if contents.contains("ignore-license") { - return true - } - let exceptions = [ - "libstd/sync/mpsc/mpsc_queue.rs", - "libstd/sync/mpsc/spsc_queue.rs", - ]; - if exceptions.iter().any(|f| file.ends_with(f)) { - return true - } - - // Skip the BOM if it's there - let bom = "\u{feff}"; - let contents = if contents.starts_with(bom) {&contents[3..]} else {contents}; - - // See if the license shows up in the first 100 lines - let lines = contents.lines().take(100).collect::>(); - lines.windows(LICENSE.lines().count()).any(|window| { - let offset = if window.iter().all(|w| w.starts_with("//")) { - 2 - } else if window.iter().all(|w| w.starts_with('#')) { - 1 - } else if window.iter().all(|w| w.starts_with(" *")) { - 2 - } else { - return false - }; - window.iter().map(|a| a[offset..].trim()) - .zip(LICENSE.lines()).all(|(a, b)| { - a == b || match b.find("") { - Some(i) => a.starts_with(&b[..i]) && a.ends_with(&b[i+6..]), - None => false, - } - }) - }) - -} From b188c2a4eb7a3eede8477e3fbeaea623fc256586 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 21 Aug 2018 14:44:36 +0100 Subject: [PATCH 18/27] Lament the invincibility of the Turbofish --- src/test/ui/bastion-of-the-turbofish.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/ui/bastion-of-the-turbofish.rs b/src/test/ui/bastion-of-the-turbofish.rs index bd789737552c1..eadd23896095d 100644 --- a/src/test/ui/bastion-of-the-turbofish.rs +++ b/src/test/ui/bastion-of-the-turbofish.rs @@ -36,6 +36,10 @@ // My heart aches in sorrow, for I know I am defeated. Let this be a warning // to all those who come after. Here stands the bastion of the Turbofish. +// See https://github.com/rust-lang/rust/pull/53562 +// and https://github.com/rust-lang/rfcs/pull/2527 +// for context. + fn main() { let (oh, woe, is, me) = ("the", "Turbofish", "remains", "undefeated"); let _: (bool, bool) = (oh(me)); From ede1f7d2a5a2f4038e3f3b2e953c44ee5ea06194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Thu, 23 Aug 2018 10:14:52 +0200 Subject: [PATCH 19/27] use String::new() instead of String::from(""), "".to_string(), "".to_owned() or "".into() --- src/librustc/infer/error_reporting/mod.rs | 2 +- src/librustc/mir/mod.rs | 2 +- src/librustc/session/config.rs | 6 +++--- src/librustc/traits/error_reporting.rs | 6 +++--- src/librustc/traits/select.rs | 4 ++-- src/librustc/util/common.rs | 2 +- src/librustc/util/profiling.rs | 2 +- src/librustc_borrowck/borrowck/unused.rs | 2 +- src/librustc_borrowck/dataflow.rs | 6 +++--- src/librustc_borrowck/graphviz.rs | 2 +- .../debuginfo/metadata.rs | 4 ++-- src/librustc_driver/profile/trace.rs | 2 +- src/librustc_errors/emitter.rs | 6 +++--- src/librustc_lint/builtin.rs | 4 ++-- src/librustc_mir/borrow_check/mod.rs | 2 +- .../borrow_check/mutability_errors.rs | 4 ++-- src/librustc_mir/util/borrowck_errors.rs | 2 +- src/librustc_resolve/resolve_imports.rs | 2 +- src/librustc_save_analysis/lib.rs | 2 +- src/librustc_target/spec/aarch64_apple_ios.rs | 2 +- src/librustc_target/spec/aarch64_fuchsia.rs | 4 ++-- .../spec/aarch64_linux_android.rs | 2 +- .../spec/aarch64_unknown_cloudabi.rs | 2 +- .../spec/aarch64_unknown_freebsd.rs | 2 +- .../spec/aarch64_unknown_hermit.rs | 2 +- .../spec/aarch64_unknown_netbsd.rs | 2 +- .../spec/aarch64_unknown_none.rs | 4 ++-- .../spec/aarch64_unknown_openbsd.rs | 2 +- .../spec/arm_linux_androideabi.rs | 2 +- .../spec/armebv7r_none_eabihf.rs | 4 ++-- src/librustc_target/spec/armv7_apple_ios.rs | 2 +- .../spec/armv7_linux_androideabi.rs | 2 +- .../spec/armv7_unknown_cloudabi_eabihf.rs | 2 +- src/librustc_target/spec/armv7s_apple_ios.rs | 2 +- .../spec/asmjs_unknown_emscripten.rs | 2 +- src/librustc_target/spec/i386_apple_ios.rs | 2 +- src/librustc_target/spec/i686_apple_darwin.rs | 2 +- .../spec/i686_linux_android.rs | 2 +- .../spec/i686_unknown_cloudabi.rs | 2 +- .../spec/i686_unknown_dragonfly.rs | 2 +- .../spec/i686_unknown_freebsd.rs | 2 +- .../spec/i686_unknown_haiku.rs | 2 +- .../spec/i686_unknown_netbsd.rs | 2 +- .../spec/i686_unknown_openbsd.rs | 2 +- src/librustc_target/spec/mod.rs | 4 ++-- src/librustc_target/spec/msp430_none_elf.rs | 4 ++-- .../spec/powerpc_unknown_netbsd.rs | 2 +- .../spec/riscv32imac_unknown_none_elf.rs | 2 +- .../spec/sparc64_unknown_netbsd.rs | 2 +- .../spec/sparcv9_sun_solaris.rs | 2 +- .../spec/thumbv6m_none_eabi.rs | 4 ++-- .../spec/thumbv7em_none_eabi.rs | 4 ++-- .../spec/thumbv7em_none_eabihf.rs | 4 ++-- .../spec/thumbv7m_none_eabi.rs | 4 ++-- .../spec/wasm32_experimental_emscripten.rs | 2 +- .../spec/wasm32_unknown_emscripten.rs | 2 +- .../spec/wasm32_unknown_unknown.rs | 4 ++-- src/librustc_target/spec/windows_base.rs | 4 ++-- src/librustc_target/spec/windows_msvc_base.rs | 4 ++-- .../spec/x86_64_apple_darwin.rs | 2 +- src/librustc_target/spec/x86_64_apple_ios.rs | 2 +- src/librustc_target/spec/x86_64_fuchsia.rs | 4 ++-- .../spec/x86_64_linux_android.rs | 2 +- .../spec/x86_64_rumprun_netbsd.rs | 2 +- .../spec/x86_64_sun_solaris.rs | 2 +- .../spec/x86_64_unknown_bitrig.rs | 2 +- .../spec/x86_64_unknown_cloudabi.rs | 2 +- .../spec/x86_64_unknown_dragonfly.rs | 2 +- .../spec/x86_64_unknown_freebsd.rs | 2 +- .../spec/x86_64_unknown_haiku.rs | 2 +- .../spec/x86_64_unknown_hermit.rs | 2 +- .../spec/x86_64_unknown_netbsd.rs | 2 +- .../spec/x86_64_unknown_openbsd.rs | 2 +- .../spec/x86_64_unknown_redox.rs | 2 +- src/librustc_typeck/check/mod.rs | 4 ++-- src/librustc_typeck/check_unused.rs | 2 +- src/librustdoc/clean/mod.rs | 20 +++++++++---------- src/librustdoc/html/format.rs | 2 +- src/librustdoc/html/layout.rs | 6 +++--- src/librustdoc/html/render.rs | 8 ++++---- src/libsyntax/ext/source_util.rs | 2 +- src/libsyntax/parse/lexer/comments.rs | 2 +- src/libsyntax/parse/parser.rs | 14 ++++++------- src/libsyntax/source_map.rs | 2 +- src/libtest/formatters/json.rs | 2 +- src/tools/compiletest/src/header.rs | 2 +- src/tools/tidy/src/features.rs | 2 +- 87 files changed, 133 insertions(+), 133 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 02da3701db297..b05ea9a5ed4b0 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1330,7 +1330,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { s }; let var_description = match var_origin { - infer::MiscVariable(_) => "".to_string(), + infer::MiscVariable(_) => String::new(), infer::PatternRegion(_) => " for pattern".to_string(), infer::AddrOfRegion(_) => " for borrow expression".to_string(), infer::Autoref(_) => " for autoref".to_string(), diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 66a42cfb11a74..2ede575c73996 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2105,7 +2105,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { region } else { // Do not even print 'static - "".to_owned() + String::new() }; write!(fmt, "&{}{}{:?}", region, kind_str, place) } diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index d594678625288..a58bb4724d2e2 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1051,7 +1051,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, "perform LLVM link-time optimizations"), target_cpu: Option = (None, parse_opt_string, [TRACKED], "select target processor (rustc --print target-cpus for details)"), - target_feature: String = ("".to_string(), parse_string, [TRACKED], + target_feature: String = (String::new(), parse_string, [TRACKED], "target specific attributes (rustc --print target-features for details)"), passes: Vec = (Vec::new(), parse_list, [TRACKED], "a list of extra LLVM passes to run (space separated)"), @@ -1085,7 +1085,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, "choose the code model to use (rustc --print code-models for details)"), metadata: Vec = (Vec::new(), parse_list, [TRACKED], "metadata to mangle symbol names with"), - extra_filename: String = ("".to_string(), parse_string, [UNTRACKED], + extra_filename: String = (String::new(), parse_string, [UNTRACKED], "extra data to put in each output filename"), codegen_units: Option = (None, parse_opt_uint, [UNTRACKED], "divide crate into N units to optimize in parallel"), @@ -1992,7 +1992,7 @@ pub fn build_session_options_and_crate_config( }; if cg.target_feature == "help" { prints.push(PrintRequest::TargetFeatures); - cg.target_feature = "".to_string(); + cg.target_feature = String::new(); } if cg.relocation_model.as_ref().map_or(false, |s| s == "help") { prints.push(PrintRequest::RelocationModels); diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 0aa15a4ae0c25..405b320f3feaf 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -472,7 +472,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { if len > 5 { format!("\nand {} others", len - 4) } else { - "".to_owned() + String::new() } )); } @@ -917,7 +917,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { remove_refs); err.span_suggestion_short_with_applicability( - sp, &format_str, String::from(""), Applicability::MachineApplicable + sp, &format_str, String::new(), Applicability::MachineApplicable ); break; } @@ -1116,7 +1116,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { .collect::>() .join(", ")) } else { - "".to_owned() + String::new() }, ); err.span_suggestion_with_applicability( diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index dd383732bf827..69bdeec6eea23 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -120,13 +120,13 @@ impl IntercrateAmbiguityCause { &IntercrateAmbiguityCause::DownstreamCrate { ref trait_desc, ref self_desc } => { let self_desc = if let &Some(ref ty) = self_desc { format!(" for type `{}`", ty) - } else { "".to_string() }; + } else { String::new() }; format!("downstream crates may implement trait `{}`{}", trait_desc, self_desc) } &IntercrateAmbiguityCause::UpstreamCrateUpdate { ref trait_desc, ref self_desc } => { let self_desc = if let &Some(ref ty) = self_desc { format!(" for type `{}`", ty) - } else { "".to_string() }; + } else { String::new() }; format!("upstream crates may add new impl of trait `{}`{} \ in future versions", trait_desc, self_desc) diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 1ec025f78c9ac..bdfba7c3e3a37 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -213,7 +213,7 @@ fn print_time_passes_entry_internal(what: &str, dur: Duration) { let mb = n as f64 / 1_000_000.0; format!("; rss: {}MB", mb.round() as usize) } - None => "".to_owned(), + None => String::new(), }; println!("{}time: {}{}\t{}", " ".repeat(indentation), diff --git a/src/librustc/util/profiling.rs b/src/librustc/util/profiling.rs index 447b75e547f01..74ff1a5f4fd0d 100644 --- a/src/librustc/util/profiling.rs +++ b/src/librustc/util/profiling.rs @@ -73,7 +73,7 @@ macro_rules! define_categories { (format!("{:.2}", (((hits as f32) / (total as f32)) * 100.0)), total.to_string()) } else { - ("".into(), "".into()) + (String::new(), String::new()) }; writeln!( diff --git a/src/librustc_borrowck/borrowck/unused.rs b/src/librustc_borrowck/borrowck/unused.rs index b8d6df368d478..f10361cb076bd 100644 --- a/src/librustc_borrowck/borrowck/unused.rs +++ b/src/librustc_borrowck/borrowck/unused.rs @@ -87,7 +87,7 @@ impl<'a, 'tcx> UnusedMutCx<'a, 'tcx> { .span_suggestion_short_with_applicability( mut_span, "remove this `mut`", - "".to_owned(), + String::new(), Applicability::MachineApplicable) .emit(); } diff --git a/src/librustc_borrowck/dataflow.rs b/src/librustc_borrowck/dataflow.rs index 75dee2b78fddb..640c23ebf9ddc 100644 --- a/src/librustc_borrowck/dataflow.rs +++ b/src/librustc_borrowck/dataflow.rs @@ -140,21 +140,21 @@ impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O let gens_str = if gens.iter().any(|&u| u != 0) { format!(" gen: {}", bits_to_string(gens)) } else { - "".to_string() + String::new() }; let action_kills = &self.action_kills[start .. end]; let action_kills_str = if action_kills.iter().any(|&u| u != 0) { format!(" action_kill: {}", bits_to_string(action_kills)) } else { - "".to_string() + String::new() }; let scope_kills = &self.scope_kills[start .. end]; let scope_kills_str = if scope_kills.iter().any(|&u| u != 0) { format!(" scope_kill: {}", bits_to_string(scope_kills)) } else { - "".to_string() + String::new() }; ps.synth_comment( diff --git a/src/librustc_borrowck/graphviz.rs b/src/librustc_borrowck/graphviz.rs index dddd6a354c115..c177ed85c3482 100644 --- a/src/librustc_borrowck/graphviz.rs +++ b/src/librustc_borrowck/graphviz.rs @@ -53,7 +53,7 @@ impl<'a, 'tcx> DataflowLabeller<'a, 'tcx> { fn dataflow_for(&self, e: EntryOrExit, n: &Node<'a>) -> String { let id = n.1.data.id(); debug!("dataflow_for({:?}, id={:?}) {:?}", e, id, self.variants); - let mut sets = "".to_string(); + let mut sets = String::new(); let mut seen_one = false; for &variant in &self.variants { if seen_one { sets.push_str(" "); } else { seen_one = true; } diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index c7a515016c01b..0221cfd9b2c28 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -1191,7 +1191,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { member_descriptions); vec![ MemberDescription { - name: "".to_string(), + name: String::new(), type_metadata: variant_type_metadata, offset: Size::ZERO, size: self.layout.size, @@ -1220,7 +1220,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { variant_type_metadata, member_descriptions); MemberDescription { - name: "".to_string(), + name: String::new(), type_metadata: variant_type_metadata, offset: Size::ZERO, size: variant.size, diff --git a/src/librustc_driver/profile/trace.rs b/src/librustc_driver/profile/trace.rs index f31111e37ba08..56cb3e9dbb829 100644 --- a/src/librustc_driver/profile/trace.rs +++ b/src/librustc_driver/profile/trace.rs @@ -85,7 +85,7 @@ pub fn html_of_effect(eff: &Effect) -> (String, String) { fn html_of_duration(_start: &Instant, dur: &Duration) -> (String, String) { use rustc::util::common::duration_to_secs_str; (duration_to_secs_str(dur.clone()), - "".to_string() + String::new() ) } diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index b4034a6a529bd..c08cf3d039df5 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -798,7 +798,7 @@ impl EmitterWriter { // at by "in this macro invocation" format!(" (#{})", i + 1) } else { - "".to_string() + String::new() }))); } // Check to make sure we're not in any <*macros> @@ -813,7 +813,7 @@ impl EmitterWriter { // backtrace is multiple levels deep format!(" (#{})", i + 1) } else { - "".to_string() + String::new() }))); if !always_backtrace { break; @@ -1065,7 +1065,7 @@ impl EmitterWriter { let col = if let Some(first_annotation) = first_line.annotations.first() { format!(":{}", first_annotation.start_col + 1) } else { - "".to_string() + String::new() }; format!("{}:{}{}", annotated_file.file.name, diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index c26d8555214c1..4922e7910544b 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -794,7 +794,7 @@ impl EarlyLintPass for DeprecatedAttr { err.span_suggestion_short_with_applicability( attr.span, "remove this attribute", - "".to_owned(), + String::new(), Applicability::MachineApplicable ); err.emit(); @@ -1250,7 +1250,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems { err.span_suggestion_short_with_applicability( no_mangle_attr.span, "remove this attribute", - "".to_owned(), + String::new(), // Use of `#[no_mangle]` suggests FFI intent; correct // fix may be to monomorphize source by hand Applicability::MaybeIncorrect diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index f96f612734904..31ca324443474 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -327,7 +327,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( err.span_suggestion_short_with_applicability( mut_span, "remove this `mut`", - "".to_owned(), + String::new(), Applicability::MachineApplicable); err.buffer(&mut mbcx.errors_buffer); diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index 05d6f49d97c6c..251586cd7949d 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -128,7 +128,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } } else { item_msg = format!("data in a {}", pointer_type); - reason = "".to_string(); + reason = String::new(); } } } @@ -138,7 +138,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { Place::Static(box Static { def_id, ty: _ }) => { if let Place::Static(_) = access_place { item_msg = format!("immutable static item `{}`", access_place_desc.unwrap()); - reason = "".to_string(); + reason = String::new(); } else { item_msg = format!("`{}`", access_place_desc.unwrap()); let static_name = &self.tcx.item_name(*def_id); diff --git a/src/librustc_mir/util/borrowck_errors.rs b/src/librustc_mir/util/borrowck_errors.rs index 1c5e1e406911a..b67780ccdbc10 100644 --- a/src/librustc_mir/util/borrowck_errors.rs +++ b/src/librustc_mir/util/borrowck_errors.rs @@ -474,7 +474,7 @@ pub trait BorrowckErrors<'cx>: Sized + Copy { ) -> DiagnosticBuilder<'cx> { let moved_path = moved_path .map(|mp| format!(": `{}`", mp)) - .unwrap_or("".to_owned()); + .unwrap_or(String::new()); let err = struct_span_err!( self, diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 87e30be7caaaf..c60f9293d58e7 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -994,7 +994,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> { let lev_suggestion = match find_best_match_for_name(names, &ident.as_str(), None) { Some(name) => format!(". Did you mean to use `{}`?", name), - None => "".to_owned(), + None => String::new(), }; let msg = match module { ModuleOrUniformRoot::Module(module) => { diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 9facd39ebea21..1549634e9b590 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -1050,7 +1050,7 @@ impl<'a> DumpHandler<'a> { .iter() .any(|ct| *ct == CrateType::Executable); let mut out_name = if executable { - "".to_owned() + String::new() } else { "lib".to_owned() }; diff --git a/src/librustc_target/spec/aarch64_apple_ios.rs b/src/librustc_target/spec/aarch64_apple_ios.rs index 90f8cd90c66ec..16dd27887faad 100644 --- a/src/librustc_target/spec/aarch64_apple_ios.rs +++ b/src/librustc_target/spec/aarch64_apple_ios.rs @@ -21,7 +21,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "ios".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "apple".to_string(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/aarch64_fuchsia.rs b/src/librustc_target/spec/aarch64_fuchsia.rs index 28baf6f66e7a1..8f7ee11d575ee 100644 --- a/src/librustc_target/spec/aarch64_fuchsia.rs +++ b/src/librustc_target/spec/aarch64_fuchsia.rs @@ -22,8 +22,8 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "fuchsia".to_string(), - target_env: "".to_string(), - target_vendor: "".to_string(), + target_env: String::new(), + target_vendor: String::new(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { abi_blacklist: super::arm_base::abi_blacklist(), diff --git a/src/librustc_target/spec/aarch64_linux_android.rs b/src/librustc_target/spec/aarch64_linux_android.rs index afd67112f0d6a..540aac2c33832 100644 --- a/src/librustc_target/spec/aarch64_linux_android.rs +++ b/src/librustc_target/spec/aarch64_linux_android.rs @@ -27,7 +27,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "android".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/aarch64_unknown_cloudabi.rs b/src/librustc_target/spec/aarch64_unknown_cloudabi.rs index ffdb7decd0b47..087b0fa543f0d 100644 --- a/src/librustc_target/spec/aarch64_unknown_cloudabi.rs +++ b/src/librustc_target/spec/aarch64_unknown_cloudabi.rs @@ -24,7 +24,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "cloudabi".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/aarch64_unknown_freebsd.rs b/src/librustc_target/spec/aarch64_unknown_freebsd.rs index 48177b8c79aed..541f0564a01e2 100644 --- a/src/librustc_target/spec/aarch64_unknown_freebsd.rs +++ b/src/librustc_target/spec/aarch64_unknown_freebsd.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "freebsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/aarch64_unknown_hermit.rs b/src/librustc_target/spec/aarch64_unknown_hermit.rs index 6b81c62e48b87..32fb7002026eb 100644 --- a/src/librustc_target/spec/aarch64_unknown_hermit.rs +++ b/src/librustc_target/spec/aarch64_unknown_hermit.rs @@ -24,7 +24,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "hermit".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/aarch64_unknown_netbsd.rs b/src/librustc_target/spec/aarch64_unknown_netbsd.rs index c300855b02187..c4afd1143fc21 100644 --- a/src/librustc_target/spec/aarch64_unknown_netbsd.rs +++ b/src/librustc_target/spec/aarch64_unknown_netbsd.rs @@ -23,7 +23,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "netbsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/aarch64_unknown_none.rs b/src/librustc_target/spec/aarch64_unknown_none.rs index cfba0614adcd6..1cf214d09cc7c 100644 --- a/src/librustc_target/spec/aarch64_unknown_none.rs +++ b/src/librustc_target/spec/aarch64_unknown_none.rs @@ -36,8 +36,8 @@ pub fn target() -> Result { target_pointer_width: "64".to_string(), target_c_int_width: "32".to_string(), target_os: "none".to_string(), - target_env: "".to_string(), - target_vendor: "".to_string(), + target_env: String::new(), + target_vendor: String::new(), data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), diff --git a/src/librustc_target/spec/aarch64_unknown_openbsd.rs b/src/librustc_target/spec/aarch64_unknown_openbsd.rs index 25817fce5ce6c..81c24fa10fac6 100644 --- a/src/librustc_target/spec/aarch64_unknown_openbsd.rs +++ b/src/librustc_target/spec/aarch64_unknown_openbsd.rs @@ -23,7 +23,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "openbsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/arm_linux_androideabi.rs b/src/librustc_target/spec/arm_linux_androideabi.rs index ffd242b2bc20e..c5e3385a91ca1 100644 --- a/src/librustc_target/spec/arm_linux_androideabi.rs +++ b/src/librustc_target/spec/arm_linux_androideabi.rs @@ -24,7 +24,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "android".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/armebv7r_none_eabihf.rs b/src/librustc_target/spec/armebv7r_none_eabihf.rs index 8bd08d355a7bc..c111d2ffe8b4a 100644 --- a/src/librustc_target/spec/armebv7r_none_eabihf.rs +++ b/src/librustc_target/spec/armebv7r_none_eabihf.rs @@ -22,8 +22,8 @@ pub fn target() -> TargetResult { data_layout: "E-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "none".to_string(), - target_env: "".to_string(), - target_vendor: "".to_string(), + target_env: String::new(), + target_vendor: String::new(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/armv7_apple_ios.rs b/src/librustc_target/spec/armv7_apple_ios.rs index da7cbb918bd71..0f7b2ad7630e8 100644 --- a/src/librustc_target/spec/armv7_apple_ios.rs +++ b/src/librustc_target/spec/armv7_apple_ios.rs @@ -21,7 +21,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(), arch: "arm".to_string(), target_os: "ios".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "apple".to_string(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/armv7_linux_androideabi.rs b/src/librustc_target/spec/armv7_linux_androideabi.rs index cfdc5cddcfb30..06abe0b2c9e4f 100644 --- a/src/librustc_target/spec/armv7_linux_androideabi.rs +++ b/src/librustc_target/spec/armv7_linux_androideabi.rs @@ -28,7 +28,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "android".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/armv7_unknown_cloudabi_eabihf.rs b/src/librustc_target/spec/armv7_unknown_cloudabi_eabihf.rs index 393c45e434e61..44e611f04b48e 100644 --- a/src/librustc_target/spec/armv7_unknown_cloudabi_eabihf.rs +++ b/src/librustc_target/spec/armv7_unknown_cloudabi_eabihf.rs @@ -26,7 +26,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "cloudabi".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/armv7s_apple_ios.rs b/src/librustc_target/spec/armv7s_apple_ios.rs index c0c577c3b8c6c..a5f35d0a77367 100644 --- a/src/librustc_target/spec/armv7s_apple_ios.rs +++ b/src/librustc_target/spec/armv7s_apple_ios.rs @@ -21,7 +21,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(), arch: "arm".to_string(), target_os: "ios".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "apple".to_string(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/asmjs_unknown_emscripten.rs b/src/librustc_target/spec/asmjs_unknown_emscripten.rs index 4e716fb207fab..da70a3ad04d46 100644 --- a/src/librustc_target/spec/asmjs_unknown_emscripten.rs +++ b/src/librustc_target/spec/asmjs_unknown_emscripten.rs @@ -40,7 +40,7 @@ pub fn target() -> Result { target_pointer_width: "32".to_string(), target_c_int_width: "32".to_string(), target_os: "emscripten".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), data_layout: "e-p:32:32-i64:64-v128:32:128-n32-S128".to_string(), arch: "asmjs".to_string(), diff --git a/src/librustc_target/spec/i386_apple_ios.rs b/src/librustc_target/spec/i386_apple_ios.rs index 9eb0327f625cc..15fd384f9ced3 100644 --- a/src/librustc_target/spec/i386_apple_ios.rs +++ b/src/librustc_target/spec/i386_apple_ios.rs @@ -21,7 +21,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "ios".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "apple".to_string(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/i686_apple_darwin.rs b/src/librustc_target/spec/i686_apple_darwin.rs index d17789dfcc07f..a298b550fea65 100644 --- a/src/librustc_target/spec/i686_apple_darwin.rs +++ b/src/librustc_target/spec/i686_apple_darwin.rs @@ -26,7 +26,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "macos".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "apple".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/i686_linux_android.rs b/src/librustc_target/spec/i686_linux_android.rs index 171e089959545..6aa139893eba1 100644 --- a/src/librustc_target/spec/i686_linux_android.rs +++ b/src/librustc_target/spec/i686_linux_android.rs @@ -31,7 +31,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "android".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/i686_unknown_cloudabi.rs b/src/librustc_target/spec/i686_unknown_cloudabi.rs index 335105bb1a869..637bca71add71 100644 --- a/src/librustc_target/spec/i686_unknown_cloudabi.rs +++ b/src/librustc_target/spec/i686_unknown_cloudabi.rs @@ -26,7 +26,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "cloudabi".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/i686_unknown_dragonfly.rs b/src/librustc_target/spec/i686_unknown_dragonfly.rs index cb0c471353b30..fa02f0dd63451 100644 --- a/src/librustc_target/spec/i686_unknown_dragonfly.rs +++ b/src/librustc_target/spec/i686_unknown_dragonfly.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "dragonfly".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/i686_unknown_freebsd.rs b/src/librustc_target/spec/i686_unknown_freebsd.rs index 3838a157d10b5..e11a455911d75 100644 --- a/src/librustc_target/spec/i686_unknown_freebsd.rs +++ b/src/librustc_target/spec/i686_unknown_freebsd.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "freebsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/i686_unknown_haiku.rs b/src/librustc_target/spec/i686_unknown_haiku.rs index 98f0787bebaf8..775d80b0cfd7e 100644 --- a/src/librustc_target/spec/i686_unknown_haiku.rs +++ b/src/librustc_target/spec/i686_unknown_haiku.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "haiku".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/i686_unknown_netbsd.rs b/src/librustc_target/spec/i686_unknown_netbsd.rs index d60ed9885991d..a9c0c11aab5c6 100644 --- a/src/librustc_target/spec/i686_unknown_netbsd.rs +++ b/src/librustc_target/spec/i686_unknown_netbsd.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "netbsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/i686_unknown_openbsd.rs b/src/librustc_target/spec/i686_unknown_openbsd.rs index f22bf2abe4501..471d6bd475603 100644 --- a/src/librustc_target/spec/i686_unknown_openbsd.rs +++ b/src/librustc_target/spec/i686_unknown_openbsd.rs @@ -26,7 +26,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "openbsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 4a8ae69b2383e..7608ccab66f3d 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -686,7 +686,7 @@ impl Default for TargetOptions { post_link_args: LinkArgs::new(), asm_args: Vec::new(), cpu: "generic".to_string(), - features: "".to_string(), + features: String::new(), dynamic_linking: false, only_cdylib: false, executables: false, @@ -698,7 +698,7 @@ impl Default for TargetOptions { function_sections: true, dll_prefix: "lib".to_string(), dll_suffix: ".so".to_string(), - exe_suffix: "".to_string(), + exe_suffix: String::new(), staticlib_prefix: "lib".to_string(), staticlib_suffix: ".a".to_string(), target_family: None, diff --git a/src/librustc_target/spec/msp430_none_elf.rs b/src/librustc_target/spec/msp430_none_elf.rs index 3ac4c459c6384..0958a95898693 100644 --- a/src/librustc_target/spec/msp430_none_elf.rs +++ b/src/librustc_target/spec/msp430_none_elf.rs @@ -19,8 +19,8 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16".to_string(), arch: "msp430".to_string(), target_os: "none".to_string(), - target_env: "".to_string(), - target_vendor: "".to_string(), + target_env: String::new(), + target_vendor: String::new(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/powerpc_unknown_netbsd.rs b/src/librustc_target/spec/powerpc_unknown_netbsd.rs index c05e40b9c25d7..740222c960805 100644 --- a/src/librustc_target/spec/powerpc_unknown_netbsd.rs +++ b/src/librustc_target/spec/powerpc_unknown_netbsd.rs @@ -26,7 +26,7 @@ pub fn target() -> TargetResult { data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), arch: "powerpc".to_string(), target_os: "netbsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/riscv32imac_unknown_none_elf.rs b/src/librustc_target/spec/riscv32imac_unknown_none_elf.rs index f8cd1b5b81207..ce56cdd44bb2f 100644 --- a/src/librustc_target/spec/riscv32imac_unknown_none_elf.rs +++ b/src/librustc_target/spec/riscv32imac_unknown_none_elf.rs @@ -19,7 +19,7 @@ pub fn target() -> TargetResult { target_pointer_width: "32".to_string(), target_c_int_width: "32".to_string(), target_os: "none".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), arch: "riscv32".to_string(), linker_flavor: LinkerFlavor::Ld, diff --git a/src/librustc_target/spec/sparc64_unknown_netbsd.rs b/src/librustc_target/spec/sparc64_unknown_netbsd.rs index 1c1bca9b2b879..c663aa344daf8 100644 --- a/src/librustc_target/spec/sparc64_unknown_netbsd.rs +++ b/src/librustc_target/spec/sparc64_unknown_netbsd.rs @@ -24,7 +24,7 @@ pub fn target() -> TargetResult { data_layout: "E-m:e-i64:64-n32:64-S128".to_string(), arch: "sparc64".to_string(), target_os: "netbsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/sparcv9_sun_solaris.rs b/src/librustc_target/spec/sparcv9_sun_solaris.rs index 7dea1b75a3c58..8bc233107b8bb 100644 --- a/src/librustc_target/spec/sparcv9_sun_solaris.rs +++ b/src/librustc_target/spec/sparcv9_sun_solaris.rs @@ -30,7 +30,7 @@ pub fn target() -> TargetResult { // just be confusing. arch: "sparc64".to_string(), target_os: "solaris".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "sun".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/thumbv6m_none_eabi.rs b/src/librustc_target/spec/thumbv6m_none_eabi.rs index 26812501814f5..bfac1ba45e1c7 100644 --- a/src/librustc_target/spec/thumbv6m_none_eabi.rs +++ b/src/librustc_target/spec/thumbv6m_none_eabi.rs @@ -21,8 +21,8 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "none".to_string(), - target_env: "".to_string(), - target_vendor: "".to_string(), + target_env: String::new(), + target_vendor: String::new(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/thumbv7em_none_eabi.rs b/src/librustc_target/spec/thumbv7em_none_eabi.rs index ab85c97b1b5ba..0207f38dea848 100644 --- a/src/librustc_target/spec/thumbv7em_none_eabi.rs +++ b/src/librustc_target/spec/thumbv7em_none_eabi.rs @@ -30,8 +30,8 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "none".to_string(), - target_env: "".to_string(), - target_vendor: "".to_string(), + target_env: String::new(), + target_vendor: String::new(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/thumbv7em_none_eabihf.rs b/src/librustc_target/spec/thumbv7em_none_eabihf.rs index 4e62f29134edf..bb1a42f0e289e 100644 --- a/src/librustc_target/spec/thumbv7em_none_eabihf.rs +++ b/src/librustc_target/spec/thumbv7em_none_eabihf.rs @@ -29,8 +29,8 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "none".to_string(), - target_env: "".to_string(), - target_vendor: "".to_string(), + target_env: String::new(), + target_vendor: String::new(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/thumbv7m_none_eabi.rs b/src/librustc_target/spec/thumbv7m_none_eabi.rs index 10dc503388afe..1eac13afd9ae5 100644 --- a/src/librustc_target/spec/thumbv7m_none_eabi.rs +++ b/src/librustc_target/spec/thumbv7m_none_eabi.rs @@ -21,8 +21,8 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "none".to_string(), - target_env: "".to_string(), - target_vendor: "".to_string(), + target_env: String::new(), + target_vendor: String::new(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/wasm32_experimental_emscripten.rs b/src/librustc_target/spec/wasm32_experimental_emscripten.rs index 164df20f84f34..60ad2d2324933 100644 --- a/src/librustc_target/spec/wasm32_experimental_emscripten.rs +++ b/src/librustc_target/spec/wasm32_experimental_emscripten.rs @@ -43,7 +43,7 @@ pub fn target() -> Result { target_pointer_width: "32".to_string(), target_c_int_width: "32".to_string(), target_os: "emscripten".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), data_layout: "e-m:e-p:32:32-i64:64-n32:64-S128".to_string(), arch: "wasm32".to_string(), diff --git a/src/librustc_target/spec/wasm32_unknown_emscripten.rs b/src/librustc_target/spec/wasm32_unknown_emscripten.rs index 5077abf1e0eb3..b4c09f86b8a97 100644 --- a/src/librustc_target/spec/wasm32_unknown_emscripten.rs +++ b/src/librustc_target/spec/wasm32_unknown_emscripten.rs @@ -40,7 +40,7 @@ pub fn target() -> Result { target_pointer_width: "32".to_string(), target_c_int_width: "32".to_string(), target_os: "emscripten".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), data_layout: "e-p:32:32-i64:64-v128:32:128-n32-S128".to_string(), arch: "wasm32".to_string(), diff --git a/src/librustc_target/spec/wasm32_unknown_unknown.rs b/src/librustc_target/spec/wasm32_unknown_unknown.rs index 94e7739b1a05a..6c368e09003a3 100644 --- a/src/librustc_target/spec/wasm32_unknown_unknown.rs +++ b/src/librustc_target/spec/wasm32_unknown_unknown.rs @@ -32,7 +32,7 @@ pub fn target() -> Result { // relatively self-explanatory! exe_suffix: ".wasm".to_string(), - dll_prefix: "".to_string(), + dll_prefix: String::new(), dll_suffix: ".wasm".to_string(), linker_is_gnu: false, @@ -65,7 +65,7 @@ pub fn target() -> Result { // This is basically guaranteed to change in the future, don't rely on // this. Use `not(target_os = "emscripten")` for now. target_os: "unknown".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), data_layout: "e-m:e-p:32:32-i64:64-n32:64-S128".to_string(), arch: "wasm32".to_string(), diff --git a/src/librustc_target/spec/windows_base.rs b/src/librustc_target/spec/windows_base.rs index 176df9f13253d..29049b1427570 100644 --- a/src/librustc_target/spec/windows_base.rs +++ b/src/librustc_target/spec/windows_base.rs @@ -77,10 +77,10 @@ pub fn opts() -> TargetOptions { linker: Some("gcc".to_string()), dynamic_linking: true, executables: true, - dll_prefix: "".to_string(), + dll_prefix: String::new(), dll_suffix: ".dll".to_string(), exe_suffix: ".exe".to_string(), - staticlib_prefix: "".to_string(), + staticlib_prefix: String::new(), staticlib_suffix: ".lib".to_string(), no_default_libraries: true, target_family: Some("windows".to_string()), diff --git a/src/librustc_target/spec/windows_msvc_base.rs b/src/librustc_target/spec/windows_msvc_base.rs index 1f00e690cd352..27879de9ab556 100644 --- a/src/librustc_target/spec/windows_msvc_base.rs +++ b/src/librustc_target/spec/windows_msvc_base.rs @@ -21,10 +21,10 @@ pub fn opts() -> TargetOptions { function_sections: true, dynamic_linking: true, executables: true, - dll_prefix: "".to_string(), + dll_prefix: String::new(), dll_suffix: ".dll".to_string(), exe_suffix: ".exe".to_string(), - staticlib_prefix: "".to_string(), + staticlib_prefix: String::new(), staticlib_suffix: ".lib".to_string(), target_family: Some("windows".to_string()), is_like_windows: true, diff --git a/src/librustc_target/spec/x86_64_apple_darwin.rs b/src/librustc_target/spec/x86_64_apple_darwin.rs index a4efd7e0066ff..150590ba68d76 100644 --- a/src/librustc_target/spec/x86_64_apple_darwin.rs +++ b/src/librustc_target/spec/x86_64_apple_darwin.rs @@ -26,7 +26,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "macos".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "apple".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_apple_ios.rs b/src/librustc_target/spec/x86_64_apple_ios.rs index eeb53d72fe8a3..e184ec2435878 100644 --- a/src/librustc_target/spec/x86_64_apple_ios.rs +++ b/src/librustc_target/spec/x86_64_apple_ios.rs @@ -21,7 +21,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "ios".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "apple".to_string(), linker_flavor: LinkerFlavor::Gcc, options: TargetOptions { diff --git a/src/librustc_target/spec/x86_64_fuchsia.rs b/src/librustc_target/spec/x86_64_fuchsia.rs index e8fa179887c87..62148a740dff5 100644 --- a/src/librustc_target/spec/x86_64_fuchsia.rs +++ b/src/librustc_target/spec/x86_64_fuchsia.rs @@ -25,8 +25,8 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "fuchsia".to_string(), - target_env: "".to_string(), - target_vendor: "".to_string(), + target_env: String::new(), + target_vendor: String::new(), linker_flavor: LinkerFlavor::Gcc, options: base, }) diff --git a/src/librustc_target/spec/x86_64_linux_android.rs b/src/librustc_target/spec/x86_64_linux_android.rs index 06abe916784dc..ea67dc6bdef12 100644 --- a/src/librustc_target/spec/x86_64_linux_android.rs +++ b/src/librustc_target/spec/x86_64_linux_android.rs @@ -27,7 +27,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "android".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_rumprun_netbsd.rs b/src/librustc_target/spec/x86_64_rumprun_netbsd.rs index ed15cfd9036f5..af846653af727 100644 --- a/src/librustc_target/spec/x86_64_rumprun_netbsd.rs +++ b/src/librustc_target/spec/x86_64_rumprun_netbsd.rs @@ -33,7 +33,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "netbsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "rumprun".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_sun_solaris.rs b/src/librustc_target/spec/x86_64_sun_solaris.rs index e84f21c500664..beb23dce06249 100644 --- a/src/librustc_target/spec/x86_64_sun_solaris.rs +++ b/src/librustc_target/spec/x86_64_sun_solaris.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "solaris".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "sun".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_unknown_bitrig.rs b/src/librustc_target/spec/x86_64_unknown_bitrig.rs index 21ec6dffcbbce..a98fc80716bcb 100644 --- a/src/librustc_target/spec/x86_64_unknown_bitrig.rs +++ b/src/librustc_target/spec/x86_64_unknown_bitrig.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "bitrig".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_unknown_cloudabi.rs b/src/librustc_target/spec/x86_64_unknown_cloudabi.rs index 8dc8bd7a7fad9..16df9000683b7 100644 --- a/src/librustc_target/spec/x86_64_unknown_cloudabi.rs +++ b/src/librustc_target/spec/x86_64_unknown_cloudabi.rs @@ -26,7 +26,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "cloudabi".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_unknown_dragonfly.rs b/src/librustc_target/spec/x86_64_unknown_dragonfly.rs index 50b2871c2ee9c..4c14a321febe6 100644 --- a/src/librustc_target/spec/x86_64_unknown_dragonfly.rs +++ b/src/librustc_target/spec/x86_64_unknown_dragonfly.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "dragonfly".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_unknown_freebsd.rs b/src/librustc_target/spec/x86_64_unknown_freebsd.rs index f0aa81ed4598b..4515b3308717e 100644 --- a/src/librustc_target/spec/x86_64_unknown_freebsd.rs +++ b/src/librustc_target/spec/x86_64_unknown_freebsd.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "freebsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_unknown_haiku.rs b/src/librustc_target/spec/x86_64_unknown_haiku.rs index 68fa58b922019..7e6b56866e4c7 100644 --- a/src/librustc_target/spec/x86_64_unknown_haiku.rs +++ b/src/librustc_target/spec/x86_64_unknown_haiku.rs @@ -27,7 +27,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "haiku".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_unknown_hermit.rs b/src/librustc_target/spec/x86_64_unknown_hermit.rs index 9f9f2e6ec43e9..c879e94e6e65a 100644 --- a/src/librustc_target/spec/x86_64_unknown_hermit.rs +++ b/src/librustc_target/spec/x86_64_unknown_hermit.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "hermit".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_unknown_netbsd.rs b/src/librustc_target/spec/x86_64_unknown_netbsd.rs index 6e8ca6b9e1991..de53c9e99ed86 100644 --- a/src/librustc_target/spec/x86_64_unknown_netbsd.rs +++ b/src/librustc_target/spec/x86_64_unknown_netbsd.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "netbsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_unknown_openbsd.rs b/src/librustc_target/spec/x86_64_unknown_openbsd.rs index c60b7c86680f8..de22c77d1e056 100644 --- a/src/librustc_target/spec/x86_64_unknown_openbsd.rs +++ b/src/librustc_target/spec/x86_64_unknown_openbsd.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "openbsd".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_target/spec/x86_64_unknown_redox.rs b/src/librustc_target/spec/x86_64_unknown_redox.rs index 548dfb06109ff..12a354b499efa 100644 --- a/src/librustc_target/spec/x86_64_unknown_redox.rs +++ b/src/librustc_target/spec/x86_64_unknown_redox.rs @@ -25,7 +25,7 @@ pub fn target() -> TargetResult { data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "redox".to_string(), - target_env: "".to_string(), + target_env: String::new(), target_vendor: "unknown".to_string(), linker_flavor: LinkerFlavor::Gcc, options: base, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index aa05191cd4ae6..0a1218a9bdffc 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3471,7 +3471,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { displayable_field_names.sort(); let truncated_fields_error = if len <= 3 { - "".to_string() + String::new() } else { format!(" and {} other field{}", (len - 3), if len - 3 == 1 {""} else {"s"}) }; @@ -4783,7 +4783,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { err.span_suggestion_with_applicability( span_semi, "consider removing this semicolon", - "".to_string(), + String::new(), Applicability::MachineApplicable); } diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 62015907f0c8e..52e6663792b26 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -142,7 +142,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) { .span_suggestion_short_with_applicability( span, "remove it", - "".to_string(), + String::new(), Applicability::MachineApplicable) .emit(); continue; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b660613bb9faf..5c23d0f6b3990 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -568,7 +568,7 @@ impl Clean for doctree::Module { let name = if self.name.is_some() { self.name.expect("No name provided").clean(cx) } else { - "".to_string() + String::new() }; // maintain a stack of mod ids, for doc comment path resolution @@ -1760,7 +1760,7 @@ impl<'a, 'tcx> Clean for (DefId, ty::PolyFnSig<'tcx>) { values: sig.skip_binder().inputs().iter().map(|t| { Argument { type_: t.clean(cx), - name: names.next().map_or("".to_string(), |name| name.to_string()), + name: names.next().map_or(String::new(), |name| name.to_string()), } }).collect(), }, @@ -3596,7 +3596,7 @@ impl Clean for hir::ForeignItem { ForeignStaticItem(Static { type_: ty.clean(cx), mutability: if mutbl {Mutable} else {Immutable}, - expr: "".to_string(), + expr: String::new(), }) } hir::ForeignItemKind::Type => { @@ -3628,7 +3628,7 @@ impl ToSource for syntax_pos::Span { debug!("converting span {:?} to snippet", self.clean(cx)); let sn = match cx.sess().source_map().span_to_snippet(*self) { Ok(x) => x.to_string(), - Err(_) => "".to_string() + Err(_) => String::new() }; debug!("got snippet {}", sn); sn @@ -3824,19 +3824,19 @@ impl Clean for attr::Stability { feature: self.feature.to_string(), since: match self.level { attr::Stable {ref since} => since.to_string(), - _ => "".to_string(), + _ => String::new(), }, deprecated_since: match self.rustc_depr { Some(attr::RustcDeprecation {ref since, ..}) => since.to_string(), - _=> "".to_string(), + _=> String::new(), }, deprecated_reason: match self.rustc_depr { Some(ref depr) => depr.reason.to_string(), - _ => "".to_string(), + _ => String::new(), }, unstable_reason: match self.level { attr::Unstable { reason: Some(ref reason), .. } => reason.to_string(), - _ => "".to_string(), + _ => String::new(), }, issue: match self.level { attr::Unstable {issue, ..} => Some(issue), @@ -3855,8 +3855,8 @@ impl<'a> Clean for &'a attr::Stability { impl Clean for attr::Deprecation { fn clean(&self, _: &DocContext) -> Deprecation { Deprecation { - since: self.since.as_ref().map_or("".to_string(), |s| s.to_string()), - note: self.note.as_ref().map_or("".to_string(), |s| s.to_string()), + since: self.since.as_ref().map_or(String::new(), |s| s.to_string()), + note: self.note.as_ref().map_or(String::new(), |s| s.to_string()), } } } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 58034d1df5a1f..7643aade83b7d 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -620,7 +620,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => { let lt = match *l { Some(ref l) => format!("{} ", *l), - _ => "".to_string(), + _ => String::new(), }; let m = MutableSpace(mutability); let amp = if f.alternate() { diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index af7c0a04215c1..582f31ce7c716 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -156,13 +156,13 @@ pub fn render( root_path = page.root_path, suffix=page.resource_suffix) } else { - "".to_owned() + String::new() }, content = *t, root_path = page.root_path, css_class = page.css_class, logo = if layout.logo.is_empty() { - "".to_string() + String::new() } else { format!("\ logo", @@ -173,7 +173,7 @@ pub fn render( description = page.description, keywords = page.keywords, favicon = if layout.favicon.is_empty() { - "".to_string() + String::new() } else { format!(r#""#, layout.favicon) }, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 4caea56faad34..8fb3b570f8a4b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -504,8 +504,8 @@ pub fn run(mut krate: clean::Crate, local_sources: FxHashMap(), issue_tracker_base_url: None, layout: layout::Layout { - logo: "".to_string(), - favicon: "".to_string(), + logo: String::new(), + favicon: String::new(), external_html: external_html.clone(), krate: krate.name.clone(), }, @@ -2183,7 +2183,7 @@ fn shorter<'a>(s: Option<&'a str>) -> String { !chr.is_whitespace() }) }).collect::>().join("\n"), - None => "".to_string() + None => String::new() } } @@ -2479,7 +2479,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, stab_docs = stab_docs, docs = MarkdownSummaryLine(doc_value, &myitem.links()), class = myitem.type_(), - stab = myitem.stability_class().unwrap_or("".to_string()), + stab = myitem.stability_class().unwrap_or(String::new()), unsafety_flag = unsafety_flag, href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()), title_type = myitem.type_(), diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 19a204cc989bf..e4b9e3216b13b 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -184,7 +184,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke Ok(..) => { // Add this input file to the code map to make it available as // dependency information, but don't enter it's contents - cx.source_map().new_source_file(file.into(), "".to_string()); + cx.source_map().new_source_file(file.into(), String::new()); base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))) } diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index dde0466f43c2d..172a48ddba2d9 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -230,7 +230,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut Vec, s: String, col: if col < len { (&s[col..len]).to_string() } else { - "".to_string() + String::new() } } None => s, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e85b5dca2b73b..74f6a65cc262d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -684,7 +684,7 @@ impl<'a> Parser<'a> { let mut i = tokens.iter(); // This might be a sign we need a connect method on Iterator. let b = i.next() - .map_or("".to_string(), |t| t.to_string()); + .map_or(String::new(), |t| t.to_string()); i.enumerate().fold(b, |mut b, (i, a)| { if tokens.len() > 2 && i == tokens.len() - 2 { b.push_str(", or "); @@ -786,7 +786,7 @@ impl<'a> Parser<'a> { } else { err.span_label(self.span, "expected identifier"); if self.token == token::Comma && self.look_ahead(1, |t| t.is_ident()) { - err.span_suggestion(self.span, "remove this comma", "".into()); + err.span_suggestion(self.span, "remove this comma", String::new()); } } err @@ -2506,7 +2506,7 @@ impl<'a> Parser<'a> { err.span_suggestion_short_with_applicability( self.span, "remove this comma", - "".to_owned(), + String::new(), Applicability::MachineApplicable ); err.note("the base struct must always be the last field"); @@ -3473,7 +3473,7 @@ impl<'a> Parser<'a> { e.span_suggestion_short_with_applicability( match_span, "try removing this `match`", - "".to_owned(), + String::new(), Applicability::MaybeIncorrect // speculative ); } @@ -3850,7 +3850,7 @@ impl<'a> Parser<'a> { if self.token == token::CloseDelim(token::Brace) { // If the struct looks otherwise well formed, recover and continue. if let Some(sp) = comma_sp { - err.span_suggestion_short(sp, "remove this comma", "".into()); + err.span_suggestion_short(sp, "remove this comma", String::new()); } err.emit(); break; @@ -3890,7 +3890,7 @@ impl<'a> Parser<'a> { err.multipart_suggestion( "move the `..` to the end of the field list", vec![ - (etc_span, "".into()), + (etc_span, String::new()), (self.span, format!("{}.. }}", if ate_comma { "" } else { ", " })), ], ); @@ -6190,7 +6190,7 @@ impl<'a> Parser<'a> { if token_str == ";" { let msg = "consider removing this semicolon"; err.span_suggestion_short_with_applicability( - self.span, msg, "".to_string(), Applicability::MachineApplicable + self.span, msg, String::new(), Applicability::MachineApplicable ); if !items.is_empty() { // Issue #51603 let previous_item = &items[items.len()-1]; diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs index c65931a857718..8f91db8efa71a 100644 --- a/src/libsyntax/source_map.rs +++ b/src/libsyntax/source_map.rs @@ -1030,7 +1030,7 @@ mod tests { cm.new_source_file(PathBuf::from("blork.rs").into(), "first line.\nsecond line".to_string()); cm.new_source_file(PathBuf::from("empty.rs").into(), - "".to_string()); + String::new()); cm.new_source_file(PathBuf::from("blork2.rs").into(), "first line.\nsecond line".to_string()); cm diff --git a/src/libtest/formatters/json.rs b/src/libtest/formatters/json.rs index 89235d897bde6..f7e0788a884c3 100644 --- a/src/libtest/formatters/json.rs +++ b/src/libtest/formatters/json.rs @@ -102,7 +102,7 @@ impl OutputFormatter for JsonFormatter { let deviation = (bs.ns_iter_summ.max - bs.ns_iter_summ.min) as usize; let mbps = if bs.mb_s == 0 { - "".into() + String::new() } else { format!(r#", "mib_per_second": {}"#, bs.mb_s) }; diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 3fd67366a8ca4..db856a1dcf94f 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -559,7 +559,7 @@ impl Config { let mut strs: Vec = nv.splitn(2, '=').map(str::to_owned).collect(); match strs.len() { - 1 => (strs.pop().unwrap(), "".to_owned()), + 1 => (strs.pop().unwrap(), String::new()), 2 => { let end = strs.pop().unwrap(); (strs.pop().unwrap(), end) diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index 1dc36221bd289..74f66c0a05169 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -252,7 +252,7 @@ pub fn collect_lib_features(base_src_path: &Path) -> Features { // add it to the set of known library features so we can still generate docs. lib_features.insert("compiler_builtins_lib".to_owned(), Feature { level: Status::Unstable, - since: "".to_owned(), + since: String::new(), has_gate_test: false, tracking_issue: None, }); From 85a05d1815217584c096ebc9d64b3a547b667f48 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Thu, 23 Aug 2018 10:52:08 +0100 Subject: [PATCH 20/27] Light restructuring. --- src/Cargo.lock | 1 - src/librustc_privacy/Cargo.toml | 1 - src/librustc_privacy/lib.rs | 34 +++++++++++++-------------------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 4b76080e500ab..8299dea1c4b0e 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -2237,7 +2237,6 @@ dependencies = [ name = "rustc_privacy" version = "0.0.0" dependencies = [ - "log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_data_structures 0.0.0", "rustc_typeck 0.0.0", diff --git a/src/librustc_privacy/Cargo.toml b/src/librustc_privacy/Cargo.toml index b7af9ec809e54..62eab40f3ec9a 100644 --- a/src/librustc_privacy/Cargo.toml +++ b/src/librustc_privacy/Cargo.toml @@ -9,7 +9,6 @@ path = "lib.rs" crate-type = ["dylib"] [dependencies] -log = { version = "0.4", features = ["release_max_level_info", "std"] } rustc = { path = "../librustc" } rustc_typeck = { path = "../librustc_typeck" } syntax = { path = "../libsyntax" } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index f6b843bbac52b..6b19f4b779107 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -18,7 +18,6 @@ #![recursion_limit="256"] -#[macro_use] extern crate log; #[macro_use] extern crate rustc; #[macro_use] extern crate syntax; extern crate rustc_typeck; @@ -150,7 +149,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { } fn visit_item(&mut self, item: &'tcx hir::Item) { - debug!("visit_item({:?})", item); let inherited_item_level = match item.node { // Impls inherit level from their types and traits hir::ItemKind::Impl(..) => { @@ -161,21 +159,12 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { hir::ItemKind::ForeignMod(..) => { self.prev_level } - // Impl trait return types mark their parent function. - // It (and its children) are revisited if the change applies. - hir::ItemKind::Existential(ref ty_data) => { - if let Some(impl_trait_fn) = ty_data.impl_trait_fn { - if let Some(node_id) = self.tcx.hir.as_local_node_id(impl_trait_fn) { - self.update(node_id, Some(AccessLevel::ReachableFromImplTrait)); - } - } - if item.vis.node.is_pub() { self.prev_level } else { None } - } // Other `pub` items inherit levels from parents hir::ItemKind::Const(..) | hir::ItemKind::Enum(..) | hir::ItemKind::ExternCrate(..) | hir::ItemKind::GlobalAsm(..) | hir::ItemKind::Fn(..) | hir::ItemKind::Mod(..) | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) | + hir::ItemKind::Existential(..) | hir::ItemKind::Ty(..) | hir::ItemKind::Union(..) | hir::ItemKind::Use(..) => { if item.vis.node.is_pub() { self.prev_level } else { None } } @@ -184,8 +173,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { // Update level of the item itself let item_level = self.update(item.id, inherited_item_level); - debug!("item_level = {:?}", item_level); - // Update levels of nested things match item.node { hir::ItemKind::Enum(ref def, _) => { @@ -230,7 +217,15 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { } } } - hir::ItemKind::Existential(..) | + // Impl trait return types mark their parent function. + // It (and its children) are revisited if the change applies. + hir::ItemKind::Existential(ref ty_data) => { + if let Some(impl_trait_fn) = ty_data.impl_trait_fn { + if let Some(node_id) = self.tcx.hir.as_local_node_id(impl_trait_fn) { + self.update(node_id, Some(AccessLevel::ReachableFromImplTrait)); + } + } + } hir::ItemKind::Use(..) | hir::ItemKind::Static(..) | hir::ItemKind::Const(..) | @@ -242,8 +237,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { hir::ItemKind::ExternCrate(..) => {} } - let orig_level = self.prev_level; - self.prev_level = item_level; + // Store this node's access level here to propagate the correct + // reachability level through interfaces and children. + let orig_level = replace(&mut self.prev_level, item_level); // Mark all items in interfaces of reachable items as reachable match item.node { @@ -1752,8 +1748,6 @@ fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } visitor.update(ast::CRATE_NODE_ID, Some(AccessLevel::Public)); - debug!("access levels after embargo: {:?}", &visitor.access_levels); - { let mut visitor = ObsoleteVisiblePrivateTypesVisitor { tcx, @@ -1783,8 +1777,6 @@ fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, krate.visit_all_item_likes(&mut DeepVisitor::new(&mut visitor)); } - debug!("final access levels: {:?}", &visitor.access_levels); - Lrc::new(visitor.access_levels) } From 9e0ff24b6dbeaa549775ef77e5fdf8493f0f82da Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Thu, 23 Aug 2018 09:35:49 -0400 Subject: [PATCH 21/27] Prefer `.nth(n)` over `.skip(n).next()`. Found by clippy. --- src/libcore/fmt/mod.rs | 2 +- src/librustc_metadata/encoder.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/test/run-pass-fulldeps/auxiliary/proc_macro_def.rs | 2 +- src/test/run-pass/command-before-exec.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 928f95e3ba2ea..6ed90fdd4b6ee 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1232,7 +1232,7 @@ impl<'a> Formatter<'a> { // If our string is longer that the precision, then we must have // truncation. However other flags like `fill`, `width` and `align` // must act as always. - if let Some((i, _)) = s.char_indices().skip(max).next() { + if let Some((i, _)) = s.char_indices().nth(max) { // LLVM here can't prove that `..i` won't panic `&s[..i]`, but // we know that it can't panic. Use `get` + `unwrap_or` to avoid // `unsafe` and otherwise don't emit any panic-related code diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 44d8d4a727769..8219ec3df248a 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -1111,7 +1111,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { let trait_ref = tcx.impl_trait_ref(def_id); let parent = if let Some(trait_ref) = trait_ref { let trait_def = tcx.trait_def(trait_ref.def_id); - trait_def.ancestors(tcx, def_id).skip(1).next().and_then(|node| { + trait_def.ancestors(tcx, def_id).nth(1).and_then(|node| { match node { specialization_graph::Node::Impl(parent) => Some(parent), _ => None, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index aa05191cd4ae6..e88162bc1e92e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1434,7 +1434,7 @@ fn check_specialization_validity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir::ImplItemKind::Type(_) => ty::AssociatedKind::Type }; - let parent = ancestors.defs(tcx, trait_item.ident, kind, trait_def.def_id).skip(1).next() + let parent = ancestors.defs(tcx, trait_item.ident, kind, trait_def.def_id).nth(1) .map(|node_item| node_item.map(|parent| parent.defaultness)); if let Some(parent) = parent { diff --git a/src/test/run-pass-fulldeps/auxiliary/proc_macro_def.rs b/src/test/run-pass-fulldeps/auxiliary/proc_macro_def.rs index 9faa7366ec5f1..b9c565a9d3c23 100644 --- a/src/test/run-pass-fulldeps/auxiliary/proc_macro_def.rs +++ b/src/test/run-pass-fulldeps/auxiliary/proc_macro_def.rs @@ -19,7 +19,7 @@ use proc_macro::*; #[proc_macro_attribute] pub fn attr_tru(_attr: TokenStream, item: TokenStream) -> TokenStream { - let name = item.into_iter().skip(1).next().unwrap(); + let name = item.into_iter().nth(1).unwrap(); quote!(fn $name() -> bool { true }) } diff --git a/src/test/run-pass/command-before-exec.rs b/src/test/run-pass/command-before-exec.rs index 9599f65da4eca..c4fc9ee53fd7f 100644 --- a/src/test/run-pass/command-before-exec.rs +++ b/src/test/run-pass/command-before-exec.rs @@ -24,7 +24,7 @@ use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; fn main() { - if let Some(arg) = env::args().skip(1).next() { + if let Some(arg) = env::args().nth(1) { match &arg[..] { "test1" => println!("hello2"), "test2" => assert_eq!(env::var("FOO").unwrap(), "BAR"), From e7709b3d44da921a65c009eb52492830141d330a Mon Sep 17 00:00:00 2001 From: Kornel Date: Sun, 19 Aug 2018 19:46:05 +0100 Subject: [PATCH 22/27] Discourage overuse of mem::forget --- src/libcore/mem.rs | 46 +++++++--------------------------------------- 1 file changed, 7 insertions(+), 39 deletions(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index ea711c69393a4..67cceb9d53605 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -29,13 +29,15 @@ use ops::{Deref, DerefMut, CoerceUnsized}; #[stable(feature = "rust1", since = "1.0.0")] pub use intrinsics::transmute; -/// Leaks a value: takes ownership and "forgets" about the value **without running -/// its destructor**. +/// Takes ownership and "forgets" about the value **without running its destructor**. /// /// Any resources the value manages, such as heap memory or a file handle, will linger -/// forever in an unreachable state. +/// forever in an unreachable state. However, it does not guarantee that pointers +/// to this memory will remain valid. /// -/// If you want to dispose of a value properly, running its destructor, see +/// * If you want to leak memory, see [`Box::leak`][leak]. +/// * If you want to obtain a raw pointer to the memory, see [`Box::into_raw`][into_raw]. +/// * If you want to dispose of a value properly, running its destructor, see /// [`mem::drop`][drop]. /// /// # Safety @@ -59,15 +61,6 @@ pub use intrinsics::transmute; /// /// # Examples /// -/// Leak some heap memory by never deallocating it: -/// -/// ``` -/// use std::mem; -/// -/// let heap_memory = Box::new(3); -/// mem::forget(heap_memory); -/// ``` -/// /// Leak an I/O object, never closing the file: /// /// ```no_run @@ -137,38 +130,13 @@ pub use intrinsics::transmute; /// } /// ``` /// -/// ## Use case 3 -/// -/// You are transferring ownership across a [FFI] boundary to code written in -/// another language. You need to `forget` the value on the Rust side because Rust -/// code is no longer responsible for it. -/// -/// ```no_run -/// use std::mem; -/// -/// extern "C" { -/// fn my_c_function(x: *const u32); -/// } -/// -/// let x: Box = Box::new(3); -/// -/// // Transfer ownership into C code. -/// unsafe { -/// my_c_function(&*x); -/// } -/// mem::forget(x); -/// ``` -/// -/// In this case, C code must call back into Rust to free the object. Calling C's `free` -/// function on a [`Box`][box] is *not* safe! Also, `Box` provides an [`into_raw`][into_raw] -/// method which is the preferred way to do this in practice. -/// /// [drop]: fn.drop.html /// [uninit]: fn.uninitialized.html /// [clone]: ../clone/trait.Clone.html /// [swap]: fn.swap.html /// [FFI]: ../../book/first-edition/ffi.html /// [box]: ../../std/boxed/struct.Box.html +/// [leak]: ../../std/boxed/struct.Box.html#method.leak /// [into_raw]: ../../std/boxed/struct.Box.html#method.into_raw /// [ub]: ../../reference/behavior-considered-undefined.html #[inline] From 747722e44445bfb067bfbc84540c434170d538e8 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Thu, 23 Aug 2018 23:21:54 +0530 Subject: [PATCH 23/27] fix testcase --- src/test/ui/lint/lints-in-foreign-macros.rs | 5 +++-- .../ui/lint/lints-in-foreign-macros.stderr | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/test/ui/lint/lints-in-foreign-macros.rs b/src/test/ui/lint/lints-in-foreign-macros.rs index 2ad1cfe71682c..3785968df871a 100644 --- a/src/test/ui/lint/lints-in-foreign-macros.rs +++ b/src/test/ui/lint/lints-in-foreign-macros.rs @@ -11,7 +11,7 @@ // aux-build:lints-in-foreign-macros.rs // compile-pass -#![warn(unused_imports)] +#![warn(unused_imports)] //~ missing documentation for crate [missing_docs] #![warn(missing_docs)] #[macro_use] @@ -25,6 +25,7 @@ mod a { foo!(); } mod b { bar!(); } mod c { baz!(use std::string::ToString;); } //~ WARN: unused import mod d { baz2!(use std::string::ToString;); } //~ WARN: unused import -mod e { baz!(pub fn undocumented() {}); }//~ WARN: missing documentation for a function +baz!(pub fn undocumented() {}); //~ WARN: missing documentation for a function +baz2!(pub fn undocumented2() {}); //~ WARN: missing documentation for a function fn main() {} diff --git a/src/test/ui/lint/lints-in-foreign-macros.stderr b/src/test/ui/lint/lints-in-foreign-macros.stderr index 4a75e1d907dc8..2ddca7781231f 100644 --- a/src/test/ui/lint/lints-in-foreign-macros.stderr +++ b/src/test/ui/lint/lints-in-foreign-macros.stderr @@ -10,7 +10,7 @@ LL | mod a { foo!(); } note: lint level defined here --> $DIR/lints-in-foreign-macros.rs:14:9 | -LL | #![warn(unused_imports)] +LL | #![warn(unused_imports)] //~ missing documentation for crate [missing_docs] | ^^^^^^^^^^^^^^ warning: unused import: `std::string::ToString` @@ -28,13 +28,13 @@ LL | mod d { baz2!(use std::string::ToString;); } //~ WARN: unused import warning: missing documentation for crate --> $DIR/lints-in-foreign-macros.rs:14:1 | -LL | / #![warn(unused_imports)] +LL | / #![warn(unused_imports)] //~ missing documentation for crate [missing_docs] LL | | #![warn(missing_docs)] LL | | LL | | #[macro_use] ... | LL | | -LL | | fn main() {} //~ WARN: missing documentation for crate [missing_docs] +LL | | fn main() {} | |____________^ | note: lint level defined here @@ -43,3 +43,15 @@ note: lint level defined here LL | #![warn(missing_docs)] | ^^^^^^^^^^^^ +warning: missing documentation for a function + --> $DIR/lints-in-foreign-macros.rs:28:6 + | +LL | baz!(pub fn undocumented() {}); //~ WARN: missing documentation for a function + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: missing documentation for a function + --> $DIR/lints-in-foreign-macros.rs:29:7 + | +LL | baz2!(pub fn undocumented2() {}); //~ WARN: missing documentation for a function + | ^^^^^^^^^^^^^^^^^^^^^^ + From 2cc2e01e04ee7706139347f5e067595af9c8ee03 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Aug 2018 23:43:30 +0200 Subject: [PATCH 24/27] Add missing fmt examples --- src/libcore/fmt/mod.rs | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 928f95e3ba2ea..6493f5b39a7d7 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1132,6 +1132,36 @@ impl<'a> Formatter<'a> { /// /// This function will correctly account for the flags provided as well as /// the minimum width. It will not take precision into account. + /// + /// # Examples + /// + /// ``` + /// use std::fmt; + /// + /// struct Foo { nb: i32 }; + /// + /// impl Foo { + /// fn new(nb: i32) -> Foo { + /// Foo { + /// nb, + /// } + /// } + /// } + /// + /// impl fmt::Display for Foo { + /// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + /// // We need to remove "-" from the number output. + /// let tmp = self.nb.abs().to_string(); + /// + /// formatter.pad_integral(self.nb > 0, "Foo ", &tmp) + /// } + /// } + /// + /// assert_eq!(&format!("{}", Foo::new(2)), "2"); + /// assert_eq!(&format!("{}", Foo::new(-1)), "-1"); + /// assert_eq!(&format!("{:#}", Foo::new(-1)), "-Foo 1"); + /// assert_eq!(&format!("{:0>#8}", Foo::new(-1)), "00-Foo 1"); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn pad_integral(&mut self, is_nonnegative: bool, @@ -1381,12 +1411,48 @@ impl<'a> Formatter<'a> { /// Writes some data to the underlying buffer contained within this /// formatter. + /// + /// # Examples + /// + /// ``` + /// use std::fmt; + /// + /// struct Foo; + /// + /// impl fmt::Display for Foo { + /// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + /// formatter.write_str("Foo") + /// // This is equivalent to: + /// // write!(formatter, "Foo") + /// } + /// } + /// + /// assert_eq!(&format!("{}", Foo), "Foo"); + /// assert_eq!(&format!("{:0>8}", Foo), "Foo"); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn write_str(&mut self, data: &str) -> Result { self.buf.write_str(data) } /// Writes some formatted information into this instance. + /// + /// # Examples + /// + /// ``` + /// use std::fmt; + /// + /// struct Foo(i32); + /// + /// impl fmt::Display for Foo { + /// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + /// formatter.write_fmt(format_args!("Foo {}", self.0)) + /// } + /// } + /// + /// assert_eq!(&format!("{}", Foo(-1)), "Foo -1"); + /// assert_eq!(&format!("{:0>8}", Foo(2)), "Foo 2"); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn write_fmt(&mut self, fmt: Arguments) -> Result { write(self.buf, fmt) From 25a83e3a88bf5f199c8a8d8d8f452bab83d9a061 Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Thu, 23 Aug 2018 20:22:22 +0200 Subject: [PATCH 25/27] Use SmallVec for SmallCStr --- src/librustc_data_structures/small_c_str.rs | 87 +++++++++------------ 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/src/librustc_data_structures/small_c_str.rs b/src/librustc_data_structures/small_c_str.rs index b0ad83e497938..08794fbec8dc5 100644 --- a/src/librustc_data_structures/small_c_str.rs +++ b/src/librustc_data_structures/small_c_str.rs @@ -11,69 +11,61 @@ use std::ffi; use std::ops::Deref; -const SIZE: usize = 38; +use smallvec::SmallVec; + +const SIZE: usize = 36; /// Like SmallVec but for C strings. #[derive(Clone)] -pub enum SmallCStr { - OnStack { - data: [u8; SIZE], - len_with_nul: u8, - }, - OnHeap { - data: ffi::CString, - } +pub struct SmallCStr { + data: SmallVec<[u8; SIZE]>, } impl SmallCStr { #[inline] pub fn new(s: &str) -> SmallCStr { - if s.len() < SIZE { - let mut data = [0; SIZE]; - data[.. s.len()].copy_from_slice(s.as_bytes()); - let len_with_nul = s.len() + 1; - - // Make sure once that this is a valid CStr - if let Err(e) = ffi::CStr::from_bytes_with_nul(&data[.. len_with_nul]) { - panic!("The string \"{}\" cannot be converted into a CStr: {}", s, e); - } - - SmallCStr::OnStack { - data, - len_with_nul: len_with_nul as u8, - } + let len = s.len(); + let len1 = len + 1; + let data = if len < SIZE { + let mut buf = [0; SIZE]; + buf[..len].copy_from_slice(s.as_bytes()); + SmallVec::from_buf_and_len(buf, len1) } else { - SmallCStr::OnHeap { - data: ffi::CString::new(s).unwrap() - } + let mut data = Vec::with_capacity(len1); + data.extend_from_slice(s.as_bytes()); + data.push(0); + SmallVec::from_vec(data) + }; + if let Err(e) = ffi::CStr::from_bytes_with_nul(&data) { + panic!("The string \"{}\" cannot be converted into a CStr: {}", s, e); } + SmallCStr { data } } + #[inline] + pub fn new_with_nul(s: &str) -> SmallCStr { + let b = s.as_bytes(); + if let Err(e) = ffi::CStr::from_bytes_with_nul(b) { + panic!("The string \"{}\" cannot be converted into a CStr: {}", s, e); + } + SmallCStr { data: SmallVec::from_slice(s.as_bytes()) } + } + + #[inline] pub fn as_c_str(&self) -> &ffi::CStr { - match *self { - SmallCStr::OnStack { ref data, len_with_nul } => { - unsafe { - let slice = &data[.. len_with_nul as usize]; - ffi::CStr::from_bytes_with_nul_unchecked(slice) - } - } - SmallCStr::OnHeap { ref data } => { - data.as_c_str() - } + unsafe { + ffi::CStr::from_bytes_with_nul_unchecked(&self.data[..]) } } #[inline] pub fn len_with_nul(&self) -> usize { - match *self { - SmallCStr::OnStack { len_with_nul, .. } => { - len_with_nul as usize - } - SmallCStr::OnHeap { ref data } => { - data.as_bytes_with_nul().len() - } - } + self.data.len() + } + + pub fn spilled(&self) -> bool { + self.data.spilled() } } @@ -85,7 +77,6 @@ impl Deref for SmallCStr { } } - #[test] fn short() { const TEXT: &str = "abcd"; @@ -95,7 +86,7 @@ fn short() { assert_eq!(scs.len_with_nul(), TEXT.len() + 1); assert_eq!(scs.as_c_str(), reference.as_c_str()); - assert!(if let SmallCStr::OnStack { .. } = scs { true } else { false }); + assert!(!scs.spilled()); } #[test] @@ -107,7 +98,7 @@ fn empty() { assert_eq!(scs.len_with_nul(), TEXT.len() + 1); assert_eq!(scs.as_c_str(), reference.as_c_str()); - assert!(if let SmallCStr::OnStack { .. } = scs { true } else { false }); + assert!(!scs.spilled()); } #[test] @@ -121,7 +112,7 @@ fn long() { assert_eq!(scs.len_with_nul(), TEXT.len() + 1); assert_eq!(scs.as_c_str(), reference.as_c_str()); - assert!(if let SmallCStr::OnHeap { .. } = scs { true } else { false }); + assert!(scs.spilled()); } #[test] From b24a30e94d19b3ac537665e9b9856f7caabc895f Mon Sep 17 00:00:00 2001 From: Isaac Woods Date: Fri, 24 Aug 2018 11:20:30 +0100 Subject: [PATCH 26/27] Remove unnecessary closure in rustc_mir/build/mod.rs --- src/librustc_mir/build/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 179bc2426ab4a..dc88446319cf3 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -37,9 +37,6 @@ use util as mir_util; /// Construct the MIR for a given def-id. pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'tcx> { let id = tcx.hir.as_local_node_id(def_id).unwrap(); - let unsupported = || { - span_bug!(tcx.hir.span(id), "can't build MIR for {:?}", def_id); - }; // Figure out what primary body this item has. let body_id = match tcx.hir.get(id) { @@ -50,7 +47,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t _ => match tcx.hir.maybe_body_owned_by(id) { Some(body) => body, - None => unsupported(), + None => span_bug!(tcx.hir.span(id), "can't build MIR for {:?}", def_id), }, }; From c802be6f30868a14b6472bcb3160de127cb6ab89 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 24 Aug 2018 13:09:34 +0200 Subject: [PATCH 27/27] Added rustc_codegen_llvm to compiler documentation. --- src/bootstrap/doc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index ed9b5b1773fae..9a5d78e58ea3f 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -712,7 +712,7 @@ impl Step for Rustc { // Find dependencies for top level crates. let mut compiler_crates = HashSet::new(); - for root_crate in &["rustc", "rustc_driver"] { + for root_crate in &["rustc", "rustc_driver", "rustc_codegen_llvm"] { let interned_root_crate = INTERNER.intern_str(root_crate); find_compiler_crates(builder, &interned_root_crate, &mut compiler_crates); }