Skip to content

use String::new() instead of String::from(""), "".to_string(), "".to_owned() or "".into() #53563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
"perform LLVM link-time optimizations"),
target_cpu: Option<String> = (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<String> = (Vec::new(), parse_list, [TRACKED],
"a list of extra LLVM passes to run (space separated)"),
Expand Down Expand Up @@ -1085,7 +1085,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
"choose the code model to use (rustc --print code-models for details)"),
metadata: Vec<String> = (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<usize> = (None, parse_opt_uint, [UNTRACKED],
"divide crate into N units to optimize in parallel"),
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
));
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -1116,7 +1116,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
.collect::<Vec<String>>()
.join(", "))
} else {
"".to_owned()
String::new()
},
);
err.span_suggestion_with_applicability(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_borrowck/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/profile/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -813,7 +813,7 @@ impl EmitterWriter {
// backtrace is multiple levels deep
format!(" (#{})", i + 1)
} else {
"".to_string()
String::new()
})));
if !always_backtrace {
break;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/util/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/aarch64_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_target/spec/aarch64_fuchsia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/aarch64_linux_android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/aarch64_unknown_cloudabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/aarch64_unknown_freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/aarch64_unknown_hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/aarch64_unknown_netbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_target/spec/aarch64_unknown_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub fn target() -> Result<Target, String> {
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),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/aarch64_unknown_openbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/arm_linux_androideabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_target/spec/armebv7r_none_eabihf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/armv7_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/armv7_linux_androideabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading