Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ce61d40

Browse files
committed
Replace every Vec in Target(Options) with it's Cow equivalent
1 parent ccff48f commit ce61d40

31 files changed

+117
-53
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,10 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
674674

675675
linker::disable_localization(&mut cmd);
676676

677-
for &(ref k, ref v) in &sess.target.link_env {
677+
for &(ref k, ref v) in sess.target.link_env.iter() {
678678
cmd.env(k.as_ref(), v.as_ref());
679679
}
680-
for k in &sess.target.link_env_remove {
680+
for k in sess.target.link_env_remove.iter() {
681681
cmd.env_remove(k.as_ref());
682682
}
683683

compiler/rustc_serialize/src/json.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,15 @@ impl<A: ToJson> ToJson for Vec<A> {
22472247
}
22482248
}
22492249

2250+
impl<'a, A: ToJson> ToJson for Cow<'a, [A]>
2251+
where
2252+
[A]: ToOwned,
2253+
{
2254+
fn to_json(&self) -> Json {
2255+
Json::Array(self.iter().map(|elt| elt.to_json()).collect())
2256+
}
2257+
}
2258+
22502259
impl<T: ToString, A: ToJson> ToJson for BTreeMap<T, A> {
22512260
fn to_json(&self) -> Json {
22522261
let mut d = BTreeMap::new();

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
956956
ret.reserve(7); // the minimum number of insertions
957957
// Target bindings.
958958
ret.insert((sym::target_os, Some(Symbol::intern(os))));
959-
for fam in &sess.target.families {
959+
for fam in sess.target.families.iter() {
960960
ret.insert((sym::target_family, Some(Symbol::intern(fam))));
961961
if fam == "windows" {
962962
ret.insert((sym::windows, None));

compiler/rustc_target/src/spec/aarch64_apple_darwin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn target() -> Target {
99
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
1010

1111
base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-arch".into(), "arm64".into()]);
12-
base.link_env_remove.extend(super::apple_base::macos_link_env_remove());
12+
base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove());
1313

1414
// Clang automatically chooses a more specific target based on
1515
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work

compiler/rustc_target/src/spec/apple_base.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::{borrow::Cow, env};
22

33
use crate::spec::{FramePointer, LldFlavor, SplitDebuginfo, TargetOptions};
44

5+
use super::cvs;
6+
57
pub fn opts(os: &'static str) -> TargetOptions {
68
// ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6
79
// either the linker will complain if it is used or the binary will end up
@@ -26,7 +28,7 @@ pub fn opts(os: &'static str) -> TargetOptions {
2628
dynamic_linking: true,
2729
linker_is_gnu: false,
2830
executables: true,
29-
families: vec!["unix".into()],
31+
families: cvs!["unix"],
3032
is_like_osx: true,
3133
dwarf_version: Some(2),
3234
frame_pointer: FramePointer::Always,
@@ -51,7 +53,7 @@ pub fn opts(os: &'static str) -> TargetOptions {
5153
// this environment variable too in recent versions.
5254
//
5355
// For some more info see the commentary on #47086
54-
link_env: vec![("ZERO_AR_DATE".into(), "1".into())],
56+
link_env: Cow::Borrowed(&[(Cow::Borrowed("ZERO_AR_DATE"), Cow::Borrowed("1"))]),
5557

5658
..Default::default()
5759
}

compiler/rustc_target/src/spec/apple_sdk_base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::TargetOptions;
1+
use crate::{spec::cvs, spec::TargetOptions};
22
use std::borrow::Cow;
33

44
use Arch::*;
@@ -36,12 +36,12 @@ fn target_cpu(arch: Arch) -> &'static str {
3636
}
3737
}
3838

39-
fn link_env_remove(arch: Arch) -> Vec<Cow<'static, str>> {
39+
fn link_env_remove(arch: Arch) -> Cow<'static, [Cow<'static, str>]> {
4040
match arch {
4141
Armv7 | Armv7s | Arm64 | I386 | X86_64 | Arm64_sim => {
42-
vec!["MACOSX_DEPLOYMENT_TARGET".into()]
42+
cvs!["MACOSX_DEPLOYMENT_TARGET"]
4343
}
44-
X86_64_macabi | Arm64_macabi => vec!["IPHONEOS_DEPLOYMENT_TARGET".into()],
44+
X86_64_macabi | Arm64_macabi => cvs!["IPHONEOS_DEPLOYMENT_TARGET"],
4545
}
4646
}
4747

compiler/rustc_target/src/spec/armv6k_nintendo_3ds.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::spec::{LinkArgs, LinkerFlavor, RelocModel, Target, TargetOptions};
22

3+
use super::cvs;
4+
35
/// A base target for Nintendo 3DS devices using the devkitARM toolchain.
46
///
57
/// Requires the devkitARM toolchain for 3DS targets on the host system.
@@ -30,7 +32,7 @@ pub fn target() -> Target {
3032
linker_flavor: LinkerFlavor::Gcc,
3133
cpu: "mpcore".into(),
3234
executables: true,
33-
families: vec!["unix".into()],
35+
families: cvs!["unix"],
3436
linker: Some("arm-none-eabi-gcc".into()),
3537
relocation_model: RelocModel::Static,
3638
features: "+vfp2".into(),

compiler/rustc_target/src/spec/dragonfly_base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use crate::spec::{RelroLevel, TargetOptions};
22

3+
use super::cvs;
4+
35
pub fn opts() -> TargetOptions {
46
TargetOptions {
57
os: "dragonfly".into(),
68
dynamic_linking: true,
79
executables: true,
8-
families: vec!["unix".into()],
10+
families: cvs!["unix"],
911
has_rpath: true,
1012
position_independent_executables: true,
1113
relro_level: RelroLevel::Full,

compiler/rustc_target/src/spec/freebsd_base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use crate::spec::{RelroLevel, TargetOptions};
22

3+
use super::cvs;
4+
35
pub fn opts() -> TargetOptions {
46
TargetOptions {
57
os: "freebsd".into(),
68
dynamic_linking: true,
79
executables: true,
8-
families: vec!["unix".into()],
10+
families: cvs!["unix"],
911
has_rpath: true,
1012
position_independent_executables: true,
1113
relro_level: RelroLevel::Full,

compiler/rustc_target/src/spec/fuchsia_base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::spec::{crt_objects, LinkArgs, LinkOutputKind, LinkerFlavor, LldFlavor, TargetOptions};
22

3+
use super::cvs;
4+
35
pub fn opts() -> TargetOptions {
46
let mut pre_link_args = LinkArgs::new();
57
pre_link_args.insert(
@@ -25,7 +27,7 @@ pub fn opts() -> TargetOptions {
2527
linker: Some("rust-lld".into()),
2628
dynamic_linking: true,
2729
executables: true,
28-
families: vec!["unix".into()],
30+
families: cvs!["unix"],
2931
is_like_fuchsia: true,
3032
pre_link_args,
3133
pre_link_objects: crt_objects::new(&[

0 commit comments

Comments
 (0)