diff options
373 files changed, 3886 insertions, 2288 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index 2e047c7eea1..5e1e1c81d26 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -304,8 +304,12 @@ pub(crate) fn run_aot( }; // FIXME handle `-Ctarget-cpu=native` - let target_cpu = - tcx.sess.opts.cg.target_cpu.as_ref().unwrap_or(&tcx.sess.target.cpu).to_owned(); + let target_cpu = match tcx.sess.opts.cg.target_cpu { + Some(ref name) => name, + None => tcx.sess.target.cpu.as_ref(), + } + .to_owned(); + Box::new(( CodegenResults { modules, diff --git a/compiler/rustc_codegen_gcc/src/common.rs b/compiler/rustc_codegen_gcc/src/common.rs index 61709dd92de..19127c7612d 100644 --- a/compiler/rustc_codegen_gcc/src/common.rs +++ b/compiler/rustc_codegen_gcc/src/common.rs @@ -91,6 +91,10 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { self.const_uint(self.type_i1(), val as u64) } + fn const_i16(&self, i: i16) -> RValue<'gcc> { + self.const_int(self.type_i16(), i as i64) + } + fn const_i32(&self, i: i32) -> RValue<'gcc> { self.const_int(self.type_i32(), i as i64) } diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index eac4a06226c..497a28354d8 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -287,8 +287,10 @@ fn handle_native(name: &str) -> &str { } pub fn target_cpu(sess: &Session) -> &str { - let name = sess.opts.cg.target_cpu.as_ref().unwrap_or(&sess.target.cpu); - handle_native(name) + match sess.opts.cg.target_cpu { + Some(ref name) => handle_native(name), + None => handle_native(sess.target.cpu.as_ref()), + } } pub fn target_features(sess: &Session) -> Vec<Symbol> { diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 101da0012cb..c098ce36f02 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -116,7 +116,7 @@ fn instrument_function_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribu // The function name varies on platforms. // See test/CodeGen/mcount.c in clang. - let mcount_name = cx.sess().target.mcount.as_str(); + let mcount_name = cx.sess().target.mcount.as_ref(); Some(llvm::CreateAttrStringValue( cx.llcx, diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index c4eb593d297..1bbfc13e05e 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -1452,7 +1452,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { } fn fptoint_sat_broken_in_llvm(&self) -> bool { - match self.tcx.sess.target.arch.as_str() { + match self.tcx.sess.target.arch.as_ref() { // FIXME - https://bugs.llvm.org/show_bug.cgi?id=50083 "riscv64" => llvm_util::get_version() < (13, 0, 0), _ => false, diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index b10e74625da..a85b2e6141b 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -147,6 +147,10 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { self.const_uint(self.type_i1(), val as u64) } + fn const_i16(&self, i: i16) -> &'ll Value { + self.const_int(self.type_i16(), i as i64) + } + fn const_i32(&self, i: i32) -> &'ll Value { self.const_int(self.type_i32(), i as i64) } diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 2b76bfdb5ec..98cf873ebbd 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -134,7 +134,7 @@ pub unsafe fn create_module<'ll>( let mod_name = SmallCStr::new(mod_name); let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx); - let mut target_data_layout = sess.target.data_layout.clone(); + let mut target_data_layout = sess.target.data_layout.to_string(); let llvm_version = llvm_util::get_version(); if llvm_version < (13, 0, 0) { if sess.target.arch == "powerpc64" { @@ -859,7 +859,10 @@ impl<'ll> CodegenCx<'ll, '_> { // This isn't an "LLVM intrinsic", but LLVM's optimization passes // recognize it like one and we assume it exists in `core::slice::cmp` - ifn!("memcmp", fn(i8p, i8p, t_isize) -> t_i32); + match self.sess().target.arch.as_ref() { + "avr" | "msp430" => ifn!("memcmp", fn(i8p, i8p, t_isize) -> t_i16), + _ => ifn!("memcmp", fn(i8p, i8p, t_isize) -> t_i32), + } // variadic intrinsics ifn!("llvm.va_start", fn(i8p) -> void); diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 10df671baa2..f4dc33452d1 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -329,7 +329,10 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> { let b_ptr = self.bitcast(b, i8p_ty); let n = self.const_usize(layout.size().bytes()); let cmp = self.call_intrinsic("memcmp", &[a_ptr, b_ptr, n]); - self.icmp(IntPredicate::IntEQ, cmp, self.const_i32(0)) + match self.cx.sess().target.arch.as_ref() { + "avr" | "msp430" => self.icmp(IntPredicate::IntEQ, cmp, self.const_i16(0)), + _ => self.icmp(IntPredicate::IntEQ, cmp, self.const_i32(0)), + } } } diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index abcdb81c0e2..c24e369ae72 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -61,8 +61,8 @@ unsafe fn configure_llvm(sess: &Session) { full_arg.trim().split(|c: char| c == '=' || c.is_whitespace()).next().unwrap_or("") } - let cg_opts = sess.opts.cg.llvm_args.iter(); - let tg_opts = sess.target.llvm_args.iter(); + let cg_opts = sess.opts.cg.llvm_args.iter().map(AsRef::as_ref); + let tg_opts = sess.target.llvm_args.iter().map(AsRef::as_ref); let sess_args = cg_opts.chain(tg_opts); let user_specified_args: FxHashSet<_> = @@ -375,8 +375,10 @@ fn handle_native(name: &str) -> &str { } pub fn target_cpu(sess: &Session) -> &str { - let name = sess.opts.cg.target_cpu.as_ref().unwrap_or(&sess.target.cpu); - handle_native(name) + match sess.opts.cg.target_cpu { + Some(ref name) => handle_native(name), + None => handle_native(sess.target.cpu.as_ref()), + } } /// The list of LLVM features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`, diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 548ae0e411d..84a1043a6a0 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -40,6 +40,7 @@ use std::ffi::OsString; use std::fs::{File, OpenOptions}; use std::io::{BufWriter, Write}; use std::lazy::OnceCell; +use std::ops::Deref; use std::path::{Path, PathBuf}; use std::process::{ExitStatus, Output, Stdio}; use std::{ascii, char, env, fmt, fs, io, mem, str}; @@ -674,11 +675,11 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( linker::disable_localization(&mut cmd); - for &(ref k, ref v) in &sess.target.link_env { - cmd.env(k, v); + for &(ref k, ref v) in sess.target.link_env.as_ref() { + cmd.env(k.as_ref(), v.as_ref()); } - for k in &sess.target.link_env_remove { - cmd.env_remove(k); + for k in sess.target.link_env_remove.as_ref() { + cmd.env_remove(k.as_ref()); } if sess.opts.prints.contains(&PrintRequest::LinkArgs) { @@ -1216,7 +1217,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) { if let Some(ret) = infer_from( sess, - sess.target.linker.clone().map(PathBuf::from), + sess.target.linker.as_deref().map(PathBuf::from), Some(sess.target.linker_flavor), ) { return ret; @@ -1586,7 +1587,7 @@ fn add_post_link_objects( /// FIXME: Determine where exactly these args need to be inserted. fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) { if let Some(args) = sess.target.pre_link_args.get(&flavor) { - cmd.args(args); + cmd.args(args.iter().map(Deref::deref)); } cmd.args(&sess.opts.debugging_opts.pre_link_args); } @@ -1602,7 +1603,7 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty let file_name = ["rustc", &sess.target.llvm_target, "linkfile.ld"].join("-"); let path = tmpdir.join(file_name); - if let Err(e) = fs::write(&path, script) { + if let Err(e) = fs::write(&path, script.as_ref()) { sess.fatal(&format!("failed to write link script to {}: {}", path.display(), e)); } @@ -1634,15 +1635,15 @@ fn add_late_link_args( }); if any_dynamic_crate { if let Some(args) = sess.target.late_link_args_dynamic.get(&flavor) { - cmd.args(args); + cmd.args(args.iter().map(Deref::deref)); } } else { if let Some(args) = sess.target.late_link_args_static.get(&flavor) { - cmd.args(args); + cmd.args(args.iter().map(Deref::deref)); } } if let Some(args) = sess.target.late_link_args.get(&flavor) { - cmd.args(args); + cmd.args(args.iter().map(Deref::deref)); } } @@ -1650,7 +1651,7 @@ fn add_late_link_args( /// FIXME: Determine where exactly these args need to be inserted. fn add_post_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) { if let Some(args) = sess.target.post_link_args.get(&flavor) { - cmd.args(args); + cmd.args(args.iter().map(Deref::deref)); } } @@ -1960,8 +1961,8 @@ fn add_order_independent_options( cmd.arg(&codegen_results.crate_info.target_cpu); cmd.arg("--cpu-features"); cmd.arg(match &sess.opts.cg.target_feature { - feat if !feat.is_empty() => feat, - _ => &sess.target.options.features, + feat if !feat.is_empty() => feat.as_ref(), + _ => sess.target.options.features.as_ref(), }); } @@ -2478,12 +2479,12 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) { let os = &sess.target.os; let llvm_target = &sess.target.llvm_target; if sess.target.vendor != "apple" - || !matches!(os.as_str(), "ios" | "tvos") + || !matches!(os.as_ref(), "ios" | "tvos") || flavor != LinkerFlavor::Gcc { return; } - let sdk_name = match (arch.as_str(), os.as_str()) { + let sdk_name = match (arch.as_ref(), os.as_ref()) { ("aarch64", "tvos") => "appletvos", ("x86_64", "tvos") => "appletvsimulator", ("arm", "ios") => "iphoneos", diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 3a66bfafaf3..2c15ed83167 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -75,7 +75,7 @@ pub fn get_linker<'a>( if let Some(ref tool) = msvc_tool { let original_path = tool.path(); if let Some(ref root_lib_path) = original_path.ancestors().nth(4) { - let arch = match t.arch.as_str() { + let arch = match t.arch.as_ref() { "x86_64" => Some("x64"), "x86" => Some("x86"), "aarch64" => Some("arm64"), @@ -1520,7 +1520,7 @@ impl<'a> L4Bender<'a> { pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> { if let Some(ref exports) = tcx.sess.target.override_export_symbols { - return exports.clone(); + return exports.iter().map(ToString::to_string).collect(); } let mut symbols = Vec::new(); diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index d4eaf6389df..9417874ffb4 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -218,7 +218,7 @@ impl ModuleConfig { false ), emit_obj, - bc_cmdline: sess.target.bitcode_llvm_cmdline.clone(), + bc_cmdline: sess.target.bitcode_llvm_cmdline.to_string(), verify_llvm_ir: sess.verify_llvm_ir(), no_prepopulate_passes: sess.opts.cg.no_prepopulate_passes, @@ -1061,7 +1061,7 @@ fn start_executing_work<B: ExtraBackendMethods>( is_pe_coff: tcx.sess.target.is_like_windows, target_can_use_split_dwarf: tcx.sess.target_can_use_split_dwarf(), target_pointer_width: tcx.sess.target.pointer_width, - target_arch: tcx.sess.target.arch.clone(), + target_arch: tcx.sess.target.arch.to_string(), debuginfo: tcx.sess.opts.debuginfo, split_debuginfo: tcx.sess.split_debuginfo(), split_dwarf_kind: tcx.sess.opts.debugging_opts.split_dwarf_kind, diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 6cf6be79a86..a2d60472ed9 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -29,6 +29,7 @@ use rustc_hir::LangItem; use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::dependency_format::Dependencies; use rustc_middle::ty::query::{ExternProviders, Providers}; +use rustc_serialize::{opaque, Decodable, Decoder, Encoder}; use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT}; use rustc_session::cstore::{self, CrateSource}; use rustc_session::utils::NativeLibKind; @@ -190,3 +191,53 @@ pub fn looks_like_rust_object_file(filename: &str) -> bool { // Check if the "inner" extension ext2 == Some(RUST_CGU_EXT) } + +const RLINK_VERSION: u32 = 1; +const RLINK_MAGIC: &[u8] = b"rustlink"; + +const RUSTC_VERSION: Option<&str> = option_env!("CFG_VERSION"); + +impl CodegenResults { + pub fn serialize_rlink(codegen_results: &CodegenResults) -> Vec<u8> { + let mut encoder = opaque::Encoder::new(vec![]); + encoder.emit_raw_bytes(RLINK_MAGIC).unwrap(); + // `emit_raw_bytes` is used to make sure that the version representation does not depend on + // Encoder's inner representation of `u32`. + encoder.emit_raw_bytes(&RLINK_VERSION.to_be_bytes()).unwrap(); + encoder.emit_str(RUSTC_VERSION.unwrap()).unwrap(); + + let mut encoder = rustc_serialize::opaque::Encoder::new(encoder.into_inner()); + rustc_serialize::Encodable::encode(codegen_results, &mut encoder).unwrap(); + encoder.into_inner() + } + + pub fn deserialize_rlink(data: Vec<u8>) -> Result<Self, String> { + // The Decodable machinery is not used here because it panics if the input data is invalid + // and because its internal representation may change. + if !data.starts_with(RLINK_MAGIC) { + return Err("The input does not look like a .rlink file".to_string()); + } + let data = &data[RLINK_MAGIC.len()..]; + if data.len() < 4 { + return Err("The input does not contain version number".to_string()); + } + + let mut version_array: [u8; 4] = Default::default(); + version_array.copy_from_slice(&data[..4]); + if u32::from_be_bytes(version_array) != RLINK_VERSION { + return Err(".rlink file was produced with encoding version {version_array}, but the current version is {RLINK_VERSION}".to_string()); + } + + let mut decoder = opaque::Decoder::new(&data[4..], 0); + let rustc_version = decoder.read_str(); + let current_version = RUSTC_VERSION.unwrap(); + if rustc_version != current_version { + return Err(format!( + ".rlink file was produced by rustc version {rustc_version}, but the current version is {current_version}." + )); + } + + let codegen_results = CodegenResults::decode(&mut decoder); + Ok(codegen_results) + } +} diff --git a/compiler/rustc_codegen_ssa/src/traits/consts.rs b/compiler/rustc_codegen_ssa/src/traits/consts.rs index 918f3684169..c3519a24d53 100644 --- a/compiler/rustc_codegen_ssa/src/traits/consts.rs +++ b/compiler/rustc_codegen_ssa/src/traits/consts.rs @@ -13,6 +13,7 @@ pub trait ConstMethods<'tcx>: BackendTypes { fn const_uint(&self, t: Self::Type, i: u64) -> Self::Value; fn const_uint_big(&self, t: Self::Type, u: u128) -> Self::Value; fn const_bool(&self, val: bool) -> Self::Value; + fn const_i16(&self, i: i16) -> Self::Value; fn const_i32(&self, i: i32) -> Self::Value; fn const_u32(&self, i: u32) -> Self::Value; fn const_u64(&self, i: u64) -> Self::Value; diff --git a/compiler/rustc_const_eval/src/const_eval/fn_queries.rs b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs index 05fbbf45d7c..19a543ae777 100644 --- a/compiler/rustc_const_eval/src/const_eval/fn_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs @@ -1,7 +1,8 @@ use rustc_hir as hir; +use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::ty::query::Providers; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{DefIdTree, TyCtxt}; use rustc_span::symbol::Symbol; use rustc_target::spec::abi::Abi; @@ -16,44 +17,47 @@ pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> { } pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { - let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); - let parent_id = tcx.hir().get_parent_node(hir_id); - matches!( - tcx.hir().get(parent_id), - hir::Node::Item(hir::Item { - kind: hir::ItemKind::Impl(hir::Impl { constness: hir::Constness::Const, .. }), - .. - }) - ) + let parent_id = tcx.local_parent(def_id).unwrap(); + tcx.def_kind(parent_id) == DefKind::Impl + && tcx.impl_constness(parent_id) == hir::Constness::Const } /// Checks whether the function has a `const` modifier or, in case it is an intrinsic, whether /// said intrinsic has a `rustc_const_{un,}stable` attribute. -fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool { +fn impl_constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness { let def_id = def_id.expect_local(); let node = tcx.hir().get_by_def_id(def_id); - if let hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) = - node - { - // Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other - // foreign items cannot be evaluated at compile-time. - let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); - if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = tcx.hir().get_foreign_abi(hir_id) { - tcx.lookup_const_stability(def_id).is_some() - } else { - false - } - } else if let Some(fn_kind) = node.fn_kind() { - if fn_kind.constness() == hir::Constness::Const { - return true; + match node { + hir::Node::Ctor(_) => hir::Constness::Const, + hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.constness, + hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) => { + // Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other + // foreign items cannot be evaluated at compile-time. + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); + let is_const = if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = + tcx.hir().get_foreign_abi(hir_id) + { + tcx.lookup_const_stability(def_id).is_some() + } else { + false + }; + if is_const { hir::Constness::Const } else { hir::Constness::NotConst } } + _ => { + if let Some(fn_kind) = node.fn_kind() { + if fn_kind.constness() == hir::Constness::Const { + return hir::Constness::Const; + } - // If the function itself is not annotated with `const`, it may still be a `const fn` - // if it resides in a const trait impl. - is_parent_const_impl_raw(tcx, def_id) - } else { - matches!(node, hir::Node::Ctor(_)) + // If the function itself is not annotated with `const`, it may still be a `const fn` + // if it resides in a const trait impl. + let is_const = is_parent_const_impl_raw(tcx, def_id); + if is_const { hir::Constness::Const } else { hir::Constness::NotConst } + } else { + hir::Constness::NotConst + } + } } } @@ -77,5 +81,5 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool { } pub fn provide(providers: &mut Providers) { - *providers = Providers { is_const_fn_raw, is_promotable_const_fn, ..*providers }; + *providers = Providers { impl_constness, is_promotable_const_fn, ..*providers }; } diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index abd7094440e..1b8186b5aad 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -23,8 +23,8 @@ use rustc_target::abi::{call::FnAbi, Align, HasDataLayout, Size, TargetDataLayou use super::{ AllocCheck, AllocId, GlobalId, Immediate, InterpErrorInfo, InterpResult, MPlaceTy, Machine, - MemPlace, MemPlaceMeta, Memory, MemoryKind, Operand, Place, PlaceTy, Pointer, Provenance, - Scalar, ScalarMaybeUninit, StackPopJump, + MemPlace, MemPlaceMeta, Memory, MemoryKind, Operand, Place, PlaceTy, Pointer, + PointerArithmetic, Provenance, Scalar, ScalarMaybeUninit, StackPopJump, }; use crate::transform::validate::equal_up_to_regions; @@ -678,7 +678,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let size = size.align_to(align); // Check if this brought us over the size limit. - if size.bytes() >= self.tcx.data_layout.obj_size_bound() { + if size > self.max_size_of_val() { throw_ub!(InvalidMeta("total size is bigger than largest supported object")); } Ok(Some((size, align))) @@ -694,9 +694,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let elem = layout.field(self, 0); // Make sure the slice is not too big. - let size = elem.size.checked_mul(len, self).ok_or_else(|| { - err_ub!(InvalidMeta("slice is bigger than largest supported object")) - })?; + let size = elem.size.bytes().saturating_mul(len); // we rely on `max_size_of_val` being smaller than `u64::MAX`. + let size = Size::from_bytes(size); + if size > self.max_size_of_val() { + throw_ub!(InvalidMeta("slice is bigger than largest supported object")); + } Ok(Some((size, elem.align.abi))) } diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 5eff7d693c5..c80d7d71787 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -531,7 +531,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ) -> InterpResult<'tcx, Pointer<Option<M::PointerTag>>> { // We cannot overflow i64 as a type's size must be <= isize::MAX. let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap(); - // The computed offset, in bytes, cannot overflow an isize. + // The computed offset, in bytes, must not overflow an isize. + // `checked_mul` enforces a too small bound, but no actual allocation can be big enough for + // the difference to be noticeable. let offset_bytes = offset_count.checked_mul(pointee_size).ok_or(err_ub!(PointerArithOverflow))?; // The offset being in bounds cannot rely on "wrapping around" the address space. @@ -563,6 +565,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let count = self.read_scalar(&count)?.to_machine_usize(self)?; let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?; let (size, align) = (layout.size, layout.align.abi); + // `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max), + // but no actual allocation can be big enough for the difference to be noticeable. let size = size.checked_mul(count, self).ok_or_else(|| { err_ub_format!( "overflow computing total size of `{}`", @@ -588,6 +592,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let byte = self.read_scalar(&byte)?.to_u8()?; let count = self.read_scalar(&count)?.to_machine_usize(self)?; + // `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max), + // but no actual allocation can be big enough for the difference to be noticeable. let len = layout .size .checked_mul(count, self) diff --git a/compiler/rustc_const_eval/src/interpret/traits.rs b/compiler/rustc_const_eval/src/interpret/traits.rs index 131674decc9..fc60a40e2ad 100644 --- a/compiler/rustc_const_eval/src/interpret/traits.rs +++ b/compiler/rustc_const_eval/src/interpret/traits.rs @@ -110,16 +110,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { .read_ptr_sized(pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES_SIZE).unwrap())? .check_init()?; let size = size.to_machine_usize(self)?; + let size = Size::from_bytes(size); let align = vtable .read_ptr_sized(pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES_ALIGN).unwrap())? .check_init()?; let align = align.to_machine_usize(self)?; let align = Align::from_bytes(align).map_err(|e| err_ub!(InvalidVtableAlignment(e)))?; - if size >= self.tcx.data_layout.obj_size_bound() { + if size > self.max_size_of_val() { throw_ub!(InvalidVtableSize); } - Ok((Size::from_bytes(size), align)) + Ok((size, align)) } pub fn read_new_vtable_after_trait_upcasting_from_vtable( diff --git a/compiler/rustc_data_structures/src/map_in_place.rs b/compiler/rustc_data_structures/src/map_in_place.rs index 5dd9fc6e8bc..874de03d37a 100644 --- a/compiler/rustc_data_structures/src/map_in_place.rs +++ b/compiler/rustc_data_structures/src/map_in_place.rs @@ -30,13 +30,13 @@ impl<T> MapInPlace<T> for Vec<T> { while read_i < old_len { // move the read_i'th item out of the vector and map it // to an iterator - let e = ptr::read(self.get_unchecked(read_i)); + let e = ptr::read(self.as_ptr().add(read_i)); let iter = f(e).into_iter(); read_i += 1; for e in iter { if write_i < read_i { - ptr::write(self.get_unchecked_mut(write_i), e); + ptr::write(self.as_mut_ptr().add(write_i), e); write_i += 1; } else { // If this is reached we ran out of space @@ -76,13 +76,13 @@ impl<T, A: Array<Item = T>> MapInPlace<T> for SmallVec<A> { while read_i < old_len { // move the read_i'th item out of the vector and map it // to an iterator - let e = ptr::read(self.get_unchecked(read_i)); + let e = ptr::read(self.as_ptr().add(read_i)); let iter = f(e).into_iter(); read_i += 1; for e in iter { if write_i < read_i { - ptr::write(self.get_unchecked_mut(write_i), e); + ptr::write(self.as_mut_ptr().add(write_i), e); write_i += 1; } else { // If this is reached we ran out of space diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 667c63b709b..69f96d07f90 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -588,8 +588,12 @@ pub fn try_process_rlink(sess: &Session, compiler: &interface::Compiler) -> Comp let rlink_data = fs::read(file).unwrap_or_else(|err| { sess.fatal(&format!("failed to read rlink file: {}", err)); }); - let mut decoder = rustc_serialize::opaque::Decoder::new(&rlink_data, 0); - let codegen_results: CodegenResults = rustc_serialize::Decodable::decode(&mut decoder); + let codegen_results = match CodegenResults::deserialize_rlink(rlink_data) { + Ok(codegen) => codegen, + Err(error) => { + sess.fatal(&format!("Could not deserialize .rlink file: {error}")); + } + }; let result = compiler.codegen_backend().link(sess, codegen_results, &outputs); abort_on_err(result, sess); } else { diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index 791ba560607..f5a93905b82 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -1,5 +1,6 @@ #![feature(associated_type_bounds)] #![feature(associated_type_defaults)] +#![feature(box_patterns)] #![feature(box_syntax)] #![feature(crate_visibility_modifier)] #![feature(decl_macro)] diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 18302ffdb8e..7d4de72c3fe 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -75,7 +75,7 @@ crate use ParseResult::*; use crate::mbe::{self, SequenceRepetition, TokenTree}; -use rustc_ast::token::{self, DocComment, Nonterminal, Token}; +use rustc_ast::token::{self, DocComment, Nonterminal, Token, TokenKind}; use rustc_parse::parser::{NtOrTt, Parser}; use rustc_session::parse::ParseSess; use rustc_span::symbol::MacroRulesNormalizedIdent; @@ -87,17 +87,6 @@ use rustc_data_structures::sync::Lrc; use rustc_span::symbol::Ident; use std::borrow::Cow; use std::collections::hash_map::Entry::{Occupied, Vacant}; -use std::mem; - -/// This is used by `parse_tt_inner` to keep track of delimited submatchers that we have -/// descended into. -#[derive(Clone)] -struct MatcherPosFrame<'tt> { - /// The "parent" matcher that we have descended from. - tts: &'tt [TokenTree], - /// The position of the "dot" in `tt` at the time we descended. - idx: usize, -} // One element is enough to cover 95-99% of vectors for most benchmarks. Also, // vectors longer than one frequently have many elements, not just two or @@ -108,6 +97,33 @@ type NamedMatchVec = SmallVec<[NamedMatch; 1]>; #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] rustc_data_structures::static_assert_size!(NamedMatchVec, 48); +#[derive(Clone)] +enum MatcherKind<'tt> { + TopLevel, + Delimited(Box<DelimitedSubmatcher<'tt>>), + Sequence(Box<SequenceSubmatcher<'tt>>), +} + +#[derive(Clone)] +struct DelimitedSubmatcher<'tt> { + parent: Parent<'tt>, +} + +#[derive(Clone)] +struct SequenceSubmatcher<'tt> { + parent: Parent<'tt>, + seq: &'tt SequenceRepetition, +} + +/// Data used to ascend from a submatcher back to its parent matcher. A subset of the fields from +/// `MathcherPos`. +#[derive(Clone)] +struct Parent<'tt> { + tts: &'tt [TokenTree], + idx: usize, + kind: MatcherKind<'tt>, +} + /// A single matcher position, which could be within the top-level matcher, a submatcher, a /// subsubmatcher, etc. For example: /// ```text @@ -116,13 +132,14 @@ rustc_data_structures::static_assert_size!(NamedMatchVec, 48); /// <--------------> first submatcher; three tts, zero metavars /// <--------------------------> top-level matcher; two tts, one metavar /// ``` -#[derive(Clone)] struct MatcherPos<'tt> { /// The tokens that make up the current matcher. When we are within a `Sequence` or `Delimited` /// submatcher, this is just the contents of that submatcher. tts: &'tt [TokenTree], - /// The "dot" position within the current submatcher, i.e. the index into `tts`. + /// The "dot" position within the current submatcher, i.e. the index into `tts`. Can go one or + /// two positions past the final elements in `tts` when dealing with sequences, see + /// `parse_tt_inner` for details. idx: usize, /// This vector ends up with one element per metavar in the *top-level* matcher, even when this @@ -134,25 +151,18 @@ struct MatcherPos<'tt> { /// The number of sequences this mp is within. seq_depth: usize, - /// The position in `matches` of the first metavar in this (sub)matcher. Zero if there are - /// no metavars. - match_lo: usize, - /// The position in `matches` of the next metavar to be matched against the source token /// stream. Should not be used if there are no metavars. match_cur: usize, - /// This field is only used if we are matching a sequence. - sequence: Option<MatcherPosSequence<'tt>>, - - /// When we are within a `Delimited` submatcher (or subsubmatcher), this tracks the parent - /// matcher(s). The bottom of the stack is the top-level matcher. - stack: SmallVec<[MatcherPosFrame<'tt>; 1]>, + /// What kind of matcher we are in. For submatchers, this contains enough information to + /// reconstitute a `MatcherPos` within the parent once we ascend out of the submatcher. + kind: MatcherKind<'tt>, } // This type is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(MatcherPos<'_>, 104); +rustc_data_structures::static_assert_size!(MatcherPos<'_>, 64); impl<'tt> MatcherPos<'tt> { fn top_level(matcher: &'tt [TokenTree], empty_matches: Lrc<NamedMatchVec>) -> Self { @@ -161,31 +171,50 @@ impl<'tt> MatcherPos<'tt> { idx: 0, matches: empty_matches, seq_depth: 0, - match_lo: 0, match_cur: 0, - stack: smallvec![], - sequence: None, + kind: MatcherKind::TopLevel, + } + } + + fn empty_sequence( + parent_mp: &MatcherPos<'tt>, + seq: &'tt SequenceRepetition, + empty_matches: Lrc<NamedMatchVec>, + ) -> Self { + let mut mp = MatcherPos { + tts: parent_mp.tts, + idx: parent_mp.idx + 1, + matches: parent_mp.matches.clone(), // a cheap clone + seq_depth: parent_mp.seq_depth, + match_cur: parent_mp.match_cur + seq.num_captures, + kind: parent_mp.kind.clone(), // an expensive clone + }; + for idx in parent_mp.match_cur..parent_mp.match_cur + seq.num_captures { + mp.push_match(idx, MatchedSeq(empty_matches.clone())); } + mp } fn sequence( - parent: Box<MatcherPos<'tt>>, + parent_mp: Box<MatcherPos<'tt>>, seq: &'tt SequenceRepetition, empty_matches: Lrc<NamedMatchVec>, ) -> Self { + let seq_kind = box SequenceSubmatcher { + parent: Parent { tts: parent_mp.tts, idx: parent_mp.idx, kind: parent_mp.kind }, + seq, + }; let mut mp = MatcherPos { tts: &seq.tts, idx: 0, - matches: parent.matches.clone(), - seq_depth: parent.seq_depth, - match_lo: parent.match_cur, - match_cur: parent.match_cur, - sequence: Some(MatcherPosSequence { parent, seq }), - stack: smallvec![], + matches: parent_mp.matches, + seq_depth: parent_mp.seq_depth, + match_cur: parent_mp.match_cur, + kind: MatcherKind::Sequence(seq_kind), }; // Start with an empty vec for each metavar within the sequence. Note that `mp.seq_depth` // must have the parent's depth at this point for these `push_match` calls to work. - for idx in mp.match_lo..mp.match_lo + seq.num_captures { + for idx in mp.match_cur..mp.match_cur + seq.num_captures { mp.push_match(idx, MatchedSeq(empty_matches.clone())); } mp.seq_depth += 1; @@ -226,16 +255,6 @@ impl<'tt> MatcherPos<'tt> { } } -#[derive(Clone)] -struct MatcherPosSequence<'tt> { - /// The parent matcher position. Effectively gives a linked list of matches all the way to the - /// top-level matcher. - parent: Box<MatcherPos<'tt>>, - - /// The sequence itself. - seq: &'tt SequenceRepetition, -} - enum EofMatcherPositions<'tt> { None, One(Box<MatcherPos<'tt>>), @@ -263,18 +282,12 @@ crate type NamedParseResult = ParseResult<FxHashMap<MacroRulesNormalizedIdent, N pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize { matcher .iter() - .map(|tt| { - match tt { - TokenTree::Delimited(_, delim) => count_metavar_decls(delim.inner_tts()), - TokenTree::MetaVar(..) => 0, - TokenTree::MetaVarDecl(..) => 1, - // RHS meta-variable expressions eventually end-up here. `0` is returned to inform - // that no meta-variable was found, because "meta-variables" != "meta-variable - // expressions". - TokenTree::MetaVarExpr(..) => 0, - TokenTree::Sequence(_, seq) => seq.num_captures, - TokenTree::Token(..) => 0, - } + .map(|tt| match tt { + TokenTree::MetaVarDecl(..) => 1, + TokenTree::Sequence(_, seq) => seq.num_captures, + TokenTree::Delimited(_, delim) => count_metavar_decls(delim.inner_tts()), + TokenTree::Token(..) => 0, + TokenTree::MetaVar(..) | TokenTree::MetaVarExpr(..) => unreachable!(), }) .sum() } @@ -454,18 +467,6 @@ impl<'tt> TtParser<'tt> { let mut eof_mps = EofMatcherPositions::None; while let Some(mut mp) = self.cur_mps.pop() { - // Backtrack out of delimited submatcher when necessary. When backtracking out again, - // we need to advance the "dot" past the delimiters in the parent matcher(s). - while mp.idx >= mp.tts.len() { - match mp.stack.pop() { - Some(MatcherPosFrame { tts, idx }) => { - mp.tts = tts; - mp.idx = idx + 1; - } - None => break, - } - } - // Get the current position of the "dot" (`idx`) in `mp` and the number of token // trees in the matcher (`len`). let idx = mp.idx; @@ -479,13 +480,11 @@ impl<'tt> TtParser<'tt> { let op = seq.kleene.op; if op == mbe::KleeneOp::ZeroOrMore || op == mbe::KleeneOp::ZeroOrOne { // Allow for the possibility of zero matches of this sequence. - let mut new_mp = mp.clone(); - new_mp.match_cur += seq.num_captures; - new_mp.idx += 1; - for idx in mp.match_cur..mp.match_cur + seq.num_captures { - new_mp.push_match(idx, MatchedSeq(self.empty_matches.clone())); - } - self.cur_mps.push(new_mp); + self.cur_mps.push(box MatcherPos::empty_sequence( + &*mp, + &seq, + self.empty_matches.clone(), + )); } // Allow for the possibility of one or more matches of this sequence. @@ -515,16 +514,17 @@ impl<'tt> TtParser<'tt> { } TokenTree::Delimited(_, delimited) => { - // To descend into a delimited submatcher, we push the current matcher onto - // a stack and push a new mp containing the submatcher onto `cur_mps`. - // - // At the beginning of the loop, if we reach the end of the delimited - // submatcher, we pop the stack to backtrack out of the descent. Note that - // we use `all_tts` to include the open and close delimiter tokens. - let tts = mem::replace(&mut mp.tts, &delimited.all_tts); - let idx = mp.idx; - mp.stack.push(MatcherPosFrame { tts, idx }); + // To descend into a delimited submatcher, we update `mp` appropriately, + // including enough information to re-ascend afterwards, and push it onto + // `cur_mps`. Later, when we reach the closing delimiter, we will recover + // the parent matcher position to ascend. Note that we use `all_tts` to + // include the open and close delimiter tokens. + let kind = MatcherKind::Delimited(box DelimitedSubmatcher { + parent: Parent { tts: mp.tts, idx: mp.idx, kind: mp.kind }, + }); + mp.tts = &delimited.all_tts; mp.idx = 0; + mp.kind = kind; self.cur_mps.push(mp); } @@ -542,6 +542,18 @@ impl<'tt> TtParser<'tt> { mp.idx += 1; self.cur_mps.push(mp); } else if token_name_eq(&t, token) { + if let TokenKind::CloseDelim(_) = token.kind { + // Ascend out of the delimited submatcher. + debug_assert_eq!(idx, len - 1); + match mp.kind { + MatcherKind::Delimited(submatcher) => { + mp.tts = submatcher.parent.tts; + mp.idx = submatcher.parent.idx; + mp.kind = submatcher.parent.kind; + } + _ => unreachable!(), + } + } mp.idx += 1; self.next_mps.push(mp); } @@ -550,38 +562,44 @@ impl<'tt> TtParser<'tt> { // These cannot appear in a matcher. TokenTree::MetaVar(..) | TokenTree::MetaVarExpr(..) => unreachable!(), } - } else if let Some(sequence) = &mp.sequence { + } else if let MatcherKind::Sequence(box SequenceSubmatcher { parent, seq }) = &mp.kind { // We are past the end of a sequence. - debug_assert!(idx <= len + 1); + // - If it has no separator, we must be only one past the end. + // - If it has a separator, we may be one past the end, in which case we must + // look for a separator. Or we may be two past the end, in which case we have + // already dealt with the separator. + debug_assert!(idx == len || idx == len + 1 && seq.separator.is_some()); if idx == len { - // Add all matches from the sequence to `parent`, and move the "dot" past the - // sequence in `parent`. This allows for the case where the sequence matching - // is finished. - let mut new_mp = sequence.parent.clone(); - new_mp.matches = mp.matches.clone(); - new_mp.match_cur = mp.match_lo + sequence.seq.num_captures; - new_mp.idx += 1; + // Sequence matching may have finished: move the "dot" past the sequence in + // `parent`. This applies whether a separator is used or not. If sequence + // matching hasn't finished, this `new_mp` will fail quietly when it is + // processed next time around the loop. + let new_mp = box MatcherPos { + tts: parent.tts, + idx: parent.idx + 1, + matches: mp.matches.clone(), // a cheap clone + seq_depth: mp.seq_depth - 1, + match_cur: mp.match_cur, + kind: parent.kind.clone(), // an expensive clone + }; self.cur_mps.push(new_mp); } - if idx == len && sequence.seq.separator.is_some() { - if sequence - .seq - .separator - .as_ref() - .map_or(false, |sep| token_name_eq(token, sep)) - { + if seq.separator.is_some() && idx == len { + // Look for the separator. + if seq.separator.as_ref().map_or(false, |sep| token_name_eq(token, sep)) { // The matcher has a separator, and it matches the current token. We can // advance past the separator token. mp.idx += 1; self.next_mps.push(mp); } - } else if sequence.seq.kleene.op != mbe::KleeneOp::ZeroOrOne { - // We don't need a separator. Move the "dot" back to the beginning of the - // matcher and try to match again UNLESS we are only allowed to have _one_ - // repetition. - mp.match_cur = mp.match_lo; + } else if seq.kleene.op != mbe::KleeneOp::ZeroOrOne { + // We don't need to look for a separator: either this sequence doesn't have + // one, or it does and we've already handled it. Also, we are allowed to have + // more than one repetition. Move the "dot" back to the beginning of the + // matcher and try to match again. + mp.match_cur -= seq.num_captures; mp.idx = 0; self.cur_mps.push(mp); } diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index d91871c7e57..48abbd7c18e 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -1,4 +1,4 @@ -use crate::mbe::macro_parser; +use crate::mbe::macro_parser::count_metavar_decls; use crate::mbe::{Delimited, KleeneOp, KleeneToken, MetaVarExpr, SequenceRepetition, TokenTree}; use rustc_ast::token::{self, Token}; @@ -211,14 +211,15 @@ fn parse_tree( let (separator, kleene) = parse_sep_and_kleene_op(&mut trees, delim_span.entire(), sess); // Count the number of captured "names" (i.e., named metavars) - let name_captures = macro_parser::count_metavar_decls(&sequence); + let num_captures = + if parsing_patterns { count_metavar_decls(&sequence) } else { 0 }; TokenTree::Sequence( delim_span, Lrc::new(SequenceRepetition { tts: sequence, separator, kleene, - num_captures: name_captures, + num_captures, }), ) } diff --git a/compiler/rustc_infer/src/infer/canonical/mod.rs b/compiler/rustc_infer/src/infer/canonical/mod.rs index 79856867985..c7fa2527eb2 100644 --- a/compiler/rustc_infer/src/infer/canonical/mod.rs +++ b/compiler/rustc_infer/src/infer/canonical/mod.rs @@ -49,7 +49,6 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { /// At the end of processing, the substitution S (once /// canonicalized) then represents the values that you computed /// for each of the canonical inputs to your query. - pub fn instantiate_canonical_with_fresh_inference_vars<T>( &self, span: Span, diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 41995ca509e..86229dbfad7 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -27,15 +27,12 @@ use super::glb::Glb; use super::lub::Lub; use super::sub::Sub; use super::type_variable::TypeVariableValue; -use super::unify_key::replace_if_possible; -use super::unify_key::{ConstVarValue, ConstVariableValue}; -use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use super::{InferCtxt, MiscVariable, TypeTrace}; - use crate::traits::{Obligation, PredicateObligations}; - use rustc_data_structures::sso::SsoHashMap; use rustc_hir::def_id::DefId; +use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue}; +use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation}; @@ -140,8 +137,8 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> { return Ok(a); } - let a = replace_if_possible(&mut self.inner.borrow_mut().const_unification_table(), a); - let b = replace_if_possible(&mut self.inner.borrow_mut().const_unification_table(), b); + let a = self.shallow_resolve(a); + let b = self.shallow_resolve(b); let a_is_expected = relation.a_is_expected(); diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 9b2fc07e9cb..d915f9a5ae8 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1091,7 +1091,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// Compares two given types, eliding parts that are the same between them and highlighting /// relevant differences, and return two representation of those types for highlighted printing. - fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> (DiagnosticStyledString, DiagnosticStyledString) { + pub fn cmp( + &self, + t1: Ty<'tcx>, + t2: Ty<'tcx>, + ) -> (DiagnosticStyledString, DiagnosticStyledString) { debug!("cmp(t1={}, t1.kind={:?}, t2={}, t2.kind={:?})", t1, t1.kind(), t2, t2.kind()); // helper functions diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index 4fcdcb63666..c33c0c996bd 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -237,7 +237,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { ObligationCauseCode::MatchImpl(parent, ..) => parent.code(), _ => cause.code(), } - && let (ObligationCauseCode::ItemObligation(item_def_id), None) = (code, override_error_code) + && let (&ObligationCauseCode::ItemObligation(item_def_id), None) = (code, override_error_code) { // Same case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a `'static` // lifetime as above, but called using a fully-qualified path to the method: @@ -245,7 +245,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { let mut v = TraitObjectVisitor(FxHashSet::default()); v.visit_ty(param.param_ty); if let Some((ident, self_ty)) = - self.get_impl_ident_and_self_ty_from_trait(*item_def_id, &v.0) + self.get_impl_ident_and_self_ty_from_trait(item_def_id, &v.0) && self.suggest_constrain_dyn_trait_in_impl(&mut err, &v.0, ident, self_ty) { override_error_code = Some(ident.name); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs index b1a42ee66c9..6d23dc4f471 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs @@ -7,7 +7,7 @@ use crate::traits::ObligationCauseCode::CompareImplMethodObligation; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::Res; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::Visitor; use rustc_middle::hir::nested_filter; use rustc_middle::ty::print::RegionHighlightMode; @@ -51,7 +51,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { { let guar = self.emit_associated_type_err( span, - self.infcx.tcx.item_name(impl_item_def_id), + self.infcx.tcx.item_name(impl_item_def_id.to_def_id()), impl_item_def_id, trait_item_def_id, ); @@ -155,7 +155,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { &self, span: Span, item_name: Symbol, - impl_item_def_id: DefId, + impl_item_def_id: LocalDefId, trait_item_def_id: DefId, ) -> ErrorGuaranteed { let impl_sp = self.tcx().def_span(impl_item_def_id); diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index e6c8dc302b6..5dcac7f56cc 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -348,7 +348,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let mut err = self.report_concrete_failure(*parent, sub, sup); let trait_item_span = self.tcx.def_span(trait_item_def_id); - let item_name = self.tcx.item_name(impl_item_def_id); + let item_name = self.tcx.item_name(impl_item_def_id.to_def_id()); err.span_label( trait_item_span, format!("definition of `{}` from trait", item_name), @@ -370,7 +370,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let where_clause_span = self .tcx .hir() - .get_generics(impl_item_def_id.expect_local()) + .get_generics(impl_item_def_id) .unwrap() .where_clause .tail_span_for_suggestion(); diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index e9d3b6a8aa1..0a11a81c294 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -30,17 +30,13 @@ //! solving a set of constraints. In contrast, the type inferencer assigns a value to each type //! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type //! inferencer knows "so far". - +use super::InferCtxt; +use rustc_data_structures::fx::FxHashMap; +use rustc_middle::infer::unify_key::ToType; use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; - -use rustc_data_structures::fx::FxHashMap; - use std::collections::hash_map::Entry; -use super::unify_key::ToType; -use super::InferCtxt; - pub struct TypeFreshener<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, ty_freshen_count: u32, diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index bd59bf4dea8..2524bd78355 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -70,8 +70,6 @@ mod sub; pub mod type_variable; mod undo_log; -pub use rustc_middle::infer::unify_key; - #[must_use] #[derive(Debug)] pub struct InferOk<'tcx, T> { @@ -425,16 +423,20 @@ pub enum SubregionOrigin<'tcx> { /// Comparing the signature and requirements of an impl method against /// the containing trait. - CompareImplMethodObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId }, + CompareImplMethodObligation { + span: Span, + impl_item_def_id: LocalDefId, + trait_item_def_id: DefId, + }, /// Comparing the signature and requirements of an impl associated type /// against the containing trait - CompareImplTypeObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId }, + CompareImplTypeObligation { span: Span, impl_item_def_id: LocalDefId, trait_item_def_id: DefId }, /// Checking that the bounds of a trait's associated type hold for a given impl CheckAssociatedTypeBounds { parent: Box<SubregionOrigin<'tcx>>, - impl_item_def_id: DefId, + impl_item_def_id: LocalDefId, trait_item_def_id: DefId, }, } @@ -558,9 +560,9 @@ impl<'tcx> fmt::Display for FixupError<'tcx> { } } -/// Helper type of a temporary returned by `tcx.infer_ctxt()`. -/// Necessary because we can't write the following bound: -/// `F: for<'b, 'tcx> where 'tcx FnOnce(InferCtxt<'b, 'tcx>)`. +/// A temporary returned by `tcx.infer_ctxt()`. This is necessary +/// for multiple `InferCtxt` to share the same `in_progress_typeck_results` +/// without using `Rc` or something similar. pub struct InferCtxtBuilder<'tcx> { tcx: TyCtxt<'tcx>, fresh_typeck_results: Option<RefCell<ty::TypeckResults<'tcx>>>, diff --git a/compiler/rustc_infer/src/traits/error_reporting/mod.rs b/compiler/rustc_infer/src/traits/error_reporting/mod.rs index c8ef08f48b6..25b11e31d57 100644 --- a/compiler/rustc_infer/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/traits/error_reporting/mod.rs @@ -4,7 +4,7 @@ use crate::infer::InferCtxt; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorGuaranteed}; use rustc_hir as hir; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::ty::TyCtxt; use rustc_span::{MultiSpan, Span}; use std::fmt; @@ -14,7 +14,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn report_extra_impl_obligation( &self, error_span: Span, - impl_item_def_id: DefId, + impl_item_def_id: LocalDefId, trait_item_def_id: DefId, requirement: &dyn fmt::Display, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { @@ -25,7 +25,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if let Some(trait_item_span) = self.tcx.hir().span_if_local(trait_item_def_id) { let span = self.tcx.sess.source_map().guess_head_span(trait_item_span); - let item_name = self.tcx.item_name(impl_item_def_id); + let item_name = self.tcx.item_name(impl_item_def_id.to_def_id()); err.span_label(span, format!("definition of `{}` from trait", item_name)); } diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 6373f4e9af1..22ab62ac372 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -3,6 +3,7 @@ use crate::passes::{self, BoxedResolver, QueryContext}; use rustc_ast as ast; use rustc_codegen_ssa::traits::CodegenBackend; +use rustc_codegen_ssa::CodegenResults; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal}; use rustc_hir::def_id::LOCAL_CRATE; @@ -360,10 +361,9 @@ impl Linker { } if sess.opts.debugging_opts.no_link { - let mut encoder = rustc_serialize::opaque::Encoder::new(Vec::new()); - rustc_serialize::Encodable::encode(&codegen_results, &mut encoder).unwrap(); + let encoded = CodegenResults::serialize_rlink(&codegen_results); let rlink_file = self.prepare_outputs.with_extension(config::RLINK_EXT); - std::fs::write(&rlink_file, encoder.into_inner()).map_err(|err| { + std::fs::write(&rlink_file, encoded).map_err(|err| { sess.fatal(&format!("failed to write file {}: {}", rlink_file.display(), err)); })?; return Ok(()); diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 50a3df21a3b..d43c661dda6 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2548,7 +2548,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { /// Return `Some` only if we are sure this type does *not* /// allow zero initialization. fn ty_find_init_error<'tcx>( - tcx: TyCtxt<'tcx>, + cx: &LateContext<'tcx>, ty: Ty<'tcx>, init: InitKind, ) -> Option<InitError> { @@ -2575,7 +2575,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { Adt(adt_def, substs) if !adt_def.is_union() => { // First check if this ADT has a layout attribute (like `NonNull` and friends). use std::ops::Bound; - match tcx.layout_scalar_valid_range(adt_def.did()) { + match cx.tcx.layout_scalar_valid_range(adt_def.did()) { // We exploit here that `layout_scalar_valid_range` will never // return `Bound::Excluded`. (And we have tests checking that we // handle the attribute correctly.) @@ -2603,12 +2603,12 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { // Proceed recursively, check all fields. let variant = &adt_def.variant(VariantIdx::from_u32(0)); variant.fields.iter().find_map(|field| { - ty_find_init_error(tcx, field.ty(tcx, substs), init).map( + ty_find_init_error(cx, field.ty(cx.tcx, substs), init).map( |(mut msg, span)| { if span.is_none() { // Point to this field, should be helpful for figuring // out where the source of the error is. - let span = tcx.def_span(field.did); + let span = cx.tcx.def_span(field.did); write!( &mut msg, " (in this {} field)", @@ -2627,7 +2627,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { // Multi-variant enum. _ => { if init == InitKind::Uninit && is_multi_variant(*adt_def) { - let span = tcx.def_span(adt_def.did()); + let span = cx.tcx.def_span(adt_def.did()); Some(( "enums have to be initialized to a variant".to_string(), Some(span), @@ -2642,7 +2642,16 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { } Tuple(..) => { // Proceed recursively, check all fields. - ty.tuple_fields().iter().find_map(|field| ty_find_init_error(tcx, field, init)) + ty.tuple_fields().iter().find_map(|field| ty_find_init_error(cx, field, init)) + } + Array(ty, len) => { + if matches!(len.try_eval_usize(cx.tcx, cx.param_env), Some(v) if v > 0) { + // Array length known at array non-empty -- recurse. + ty_find_init_error(cx, *ty, init) + } else { + // Empty array or size unknown. + None + } } // Conservative fallback. _ => None, @@ -2655,7 +2664,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { // We are extremely conservative with what we warn about. let conjured_ty = cx.typeck_results().expr_ty(expr); if let Some((msg, span)) = - with_no_trimmed_paths!(ty_find_init_error(cx.tcx, conjured_ty, init)) + with_no_trimmed_paths!(ty_find_init_error(cx, conjured_ty, init)) { cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| { let mut err = lint.build(&format!( diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 2204b44e3a1..43bda7c0734 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -416,10 +416,10 @@ impl<'a> CrateLocator<'a> { (&f[rlib_prefix.len()..(f.len() - rlib_suffix.len())], CrateFlavor::Rlib) } else if f.starts_with(rmeta_prefix) && f.ends_with(rmeta_suffix) { (&f[rmeta_prefix.len()..(f.len() - rmeta_suffix.len())], CrateFlavor::Rmeta) - } else if f.starts_with(dylib_prefix) && f.ends_with(dylib_suffix) { + } else if f.starts_with(dylib_prefix) && f.ends_with(dylib_suffix.as_ref()) { (&f[dylib_prefix.len()..(f.len() - dylib_suffix.len())], CrateFlavor::Dylib) } else { - if f.starts_with(staticlib_prefix) && f.ends_with(staticlib_suffix) { + if f.starts_with(staticlib_prefix) && f.ends_with(staticlib_suffix.as_ref()) { self.crate_rejections.via_kind.push(CrateMismatch { path: spf.path.clone(), got: "static".to_string(), @@ -698,8 +698,8 @@ impl<'a> CrateLocator<'a> { }; if file.starts_with("lib") && (file.ends_with(".rlib") || file.ends_with(".rmeta")) - || file.starts_with(&self.target.dll_prefix) - && file.ends_with(&self.target.dll_suffix) + || file.starts_with(self.target.dll_prefix.as_ref()) + && file.ends_with(self.target.dll_suffix.as_ref()) { // Make sure there's at most one rlib and at most one dylib. // Note to take care and match against the non-canonicalized name: @@ -733,8 +733,8 @@ impl<'a> CrateLocator<'a> { crate_name: self.crate_name, root, triple: self.triple, - dll_prefix: self.target.dll_prefix.clone(), - dll_suffix: self.target.dll_suffix.clone(), + dll_prefix: self.target.dll_prefix.to_string(), + dll_suffix: self.target.dll_suffix.to_string(), crate_rejections: self.crate_rejections, }) } diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 6993ffbeddf..046322a42d8 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -14,7 +14,6 @@ use rustc_data_structures::sync::{Lock, LockGuard, Lrc, OnceCell}; use rustc_data_structures::unhash::UnhashMap; use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind}; use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, ProcMacroDerive}; -use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash}; @@ -909,40 +908,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { ) } - fn get_trait_def(self, item_id: DefIndex, sess: &Session) -> ty::TraitDef { - match self.kind(item_id) { - EntryKind::Trait(data) => { - let data = data.decode((self, sess)); - ty::TraitDef::new( - self.local_def_id(item_id), - data.unsafety, - data.paren_sugar, - data.has_auto_impl, - data.is_marker, - data.skip_array_during_method_dispatch, - data.specialization_kind, - self.def_path_hash(item_id), - data.must_implement_one_of, - ) - } - EntryKind::TraitAlias => ty::TraitDef::new( - self.local_def_id(item_id), - hir::Unsafety::Normal, - false, - false, - false, - false, - ty::trait_def::TraitSpecializationKind::None, - self.def_path_hash(item_id), - None, - ), - _ => bug!("def-index does not refer to trait or trait alias"), - } - } - fn get_variant(self, kind: &EntryKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef { let data = match kind { - EntryKind::Variant(data) | EntryKind::Struct(data, _) | EntryKind::Union(data, _) => { + EntryKind::Variant(data) | EntryKind::Struct(data) | EntryKind::Union(data) => { data.decode(self) } _ => bug!(), @@ -988,12 +956,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { let kind = self.kind(item_id); let did = self.local_def_id(item_id); - let (adt_kind, repr) = match kind { - EntryKind::Enum(repr) => (ty::AdtKind::Enum, repr), - EntryKind::Struct(_, repr) => (ty::AdtKind::Struct, repr), - EntryKind::Union(_, repr) => (ty::AdtKind::Union, repr), + let adt_kind = match kind { + EntryKind::Enum => ty::AdtKind::Enum, + EntryKind::Struct(_) => ty::AdtKind::Struct, + EntryKind::Union(_) => ty::AdtKind::Union, _ => bug!("get_adt_def called on a non-ADT {:?}", did), }; + let repr = self.root.tables.repr_options.get(self, item_id).unwrap().decode(self); let variants = if let ty::AdtKind::Enum = adt_kind { self.root @@ -1171,7 +1140,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { callback(exp); } } - EntryKind::Enum(..) | EntryKind::Trait(..) => {} + EntryKind::Enum | EntryKind::Trait => {} _ => bug!("`for_each_module_child` is called on a non-module: {:?}", self.def_kind(id)), } } @@ -1186,7 +1155,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId { match self.kind(id) { - EntryKind::Mod(_) | EntryKind::Enum(_) | EntryKind::Trait(_) => { + EntryKind::Mod(_) | EntryKind::Enum | EntryKind::Trait => { self.get_expn_that_defined(id, sess) } _ => panic!("Expected module, found {:?}", self.local_def_id(id)), @@ -1239,7 +1208,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn get_ctor_def_id_and_kind(self, node_id: DefIndex) -> Option<(DefId, CtorKind)> { match self.kind(node_id) { - EntryKind::Struct(data, _) | EntryKind::Variant(data) => { + EntryKind::Struct(data) | EntryKind::Variant(data) => { let vdata = data.decode(self); vdata.ctor.map(|index| (self.local_def_id(index), vdata.ctor_kind)) } @@ -1395,7 +1364,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { _ => return None, } def_key.parent.and_then(|parent_index| match self.kind(parent_index) { - EntryKind::Trait(_) | EntryKind::TraitAlias => Some(self.local_def_id(parent_index)), + EntryKind::Trait | EntryKind::TraitAlias => Some(self.local_def_id(parent_index)), _ => None, }) } @@ -1449,22 +1418,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } } - // This replicates some of the logic of the crate-local `is_const_fn_raw` query, because we - // don't serialize constness for tuple variant and tuple struct constructors. - fn is_const_fn_raw(self, id: DefIndex) -> bool { - let constness = match self.kind(id) { - EntryKind::AssocFn(data) => data.decode(self).fn_data.constness, - EntryKind::Fn(data) => data.decode(self).constness, - EntryKind::ForeignFn(data) => data.decode(self).constness, - EntryKind::Variant(..) | EntryKind::Struct(..) => hir::Constness::Const, - _ => hir::Constness::NotConst, - }; - constness == hir::Constness::Const - } - fn is_foreign_item(self, id: DefIndex) -> bool { match self.kind(id) { - EntryKind::ForeignStatic | EntryKind::ForeignFn(_) => true, + EntryKind::ForeignStatic | EntryKind::ForeignFn => true, _ => false, } } diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 5a2c59b4601..cd3a1d72d41 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -153,8 +153,8 @@ provide! { <'tcx> tcx, def_id, other, cdata, asyncness => { table } fn_arg_names => { table } generator_kind => { table } + trait_def => { table } - trait_def => { cdata.get_trait_def(def_id.index, tcx.sess) } adt_def => { cdata.get_adt_def(def_id.index, tcx) } adt_destructor => { let _ = cdata; @@ -163,7 +163,6 @@ provide! { <'tcx> tcx, def_id, other, cdata, associated_item_def_ids => { cdata.get_associated_item_def_ids(tcx, def_id.index) } associated_item => { cdata.get_associated_item(def_id.index) } inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) } - is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) } is_foreign_item => { cdata.is_foreign_item(def_id.index) } item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) } trait_of_item => { cdata.get_trait_of_item(def_id.index) } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index cb3932eba35..6c758b8e5b6 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1048,6 +1048,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { }; record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data))); + record!(self.tables.impl_constness[def_id] <- hir::Constness::Const); record!(self.tables.children[def_id] <- variant.fields.iter().map(|f| { assert!(f.did.is_local()); f.did.index @@ -1077,6 +1078,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { }; record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data))); + record!(self.tables.impl_constness[def_id] <- hir::Constness::Const); self.encode_item_type(def_id); if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); @@ -1154,7 +1156,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { is_non_exhaustive: variant.is_field_list_non_exhaustive(), }; - record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr())); + record!(self.tables.repr_options[def_id] <- adt_def.repr()); + record!(self.tables.impl_constness[def_id] <- hir::Constness::Const); + record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data))); self.encode_item_type(def_id); if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); @@ -1194,22 +1198,18 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { record!(self.tables.rendered_const[def_id] <- rendered); } ty::AssocKind::Fn => { - let fn_data = if let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind { - match *m { - hir::TraitFn::Required(ref names) => { - record!(self.tables.fn_arg_names[def_id] <- *names) - } - hir::TraitFn::Provided(body) => { - record!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)) - } - }; - record!(self.tables.asyncness[def_id] <- m_sig.header.asyncness); - FnData { constness: hir::Constness::NotConst } - } else { - bug!() + let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind else { bug!() }; + match *m { + hir::TraitFn::Required(ref names) => { + record!(self.tables.fn_arg_names[def_id] <- *names) + } + hir::TraitFn::Provided(body) => { + record!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)) + } }; + record!(self.tables.asyncness[def_id] <- m_sig.header.asyncness); + record!(self.tables.impl_constness[def_id] <- hir::Constness::NotConst); record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData { - fn_data, container, has_self: trait_item.fn_has_self_parameter, }))); @@ -1264,22 +1264,17 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } } ty::AssocKind::Fn => { - let fn_data = if let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind { - record!(self.tables.asyncness[def_id] <- sig.header.asyncness); - record!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)); - FnData { - // Can be inside `impl const Trait`, so using sig.header.constness is not reliable - constness: if self.tcx.is_const_fn_raw(def_id) { - hir::Constness::Const - } else { - hir::Constness::NotConst - }, - } + let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind else { bug!() }; + record!(self.tables.asyncness[def_id] <- sig.header.asyncness); + record!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)); + // Can be inside `impl const Trait`, so using sig.header.constness is not reliable + let constness = if self.tcx.is_const_fn_raw(def_id) { + hir::Constness::Const } else { - bug!() + hir::Constness::NotConst }; + record!(self.tables.impl_constness[def_id] <- constness); record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData { - fn_data, container, has_self: impl_item.fn_has_self_parameter, }))); @@ -1401,9 +1396,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { hir::ItemKind::Fn(ref sig, .., body) => { record!(self.tables.asyncness[def_id] <- sig.header.asyncness); record!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body)); - let data = FnData { constness: sig.header.constness }; - - EntryKind::Fn(self.lazy(data)) + record!(self.tables.impl_constness[def_id] <- sig.header.constness); + EntryKind::Fn } hir::ItemKind::Macro(ref macro_def, _) => { EntryKind::MacroDef(self.lazy(&*macro_def.body), macro_def.macro_rules) @@ -1418,10 +1412,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.encode_explicit_item_bounds(def_id); EntryKind::OpaqueTy } - hir::ItemKind::Enum(..) => EntryKind::Enum(self.tcx.adt_def(def_id).repr()), + hir::ItemKind::Enum(..) => { + let adt_def = self.tcx.adt_def(def_id); + record!(self.tables.repr_options[def_id] <- adt_def.repr()); + EntryKind::Enum + } hir::ItemKind::Struct(ref struct_def, _) => { let adt_def = self.tcx.adt_def(def_id); - let variant = adt_def.non_enum_variant(); + record!(self.tables.repr_options[def_id] <- adt_def.repr()); + record!(self.tables.impl_constness[def_id] <- hir::Constness::Const); // Encode def_ids for each field and method // for methods, write all the stuff get_trait_method @@ -1430,29 +1429,25 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { .ctor_hir_id() .map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index); - EntryKind::Struct( - self.lazy(VariantData { - ctor_kind: variant.ctor_kind, - discr: variant.discr, - ctor, - is_non_exhaustive: variant.is_field_list_non_exhaustive(), - }), - adt_def.repr(), - ) + let variant = adt_def.non_enum_variant(); + EntryKind::Struct(self.lazy(VariantData { + ctor_kind: variant.ctor_kind, + discr: variant.discr, + ctor, + is_non_exhaustive: variant.is_field_list_non_exhaustive(), + })) } hir::ItemKind::Union(..) => { let adt_def = self.tcx.adt_def(def_id); - let variant = adt_def.non_enum_variant(); + record!(self.tables.repr_options[def_id] <- adt_def.repr()); - EntryKind::Union( - self.lazy(VariantData { - ctor_kind: variant.ctor_kind, - discr: variant.discr, - ctor: None, - is_non_exhaustive: variant.is_field_list_non_exhaustive(), - }), - adt_def.repr(), - ) + let variant = adt_def.non_enum_variant(); + EntryKind::Union(self.lazy(VariantData { + ctor_kind: variant.ctor_kind, + discr: variant.discr, + ctor: None, + is_non_exhaustive: variant.is_field_list_non_exhaustive(), + })) } hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => { record!(self.tables.impl_defaultness[def_id] <- defaultness); @@ -1483,19 +1478,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } hir::ItemKind::Trait(..) => { let trait_def = self.tcx.trait_def(def_id); - let data = TraitData { - unsafety: trait_def.unsafety, - paren_sugar: trait_def.paren_sugar, - has_auto_impl: self.tcx.trait_is_auto(def_id), - is_marker: trait_def.is_marker, - skip_array_during_method_dispatch: trait_def.skip_array_during_method_dispatch, - specialization_kind: trait_def.specialization_kind, - must_implement_one_of: trait_def.must_implement_one_of.clone(), - }; + record!(self.tables.trait_def[def_id] <- trait_def); + + EntryKind::Trait + } + hir::ItemKind::TraitAlias(..) => { + let trait_def = self.tcx.trait_def(def_id); + record!(self.tables.trait_def[def_id] <- trait_def); - EntryKind::Trait(self.lazy(data)) + EntryKind::TraitAlias } - hir::ItemKind::TraitAlias(..) => EntryKind::TraitAlias, hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) => { bug!("cannot encode info for item {:?}", item) } @@ -1896,14 +1888,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { hir::ForeignItemKind::Fn(_, ref names, _) => { record!(self.tables.asyncness[def_id] <- hir::IsAsync::NotAsync); record!(self.tables.fn_arg_names[def_id] <- *names); - let data = FnData { - constness: if self.tcx.is_const_fn_raw(def_id) { - hir::Constness::Const - } else { - hir::Constness::NotConst - }, + let constness = if self.tcx.is_const_fn_raw(def_id) { + hir::Constness::Const + } else { + hir::Constness::NotConst }; - record!(self.tables.kind[def_id] <- EntryKind::ForeignFn(self.lazy(data))); + record!(self.tables.impl_constness[def_id] <- constness); + record!(self.tables.kind[def_id] <- EntryKind::ForeignFn); } hir::ForeignItemKind::Static(..) => { record!(self.tables.kind[def_id] <- EntryKind::ForeignStatic); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 06581033129..15e8693d712 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -320,11 +320,13 @@ define_tables! { asyncness: Table<DefIndex, Lazy!(hir::IsAsync)>, fn_arg_names: Table<DefIndex, Lazy!([Ident])>, generator_kind: Table<DefIndex, Lazy!(hir::GeneratorKind)>, + trait_def: Table<DefIndex, Lazy!(ty::TraitDef)>, trait_item_def_id: Table<DefIndex, Lazy<DefId>>, inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>, expn_that_defined: Table<DefIndex, Lazy<ExpnId>>, unused_generic_params: Table<DefIndex, Lazy<FiniteBitSet<u32>>>, + repr_options: Table<DefIndex, Lazy<ReprOptions>>, // `def_keys` and `def_path_hashes` represent a lazy version of a // `DefPathTable`. This allows us to avoid deserializing an entire // `DefPathTable` up front, since we may only ever use a few @@ -347,19 +349,19 @@ enum EntryKind { TypeParam, ConstParam, OpaqueTy, - Enum(ReprOptions), + Enum, Field, Variant(Lazy<VariantData>), - Struct(Lazy<VariantData>, ReprOptions), - Union(Lazy<VariantData>, ReprOptions), - Fn(Lazy<FnData>), - ForeignFn(Lazy<FnData>), + Struct(Lazy<VariantData>), + Union(Lazy<VariantData>), + Fn, + ForeignFn, Mod(Lazy<[ModChild]>), MacroDef(Lazy<ast::MacArgs>, /*macro_rules*/ bool), ProcMacro(MacroKind), Closure, Generator, - Trait(Lazy<TraitData>), + Trait, Impl, AssocFn(Lazy<AssocFnData>), AssocType(AssocContainer), @@ -367,11 +369,6 @@ enum EntryKind { TraitAlias, } -#[derive(MetadataEncodable, MetadataDecodable)] -struct FnData { - constness: hir::Constness, -} - #[derive(TyEncodable, TyDecodable)] struct VariantData { ctor_kind: CtorKind, @@ -381,17 +378,6 @@ struct VariantData { is_non_exhaustive: bool, } -#[derive(TyEncodable, TyDecodable)] -struct TraitData { - unsafety: hir::Unsafety, - paren_sugar: bool, - has_auto_impl: bool, - is_marker: bool, - skip_array_during_method_dispatch: bool, - specialization_kind: ty::trait_def::TraitSpecializationKind, - must_implement_one_of: Option<Box<[Ident]>>, -} - /// Describes whether the container of an associated item /// is a trait or an impl and whether, in a trait, it has /// a default, or an in impl, whether it's marked "default". @@ -429,7 +415,6 @@ impl AssocContainer { #[derive(MetadataEncodable, MetadataDecodable)] struct AssocFnData { - fn_data: FnData, container: AssocContainer, has_self: bool, } diff --git a/compiler/rustc_middle/src/infer/unify_key.rs b/compiler/rustc_middle/src/infer/unify_key.rs index dd303aaada9..f2627885d03 100644 --- a/compiler/rustc_middle/src/infer/unify_key.rs +++ b/compiler/rustc_middle/src/infer/unify_key.rs @@ -1,13 +1,8 @@ -use crate::ty::{self, InferConst, Ty, TyCtxt}; -use rustc_data_structures::snapshot_vec; -use rustc_data_structures::undo_log::UndoLogs; -use rustc_data_structures::unify::{ - self, EqUnifyValue, InPlace, NoError, UnificationTable, UnifyKey, UnifyValue, -}; +use crate::ty::{self, Ty, TyCtxt}; +use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue}; use rustc_span::def_id::DefId; use rustc_span::symbol::Symbol; use rustc_span::Span; - use std::cmp; use std::marker::PhantomData; @@ -165,23 +160,3 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> { }) } } - -impl<'tcx> EqUnifyValue for ty::Const<'tcx> {} - -pub fn replace_if_possible<'tcx, V, L>( - table: &mut UnificationTable<InPlace<ty::ConstVid<'tcx>, V, L>>, - c: ty::Const<'tcx>, -) -> ty::Const<'tcx> -where - V: snapshot_vec::VecLike<unify::Delegate<ty::ConstVid<'tcx>>>, - L: UndoLogs<snapshot_vec::UndoLog<unify::Delegate<ty::ConstVid<'tcx>>>>, -{ - if let ty::ConstKind::Infer(InferConst::Var(vid)) = c.val() { - match table.probe_value(vid).val.known() { - Some(c) => c, - None => c, - } - } else { - c - } -} diff --git a/compiler/rustc_middle/src/mir/interpret/pointer.rs b/compiler/rustc_middle/src/mir/interpret/pointer.rs index 7d101046a96..813c0912f53 100644 --- a/compiler/rustc_middle/src/mir/interpret/pointer.rs +++ b/compiler/rustc_middle/src/mir/interpret/pointer.rs @@ -18,6 +18,11 @@ pub trait PointerArithmetic: HasDataLayout { self.data_layout().pointer_size } + #[inline(always)] + fn max_size_of_val(&self) -> Size { + Size::from_bytes(self.machine_isize_max()) + } + #[inline] fn machine_usize_max(&self) -> u64 { self.pointer_size().unsigned_int_max().try_into().unwrap() diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index bf45269e06f..89761bf4e27 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -124,7 +124,10 @@ rustc_queries! { separate_provide_extern } - /// Records the type of every item. + /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points + /// to an alias, it will "skip" this alias to return the aliased type. + /// + /// [`DefId`]: rustc_hir::def_id::DefId query type_of(key: DefId) -> Ty<'tcx> { desc { |tcx| "{action} `{path}`", @@ -559,7 +562,7 @@ rustc_queries! { /// /// **Do not call this function manually.** It is only meant to cache the base data for the /// `is_const_fn` function. - query is_const_fn_raw(key: DefId) -> bool { + query impl_constness(key: DefId) -> hir::Constness { desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) } separate_provide_extern } @@ -1329,11 +1332,6 @@ rustc_queries! { separate_provide_extern } - query impl_constness(def_id: DefId) -> hir::Constness { - desc { |tcx| "looking up whether `{}` is a const impl", tcx.def_path_str(def_id) } - separate_provide_extern - } - query check_item_well_formed(key: LocalDefId) -> () { desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) } } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 1f18260d915..7c3d08b26bf 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -276,24 +276,23 @@ pub enum ObligationCauseCode<'tcx> { /// Error derived when matching traits/impls; see ObligationCause for more details CompareImplMethodObligation { - impl_item_def_id: DefId, + impl_item_def_id: LocalDefId, trait_item_def_id: DefId, }, /// Error derived when matching traits/impls; see ObligationCause for more details CompareImplTypeObligation { - impl_item_def_id: DefId, + impl_item_def_id: LocalDefId, trait_item_def_id: DefId, }, /// Checking that the bounds of a trait's associated type hold for a given impl CheckAssociatedTypeBounds { - impl_item_def_id: DefId, + impl_item_def_id: LocalDefId, trait_item_def_id: DefId, }, - /// Checking that this expression can be assigned where it needs to be - // FIXME(eddyb) #11161 is the original Expr required? + /// Checking that this expression can be assigned to its target. ExprAssignable, /// Computing common supertype in the arms of a match expression diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs index 1446f7dac36..3bddf7fb6ff 100644 --- a/compiler/rustc_middle/src/ty/closure.rs +++ b/compiler/rustc_middle/src/ty/closure.rs @@ -119,9 +119,21 @@ impl<'tcx> ClosureKind { /// See `Ty::to_opt_closure_kind` for more details. pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self { - ty::ClosureKind::Fn => tcx.types.i8, - ty::ClosureKind::FnMut => tcx.types.i16, - ty::ClosureKind::FnOnce => tcx.types.i32, + ClosureKind::Fn => tcx.types.i8, + ClosureKind::FnMut => tcx.types.i16, + ClosureKind::FnOnce => tcx.types.i32, + } + } + + pub fn from_def_id(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ClosureKind> { + if Some(def_id) == tcx.lang_items().fn_once_trait() { + Some(ClosureKind::FnOnce) + } else if Some(def_id) == tcx.lang_items().fn_mut_trait() { + Some(ClosureKind::FnMut) + } else if Some(def_id) == tcx.lang_items().fn_trait() { + Some(ClosureKind::Fn) + } else { + None } } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 653b4908ab5..37425c91157 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -289,6 +289,11 @@ pub struct ClosureSizeProfileData<'tcx> { pub trait DefIdTree: Copy { fn parent(self, id: DefId) -> Option<DefId>; + #[inline] + fn local_parent(self, id: LocalDefId) -> Option<LocalDefId> { + Some(self.parent(id.to_def_id())?.expect_local()) + } + fn is_descendant_of(self, mut descendant: DefId, ancestor: DefId) -> bool { if descendant.krate != ancestor.krate { return false; @@ -2256,6 +2261,12 @@ impl<'tcx> TyCtxt<'tcx> { pub fn is_object_safe(self, key: DefId) -> bool { self.object_safety_violations(key).is_empty() } + + #[inline] + pub fn is_const_fn_raw(self, def_id: DefId) -> bool { + matches!(self.def_kind(def_id), DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..)) + && self.impl_constness(def_id) == hir::Constness::Const + } } /// Yields the parent function's `LocalDefId` if `def_id` is an `impl Trait` definition. diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index 943f610cc0d..ca6fabf7f40 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -5,7 +5,6 @@ use crate::ty::{Ident, Ty, TyCtxt}; use hir::def_id::LOCAL_CRATE; use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc_hir::definitions::DefPathHash; use std::iter; use rustc_data_structures::fx::FxIndexMap; @@ -13,10 +12,8 @@ use rustc_errors::ErrorGuaranteed; use rustc_macros::HashStable; /// A trait's definition with type information. -#[derive(HashStable)] +#[derive(HashStable, Encodable, Decodable)] pub struct TraitDef { - // We already have the def_path_hash below, no need to hash it twice - #[stable_hasher(ignore)] pub def_id: DefId, pub unsafety: hir::Unsafety, @@ -43,10 +40,6 @@ pub struct TraitDef { /// on this trait. pub specialization_kind: TraitSpecializationKind, - /// The ICH of this trait's DefPath, cached here so it doesn't have to be - /// recomputed all the time. - pub def_path_hash: DefPathHash, - /// List of functions from `#[rustc_must_implement_one_of]` attribute one of which /// must be implemented. pub must_implement_one_of: Option<Box<[Ident]>>, @@ -54,7 +47,7 @@ pub struct TraitDef { /// Whether this trait is treated specially by the standard library /// specialization lint. -#[derive(HashStable, PartialEq, Clone, Copy, TyEncodable, TyDecodable)] +#[derive(HashStable, PartialEq, Clone, Copy, Encodable, Decodable)] pub enum TraitSpecializationKind { /// The default. Specializing on this trait is not allowed. None, @@ -92,7 +85,6 @@ impl<'tcx> TraitDef { is_marker: bool, skip_array_during_method_dispatch: bool, specialization_kind: TraitSpecializationKind, - def_path_hash: DefPathHash, must_implement_one_of: Option<Box<[Ident]>>, ) -> TraitDef { TraitDef { @@ -103,7 +95,6 @@ impl<'tcx> TraitDef { is_marker, skip_array_during_method_dispatch, specialization_kind, - def_path_hash, must_implement_one_of, } } diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 1b429731d70..2f0673b9a76 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -1,7 +1,6 @@ //! Inlining pass for MIR functions use rustc_attr::InlineAttr; -use rustc_hir as hir; use rustc_index::bit_set::BitSet; use rustc_index::vec::Idx; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; @@ -88,7 +87,6 @@ fn inline<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool { tcx, param_env, codegen_fn_attrs: tcx.codegen_fn_attrs(def_id), - hir_id, history: Vec::new(), changed: false, }; @@ -102,8 +100,6 @@ struct Inliner<'tcx> { param_env: ParamEnv<'tcx>, /// Caller codegen attributes. codegen_fn_attrs: &'tcx CodegenFnAttrs, - /// Caller HirID. - hir_id: hir::HirId, /// Stack of inlined Instances. history: Vec<ty::Instance<'tcx>>, /// Indicates that the caller body has been modified. @@ -179,7 +175,9 @@ impl<'tcx> Inliner<'tcx> { caller_body: &Body<'tcx>, callee: &Instance<'tcx>, ) -> Result<(), &'static str> { - if callee.def_id() == caller_body.source.def_id() { + let caller_def_id = caller_body.source.def_id(); + let callee_def_id = callee.def_id(); + if callee_def_id == caller_def_id { return Err("self-recursion"); } @@ -188,7 +186,7 @@ impl<'tcx> Inliner<'tcx> { // If there is no MIR available (either because it was not in metadata or // because it has no MIR because it's an extern function), then the inliner // won't cause cycles on this. - if !self.tcx.is_mir_available(callee.def_id()) { + if !self.tcx.is_mir_available(callee_def_id) { return Err("item MIR unavailable"); } } @@ -208,29 +206,26 @@ impl<'tcx> Inliner<'tcx> { | InstanceDef::CloneShim(..) => return Ok(()), } - if self.tcx.is_constructor(callee.def_id()) { + if self.tcx.is_constructor(callee_def_id) { trace!("constructors always have MIR"); // Constructor functions cannot cause a query cycle. return Ok(()); } - if let Some(callee_def_id) = callee.def_id().as_local() { - let callee_hir_id = self.tcx.hir().local_def_id_to_hir_id(callee_def_id); + if callee_def_id.is_local() { // Avoid a cycle here by only using `instance_mir` only if we have - // a lower `HirId` than the callee. This ensures that the callee will - // not inline us. This trick only works without incremental compilation. - // So don't do it if that is enabled. - if !self.tcx.dep_graph.is_fully_enabled() && self.hir_id.index() < callee_hir_id.index() + // a lower `DefPathHash` than the callee. This ensures that the callee will + // not inline us. This trick even works with incremental compilation, + // since `DefPathHash` is stable. + if self.tcx.def_path_hash(caller_def_id).local_hash() + < self.tcx.def_path_hash(callee_def_id).local_hash() { return Ok(()); } // If we know for sure that the function we're calling will itself try to // call us, then we avoid inlining that function. - if self - .tcx - .mir_callgraph_reachable((*callee, caller_body.source.def_id().expect_local())) - { + if self.tcx.mir_callgraph_reachable((*callee, caller_def_id.expect_local())) { return Err("caller might be reachable from callee (query cycle avoidance)"); } diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 8f64d6d732f..3ac226114cd 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -17,7 +17,7 @@ use rustc_ast::{ }; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed}; +use rustc_errors::{pluralize, struct_span_err, Diagnostic, EmissionGuarantee, ErrorGuaranteed}; use rustc_errors::{Applicability, DiagnosticBuilder, Handler, PResult}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, Ident}; @@ -156,6 +156,89 @@ impl AttemptLocalParseRecovery { } } +/// Information for emitting suggestions and recovering from +/// C-style `i++`, `--i`, etc. +#[derive(Debug, Copy, Clone)] +struct IncDecRecovery { + /// Is this increment/decrement its own statement? + standalone: IsStandalone, + /// Is this an increment or decrement? + op: IncOrDec, + /// Is this pre- or postfix? + fixity: UnaryFixity, +} + +/// Is an increment or decrement expression its own statement? +#[derive(Debug, Copy, Clone)] +enum IsStandalone { + /// It's standalone, i.e., its own statement. + Standalone, + /// It's a subexpression, i.e., *not* standalone. + Subexpr, + /// It's maybe standalone; we're not sure. + Maybe, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +enum IncOrDec { + Inc, + // FIXME: `i--` recovery isn't implemented yet + #[allow(dead_code)] + Dec, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +enum UnaryFixity { + Pre, + Post, +} + +impl IncOrDec { + fn chr(&self) -> char { + match self { + Self::Inc => '+', + Self::Dec => '-', + } + } + + fn name(&self) -> &'static str { + match self { + Self::Inc => "increment", + Self::Dec => "decrement", + } + } +} + +impl std::fmt::Display for UnaryFixity { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Pre => write!(f, "prefix"), + Self::Post => write!(f, "postfix"), + } + } +} + +struct MultiSugg { + msg: String, + patches: Vec<(Span, String)>, + applicability: Applicability, +} + +impl MultiSugg { + fn emit<G: EmissionGuarantee>(self, err: &mut DiagnosticBuilder<'_, G>) { + err.multipart_suggestion(&self.msg, self.patches, self.applicability); + } + + /// Overrides individual messages and applicabilities. + fn emit_many<G: EmissionGuarantee>( + err: &mut DiagnosticBuilder<'_, G>, + msg: &str, + applicability: Applicability, + suggestions: impl Iterator<Item = Self>, + ) { + err.multipart_suggestions(msg, suggestions.map(|s| s.patches), applicability); + } +} // SnapshotParser is used to create a snapshot of the parser // without causing duplicate errors being emitted when the `Parser` // is dropped. @@ -210,6 +293,10 @@ impl<'a> Parser<'a> { self.unclosed_delims.extend(snapshot.unclosed_delims.clone()); } + pub fn unclosed_delims(&self) -> &[UnmatchedBrace] { + &self.unclosed_delims + } + /// Create a snapshot of the `Parser`. pub(super) fn create_snapshot_for_diagnostic(&self) -> SnapshotParser<'a> { let mut snapshot = self.clone(); @@ -1167,6 +1254,135 @@ impl<'a> Parser<'a> { Ok(()) } + pub(super) fn recover_from_prefix_increment( + &mut self, + operand_expr: P<Expr>, + op_span: Span, + prev_is_semi: bool, + ) -> PResult<'a, P<Expr>> { + let standalone = + if prev_is_semi { IsStandalone::Standalone } else { IsStandalone::Subexpr }; + let kind = IncDecRecovery { standalone, op: IncOrDec::Inc, fixity: UnaryFixity::Pre }; + + self.recover_from_inc_dec(operand_expr, kind, op_span) + } + + pub(super) fn recover_from_postfix_increment( + &mut self, + operand_expr: P<Expr>, + op_span: Span, + ) -> PResult<'a, P<Expr>> { + let kind = IncDecRecovery { + standalone: IsStandalone::Maybe, + op: IncOrDec::Inc, + fixity: UnaryFixity::Post, + }; + + self.recover_from_inc_dec(operand_expr, kind, op_span) + } + + fn recover_from_inc_dec( + &mut self, + base: P<Expr>, + kind: IncDecRecovery, + op_span: Span, + ) -> PResult<'a, P<Expr>> { + let mut err = self.struct_span_err( + op_span, + &format!("Rust has no {} {} operator", kind.fixity, kind.op.name()), + ); + err.span_label(op_span, &format!("not a valid {} operator", kind.fixity)); + + let help_base_case = |mut err: DiagnosticBuilder<'_, _>, base| { + err.help(&format!("use `{}= 1` instead", kind.op.chr())); + err.emit(); + Ok(base) + }; + + // (pre, post) + let spans = match kind.fixity { + UnaryFixity::Pre => (op_span, base.span.shrink_to_hi()), + UnaryFixity::Post => (base.span.shrink_to_lo(), op_span), + }; + + match kind.standalone { + IsStandalone::Standalone => self.inc_dec_standalone_suggest(kind, spans).emit(&mut err), + IsStandalone::Subexpr => { + let Ok(base_src) = self.span_to_snippet(base.span) + else { return help_base_case(err, base) }; + match kind.fixity { + UnaryFixity::Pre => { + self.prefix_inc_dec_suggest(base_src, kind, spans).emit(&mut err) + } + UnaryFixity::Post => { + self.postfix_inc_dec_suggest(base_src, kind, spans).emit(&mut err) + } + } + } + IsStandalone::Maybe => { + let Ok(base_src) = self.span_to_snippet(base.span) + else { return help_base_case(err, base) }; + let sugg1 = match kind.fixity { + UnaryFixity::Pre => self.prefix_inc_dec_suggest(base_src, kind, spans), + UnaryFixity::Post => self.postfix_inc_dec_suggest(base_src, kind, spans), + }; + let sugg2 = self.inc_dec_standalone_suggest(kind, spans); + MultiSugg::emit_many( + &mut err, + "use `+= 1` instead", + Applicability::Unspecified, + [sugg1, sugg2].into_iter(), + ) + } + } + Err(err) + } + + fn prefix_inc_dec_suggest( + &mut self, + base_src: String, + kind: IncDecRecovery, + (pre_span, post_span): (Span, Span), + ) -> MultiSugg { + MultiSugg { + msg: format!("use `{}= 1` instead", kind.op.chr()), + patches: vec![ + (pre_span, "{ ".to_string()), + (post_span, format!(" {}= 1; {} }}", kind.op.chr(), base_src)), + ], + applicability: Applicability::MachineApplicable, + } + } + + fn postfix_inc_dec_suggest( + &mut self, + base_src: String, + kind: IncDecRecovery, + (pre_span, post_span): (Span, Span), + ) -> MultiSugg { + let tmp_var = if base_src.trim() == "tmp" { "tmp_" } else { "tmp" }; + MultiSugg { + msg: format!("use `{}= 1` instead", kind.op.chr()), + patches: vec![ + (pre_span, format!("{{ let {} = ", tmp_var)), + (post_span, format!("; {} {}= 1; {} }}", base_src, kind.op.chr(), tmp_var)), + ], + applicability: Applicability::HasPlaceholders, + } + } + + fn inc_dec_standalone_suggest( + &mut self, + kind: IncDecRecovery, + (pre_span, post_span): (Span, Span), + ) -> MultiSugg { + MultiSugg { + msg: format!("use `{}= 1` instead", kind.op.chr()), + patches: vec![(pre_span, String::new()), (post_span, format!(" {}= 1", kind.op.chr()))], + applicability: Applicability::MachineApplicable, + } + } + /// Tries to recover from associated item paths like `[T]::AssocItem` / `(T, U)::AssocItem`. /// Attempts to convert the base expression/pattern/type into a type, parses the `::AssocItem` /// tail, and combines them into a `<Ty>::AssocItem` expression/pattern/type. diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index a970d180b1a..7c407cbe465 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -267,6 +267,17 @@ impl<'a> Parser<'a> { self.bump(); } + if self.prev_token == token::BinOp(token::Plus) + && self.token == token::BinOp(token::Plus) + && self.prev_token.span.between(self.token.span).is_empty() + { + let op_span = self.prev_token.span.to(self.token.span); + // Eat the second `+` + self.bump(); + lhs = self.recover_from_postfix_increment(lhs, op_span)?; + continue; + } + let op = op.node; // Special cases: if op == AssocOp::As { @@ -580,6 +591,19 @@ impl<'a> Parser<'a> { this.bump(); this.parse_prefix_expr(None) } // `+expr` + // Recover from `++x`: + token::BinOp(token::Plus) + if this.look_ahead(1, |t| *t == token::BinOp(token::Plus)) => + { + let prev_is_semi = this.prev_token == token::Semi; + let pre_span = this.token.span.to(this.look_ahead(1, |t| t.span)); + // Eat both `+`s. + this.bump(); + this.bump(); + + let operand_expr = this.parse_dot_or_call_expr(Default::default())?; + this.recover_from_prefix_increment(operand_expr, pre_span, prev_is_semi) + } token::Ident(..) if this.token.is_keyword(kw::Box) => { make_it!(this, attrs, |this, _| this.parse_box_expr(lo)) } @@ -1919,17 +1943,13 @@ impl<'a> Parser<'a> { match snapshot.parse_array_or_repeat_expr(attrs, token::Brace) { Ok(arr) => { let hi = snapshot.prev_token.span; - self.struct_span_err( - arr.span, - "this code is interpreted as a block expression, not an array", - ) - .multipart_suggestion( - "try using [] instead of {}", - vec![(lo, "[".to_owned()), (hi, "]".to_owned())], - Applicability::MaybeIncorrect, - ) - .note("to define an array, one would use square brackets instead of curly braces") - .emit(); + self.struct_span_err(arr.span, "this is a block expression, not an array") + .multipart_suggestion( + "to make an array, use square brackets instead of curly braces", + vec![(lo, "[".to_owned()), (hi, "]".to_owned())], + Applicability::MaybeIncorrect, + ) + .emit(); self.restore_snapshot(snapshot); Some(self.mk_expr_err(arr.span)) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 8aa659fa6ac..7ad87481356 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1859,7 +1859,7 @@ impl CheckAttrVisitor<'_> { ) -> bool { match target { Target::Fn | Target::Method(_) - if self.tcx.is_const_fn_raw(self.tcx.hir().local_def_id(hir_id)) => + if self.tcx.is_const_fn_raw(self.tcx.hir().local_def_id(hir_id).to_def_id()) => { true } diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 00445690f8f..c414d7c031c 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -29,10 +29,11 @@ impl<'tcx> LibFeatureCollector<'tcx> { } fn extract(&self, attr: &Attribute) -> Option<(Symbol, Option<Symbol>, Span)> { - let stab_attrs = [sym::stable, sym::unstable, sym::rustc_const_unstable]; + let stab_attrs = + [sym::stable, sym::unstable, sym::rustc_const_stable, sym::rustc_const_unstable]; - // Find a stability attribute (i.e., `#[stable (..)]`, `#[unstable (..)]`, - // `#[rustc_const_unstable (..)]`). + // Find a stability attribute: one of #[stable(…)], #[unstable(…)], + // #[rustc_const_stable(…)], or #[rustc_const_unstable(…)]. if let Some(stab_attr) = stab_attrs.iter().find(|stab_attr| attr.has_name(**stab_attr)) { let meta_kind = attr.meta_kind(); if let Some(MetaItemKind::List(ref metas)) = meta_kind { @@ -52,7 +53,9 @@ impl<'tcx> LibFeatureCollector<'tcx> { // This additional check for stability is to make sure we // don't emit additional, irrelevant errors for malformed // attributes. - if *stab_attr != sym::stable || since.is_some() { + let is_unstable = + matches!(*stab_attr, sym::unstable | sym::rustc_const_unstable); + if since.is_some() || is_unstable { return Some((feature, since, attr.span)); } } diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index cd966df119f..af78fd5a6f2 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -1,7 +1,7 @@ //! Checks validity of naked functions. use rustc_ast::{Attribute, InlineAsmOptions}; -use rustc_errors::struct_span_err; +use rustc_errors::{struct_span_err, Applicability}; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{FnKind, Visitor}; @@ -293,12 +293,25 @@ impl<'tcx> CheckInlineAssembly<'tcx> { } if !asm.options.contains(InlineAsmOptions::NORETURN) { + let last_span = asm + .operands + .last() + .map_or_else(|| asm.template_strs.last().unwrap().2, |op| op.1) + .shrink_to_hi(); + struct_span_err!( self.tcx.sess, span, E0787, "asm in naked functions must use `noreturn` option" ) + .span_suggestion( + last_span, + "consider specifying that the asm block is responsible \ + for returning from the function", + String::from(", options(noreturn)"), + Applicability::MachineApplicable, + ) .emit(); } } diff --git a/compiler/rustc_serialize/src/json.rs b/compiler/rustc_serialize/src/json.rs index 0cbea3a07a8..c915dd5bbf6 100644 --- a/compiler/rustc_serialize/src/json.rs +++ b/compiler/rustc_serialize/src/json.rs @@ -170,6 +170,7 @@ use self::JsonEvent::*; use self::ParserError::*; use self::ParserState::*; +use std::borrow::Cow; use std::collections::{BTreeMap, HashMap}; use std::mem::swap; use std::num::FpCategory as Fp; @@ -2196,6 +2197,12 @@ impl ToJson for string::String { } } +impl<'a> ToJson for Cow<'a, str> { + fn to_json(&self) -> Json { + Json::String(self.to_string()) + } +} + macro_rules! tuple_impl { // use variables to indicate the arity of the tuple ($($tyvar:ident),* ) => { @@ -2240,6 +2247,15 @@ impl<A: ToJson> ToJson for Vec<A> { } } +impl<'a, A: ToJson> ToJson for Cow<'a, [A]> +where + [A]: ToOwned, +{ + fn to_json(&self) -> Json { + Json::Array(self.iter().map(|elt| elt.to_json()).collect()) + } +} + impl<T: ToString, A: ToJson> ToJson for BTreeMap<T, A> { fn to_json(&self) -> Json { let mut d = BTreeMap::new(); diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 856436e44db..4182a5d0711 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -956,7 +956,7 @@ fn default_configuration(sess: &Session) -> CrateConfig { ret.reserve(7); // the minimum number of insertions // Target bindings. ret.insert((sym::target_os, Some(Symbol::intern(os)))); - for fam in &sess.target.families { + for fam in sess.target.families.as_ref() { ret.insert((sym::target_family, Some(Symbol::intern(fam)))); if fam == "windows" { ret.insert((sym::windows, None)); diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index 14273b07ebd..3151b025fff 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -1,5 +1,6 @@ #![feature(crate_visibility_modifier)] #![feature(derive_default_enum)] +#![feature(if_let_guard)] #![feature(let_chains)] #![feature(let_else)] #![feature(min_specialization)] diff --git a/compiler/rustc_session/src/utils.rs b/compiler/rustc_session/src/utils.rs index 6a8775bd10b..9a286d94ab8 100644 --- a/compiler/rustc_session/src/utils.rs +++ b/compiler/rustc_session/src/utils.rs @@ -132,6 +132,9 @@ impl<'a> FlattenNonterminals<'a> { pub fn process_token(&mut self, token: Token) -> TokenStream { match token.kind { + token::Interpolated(nt) if let token::NtIdent(ident, is_raw) = *nt => { + TokenTree::Token(Token::new(token::Ident(ident.name, is_raw), ident.span)).into() + } token::Interpolated(nt) => { let tts = (self.nt_to_tokenstream)(&nt, self.parse_sess, self.synthesize_tokens); TokenTree::Delimited( diff --git a/compiler/rustc_target/src/spec/aarch64_apple_darwin.rs b/compiler/rustc_target/src/spec/aarch64_apple_darwin.rs index f01ff02da07..86f76fdb6a7 100644 --- a/compiler/rustc_target/src/spec/aarch64_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/aarch64_apple_darwin.rs @@ -2,14 +2,14 @@ use crate::spec::{FramePointer, LinkerFlavor, SanitizerSet, Target, TargetOption pub fn target() -> Target { let mut base = super::apple_base::opts("macos"); - base.cpu = "apple-a14".to_string(); + base.cpu = "apple-a14".into(); base.max_atomic_width = Some(128); // FIXME: The leak sanitizer currently fails the tests, see #88132. base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD; - base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-arch".to_string(), "arm64".to_string()]); - base.link_env_remove.extend(super::apple_base::macos_link_env_remove()); + base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-arch".into(), "arm64".into()]); + base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove()); // Clang automatically chooses a more specific target based on // MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work @@ -17,12 +17,12 @@ pub fn target() -> Target { let llvm_target = super::apple_base::macos_llvm_target("arm64"); Target { - llvm_target, + llvm_target: llvm_target.into(), pointer_width: 64, - data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - mcount: "\u{1}mcount".to_string(), + mcount: "\u{1}mcount".into(), frame_pointer: FramePointer::NonLeaf, ..base }, diff --git a/compiler/rustc_target/src/spec/aarch64_apple_ios.rs b/compiler/rustc_target/src/spec/aarch64_apple_ios.rs index 6468419fce7..beb9042390b 100644 --- a/compiler/rustc_target/src/spec/aarch64_apple_ios.rs +++ b/compiler/rustc_target/src/spec/aarch64_apple_ios.rs @@ -10,12 +10,12 @@ pub fn target() -> Target { let llvm_target = super::apple_base::ios_llvm_target(arch); Target { - llvm_target, + llvm_target: llvm_target.into(), pointer_width: 64, - data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - features: "+neon,+fp-armv8,+apple-a7".to_string(), + features: "+neon,+fp-armv8,+apple-a7".into(), max_atomic_width: Some(128), forces_embed_bitcode: true, frame_pointer: FramePointer::NonLeaf, @@ -29,7 +29,7 @@ pub fn target() -> Target { -target-abi\0\ darwinpcs\0\ -Os\0" - .to_string(), + .into(), ..opts("ios", Arch::Arm64) }, } diff --git a/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs b/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs index d16328f00f9..57634cbbfb1 100644 --- a/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs +++ b/compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs @@ -3,12 +3,12 @@ use crate::spec::{FramePointer, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "arm64-apple-ios14.0-macabi".to_string(), + llvm_target: "arm64-apple-ios14.0-macabi".into(), pointer_width: 64, - data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - features: "+neon,+fp-armv8,+apple-a12".to_string(), + features: "+neon,+fp-armv8,+apple-a12".into(), max_atomic_width: Some(128), forces_embed_bitcode: true, frame_pointer: FramePointer::NonLeaf, @@ -20,7 +20,7 @@ pub fn target() -> Target { -emit-obj\0\ -disable-llvm-passes\0\ -Os\0" - .to_string(), + .into(), ..opts("ios", Arch::Arm64_macabi) }, } diff --git a/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs b/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs index 07b3453218f..b4e135f66e9 100644 --- a/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs +++ b/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs @@ -12,12 +12,12 @@ pub fn target() -> Target { let llvm_target = super::apple_base::ios_sim_llvm_target(arch); Target { - llvm_target: llvm_target, + llvm_target: llvm_target.into(), pointer_width: 64, - data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - features: "+neon,+fp-armv8,+apple-a7".to_string(), + features: "+neon,+fp-armv8,+apple-a7".into(), max_atomic_width: Some(128), forces_embed_bitcode: true, frame_pointer: FramePointer::NonLeaf, @@ -31,7 +31,7 @@ pub fn target() -> Target { -target-abi\0\ darwinpcs\0\ -Os\0" - .to_string(), + .into(), ..base }, } diff --git a/compiler/rustc_target/src/spec/aarch64_apple_tvos.rs b/compiler/rustc_target/src/spec/aarch64_apple_tvos.rs index b4bd72a082b..2e31d16dc76 100644 --- a/compiler/rustc_target/src/spec/aarch64_apple_tvos.rs +++ b/compiler/rustc_target/src/spec/aarch64_apple_tvos.rs @@ -3,12 +3,12 @@ use crate::spec::{FramePointer, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "arm64-apple-tvos".to_string(), + llvm_target: "arm64-apple-tvos".into(), pointer_width: 64, - data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - features: "+neon,+fp-armv8,+apple-a7".to_string(), + features: "+neon,+fp-armv8,+apple-a7".into(), max_atomic_width: Some(128), forces_embed_bitcode: true, frame_pointer: FramePointer::NonLeaf, diff --git a/compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu.rs index a393858879b..9bce82a191e 100644 --- a/compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu.rs @@ -3,14 +3,14 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "aarch64_be-unknown-linux-gnu".to_string(), + llvm_target: "aarch64_be-unknown-linux-gnu".into(), pointer_width: 64, - data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - features: "+outline-atomics".to_string(), + features: "+outline-atomics".into(), max_atomic_width: Some(128), - mcount: "\u{1}_mcount".to_string(), + mcount: "\u{1}_mcount".into(), endian: Endian::Big, ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu_ilp32.rs b/compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu_ilp32.rs index e75100f1435..c9ceb55ddad 100644 --- a/compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu_ilp32.rs +++ b/compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu_ilp32.rs @@ -6,14 +6,14 @@ pub fn target() -> Target { base.max_atomic_width = Some(128); Target { - llvm_target: "aarch64_be-unknown-linux-gnu_ilp32".to_string(), + llvm_target: "aarch64_be-unknown-linux-gnu_ilp32".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - abi: "ilp32".to_string(), - features: "+outline-atomics".to_string(), - mcount: "\u{1}_mcount".to_string(), + abi: "ilp32".into(), + features: "+outline-atomics".into(), + mcount: "\u{1}_mcount".into(), endian: Endian::Big, ..base }, diff --git a/compiler/rustc_target/src/spec/aarch64_fuchsia.rs b/compiler/rustc_target/src/spec/aarch64_fuchsia.rs index 05e0c65dd5c..4634433c4a9 100644 --- a/compiler/rustc_target/src/spec/aarch64_fuchsia.rs +++ b/compiler/rustc_target/src/spec/aarch64_fuchsia.rs @@ -2,10 +2,10 @@ use crate::spec::{SanitizerSet, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "aarch64-fuchsia".to_string(), + llvm_target: "aarch64-fuchsia".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { max_atomic_width: Some(128), supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::CFI, diff --git a/compiler/rustc_target/src/spec/aarch64_kmc_solid_asp3.rs b/compiler/rustc_target/src/spec/aarch64_kmc_solid_asp3.rs index 61e3be617e9..6ea9ae2667e 100644 --- a/compiler/rustc_target/src/spec/aarch64_kmc_solid_asp3.rs +++ b/compiler/rustc_target/src/spec/aarch64_kmc_solid_asp3.rs @@ -3,13 +3,13 @@ use super::{RelocModel, Target, TargetOptions}; pub fn target() -> Target { let base = super::solid_base::opts("asp3"); Target { - llvm_target: "aarch64-unknown-none".to_string(), + llvm_target: "aarch64-unknown-none".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - linker: Some("aarch64-kmc-elf-gcc".to_owned()), - features: "+neon,+fp-armv8".to_string(), + linker: Some("aarch64-kmc-elf-gcc".into()), + features: "+neon,+fp-armv8".into(), relocation_model: RelocModel::Static, disable_redzone: true, max_atomic_width: Some(128), diff --git a/compiler/rustc_target/src/spec/aarch64_linux_android.rs b/compiler/rustc_target/src/spec/aarch64_linux_android.rs index 87696b3664c..5e31859aaef 100644 --- a/compiler/rustc_target/src/spec/aarch64_linux_android.rs +++ b/compiler/rustc_target/src/spec/aarch64_linux_android.rs @@ -5,15 +5,15 @@ use crate::spec::{SanitizerSet, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "aarch64-linux-android".to_string(), + llvm_target: "aarch64-linux-android".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { max_atomic_width: Some(128), // As documented in https://developer.android.com/ndk/guides/cpu-features.html // the neon (ASIMD) and FP must exist on all android aarch64 targets. - features: "+neon,+fp-armv8".to_string(), + features: "+neon,+fp-armv8".into(), supported_sanitizers: SanitizerSet::CFI | SanitizerSet::HWADDRESS | SanitizerSet::MEMTAG diff --git a/compiler/rustc_target/src/spec/aarch64_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/aarch64_pc_windows_msvc.rs index a9a0977e702..856ec4fb0b4 100644 --- a/compiler/rustc_target/src/spec/aarch64_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/aarch64_pc_windows_msvc.rs @@ -3,13 +3,13 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::windows_msvc_base::opts(); base.max_atomic_width = Some(64); - base.features = "+neon,+fp-armv8".to_string(); + base.features = "+neon,+fp-armv8".into(); Target { - llvm_target: "aarch64-pc-windows-msvc".to_string(), + llvm_target: "aarch64-pc-windows-msvc".into(), pointer_width: 64, - data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_freebsd.rs b/compiler/rustc_target/src/spec/aarch64_unknown_freebsd.rs index 03ee7ba4875..2f39c4862cf 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_freebsd.rs @@ -2,10 +2,10 @@ use crate::spec::{SanitizerSet, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "aarch64-unknown-freebsd".to_string(), + llvm_target: "aarch64-unknown-freebsd".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { max_atomic_width: Some(128), supported_sanitizers: SanitizerSet::ADDRESS diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs b/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs index f8e1e1b02f5..1d7269c8d73 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_hermit.rs @@ -3,13 +3,13 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::hermit_base::opts(); base.max_atomic_width = Some(128); - base.features = "+strict-align,+neon,+fp-armv8".to_string(); + base.features = "+strict-align,+neon,+fp-armv8".into(); Target { - llvm_target: "aarch64-unknown-hermit".to_string(), + llvm_target: "aarch64-unknown-hermit".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu.rs index 974a5b84d1d..3006044d54a 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu.rs @@ -2,13 +2,13 @@ use crate::spec::{SanitizerSet, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "aarch64-unknown-linux-gnu".to_string(), + llvm_target: "aarch64-unknown-linux-gnu".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - features: "+outline-atomics".to_string(), - mcount: "\u{1}_mcount".to_string(), + features: "+outline-atomics".into(), + mcount: "\u{1}_mcount".into(), max_atomic_width: Some(128), supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::CFI diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu_ilp32.rs b/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu_ilp32.rs index 1c931d5a705..63023df1d6c 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu_ilp32.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu_ilp32.rs @@ -2,15 +2,15 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "aarch64-unknown-linux-gnu_ilp32".to_string(), + llvm_target: "aarch64-unknown-linux-gnu_ilp32".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - abi: "ilp32".to_string(), - features: "+outline-atomics".to_string(), + abi: "ilp32".into(), + features: "+outline-atomics".into(), max_atomic_width: Some(128), - mcount: "\u{1}_mcount".to_string(), + mcount: "\u{1}_mcount".into(), ..super::linux_gnu_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/aarch64_unknown_linux_musl.rs index 6a16b4ce419..002d0dac2a6 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_linux_musl.rs @@ -5,10 +5,10 @@ pub fn target() -> Target { base.max_atomic_width = Some(128); Target { - llvm_target: "aarch64-unknown-linux-musl".to_string(), + llvm_target: "aarch64-unknown-linux-musl".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), - options: TargetOptions { mcount: "\u{1}_mcount".to_string(), ..base }, + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), + options: TargetOptions { mcount: "\u{1}_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_netbsd.rs b/compiler/rustc_target/src/spec/aarch64_unknown_netbsd.rs index 4042028e2dc..703f7502295 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_netbsd.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_netbsd.rs @@ -2,12 +2,12 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "aarch64-unknown-netbsd".to_string(), + llvm_target: "aarch64-unknown-netbsd".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { - mcount: "__mcount".to_string(), + mcount: "__mcount".into(), max_atomic_width: Some(128), ..super::netbsd_base::opts() }, diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_none.rs b/compiler/rustc_target/src/spec/aarch64_unknown_none.rs index 9d365279010..2c7834c225b 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_none.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_none.rs @@ -11,8 +11,8 @@ use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, Target, TargetOp pub fn target() -> Target { let opts = TargetOptions { linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_owned()), - features: "+strict-align,+neon,+fp-armv8".to_string(), + linker: Some("rust-lld".into()), + features: "+strict-align,+neon,+fp-armv8".into(), executables: true, relocation_model: RelocModel::Static, disable_redzone: true, @@ -21,10 +21,10 @@ pub fn target() -> Target { ..Default::default() }; Target { - llvm_target: "aarch64-unknown-none".to_string(), + llvm_target: "aarch64-unknown-none".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: opts, } } diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_none_softfloat.rs b/compiler/rustc_target/src/spec/aarch64_unknown_none_softfloat.rs index fa93ca80549..1b6525a7c69 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_none_softfloat.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_none_softfloat.rs @@ -10,10 +10,10 @@ use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, Target, TargetOp pub fn target() -> Target { let opts = TargetOptions { - abi: "softfloat".to_string(), + abi: "softfloat".into(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_owned()), - features: "+strict-align,-neon,-fp-armv8".to_string(), + linker: Some("rust-lld".into()), + features: "+strict-align,-neon,-fp-armv8".into(), executables: true, relocation_model: RelocModel::Static, disable_redzone: true, @@ -22,10 +22,10 @@ pub fn target() -> Target { ..Default::default() }; Target { - llvm_target: "aarch64-unknown-none".to_string(), + llvm_target: "aarch64-unknown-none".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: opts, } } diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_openbsd.rs b/compiler/rustc_target/src/spec/aarch64_unknown_openbsd.rs index 193f9814210..3d99040f0d3 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_openbsd.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_openbsd.rs @@ -2,10 +2,10 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "aarch64-unknown-openbsd".to_string(), + llvm_target: "aarch64-unknown-openbsd".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { max_atomic_width: Some(128), ..super::openbsd_base::opts() }, } } diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_redox.rs b/compiler/rustc_target/src/spec/aarch64_unknown_redox.rs index b9c9325831d..6c9be4c8e93 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_redox.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_redox.rs @@ -5,10 +5,10 @@ pub fn target() -> Target { base.max_atomic_width = Some(128); Target { - llvm_target: "aarch64-unknown-redox".to_string(), + llvm_target: "aarch64-unknown-redox".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_uefi.rs b/compiler/rustc_target/src/spec/aarch64_unknown_uefi.rs index 20c528d25f3..965b254c289 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_uefi.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_uefi.rs @@ -9,7 +9,7 @@ pub fn target() -> Target { base.max_atomic_width = Some(64); - let pre_link_args_msvc = vec!["/machine:arm64".to_string()]; + let pre_link_args_msvc = vec!["/machine:arm64".into()]; base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().extend(pre_link_args_msvc.clone()); base.pre_link_args @@ -18,10 +18,10 @@ pub fn target() -> Target { .extend(pre_link_args_msvc); Target { - llvm_target: "aarch64-unknown-windows".to_string(), + llvm_target: "aarch64-unknown-windows".into(), pointer_width: 64, - data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/aarch64_uwp_windows_msvc.rs b/compiler/rustc_target/src/spec/aarch64_uwp_windows_msvc.rs index db4eb204e0b..54247fd93f2 100644 --- a/compiler/rustc_target/src/spec/aarch64_uwp_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/aarch64_uwp_windows_msvc.rs @@ -5,10 +5,10 @@ pub fn target() -> Target { base.max_atomic_width = Some(64); Target { - llvm_target: "aarch64-pc-windows-msvc".to_string(), + llvm_target: "aarch64-pc-windows-msvc".into(), pointer_width: 64, - data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/aarch64_wrs_vxworks.rs b/compiler/rustc_target/src/spec/aarch64_wrs_vxworks.rs index 66140060f8e..e118553dfd2 100644 --- a/compiler/rustc_target/src/spec/aarch64_wrs_vxworks.rs +++ b/compiler/rustc_target/src/spec/aarch64_wrs_vxworks.rs @@ -2,10 +2,10 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "aarch64-unknown-linux-gnu".to_string(), + llvm_target: "aarch64-unknown-linux-gnu".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), - arch: "aarch64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(), + arch: "aarch64".into(), options: TargetOptions { max_atomic_width: Some(128), ..super::vxworks_base::opts() }, } } diff --git a/compiler/rustc_target/src/spec/android_base.rs b/compiler/rustc_target/src/spec/android_base.rs index dc14d260e92..c2b9d696776 100644 --- a/compiler/rustc_target/src/spec/android_base.rs +++ b/compiler/rustc_target/src/spec/android_base.rs @@ -2,7 +2,7 @@ use crate::spec::TargetOptions; pub fn opts() -> TargetOptions { let mut base = super::linux_base::opts(); - base.os = "android".to_string(); + base.os = "android".into(); base.dwarf_version = Some(2); base.position_independent_executables = true; base.has_thread_local = false; diff --git a/compiler/rustc_target/src/spec/apple_base.rs b/compiler/rustc_target/src/spec/apple_base.rs index a4488f695f2..238d3f8bda5 100644 --- a/compiler/rustc_target/src/spec/apple_base.rs +++ b/compiler/rustc_target/src/spec/apple_base.rs @@ -1,8 +1,8 @@ -use std::env; +use std::{borrow::Cow, env}; -use crate::spec::{FramePointer, LldFlavor, SplitDebuginfo, TargetOptions}; +use crate::spec::{cvs, FramePointer, LldFlavor, SplitDebuginfo, TargetOptions}; -pub fn opts(os: &str) -> TargetOptions { +pub fn opts(os: &'static str) -> TargetOptions { // ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6 // either the linker will complain if it is used or the binary will end up // segfaulting at runtime when run on 10.6. Rust by default supports macOS @@ -19,20 +19,20 @@ pub fn opts(os: &str) -> TargetOptions { let has_thread_local = macos_deployment_target("x86_64") >= (10, 7); TargetOptions { - os: os.to_string(), - vendor: "apple".to_string(), + os: os.into(), + vendor: "apple".into(), // macOS has -dead_strip, which doesn't rely on function_sections function_sections: false, dynamic_linking: true, linker_is_gnu: false, executables: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], is_like_osx: true, dwarf_version: Some(2), frame_pointer: FramePointer::Always, has_rpath: true, - dll_suffix: ".dylib".to_string(), - archive_format: "darwin".to_string(), + dll_suffix: ".dylib".into(), + archive_format: "darwin".into(), has_thread_local, abi_return_struct_as_int: true, emit_debug_gdb_scripts: false, @@ -51,7 +51,7 @@ pub fn opts(os: &str) -> TargetOptions { // this environment variable too in recent versions. // // For some more info see the commentary on #47086 - link_env: vec![("ZERO_AR_DATE".to_string(), "1".to_string())], + link_env: Cow::Borrowed(&[(Cow::Borrowed("ZERO_AR_DATE"), Cow::Borrowed("1"))]), ..Default::default() } @@ -79,19 +79,19 @@ pub fn macos_llvm_target(arch: &str) -> String { format!("{}-apple-macosx{}.{}.0", arch, major, minor) } -pub fn macos_link_env_remove() -> Vec<String> { +pub fn macos_link_env_remove() -> Vec<Cow<'static, str>> { let mut env_remove = Vec::with_capacity(2); // Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which // may occur when we're linking a custom build script while targeting iOS for example. if let Ok(sdkroot) = env::var("SDKROOT") { if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("iPhoneSimulator.platform") { - env_remove.push("SDKROOT".to_string()) + env_remove.push("SDKROOT".into()) } } // Additionally, `IPHONEOS_DEPLOYMENT_TARGET` must not be set when using the Xcode linker at // "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", // although this is apparently ignored when using the linker at "/usr/bin/ld". - env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".to_string()); + env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into()); env_remove } diff --git a/compiler/rustc_target/src/spec/apple_sdk_base.rs b/compiler/rustc_target/src/spec/apple_sdk_base.rs index 874e9b56aaa..e2d08955c08 100644 --- a/compiler/rustc_target/src/spec/apple_sdk_base.rs +++ b/compiler/rustc_target/src/spec/apple_sdk_base.rs @@ -1,4 +1,5 @@ -use crate::spec::TargetOptions; +use crate::{spec::cvs, spec::TargetOptions}; +use std::borrow::Cow; use Arch::*; #[allow(non_camel_case_types)] @@ -14,16 +15,15 @@ pub enum Arch { Arm64_sim, } -fn target_abi(arch: Arch) -> String { +fn target_abi(arch: Arch) -> &'static str { match arch { Armv7 | Armv7s | Arm64 | I386 | X86_64 => "", X86_64_macabi | Arm64_macabi => "macabi", Arm64_sim => "sim", } - .to_string() } -fn target_cpu(arch: Arch) -> String { +fn target_cpu(arch: Arch) -> &'static str { match arch { Armv7 => "cortex-a8", // iOS7 is supported on iPhone 4 and higher Armv7s => "cortex-a9", @@ -34,22 +34,21 @@ fn target_cpu(arch: Arch) -> String { Arm64_macabi => "apple-a12", Arm64_sim => "apple-a12", } - .to_string() } -fn link_env_remove(arch: Arch) -> Vec<String> { +fn link_env_remove(arch: Arch) -> Cow<'static, [Cow<'static, str>]> { match arch { Armv7 | Armv7s | Arm64 | I386 | X86_64 | Arm64_sim => { - vec!["MACOSX_DEPLOYMENT_TARGET".to_string()] + cvs!["MACOSX_DEPLOYMENT_TARGET"] } - X86_64_macabi | Arm64_macabi => vec!["IPHONEOS_DEPLOYMENT_TARGET".to_string()], + X86_64_macabi | Arm64_macabi => cvs!["IPHONEOS_DEPLOYMENT_TARGET"], } } -pub fn opts(os: &str, arch: Arch) -> TargetOptions { +pub fn opts(os: &'static str, arch: Arch) -> TargetOptions { TargetOptions { - abi: target_abi(arch), - cpu: target_cpu(arch), + abi: target_abi(arch).into(), + cpu: target_cpu(arch).into(), dynamic_linking: false, executables: true, link_env_remove: link_env_remove(arch), diff --git a/compiler/rustc_target/src/spec/arm_linux_androideabi.rs b/compiler/rustc_target/src/spec/arm_linux_androideabi.rs index 933b43986c9..bbf1fa315ab 100644 --- a/compiler/rustc_target/src/spec/arm_linux_androideabi.rs +++ b/compiler/rustc_target/src/spec/arm_linux_androideabi.rs @@ -2,14 +2,14 @@ use crate::spec::{SanitizerSet, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "arm-linux-androideabi".to_string(), + llvm_target: "arm-linux-androideabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), // https://developer.android.com/ndk/guides/abis.html#armeabi - features: "+strict-align,+v5te".to_string(), + features: "+strict-align,+v5te".into(), supported_sanitizers: SanitizerSet::ADDRESS, max_atomic_width: Some(32), ..super::android_base::opts() diff --git a/compiler/rustc_target/src/spec/arm_unknown_linux_gnueabi.rs b/compiler/rustc_target/src/spec/arm_unknown_linux_gnueabi.rs index 442f56d4fb5..c0f1827ad3f 100644 --- a/compiler/rustc_target/src/spec/arm_unknown_linux_gnueabi.rs +++ b/compiler/rustc_target/src/spec/arm_unknown_linux_gnueabi.rs @@ -2,15 +2,15 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "arm-unknown-linux-gnueabi".to_string(), + llvm_target: "arm-unknown-linux-gnueabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), - features: "+strict-align,+v6".to_string(), + abi: "eabi".into(), + features: "+strict-align,+v6".into(), max_atomic_width: Some(64), - mcount: "\u{1}__gnu_mcount_nc".to_string(), + mcount: "\u{1}__gnu_mcount_nc".into(), ..super::linux_gnu_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/arm_unknown_linux_gnueabihf.rs b/compiler/rustc_target/src/spec/arm_unknown_linux_gnueabihf.rs index 2c12a71e29f..79b8958c22a 100644 --- a/compiler/rustc_target/src/spec/arm_unknown_linux_gnueabihf.rs +++ b/compiler/rustc_target/src/spec/arm_unknown_linux_gnueabihf.rs @@ -2,15 +2,15 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "arm-unknown-linux-gnueabihf".to_string(), + llvm_target: "arm-unknown-linux-gnueabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), - features: "+strict-align,+v6,+vfp2,-d32".to_string(), + abi: "eabihf".into(), + features: "+strict-align,+v6,+vfp2,-d32".into(), max_atomic_width: Some(64), - mcount: "\u{1}__gnu_mcount_nc".to_string(), + mcount: "\u{1}__gnu_mcount_nc".into(), ..super::linux_gnu_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/arm_unknown_linux_musleabi.rs b/compiler/rustc_target/src/spec/arm_unknown_linux_musleabi.rs index d187dfd9189..3ef441d6a60 100644 --- a/compiler/rustc_target/src/spec/arm_unknown_linux_musleabi.rs +++ b/compiler/rustc_target/src/spec/arm_unknown_linux_musleabi.rs @@ -5,17 +5,17 @@ pub fn target() -> Target { // It's important we use "gnueabi" and not "musleabi" here. LLVM uses it // to determine the calling convention and float ABI, and it doesn't // support the "musleabi" value. - llvm_target: "arm-unknown-linux-gnueabi".to_string(), + llvm_target: "arm-unknown-linux-gnueabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), // Most of these settings are copied from the arm_unknown_linux_gnueabi // target. - features: "+strict-align,+v6".to_string(), + features: "+strict-align,+v6".into(), max_atomic_width: Some(64), - mcount: "\u{1}mcount".to_string(), + mcount: "\u{1}mcount".into(), ..super::linux_musl_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/arm_unknown_linux_musleabihf.rs b/compiler/rustc_target/src/spec/arm_unknown_linux_musleabihf.rs index 3d72734f5fa..eb6660d4c28 100644 --- a/compiler/rustc_target/src/spec/arm_unknown_linux_musleabihf.rs +++ b/compiler/rustc_target/src/spec/arm_unknown_linux_musleabihf.rs @@ -5,17 +5,17 @@ pub fn target() -> Target { // It's important we use "gnueabihf" and not "musleabihf" here. LLVM // uses it to determine the calling convention and float ABI, and it // doesn't support the "musleabihf" value. - llvm_target: "arm-unknown-linux-gnueabihf".to_string(), + llvm_target: "arm-unknown-linux-gnueabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), // Most of these settings are copied from the arm_unknown_linux_gnueabihf // target. - features: "+strict-align,+v6,+vfp2,-d32".to_string(), + features: "+strict-align,+v6,+vfp2,-d32".into(), max_atomic_width: Some(64), - mcount: "\u{1}mcount".to_string(), + mcount: "\u{1}mcount".into(), ..super::linux_musl_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/armebv7r_none_eabi.rs b/compiler/rustc_target/src/spec/armebv7r_none_eabi.rs index ed4779c0c02..0cb18f17310 100644 --- a/compiler/rustc_target/src/spec/armebv7r_none_eabi.rs +++ b/compiler/rustc_target/src/spec/armebv7r_none_eabi.rs @@ -6,16 +6,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armebv7r-unknown-none-eabi".to_string(), + llvm_target: "armebv7r-unknown-none-eabi".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), endian: Endian::Big, linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), executables: true, - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), relocation_model: RelocModel::Static, panic_strategy: PanicStrategy::Abort, max_atomic_width: Some(32), diff --git a/compiler/rustc_target/src/spec/armebv7r_none_eabihf.rs b/compiler/rustc_target/src/spec/armebv7r_none_eabihf.rs index b60e2895d77..a5b7c12cc7b 100644 --- a/compiler/rustc_target/src/spec/armebv7r_none_eabihf.rs +++ b/compiler/rustc_target/src/spec/armebv7r_none_eabihf.rs @@ -6,19 +6,19 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armebv7r-unknown-none-eabihf".to_string(), + llvm_target: "armebv7r-unknown-none-eabihf".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), endian: Endian::Big, linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), executables: true, - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), relocation_model: RelocModel::Static, panic_strategy: PanicStrategy::Abort, - features: "+vfp3,-d32,-fp16".to_string(), + features: "+vfp3,-d32,-fp16".into(), max_atomic_width: Some(32), emit_debug_gdb_scripts: false, // GCC and Clang default to 8 for arm-none here diff --git a/compiler/rustc_target/src/spec/armv4t_unknown_linux_gnueabi.rs b/compiler/rustc_target/src/spec/armv4t_unknown_linux_gnueabi.rs index f1b193a384f..1de63a920c8 100644 --- a/compiler/rustc_target/src/spec/armv4t_unknown_linux_gnueabi.rs +++ b/compiler/rustc_target/src/spec/armv4t_unknown_linux_gnueabi.rs @@ -2,16 +2,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv4t-unknown-linux-gnueabi".to_string(), + llvm_target: "armv4t-unknown-linux-gnueabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), - features: "+soft-float,+strict-align".to_string(), + abi: "eabi".into(), + features: "+soft-float,+strict-align".into(), // Atomic operations provided by compiler-builtins max_atomic_width: Some(32), - mcount: "\u{1}__gnu_mcount_nc".to_string(), + mcount: "\u{1}__gnu_mcount_nc".into(), has_thumb_interworking: true, ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/armv5te_unknown_linux_gnueabi.rs b/compiler/rustc_target/src/spec/armv5te_unknown_linux_gnueabi.rs index a6c4f2304c2..b940563102b 100644 --- a/compiler/rustc_target/src/spec/armv5te_unknown_linux_gnueabi.rs +++ b/compiler/rustc_target/src/spec/armv5te_unknown_linux_gnueabi.rs @@ -2,16 +2,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv5te-unknown-linux-gnueabi".to_string(), + llvm_target: "armv5te-unknown-linux-gnueabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), - features: "+soft-float,+strict-align".to_string(), + abi: "eabi".into(), + features: "+soft-float,+strict-align".into(), // Atomic operations provided by compiler-builtins max_atomic_width: Some(32), - mcount: "\u{1}__gnu_mcount_nc".to_string(), + mcount: "\u{1}__gnu_mcount_nc".into(), has_thumb_interworking: true, ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/armv5te_unknown_linux_musleabi.rs b/compiler/rustc_target/src/spec/armv5te_unknown_linux_musleabi.rs index de2a350e231..2530971b502 100644 --- a/compiler/rustc_target/src/spec/armv5te_unknown_linux_musleabi.rs +++ b/compiler/rustc_target/src/spec/armv5te_unknown_linux_musleabi.rs @@ -6,16 +6,16 @@ pub fn target() -> Target { // It's important we use "gnueabihf" and not "musleabihf" here. LLVM // uses it to determine the calling convention and float ABI, and LLVM // doesn't support the "musleabihf" value. - llvm_target: "armv5te-unknown-linux-gnueabi".to_string(), + llvm_target: "armv5te-unknown-linux-gnueabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), - features: "+soft-float,+strict-align".to_string(), + abi: "eabi".into(), + features: "+soft-float,+strict-align".into(), // Atomic operations provided by compiler-builtins max_atomic_width: Some(32), - mcount: "\u{1}mcount".to_string(), + mcount: "\u{1}mcount".into(), has_thumb_interworking: true, ..super::linux_musl_base::opts() }, diff --git a/compiler/rustc_target/src/spec/armv5te_unknown_linux_uclibceabi.rs b/compiler/rustc_target/src/spec/armv5te_unknown_linux_uclibceabi.rs index 91b4bd27caa..a51be10a3d8 100644 --- a/compiler/rustc_target/src/spec/armv5te_unknown_linux_uclibceabi.rs +++ b/compiler/rustc_target/src/spec/armv5te_unknown_linux_uclibceabi.rs @@ -2,16 +2,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv5te-unknown-linux-uclibcgnueabi".to_string(), + llvm_target: "armv5te-unknown-linux-uclibcgnueabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), - features: "+soft-float,+strict-align".to_string(), + abi: "eabi".into(), + features: "+soft-float,+strict-align".into(), // Atomic operations provided by compiler-builtins max_atomic_width: Some(32), - mcount: "\u{1}__gnu_mcount_nc".to_string(), + mcount: "\u{1}__gnu_mcount_nc".into(), has_thumb_interworking: true, ..super::linux_uclibc_base::opts() }, diff --git a/compiler/rustc_target/src/spec/armv6_unknown_freebsd.rs b/compiler/rustc_target/src/spec/armv6_unknown_freebsd.rs index ee2f8f6238b..b7cfccc8b3d 100644 --- a/compiler/rustc_target/src/spec/armv6_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/armv6_unknown_freebsd.rs @@ -2,17 +2,17 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv6-unknown-freebsd-gnueabihf".to_string(), + llvm_target: "armv6-unknown-freebsd-gnueabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), // FIXME: change env to "gnu" when cfg_target_abi becomes stable - env: "gnueabihf".to_string(), - features: "+v6,+vfp2,-d32".to_string(), + env: "gnueabihf".into(), + features: "+v6,+vfp2,-d32".into(), max_atomic_width: Some(64), - mcount: "\u{1}__gnu_mcount_nc".to_string(), + mcount: "\u{1}__gnu_mcount_nc".into(), ..super::freebsd_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/armv6_unknown_netbsd_eabihf.rs b/compiler/rustc_target/src/spec/armv6_unknown_netbsd_eabihf.rs index b046819d4d7..6e26f686fcb 100644 --- a/compiler/rustc_target/src/spec/armv6_unknown_netbsd_eabihf.rs +++ b/compiler/rustc_target/src/spec/armv6_unknown_netbsd_eabihf.rs @@ -2,17 +2,17 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv6-unknown-netbsdelf-eabihf".to_string(), + llvm_target: "armv6-unknown-netbsdelf-eabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), // FIXME: remove env when cfg_target_abi becomes stable - env: "eabihf".to_string(), - features: "+v6,+vfp2,-d32".to_string(), + env: "eabihf".into(), + features: "+v6,+vfp2,-d32".into(), max_atomic_width: Some(64), - mcount: "__mcount".to_string(), + mcount: "__mcount".into(), ..super::netbsd_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/armv6k_nintendo_3ds.rs b/compiler/rustc_target/src/spec/armv6k_nintendo_3ds.rs index 84105fbad47..ffcd1a3f4df 100644 --- a/compiler/rustc_target/src/spec/armv6k_nintendo_3ds.rs +++ b/compiler/rustc_target/src/spec/armv6k_nintendo_3ds.rs @@ -1,4 +1,4 @@ -use crate::spec::{LinkArgs, LinkerFlavor, RelocModel, Target, TargetOptions}; +use crate::spec::{cvs, LinkArgs, LinkerFlavor, RelocModel, Target, TargetOptions}; /// A base target for Nintendo 3DS devices using the devkitARM toolchain. /// @@ -9,33 +9,33 @@ pub fn target() -> Target { pre_link_args.insert( LinkerFlavor::Gcc, vec![ - "-specs=3dsx.specs".to_string(), - "-mtune=mpcore".to_string(), - "-mfloat-abi=hard".to_string(), - "-mtp=soft".to_string(), + "-specs=3dsx.specs".into(), + "-mtune=mpcore".into(), + "-mfloat-abi=hard".into(), + "-mtp=soft".into(), ], ); Target { - llvm_target: "armv6k-none-eabihf".to_string(), + llvm_target: "armv6k-none-eabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - os: "horizon".to_string(), - env: "newlib".to_string(), - vendor: "nintendo".to_string(), - abi: "eabihf".to_string(), + os: "horizon".into(), + env: "newlib".into(), + vendor: "nintendo".into(), + abi: "eabihf".into(), linker_flavor: LinkerFlavor::Gcc, - cpu: "mpcore".to_string(), + cpu: "mpcore".into(), executables: true, - families: vec!["unix".to_string()], - linker: Some("arm-none-eabi-gcc".to_string()), + families: cvs!["unix"], + linker: Some("arm-none-eabi-gcc".into()), relocation_model: RelocModel::Static, - features: "+vfp2".to_string(), + features: "+vfp2".into(), pre_link_args, - exe_suffix: ".elf".to_string(), + exe_suffix: ".elf".into(), no_default_libraries: false, has_thread_local: true, ..Default::default() diff --git a/compiler/rustc_target/src/spec/armv7_apple_ios.rs b/compiler/rustc_target/src/spec/armv7_apple_ios.rs index 1f90c78f14a..57fd74a36b6 100644 --- a/compiler/rustc_target/src/spec/armv7_apple_ios.rs +++ b/compiler/rustc_target/src/spec/armv7_apple_ios.rs @@ -2,13 +2,15 @@ use super::apple_sdk_base::{opts, Arch}; use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { + let llvm_target = super::apple_base::ios_llvm_target("armv7"); + Target { - llvm_target: super::apple_base::ios_llvm_target("armv7"), + llvm_target: llvm_target.into(), pointer_width: 32, - data_layout: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".into(), + arch: "arm".into(), options: TargetOptions { - features: "+v7,+vfp3,+neon".to_string(), + features: "+v7,+vfp3,+neon".into(), max_atomic_width: Some(64), ..opts("ios", Arch::Armv7) }, diff --git a/compiler/rustc_target/src/spec/armv7_linux_androideabi.rs b/compiler/rustc_target/src/spec/armv7_linux_androideabi.rs index adf831c12eb..2afd93fcad8 100644 --- a/compiler/rustc_target/src/spec/armv7_linux_androideabi.rs +++ b/compiler/rustc_target/src/spec/armv7_linux_androideabi.rs @@ -10,15 +10,15 @@ use crate::spec::{LinkerFlavor, SanitizerSet, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::android_base::opts(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-march=armv7-a".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-march=armv7-a".into()); Target { - llvm_target: "armv7-none-linux-android".to_string(), + llvm_target: "armv7-none-linux-android".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), - features: "+v7,+thumb-mode,+thumb2,+vfp3,-d32,-neon".to_string(), + abi: "eabi".into(), + features: "+v7,+thumb-mode,+thumb2,+vfp3,-d32,-neon".into(), supported_sanitizers: SanitizerSet::ADDRESS, max_atomic_width: Some(64), ..base diff --git a/compiler/rustc_target/src/spec/armv7_unknown_freebsd.rs b/compiler/rustc_target/src/spec/armv7_unknown_freebsd.rs index fbfb1c27681..bc37b62de8e 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_freebsd.rs @@ -2,17 +2,17 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv7-unknown-freebsd-gnueabihf".to_string(), + llvm_target: "armv7-unknown-freebsd-gnueabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), // FIXME: change env to "gnu" when cfg_target_abi becomes stable - env: "gnueabihf".to_string(), - features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(), + env: "gnueabihf".into(), + features: "+v7,+vfp3,-d32,+thumb2,-neon".into(), max_atomic_width: Some(64), - mcount: "\u{1}__gnu_mcount_nc".to_string(), + mcount: "\u{1}__gnu_mcount_nc".into(), ..super::freebsd_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_gnueabi.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_gnueabi.rs index 0a3b8033dd1..903042d7e7a 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_linux_gnueabi.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_gnueabi.rs @@ -5,15 +5,15 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv7-unknown-linux-gnueabi".to_string(), + llvm_target: "armv7-unknown-linux-gnueabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), - features: "+v7,+thumb2,+soft-float,-neon".to_string(), + abi: "eabi".into(), + features: "+v7,+thumb2,+soft-float,-neon".into(), max_atomic_width: Some(64), - mcount: "\u{1}__gnu_mcount_nc".to_string(), + mcount: "\u{1}__gnu_mcount_nc".into(), ..super::linux_gnu_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_gnueabihf.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_gnueabihf.rs index 662b81cae3e..e39ea49a003 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_linux_gnueabihf.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_gnueabihf.rs @@ -5,16 +5,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv7-unknown-linux-gnueabihf".to_string(), + llvm_target: "armv7-unknown-linux-gnueabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), // Info about features at https://wiki.debian.org/ArmHardFloatPort - features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(), + features: "+v7,+vfp3,-d32,+thumb2,-neon".into(), max_atomic_width: Some(64), - mcount: "\u{1}__gnu_mcount_nc".to_string(), + mcount: "\u{1}__gnu_mcount_nc".into(), ..super::linux_gnu_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_musleabi.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_musleabi.rs index c0fd1de17cf..7dae8577396 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_linux_musleabi.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_musleabi.rs @@ -10,16 +10,16 @@ pub fn target() -> Target { // It's important we use "gnueabi" and not "musleabi" here. LLVM uses it // to determine the calling convention and float ABI, and it doesn't // support the "musleabi" value. - llvm_target: "armv7-unknown-linux-gnueabi".to_string(), + llvm_target: "armv7-unknown-linux-gnueabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), - features: "+v7,+thumb2,+soft-float,-neon".to_string(), + abi: "eabi".into(), + features: "+v7,+thumb2,+soft-float,-neon".into(), max_atomic_width: Some(64), - mcount: "\u{1}mcount".to_string(), + mcount: "\u{1}mcount".into(), ..super::linux_musl_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_musleabihf.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_musleabihf.rs index 67ff7999dea..ba83964bf58 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_linux_musleabihf.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_musleabihf.rs @@ -7,18 +7,18 @@ pub fn target() -> Target { // It's important we use "gnueabihf" and not "musleabihf" here. LLVM // uses it to determine the calling convention and float ABI, and LLVM // doesn't support the "musleabihf" value. - llvm_target: "armv7-unknown-linux-gnueabihf".to_string(), + llvm_target: "armv7-unknown-linux-gnueabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), // Most of these settings are copied from the armv7_unknown_linux_gnueabihf // target. options: TargetOptions { - abi: "eabihf".to_string(), - features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(), + abi: "eabihf".into(), + features: "+v7,+vfp3,-d32,+thumb2,-neon".into(), max_atomic_width: Some(64), - mcount: "\u{1}mcount".to_string(), + mcount: "\u{1}mcount".into(), ..super::linux_musl_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabi.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabi.rs index 7faa8ed7a80..171f67070d5 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabi.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabi.rs @@ -6,17 +6,17 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { let base = super::linux_uclibc_base::opts(); Target { - llvm_target: "armv7-unknown-linux-gnueabi".to_string(), + llvm_target: "armv7-unknown-linux-gnueabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - features: "+v7,+thumb2,+soft-float,-neon".to_string(), - cpu: "generic".to_string(), + features: "+v7,+thumb2,+soft-float,-neon".into(), + cpu: "generic".into(), max_atomic_width: Some(64), - mcount: "_mcount".to_string(), - abi: "eabi".to_string(), + mcount: "_mcount".into(), + abi: "eabi".into(), ..base }, } diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabihf.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabihf.rs index d230f77bde2..d3e95a6573d 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabihf.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabihf.rs @@ -6,18 +6,18 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { let base = super::linux_uclibc_base::opts(); Target { - llvm_target: "armv7-unknown-linux-gnueabihf".to_string(), + llvm_target: "armv7-unknown-linux-gnueabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { // Info about features at https://wiki.debian.org/ArmHardFloatPort - features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(), - cpu: "generic".to_string(), + features: "+v7,+vfp3,-d32,+thumb2,-neon".into(), + cpu: "generic".into(), max_atomic_width: Some(64), - mcount: "_mcount".to_string(), - abi: "eabihf".to_string(), + mcount: "_mcount".into(), + abi: "eabihf".into(), ..base }, } diff --git a/compiler/rustc_target/src/spec/armv7_unknown_netbsd_eabihf.rs b/compiler/rustc_target/src/spec/armv7_unknown_netbsd_eabihf.rs index 60a552b018d..c89ae248398 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_netbsd_eabihf.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_netbsd_eabihf.rs @@ -2,17 +2,17 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv7-unknown-netbsdelf-eabihf".to_string(), + llvm_target: "armv7-unknown-netbsdelf-eabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), // FIXME: remove env when cfg_target_abi becomes stable - env: "eabihf".to_string(), - features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(), + env: "eabihf".into(), + features: "+v7,+vfp3,-d32,+thumb2,-neon".into(), max_atomic_width: Some(64), - mcount: "__mcount".to_string(), + mcount: "__mcount".into(), ..super::netbsd_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/armv7_wrs_vxworks_eabihf.rs b/compiler/rustc_target/src/spec/armv7_wrs_vxworks_eabihf.rs index 27d404b101f..c1ab90172e2 100644 --- a/compiler/rustc_target/src/spec/armv7_wrs_vxworks_eabihf.rs +++ b/compiler/rustc_target/src/spec/armv7_wrs_vxworks_eabihf.rs @@ -2,14 +2,14 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv7-unknown-linux-gnueabihf".to_string(), + llvm_target: "armv7-unknown-linux-gnueabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), // Info about features at https://wiki.debian.org/ArmHardFloatPort - features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(), + features: "+v7,+vfp3,-d32,+thumb2,-neon".into(), max_atomic_width: Some(64), ..super::vxworks_base::opts() }, diff --git a/compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabi.rs b/compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabi.rs index 344c48022b2..b49dc650bd0 100644 --- a/compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabi.rs +++ b/compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabi.rs @@ -3,13 +3,13 @@ use super::{RelocModel, Target, TargetOptions}; pub fn target() -> Target { let base = super::solid_base::opts("asp3"); Target { - llvm_target: "armv7a-none-eabi".to_string(), + llvm_target: "armv7a-none-eabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - linker: Some("arm-kmc-eabi-gcc".to_owned()), - features: "+v7,+soft-float,+thumb2,-neon".to_string(), + linker: Some("arm-kmc-eabi-gcc".into()), + features: "+v7,+soft-float,+thumb2,-neon".into(), relocation_model: RelocModel::Static, disable_redzone: true, max_atomic_width: Some(64), diff --git a/compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabihf.rs b/compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabihf.rs index 375502478fe..7d30238e8ab 100644 --- a/compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabihf.rs +++ b/compiler/rustc_target/src/spec/armv7a_kmc_solid_asp3_eabihf.rs @@ -3,13 +3,13 @@ use super::{RelocModel, Target, TargetOptions}; pub fn target() -> Target { let base = super::solid_base::opts("asp3"); Target { - llvm_target: "armv7a-none-eabihf".to_string(), + llvm_target: "armv7a-none-eabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - linker: Some("arm-kmc-eabi-gcc".to_owned()), - features: "+v7,+vfp3,-d32,+thumb2,-neon".to_string(), + linker: Some("arm-kmc-eabi-gcc".into()), + features: "+v7,+vfp3,-d32,+thumb2,-neon".into(), relocation_model: RelocModel::Static, disable_redzone: true, max_atomic_width: Some(64), diff --git a/compiler/rustc_target/src/spec/armv7a_none_eabi.rs b/compiler/rustc_target/src/spec/armv7a_none_eabi.rs index 88040f49d9e..ff649434312 100644 --- a/compiler/rustc_target/src/spec/armv7a_none_eabi.rs +++ b/compiler/rustc_target/src/spec/armv7a_none_eabi.rs @@ -18,10 +18,10 @@ use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, Target, TargetOp pub fn target() -> Target { let opts = TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_owned()), - features: "+v7,+thumb2,+soft-float,-neon,+strict-align".to_string(), + linker: Some("rust-lld".into()), + features: "+v7,+thumb2,+soft-float,-neon,+strict-align".into(), executables: true, relocation_model: RelocModel::Static, disable_redzone: true, @@ -32,10 +32,10 @@ pub fn target() -> Target { ..Default::default() }; Target { - llvm_target: "armv7a-none-eabi".to_string(), + llvm_target: "armv7a-none-eabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: opts, } } diff --git a/compiler/rustc_target/src/spec/armv7a_none_eabihf.rs b/compiler/rustc_target/src/spec/armv7a_none_eabihf.rs index af324843ced..c0321d0bef4 100644 --- a/compiler/rustc_target/src/spec/armv7a_none_eabihf.rs +++ b/compiler/rustc_target/src/spec/armv7a_none_eabihf.rs @@ -9,10 +9,10 @@ use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, Target, TargetOp pub fn target() -> Target { let opts = TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_owned()), - features: "+v7,+vfp3,-d32,+thumb2,-neon,+strict-align".to_string(), + linker: Some("rust-lld".into()), + features: "+v7,+vfp3,-d32,+thumb2,-neon,+strict-align".into(), executables: true, relocation_model: RelocModel::Static, disable_redzone: true, @@ -24,10 +24,10 @@ pub fn target() -> Target { ..Default::default() }; Target { - llvm_target: "armv7a-none-eabihf".to_string(), + llvm_target: "armv7a-none-eabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: opts, } } diff --git a/compiler/rustc_target/src/spec/armv7r_none_eabi.rs b/compiler/rustc_target/src/spec/armv7r_none_eabi.rs index c0e970983e7..2c3f79cc58b 100644 --- a/compiler/rustc_target/src/spec/armv7r_none_eabi.rs +++ b/compiler/rustc_target/src/spec/armv7r_none_eabi.rs @@ -5,16 +5,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv7r-unknown-none-eabi".to_string(), + llvm_target: "armv7r-unknown-none-eabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), executables: true, - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), relocation_model: RelocModel::Static, panic_strategy: PanicStrategy::Abort, max_atomic_width: Some(32), diff --git a/compiler/rustc_target/src/spec/armv7r_none_eabihf.rs b/compiler/rustc_target/src/spec/armv7r_none_eabihf.rs index b126887b27b..5c82e768483 100644 --- a/compiler/rustc_target/src/spec/armv7r_none_eabihf.rs +++ b/compiler/rustc_target/src/spec/armv7r_none_eabihf.rs @@ -5,19 +5,19 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv7r-unknown-none-eabihf".to_string(), + llvm_target: "armv7r-unknown-none-eabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), executables: true, - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), relocation_model: RelocModel::Static, panic_strategy: PanicStrategy::Abort, - features: "+vfp3,-d32,-fp16".to_string(), + features: "+vfp3,-d32,-fp16".into(), max_atomic_width: Some(32), emit_debug_gdb_scripts: false, // GCC and Clang default to 8 for arm-none here diff --git a/compiler/rustc_target/src/spec/armv7s_apple_ios.rs b/compiler/rustc_target/src/spec/armv7s_apple_ios.rs index 2a48e7b6214..cc17265b2b8 100644 --- a/compiler/rustc_target/src/spec/armv7s_apple_ios.rs +++ b/compiler/rustc_target/src/spec/armv7s_apple_ios.rs @@ -3,12 +3,12 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv7s-apple-ios".to_string(), + llvm_target: "armv7s-apple-ios".into(), pointer_width: 32, - data_layout: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".into(), + arch: "arm".into(), options: TargetOptions { - features: "+v7,+vfp4,+neon".to_string(), + features: "+v7,+vfp4,+neon".into(), max_atomic_width: Some(64), ..opts("ios", Arch::Armv7s) }, diff --git a/compiler/rustc_target/src/spec/asmjs_unknown_emscripten.rs b/compiler/rustc_target/src/spec/asmjs_unknown_emscripten.rs index b1adefe1a51..a90c7b7bc6f 100644 --- a/compiler/rustc_target/src/spec/asmjs_unknown_emscripten.rs +++ b/compiler/rustc_target/src/spec/asmjs_unknown_emscripten.rs @@ -6,6 +6,6 @@ pub fn target() -> Target { .post_link_args .entry(LinkerFlavor::Em) .or_default() - .extend(vec!["-s".to_string(), "WASM=0".to_string()]); + .extend(vec!["-s".into(), "WASM=0".into()]); target } diff --git a/compiler/rustc_target/src/spec/avr_gnu_base.rs b/compiler/rustc_target/src/spec/avr_gnu_base.rs index a6c1b344d70..c288e8b0e9e 100644 --- a/compiler/rustc_target/src/spec/avr_gnu_base.rs +++ b/compiler/rustc_target/src/spec/avr_gnu_base.rs @@ -3,24 +3,24 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; /// A base target for AVR devices using the GNU toolchain. /// /// Requires GNU avr-gcc and avr-binutils on the host system. -pub fn target(target_cpu: String) -> Target { +pub fn target(target_cpu: &'static str) -> Target { Target { - arch: "avr".to_string(), - data_layout: "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8".to_string(), - llvm_target: "avr-unknown-unknown".to_string(), + arch: "avr".into(), + data_layout: "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8".into(), + llvm_target: "avr-unknown-unknown".into(), pointer_width: 16, options: TargetOptions { - c_int_width: "16".to_string(), - cpu: target_cpu.clone(), - exe_suffix: ".elf".to_string(), + c_int_width: "16".into(), + cpu: target_cpu.into(), + exe_suffix: ".elf".into(), - linker: Some("avr-gcc".to_owned()), + linker: Some("avr-gcc".into()), executables: true, eh_frame_header: false, - pre_link_args: [(LinkerFlavor::Gcc, vec![format!("-mmcu={}", target_cpu)])] + pre_link_args: [(LinkerFlavor::Gcc, vec![format!("-mmcu={}", target_cpu).into()])] .into_iter() .collect(), - late_link_args: [(LinkerFlavor::Gcc, vec!["-lgcc".to_owned()])].into_iter().collect(), + late_link_args: [(LinkerFlavor::Gcc, vec!["-lgcc".into()])].into_iter().collect(), max_atomic_width: Some(0), atomic_cas: false, ..TargetOptions::default() diff --git a/compiler/rustc_target/src/spec/avr_unknown_gnu_atmega328.rs b/compiler/rustc_target/src/spec/avr_unknown_gnu_atmega328.rs index 7e63ae9c5aa..6871ca0f789 100644 --- a/compiler/rustc_target/src/spec/avr_unknown_gnu_atmega328.rs +++ b/compiler/rustc_target/src/spec/avr_unknown_gnu_atmega328.rs @@ -1,5 +1,5 @@ use crate::spec::Target; pub fn target() -> Target { - super::avr_gnu_base::target("atmega328".to_owned()) + super::avr_gnu_base::target("atmega328") } diff --git a/compiler/rustc_target/src/spec/bpfeb_unknown_none.rs b/compiler/rustc_target/src/spec/bpfeb_unknown_none.rs index a45da82eb40..174ddfa50bf 100644 --- a/compiler/rustc_target/src/spec/bpfeb_unknown_none.rs +++ b/compiler/rustc_target/src/spec/bpfeb_unknown_none.rs @@ -3,10 +3,10 @@ use crate::{abi::Endian, spec::bpf_base}; pub fn target() -> Target { Target { - llvm_target: "bpfeb".to_string(), - data_layout: "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128".to_string(), + llvm_target: "bpfeb".into(), + data_layout: "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(), pointer_width: 64, - arch: "bpf".to_string(), + arch: "bpf".into(), options: bpf_base::opts(Endian::Big), } } diff --git a/compiler/rustc_target/src/spec/bpfel_unknown_none.rs b/compiler/rustc_target/src/spec/bpfel_unknown_none.rs index 6c9afdf35ae..7625e7b0e48 100644 --- a/compiler/rustc_target/src/spec/bpfel_unknown_none.rs +++ b/compiler/rustc_target/src/spec/bpfel_unknown_none.rs @@ -3,10 +3,10 @@ use crate::{abi::Endian, spec::bpf_base}; pub fn target() -> Target { Target { - llvm_target: "bpfel".to_string(), - data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".to_string(), + llvm_target: "bpfel".into(), + data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(), pointer_width: 64, - arch: "bpf".to_string(), + arch: "bpf".into(), options: bpf_base::opts(Endian::Little), } } diff --git a/compiler/rustc_target/src/spec/crt_objects.rs b/compiler/rustc_target/src/spec/crt_objects.rs index 2fc9ab29f92..51f392a64b1 100644 --- a/compiler/rustc_target/src/spec/crt_objects.rs +++ b/compiler/rustc_target/src/spec/crt_objects.rs @@ -42,16 +42,17 @@ use crate::spec::LinkOutputKind; use rustc_serialize::json::{Json, ToJson}; +use std::borrow::Cow; use std::collections::BTreeMap; use std::str::FromStr; -pub type CrtObjects = BTreeMap<LinkOutputKind, Vec<String>>; +pub type CrtObjects = BTreeMap<LinkOutputKind, Vec<Cow<'static, str>>>; -pub(super) fn new(obj_table: &[(LinkOutputKind, &[&str])]) -> CrtObjects { - obj_table.iter().map(|(z, k)| (*z, k.iter().map(|b| b.to_string()).collect())).collect() +pub(super) fn new(obj_table: &[(LinkOutputKind, &[&'static str])]) -> CrtObjects { + obj_table.iter().map(|(z, k)| (*z, k.iter().map(|b| (*b).into()).collect())).collect() } -pub(super) fn all(obj: &str) -> CrtObjects { +pub(super) fn all(obj: &'static str) -> CrtObjects { new(&[ (LinkOutputKind::DynamicNoPicExe, &[obj]), (LinkOutputKind::DynamicPicExe, &[obj]), diff --git a/compiler/rustc_target/src/spec/dragonfly_base.rs b/compiler/rustc_target/src/spec/dragonfly_base.rs index e13a640d4d2..b59322d07f5 100644 --- a/compiler/rustc_target/src/spec/dragonfly_base.rs +++ b/compiler/rustc_target/src/spec/dragonfly_base.rs @@ -1,11 +1,11 @@ -use crate::spec::{RelroLevel, TargetOptions}; +use crate::spec::{cvs, RelroLevel, TargetOptions}; pub fn opts() -> TargetOptions { TargetOptions { - os: "dragonfly".to_string(), + os: "dragonfly".into(), dynamic_linking: true, executables: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], has_rpath: true, position_independent_executables: true, relro_level: RelroLevel::Full, diff --git a/compiler/rustc_target/src/spec/freebsd_base.rs b/compiler/rustc_target/src/spec/freebsd_base.rs index f2ec6aae9f2..a7e0f9f7041 100644 --- a/compiler/rustc_target/src/spec/freebsd_base.rs +++ b/compiler/rustc_target/src/spec/freebsd_base.rs @@ -1,11 +1,11 @@ -use crate::spec::{RelroLevel, TargetOptions}; +use crate::spec::{cvs, RelroLevel, TargetOptions}; pub fn opts() -> TargetOptions { TargetOptions { - os: "freebsd".to_string(), + os: "freebsd".into(), dynamic_linking: true, executables: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], has_rpath: true, position_independent_executables: true, relro_level: RelroLevel::Full, diff --git a/compiler/rustc_target/src/spec/fuchsia_base.rs b/compiler/rustc_target/src/spec/fuchsia_base.rs index 4a7686ae1a1..04e30ff0c3e 100644 --- a/compiler/rustc_target/src/spec/fuchsia_base.rs +++ b/compiler/rustc_target/src/spec/fuchsia_base.rs @@ -1,31 +1,33 @@ -use crate::spec::{crt_objects, LinkArgs, LinkOutputKind, LinkerFlavor, LldFlavor, TargetOptions}; +use crate::spec::{ + crt_objects, cvs, LinkArgs, LinkOutputKind, LinkerFlavor, LldFlavor, TargetOptions, +}; pub fn opts() -> TargetOptions { let mut pre_link_args = LinkArgs::new(); pre_link_args.insert( LinkerFlavor::Lld(LldFlavor::Ld), vec![ - "--build-id".to_string(), - "--hash-style=gnu".to_string(), - "-z".to_string(), - "max-page-size=4096".to_string(), - "-z".to_string(), - "now".to_string(), - "-z".to_string(), - "rodynamic".to_string(), - "-z".to_string(), - "separate-loadable-segments".to_string(), - "--pack-dyn-relocs=relr".to_string(), + "--build-id".into(), + "--hash-style=gnu".into(), + "-z".into(), + "max-page-size=4096".into(), + "-z".into(), + "now".into(), + "-z".into(), + "rodynamic".into(), + "-z".into(), + "separate-loadable-segments".into(), + "--pack-dyn-relocs=relr".into(), ], ); TargetOptions { - os: "fuchsia".to_string(), + os: "fuchsia".into(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), dynamic_linking: true, executables: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], is_like_fuchsia: true, pre_link_args, pre_link_objects: crt_objects::new(&[ diff --git a/compiler/rustc_target/src/spec/haiku_base.rs b/compiler/rustc_target/src/spec/haiku_base.rs index 2b95523d6f7..61c05a2bdb6 100644 --- a/compiler/rustc_target/src/spec/haiku_base.rs +++ b/compiler/rustc_target/src/spec/haiku_base.rs @@ -1,11 +1,11 @@ -use crate::spec::{RelroLevel, TargetOptions}; +use crate::spec::{cvs, RelroLevel, TargetOptions}; pub fn opts() -> TargetOptions { TargetOptions { - os: "haiku".to_string(), + os: "haiku".into(), dynamic_linking: true, executables: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], relro_level: RelroLevel::Full, ..Default::default() } diff --git a/compiler/rustc_target/src/spec/hermit_base.rs b/compiler/rustc_target/src/spec/hermit_base.rs index b0b1d80ab37..7cbd42417e6 100644 --- a/compiler/rustc_target/src/spec/hermit_base.rs +++ b/compiler/rustc_target/src/spec/hermit_base.rs @@ -4,13 +4,13 @@ pub fn opts() -> TargetOptions { let mut pre_link_args = LinkArgs::new(); pre_link_args.insert( LinkerFlavor::Lld(LldFlavor::Ld), - vec!["--build-id".to_string(), "--hash-style=gnu".to_string(), "--Bstatic".to_string()], + vec!["--build-id".into(), "--hash-style=gnu".into(), "--Bstatic".into()], ); TargetOptions { - os: "hermit".to_string(), + os: "hermit".into(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), executables: true, has_thread_local: true, pre_link_args, diff --git a/compiler/rustc_target/src/spec/hexagon_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/hexagon_unknown_linux_musl.rs index 27d306c41b7..80cf09517cc 100644 --- a/compiler/rustc_target/src/spec/hexagon_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/hexagon_unknown_linux_musl.rs @@ -2,10 +2,10 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.cpu = "hexagonv60".to_string(); + base.cpu = "hexagonv60".into(); base.max_atomic_width = Some(32); // FIXME: HVX length defaults are per-CPU - base.features = "-small-data,+hvx-length128b".to_string(); + base.features = "-small-data,+hvx-length128b".into(); base.crt_static_default = false; base.has_rpath = true; @@ -16,7 +16,7 @@ pub fn target() -> Target { base.c_enum_min_bits = 8; Target { - llvm_target: "hexagon-unknown-linux-musl".to_string(), + llvm_target: "hexagon-unknown-linux-musl".into(), pointer_width: 32, data_layout: concat!( "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32", @@ -24,8 +24,8 @@ pub fn target() -> Target { ":32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048", ":2048:2048" ) - .to_string(), - arch: "hexagon".to_string(), + .into(), + arch: "hexagon".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/i386_apple_ios.rs b/compiler/rustc_target/src/spec/i386_apple_ios.rs index 4419dfe92f4..8b6266c5800 100644 --- a/compiler/rustc_target/src/spec/i386_apple_ios.rs +++ b/compiler/rustc_target/src/spec/i386_apple_ios.rs @@ -3,13 +3,15 @@ use crate::spec::{StackProbeType, Target, TargetOptions}; pub fn target() -> Target { let base = opts("ios", Arch::I386); + let llvm_target = super::apple_base::ios_sim_llvm_target("i386"); + Target { - llvm_target: super::apple_base::ios_sim_llvm_target("i386"), + llvm_target: llvm_target.into(), pointer_width: 32, data_layout: "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ f64:32:64-f80:128-n8:16:32-S128" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: TargetOptions { max_atomic_width: Some(64), // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved diff --git a/compiler/rustc_target/src/spec/i386_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/i386_unknown_linux_gnu.rs index f329b2d2c88..801a8893399 100644 --- a/compiler/rustc_target/src/spec/i386_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/i386_unknown_linux_gnu.rs @@ -2,7 +2,7 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::i686_unknown_linux_gnu::target(); - base.cpu = "i386".to_string(); - base.llvm_target = "i386-unknown-linux-gnu".to_string(); + base.cpu = "i386".into(); + base.llvm_target = "i386-unknown-linux-gnu".into(); base } diff --git a/compiler/rustc_target/src/spec/i486_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/i486_unknown_linux_gnu.rs index 5d96a558cb7..a11fbecc3c3 100644 --- a/compiler/rustc_target/src/spec/i486_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/i486_unknown_linux_gnu.rs @@ -2,7 +2,7 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::i686_unknown_linux_gnu::target(); - base.cpu = "i486".to_string(); - base.llvm_target = "i486-unknown-linux-gnu".to_string(); + base.cpu = "i486".into(); + base.llvm_target = "i486-unknown-linux-gnu".into(); base } diff --git a/compiler/rustc_target/src/spec/i586_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/i586_pc_windows_msvc.rs index 4a7779a6df0..befb0f89f3b 100644 --- a/compiler/rustc_target/src/spec/i586_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/i586_pc_windows_msvc.rs @@ -2,7 +2,7 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::i686_pc_windows_msvc::target(); - base.cpu = "pentium".to_string(); - base.llvm_target = "i586-pc-windows-msvc".to_string(); + base.cpu = "pentium".into(); + base.llvm_target = "i586-pc-windows-msvc".into(); base } diff --git a/compiler/rustc_target/src/spec/i586_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/i586_unknown_linux_gnu.rs index 7c92dda8a9d..b699a7af177 100644 --- a/compiler/rustc_target/src/spec/i586_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/i586_unknown_linux_gnu.rs @@ -2,7 +2,7 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::i686_unknown_linux_gnu::target(); - base.cpu = "pentium".to_string(); - base.llvm_target = "i586-unknown-linux-gnu".to_string(); + base.cpu = "pentium".into(); + base.llvm_target = "i586-unknown-linux-gnu".into(); base } diff --git a/compiler/rustc_target/src/spec/i586_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/i586_unknown_linux_musl.rs index 1fea02bbee8..55a26eb004a 100644 --- a/compiler/rustc_target/src/spec/i586_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/i586_unknown_linux_musl.rs @@ -2,7 +2,7 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::i686_unknown_linux_musl::target(); - base.cpu = "pentium".to_string(); - base.llvm_target = "i586-unknown-linux-musl".to_string(); + base.cpu = "pentium".into(); + base.llvm_target = "i586-unknown-linux-musl".into(); base } diff --git a/compiler/rustc_target/src/spec/i686_apple_darwin.rs b/compiler/rustc_target/src/spec/i686_apple_darwin.rs index f2635f0656d..ad716a6cd5a 100644 --- a/compiler/rustc_target/src/spec/i686_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/i686_apple_darwin.rs @@ -2,10 +2,10 @@ use crate::spec::{FramePointer, LinkerFlavor, StackProbeType, Target, TargetOpti pub fn target() -> Target { let mut base = super::apple_base::opts("macos"); - base.cpu = "yonah".to_string(); + base.cpu = "yonah".into(); base.max_atomic_width = Some(64); - base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m32".to_string()]); - base.link_env_remove.extend(super::apple_base::macos_link_env_remove()); + base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m32".into()]); + base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; base.frame_pointer = FramePointer::Always; @@ -17,12 +17,12 @@ pub fn target() -> Target { let llvm_target = super::apple_base::macos_llvm_target(&arch); Target { - llvm_target, + llvm_target: llvm_target.into(), pointer_width: 32, data_layout: "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ f64:32:64-f80:128-n8:16:32-S128" - .to_string(), - arch: "x86".to_string(), - options: TargetOptions { mcount: "\u{1}mcount".to_string(), ..base }, + .into(), + arch: "x86".into(), + options: TargetOptions { mcount: "\u{1}mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/i686_linux_android.rs b/compiler/rustc_target/src/spec/i686_linux_android.rs index e9ddaa37c26..bdaf5c99069 100644 --- a/compiler/rustc_target/src/spec/i686_linux_android.rs +++ b/compiler/rustc_target/src/spec/i686_linux_android.rs @@ -9,18 +9,18 @@ pub fn target() -> Target { base.max_atomic_width = Some(64); // https://developer.android.com/ndk/guides/abis.html#x86 - base.cpu = "pentiumpro".to_string(); - base.features = "+mmx,+sse,+sse2,+sse3,+ssse3".to_string(); + base.cpu = "pentiumpro".into(); + base.features = "+mmx,+sse,+sse2,+sse3,+ssse3".into(); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "i686-linux-android".to_string(), + llvm_target: "i686-linux-android".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ f64:32:64-f80:32-n8:16:32-S128" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: TargetOptions { supported_sanitizers: SanitizerSet::ADDRESS, ..base }, } } diff --git a/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs b/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs index 92c3a1554ac..554b0f34499 100644 --- a/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs +++ b/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs @@ -2,27 +2,26 @@ use crate::spec::{FramePointer, LinkerFlavor, LldFlavor, Target}; pub fn target() -> Target { let mut base = super::windows_gnu_base::opts(); - base.cpu = "pentium4".to_string(); - base.pre_link_args - .insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".to_string(), "i386pe".to_string()]); + base.cpu = "pentium4".into(); + base.pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".into(), "i386pe".into()]); base.max_atomic_width = Some(64); base.frame_pointer = FramePointer::Always; // Required for backtraces - base.linker = Some("i686-w64-mingw32-gcc".to_string()); + base.linker = Some("i686-w64-mingw32-gcc".into()); // Mark all dynamic libraries and executables as compatible with the larger 4GiB address // space available to x86 Windows binaries on x86_64. base.pre_link_args .entry(LinkerFlavor::Gcc) .or_default() - .push("-Wl,--large-address-aware".to_string()); + .push("-Wl,--large-address-aware".into()); Target { - llvm_target: "i686-pc-windows-gnu".to_string(), + llvm_target: "i686-pc-windows-gnu".into(), pointer_width: 32, data_layout: "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ i64:64-f80:32-n8:16:32-a:0:32-S32" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/i686_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/i686_pc_windows_msvc.rs index 174294895bf..fb0cb6a6943 100644 --- a/compiler/rustc_target/src/spec/i686_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/i686_pc_windows_msvc.rs @@ -2,31 +2,33 @@ use crate::spec::{LinkerFlavor, LldFlavor, Target}; pub fn target() -> Target { let mut base = super::windows_msvc_base::opts(); - base.cpu = "pentium4".to_string(); + base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); let pre_link_args_msvc = vec![ // Mark all dynamic libraries and executables as compatible with the larger 4GiB address // space available to x86 Windows binaries on x86_64. - "/LARGEADDRESSAWARE".to_string(), + "/LARGEADDRESSAWARE".into(), // Ensure the linker will only produce an image if it can also produce a table of // the image's safe exception handlers. // https://docs.microsoft.com/en-us/cpp/build/reference/safeseh-image-has-safe-exception-handlers - "/SAFESEH".to_string(), + "/SAFESEH".into(), ]; base.pre_link_args.entry(LinkerFlavor::Msvc).or_default().extend(pre_link_args_msvc.clone()); base.pre_link_args .entry(LinkerFlavor::Lld(LldFlavor::Link)) .or_default() .extend(pre_link_args_msvc); + // Workaround for #95429 + base.has_thread_local = false; Target { - llvm_target: "i686-pc-windows-msvc".to_string(), + llvm_target: "i686-pc-windows-msvc".into(), pointer_width: 32, data_layout: "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ i64:64-f80:128-n8:16:32-a:0:32-S32" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/i686_unknown_freebsd.rs b/compiler/rustc_target/src/spec/i686_unknown_freebsd.rs index d8e37e72371..9f0cb04c65d 100644 --- a/compiler/rustc_target/src/spec/i686_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/i686_unknown_freebsd.rs @@ -2,21 +2,21 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::freebsd_base::opts(); - base.cpu = "pentium4".to_string(); + base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); let pre_link_args = base.pre_link_args.entry(LinkerFlavor::Gcc).or_default(); - pre_link_args.push("-m32".to_string()); - pre_link_args.push("-Wl,-znotext".to_string()); + pre_link_args.push("-m32".into()); + pre_link_args.push("-Wl,-znotext".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "i686-unknown-freebsd".to_string(), + llvm_target: "i686-unknown-freebsd".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ f64:32:64-f80:32-n8:16:32-S128" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/i686_unknown_haiku.rs b/compiler/rustc_target/src/spec/i686_unknown_haiku.rs index e4c01db5439..d1af163f1cf 100644 --- a/compiler/rustc_target/src/spec/i686_unknown_haiku.rs +++ b/compiler/rustc_target/src/spec/i686_unknown_haiku.rs @@ -2,19 +2,19 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::haiku_base::opts(); - base.cpu = "pentium4".to_string(); + base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); - base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m32".to_string()]); + base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m32".into()]); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "i686-unknown-haiku".to_string(), + llvm_target: "i686-unknown-haiku".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ f64:32:64-f80:32-n8:16:32-S128" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs index 165505ee731..0998c618f31 100644 --- a/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs @@ -2,19 +2,19 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); - base.cpu = "pentium4".to_string(); + base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "i686-unknown-linux-gnu".to_string(), + llvm_target: "i686-unknown-linux-gnu".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ f64:32:64-f80:32-n8:16:32-S128" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/i686_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/i686_unknown_linux_musl.rs index d95cb6a82d5..a697f292da0 100644 --- a/compiler/rustc_target/src/spec/i686_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/i686_unknown_linux_musl.rs @@ -2,10 +2,10 @@ use crate::spec::{FramePointer, LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.cpu = "pentium4".to_string(); + base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-Wl,-melf_i386".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".into()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-Wl,-melf_i386".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; @@ -24,12 +24,12 @@ pub fn target() -> Target { base.frame_pointer = FramePointer::Always; Target { - llvm_target: "i686-unknown-linux-musl".to_string(), + llvm_target: "i686-unknown-linux-musl".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ f64:32:64-f80:32-n8:16:32-S128" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/i686_unknown_netbsd.rs b/compiler/rustc_target/src/spec/i686_unknown_netbsd.rs index 989e3fb1adf..2807d328205 100644 --- a/compiler/rustc_target/src/spec/i686_unknown_netbsd.rs +++ b/compiler/rustc_target/src/spec/i686_unknown_netbsd.rs @@ -2,19 +2,19 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::netbsd_base::opts(); - base.cpu = "pentium4".to_string(); + base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "i686-unknown-netbsdelf".to_string(), + llvm_target: "i686-unknown-netbsdelf".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ f64:32:64-f80:32-n8:16:32-S128" - .to_string(), - arch: "x86".to_string(), - options: TargetOptions { mcount: "__mcount".to_string(), ..base }, + .into(), + arch: "x86".into(), + options: TargetOptions { mcount: "__mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/i686_unknown_openbsd.rs b/compiler/rustc_target/src/spec/i686_unknown_openbsd.rs index 7ff79961375..78462eb63b8 100644 --- a/compiler/rustc_target/src/spec/i686_unknown_openbsd.rs +++ b/compiler/rustc_target/src/spec/i686_unknown_openbsd.rs @@ -2,20 +2,20 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::openbsd_base::opts(); - base.cpu = "pentium4".to_string(); + base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-fuse-ld=lld".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".into()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-fuse-ld=lld".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "i686-unknown-openbsd".to_string(), + llvm_target: "i686-unknown-openbsd".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ f64:32:64-f80:32-n8:16:32-S128" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/i686_unknown_uefi.rs b/compiler/rustc_target/src/spec/i686_unknown_uefi.rs index cc3c31538a4..a2e42c5e61d 100644 --- a/compiler/rustc_target/src/spec/i686_unknown_uefi.rs +++ b/compiler/rustc_target/src/spec/i686_unknown_uefi.rs @@ -9,7 +9,7 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::uefi_msvc_base::opts(); - base.cpu = "pentium4".to_string(); + base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); // We disable MMX and SSE for now, even though UEFI allows using them. Problem is, you have to @@ -21,7 +21,7 @@ pub fn target() -> Target { // far. // If you initialize FP units yourself, you can override these flags with custom linker // arguments, thus giving you access to full MMX/SSE acceleration. - base.features = "-mmx,-sse,+soft-float".to_string(); + base.features = "-mmx,-sse,+soft-float".into(); // Use -GNU here, because of the reason below: // Background and Problem: @@ -77,12 +77,12 @@ pub fn target() -> Target { // compiler-builtins. After compiler-builtins implements all required intrinsics, we may // remove -gnu and use the default one. Target { - llvm_target: "i686-unknown-windows-gnu".to_string(), + llvm_target: "i686-unknown-windows-gnu".into(), pointer_width: 32, data_layout: "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ i64:64-f80:32-n8:16:32-a:0:32-S32" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } diff --git a/compiler/rustc_target/src/spec/i686_uwp_windows_gnu.rs b/compiler/rustc_target/src/spec/i686_uwp_windows_gnu.rs index 27a0ac585e3..75f7a2209c8 100644 --- a/compiler/rustc_target/src/spec/i686_uwp_windows_gnu.rs +++ b/compiler/rustc_target/src/spec/i686_uwp_windows_gnu.rs @@ -2,9 +2,8 @@ use crate::spec::{FramePointer, LinkerFlavor, LldFlavor, Target}; pub fn target() -> Target { let mut base = super::windows_uwp_gnu_base::opts(); - base.cpu = "pentium4".to_string(); - base.pre_link_args - .insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".to_string(), "i386pe".to_string()]); + base.cpu = "pentium4".into(); + base.pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".into(), "i386pe".into()]); base.max_atomic_width = Some(64); base.frame_pointer = FramePointer::Always; // Required for backtraces @@ -13,15 +12,15 @@ pub fn target() -> Target { base.pre_link_args .entry(LinkerFlavor::Gcc) .or_default() - .push("-Wl,--large-address-aware".to_string()); + .push("-Wl,--large-address-aware".into()); Target { - llvm_target: "i686-pc-windows-gnu".to_string(), + llvm_target: "i686-pc-windows-gnu".into(), pointer_width: 32, data_layout: "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ i64:64-f80:32-n8:16:32-a:0:32-S32" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/i686_uwp_windows_msvc.rs b/compiler/rustc_target/src/spec/i686_uwp_windows_msvc.rs index e2f65e7a7c9..4c657fe908a 100644 --- a/compiler/rustc_target/src/spec/i686_uwp_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/i686_uwp_windows_msvc.rs @@ -2,16 +2,16 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::windows_uwp_msvc_base::opts(); - base.cpu = "pentium4".to_string(); + base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); Target { - llvm_target: "i686-pc-windows-msvc".to_string(), + llvm_target: "i686-pc-windows-msvc".into(), pointer_width: 32, data_layout: "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ i64:64-f80:128-n8:16:32-a:0:32-S32" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/i686_wrs_vxworks.rs b/compiler/rustc_target/src/spec/i686_wrs_vxworks.rs index c7963dbde77..d51ed7c1f7a 100644 --- a/compiler/rustc_target/src/spec/i686_wrs_vxworks.rs +++ b/compiler/rustc_target/src/spec/i686_wrs_vxworks.rs @@ -2,19 +2,19 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::vxworks_base::opts(); - base.cpu = "pentium4".to_string(); + base.cpu = "pentium4".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "i686-unknown-linux-gnu".to_string(), + llvm_target: "i686-unknown-linux-gnu".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ f64:32:64-f80:32-n8:16:32-S128" - .to_string(), - arch: "x86".to_string(), + .into(), + arch: "x86".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/illumos_base.rs b/compiler/rustc_target/src/spec/illumos_base.rs index aeb40f7712e..ef8f90a4da8 100644 --- a/compiler/rustc_target/src/spec/illumos_base.rs +++ b/compiler/rustc_target/src/spec/illumos_base.rs @@ -1,5 +1,4 @@ -use crate::spec::{FramePointer, LinkArgs, LinkerFlavor, TargetOptions}; -use std::default::Default; +use crate::spec::{cvs, FramePointer, LinkArgs, LinkerFlavor, TargetOptions}; pub fn opts() -> TargetOptions { let mut late_link_args = LinkArgs::new(); @@ -16,22 +15,22 @@ pub fn opts() -> TargetOptions { // FIXME: This should be replaced by a more complete and generic // mechanism for controlling the order of library arguments passed // to the linker. - "-lc".to_string(), + "-lc".into(), // LLVM will insert calls to the stack protector functions // "__stack_chk_fail" and "__stack_chk_guard" into code in native // object files. Some platforms include these symbols directly in // libc, but at least historically these have been provided in // libssp.so on illumos and Solaris systems. - "-lssp".to_string(), + "-lssp".into(), ], ); TargetOptions { - os: "illumos".to_string(), + os: "illumos".into(), dynamic_linking: true, executables: true, has_rpath: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], is_like_solaris: true, linker_is_gnu: false, limit_rdylib_exports: false, // Linker doesn't support this @@ -54,8 +53,8 @@ pub fn opts() -> TargetOptions { // // We want XPG6 behavior from libc and libm. See standards(5) //pre_link_objects_exe: vec![ - // "/usr/lib/amd64/values-Xc.o".to_string(), - // "/usr/lib/amd64/values-xpg6.o".to_string(), + // "/usr/lib/amd64/values-Xc.o".into(), + // "/usr/lib/amd64/values-xpg6.o".into(), //], ..Default::default() } diff --git a/compiler/rustc_target/src/spec/l4re_base.rs b/compiler/rustc_target/src/spec/l4re_base.rs index 9e7973f63a9..7a051532f82 100644 --- a/compiler/rustc_target/src/spec/l4re_base.rs +++ b/compiler/rustc_target/src/spec/l4re_base.rs @@ -1,16 +1,15 @@ -use crate::spec::{LinkerFlavor, PanicStrategy, TargetOptions}; -use std::default::Default; +use crate::spec::{cvs, LinkerFlavor, PanicStrategy, TargetOptions}; pub fn opts() -> TargetOptions { TargetOptions { - os: "l4re".to_string(), - env: "uclibc".to_string(), + os: "l4re".into(), + env: "uclibc".into(), linker_flavor: LinkerFlavor::L4Bender, executables: true, panic_strategy: PanicStrategy::Abort, - linker: Some("l4-bender".to_string()), + linker: Some("l4-bender".into()), linker_is_gnu: false, - families: vec!["unix".to_string()], + families: cvs!["unix"], ..Default::default() } } diff --git a/compiler/rustc_target/src/spec/linux_base.rs b/compiler/rustc_target/src/spec/linux_base.rs index e53d465e20d..0f79ada0d93 100644 --- a/compiler/rustc_target/src/spec/linux_base.rs +++ b/compiler/rustc_target/src/spec/linux_base.rs @@ -1,11 +1,11 @@ -use crate::spec::{RelroLevel, TargetOptions}; +use crate::spec::{cvs, RelroLevel, TargetOptions}; pub fn opts() -> TargetOptions { TargetOptions { - os: "linux".to_string(), + os: "linux".into(), dynamic_linking: true, executables: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], has_rpath: true, position_independent_executables: true, relro_level: RelroLevel::Full, diff --git a/compiler/rustc_target/src/spec/linux_gnu_base.rs b/compiler/rustc_target/src/spec/linux_gnu_base.rs index 3d940ceaf02..8d6b3f18512 100644 --- a/compiler/rustc_target/src/spec/linux_gnu_base.rs +++ b/compiler/rustc_target/src/spec/linux_gnu_base.rs @@ -1,5 +1,5 @@ use crate::spec::TargetOptions; pub fn opts() -> TargetOptions { - TargetOptions { env: "gnu".to_string(), ..super::linux_base::opts() } + TargetOptions { env: "gnu".into(), ..super::linux_base::opts() } } diff --git a/compiler/rustc_target/src/spec/linux_kernel_base.rs b/compiler/rustc_target/src/spec/linux_kernel_base.rs index a332e3b847a..0f5d85205f8 100644 --- a/compiler/rustc_target/src/spec/linux_kernel_base.rs +++ b/compiler/rustc_target/src/spec/linux_kernel_base.rs @@ -3,7 +3,7 @@ use crate::spec::{FramePointer, PanicStrategy, RelocModel, RelroLevel, StackProb pub fn opts() -> TargetOptions { TargetOptions { - env: "gnu".to_string(), + env: "gnu".into(), disable_redzone: true, panic_strategy: PanicStrategy::Abort, // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved diff --git a/compiler/rustc_target/src/spec/linux_musl_base.rs b/compiler/rustc_target/src/spec/linux_musl_base.rs index 5038a967d0a..207a87ab039 100644 --- a/compiler/rustc_target/src/spec/linux_musl_base.rs +++ b/compiler/rustc_target/src/spec/linux_musl_base.rs @@ -4,7 +4,7 @@ use crate::spec::TargetOptions; pub fn opts() -> TargetOptions { let mut base = super::linux_base::opts(); - base.env = "musl".to_string(); + base.env = "musl".into(); base.pre_link_objects_fallback = crt_objects::pre_musl_fallback(); base.post_link_objects_fallback = crt_objects::post_musl_fallback(); base.crt_objects_fallback = Some(CrtObjectsFallback::Musl); diff --git a/compiler/rustc_target/src/spec/linux_uclibc_base.rs b/compiler/rustc_target/src/spec/linux_uclibc_base.rs index ef6d50656e4..4ba480ffecf 100644 --- a/compiler/rustc_target/src/spec/linux_uclibc_base.rs +++ b/compiler/rustc_target/src/spec/linux_uclibc_base.rs @@ -1,5 +1,5 @@ use crate::spec::TargetOptions; pub fn opts() -> TargetOptions { - TargetOptions { env: "uclibc".to_string(), ..super::linux_base::opts() } + TargetOptions { env: "uclibc".into(), ..super::linux_base::opts() } } diff --git a/compiler/rustc_target/src/spec/m68k_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/m68k_unknown_linux_gnu.rs index 5671b59c63f..ebd74012dcd 100644 --- a/compiler/rustc_target/src/spec/m68k_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/m68k_unknown_linux_gnu.rs @@ -6,10 +6,10 @@ pub fn target() -> Target { base.max_atomic_width = Some(32); Target { - llvm_target: "m68k-unknown-linux-gnu".to_string(), + llvm_target: "m68k-unknown-linux-gnu".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:16:32-i8:8:8-i16:16:16-i32:16:32-n8:16:32-a:0:16-S16".to_string(), - arch: "m68k".to_string(), - options: TargetOptions { endian: Endian::Big, mcount: "_mcount".to_string(), ..base }, + data_layout: "E-m:e-p:32:16:32-i8:8:8-i16:16:16-i32:16:32-n8:16:32-a:0:16-S16".into(), + arch: "m68k".into(), + options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs b/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs index 5991cd8bfa9..3c6ef52c6cd 100644 --- a/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs +++ b/compiler/rustc_target/src/spec/mips64_openwrt_linux_musl.rs @@ -5,21 +5,21 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.cpu = "mips64r2".to_string(); - base.features = "+mips64r2,+soft-float".to_string(); + base.cpu = "mips64r2".into(); + base.features = "+mips64r2,+soft-float".into(); base.max_atomic_width = Some(64); base.crt_static_default = false; Target { // LLVM doesn't recognize "muslabi64" yet. - llvm_target: "mips64-unknown-linux-musl".to_string(), + llvm_target: "mips64-unknown-linux-musl".into(), pointer_width: 64, - data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(), - arch: "mips64".to_string(), + data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".into(), + arch: "mips64".into(), options: TargetOptions { - abi: "abi64".to_string(), + abi: "abi64".into(), endian: Endian::Big, - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..base }, } diff --git a/compiler/rustc_target/src/spec/mips64_unknown_linux_gnuabi64.rs b/compiler/rustc_target/src/spec/mips64_unknown_linux_gnuabi64.rs index 161a27ab689..fc5dbd114e4 100644 --- a/compiler/rustc_target/src/spec/mips64_unknown_linux_gnuabi64.rs +++ b/compiler/rustc_target/src/spec/mips64_unknown_linux_gnuabi64.rs @@ -3,18 +3,18 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mips64-unknown-linux-gnuabi64".to_string(), + llvm_target: "mips64-unknown-linux-gnuabi64".into(), pointer_width: 64, - data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(), - arch: "mips64".to_string(), + data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".into(), + arch: "mips64".into(), options: TargetOptions { - abi: "abi64".to_string(), + abi: "abi64".into(), endian: Endian::Big, // NOTE(mips64r2) matches C toolchain - cpu: "mips64r2".to_string(), - features: "+mips64r2".to_string(), + cpu: "mips64r2".into(), + features: "+mips64r2".into(), max_atomic_width: Some(64), - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/mips64_unknown_linux_muslabi64.rs b/compiler/rustc_target/src/spec/mips64_unknown_linux_muslabi64.rs index a8984645698..465e97a026c 100644 --- a/compiler/rustc_target/src/spec/mips64_unknown_linux_muslabi64.rs +++ b/compiler/rustc_target/src/spec/mips64_unknown_linux_muslabi64.rs @@ -3,19 +3,19 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.cpu = "mips64r2".to_string(); - base.features = "+mips64r2".to_string(); + base.cpu = "mips64r2".into(); + base.features = "+mips64r2".into(); base.max_atomic_width = Some(64); Target { // LLVM doesn't recognize "muslabi64" yet. - llvm_target: "mips64-unknown-linux-musl".to_string(), + llvm_target: "mips64-unknown-linux-musl".into(), pointer_width: 64, - data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(), - arch: "mips64".to_string(), + data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".into(), + arch: "mips64".into(), options: TargetOptions { - abi: "abi64".to_string(), + abi: "abi64".into(), endian: Endian::Big, - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..base }, } diff --git a/compiler/rustc_target/src/spec/mips64el_unknown_linux_gnuabi64.rs b/compiler/rustc_target/src/spec/mips64el_unknown_linux_gnuabi64.rs index 2f58560d450..e0d5f6f57f1 100644 --- a/compiler/rustc_target/src/spec/mips64el_unknown_linux_gnuabi64.rs +++ b/compiler/rustc_target/src/spec/mips64el_unknown_linux_gnuabi64.rs @@ -2,17 +2,17 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mips64el-unknown-linux-gnuabi64".to_string(), + llvm_target: "mips64el-unknown-linux-gnuabi64".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(), - arch: "mips64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".into(), + arch: "mips64".into(), options: TargetOptions { - abi: "abi64".to_string(), + abi: "abi64".into(), // NOTE(mips64r2) matches C toolchain - cpu: "mips64r2".to_string(), - features: "+mips64r2".to_string(), + cpu: "mips64r2".into(), + features: "+mips64r2".into(), max_atomic_width: Some(64), - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/mips64el_unknown_linux_muslabi64.rs b/compiler/rustc_target/src/spec/mips64el_unknown_linux_muslabi64.rs index 01c34bc3992..75575eb7eeb 100644 --- a/compiler/rustc_target/src/spec/mips64el_unknown_linux_muslabi64.rs +++ b/compiler/rustc_target/src/spec/mips64el_unknown_linux_muslabi64.rs @@ -2,15 +2,15 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.cpu = "mips64r2".to_string(); - base.features = "+mips64r2".to_string(); + base.cpu = "mips64r2".into(); + base.features = "+mips64r2".into(); base.max_atomic_width = Some(64); Target { // LLVM doesn't recognize "muslabi64" yet. - llvm_target: "mips64el-unknown-linux-musl".to_string(), + llvm_target: "mips64el-unknown-linux-musl".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(), - arch: "mips64".to_string(), - options: TargetOptions { abi: "abi64".to_string(), mcount: "_mcount".to_string(), ..base }, + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".into(), + arch: "mips64".into(), + options: TargetOptions { abi: "abi64".into(), mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/mips_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/mips_unknown_linux_gnu.rs index b41b28cbc87..8df8b0b4c2c 100644 --- a/compiler/rustc_target/src/spec/mips_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/mips_unknown_linux_gnu.rs @@ -3,16 +3,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mips-unknown-linux-gnu".to_string(), + llvm_target: "mips-unknown-linux-gnu".into(), pointer_width: 32, - data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), - arch: "mips".to_string(), + data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + arch: "mips".into(), options: TargetOptions { endian: Endian::Big, - cpu: "mips32r2".to_string(), - features: "+mips32r2,+fpxx,+nooddspreg".to_string(), + cpu: "mips32r2".into(), + features: "+mips32r2,+fpxx,+nooddspreg".into(), max_atomic_width: Some(32), - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/mips_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/mips_unknown_linux_musl.rs index 3713af43d73..c2846313a9e 100644 --- a/compiler/rustc_target/src/spec/mips_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/mips_unknown_linux_musl.rs @@ -3,15 +3,15 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.cpu = "mips32r2".to_string(); - base.features = "+mips32r2,+soft-float".to_string(); + base.cpu = "mips32r2".into(); + base.features = "+mips32r2,+soft-float".into(); base.max_atomic_width = Some(32); base.crt_static_default = false; Target { - llvm_target: "mips-unknown-linux-musl".to_string(), + llvm_target: "mips-unknown-linux-musl".into(), pointer_width: 32, - data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), - arch: "mips".to_string(), - options: TargetOptions { endian: Endian::Big, mcount: "_mcount".to_string(), ..base }, + data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + arch: "mips".into(), + options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/mips_unknown_linux_uclibc.rs b/compiler/rustc_target/src/spec/mips_unknown_linux_uclibc.rs index 042ec9140fa..c59bb5fdd22 100644 --- a/compiler/rustc_target/src/spec/mips_unknown_linux_uclibc.rs +++ b/compiler/rustc_target/src/spec/mips_unknown_linux_uclibc.rs @@ -3,16 +3,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mips-unknown-linux-uclibc".to_string(), + llvm_target: "mips-unknown-linux-uclibc".into(), pointer_width: 32, - data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), - arch: "mips".to_string(), + data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + arch: "mips".into(), options: TargetOptions { endian: Endian::Big, - cpu: "mips32r2".to_string(), - features: "+mips32r2,+soft-float".to_string(), + cpu: "mips32r2".into(), + features: "+mips32r2,+soft-float".into(), max_atomic_width: Some(32), - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..super::linux_uclibc_base::opts() }, diff --git a/compiler/rustc_target/src/spec/mipsel_sony_psp.rs b/compiler/rustc_target/src/spec/mipsel_sony_psp.rs index dc14e4bdf94..45966b97d6a 100644 --- a/compiler/rustc_target/src/spec/mipsel_sony_psp.rs +++ b/compiler/rustc_target/src/spec/mipsel_sony_psp.rs @@ -1,35 +1,35 @@ +use crate::spec::{cvs, Target, TargetOptions}; use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, RelocModel}; -use crate::spec::{Target, TargetOptions}; // The PSP has custom linker requirements. const LINKER_SCRIPT: &str = include_str!("./mipsel_sony_psp_linker_script.ld"); pub fn target() -> Target { let mut pre_link_args = LinkArgs::new(); - pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["--emit-relocs".to_string()]); + pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["--emit-relocs".into()]); Target { - llvm_target: "mipsel-sony-psp".to_string(), + llvm_target: "mipsel-sony-psp".into(), pointer_width: 32, - data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), - arch: "mips".to_string(), + data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + arch: "mips".into(), options: TargetOptions { - os: "psp".to_string(), - vendor: "sony".to_string(), + os: "psp".into(), + vendor: "sony".into(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - cpu: "mips2".to_string(), + cpu: "mips2".into(), executables: true, - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), relocation_model: RelocModel::Static, // PSP FPU only supports single precision floats. - features: "+single-float".to_string(), + features: "+single-float".into(), // PSP does not support trap-on-condition instructions. - llvm_args: vec!["-mno-check-zero-division".to_string()], + llvm_args: cvs!["-mno-check-zero-division"], pre_link_args, - link_script: Some(LINKER_SCRIPT.to_string()), + link_script: Some(LINKER_SCRIPT.into()), ..Default::default() }, } diff --git a/compiler/rustc_target/src/spec/mipsel_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/mipsel_unknown_linux_gnu.rs index 9cb2a13c7d4..01346e71a92 100644 --- a/compiler/rustc_target/src/spec/mipsel_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/mipsel_unknown_linux_gnu.rs @@ -2,16 +2,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mipsel-unknown-linux-gnu".to_string(), + llvm_target: "mipsel-unknown-linux-gnu".into(), pointer_width: 32, - data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), - arch: "mips".to_string(), + data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + arch: "mips".into(), options: TargetOptions { - cpu: "mips32r2".to_string(), - features: "+mips32r2,+fpxx,+nooddspreg".to_string(), + cpu: "mips32r2".into(), + features: "+mips32r2,+fpxx,+nooddspreg".into(), max_atomic_width: Some(32), - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/mipsel_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/mipsel_unknown_linux_musl.rs index 3374cdd4485..0e8f1a2c8e0 100644 --- a/compiler/rustc_target/src/spec/mipsel_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/mipsel_unknown_linux_musl.rs @@ -2,15 +2,15 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.cpu = "mips32r2".to_string(); - base.features = "+mips32r2,+soft-float".to_string(); + base.cpu = "mips32r2".into(); + base.features = "+mips32r2,+soft-float".into(); base.max_atomic_width = Some(32); base.crt_static_default = false; Target { - llvm_target: "mipsel-unknown-linux-musl".to_string(), + llvm_target: "mipsel-unknown-linux-musl".into(), pointer_width: 32, - data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), - arch: "mips".to_string(), - options: TargetOptions { mcount: "_mcount".to_string(), ..base }, + data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + arch: "mips".into(), + options: TargetOptions { mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/mipsel_unknown_linux_uclibc.rs b/compiler/rustc_target/src/spec/mipsel_unknown_linux_uclibc.rs index 0831eb7a0a7..8342074586b 100644 --- a/compiler/rustc_target/src/spec/mipsel_unknown_linux_uclibc.rs +++ b/compiler/rustc_target/src/spec/mipsel_unknown_linux_uclibc.rs @@ -2,16 +2,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mipsel-unknown-linux-uclibc".to_string(), + llvm_target: "mipsel-unknown-linux-uclibc".into(), pointer_width: 32, - data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), - arch: "mips".to_string(), + data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + arch: "mips".into(), options: TargetOptions { - cpu: "mips32r2".to_string(), - features: "+mips32r2,+soft-float".to_string(), + cpu: "mips32r2".into(), + features: "+mips32r2,+soft-float".into(), max_atomic_width: Some(32), - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..super::linux_uclibc_base::opts() }, diff --git a/compiler/rustc_target/src/spec/mipsel_unknown_none.rs b/compiler/rustc_target/src/spec/mipsel_unknown_none.rs index 5955baa31db..736af15cf44 100644 --- a/compiler/rustc_target/src/spec/mipsel_unknown_none.rs +++ b/compiler/rustc_target/src/spec/mipsel_unknown_none.rs @@ -7,18 +7,18 @@ use crate::spec::{PanicStrategy, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mipsel-unknown-none".to_string(), + llvm_target: "mipsel-unknown-none".into(), pointer_width: 32, - data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), - arch: "mips".to_string(), + data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + arch: "mips".into(), options: TargetOptions { linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - cpu: "mips32r2".to_string(), - features: "+mips32r2,+soft-float,+noabicalls".to_string(), + cpu: "mips32r2".into(), + features: "+mips32r2,+soft-float,+noabicalls".into(), max_atomic_width: Some(32), executables: true, - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), panic_strategy: PanicStrategy::Abort, relocation_model: RelocModel::Static, emit_debug_gdb_scripts: false, diff --git a/compiler/rustc_target/src/spec/mipsisa32r6_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/mipsisa32r6_unknown_linux_gnu.rs index a81c90fe0cd..1e066b271e2 100644 --- a/compiler/rustc_target/src/spec/mipsisa32r6_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/mipsisa32r6_unknown_linux_gnu.rs @@ -3,16 +3,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mipsisa32r6-unknown-linux-gnu".to_string(), + llvm_target: "mipsisa32r6-unknown-linux-gnu".into(), pointer_width: 32, - data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), - arch: "mips".to_string(), + data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + arch: "mips".into(), options: TargetOptions { endian: Endian::Big, - cpu: "mips32r6".to_string(), - features: "+mips32r6".to_string(), + cpu: "mips32r6".into(), + features: "+mips32r6".into(), max_atomic_width: Some(32), - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/mipsisa32r6el_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/mipsisa32r6el_unknown_linux_gnu.rs index 06a5f40d69b..4785929c100 100644 --- a/compiler/rustc_target/src/spec/mipsisa32r6el_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/mipsisa32r6el_unknown_linux_gnu.rs @@ -2,16 +2,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mipsisa32r6el-unknown-linux-gnu".to_string(), + llvm_target: "mipsisa32r6el-unknown-linux-gnu".into(), pointer_width: 32, - data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), - arch: "mips".to_string(), + data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(), + arch: "mips".into(), options: TargetOptions { - cpu: "mips32r6".to_string(), - features: "+mips32r6".to_string(), + cpu: "mips32r6".into(), + features: "+mips32r6".into(), max_atomic_width: Some(32), - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/mipsisa64r6_unknown_linux_gnuabi64.rs b/compiler/rustc_target/src/spec/mipsisa64r6_unknown_linux_gnuabi64.rs index 80a155a4865..766ac768064 100644 --- a/compiler/rustc_target/src/spec/mipsisa64r6_unknown_linux_gnuabi64.rs +++ b/compiler/rustc_target/src/spec/mipsisa64r6_unknown_linux_gnuabi64.rs @@ -3,18 +3,18 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mipsisa64r6-unknown-linux-gnuabi64".to_string(), + llvm_target: "mipsisa64r6-unknown-linux-gnuabi64".into(), pointer_width: 64, - data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(), - arch: "mips64".to_string(), + data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".into(), + arch: "mips64".into(), options: TargetOptions { - abi: "abi64".to_string(), + abi: "abi64".into(), endian: Endian::Big, // NOTE(mips64r6) matches C toolchain - cpu: "mips64r6".to_string(), - features: "+mips64r6".to_string(), + cpu: "mips64r6".into(), + features: "+mips64r6".into(), max_atomic_width: Some(64), - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/mipsisa64r6el_unknown_linux_gnuabi64.rs b/compiler/rustc_target/src/spec/mipsisa64r6el_unknown_linux_gnuabi64.rs index 58f9862715f..d2b07c654dc 100644 --- a/compiler/rustc_target/src/spec/mipsisa64r6el_unknown_linux_gnuabi64.rs +++ b/compiler/rustc_target/src/spec/mipsisa64r6el_unknown_linux_gnuabi64.rs @@ -2,17 +2,17 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "mipsisa64r6el-unknown-linux-gnuabi64".to_string(), + llvm_target: "mipsisa64r6el-unknown-linux-gnuabi64".into(), pointer_width: 64, - data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(), - arch: "mips64".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".into(), + arch: "mips64".into(), options: TargetOptions { - abi: "abi64".to_string(), + abi: "abi64".into(), // NOTE(mips64r6) matches C toolchain - cpu: "mips64r6".to_string(), - features: "+mips64r6".to_string(), + cpu: "mips64r6".into(), + features: "+mips64r6".into(), max_atomic_width: Some(64), - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 4953dafe89b..bd5b712c143 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -40,6 +40,7 @@ use crate::spec::crt_objects::{CrtObjects, CrtObjectsFallback}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_serialize::json::{Json, ToJson}; use rustc_span::symbol::{sym, Symbol}; +use std::borrow::Cow; use std::collections::BTreeMap; use std::convert::TryFrom; use std::iter::FromIterator; @@ -458,7 +459,7 @@ impl fmt::Display for LinkOutputKind { } } -pub type LinkArgs = BTreeMap<LinkerFlavor, Vec<String>>; +pub type LinkArgs = BTreeMap<LinkerFlavor, Vec<StaticCow<str>>>; #[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)] pub enum SplitDebuginfo { @@ -1026,6 +1027,22 @@ supported_targets! { ("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl), } +/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]> +macro_rules! cvs { + () => { + ::std::borrow::Cow::Borrowed(&[]) + }; + ($($x:expr),+ $(,)?) => { + ::std::borrow::Cow::Borrowed(&[ + $( + ::std::borrow::Cow::Borrowed($x), + )* + ]) + }; +} + +pub(crate) use cvs; + /// Warnings encountered when parsing the target `json`. /// /// Includes fields that weren't recognized and fields that don't have the expected type. @@ -1064,14 +1081,14 @@ impl TargetWarnings { #[derive(PartialEq, Clone, Debug)] pub struct Target { /// Target triple to pass to LLVM. - pub llvm_target: String, + pub llvm_target: StaticCow<str>, /// Number of bits in a pointer. Influences the `target_pointer_width` `cfg` variable. pub pointer_width: u32, /// Architecture to use for ABI considerations. Valid options include: "x86", /// "x86_64", "arm", "aarch64", "mips", "powerpc", "powerpc64", and others. - pub arch: String, + pub arch: StaticCow<str>, /// [Data layout](https://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM. - pub data_layout: String, + pub data_layout: StaticCow<str>, /// Optional settings with defaults. pub options: TargetOptions, } @@ -1087,6 +1104,8 @@ impl HasTargetSpec for Target { } } +type StaticCow<T> = Cow<'static, T>; + /// Optional aspects of a target specification. /// /// This has an implementation of `Default`, see each field for what the default is. In general, @@ -1103,25 +1122,25 @@ pub struct TargetOptions { /// Used as the `target_endian` `cfg` variable. Defaults to little endian. pub endian: Endian, /// Width of c_int type. Defaults to "32". - pub c_int_width: String, + pub c_int_width: StaticCow<str>, /// OS name to use for conditional compilation (`target_os`). Defaults to "none". /// "none" implies a bare metal target without `std` library. /// A couple of targets having `std` also use "unknown" as an `os` value, /// but they are exceptions. - pub os: String, + pub os: StaticCow<str>, /// Environment name to use for conditional compilation (`target_env`). Defaults to "". - pub env: String, + pub env: StaticCow<str>, /// ABI name to distinguish multiple ABIs on the same OS and architecture. For instance, `"eabi"` /// or `"eabihf"`. Defaults to "". - pub abi: String, + pub abi: StaticCow<str>, /// Vendor name to use for conditional compilation (`target_vendor`). Defaults to "unknown". - pub vendor: String, + pub vendor: StaticCow<str>, /// Default linker flavor used if `-C linker-flavor` or `-C linker` are not passed /// on the command line. Defaults to `LinkerFlavor::Gcc`. pub linker_flavor: LinkerFlavor, /// Linker to invoke - pub linker: Option<String>, + pub linker: Option<StaticCow<str>>, /// LLD flavor used if `lld` (or `rust-lld`) is specified as a linker /// without clarifying its flavor in any way. @@ -1156,23 +1175,23 @@ pub struct TargetOptions { /// Optional link script applied to `dylib` and `executable` crate types. /// This is a string containing the script, not a path. Can only be applied /// to linkers where `linker_is_gnu` is true. - pub link_script: Option<String>, + pub link_script: Option<StaticCow<str>>, /// Environment variables to be set for the linker invocation. - pub link_env: Vec<(String, String)>, + pub link_env: StaticCow<[(StaticCow<str>, StaticCow<str>)]>, /// Environment variables to be removed for the linker invocation. - pub link_env_remove: Vec<String>, + pub link_env_remove: StaticCow<[StaticCow<str>]>, /// Extra arguments to pass to the external assembler (when used) - pub asm_args: Vec<String>, + pub asm_args: StaticCow<[StaticCow<str>]>, /// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults /// to "generic". - pub cpu: String, + pub cpu: StaticCow<str>, /// Default target features to pass to LLVM. These features will *always* be /// passed, and cannot be disabled even via `-C`. Corresponds to `llc /// -mattr=$features`. - pub features: String, + pub features: StaticCow<str>, /// Whether dynamic linking is available on this target. Defaults to false. pub dynamic_linking: bool, /// If dynamic linking is available, whether only cdylibs are supported. @@ -1196,21 +1215,21 @@ pub struct TargetOptions { /// Emit each function in its own section. Defaults to true. pub function_sections: bool, /// String to prepend to the name of every dynamic library. Defaults to "lib". - pub dll_prefix: String, + pub dll_prefix: StaticCow<str>, /// String to append to the name of every dynamic library. Defaults to ".so". - pub dll_suffix: String, + pub dll_suffix: StaticCow<str>, /// String to append to the name of every executable. - pub exe_suffix: String, + pub exe_suffix: StaticCow<str>, /// String to prepend to the name of every static library. Defaults to "lib". - pub staticlib_prefix: String, + pub staticlib_prefix: StaticCow<str>, /// String to append to the name of every static library. Defaults to ".a". - pub staticlib_suffix: String, + pub staticlib_suffix: StaticCow<str>, /// Values of the `target_family` cfg set for this target. /// /// Common options are: "unix", "windows". Defaults to no families. /// /// See <https://doc.rust-lang.org/reference/conditional-compilation.html#target_family>. - pub families: Vec<String>, + pub families: StaticCow<[StaticCow<str>]>, /// Whether the target toolchain's ABI supports returning small structs as an integer. pub abi_return_struct_as_int: bool, /// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS, @@ -1282,7 +1301,7 @@ pub struct TargetOptions { /// LLVM to assemble an archive or fall back to the system linker, and /// currently only "gnu" is used to fall into LLVM. Unknown strings cause /// the system linker to be used. - pub archive_format: String, + pub archive_format: StaticCow<str>, /// Is asm!() allowed? Defaults to true. pub allow_asm: bool, /// Whether the runtime startup code requires the `main` function be passed @@ -1298,7 +1317,7 @@ pub struct TargetOptions { /// Whether the target requires that emitted object code includes bitcode. pub forces_embed_bitcode: bool, /// Content of the LLVM cmdline section associated with embedded bitcode. - pub bitcode_llvm_cmdline: String, + pub bitcode_llvm_cmdline: StaticCow<str>, /// Don't use this field; instead use the `.min_atomic_width()` method. pub min_atomic_width: Option<u64>, @@ -1370,7 +1389,7 @@ pub struct TargetOptions { /// If set, have the linker export exactly these symbols, instead of using /// the usual logic to figure this out from the crate itself. - pub override_export_symbols: Option<Vec<String>>, + pub override_export_symbols: Option<StaticCow<[StaticCow<str>]>>, /// Determines how or whether the MergeFunctions LLVM pass should run for /// this target. Either "disabled", "trampolines", or "aliases". @@ -1381,16 +1400,16 @@ pub struct TargetOptions { pub merge_functions: MergeFunctions, /// Use platform dependent mcount function - pub mcount: String, + pub mcount: StaticCow<str>, /// LLVM ABI name, corresponds to the '-mabi' parameter available in multilib C compilers - pub llvm_abiname: String, + pub llvm_abiname: StaticCow<str>, /// Whether or not RelaxElfRelocation flag will be passed to the linker pub relax_elf_relocations: bool, /// Additional arguments to pass to LLVM, similar to the `-C llvm-args` codegen option. - pub llvm_args: Vec<String>, + pub llvm_args: StaticCow<[StaticCow<str>]>, /// Whether to use legacy .ctors initialization hooks rather than .init_array. Defaults /// to false (uses .init_array). @@ -1437,20 +1456,20 @@ impl Default for TargetOptions { TargetOptions { is_builtin: false, endian: Endian::Little, - c_int_width: "32".to_string(), - os: "none".to_string(), - env: String::new(), - abi: String::new(), - vendor: "unknown".to_string(), + c_int_width: "32".into(), + os: "none".into(), + env: "".into(), + abi: "".into(), + vendor: "unknown".into(), linker_flavor: LinkerFlavor::Gcc, - linker: option_env!("CFG_DEFAULT_LINKER").map(|s| s.to_string()), + linker: option_env!("CFG_DEFAULT_LINKER").map(|s| s.into()), lld_flavor: LldFlavor::Ld, pre_link_args: LinkArgs::new(), post_link_args: LinkArgs::new(), link_script: None, - asm_args: Vec::new(), - cpu: "generic".to_string(), - features: String::new(), + asm_args: cvs![], + cpu: "generic".into(), + features: "".into(), dynamic_linking: false, only_cdylib: false, executables: false, @@ -1460,12 +1479,12 @@ impl Default for TargetOptions { disable_redzone: false, frame_pointer: FramePointer::MayOmit, function_sections: true, - dll_prefix: "lib".to_string(), - dll_suffix: ".so".to_string(), - exe_suffix: String::new(), - staticlib_prefix: "lib".to_string(), - staticlib_suffix: ".a".to_string(), - families: Vec::new(), + dll_prefix: "lib".into(), + dll_suffix: ".so".into(), + exe_suffix: "".into(), + staticlib_prefix: "lib".into(), + staticlib_suffix: ".a".into(), + families: cvs![], abi_return_struct_as_int: false, is_like_osx: false, is_like_solaris: false, @@ -1491,15 +1510,15 @@ impl Default for TargetOptions { late_link_args: LinkArgs::new(), late_link_args_dynamic: LinkArgs::new(), late_link_args_static: LinkArgs::new(), - link_env: Vec::new(), - link_env_remove: Vec::new(), - archive_format: "gnu".to_string(), + link_env: cvs![], + link_env_remove: cvs![], + archive_format: "gnu".into(), main_needs_argc_argv: true, allow_asm: true, has_thread_local: false, obj_is_bitcode: false, forces_embed_bitcode: false, - bitcode_llvm_cmdline: String::new(), + bitcode_llvm_cmdline: "".into(), min_atomic_width: None, max_atomic_width: None, atomic_cas: true, @@ -1522,10 +1541,10 @@ impl Default for TargetOptions { limit_rdylib_exports: true, override_export_symbols: None, merge_functions: MergeFunctions::Aliases, - mcount: "mcount".to_string(), - llvm_abiname: "".to_string(), + mcount: "mcount".into(), + llvm_abiname: "".into(), relax_elf_relocations: false, - llvm_args: vec![], + llvm_args: cvs![], use_ctors_section: false, eh_frame_header: true, has_thumb_interworking: false, @@ -1671,12 +1690,12 @@ impl Target { }; let mut base = Target { - llvm_target: get_req_field("llvm-target")?, + llvm_target: get_req_field("llvm-target")?.into(), pointer_width: get_req_field("target-pointer-width")? .parse::<u32>() .map_err(|_| "target-pointer-width must be an integer".to_string())?, - data_layout: get_req_field("data-layout")?, - arch: get_req_field("arch")?, + data_layout: get_req_field("data-layout")?.into(), + arch: get_req_field("arch")?.into(), options: Default::default(), }; @@ -1685,13 +1704,13 @@ impl Target { macro_rules! key { ($key_name:ident) => ( { let name = (stringify!($key_name)).replace("_", "-"); - if let Some(s) = obj.remove_key(&name).and_then(|j| Json::as_string(&j).map(str::to_string)) { + if let Some(s) = obj.remove_key(&name).and_then(|j| Json::as_string(&j).map(str::to_string).map(Cow::from)) { base.$key_name = s; } } ); ($key_name:ident = $json_name:expr) => ( { let name = $json_name; - if let Some(s) = obj.remove_key(&name).and_then(|j| Json::as_string(&j).map(str::to_string)) { + if let Some(s) = obj.remove_key(&name).and_then(|j| Json::as_string(&j).map(str::to_string).map(Cow::from)) { base.$key_name = s; } } ); @@ -1711,7 +1730,7 @@ impl Target { let name = (stringify!($key_name)).replace("_", "-"); if let Some(s) = obj.remove_key(&name).and_then(|j| Json::as_u64(&j)) { if s < 1 || s > 5 { - return Err("Not a valid DWARF version number".to_string()); + return Err("Not a valid DWARF version number".into()); } base.$key_name = Some(s as u32); } @@ -1813,7 +1832,7 @@ impl Target { if let Some(j) = obj.remove_key(&name){ if let Some(v) = Json::as_array(&j) { base.$key_name = v.iter() - .map(|a| a.as_string().unwrap().to_string()) + .map(|a| a.as_string().unwrap().to_string().into()) .collect(); } else { incorrect_type.push(name) @@ -1825,7 +1844,7 @@ impl Target { if let Some(j) = obj.remove_key(&name) { if let Some(v) = Json::as_array(&j) { base.$key_name = Some(v.iter() - .map(|a| a.as_string().unwrap().to_string()) + .map(|a| a.as_string().unwrap().to_string().into()) .collect()); } else { incorrect_type.push(name) @@ -1837,7 +1856,7 @@ impl Target { if let Some(o) = obj.remove_key(&name[..]) { base.$key_name = o .as_string() - .map(|s| s.to_string() ); + .map(|s| s.to_string().into()); } } ); ($key_name:ident, LldFlavor) => ( { @@ -1931,7 +1950,7 @@ impl Target { .map(|(i,s)| { let s = s.as_string().ok_or_else(|| format!("{}.{}[{}]: expected a JSON string", name, k, i))?; - Ok(s.to_owned()) + Ok(s.to_string().into()) }) .collect::<Result<Vec<_>, String>>()?; @@ -1958,7 +1977,7 @@ impl Target { .map(|(i,s)| { let s = s.as_string().ok_or_else(|| format!("{}.{}[{}]: expected a JSON string", name, k, i))?; - Ok(s.to_owned()) + Ok(s.to_string().into()) }) .collect::<Result<Vec<_>, String>>()?; @@ -1977,7 +1996,7 @@ impl Target { if p.len() == 2 { let k = p[0].to_string(); let v = p[1].to_string(); - base.$key_name.push((k, v)); + base.$key_name.to_mut().push((k.into(), v.into())); } } } @@ -2000,10 +2019,10 @@ impl Target { if let Some(value) = obj.remove_key("target-family") { if let Some(v) = Json::as_array(&value) { base.$key_name = v.iter() - .map(|a| a.as_string().unwrap().to_string()) + .map(|a| a.as_string().unwrap().to_string().into()) .collect(); } else if let Some(v) = Json::as_string(&value) { - base.$key_name = vec![v.to_string()]; + base.$key_name = vec![v.to_string().into()].into(); } } } ); @@ -2013,7 +2032,7 @@ impl Target { if let Some(s) = Json::as_string(&j) { base.endian = s.parse()?; } else { - incorrect_type.push("target-endian".to_string()) + incorrect_type.push("target-endian".into()) } } @@ -2023,7 +2042,7 @@ impl Target { .parse() .map_err(|()| format!("'{}' is not a valid value for frame-pointer", s))?; } else { - incorrect_type.push("frame-pointer".to_string()) + incorrect_type.push("frame-pointer".into()) } } @@ -2128,7 +2147,7 @@ impl Target { if base.is_builtin { // This can cause unfortunate ICEs later down the line. - return Err("may not set is_builtin for targets not built-in".to_string()); + return Err("may not set is_builtin for targets not built-in".into()); } // Each field should have been read using `Json::remove_key` so any keys remaining are unused. let remaining_keys = obj.as_object().ok_or("Expected JSON object for target")?.keys(); @@ -2232,7 +2251,7 @@ impl ToJson for Target { }}; ($attr:ident, $key_name:expr) => {{ let name = $key_name; - d.insert(name.to_string(), self.$attr.to_json()); + d.insert(name.into(), self.$attr.to_json()); }}; } @@ -2246,7 +2265,7 @@ impl ToJson for Target { ($attr:ident, $key_name:expr) => {{ let name = $key_name; if default.$attr != self.$attr { - d.insert(name.to_string(), self.$attr.to_json()); + d.insert(name.into(), self.$attr.to_json()); } }}; (link_args - $attr:ident) => {{ @@ -2255,7 +2274,7 @@ impl ToJson for Target { let obj = self .$attr .iter() - .map(|(k, v)| (k.desc().to_owned(), v.clone())) + .map(|(k, v)| (k.desc().to_string(), v.clone())) .collect::<BTreeMap<_, _>>(); d.insert(name, obj.to_json()); } @@ -2266,7 +2285,7 @@ impl ToJson for Target { let obj = self .$attr .iter() - .map(|&(ref k, ref v)| k.clone() + "=" + &v) + .map(|&(ref k, ref v)| format!("{k}={v}")) .collect::<Vec<_>>(); d.insert(name, obj.to_json()); } @@ -2379,7 +2398,7 @@ impl ToJson for Target { target_option_val!(supports_stack_protector); if let Some(abi) = self.default_adjusted_cabi { - d.insert("default-adjusted-cabi".to_string(), Abi::name(abi).to_json()); + d.insert("default-adjusted-cabi".into(), Abi::name(abi).to_json()); } Json::Object(d) @@ -2396,7 +2415,7 @@ pub enum TargetTriple { impl TargetTriple { /// Creates a target triple from the passed target triple string. pub fn from_triple(triple: &str) -> Self { - TargetTriple::TargetTriple(triple.to_string()) + TargetTriple::TargetTriple(triple.into()) } /// Creates a target triple from the passed target path. @@ -2434,7 +2453,7 @@ impl TargetTriple { let hash = hasher.finish(); format!("{}-{}", triple, hash) } else { - triple.to_owned() + triple.into() } } } diff --git a/compiler/rustc_target/src/spec/msp430_none_elf.rs b/compiler/rustc_target/src/spec/msp430_none_elf.rs index 6e3a241a86e..cedacb60f31 100644 --- a/compiler/rustc_target/src/spec/msp430_none_elf.rs +++ b/compiler/rustc_target/src/spec/msp430_none_elf.rs @@ -1,22 +1,22 @@ -use crate::spec::{PanicStrategy, RelocModel, Target, TargetOptions}; +use crate::spec::{cvs, PanicStrategy, RelocModel, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "msp430-none-elf".to_string(), + llvm_target: "msp430-none-elf".into(), pointer_width: 16, - 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(), + data_layout: "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16".into(), + arch: "msp430".into(), options: TargetOptions { - c_int_width: "16".to_string(), + c_int_width: "16".into(), executables: true, // The LLVM backend currently can't generate object files. To // workaround this LLVM generates assembly files which then we feed // to gcc to get object files. For this reason we have a hard // dependency on this specific gcc. - asm_args: vec!["-mcpu=msp430".to_string()], - linker: Some("msp430-elf-gcc".to_string()), + asm_args: cvs!["-mcpu=msp430"], + linker: Some("msp430-elf-gcc".into()), linker_is_gnu: false, // There are no atomic CAS instructions available in the MSP430 diff --git a/compiler/rustc_target/src/spec/msvc_base.rs b/compiler/rustc_target/src/spec/msvc_base.rs index f1ed4c154d2..00cc9620243 100644 --- a/compiler/rustc_target/src/spec/msvc_base.rs +++ b/compiler/rustc_target/src/spec/msvc_base.rs @@ -4,7 +4,7 @@ pub fn opts() -> TargetOptions { let pre_link_args_msvc = vec![ // Suppress the verbose logo and authorship debugging output, which would needlessly // clog any log files. - "/NOLOGO".to_string(), + "/NOLOGO".into(), ]; let mut pre_link_args = LinkArgs::new(); pre_link_args.insert(LinkerFlavor::Msvc, pre_link_args_msvc.clone()); diff --git a/compiler/rustc_target/src/spec/netbsd_base.rs b/compiler/rustc_target/src/spec/netbsd_base.rs index 6bb6083d47c..69016d77cf9 100644 --- a/compiler/rustc_target/src/spec/netbsd_base.rs +++ b/compiler/rustc_target/src/spec/netbsd_base.rs @@ -1,11 +1,11 @@ -use crate::spec::{RelroLevel, TargetOptions}; +use crate::spec::{cvs, RelroLevel, TargetOptions}; pub fn opts() -> TargetOptions { TargetOptions { - os: "netbsd".to_string(), + os: "netbsd".into(), dynamic_linking: true, executables: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], no_default_libraries: false, has_rpath: true, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/nvptx64_nvidia_cuda.rs b/compiler/rustc_target/src/spec/nvptx64_nvidia_cuda.rs index ba32a312910..9d94ed8aa48 100644 --- a/compiler/rustc_target/src/spec/nvptx64_nvidia_cuda.rs +++ b/compiler/rustc_target/src/spec/nvptx64_nvidia_cuda.rs @@ -2,21 +2,21 @@ use crate::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, Target, TargetOpt pub fn target() -> Target { Target { - arch: "nvptx64".to_string(), - data_layout: "e-i64:64-i128:128-v16:16-v32:32-n16:32:64".to_string(), - llvm_target: "nvptx64-nvidia-cuda".to_string(), + arch: "nvptx64".into(), + data_layout: "e-i64:64-i128:128-v16:16-v32:32-n16:32:64".into(), + llvm_target: "nvptx64-nvidia-cuda".into(), pointer_width: 64, options: TargetOptions { - os: "cuda".to_string(), - vendor: "nvidia".to_string(), + os: "cuda".into(), + vendor: "nvidia".into(), linker_flavor: LinkerFlavor::PtxLinker, // The linker can be installed from `crates.io`. - linker: Some("rust-ptx-linker".to_string()), + linker: Some("rust-ptx-linker".into()), linker_is_gnu: false, // With `ptx-linker` approach, it can be later overridden via link flags. - cpu: "sm_30".to_string(), + cpu: "sm_30".into(), // FIXME: create tests for the atomics. max_atomic_width: Some(64), @@ -36,9 +36,9 @@ pub fn target() -> Target { obj_is_bitcode: true, // Convenient and predicable naming scheme. - dll_prefix: "".to_string(), - dll_suffix: ".ptx".to_string(), - exe_suffix: ".ptx".to_string(), + dll_prefix: "".into(), + dll_suffix: ".ptx".into(), + exe_suffix: ".ptx".into(), // Disable MergeFunctions LLVM optimisation pass because it can // produce kernel functions that call other kernel functions. diff --git a/compiler/rustc_target/src/spec/openbsd_base.rs b/compiler/rustc_target/src/spec/openbsd_base.rs index 70e9e4aed92..bbd322bb6ce 100644 --- a/compiler/rustc_target/src/spec/openbsd_base.rs +++ b/compiler/rustc_target/src/spec/openbsd_base.rs @@ -1,11 +1,11 @@ -use crate::spec::{FramePointer, RelroLevel, TargetOptions}; +use crate::spec::{cvs, FramePointer, RelroLevel, TargetOptions}; pub fn opts() -> TargetOptions { TargetOptions { - os: "openbsd".to_string(), + os: "openbsd".into(), dynamic_linking: true, executables: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], has_rpath: true, abi_return_struct_as_int: true, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/powerpc64_unknown_freebsd.rs b/compiler/rustc_target/src/spec/powerpc64_unknown_freebsd.rs index b3d6b7c6107..595769c4bfa 100644 --- a/compiler/rustc_target/src/spec/powerpc64_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/powerpc64_unknown_freebsd.rs @@ -3,15 +3,15 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::freebsd_base::opts(); - base.cpu = "ppc64".to_string(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.cpu = "ppc64".into(); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); base.max_atomic_width = Some(64); Target { - llvm_target: "powerpc64-unknown-freebsd".to_string(), + llvm_target: "powerpc64-unknown-freebsd".into(), pointer_width: 64, - data_layout: "E-m:e-i64:64-n32:64".to_string(), - arch: "powerpc64".to_string(), - options: TargetOptions { endian: Endian::Big, mcount: "_mcount".to_string(), ..base }, + data_layout: "E-m:e-i64:64-n32:64".into(), + arch: "powerpc64".into(), + options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc64_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/powerpc64_unknown_linux_gnu.rs index f10d4d49bb9..24d5d187e1a 100644 --- a/compiler/rustc_target/src/spec/powerpc64_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/powerpc64_unknown_linux_gnu.rs @@ -3,8 +3,8 @@ use crate::spec::{LinkerFlavor, RelroLevel, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); - base.cpu = "ppc64".to_string(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.cpu = "ppc64".into(); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); base.max_atomic_width = Some(64); // ld.so in at least RHEL6 on ppc64 has a bug related to BIND_NOW, so only enable partial RELRO @@ -12,10 +12,10 @@ pub fn target() -> Target { base.relro_level = RelroLevel::Partial; Target { - llvm_target: "powerpc64-unknown-linux-gnu".to_string(), + llvm_target: "powerpc64-unknown-linux-gnu".into(), pointer_width: 64, - data_layout: "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".to_string(), - arch: "powerpc64".to_string(), - options: TargetOptions { endian: Endian::Big, mcount: "_mcount".to_string(), ..base }, + data_layout: "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(), + arch: "powerpc64".into(), + options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc64_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/powerpc64_unknown_linux_musl.rs index 611621727bd..0f465ccfe77 100644 --- a/compiler/rustc_target/src/spec/powerpc64_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/powerpc64_unknown_linux_musl.rs @@ -3,15 +3,15 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.cpu = "ppc64".to_string(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.cpu = "ppc64".into(); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); base.max_atomic_width = Some(64); Target { - llvm_target: "powerpc64-unknown-linux-musl".to_string(), + llvm_target: "powerpc64-unknown-linux-musl".into(), pointer_width: 64, - data_layout: "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".to_string(), - arch: "powerpc64".to_string(), - options: TargetOptions { endian: Endian::Big, mcount: "_mcount".to_string(), ..base }, + data_layout: "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(), + arch: "powerpc64".into(), + options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc64_wrs_vxworks.rs b/compiler/rustc_target/src/spec/powerpc64_wrs_vxworks.rs index 9c63997ce2f..491d344aedb 100644 --- a/compiler/rustc_target/src/spec/powerpc64_wrs_vxworks.rs +++ b/compiler/rustc_target/src/spec/powerpc64_wrs_vxworks.rs @@ -3,15 +3,15 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::vxworks_base::opts(); - base.cpu = "ppc64".to_string(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.cpu = "ppc64".into(); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); base.max_atomic_width = Some(64); Target { - llvm_target: "powerpc64-unknown-linux-gnu".to_string(), + llvm_target: "powerpc64-unknown-linux-gnu".into(), pointer_width: 64, - data_layout: "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".to_string(), - arch: "powerpc64".to_string(), + data_layout: "E-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(), + arch: "powerpc64".into(), options: TargetOptions { endian: Endian::Big, ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc64le_unknown_freebsd.rs b/compiler/rustc_target/src/spec/powerpc64le_unknown_freebsd.rs index 283e9f744cb..b198e667ccc 100644 --- a/compiler/rustc_target/src/spec/powerpc64le_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/powerpc64le_unknown_freebsd.rs @@ -2,15 +2,15 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::freebsd_base::opts(); - base.cpu = "ppc64le".to_string(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.cpu = "ppc64le".into(); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); base.max_atomic_width = Some(64); Target { - llvm_target: "powerpc64le-unknown-freebsd".to_string(), + llvm_target: "powerpc64le-unknown-freebsd".into(), pointer_width: 64, - data_layout: "e-m:e-i64:64-n32:64".to_string(), - arch: "powerpc64".to_string(), - options: TargetOptions { mcount: "_mcount".to_string(), ..base }, + data_layout: "e-m:e-i64:64-n32:64".into(), + arch: "powerpc64".into(), + options: TargetOptions { mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_gnu.rs index f645eceadfe..09e3936db26 100644 --- a/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_gnu.rs @@ -2,15 +2,15 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); - base.cpu = "ppc64le".to_string(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.cpu = "ppc64le".into(); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); base.max_atomic_width = Some(64); Target { - llvm_target: "powerpc64le-unknown-linux-gnu".to_string(), + llvm_target: "powerpc64le-unknown-linux-gnu".into(), pointer_width: 64, - data_layout: "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".to_string(), - arch: "powerpc64".to_string(), - options: TargetOptions { mcount: "_mcount".to_string(), ..base }, + data_layout: "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(), + arch: "powerpc64".into(), + options: TargetOptions { mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_musl.rs index 934371fb221..8a947b091cb 100644 --- a/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/powerpc64le_unknown_linux_musl.rs @@ -2,15 +2,15 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.cpu = "ppc64le".to_string(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.cpu = "ppc64le".into(); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); base.max_atomic_width = Some(64); Target { - llvm_target: "powerpc64le-unknown-linux-musl".to_string(), + llvm_target: "powerpc64le-unknown-linux-musl".into(), pointer_width: 64, - data_layout: "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".to_string(), - arch: "powerpc64".to_string(), - options: TargetOptions { mcount: "_mcount".to_string(), ..base }, + data_layout: "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(), + arch: "powerpc64".into(), + options: TargetOptions { mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc_unknown_freebsd.rs b/compiler/rustc_target/src/spec/powerpc_unknown_freebsd.rs index e11318027d5..c27b84775df 100644 --- a/compiler/rustc_target/src/spec/powerpc_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/powerpc_unknown_freebsd.rs @@ -3,24 +3,24 @@ use crate::spec::{LinkerFlavor, RelocModel, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::freebsd_base::opts(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".into()); // Extra hint to linker that we are generating secure-PLT code. base.pre_link_args .entry(LinkerFlavor::Gcc) .or_default() - .push("--target=powerpc-unknown-freebsd13.0".to_string()); + .push("--target=powerpc-unknown-freebsd13.0".into()); base.max_atomic_width = Some(32); Target { - llvm_target: "powerpc-unknown-freebsd13.0".to_string(), + llvm_target: "powerpc-unknown-freebsd13.0".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), - arch: "powerpc".to_string(), + data_layout: "E-m:e-p:32:32-i64:64-n32".into(), + arch: "powerpc".into(), options: TargetOptions { endian: Endian::Big, - features: "+secure-plt".to_string(), + features: "+secure-plt".into(), relocation_model: RelocModel::Pic, - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..base }, } diff --git a/compiler/rustc_target/src/spec/powerpc_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/powerpc_unknown_linux_gnu.rs index 21ffdd2d160..88f61500e3c 100644 --- a/compiler/rustc_target/src/spec/powerpc_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/powerpc_unknown_linux_gnu.rs @@ -3,14 +3,14 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".into()); base.max_atomic_width = Some(32); Target { - llvm_target: "powerpc-unknown-linux-gnu".to_string(), + llvm_target: "powerpc-unknown-linux-gnu".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), - arch: "powerpc".to_string(), - options: TargetOptions { endian: Endian::Big, mcount: "_mcount".to_string(), ..base }, + data_layout: "E-m:e-p:32:32-i64:64-n32".into(), + arch: "powerpc".into(), + options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc_unknown_linux_gnuspe.rs b/compiler/rustc_target/src/spec/powerpc_unknown_linux_gnuspe.rs index 362d8a104e4..3ee548750b9 100644 --- a/compiler/rustc_target/src/spec/powerpc_unknown_linux_gnuspe.rs +++ b/compiler/rustc_target/src/spec/powerpc_unknown_linux_gnuspe.rs @@ -3,18 +3,18 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-mspe".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-mspe".into()); base.max_atomic_width = Some(32); Target { - llvm_target: "powerpc-unknown-linux-gnuspe".to_string(), + llvm_target: "powerpc-unknown-linux-gnuspe".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), - arch: "powerpc".to_string(), + data_layout: "E-m:e-p:32:32-i64:64-n32".into(), + arch: "powerpc".into(), options: TargetOptions { - abi: "spe".to_string(), + abi: "spe".into(), endian: Endian::Big, - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..base }, } diff --git a/compiler/rustc_target/src/spec/powerpc_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/powerpc_unknown_linux_musl.rs index 9633705db6d..ce33c787f33 100644 --- a/compiler/rustc_target/src/spec/powerpc_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/powerpc_unknown_linux_musl.rs @@ -3,14 +3,14 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".into()); base.max_atomic_width = Some(32); Target { - llvm_target: "powerpc-unknown-linux-musl".to_string(), + llvm_target: "powerpc-unknown-linux-musl".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), - arch: "powerpc".to_string(), - options: TargetOptions { endian: Endian::Big, mcount: "_mcount".to_string(), ..base }, + data_layout: "E-m:e-p:32:32-i64:64-n32".into(), + arch: "powerpc".into(), + options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc_unknown_netbsd.rs b/compiler/rustc_target/src/spec/powerpc_unknown_netbsd.rs index 4cc5224fae3..998225f4dae 100644 --- a/compiler/rustc_target/src/spec/powerpc_unknown_netbsd.rs +++ b/compiler/rustc_target/src/spec/powerpc_unknown_netbsd.rs @@ -3,14 +3,14 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::netbsd_base::opts(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".into()); base.max_atomic_width = Some(32); Target { - llvm_target: "powerpc-unknown-netbsd".to_string(), + llvm_target: "powerpc-unknown-netbsd".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), - arch: "powerpc".to_string(), - options: TargetOptions { endian: Endian::Big, mcount: "__mcount".to_string(), ..base }, + data_layout: "E-m:e-p:32:32-i64:64-n32".into(), + arch: "powerpc".into(), + options: TargetOptions { endian: Endian::Big, mcount: "__mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc_unknown_openbsd.rs b/compiler/rustc_target/src/spec/powerpc_unknown_openbsd.rs index c17183faa7a..ad2c3d40f35 100644 --- a/compiler/rustc_target/src/spec/powerpc_unknown_openbsd.rs +++ b/compiler/rustc_target/src/spec/powerpc_unknown_openbsd.rs @@ -7,10 +7,10 @@ pub fn target() -> Target { base.max_atomic_width = Some(32); Target { - llvm_target: "powerpc-unknown-openbsd".to_string(), + llvm_target: "powerpc-unknown-openbsd".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), - arch: "powerpc".to_string(), + data_layout: "E-m:e-p:32:32-i64:64-n32".into(), + arch: "powerpc".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/powerpc_wrs_vxworks.rs b/compiler/rustc_target/src/spec/powerpc_wrs_vxworks.rs index 2f0a6ca44a0..76709cec591 100644 --- a/compiler/rustc_target/src/spec/powerpc_wrs_vxworks.rs +++ b/compiler/rustc_target/src/spec/powerpc_wrs_vxworks.rs @@ -3,15 +3,15 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::vxworks_base::opts(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".to_string()); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("--secure-plt".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m32".into()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("--secure-plt".into()); base.max_atomic_width = Some(32); Target { - llvm_target: "powerpc-unknown-linux-gnu".to_string(), + llvm_target: "powerpc-unknown-linux-gnu".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), - arch: "powerpc".to_string(), - options: TargetOptions { endian: Endian::Big, features: "+secure-plt".to_string(), ..base }, + data_layout: "E-m:e-p:32:32-i64:64-n32".into(), + arch: "powerpc".into(), + options: TargetOptions { endian: Endian::Big, features: "+secure-plt".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/powerpc_wrs_vxworks_spe.rs b/compiler/rustc_target/src/spec/powerpc_wrs_vxworks_spe.rs index a2b85f7dd86..7b5d1242c52 100644 --- a/compiler/rustc_target/src/spec/powerpc_wrs_vxworks_spe.rs +++ b/compiler/rustc_target/src/spec/powerpc_wrs_vxworks_spe.rs @@ -3,20 +3,20 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::vxworks_base::opts(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-mspe".to_string()); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("--secure-plt".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-mspe".into()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("--secure-plt".into()); base.max_atomic_width = Some(32); Target { - llvm_target: "powerpc-unknown-linux-gnuspe".to_string(), + llvm_target: "powerpc-unknown-linux-gnuspe".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), - arch: "powerpc".to_string(), + data_layout: "E-m:e-p:32:32-i64:64-n32".into(), + arch: "powerpc".into(), options: TargetOptions { - abi: "spe".to_string(), + abi: "spe".into(), endian: Endian::Big, // feature msync would disable instruction 'fsync' which is not supported by fsl_p1p2 - features: "+secure-plt,+msync".to_string(), + features: "+secure-plt,+msync".into(), ..base }, } diff --git a/compiler/rustc_target/src/spec/redox_base.rs b/compiler/rustc_target/src/spec/redox_base.rs index bcb536b37a1..1878cc3fc11 100644 --- a/compiler/rustc_target/src/spec/redox_base.rs +++ b/compiler/rustc_target/src/spec/redox_base.rs @@ -1,12 +1,12 @@ -use crate::spec::{RelroLevel, TargetOptions}; +use crate::spec::{cvs, RelroLevel, TargetOptions}; pub fn opts() -> TargetOptions { TargetOptions { - os: "redox".to_string(), - env: "relibc".to_string(), + os: "redox".into(), + env: "relibc".into(), dynamic_linking: true, executables: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], has_rpath: true, position_independent_executables: true, relro_level: RelroLevel::Full, diff --git a/compiler/rustc_target/src/spec/riscv32gc_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/riscv32gc_unknown_linux_gnu.rs index a9cdad1a8b1..bffd377bc4a 100644 --- a/compiler/rustc_target/src/spec/riscv32gc_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/riscv32gc_unknown_linux_gnu.rs @@ -2,15 +2,15 @@ use crate::spec::{CodeModel, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "riscv32-unknown-linux-gnu".to_string(), + llvm_target: "riscv32-unknown-linux-gnu".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(), - arch: "riscv32".to_string(), + data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), + arch: "riscv32".into(), options: TargetOptions { code_model: Some(CodeModel::Medium), - cpu: "generic-rv32".to_string(), - features: "+m,+a,+f,+d,+c".to_string(), - llvm_abiname: "ilp32d".to_string(), + cpu: "generic-rv32".into(), + features: "+m,+a,+f,+d,+c".into(), + llvm_abiname: "ilp32d".into(), max_atomic_width: Some(32), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/riscv32gc_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/riscv32gc_unknown_linux_musl.rs index a64a82d55b9..c9f3acffb77 100644 --- a/compiler/rustc_target/src/spec/riscv32gc_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/riscv32gc_unknown_linux_musl.rs @@ -2,15 +2,15 @@ use crate::spec::{CodeModel, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "riscv32-unknown-linux-musl".to_string(), + llvm_target: "riscv32-unknown-linux-musl".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(), - arch: "riscv32".to_string(), + data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), + arch: "riscv32".into(), options: TargetOptions { code_model: Some(CodeModel::Medium), - cpu: "generic-rv32".to_string(), - features: "+m,+a,+f,+d,+c".to_string(), - llvm_abiname: "ilp32d".to_string(), + cpu: "generic-rv32".into(), + features: "+m,+a,+f,+d,+c".into(), + llvm_abiname: "ilp32d".into(), max_atomic_width: Some(32), ..super::linux_musl_base::opts() }, diff --git a/compiler/rustc_target/src/spec/riscv32i_unknown_none_elf.rs b/compiler/rustc_target/src/spec/riscv32i_unknown_none_elf.rs index 16d37218f41..7124e2df9b3 100644 --- a/compiler/rustc_target/src/spec/riscv32i_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/riscv32i_unknown_none_elf.rs @@ -3,15 +3,15 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(), - llvm_target: "riscv32".to_string(), + data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), + llvm_target: "riscv32".into(), pointer_width: 32, - arch: "riscv32".to_string(), + arch: "riscv32".into(), options: TargetOptions { linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_string()), - cpu: "generic-rv32".to_string(), + linker: Some("rust-lld".into()), + cpu: "generic-rv32".into(), max_atomic_width: Some(0), atomic_cas: false, executables: true, diff --git a/compiler/rustc_target/src/spec/riscv32im_unknown_none_elf.rs b/compiler/rustc_target/src/spec/riscv32im_unknown_none_elf.rs index 0357a94914f..508982eed68 100644 --- a/compiler/rustc_target/src/spec/riscv32im_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/riscv32im_unknown_none_elf.rs @@ -3,18 +3,18 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(), - llvm_target: "riscv32".to_string(), + data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), + llvm_target: "riscv32".into(), pointer_width: 32, - arch: "riscv32".to_string(), + arch: "riscv32".into(), options: TargetOptions { linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_string()), - cpu: "generic-rv32".to_string(), + linker: Some("rust-lld".into()), + cpu: "generic-rv32".into(), max_atomic_width: Some(0), atomic_cas: false, - features: "+m".to_string(), + features: "+m".into(), executables: true, panic_strategy: PanicStrategy::Abort, relocation_model: RelocModel::Static, diff --git a/compiler/rustc_target/src/spec/riscv32imac_unknown_none_elf.rs b/compiler/rustc_target/src/spec/riscv32imac_unknown_none_elf.rs index b53bae6cb56..f2bd6249f0a 100644 --- a/compiler/rustc_target/src/spec/riscv32imac_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/riscv32imac_unknown_none_elf.rs @@ -3,17 +3,17 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(), - llvm_target: "riscv32".to_string(), + data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), + llvm_target: "riscv32".into(), pointer_width: 32, - arch: "riscv32".to_string(), + arch: "riscv32".into(), options: TargetOptions { linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_string()), - cpu: "generic-rv32".to_string(), + linker: Some("rust-lld".into()), + cpu: "generic-rv32".into(), max_atomic_width: Some(32), - features: "+m,+a,+c".to_string(), + features: "+m,+a,+c".into(), executables: true, panic_strategy: PanicStrategy::Abort, relocation_model: RelocModel::Static, diff --git a/compiler/rustc_target/src/spec/riscv32imc_esp_espidf.rs b/compiler/rustc_target/src/spec/riscv32imc_esp_espidf.rs index d506e7f6aac..0200862c7e0 100644 --- a/compiler/rustc_target/src/spec/riscv32imc_esp_espidf.rs +++ b/compiler/rustc_target/src/spec/riscv32imc_esp_espidf.rs @@ -1,21 +1,21 @@ +use crate::spec::{cvs, Target, TargetOptions}; use crate::spec::{LinkerFlavor, PanicStrategy, RelocModel}; -use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(), - llvm_target: "riscv32".to_string(), + data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), + llvm_target: "riscv32".into(), pointer_width: 32, - arch: "riscv32".to_string(), + arch: "riscv32".into(), options: TargetOptions { - families: vec!["unix".to_string()], - os: "espidf".to_string(), - env: "newlib".to_string(), - vendor: "espressif".to_string(), + families: cvs!["unix"], + os: "espidf".into(), + env: "newlib".into(), + vendor: "espressif".into(), linker_flavor: LinkerFlavor::Gcc, - linker: Some("riscv32-esp-elf-gcc".to_string()), - cpu: "generic-rv32".to_string(), + linker: Some("riscv32-esp-elf-gcc".into()), + cpu: "generic-rv32".into(), // While the RiscV32IMC architecture does not natively support atomics, ESP-IDF does support // the __atomic* and __sync* GCC builtins, so setting `max_atomic_width` to `Some(64)` @@ -25,7 +25,7 @@ pub fn target() -> Target { max_atomic_width: Some(64), atomic_cas: true, - features: "+m,+c".to_string(), + features: "+m,+c".into(), executables: true, panic_strategy: PanicStrategy::Abort, relocation_model: RelocModel::Static, diff --git a/compiler/rustc_target/src/spec/riscv32imc_unknown_none_elf.rs b/compiler/rustc_target/src/spec/riscv32imc_unknown_none_elf.rs index 9a23def1996..4216968cb77 100644 --- a/compiler/rustc_target/src/spec/riscv32imc_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/riscv32imc_unknown_none_elf.rs @@ -3,18 +3,18 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - data_layout: "e-m:e-p:32:32-i64:64-n32-S128".to_string(), - llvm_target: "riscv32".to_string(), + data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(), + llvm_target: "riscv32".into(), pointer_width: 32, - arch: "riscv32".to_string(), + arch: "riscv32".into(), options: TargetOptions { linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_string()), - cpu: "generic-rv32".to_string(), + linker: Some("rust-lld".into()), + cpu: "generic-rv32".into(), max_atomic_width: Some(0), atomic_cas: false, - features: "+m,+c".to_string(), + features: "+m,+c".into(), executables: true, panic_strategy: PanicStrategy::Abort, relocation_model: RelocModel::Static, diff --git a/compiler/rustc_target/src/spec/riscv64gc_unknown_freebsd.rs b/compiler/rustc_target/src/spec/riscv64gc_unknown_freebsd.rs index 1ea1b9bea2e..0539eca6c1f 100644 --- a/compiler/rustc_target/src/spec/riscv64gc_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/riscv64gc_unknown_freebsd.rs @@ -2,15 +2,15 @@ use crate::spec::{CodeModel, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "riscv64-unknown-freebsd".to_string(), + llvm_target: "riscv64-unknown-freebsd".into(), pointer_width: 64, - data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".to_string(), - arch: "riscv64".to_string(), + data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(), + arch: "riscv64".into(), options: TargetOptions { code_model: Some(CodeModel::Medium), - cpu: "generic-rv64".to_string(), - features: "+m,+a,+f,+d,+c".to_string(), - llvm_abiname: "lp64d".to_string(), + cpu: "generic-rv64".into(), + features: "+m,+a,+f,+d,+c".into(), + llvm_abiname: "lp64d".into(), max_atomic_width: Some(64), ..super::freebsd_base::opts() }, diff --git a/compiler/rustc_target/src/spec/riscv64gc_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/riscv64gc_unknown_linux_gnu.rs index 02d44b5ed7e..7d1bf228c37 100644 --- a/compiler/rustc_target/src/spec/riscv64gc_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/riscv64gc_unknown_linux_gnu.rs @@ -2,15 +2,15 @@ use crate::spec::{CodeModel, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "riscv64-unknown-linux-gnu".to_string(), + llvm_target: "riscv64-unknown-linux-gnu".into(), pointer_width: 64, - data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".to_string(), - arch: "riscv64".to_string(), + data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(), + arch: "riscv64".into(), options: TargetOptions { code_model: Some(CodeModel::Medium), - cpu: "generic-rv64".to_string(), - features: "+m,+a,+f,+d,+c".to_string(), - llvm_abiname: "lp64d".to_string(), + cpu: "generic-rv64".into(), + features: "+m,+a,+f,+d,+c".into(), + llvm_abiname: "lp64d".into(), max_atomic_width: Some(64), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/riscv64gc_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/riscv64gc_unknown_linux_musl.rs index 3754750e48d..f04f8a48bc8 100644 --- a/compiler/rustc_target/src/spec/riscv64gc_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/riscv64gc_unknown_linux_musl.rs @@ -2,15 +2,15 @@ use crate::spec::{CodeModel, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "riscv64-unknown-linux-musl".to_string(), + llvm_target: "riscv64-unknown-linux-musl".into(), pointer_width: 64, - data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".to_string(), - arch: "riscv64".to_string(), + data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(), + arch: "riscv64".into(), options: TargetOptions { code_model: Some(CodeModel::Medium), - cpu: "generic-rv64".to_string(), - features: "+m,+a,+f,+d,+c".to_string(), - llvm_abiname: "lp64d".to_string(), + cpu: "generic-rv64".into(), + features: "+m,+a,+f,+d,+c".into(), + llvm_abiname: "lp64d".into(), max_atomic_width: Some(64), ..super::linux_musl_base::opts() }, diff --git a/compiler/rustc_target/src/spec/riscv64gc_unknown_none_elf.rs b/compiler/rustc_target/src/spec/riscv64gc_unknown_none_elf.rs index f527a6cd26d..2a93459ef4f 100644 --- a/compiler/rustc_target/src/spec/riscv64gc_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/riscv64gc_unknown_none_elf.rs @@ -3,18 +3,18 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".to_string(), - llvm_target: "riscv64".to_string(), + data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(), + llvm_target: "riscv64".into(), pointer_width: 64, - arch: "riscv64".to_string(), + arch: "riscv64".into(), options: TargetOptions { linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_string()), - llvm_abiname: "lp64d".to_string(), - cpu: "generic-rv64".to_string(), + linker: Some("rust-lld".into()), + llvm_abiname: "lp64d".into(), + cpu: "generic-rv64".into(), max_atomic_width: Some(64), - features: "+m,+a,+f,+d,+c".to_string(), + features: "+m,+a,+f,+d,+c".into(), executables: true, panic_strategy: PanicStrategy::Abort, relocation_model: RelocModel::Static, diff --git a/compiler/rustc_target/src/spec/riscv64imac_unknown_none_elf.rs b/compiler/rustc_target/src/spec/riscv64imac_unknown_none_elf.rs index 8b1ba88e67f..6a8d8a97de6 100644 --- a/compiler/rustc_target/src/spec/riscv64imac_unknown_none_elf.rs +++ b/compiler/rustc_target/src/spec/riscv64imac_unknown_none_elf.rs @@ -3,17 +3,17 @@ use crate::spec::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel}; pub fn target() -> Target { Target { - data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".to_string(), - llvm_target: "riscv64".to_string(), + data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(), + llvm_target: "riscv64".into(), pointer_width: 64, - arch: "riscv64".to_string(), + arch: "riscv64".into(), options: TargetOptions { linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_string()), - cpu: "generic-rv64".to_string(), + linker: Some("rust-lld".into()), + cpu: "generic-rv64".into(), max_atomic_width: Some(64), - features: "+m,+a,+c".to_string(), + features: "+m,+a,+c".into(), executables: true, panic_strategy: PanicStrategy::Abort, relocation_model: RelocModel::Static, diff --git a/compiler/rustc_target/src/spec/s390x_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/s390x_unknown_linux_gnu.rs index 4eeea9bedfb..8757bbed8ad 100644 --- a/compiler/rustc_target/src/spec/s390x_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/s390x_unknown_linux_gnu.rs @@ -5,19 +5,19 @@ pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); base.endian = Endian::Big; // z10 is the oldest CPU supported by LLVM - base.cpu = "z10".to_string(); + base.cpu = "z10".into(); // FIXME: The data_layout string below and the ABI implementation in // cabi_s390x.rs are for now hard-coded to assume the no-vector ABI. // Pass the -vector feature string to LLVM to respect this assumption. - base.features = "-vector".to_string(); + base.features = "-vector".into(); base.max_atomic_width = Some(64); base.min_global_align = Some(16); Target { - llvm_target: "s390x-unknown-linux-gnu".to_string(), + llvm_target: "s390x-unknown-linux-gnu".into(), pointer_width: 64, - data_layout: "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64".to_string(), - arch: "s390x".to_string(), + data_layout: "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64".into(), + arch: "s390x".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/s390x_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/s390x_unknown_linux_musl.rs index 4f811ce98c1..4c855271a2a 100644 --- a/compiler/rustc_target/src/spec/s390x_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/s390x_unknown_linux_musl.rs @@ -5,20 +5,20 @@ pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); base.endian = Endian::Big; // z10 is the oldest CPU supported by LLVM - base.cpu = "z10".to_string(); + base.cpu = "z10".into(); // FIXME: The data_layout string below and the ABI implementation in // cabi_s390x.rs are for now hard-coded to assume the no-vector ABI. // Pass the -vector feature string to LLVM to respect this assumption. - base.features = "-vector".to_string(); + base.features = "-vector".into(); base.max_atomic_width = Some(64); base.min_global_align = Some(16); base.static_position_independent_executables = true; Target { - llvm_target: "s390x-unknown-linux-musl".to_string(), + llvm_target: "s390x-unknown-linux-musl".into(), pointer_width: 64, - data_layout: "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64".to_string(), - arch: "s390x".to_string(), + data_layout: "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64".into(), + arch: "s390x".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/solaris_base.rs b/compiler/rustc_target/src/spec/solaris_base.rs index bc32b501688..d61e1b2ec10 100644 --- a/compiler/rustc_target/src/spec/solaris_base.rs +++ b/compiler/rustc_target/src/spec/solaris_base.rs @@ -1,12 +1,12 @@ -use crate::spec::TargetOptions; +use crate::spec::{cvs, TargetOptions}; pub fn opts() -> TargetOptions { TargetOptions { - os: "solaris".to_string(), + os: "solaris".into(), dynamic_linking: true, executables: true, has_rpath: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], is_like_solaris: true, linker_is_gnu: false, limit_rdylib_exports: false, // Linker doesn't support this diff --git a/compiler/rustc_target/src/spec/solid_base.rs b/compiler/rustc_target/src/spec/solid_base.rs index 421cfc40112..c5602a4513a 100644 --- a/compiler/rustc_target/src/spec/solid_base.rs +++ b/compiler/rustc_target/src/spec/solid_base.rs @@ -3,8 +3,8 @@ use crate::spec::TargetOptions; pub fn opts(kernel: &str) -> TargetOptions { TargetOptions { - os: format!("solid_{}", kernel), - vendor: "kmc".to_string(), + os: format!("solid_{}", kernel).into(), + vendor: "kmc".into(), frame_pointer: FramePointer::NonLeaf, has_thread_local: true, ..Default::default() diff --git a/compiler/rustc_target/src/spec/sparc64_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/sparc64_unknown_linux_gnu.rs index e1aa48872b9..39efd8f305c 100644 --- a/compiler/rustc_target/src/spec/sparc64_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/sparc64_unknown_linux_gnu.rs @@ -4,14 +4,14 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); base.endian = Endian::Big; - base.cpu = "v9".to_string(); + base.cpu = "v9".into(); base.max_atomic_width = Some(64); Target { - llvm_target: "sparc64-unknown-linux-gnu".to_string(), + llvm_target: "sparc64-unknown-linux-gnu".into(), pointer_width: 64, - data_layout: "E-m:e-i64:64-n32:64-S128".to_string(), - arch: "sparc64".to_string(), + data_layout: "E-m:e-i64:64-n32:64-S128".into(), + arch: "sparc64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/sparc64_unknown_netbsd.rs b/compiler/rustc_target/src/spec/sparc64_unknown_netbsd.rs index b4286dfd88f..718303a4b4d 100644 --- a/compiler/rustc_target/src/spec/sparc64_unknown_netbsd.rs +++ b/compiler/rustc_target/src/spec/sparc64_unknown_netbsd.rs @@ -3,15 +3,15 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::netbsd_base::opts(); - base.cpu = "v9".to_string(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.cpu = "v9".into(); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); base.max_atomic_width = Some(64); Target { - llvm_target: "sparc64-unknown-netbsd".to_string(), + llvm_target: "sparc64-unknown-netbsd".into(), pointer_width: 64, - data_layout: "E-m:e-i64:64-n32:64-S128".to_string(), - arch: "sparc64".to_string(), - options: TargetOptions { endian: Endian::Big, mcount: "__mcount".to_string(), ..base }, + data_layout: "E-m:e-i64:64-n32:64-S128".into(), + arch: "sparc64".into(), + options: TargetOptions { endian: Endian::Big, mcount: "__mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/sparc64_unknown_openbsd.rs b/compiler/rustc_target/src/spec/sparc64_unknown_openbsd.rs index 9732983161f..2aaa0ca6df8 100644 --- a/compiler/rustc_target/src/spec/sparc64_unknown_openbsd.rs +++ b/compiler/rustc_target/src/spec/sparc64_unknown_openbsd.rs @@ -4,15 +4,15 @@ use crate::spec::{LinkerFlavor, Target}; pub fn target() -> Target { let mut base = super::openbsd_base::opts(); base.endian = Endian::Big; - base.cpu = "v9".to_string(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.cpu = "v9".into(); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); base.max_atomic_width = Some(64); Target { - llvm_target: "sparc64-unknown-openbsd".to_string(), + llvm_target: "sparc64-unknown-openbsd".into(), pointer_width: 64, - data_layout: "E-m:e-i64:64-n32:64-S128".to_string(), - arch: "sparc64".to_string(), + data_layout: "E-m:e-i64:64-n32:64-S128".into(), + arch: "sparc64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/sparc_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/sparc_unknown_linux_gnu.rs index 1fd4cadfffc..71d3de0bfd1 100644 --- a/compiler/rustc_target/src/spec/sparc_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/sparc_unknown_linux_gnu.rs @@ -4,15 +4,15 @@ use crate::spec::{LinkerFlavor, Target}; pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); base.endian = Endian::Big; - base.cpu = "v9".to_string(); + base.cpu = "v9".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-mv8plus".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-mv8plus".into()); Target { - llvm_target: "sparc-unknown-linux-gnu".to_string(), + llvm_target: "sparc-unknown-linux-gnu".into(), pointer_width: 32, - data_layout: "E-m:e-p:32:32-i64:64-f128:64-n32-S64".to_string(), - arch: "sparc".to_string(), + data_layout: "E-m:e-p:32:32-i64:64-f128:64-n32-S64".into(), + arch: "sparc".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/sparcv9_sun_solaris.rs b/compiler/rustc_target/src/spec/sparcv9_sun_solaris.rs index abc46a8c9c3..79ae54aa666 100644 --- a/compiler/rustc_target/src/spec/sparcv9_sun_solaris.rs +++ b/compiler/rustc_target/src/spec/sparcv9_sun_solaris.rs @@ -4,21 +4,21 @@ use crate::spec::{LinkerFlavor, Target}; pub fn target() -> Target { let mut base = super::solaris_base::opts(); base.endian = Endian::Big; - base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".to_string()]); + base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".into()]); // llvm calls this "v9" - base.cpu = "v9".to_string(); - base.vendor = "sun".to_string(); + base.cpu = "v9".into(); + base.vendor = "sun".into(); base.max_atomic_width = Some(64); Target { - llvm_target: "sparcv9-sun-solaris".to_string(), + llvm_target: "sparcv9-sun-solaris".into(), pointer_width: 64, - data_layout: "E-m:e-i64:64-n32:64-S128".to_string(), + data_layout: "E-m:e-i64:64-n32:64-S128".into(), // Use "sparc64" instead of "sparcv9" here, since the former is already // used widely in the source base. If we ever needed ABI // differentiation from the sparc64, we could, but that would probably // just be confusing. - arch: "sparc64".to_string(), + arch: "sparc64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/thumb_base.rs b/compiler/rustc_target/src/spec/thumb_base.rs index e2e528561e7..ef6038e6120 100644 --- a/compiler/rustc_target/src/spec/thumb_base.rs +++ b/compiler/rustc_target/src/spec/thumb_base.rs @@ -36,7 +36,7 @@ pub fn opts() -> TargetOptions { linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), executables: true, // In most cases, LLD is good enough - linker: Some("rust-lld".to_string()), + linker: Some("rust-lld".into()), // Because these devices have very little resources having an unwinder is too onerous so we // default to "abort" because the "unwind" strategy is very rare. panic_strategy: PanicStrategy::Abort, diff --git a/compiler/rustc_target/src/spec/thumbv4t_none_eabi.rs b/compiler/rustc_target/src/spec/thumbv4t_none_eabi.rs index f86efd5d0f4..8d6130a8a79 100644 --- a/compiler/rustc_target/src/spec/thumbv4t_none_eabi.rs +++ b/compiler/rustc_target/src/spec/thumbv4t_none_eabi.rs @@ -8,13 +8,13 @@ //! //! **Important:** This target profile **does not** specify a linker script. You just get the default link script when you build a binary for this target. The default link script is very likely wrong, so you should use `-Clink-arg=-Tmy_script.ld` to override that with a correct linker script. -use crate::spec::{LinkerFlavor, Target, TargetOptions}; +use crate::spec::{cvs, LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "thumbv4t-none-eabi".to_string(), + llvm_target: "thumbv4t-none-eabi".into(), pointer_width: 32, - arch: "arm".to_string(), + arch: "arm".into(), /* Data layout args are '-' separated: * little endian * stack is 64-bit aligned (EABI) @@ -24,24 +24,20 @@ pub fn target() -> Target { * native integers are 32-bit * All other elements are default */ - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), options: TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), linker_flavor: LinkerFlavor::Ld, - linker: Some("arm-none-eabi-ld".to_string()), + linker: Some("arm-none-eabi-ld".into()), // extra args passed to the external assembler (assuming `arm-none-eabi-as`): // * activate t32/a32 interworking // * use arch ARMv4T // * use little-endian - asm_args: vec![ - "-mthumb-interwork".to_string(), - "-march=armv4t".to_string(), - "-mlittle-endian".to_string(), - ], + asm_args: cvs!["-mthumb-interwork", "-march=armv4t", "-mlittle-endian",], // minimum extra features, these cannot be disabled via -C - features: "+soft-float,+strict-align".to_string(), + features: "+soft-float,+strict-align".into(), main_needs_argc_argv: false, diff --git a/compiler/rustc_target/src/spec/thumbv6m_none_eabi.rs b/compiler/rustc_target/src/spec/thumbv6m_none_eabi.rs index 40e3281060f..2546ab9b7e6 100644 --- a/compiler/rustc_target/src/spec/thumbv6m_none_eabi.rs +++ b/compiler/rustc_target/src/spec/thumbv6m_none_eabi.rs @@ -4,16 +4,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "thumbv6m-none-eabi".to_string(), + llvm_target: "thumbv6m-none-eabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), // The ARMv6-M architecture doesn't support unaligned loads/stores so we disable them // with +strict-align. - features: "+strict-align".to_string(), + features: "+strict-align".into(), // There are no atomic CAS instructions available in the instruction set of the ARMv6-M // architecture atomic_cas: false, diff --git a/compiler/rustc_target/src/spec/thumbv7a_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/thumbv7a_pc_windows_msvc.rs index 369e6cd5e93..f6cbbd38cf4 100644 --- a/compiler/rustc_target/src/spec/thumbv7a_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/thumbv7a_pc_windows_msvc.rs @@ -9,20 +9,20 @@ pub fn target() -> Target { // should be smart enough to insert branch islands only // where necessary, but this is not the observed behavior. // Disabling the LBR optimization works around the issue. - let pre_link_args_msvc = "/OPT:NOLBR".to_string(); - base.pre_link_args.entry(LinkerFlavor::Msvc).or_default().push(pre_link_args_msvc.clone()); + let pre_link_args_msvc = "/OPT:NOLBR"; + base.pre_link_args.entry(LinkerFlavor::Msvc).or_default().push(pre_link_args_msvc.into()); base.pre_link_args .entry(LinkerFlavor::Lld(LldFlavor::Link)) .or_default() - .push(pre_link_args_msvc); + .push(pre_link_args_msvc.into()); Target { - llvm_target: "thumbv7a-pc-windows-msvc".to_string(), + llvm_target: "thumbv7a-pc-windows-msvc".into(), pointer_width: 32, - data_layout: "e-m:w-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:w-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - features: "+vfp3,+neon".to_string(), + features: "+vfp3,+neon".into(), max_atomic_width: Some(64), // FIXME(jordanrh): use PanicStrategy::Unwind when SEH is // implemented for windows/arm in LLVM diff --git a/compiler/rustc_target/src/spec/thumbv7a_uwp_windows_msvc.rs b/compiler/rustc_target/src/spec/thumbv7a_uwp_windows_msvc.rs index 72d39ef9a95..65c2f5a704b 100644 --- a/compiler/rustc_target/src/spec/thumbv7a_uwp_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/thumbv7a_uwp_windows_msvc.rs @@ -2,12 +2,12 @@ use crate::spec::{PanicStrategy, Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "thumbv7a-pc-windows-msvc".to_string(), + llvm_target: "thumbv7a-pc-windows-msvc".into(), pointer_width: 32, - data_layout: "e-m:w-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:w-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - features: "+vfp3,+neon".to_string(), + features: "+vfp3,+neon".into(), max_atomic_width: Some(64), // FIXME(jordanrh): use PanicStrategy::Unwind when SEH is // implemented for windows/arm in LLVM diff --git a/compiler/rustc_target/src/spec/thumbv7em_none_eabi.rs b/compiler/rustc_target/src/spec/thumbv7em_none_eabi.rs index 107474a86bb..000e5f2d3c6 100644 --- a/compiler/rustc_target/src/spec/thumbv7em_none_eabi.rs +++ b/compiler/rustc_target/src/spec/thumbv7em_none_eabi.rs @@ -13,13 +13,13 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "thumbv7em-none-eabi".to_string(), + llvm_target: "thumbv7em-none-eabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), max_atomic_width: Some(32), ..super::thumb_base::opts() }, diff --git a/compiler/rustc_target/src/spec/thumbv7em_none_eabihf.rs b/compiler/rustc_target/src/spec/thumbv7em_none_eabihf.rs index 65fc0db6528..39a72564e49 100644 --- a/compiler/rustc_target/src/spec/thumbv7em_none_eabihf.rs +++ b/compiler/rustc_target/src/spec/thumbv7em_none_eabihf.rs @@ -12,13 +12,13 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "thumbv7em-none-eabihf".to_string(), + llvm_target: "thumbv7em-none-eabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), // `+vfp4` is the lowest common denominator between the Cortex-M4 (vfp4-16) and the // Cortex-M7 (vfp5) // `-d32` both the Cortex-M4 and the Cortex-M7 only have 16 double-precision registers @@ -28,7 +28,7 @@ pub fn target() -> Target { // // Reference: // ARMv7-M Architecture Reference Manual - A2.5 The optional floating-point extension - features: "+vfp4,-d32,-fp64".to_string(), + features: "+vfp4,-d32,-fp64".into(), max_atomic_width: Some(32), ..super::thumb_base::opts() }, diff --git a/compiler/rustc_target/src/spec/thumbv7m_none_eabi.rs b/compiler/rustc_target/src/spec/thumbv7m_none_eabi.rs index ff939348c35..ab25cde66c7 100644 --- a/compiler/rustc_target/src/spec/thumbv7m_none_eabi.rs +++ b/compiler/rustc_target/src/spec/thumbv7m_none_eabi.rs @@ -4,13 +4,13 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "thumbv7m-none-eabi".to_string(), + llvm_target: "thumbv7m-none-eabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), max_atomic_width: Some(32), ..super::thumb_base::opts() }, diff --git a/compiler/rustc_target/src/spec/thumbv7neon_linux_androideabi.rs b/compiler/rustc_target/src/spec/thumbv7neon_linux_androideabi.rs index fcb7b5d718c..9a3e8b5c5f8 100644 --- a/compiler/rustc_target/src/spec/thumbv7neon_linux_androideabi.rs +++ b/compiler/rustc_target/src/spec/thumbv7neon_linux_androideabi.rs @@ -10,15 +10,15 @@ use crate::spec::{LinkerFlavor, Target, TargetOptions}; pub fn target() -> Target { let mut base = super::android_base::opts(); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-march=armv7-a".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-march=armv7-a".into()); Target { - llvm_target: "armv7-none-linux-android".to_string(), + llvm_target: "armv7-none-linux-android".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), - features: "+v7,+thumb-mode,+thumb2,+vfp3,+neon".to_string(), + abi: "eabi".into(), + features: "+v7,+thumb-mode,+thumb2,+vfp3,+neon".into(), max_atomic_width: Some(64), ..base }, diff --git a/compiler/rustc_target/src/spec/thumbv7neon_unknown_linux_gnueabihf.rs b/compiler/rustc_target/src/spec/thumbv7neon_unknown_linux_gnueabihf.rs index 9d34d9ac874..28c81340ad8 100644 --- a/compiler/rustc_target/src/spec/thumbv7neon_unknown_linux_gnueabihf.rs +++ b/compiler/rustc_target/src/spec/thumbv7neon_unknown_linux_gnueabihf.rs @@ -8,14 +8,14 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "armv7-unknown-linux-gnueabihf".to_string(), + llvm_target: "armv7-unknown-linux-gnueabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), // Info about features at https://wiki.debian.org/ArmHardFloatPort - features: "+v7,+thumb-mode,+thumb2,+vfp3,+neon".to_string(), + features: "+v7,+thumb-mode,+thumb2,+vfp3,+neon".into(), max_atomic_width: Some(64), ..super::linux_gnu_base::opts() }, diff --git a/compiler/rustc_target/src/spec/thumbv7neon_unknown_linux_musleabihf.rs b/compiler/rustc_target/src/spec/thumbv7neon_unknown_linux_musleabihf.rs index 4e339cbd6be..2c375ab22d7 100644 --- a/compiler/rustc_target/src/spec/thumbv7neon_unknown_linux_musleabihf.rs +++ b/compiler/rustc_target/src/spec/thumbv7neon_unknown_linux_musleabihf.rs @@ -11,18 +11,18 @@ pub fn target() -> Target { // It's important we use "gnueabihf" and not "musleabihf" here. LLVM // uses it to determine the calling convention and float ABI, and LLVM // doesn't support the "musleabihf" value. - llvm_target: "armv7-unknown-linux-gnueabihf".to_string(), + llvm_target: "armv7-unknown-linux-gnueabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), // Most of these settings are copied from the thumbv7neon_unknown_linux_gnueabihf // target. options: TargetOptions { - abi: "eabihf".to_string(), - features: "+v7,+thumb-mode,+thumb2,+vfp3,+neon".to_string(), + abi: "eabihf".into(), + features: "+v7,+thumb-mode,+thumb2,+vfp3,+neon".into(), max_atomic_width: Some(64), - mcount: "\u{1}mcount".to_string(), + mcount: "\u{1}mcount".into(), ..super::linux_musl_base::opts() }, } diff --git a/compiler/rustc_target/src/spec/thumbv8m_base_none_eabi.rs b/compiler/rustc_target/src/spec/thumbv8m_base_none_eabi.rs index ef0f52d2199..756b1834c82 100644 --- a/compiler/rustc_target/src/spec/thumbv8m_base_none_eabi.rs +++ b/compiler/rustc_target/src/spec/thumbv8m_base_none_eabi.rs @@ -4,16 +4,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "thumbv8m.base-none-eabi".to_string(), + llvm_target: "thumbv8m.base-none-eabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), // ARMv8-M baseline doesn't support unaligned loads/stores so we disable them // with +strict-align. - features: "+strict-align".to_string(), + features: "+strict-align".into(), max_atomic_width: Some(32), ..super::thumb_base::opts() }, diff --git a/compiler/rustc_target/src/spec/thumbv8m_main_none_eabi.rs b/compiler/rustc_target/src/spec/thumbv8m_main_none_eabi.rs index dbd184debcb..4b626854654 100644 --- a/compiler/rustc_target/src/spec/thumbv8m_main_none_eabi.rs +++ b/compiler/rustc_target/src/spec/thumbv8m_main_none_eabi.rs @@ -5,13 +5,13 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "thumbv8m.main-none-eabi".to_string(), + llvm_target: "thumbv8m.main-none-eabi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabi".to_string(), + abi: "eabi".into(), max_atomic_width: Some(32), ..super::thumb_base::opts() }, diff --git a/compiler/rustc_target/src/spec/thumbv8m_main_none_eabihf.rs b/compiler/rustc_target/src/spec/thumbv8m_main_none_eabihf.rs index 3caf705421c..86c25f9e4b9 100644 --- a/compiler/rustc_target/src/spec/thumbv8m_main_none_eabihf.rs +++ b/compiler/rustc_target/src/spec/thumbv8m_main_none_eabihf.rs @@ -5,19 +5,19 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { Target { - llvm_target: "thumbv8m.main-none-eabihf".to_string(), + llvm_target: "thumbv8m.main-none-eabihf".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), - arch: "arm".to_string(), + data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(), + arch: "arm".into(), options: TargetOptions { - abi: "eabihf".to_string(), + abi: "eabihf".into(), // If the Floating Point extension is implemented in the Cortex-M33 // processor, the Cortex-M33 Technical Reference Manual states that // the FPU uses the FPv5 architecture, single-precision instructions // and 16 D registers. // These parameters map to the following LLVM features. - features: "+fp-armv8,-fp64,-d32".to_string(), + features: "+fp-armv8,-fp64,-d32".into(), max_atomic_width: Some(32), ..super::thumb_base::opts() }, diff --git a/compiler/rustc_target/src/spec/uefi_msvc_base.rs b/compiler/rustc_target/src/spec/uefi_msvc_base.rs index 6b6b6018601..bc7244b3a45 100644 --- a/compiler/rustc_target/src/spec/uefi_msvc_base.rs +++ b/compiler/rustc_target/src/spec/uefi_msvc_base.rs @@ -18,7 +18,7 @@ pub fn opts() -> TargetOptions { // Non-standard subsystems have no default entry-point in PE+ files. We have to define // one. "efi_main" seems to be a common choice amongst other implementations and the // spec. - "/entry:efi_main".to_string(), + "/entry:efi_main".into(), // COFF images have a "Subsystem" field in their header, which defines what kind of // program it is. UEFI has 3 fields reserved, which are EFI_APPLICATION, // EFI_BOOT_SERVICE_DRIVER, and EFI_RUNTIME_DRIVER. We default to EFI_APPLICATION, @@ -28,7 +28,7 @@ pub fn opts() -> TargetOptions { // regions the application is loaded into (runtime-drivers need to be put into // reserved areas), as well as whether a return from the entry-point is treated as // exit (default for applications). - "/subsystem:efi_application".to_string(), + "/subsystem:efi_application".into(), ]; base.pre_link_args.entry(LinkerFlavor::Msvc).or_default().extend(pre_link_args_msvc.clone()); base.pre_link_args @@ -37,17 +37,17 @@ pub fn opts() -> TargetOptions { .extend(pre_link_args_msvc); TargetOptions { - os: "uefi".to_string(), + os: "uefi".into(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Link), disable_redzone: true, - exe_suffix: ".efi".to_string(), + exe_suffix: ".efi".into(), allows_weak_linkage: false, panic_strategy: PanicStrategy::Abort, // LLVM does not emit inline assembly because the LLVM target does not get considered as… // "Windows". stack_probes: StackProbeType::Call, singlethread: true, - linker: Some("rust-lld".to_string()), + linker: Some("rust-lld".into()), ..base } } diff --git a/compiler/rustc_target/src/spec/vxworks_base.rs b/compiler/rustc_target/src/spec/vxworks_base.rs index 3f709e70234..2beb279e398 100644 --- a/compiler/rustc_target/src/spec/vxworks_base.rs +++ b/compiler/rustc_target/src/spec/vxworks_base.rs @@ -1,22 +1,22 @@ -use crate::spec::TargetOptions; +use crate::spec::{cvs, TargetOptions}; pub fn opts() -> TargetOptions { TargetOptions { - os: "vxworks".to_string(), - env: "gnu".to_string(), - vendor: "wrs".to_string(), - linker: Some("wr-c++".to_string()), - exe_suffix: ".vxe".to_string(), + os: "vxworks".into(), + env: "gnu".into(), + vendor: "wrs".into(), + linker: Some("wr-c++".into()), + exe_suffix: ".vxe".into(), dynamic_linking: true, executables: true, - families: vec!["unix".to_string()], + families: cvs!["unix"], has_rpath: true, has_thread_local: true, crt_static_default: true, crt_static_respected: true, crt_static_allows_dylibs: true, // VxWorks needs to implement this to support profiling - mcount: "_mcount".to_string(), + mcount: "_mcount".into(), ..Default::default() } } diff --git a/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs b/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs index 8fcdbc146af..b34cac41d78 100644 --- a/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs +++ b/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs @@ -1,4 +1,4 @@ -use super::wasm_base; +use super::{cvs, wasm_base}; use super::{LinkArgs, LinkerFlavor, PanicStrategy, Target, TargetOptions}; pub fn target() -> Target { @@ -11,41 +11,40 @@ pub fn target() -> Target { // however it does have the side effect of automatically exporting a lot // of symbols, which approximates what people want when compiling for // wasm32-unknown-unknown expect, so use it for now. - clang_args.push("--export-dynamic".to_string()); + clang_args.push("--export-dynamic".into()); let mut post_link_args = LinkArgs::new(); post_link_args.insert( LinkerFlavor::Em, vec![ - "-s".to_string(), - "ERROR_ON_UNDEFINED_SYMBOLS=1".to_string(), - "-s".to_string(), - "ASSERTIONS=1".to_string(), - "-s".to_string(), - "ABORTING_MALLOC=0".to_string(), - "-Wl,--fatal-warnings".to_string(), + "-s".into(), + "ERROR_ON_UNDEFINED_SYMBOLS=1".into(), + "-s".into(), + "ASSERTIONS=1".into(), + "-s".into(), + "ABORTING_MALLOC=0".into(), + "-Wl,--fatal-warnings".into(), ], ); let opts = TargetOptions { - os: "emscripten".to_string(), + os: "emscripten".into(), linker_flavor: LinkerFlavor::Em, // emcc emits two files - a .js file to instantiate the wasm and supply platform // functionality, and a .wasm file. - exe_suffix: ".js".to_string(), + exe_suffix: ".js".into(), linker: None, is_like_emscripten: true, panic_strategy: PanicStrategy::Unwind, post_link_args, - families: vec!["unix".to_string(), "wasm".to_string()], + families: cvs!["unix", "wasm"], ..options }; Target { - llvm_target: "wasm32-unknown-emscripten".to_string(), + llvm_target: "wasm32-unknown-emscripten".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20" - .to_string(), - arch: "wasm32".to_string(), + data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20".into(), + arch: "wasm32".into(), options: opts, } } diff --git a/compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs b/compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs index e50cf974094..214b5fce5a6 100644 --- a/compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/wasm32_unknown_unknown.rs @@ -16,7 +16,7 @@ use crate::spec::abi::Abi; pub fn target() -> Target { let mut options = wasm_base::options(); - options.os = "unknown".to_string(); + options.os = "unknown".into(); options.linker_flavor = LinkerFlavor::Lld(LldFlavor::Wasm); // This is a default for backwards-compatibility with the original @@ -33,29 +33,29 @@ pub fn target() -> Target { // Make sure clang uses LLD as its linker and is configured appropriately // otherwise - clang_args.push("--target=wasm32-unknown-unknown".to_string()); + clang_args.push("--target=wasm32-unknown-unknown".into()); // For now this target just never has an entry symbol no matter the output // type, so unconditionally pass this. - clang_args.push("-Wl,--no-entry".to_string()); + clang_args.push("-Wl,--no-entry".into()); // Rust really needs a way for users to specify exports and imports in // the source code. --export-dynamic isn't the right tool for this job, // however it does have the side effect of automatically exporting a lot // of symbols, which approximates what people want when compiling for // wasm32-unknown-unknown expect, so use it for now. - clang_args.push("-Wl,--export-dynamic".to_string()); + clang_args.push("-Wl,--export-dynamic".into()); // Add the flags to wasm-ld's args too. let lld_args = options.pre_link_args.entry(LinkerFlavor::Lld(LldFlavor::Wasm)).or_default(); - lld_args.push("--no-entry".to_string()); - lld_args.push("--export-dynamic".to_string()); + lld_args.push("--no-entry".into()); + lld_args.push("--export-dynamic".into()); Target { - llvm_target: "wasm32-unknown-unknown".to_string(), + llvm_target: "wasm32-unknown-unknown".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".to_string(), - arch: "wasm32".to_string(), + data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".into(), + arch: "wasm32".into(), options, } } diff --git a/compiler/rustc_target/src/spec/wasm32_wasi.rs b/compiler/rustc_target/src/spec/wasm32_wasi.rs index a4b81c9a278..10eb78e4e25 100644 --- a/compiler/rustc_target/src/spec/wasm32_wasi.rs +++ b/compiler/rustc_target/src/spec/wasm32_wasi.rs @@ -78,13 +78,13 @@ use super::{crt_objects, LinkerFlavor, LldFlavor, Target}; pub fn target() -> Target { let mut options = wasm_base::options(); - options.os = "wasi".to_string(); + options.os = "wasi".into(); options.linker_flavor = LinkerFlavor::Lld(LldFlavor::Wasm); options .pre_link_args .entry(LinkerFlavor::Gcc) .or_insert(Vec::new()) - .push("--target=wasm32-wasi".to_string()); + .push("--target=wasm32-wasi".into()); options.pre_link_objects_fallback = crt_objects::pre_wasi_fallback(); options.post_link_objects_fallback = crt_objects::post_wasi_fallback(); @@ -107,10 +107,10 @@ pub fn target() -> Target { options.main_needs_argc_argv = false; Target { - llvm_target: "wasm32-wasi".to_string(), + llvm_target: "wasm32-wasi".into(), pointer_width: 32, - data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".to_string(), - arch: "wasm32".to_string(), + data_layout: "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20".into(), + arch: "wasm32".into(), options, } } diff --git a/compiler/rustc_target/src/spec/wasm64_unknown_unknown.rs b/compiler/rustc_target/src/spec/wasm64_unknown_unknown.rs index 6b7dfbb87d2..609b7d42e43 100644 --- a/compiler/rustc_target/src/spec/wasm64_unknown_unknown.rs +++ b/compiler/rustc_target/src/spec/wasm64_unknown_unknown.rs @@ -12,32 +12,32 @@ use super::{LinkerFlavor, LldFlavor, Target}; pub fn target() -> Target { let mut options = wasm_base::options(); - options.os = "unknown".to_string(); + options.os = "unknown".into(); options.linker_flavor = LinkerFlavor::Lld(LldFlavor::Wasm); let clang_args = options.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap(); // Make sure clang uses LLD as its linker and is configured appropriately // otherwise - clang_args.push("--target=wasm64-unknown-unknown".to_string()); + clang_args.push("--target=wasm64-unknown-unknown".into()); // For now this target just never has an entry symbol no matter the output // type, so unconditionally pass this. - clang_args.push("-Wl,--no-entry".to_string()); + clang_args.push("-Wl,--no-entry".into()); let lld_args = options.pre_link_args.get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm)).unwrap(); - lld_args.push("--no-entry".to_string()); - lld_args.push("-mwasm64".to_string()); + lld_args.push("--no-entry".into()); + lld_args.push("-mwasm64".into()); // Any engine that implements wasm64 will surely implement the rest of these // features since they were all merged into the official spec by the time // wasm64 was designed. - options.features = "+bulk-memory,+mutable-globals,+sign-ext,+nontrapping-fptoint".to_string(); + options.features = "+bulk-memory,+mutable-globals,+sign-ext,+nontrapping-fptoint".into(); Target { - llvm_target: "wasm64-unknown-unknown".to_string(), + llvm_target: "wasm64-unknown-unknown".into(), pointer_width: 64, - data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20".to_string(), - arch: "wasm64".to_string(), + data_layout: "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20".into(), + arch: "wasm64".into(), options, } } diff --git a/compiler/rustc_target/src/spec/wasm_base.rs b/compiler/rustc_target/src/spec/wasm_base.rs index e1a23b213f0..de7b7374af3 100644 --- a/compiler/rustc_target/src/spec/wasm_base.rs +++ b/compiler/rustc_target/src/spec/wasm_base.rs @@ -1,13 +1,13 @@ use super::crt_objects::CrtObjectsFallback; -use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, TargetOptions, TlsModel}; +use super::{cvs, LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, TargetOptions, TlsModel}; use std::collections::BTreeMap; pub fn options() -> TargetOptions { let mut lld_args = Vec::new(); let mut clang_args = Vec::new(); - let mut arg = |arg: &str| { - lld_args.push(arg.to_string()); - clang_args.push(format!("-Wl,{}", arg)); + let mut arg = |arg: &'static str| { + lld_args.push(arg.into()); + clang_args.push(format!("-Wl,{}", arg).into()); }; // By default LLD only gives us one page of stack (64k) which is a @@ -61,7 +61,7 @@ pub fn options() -> TargetOptions { TargetOptions { is_like_wasm: true, - families: vec!["wasm".to_string()], + families: cvs!["wasm"], // we allow dynamic linking, but only cdylibs. Basically we allow a // final library artifact that exports some symbols (a wasm module) but @@ -73,9 +73,9 @@ pub fn options() -> TargetOptions { executables: true, // relatively self-explanatory! - exe_suffix: ".wasm".to_string(), - dll_prefix: String::new(), - dll_suffix: ".wasm".to_string(), + exe_suffix: ".wasm".into(), + dll_prefix: "".into(), + dll_suffix: ".wasm".into(), eh_frame_header: false, max_atomic_width: Some(64), @@ -100,7 +100,7 @@ pub fn options() -> TargetOptions { limit_rdylib_exports: false, // we use the LLD shipped with the Rust toolchain by default - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), lld_flavor: LldFlavor::Wasm, linker_is_gnu: false, diff --git a/compiler/rustc_target/src/spec/windows_gnu_base.rs b/compiler/rustc_target/src/spec/windows_gnu_base.rs index 35a52896f6f..d11f1f7d3f8 100644 --- a/compiler/rustc_target/src/spec/windows_gnu_base.rs +++ b/compiler/rustc_target/src/spec/windows_gnu_base.rs @@ -1,5 +1,5 @@ use crate::spec::crt_objects::{self, CrtObjectsFallback}; -use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, TargetOptions}; +use crate::spec::{cvs, LinkArgs, LinkerFlavor, LldFlavor, TargetOptions}; pub fn opts() -> TargetOptions { let mut pre_link_args = LinkArgs::new(); @@ -8,11 +8,11 @@ pub fn opts() -> TargetOptions { vec![ // Tell GCC to avoid linker plugins, because we are not bundling // them with Windows installer, and Rust does its own LTO anyways. - "-fno-use-linker-plugin".to_string(), + "-fno-use-linker-plugin".into(), // Enable ASLR - "-Wl,--dynamicbase".to_string(), + "-Wl,--dynamicbase".into(), // ASLR will rebase it anyway so leaving that option enabled only leads to confusion - "-Wl,--disable-auto-image-base".to_string(), + "-Wl,--disable-auto-image-base".into(), ], ); @@ -22,10 +22,10 @@ pub fn opts() -> TargetOptions { // Order of `late_link_args*` was found through trial and error to work with various // mingw-w64 versions (not tested on the CI). It's expected to change from time to time. let mingw_libs = vec![ - "-lmsvcrt".to_string(), - "-lmingwex".to_string(), - "-lmingw32".to_string(), - "-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc + "-lmsvcrt".into(), + "-lmingwex".into(), + "-lmingw32".into(), + "-lgcc".into(), // alas, mingw* libraries above depend on libgcc // mingw's msvcrt is a weird hybrid import library and static library. // And it seems that the linker fails to use import symbols from msvcrt // that are required from functions in msvcrt in certain cases. For example @@ -33,9 +33,9 @@ pub fn opts() -> TargetOptions { // The library is purposely listed twice to fix that. // // See https://github.com/rust-lang/rust/pull/47483 for some more details. - "-lmsvcrt".to_string(), - "-luser32".to_string(), - "-lkernel32".to_string(), + "-lmsvcrt".into(), + "-luser32".into(), + "-lkernel32".into(), ]; late_link_args.insert(LinkerFlavor::Gcc, mingw_libs.clone()); late_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), mingw_libs); @@ -43,7 +43,7 @@ pub fn opts() -> TargetOptions { // If any of our crates are dynamically linked then we need to use // the shared libgcc_s-dw2-1.dll. This is required to support // unwinding across DLL boundaries. - "-lgcc_s".to_string(), + "-lgcc_s".into(), ]; late_link_args_dynamic.insert(LinkerFlavor::Gcc, dynamic_unwind_libs.clone()); late_link_args_dynamic.insert(LinkerFlavor::Lld(LldFlavor::Ld), dynamic_unwind_libs); @@ -53,25 +53,25 @@ pub fn opts() -> TargetOptions { // binaries to be redistributed without the libgcc_s-dw2-1.dll // dependency, but unfortunately break unwinding across DLL // boundaries when unwinding across FFI boundaries. - "-lgcc_eh".to_string(), - "-l:libpthread.a".to_string(), + "-lgcc_eh".into(), + "-l:libpthread.a".into(), ]; late_link_args_static.insert(LinkerFlavor::Gcc, static_unwind_libs.clone()); late_link_args_static.insert(LinkerFlavor::Lld(LldFlavor::Ld), static_unwind_libs); TargetOptions { - os: "windows".to_string(), - env: "gnu".to_string(), - vendor: "pc".to_string(), + os: "windows".into(), + env: "gnu".into(), + vendor: "pc".into(), // FIXME(#13846) this should be enabled for windows function_sections: false, - linker: Some("gcc".to_string()), + linker: Some("gcc".into()), dynamic_linking: true, executables: true, - dll_prefix: String::new(), - dll_suffix: ".dll".to_string(), - exe_suffix: ".exe".to_string(), - families: vec!["windows".to_string()], + dll_prefix: "".into(), + dll_suffix: ".dll".into(), + exe_suffix: ".exe".into(), + families: cvs!["windows"], is_like_windows: true, allows_weak_linkage: false, pre_link_args, @@ -87,7 +87,6 @@ pub fn opts() -> TargetOptions { emit_debug_gdb_scripts: false, requires_uwtable: true, eh_frame_header: false, - ..Default::default() } } diff --git a/compiler/rustc_target/src/spec/windows_msvc_base.rs b/compiler/rustc_target/src/spec/windows_msvc_base.rs index 063b6538d95..21062c337d8 100644 --- a/compiler/rustc_target/src/spec/windows_msvc_base.rs +++ b/compiler/rustc_target/src/spec/windows_msvc_base.rs @@ -1,19 +1,19 @@ -use crate::spec::TargetOptions; +use crate::spec::{cvs, TargetOptions}; pub fn opts() -> TargetOptions { let base = super::msvc_base::opts(); TargetOptions { - os: "windows".to_string(), - env: "msvc".to_string(), - vendor: "pc".to_string(), + os: "windows".into(), + env: "msvc".into(), + vendor: "pc".into(), dynamic_linking: true, - dll_prefix: String::new(), - dll_suffix: ".dll".to_string(), - exe_suffix: ".exe".to_string(), - staticlib_prefix: String::new(), - staticlib_suffix: ".lib".to_string(), - families: vec!["windows".to_string()], + dll_prefix: "".into(), + dll_suffix: ".dll".into(), + exe_suffix: ".exe".into(), + staticlib_prefix: "".into(), + staticlib_suffix: ".lib".into(), + families: cvs!["windows"], crt_static_allows_dylibs: true, crt_static_respected: true, requires_uwtable: true, diff --git a/compiler/rustc_target/src/spec/windows_uwp_gnu_base.rs b/compiler/rustc_target/src/spec/windows_uwp_gnu_base.rs index 86df816f10d..11968391776 100644 --- a/compiler/rustc_target/src/spec/windows_uwp_gnu_base.rs +++ b/compiler/rustc_target/src/spec/windows_uwp_gnu_base.rs @@ -9,24 +9,24 @@ pub fn opts() -> TargetOptions { let late_link_args_dynamic = LinkArgs::new(); let late_link_args_static = LinkArgs::new(); let mingw_libs = vec![ - //"-lwinstorecompat".to_string(), - //"-lmingwex".to_string(), - //"-lwinstorecompat".to_string(), - "-lwinstorecompat".to_string(), - "-lruntimeobject".to_string(), - "-lsynchronization".to_string(), - "-lvcruntime140_app".to_string(), - "-lucrt".to_string(), - "-lwindowsapp".to_string(), - "-lmingwex".to_string(), - "-lmingw32".to_string(), + //"-lwinstorecompat".into(), + //"-lmingwex".into(), + //"-lwinstorecompat".into(), + "-lwinstorecompat".into(), + "-lruntimeobject".into(), + "-lsynchronization".into(), + "-lvcruntime140_app".into(), + "-lucrt".into(), + "-lwindowsapp".into(), + "-lmingwex".into(), + "-lmingw32".into(), ]; late_link_args.insert(LinkerFlavor::Gcc, mingw_libs.clone()); late_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), mingw_libs); TargetOptions { - abi: "uwp".to_string(), - vendor: "uwp".to_string(), + abi: "uwp".into(), + vendor: "uwp".into(), executables: false, limit_rdylib_exports: false, late_link_args, diff --git a/compiler/rustc_target/src/spec/windows_uwp_msvc_base.rs b/compiler/rustc_target/src/spec/windows_uwp_msvc_base.rs index 7b56b468c28..d6b065b529a 100644 --- a/compiler/rustc_target/src/spec/windows_uwp_msvc_base.rs +++ b/compiler/rustc_target/src/spec/windows_uwp_msvc_base.rs @@ -3,9 +3,9 @@ use crate::spec::{LinkerFlavor, LldFlavor, TargetOptions}; pub fn opts() -> TargetOptions { let mut opts = super::windows_msvc_base::opts(); - opts.abi = "uwp".to_string(); - opts.vendor = "uwp".to_string(); - let pre_link_args_msvc = vec!["/APPCONTAINER".to_string(), "mincore.lib".to_string()]; + opts.abi = "uwp".into(); + opts.vendor = "uwp".into(); + let pre_link_args_msvc = vec!["/APPCONTAINER".into(), "mincore.lib".into()]; opts.pre_link_args.entry(LinkerFlavor::Msvc).or_default().extend(pre_link_args_msvc.clone()); opts.pre_link_args .entry(LinkerFlavor::Lld(LldFlavor::Link)) diff --git a/compiler/rustc_target/src/spec/x86_64_apple_darwin.rs b/compiler/rustc_target/src/spec/x86_64_apple_darwin.rs index 22fdaabfcb8..51d14f0403a 100644 --- a/compiler/rustc_target/src/spec/x86_64_apple_darwin.rs +++ b/compiler/rustc_target/src/spec/x86_64_apple_darwin.rs @@ -3,14 +3,12 @@ use crate::spec::{FramePointer, LinkerFlavor, SanitizerSet, StackProbeType, Targ pub fn target() -> Target { let mut base = super::apple_base::opts("macos"); - base.cpu = "core2".to_string(); + base.cpu = "core2".into(); base.max_atomic_width = Some(128); // core2 support cmpxchg16b base.frame_pointer = FramePointer::Always; - base.pre_link_args.insert( - LinkerFlavor::Gcc, - vec!["-m64".to_string(), "-arch".to_string(), "x86_64".to_string()], - ); - base.link_env_remove.extend(super::apple_base::macos_link_env_remove()); + base.pre_link_args + .insert(LinkerFlavor::Gcc, vec!["-m64".into(), "-arch".into(), "x86_64".into()]); + base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; base.supported_sanitizers = @@ -23,11 +21,11 @@ pub fn target() -> Target { let llvm_target = super::apple_base::macos_llvm_target(&arch); Target { - llvm_target, + llvm_target: llvm_target.into(), pointer_width: 64, data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: arch.to_string(), - options: TargetOptions { mcount: "\u{1}mcount".to_string(), ..base }, + .into(), + arch: arch.into(), + options: TargetOptions { mcount: "\u{1}mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/x86_64_apple_ios.rs b/compiler/rustc_target/src/spec/x86_64_apple_ios.rs index 6e20bd23f17..5e64ed0cff6 100644 --- a/compiler/rustc_target/src/spec/x86_64_apple_ios.rs +++ b/compiler/rustc_target/src/spec/x86_64_apple_ios.rs @@ -3,12 +3,14 @@ use crate::spec::{StackProbeType, Target, TargetOptions}; pub fn target() -> Target { let base = opts("ios", Arch::X86_64); + let llvm_target = super::apple_base::ios_sim_llvm_target("x86_64"); + Target { - llvm_target: super::apple_base::ios_sim_llvm_target("x86_64"), + llvm_target: llvm_target.into(), pointer_width: 64, data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: TargetOptions { max_atomic_width: Some(64), // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved diff --git a/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs b/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs index c228e42ef30..c75632571ad 100644 --- a/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs +++ b/compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs @@ -4,11 +4,11 @@ use crate::spec::{StackProbeType, Target, TargetOptions}; pub fn target() -> Target { let base = opts("ios", Arch::X86_64_macabi); Target { - llvm_target: "x86_64-apple-ios13.0-macabi".to_string(), + llvm_target: "x86_64-apple-ios13.0-macabi".into(), pointer_width: 64, data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: TargetOptions { max_atomic_width: Some(64), // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved diff --git a/compiler/rustc_target/src/spec/x86_64_apple_tvos.rs b/compiler/rustc_target/src/spec/x86_64_apple_tvos.rs index e3a5de4cbd1..a848c5a0aff 100644 --- a/compiler/rustc_target/src/spec/x86_64_apple_tvos.rs +++ b/compiler/rustc_target/src/spec/x86_64_apple_tvos.rs @@ -4,10 +4,10 @@ use crate::spec::{StackProbeType, Target, TargetOptions}; pub fn target() -> Target { let base = opts("tvos", Arch::X86_64); Target { - llvm_target: "x86_64-apple-tvos".to_string(), + llvm_target: "x86_64-apple-tvos".into(), pointer_width: 64, - data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".to_string(), - arch: "x86_64".to_string(), + data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".into(), + arch: "x86_64".into(), options: TargetOptions { max_atomic_width: Some(64), // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved diff --git a/compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs b/compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs index 59cd56ebcd5..47c70513faf 100644 --- a/compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs +++ b/compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs @@ -1,4 +1,6 @@ -use std::iter; +use std::{borrow::Cow, iter}; + +use crate::spec::cvs; use super::{LinkerFlavor, LldFlavor, Target, TargetOptions}; @@ -58,18 +60,18 @@ pub fn target() -> Target { abi: "fortanix".into(), linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), executables: true, - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), max_atomic_width: Some(64), cpu: "x86-64".into(), features: "+rdrnd,+rdseed,+lvi-cfi,+lvi-load-hardening".into(), - llvm_args: vec!["--x86-experimental-lvi-inline-asm-hardening".into()], + llvm_args: cvs!["--x86-experimental-lvi-inline-asm-hardening"], position_independent_executables: true, pre_link_args: iter::once(( LinkerFlavor::Lld(LldFlavor::Ld), - PRE_LINK_ARGS.iter().cloned().map(String::from).collect(), + PRE_LINK_ARGS.iter().cloned().map(Cow::from).collect(), )) .collect(), - override_export_symbols: Some(EXPORT_SYMBOLS.iter().cloned().map(String::from).collect()), + override_export_symbols: Some(EXPORT_SYMBOLS.iter().cloned().map(Cow::from).collect()), relax_elf_relocations: true, ..Default::default() }; diff --git a/compiler/rustc_target/src/spec/x86_64_fuchsia.rs b/compiler/rustc_target/src/spec/x86_64_fuchsia.rs index c253c0c30b3..4f88fc3500b 100644 --- a/compiler/rustc_target/src/spec/x86_64_fuchsia.rs +++ b/compiler/rustc_target/src/spec/x86_64_fuchsia.rs @@ -2,18 +2,18 @@ use crate::spec::{SanitizerSet, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::fuchsia_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI; Target { - llvm_target: "x86_64-fuchsia".to_string(), + llvm_target: "x86_64-fuchsia".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_linux_android.rs b/compiler/rustc_target/src/spec/x86_64_linux_android.rs index 657520a8caf..049cab0d554 100644 --- a/compiler/rustc_target/src/spec/x86_64_linux_android.rs +++ b/compiler/rustc_target/src/spec/x86_64_linux_android.rs @@ -2,20 +2,20 @@ use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target, TargetOpti pub fn target() -> Target { let mut base = super::android_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); // https://developer.android.com/ndk/guides/abis.html#86-64 - base.features = "+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt".to_string(); + base.features = "+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "x86_64-linux-android".to_string(), + llvm_target: "x86_64-linux-android".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: TargetOptions { supported_sanitizers: SanitizerSet::ADDRESS, ..base }, } } diff --git a/compiler/rustc_target/src/spec/x86_64_pc_solaris.rs b/compiler/rustc_target/src/spec/x86_64_pc_solaris.rs index 6aa07286682..2a697daeb28 100644 --- a/compiler/rustc_target/src/spec/x86_64_pc_solaris.rs +++ b/compiler/rustc_target/src/spec/x86_64_pc_solaris.rs @@ -2,20 +2,20 @@ use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::solaris_base::opts(); - base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".to_string()]); - base.cpu = "x86-64".to_string(); - base.vendor = "pc".to_string(); + base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".into()]); + base.cpu = "x86-64".into(); + base.vendor = "pc".into(); base.max_atomic_width = Some(64); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI; Target { - llvm_target: "x86_64-pc-solaris".to_string(), + llvm_target: "x86_64-pc-solaris".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs b/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs index 26a81a484b9..0fa43481c9b 100644 --- a/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs +++ b/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs @@ -2,22 +2,22 @@ use crate::spec::{LinkerFlavor, LldFlavor, Target}; pub fn target() -> Target { let mut base = super::windows_gnu_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); let gcc_pre_link_args = base.pre_link_args.entry(LinkerFlavor::Gcc).or_default(); - gcc_pre_link_args.push("-m64".to_string()); + gcc_pre_link_args.push("-m64".into()); // Use high-entropy 64 bit address space for ASLR - gcc_pre_link_args.push("-Wl,--high-entropy-va".to_string()); + gcc_pre_link_args.push("-Wl,--high-entropy-va".into()); base.pre_link_args - .insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".to_string(), "i386pep".to_string()]); + .insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".into(), "i386pep".into()]); base.max_atomic_width = Some(64); - base.linker = Some("x86_64-w64-mingw32-gcc".to_string()); + base.linker = Some("x86_64-w64-mingw32-gcc".into()); Target { - llvm_target: "x86_64-pc-windows-gnu".to_string(), + llvm_target: "x86_64-pc-windows-gnu".into(), pointer_width: 64, data_layout: "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/x86_64_pc_windows_msvc.rs index 1c4ccebb488..081806aa698 100644 --- a/compiler/rustc_target/src/spec/x86_64_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/x86_64_pc_windows_msvc.rs @@ -2,15 +2,15 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::windows_msvc_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); Target { - llvm_target: "x86_64-pc-windows-msvc".to_string(), + llvm_target: "x86_64-pc-windows-msvc".into(), pointer_width: 64, data_layout: "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_sun_solaris.rs b/compiler/rustc_target/src/spec/x86_64_sun_solaris.rs index 2fa53470f74..a02018266fb 100644 --- a/compiler/rustc_target/src/spec/x86_64_sun_solaris.rs +++ b/compiler/rustc_target/src/spec/x86_64_sun_solaris.rs @@ -2,19 +2,19 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::solaris_base::opts(); - base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".to_string()]); - base.cpu = "x86-64".to_string(); - base.vendor = "sun".to_string(); + base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".into()]); + base.cpu = "x86-64".into(); + base.vendor = "sun".into(); base.max_atomic_width = Some(64); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "x86_64-pc-solaris".to_string(), + llvm_target: "x86_64-pc-solaris".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_dragonfly.rs b/compiler/rustc_target/src/spec/x86_64_unknown_dragonfly.rs index d69830f0a3f..1f2b998a7ba 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_dragonfly.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_dragonfly.rs @@ -2,18 +2,18 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::dragonfly_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "x86_64-unknown-dragonfly".to_string(), + llvm_target: "x86_64-unknown-dragonfly".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_freebsd.rs b/compiler/rustc_target/src/spec/x86_64_unknown_freebsd.rs index 24cc7ae788b..c9aedd6ea82 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_freebsd.rs @@ -2,20 +2,20 @@ use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::freebsd_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::MEMORY | SanitizerSet::THREAD; Target { - llvm_target: "x86_64-unknown-freebsd".to_string(), + llvm_target: "x86_64-unknown-freebsd".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_haiku.rs b/compiler/rustc_target/src/spec/x86_64_unknown_haiku.rs index fcd96ddd61b..aebbd18c66a 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_haiku.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_haiku.rs @@ -2,20 +2,20 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::haiku_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); - base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".to_string()]); + base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".into()]); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; // This option is required to build executables on Haiku x86_64 base.position_independent_executables = true; Target { - llvm_target: "x86_64-unknown-haiku".to_string(), + llvm_target: "x86_64-unknown-haiku".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_hermit.rs b/compiler/rustc_target/src/spec/x86_64_unknown_hermit.rs index 1ef24b6eb36..d315301615b 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_hermit.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_hermit.rs @@ -2,18 +2,18 @@ use crate::spec::{StackProbeType, Target}; pub fn target() -> Target { let mut base = super::hermit_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); - base.features = "+rdrnd,+rdseed".to_string(); + base.features = "+rdrnd,+rdseed".into(); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "x86_64-unknown-hermit".to_string(), + llvm_target: "x86_64-unknown-hermit".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_illumos.rs b/compiler/rustc_target/src/spec/x86_64_unknown_illumos.rs index 79ccf63acfa..9529fa9640d 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_illumos.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_illumos.rs @@ -2,19 +2,19 @@ use crate::spec::{LinkerFlavor, SanitizerSet, Target}; pub fn target() -> Target { let mut base = super::illumos_base::opts(); - base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".to_string(), "-std=c99".to_string()]); - base.cpu = "x86-64".to_string(); + base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".into(), "-std=c99".into()]); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI; Target { // LLVM does not currently have a separate illumos target, // so we still pass Solaris to it - llvm_target: "x86_64-pc-solaris".to_string(), + llvm_target: "x86_64-pc-solaris".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs b/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs index 64c7c1c5f6f..78189a0c096 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_l4re_uclibc.rs @@ -2,18 +2,18 @@ use crate::spec::{PanicStrategy, Target}; pub fn target() -> Target { let mut base = super::l4re_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); base.crt_static_allows_dylibs = false; base.dynamic_linking = false; base.panic_strategy = PanicStrategy::Abort; Target { - llvm_target: "x86_64-unknown-l4re-uclibc".to_string(), + llvm_target: "x86_64-unknown-l4re-uclibc".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs index aefbb398286..e525cfdde14 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs @@ -2,9 +2,9 @@ use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; base.static_position_independent_executables = true; @@ -15,11 +15,11 @@ pub fn target() -> Target { | SanitizerSet::THREAD; Target { - llvm_target: "x86_64-unknown-linux-gnu".to_string(), + llvm_target: "x86_64-unknown-linux-gnu".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnux32.rs b/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnux32.rs index 109f86d3a41..863b41633e2 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnux32.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnux32.rs @@ -2,10 +2,10 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); - base.cpu = "x86-64".to_string(); - base.abi = "x32".to_string(); + base.cpu = "x86-64".into(); + base.abi = "x32".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-mx32".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-mx32".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; base.has_thread_local = false; @@ -14,12 +14,12 @@ pub fn target() -> Target { base.needs_plt = true; Target { - llvm_target: "x86_64-unknown-linux-gnux32".to_string(), + llvm_target: "x86_64-unknown-linux-gnux32".into(), pointer_width: 32, data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\ i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/x86_64_unknown_linux_musl.rs index a5e79803335..8678f06e2cb 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_linux_musl.rs @@ -2,9 +2,9 @@ use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::linux_musl_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; base.static_position_independent_executables = true; @@ -15,11 +15,11 @@ pub fn target() -> Target { | SanitizerSet::THREAD; Target { - llvm_target: "x86_64-unknown-linux-musl".to_string(), + llvm_target: "x86_64-unknown-linux-musl".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_netbsd.rs b/compiler/rustc_target/src/spec/x86_64_unknown_netbsd.rs index bdb2be4f863..a7115dace1c 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_netbsd.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_netbsd.rs @@ -2,9 +2,9 @@ use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target, TargetOpti pub fn target() -> Target { let mut base = super::netbsd_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; base.supported_sanitizers = SanitizerSet::ADDRESS @@ -14,11 +14,11 @@ pub fn target() -> Target { | SanitizerSet::THREAD; Target { - llvm_target: "x86_64-unknown-netbsd".to_string(), + llvm_target: "x86_64-unknown-netbsd".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), - options: TargetOptions { mcount: "__mcount".to_string(), ..base }, + .into(), + arch: "x86_64".into(), + options: TargetOptions { mcount: "__mcount".into(), ..base }, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_none.rs b/compiler/rustc_target/src/spec/x86_64_unknown_none.rs index 722409dd168..0c510dfaa12 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_none.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_none.rs @@ -11,7 +11,7 @@ use super::{ pub fn target() -> Target { let opts = TargetOptions { - cpu: "x86-64".to_string(), + cpu: "x86-64".into(), max_atomic_width: Some(64), // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved stack_probes: StackProbeType::Call, @@ -20,10 +20,10 @@ pub fn target() -> Target { relro_level: RelroLevel::Full, relocation_model: RelocModel::Pic, linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), - linker: Some("rust-lld".to_owned()), + linker: Some("rust-lld".into()), features: "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float" - .to_string(), + .into(), executables: true, disable_redzone: true, panic_strategy: PanicStrategy::Abort, @@ -31,11 +31,11 @@ pub fn target() -> Target { ..Default::default() }; Target { - llvm_target: "x86_64-unknown-none-elf".to_string(), + llvm_target: "x86_64-unknown-none-elf".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: opts, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_none_linuxkernel.rs b/compiler/rustc_target/src/spec/x86_64_unknown_none_linuxkernel.rs index fa6f255d4d9..0db88d64ac0 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_none_linuxkernel.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_none_linuxkernel.rs @@ -5,24 +5,23 @@ use crate::spec::{CodeModel, LinkerFlavor, Target}; pub fn target() -> Target { let mut base = super::linux_kernel_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); base.features = - "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float" - .to_string(); + "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float".into(); base.code_model = Some(CodeModel::Kernel); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); Target { // FIXME: Some dispute, the linux-on-clang folks think this should use // "Linux". We disagree because running *on* Linux is nothing like // running *as" linux, and historically the "os" component as has always // been used to mean the "on" part. - llvm_target: "x86_64-unknown-none-elf".to_string(), + llvm_target: "x86_64-unknown-none-elf".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_openbsd.rs b/compiler/rustc_target/src/spec/x86_64_unknown_openbsd.rs index 4eb3f34a036..11e9cc4abc0 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_openbsd.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_openbsd.rs @@ -2,18 +2,18 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::openbsd_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "x86_64-unknown-openbsd".to_string(), + llvm_target: "x86_64-unknown-openbsd".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_redox.rs b/compiler/rustc_target/src/spec/x86_64_unknown_redox.rs index b8269ecae20..af8b9673c30 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_redox.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_redox.rs @@ -2,18 +2,18 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::redox_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; Target { - llvm_target: "x86_64-unknown-redox".to_string(), + llvm_target: "x86_64-unknown-redox".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_uefi.rs b/compiler/rustc_target/src/spec/x86_64_unknown_uefi.rs index be0e62bea02..a7ae17839da 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_uefi.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_uefi.rs @@ -9,7 +9,7 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::uefi_msvc_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); // We disable MMX and SSE for now, even though UEFI allows using them. Problem is, you have to @@ -22,14 +22,14 @@ pub fn target() -> Target { // // If you initialize FP units yourself, you can override these flags with custom linker // arguments, thus giving you access to full MMX/SSE acceleration. - base.features = "-mmx,-sse,+soft-float".to_string(); + base.features = "-mmx,-sse,+soft-float".into(); Target { - llvm_target: "x86_64-unknown-windows".to_string(), + llvm_target: "x86_64-unknown-windows".into(), pointer_width: 64, data_layout: "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } diff --git a/compiler/rustc_target/src/spec/x86_64_uwp_windows_gnu.rs b/compiler/rustc_target/src/spec/x86_64_uwp_windows_gnu.rs index a5425e1c129..a94bbbf6ede 100644 --- a/compiler/rustc_target/src/spec/x86_64_uwp_windows_gnu.rs +++ b/compiler/rustc_target/src/spec/x86_64_uwp_windows_gnu.rs @@ -2,21 +2,21 @@ use crate::spec::{LinkerFlavor, LldFlavor, Target}; pub fn target() -> Target { let mut base = super::windows_uwp_gnu_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); let gcc_pre_link_args = base.pre_link_args.entry(LinkerFlavor::Gcc).or_default(); - gcc_pre_link_args.push("-m64".to_string()); + gcc_pre_link_args.push("-m64".into()); // Use high-entropy 64 bit address space for ASLR - gcc_pre_link_args.push("-Wl,--high-entropy-va".to_string()); + gcc_pre_link_args.push("-Wl,--high-entropy-va".into()); base.pre_link_args - .insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".to_string(), "i386pep".to_string()]); + .insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".into(), "i386pep".into()]); base.max_atomic_width = Some(64); Target { - llvm_target: "x86_64-pc-windows-gnu".to_string(), + llvm_target: "x86_64-pc-windows-gnu".into(), pointer_width: 64, data_layout: "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_uwp_windows_msvc.rs b/compiler/rustc_target/src/spec/x86_64_uwp_windows_msvc.rs index 06ccc272300..b2769350bf6 100644 --- a/compiler/rustc_target/src/spec/x86_64_uwp_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/x86_64_uwp_windows_msvc.rs @@ -2,15 +2,15 @@ use crate::spec::Target; pub fn target() -> Target { let mut base = super::windows_uwp_msvc_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); Target { - llvm_target: "x86_64-pc-windows-msvc".to_string(), + llvm_target: "x86_64-pc-windows-msvc".into(), pointer_width: 64, data_layout: "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_target/src/spec/x86_64_wrs_vxworks.rs b/compiler/rustc_target/src/spec/x86_64_wrs_vxworks.rs index f9f775084fb..16d29753e7d 100644 --- a/compiler/rustc_target/src/spec/x86_64_wrs_vxworks.rs +++ b/compiler/rustc_target/src/spec/x86_64_wrs_vxworks.rs @@ -2,19 +2,19 @@ use crate::spec::{LinkerFlavor, StackProbeType, Target}; pub fn target() -> Target { let mut base = super::vxworks_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "x86-64".into(); base.max_atomic_width = Some(64); - base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string()); + base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".into()); // don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved base.stack_probes = StackProbeType::Call; base.disable_redzone = true; Target { - llvm_target: "x86_64-unknown-linux-gnu".to_string(), + llvm_target: "x86_64-unknown-linux-gnu".into(), pointer_width: 64, data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - .to_string(), - arch: "x86_64".to_string(), + .into(), + arch: "x86_64".into(), options: base, } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index d83781170e8..216aa89dd1f 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -2,10 +2,10 @@ pub mod on_unimplemented; pub mod suggestions; use super::{ - EvaluationResult, FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes, - Obligation, ObligationCause, ObligationCauseCode, OnUnimplementedDirective, - OnUnimplementedNote, OutputTypeParameterMismatch, Overflow, PredicateObligation, - SelectionContext, SelectionError, TraitNotObjectSafe, + EvaluationResult, FulfillmentContext, FulfillmentError, FulfillmentErrorCode, + MismatchedProjectionTypes, Obligation, ObligationCause, ObligationCauseCode, + OnUnimplementedDirective, OnUnimplementedNote, OutputTypeParameterMismatch, Overflow, + PredicateObligation, SelectionContext, SelectionError, TraitNotObjectSafe, }; use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode}; @@ -21,6 +21,8 @@ use rustc_hir::intravisit::Visitor; use rustc_hir::GenericParam; use rustc_hir::Item; use rustc_hir::Node; +use rustc_infer::infer::error_reporting::same_type_modulo_infer; +use rustc_infer::traits::TraitEngine; use rustc_middle::thir::abstract_const::NotConstEvaluatable; use rustc_middle::traits::select::OverflowError; use rustc_middle::ty::error::ExpectedFound; @@ -103,6 +105,17 @@ pub trait InferCtxtExt<'tcx> { found_args: Vec<ArgKind>, is_closure: bool, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>; + + /// Checks if the type implements one of `Fn`, `FnMut`, or `FnOnce` + /// in that order, and returns the generic type corresponding to the + /// argument of that trait (corresponding to the closure arguments). + fn type_implements_fn_trait( + &self, + param_env: ty::ParamEnv<'tcx>, + ty: ty::Binder<'tcx, Ty<'tcx>>, + constness: ty::BoundConstness, + polarity: ty::ImplPolarity, + ) -> Result<(ty::ClosureKind, ty::Binder<'tcx, Ty<'tcx>>), ()>; } impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { @@ -563,7 +576,64 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } // Try to report a help message - if !trait_ref.has_infer_types_or_consts() + if is_fn_trait + && let Ok((implemented_kind, params)) = self.type_implements_fn_trait( + obligation.param_env, + trait_ref.self_ty(), + trait_predicate.skip_binder().constness, + trait_predicate.skip_binder().polarity, + ) + { + // If the type implements `Fn`, `FnMut`, or `FnOnce`, suppress the following + // suggestion to add trait bounds for the type, since we only typically implement + // these traits once. + + // Note if the `FnMut` or `FnOnce` is less general than the trait we're trying + // to implement. + let selected_kind = + ty::ClosureKind::from_def_id(self.tcx, trait_ref.def_id()) + .expect("expected to map DefId to ClosureKind"); + if !implemented_kind.extends(selected_kind) { + err.note( + &format!( + "`{}` implements `{}`, but it must implement `{}`, which is more general", + trait_ref.skip_binder().self_ty(), + implemented_kind, + selected_kind + ) + ); + } + + // Note any argument mismatches + let given_ty = params.skip_binder(); + let expected_ty = trait_ref.skip_binder().substs.type_at(1); + if let ty::Tuple(given) = given_ty.kind() + && let ty::Tuple(expected) = expected_ty.kind() + { + if expected.len() != given.len() { + // Note number of types that were expected and given + err.note( + &format!( + "expected a closure taking {} argument{}, but one taking {} argument{} was given", + given.len(), + if given.len() == 1 { "" } else { "s" }, + expected.len(), + if expected.len() == 1 { "" } else { "s" }, + ) + ); + } else if !same_type_modulo_infer(given_ty, expected_ty) { + // Print type mismatch + let (expected_args, given_args) = + self.cmp(given_ty, expected_ty); + err.note_expected_found( + &"a closure with arguments", + expected_args, + &"a closure with arguments", + given_args, + ); + } + } + } else if !trait_ref.has_infer_types_or_consts() && self.predicate_can_apply(obligation.param_env, trait_ref) { // If a where-clause may be useful, remind the @@ -1148,6 +1218,52 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err } + + fn type_implements_fn_trait( + &self, + param_env: ty::ParamEnv<'tcx>, + ty: ty::Binder<'tcx, Ty<'tcx>>, + constness: ty::BoundConstness, + polarity: ty::ImplPolarity, + ) -> Result<(ty::ClosureKind, ty::Binder<'tcx, Ty<'tcx>>), ()> { + self.commit_if_ok(|_| { + for trait_def_id in [ + self.tcx.lang_items().fn_trait(), + self.tcx.lang_items().fn_mut_trait(), + self.tcx.lang_items().fn_once_trait(), + ] { + let Some(trait_def_id) = trait_def_id else { continue }; + // Make a fresh inference variable so we can determine what the substitutions + // of the trait are. + let var = self.next_ty_var(TypeVariableOrigin { + span: DUMMY_SP, + kind: TypeVariableOriginKind::MiscVariable, + }); + let substs = self.tcx.mk_substs_trait(ty.skip_binder(), &[var.into()]); + let obligation = Obligation::new( + ObligationCause::dummy(), + param_env, + ty.rebind(ty::TraitPredicate { + trait_ref: ty::TraitRef::new(trait_def_id, substs), + constness, + polarity, + }) + .to_predicate(self.tcx), + ); + let mut fulfill_cx = FulfillmentContext::new_in_snapshot(); + fulfill_cx.register_predicate_obligation(self, obligation); + if fulfill_cx.select_all_or_error(self).is_empty() { + return Ok(( + ty::ClosureKind::from_def_id(self.tcx, trait_def_id) + .expect("expected to map DefId to ClosureKind"), + ty.rebind(self.resolve_vars_if_possible(var)), + )); + } + } + + Err(()) + }) + } } trait InferCtxtPrivExt<'hir, 'tcx> { @@ -1797,15 +1913,15 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id()); } else if let ( Ok(ref snippet), - ObligationCauseCode::BindingObligation(ref def_id, _), + &ObligationCauseCode::BindingObligation(def_id, _), ) = (self.tcx.sess.source_map().span_to_snippet(span), obligation.cause.code()) { - let generics = self.tcx.generics_of(*def_id); + let generics = self.tcx.generics_of(def_id); if generics.params.iter().any(|p| p.name != kw::SelfUpper) && !snippet.ends_with('>') && !generics.has_impl_trait() - && !self.tcx.fn_trait_kind_from_lang_item(*def_id).is_some() + && !self.tcx.fn_trait_kind_from_lang_item(def_id).is_some() { // FIXME: To avoid spurious suggestions in functions where type arguments // where already supplied, we check the snippet to make sure it doesn't @@ -2107,6 +2223,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { "suggest_unsized_bound_if_applicable: pred={:?} item_def_id={:?} span={:?}", pred, item_def_id, span ); + let (Some(node), true) = ( self.tcx.hir().get_if_local(item_def_id), Some(pred.def_id()) == self.tcx.lang_items().sized_trait(), diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 58e002b3360..b49a5f6578f 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -128,7 +128,7 @@ pub trait InferCtxtExt<'tcx> { fn suggest_fully_qualified_path( &self, err: &mut Diagnostic, - def_id: DefId, + item_def_id: DefId, span: Span, trait_ref: DefId, ); @@ -1317,16 +1317,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_fully_qualified_path( &self, err: &mut Diagnostic, - def_id: DefId, + item_def_id: DefId, span: Span, trait_ref: DefId, ) { - if let Some(assoc_item) = self.tcx.opt_associated_item(def_id) { + if let Some(assoc_item) = self.tcx.opt_associated_item(item_def_id) { if let ty::AssocKind::Const | ty::AssocKind::Type = assoc_item.kind { err.note(&format!( "{}s cannot be accessed directly on a `trait`, they can only be \ accessed through a specific `impl`", - assoc_item.kind.as_def_kind().descr(def_id) + assoc_item.kind.as_def_kind().descr(item_def_id) )); err.span_suggestion( span, diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 6cceec86213..54f7c68060f 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -131,16 +131,18 @@ fn object_safety_violations_for_trait( }), ); - violations.extend( - tcx.associated_items(trait_def_id) - .in_definition_order() - .filter(|item| item.kind == ty::AssocKind::Type) - .filter(|item| !tcx.generics_of(item.def_id).params.is_empty()) - .map(|item| { - let ident = item.ident(tcx); - ObjectSafetyViolation::GAT(ident.name, ident.span) - }), - ); + if !tcx.features().generic_associated_types_extended { + violations.extend( + tcx.associated_items(trait_def_id) + .in_definition_order() + .filter(|item| item.kind == ty::AssocKind::Type) + .filter(|item| !tcx.generics_of(item.def_id).params.is_empty()) + .map(|item| { + let ident = item.ident(tcx); + ObjectSafetyViolation::GAT(ident.name, ident.span) + }), + ); + } debug!( "object_safety_violations_for_trait(trait_def_id={:?}) = {:?}", diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 9c871eea1cd..18a37759543 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -11,8 +11,8 @@ use rustc_hir::lang_items::LangItem; use rustc_index::bit_set::GrowableBitSet; use rustc_infer::infer::InferOk; use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType; -use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst, SubstsRef}; -use rustc_middle::ty::{self, Ty}; +use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef}; +use rustc_middle::ty::{self, GenericParamDefKind, Ty}; use rustc_middle::ty::{ToPolyTraitRef, ToPredicate}; use rustc_span::def_id::DefId; @@ -487,18 +487,80 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .collect(); for assoc_type in assoc_types { - if !tcx.generics_of(assoc_type).params.is_empty() { + let defs: &ty::Generics = tcx.generics_of(assoc_type); + + if !defs.params.is_empty() && !tcx.features().generic_associated_types_extended { tcx.sess.delay_span_bug( obligation.cause.span, "GATs in trait object shouldn't have been considered", ); return Err(SelectionError::Unimplemented); } + // This maybe belongs in wf, but that can't (doesn't) handle // higher-ranked things. // Prevent, e.g., `dyn Iterator<Item = str>`. for bound in self.tcx().item_bounds(assoc_type) { - let subst_bound = bound.subst(tcx, trait_predicate.trait_ref.substs); + let subst_bound = + if defs.count() == 0 { + bound.subst(tcx, trait_predicate.trait_ref.substs) + } else { + let mut substs = smallvec::SmallVec::with_capacity(defs.count()); + substs.extend(trait_predicate.trait_ref.substs.iter()); + let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> = + smallvec::SmallVec::with_capacity( + bound.kind().bound_vars().len() + defs.count(), + ); + bound_vars.extend(bound.kind().bound_vars().into_iter()); + InternalSubsts::fill_single(&mut substs, defs, &mut |param, _| match param + .kind + { + GenericParamDefKind::Type { .. } => { + let kind = ty::BoundTyKind::Param(param.name); + let bound_var = ty::BoundVariableKind::Ty(kind); + bound_vars.push(bound_var); + tcx.mk_ty(ty::Bound( + ty::INNERMOST, + ty::BoundTy { + var: ty::BoundVar::from_usize(bound_vars.len() - 1), + kind, + }, + )) + .into() + } + GenericParamDefKind::Lifetime => { + let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name); + let bound_var = ty::BoundVariableKind::Region(kind); + bound_vars.push(bound_var); + tcx.mk_region(ty::ReLateBound( + ty::INNERMOST, + ty::BoundRegion { + var: ty::BoundVar::from_usize(bound_vars.len() - 1), + kind, + }, + )) + .into() + } + GenericParamDefKind::Const { .. } => { + let bound_var = ty::BoundVariableKind::Const; + bound_vars.push(bound_var); + tcx.mk_const(ty::ConstS { + ty: tcx.type_of(param.def_id), + val: ty::ConstKind::Bound( + ty::INNERMOST, + ty::BoundVar::from_usize(bound_vars.len() - 1), + ), + }) + .into() + } + }); + let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter()); + let assoc_ty_substs = tcx.intern_substs(&substs); + + let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter()); + let bound = bound.kind().skip_binder().subst(tcx, assoc_ty_substs); + tcx.mk_predicate(ty::Binder::bind_with_vars(bound, bound_vars)) + }; let normalized_bound = normalize_with_depth_to( self, obligation.param_env, diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 44ef0a09a65..64145bbf189 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -77,15 +77,6 @@ fn impl_defaultness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Defaultness { } } -fn impl_constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness { - let item = tcx.hir().expect_item(def_id.expect_local()); - if let hir::ItemKind::Impl(impl_) = &item.kind { - impl_.constness - } else { - bug!("`impl_constness` called on {:?}", item); - } -} - /// Calculates the `Sized` constraint. /// /// In fact, there are only a few options for the types in the constraint: @@ -498,7 +489,6 @@ pub fn provide(providers: &mut ty::query::Providers) { instance_def_size_estimate, issue33140_self_ty, impl_defaultness, - impl_constness, conservative_is_privately_uninhabited: conservative_is_privately_uninhabited_raw, ..*providers }; diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index a22c9210a9c..0bd5e018f4a 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -28,7 +28,6 @@ use super::{potentially_plural_count, FnCtxt, Inherited}; /// - `impl_m_span`: span to use for reporting errors /// - `trait_m`: the method in the trait /// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation - crate fn compare_impl_method<'tcx>( tcx: TyCtxt<'tcx>, impl_m: &ty::AssocItem, @@ -88,7 +87,7 @@ fn compare_predicate_entailment<'tcx>( impl_m_span, impl_m_hir_id, ObligationCauseCode::CompareImplMethodObligation { - impl_item_def_id: impl_m.def_id, + impl_item_def_id: impl_m.def_id.expect_local(), trait_item_def_id: trait_m.def_id, }, ); @@ -231,7 +230,7 @@ fn compare_predicate_entailment<'tcx>( span, impl_m_hir_id, ObligationCauseCode::CompareImplMethodObligation { - impl_item_def_id: impl_m.def_id, + impl_item_def_id: impl_m.def_id.expect_local(), trait_item_def_id: trait_m.def_id, }, ); @@ -1154,7 +1153,7 @@ fn compare_type_predicate_entailment<'tcx>( impl_ty_span, impl_ty_hir_id, ObligationCauseCode::CompareImplTypeObligation { - impl_item_def_id: impl_ty.def_id, + impl_item_def_id: impl_ty.def_id.expect_local(), trait_item_def_id: trait_ty.def_id, }, ); @@ -1383,7 +1382,7 @@ pub fn check_type_bounds<'tcx>( impl_ty_span, impl_ty_hir_id, ObligationCauseCode::CheckAssociatedTypeBounds { - impl_item_def_id: impl_ty.def_id, + impl_item_def_id: impl_ty.def_id.expect_local(), trait_item_def_id: trait_ty.def_id, }, ); diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index d2b462b5959..00bc16452b9 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -39,6 +39,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.suggest_no_capture_closure(err, expected, expr_ty); self.suggest_boxing_when_appropriate(err, expr, expected, expr_ty); self.suggest_missing_parentheses(err, expr); + self.suggest_block_to_brackets_peeling_refs(err, expr, expr_ty, expected); self.note_need_for_fn_pointer(err, expected, expr_ty); self.note_internal_mutation_in_method(err, expr, expected, expr_ty); self.report_closure_inferred_return_type(err, expected); diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 4d3fdea1fc3..2a1b7a5ab47 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -774,57 +774,68 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let prev_diverges = self.diverges.get(); let ctxt = BreakableCtxt { coerce: Some(coerce), may_break: false }; - let (ctxt, ()) = - self.with_breakable_ctxt(blk.hir_id, ctxt, || { - for (pos, s) in blk.stmts.iter().enumerate() { - self.check_stmt(s, blk.stmts.len() - 1 == pos); - } + let (ctxt, ()) = self.with_breakable_ctxt(blk.hir_id, ctxt, || { + for (pos, s) in blk.stmts.iter().enumerate() { + self.check_stmt(s, blk.stmts.len() - 1 == pos); + } - // check the tail expression **without** holding the - // `enclosing_breakables` lock below. - let tail_expr_ty = tail_expr.map(|t| self.check_expr_with_expectation(t, expected)); - - let mut enclosing_breakables = self.enclosing_breakables.borrow_mut(); - let ctxt = enclosing_breakables.find_breakable(blk.hir_id); - let coerce = ctxt.coerce.as_mut().unwrap(); - if let Some(tail_expr_ty) = tail_expr_ty { - let tail_expr = tail_expr.unwrap(); - let span = self.get_expr_coercion_span(tail_expr); - let cause = - self.cause(span, ObligationCauseCode::BlockTailExpression(blk.hir_id)); - coerce.coerce(self, &cause, tail_expr, tail_expr_ty); - } else { - // Subtle: if there is no explicit tail expression, - // that is typically equivalent to a tail expression - // of `()` -- except if the block diverges. In that - // case, there is no value supplied from the tail - // expression (assuming there are no other breaks, - // this implies that the type of the block will be - // `!`). - // - // #41425 -- label the implicit `()` as being the - // "found type" here, rather than the "expected type". - if !self.diverges.get().is_always() { - // #50009 -- Do not point at the entire fn block span, point at the return type - // span, as it is the cause of the requirement, and - // `consider_hint_about_removing_semicolon` will point at the last expression - // if it were a relevant part of the error. This improves usability in editors - // that highlight errors inline. - let mut sp = blk.span; - let mut fn_span = None; - if let Some((decl, ident)) = self.get_parent_fn_decl(blk.hir_id) { - let ret_sp = decl.output.span(); - if let Some(block_sp) = self.parent_item_span(blk.hir_id) { - // HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the - // output would otherwise be incorrect and even misleading. Make sure - // the span we're aiming at correspond to a `fn` body. - if block_sp == blk.span { - sp = ret_sp; - fn_span = Some(ident.span); - } + // check the tail expression **without** holding the + // `enclosing_breakables` lock below. + let tail_expr_ty = tail_expr.map(|t| self.check_expr_with_expectation(t, expected)); + + let mut enclosing_breakables = self.enclosing_breakables.borrow_mut(); + let ctxt = enclosing_breakables.find_breakable(blk.hir_id); + let coerce = ctxt.coerce.as_mut().unwrap(); + if let Some(tail_expr_ty) = tail_expr_ty { + let tail_expr = tail_expr.unwrap(); + let span = self.get_expr_coercion_span(tail_expr); + let cause = self.cause(span, ObligationCauseCode::BlockTailExpression(blk.hir_id)); + let ty_for_diagnostic = coerce.merged_ty(); + // We use coerce_inner here because we want to augment the error + // suggesting to wrap the block in square brackets if it might've + // been mistaken array syntax + coerce.coerce_inner( + self, + &cause, + Some(tail_expr), + tail_expr_ty, + Some(&mut |diag: &mut Diagnostic| { + self.suggest_block_to_brackets(diag, blk, tail_expr_ty, ty_for_diagnostic); + }), + false, + ); + } else { + // Subtle: if there is no explicit tail expression, + // that is typically equivalent to a tail expression + // of `()` -- except if the block diverges. In that + // case, there is no value supplied from the tail + // expression (assuming there are no other breaks, + // this implies that the type of the block will be + // `!`). + // + // #41425 -- label the implicit `()` as being the + // "found type" here, rather than the "expected type". + if !self.diverges.get().is_always() { + // #50009 -- Do not point at the entire fn block span, point at the return type + // span, as it is the cause of the requirement, and + // `consider_hint_about_removing_semicolon` will point at the last expression + // if it were a relevant part of the error. This improves usability in editors + // that highlight errors inline. + let mut sp = blk.span; + let mut fn_span = None; + if let Some((decl, ident)) = self.get_parent_fn_decl(blk.hir_id) { + let ret_sp = decl.output.span(); + if let Some(block_sp) = self.parent_item_span(blk.hir_id) { + // HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the + // output would otherwise be incorrect and even misleading. Make sure + // the span we're aiming at correspond to a `fn` body. + if block_sp == blk.span { + sp = ret_sp; + fn_span = Some(ident.span); } } - coerce.coerce_forced_unit( + } + coerce.coerce_forced_unit( self, &self.misc(sp), &mut |err| { @@ -837,21 +848,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Our block must be a `assign desugar local; assignment` if let Some(hir::Node::Block(hir::Block { stmts: - [hir::Stmt { - kind: - hir::StmtKind::Local(hir::Local { - source: hir::LocalSource::AssignDesugar(_), - .. - }), - .. - }, hir::Stmt { - kind: - hir::StmtKind::Expr(hir::Expr { - kind: hir::ExprKind::Assign(..), - .. - }), - .. - }], + [ + hir::Stmt { + kind: + hir::StmtKind::Local(hir::Local { + source: + hir::LocalSource::AssignDesugar(_), + .. + }), + .. + }, + hir::Stmt { + kind: + hir::StmtKind::Expr(hir::Expr { + kind: hir::ExprKind::Assign(..), + .. + }), + .. + }, + ], .. })) = self.tcx.hir().find(blk.hir_id) { @@ -871,9 +886,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, false, ); - } } - }); + } + }); if ctxt.may_break { // If we can break from the block, then the block's exit is always reachable diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs index 6c55f821294..55a5eb966c2 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs @@ -14,7 +14,7 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; +use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, Const, Ty, TyCtxt}; diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index e6a98ad6dc0..68d555b3a65 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -766,6 +766,77 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } + /// Given an expression type mismatch, peel any `&` expressions until we get to + /// a block expression, and then suggest replacing the braces with square braces + /// if it was possibly mistaken array syntax. + pub(crate) fn suggest_block_to_brackets_peeling_refs( + &self, + diag: &mut Diagnostic, + mut expr: &hir::Expr<'_>, + mut expr_ty: Ty<'tcx>, + mut expected_ty: Ty<'tcx>, + ) { + loop { + match (&expr.kind, expr_ty.kind(), expected_ty.kind()) { + ( + hir::ExprKind::AddrOf(_, _, inner_expr), + ty::Ref(_, inner_expr_ty, _), + ty::Ref(_, inner_expected_ty, _), + ) => { + expr = *inner_expr; + expr_ty = *inner_expr_ty; + expected_ty = *inner_expected_ty; + } + (hir::ExprKind::Block(blk, _), _, _) => { + self.suggest_block_to_brackets(diag, *blk, expr_ty, expected_ty); + break; + } + _ => break, + } + } + } + + /// Suggest wrapping the block in square brackets instead of curly braces + /// in case the block was mistaken array syntax, e.g. `{ 1 }` -> `[ 1 ]`. + pub(crate) fn suggest_block_to_brackets( + &self, + diag: &mut Diagnostic, + blk: &hir::Block<'_>, + blk_ty: Ty<'tcx>, + expected_ty: Ty<'tcx>, + ) { + if let ty::Slice(elem_ty) | ty::Array(elem_ty, _) = expected_ty.kind() { + if self.can_coerce(blk_ty, *elem_ty) + && blk.stmts.is_empty() + && blk.rules == hir::BlockCheckMode::DefaultBlock + { + let source_map = self.tcx.sess.source_map(); + if let Ok(snippet) = source_map.span_to_snippet(blk.span) { + if snippet.starts_with('{') && snippet.ends_with('}') { + diag.multipart_suggestion_verbose( + "to create an array, use square brackets instead of curly braces", + vec![ + ( + blk.span + .shrink_to_lo() + .with_hi(rustc_span::BytePos(blk.span.lo().0 + 1)), + "[".to_string(), + ), + ( + blk.span + .shrink_to_hi() + .with_lo(rustc_span::BytePos(blk.span.hi().0 - 1)), + "]".to_string(), + ), + ], + Applicability::MachineApplicable, + ); + } + } + } + } + } + fn is_loop(&self, id: hir::HirId) -> bool { let node = self.tcx.hir().get(id); matches!(node, Node::Expr(Expr { kind: ExprKind::Loop(..), .. })) diff --git a/compiler/rustc_typeck/src/check/inherited.rs b/compiler/rustc_typeck/src/check/inherited.rs index e7cfa3a7c14..62ca728868b 100644 --- a/compiler/rustc_typeck/src/check/inherited.rs +++ b/compiler/rustc_typeck/src/check/inherited.rs @@ -68,9 +68,9 @@ impl<'a, 'tcx> Deref for Inherited<'a, 'tcx> { } } -/// Helper type of a temporary returned by `Inherited::build(...)`. -/// Necessary because we can't write the following bound: -/// `F: for<'b, 'tcx> where 'tcx FnOnce(Inherited<'b, 'tcx>)`. +/// A temporary returned by `Inherited::build(...)`. This is necessary +/// for multiple `InferCtxt` to share the same `in_progress_typeck_results` +/// without using `Rc` or something similar. pub struct InheritedBuilder<'tcx> { infcx: infer::InferCtxtBuilder<'tcx>, def_id: LocalDefId, diff --git a/compiler/rustc_typeck/src/check/method/confirm.rs b/compiler/rustc_typeck/src/check/method/confirm.rs index 3fa873e46ab..bc0fa916556 100644 --- a/compiler/rustc_typeck/src/check/method/confirm.rs +++ b/compiler/rustc_typeck/src/check/method/confirm.rs @@ -2,9 +2,9 @@ use super::{probe, MethodCallee}; use crate::astconv::{AstConv, CreateSubstsForGenericArgsCtxt, IsMethodCall}; use crate::check::{callee, FnCtxt}; -use crate::hir::def_id::DefId; -use crate::hir::GenericArg; use rustc_hir as hir; +use rustc_hir::def_id::DefId; +use rustc_hir::GenericArg; use rustc_infer::infer::{self, InferOk}; use rustc_middle::traits::{ObligationCauseCode, UnifyReceiverContext}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast}; diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index e3782fe5911..6edcc12bcf5 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -15,8 +15,8 @@ use rustc_hir::def::Namespace; use rustc_infer::infer::canonical::OriginalQueryValues; use rustc_infer::infer::canonical::{Canonical, QueryResponse}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_infer::infer::{self, InferOk, TyCtxtInferExt}; +use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::middle::stability; use rustc_middle::ty::fast_reject::{simplify_type, TreatParams}; use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index bd08da9529a..9b1767c7835 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -940,7 +940,7 @@ fn check_associated_item( item.ident(fcx.tcx).span, sig, hir_sig.decl, - item.def_id, + item.def_id.expect_local(), &mut implied_bounds, ); check_method_receiver(fcx, hir_sig, item, self_ty); @@ -1068,7 +1068,7 @@ fn check_type_defn<'tcx, F>( } } - check_where_clauses(fcx, item.span, item.def_id.to_def_id(), None); + check_where_clauses(fcx, item.span, item.def_id, None); // No implied bounds in a struct definition. FxHashSet::default() @@ -1096,7 +1096,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) { // FIXME: this shouldn't use an `FnCtxt` at all. for_item(tcx, item).with_fcx(|fcx| { - check_where_clauses(fcx, item.span, item.def_id.to_def_id(), None); + check_where_clauses(fcx, item.span, item.def_id, None); FxHashSet::default() }); @@ -1144,7 +1144,7 @@ fn check_item_fn( for_id(tcx, def_id, span).with_fcx(|fcx| { let sig = tcx.fn_sig(def_id); let mut implied_bounds = FxHashSet::default(); - check_fn_or_method(fcx, ident.span, sig, decl, def_id.to_def_id(), &mut implied_bounds); + check_fn_or_method(fcx, ident.span, sig, decl, def_id, &mut implied_bounds); implied_bounds }) } @@ -1238,7 +1238,7 @@ fn check_impl<'tcx>( } } - check_where_clauses(fcx, item.span, item.def_id.to_def_id(), None); + check_where_clauses(fcx, item.span, item.def_id, None); fcx.impl_implied_bounds(item.def_id.to_def_id(), item.span) }); @@ -1249,7 +1249,7 @@ fn check_impl<'tcx>( fn check_where_clauses<'tcx, 'fcx>( fcx: &FnCtxt<'fcx, 'tcx>, span: Span, - def_id: DefId, + def_id: LocalDefId, return_ty: Option<(Ty<'tcx>, Span)>, ) { let tcx = fcx.tcx; @@ -1317,7 +1317,7 @@ fn check_where_clauses<'tcx, 'fcx>( // For more examples see tests `defaults-well-formedness.rs` and `type-check-defaults.rs`. // // First we build the defaulted substitution. - let substs = InternalSubsts::for_item(tcx, def_id, |param, _| { + let substs = InternalSubsts::for_item(tcx, def_id.to_def_id(), |param, _| { match param.kind { GenericParamDefKind::Lifetime => { // All regions are identity. @@ -1411,8 +1411,11 @@ fn check_where_clauses<'tcx, 'fcx>( // below: there, we are not trying to prove those predicates // to be *true* but merely *well-formed*. let pred = fcx.normalize_associated_types_in(sp, pred); - let cause = - traits::ObligationCause::new(sp, fcx.body_id, traits::ItemObligation(def_id)); + let cause = traits::ObligationCause::new( + sp, + fcx.body_id, + traits::ItemObligation(def_id.to_def_id()), + ); traits::Obligation::new(cause, fcx.param_env, pred) }); @@ -1445,10 +1448,10 @@ fn check_fn_or_method<'fcx, 'tcx>( span: Span, sig: ty::PolyFnSig<'tcx>, hir_decl: &hir::FnDecl<'_>, - def_id: DefId, + def_id: LocalDefId, implied_bounds: &mut FxHashSet<Ty<'tcx>>, ) { - let sig = fcx.tcx.liberate_late_bound_regions(def_id, sig); + let sig = fcx.tcx.liberate_late_bound_regions(def_id.to_def_id(), sig); // Normalize the input and output types one at a time, using a different // `WellFormedLoc` for each. We cannot call `normalize_associated_types` @@ -1462,7 +1465,7 @@ fn check_fn_or_method<'fcx, 'tcx>( span, ty, WellFormedLoc::Param { - function: def_id.expect_local(), + function: def_id, // Note that the `param_idx` of the output type is // one greater than the index of the last input type. param_idx: i.try_into().unwrap(), @@ -1485,7 +1488,7 @@ fn check_fn_or_method<'fcx, 'tcx>( input_ty.into(), ty.span, ObligationCauseCode::WellFormed(Some(WellFormedLoc::Param { - function: def_id.expect_local(), + function: def_id, param_idx: i.try_into().unwrap(), })), ); diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 700ae83e4c9..90b880adcd0 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -1218,8 +1218,6 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef { } else { ty::trait_def::TraitSpecializationKind::None }; - let def_path_hash = tcx.def_path_hash(def_id); - let must_implement_one_of = tcx .get_attrs(def_id) .iter() @@ -1326,7 +1324,6 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef { is_marker, skip_array_during_method_dispatch, spec_kind, - def_path_hash, must_implement_one_of, ) } diff --git a/library/alloc/benches/vec.rs b/library/alloc/benches/vec.rs index 0da4886278e..333b3c20d1d 100644 --- a/library/alloc/benches/vec.rs +++ b/library/alloc/benches/vec.rs @@ -627,10 +627,10 @@ fn bench_map_regular(b: &mut Bencher) { fn bench_map_fast(b: &mut Bencher) { let data = black_box([(0, 0); LEN]); b.iter(|| { - let mut result = Vec::with_capacity(data.len()); + let mut result: Vec<u32> = Vec::with_capacity(data.len()); for i in 0..data.len() { unsafe { - *result.get_unchecked_mut(i) = data[i].0; + *result.as_mut_ptr().add(i) = data[i].0; result.set_len(i); } } diff --git a/library/alloc/tests/str.rs b/library/alloc/tests/str.rs index 32396e35696..273b39aa45a 100644 --- a/library/alloc/tests/str.rs +++ b/library/alloc/tests/str.rs @@ -2234,11 +2234,14 @@ fn utf8_chars() { #[test] fn utf8_char_counts() { let strs = [("e", 1), ("é", 1), ("€", 1), ("\u{10000}", 1), ("eé€\u{10000}", 4)]; - let mut reps = - [8, 64, 256, 512, 1024].iter().copied().flat_map(|n| n - 8..=n + 8).collect::<Vec<usize>>(); + let spread = if cfg!(miri) { 4 } else { 8 }; + let mut reps = [8, 64, 256, 512] + .iter() + .copied() + .flat_map(|n| n - spread..=n + spread) + .collect::<Vec<usize>>(); if cfg!(not(miri)) { - let big = 1 << 16; - reps.extend(big - 8..=big + 8); + reps.extend([1024, 1 << 16].iter().copied().flat_map(|n| n - spread..=n + spread)); } let counts = if cfg!(miri) { 0..1 } else { 0..8 }; let padding = counts.map(|len| " ".repeat(len)).collect::<Vec<String>>(); diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index 0639d6eed62..db6898c1308 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -56,7 +56,7 @@ impl Layout { /// must not overflow (i.e., the rounded value must be less than /// or equal to `usize::MAX`). #[stable(feature = "alloc_layout", since = "1.28.0")] - #[rustc_const_stable(feature = "const_alloc_layout", since = "1.50.0")] + #[rustc_const_stable(feature = "const_alloc_layout_size_align", since = "1.50.0")] #[inline] pub const fn from_size_align(size: usize, align: usize) -> Result<Self, LayoutError> { if !align.is_power_of_two() { @@ -93,7 +93,7 @@ impl Layout { /// This function is unsafe as it does not verify the preconditions from /// [`Layout::from_size_align`]. #[stable(feature = "alloc_layout", since = "1.28.0")] - #[rustc_const_stable(feature = "alloc_layout", since = "1.36.0")] + #[rustc_const_stable(feature = "const_alloc_layout_unchecked", since = "1.36.0")] #[must_use] #[inline] pub const unsafe fn from_size_align_unchecked(size: usize, align: usize) -> Self { @@ -103,7 +103,7 @@ impl Layout { /// The minimum size in bytes for a memory block of this layout. #[stable(feature = "alloc_layout", since = "1.28.0")] - #[rustc_const_stable(feature = "const_alloc_layout", since = "1.50.0")] + #[rustc_const_stable(feature = "const_alloc_layout_size_align", since = "1.50.0")] #[must_use] #[inline] pub const fn size(&self) -> usize { @@ -112,7 +112,7 @@ impl Layout { /// The minimum byte alignment for a memory block of this layout. #[stable(feature = "alloc_layout", since = "1.28.0")] - #[rustc_const_stable(feature = "const_alloc_layout", since = "1.50.0")] + #[rustc_const_stable(feature = "const_alloc_layout_size_align", since = "1.50.0")] #[must_use = "this returns the minimum alignment, \ without modifying the layout"] #[inline] diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 1f1033b0437..242725b96bd 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -173,6 +173,8 @@ pub unsafe trait Allocator { /// * `old_layout` must [*fit*] that block of memory (The `new_layout` argument need not fit it.). /// * `new_layout.size()` must be greater than or equal to `old_layout.size()`. /// + /// Note that `new_layout.align()` need not be the same as `old_layout.align()`. + /// /// [*currently allocated*]: #currently-allocated-memory /// [*fit*]: #memory-fitting /// @@ -234,6 +236,8 @@ pub unsafe trait Allocator { /// * `old_layout` must [*fit*] that block of memory (The `new_layout` argument need not fit it.). /// * `new_layout.size()` must be greater than or equal to `old_layout.size()`. /// + /// Note that `new_layout.align()` need not be the same as `old_layout.align()`. + /// /// [*currently allocated*]: #currently-allocated-memory /// [*fit*]: #memory-fitting /// @@ -296,6 +300,8 @@ pub unsafe trait Allocator { /// * `old_layout` must [*fit*] that block of memory (The `new_layout` argument need not fit it.). /// * `new_layout.size()` must be smaller than or equal to `old_layout.size()`. /// + /// Note that `new_layout.align()` need not be the same as `old_layout.align()`. + /// /// [*currently allocated*]: #currently-allocated-memory /// [*fit*]: #memory-fitting /// diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 7deb3358c95..3195205b1b6 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -1092,7 +1092,7 @@ impl char { /// ``` #[must_use] #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] - #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.32.0")] + #[rustc_const_stable(feature = "const_char_is_ascii", since = "1.32.0")] #[inline] pub const fn is_ascii(&self) -> bool { *self as u32 <= 0x7F diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index 2b611e5aae2..e61ea9ce87f 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -57,6 +57,9 @@ type_alias! { "c_schar.md", c_schar = i8, NonZero_c_schar = NonZeroI8; } type_alias! { "c_uchar.md", c_uchar = u8, NonZero_c_uchar = NonZeroU8; } type_alias! { "c_short.md", c_short = i16, NonZero_c_short = NonZeroI16; } type_alias! { "c_ushort.md", c_ushort = u16, NonZero_c_ushort = NonZeroU16; } +#[cfg(any(target_arch = "avr", target_arch = "msp430"))] +type_alias! { "c_int.md", c_int = i16, NonZero_c_int = NonZeroI16; } +#[cfg(not(any(target_arch = "avr", target_arch = "msp430")))] type_alias! { "c_int.md", c_int = i32, NonZero_c_int = NonZeroI32; } type_alias! { "c_uint.md", c_uint = u32, NonZero_c_uint = NonZeroU32; } type_alias! { "c_long.md", c_long = i32, NonZero_c_long = NonZeroI32; diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 8ad4317c145..0744e9cf426 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1638,7 +1638,7 @@ extern "rust-intrinsic" { /// let num_trailing = unsafe { cttz_nonzero(x) }; /// assert_eq!(num_trailing, 3); /// ``` - #[rustc_const_stable(feature = "const_cttz", since = "1.53.0")] + #[rustc_const_stable(feature = "const_cttz_nonzero", since = "1.53.0")] pub fn cttz_nonzero<T: Copy>(x: T) -> T; /// Reverses the bytes in an integer type `T`. @@ -1718,7 +1718,7 @@ extern "rust-intrinsic" { /// Safe wrappers for this intrinsic are available on the integer /// primitives via the `checked_div` method. For example, /// [`u32::checked_div`] - #[rustc_const_stable(feature = "const_int_unchecked_arith", since = "1.52.0")] + #[rustc_const_stable(feature = "const_int_unchecked_div", since = "1.52.0")] pub fn unchecked_div<T: Copy>(x: T, y: T) -> T; /// Returns the remainder of an unchecked division, resulting in /// undefined behavior when `y == 0` or `x == T::MIN && y == -1` @@ -1726,7 +1726,7 @@ extern "rust-intrinsic" { /// Safe wrappers for this intrinsic are available on the integer /// primitives via the `checked_rem` method. For example, /// [`u32::checked_rem`] - #[rustc_const_stable(feature = "const_int_unchecked_arith", since = "1.52.0")] + #[rustc_const_stable(feature = "const_int_unchecked_rem", since = "1.52.0")] pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T; /// Performs an unchecked left shift, resulting in undefined behavior when @@ -1969,6 +1969,40 @@ extern "rust-intrinsic" { // (`transmute` also falls into this category, but it cannot be wrapped due to the // check that `T` and `U` have the same size.) +/// Check that the preconditions of an unsafe function are followed, if debug_assertions are on, +/// and only at runtime. +/// +/// # Safety +/// +/// Invoking this macro is only sound if the following code is already UB when the passed +/// expression evaluates to false. +/// +/// This macro expands to a check at runtime if debug_assertions is set. It has no effect at +/// compile time, but the semantics of the contained `const_eval_select` must be the same at +/// runtime and at compile time. Thus if the expression evaluates to false, this macro produces +/// different behavior at compile time and at runtime, and invoking it is incorrect. +/// +/// So in a sense it is UB if this macro is useful, but we expect callers of `unsafe fn` to make +/// the occasional mistake, and this check should help them figure things out. +#[allow_internal_unstable(const_eval_select)] // permit this to be called in stably-const fn +macro_rules! assert_unsafe_precondition { + ($e:expr) => { + if cfg!(debug_assertions) { + // Use a closure so that we can capture arbitrary expressions from the invocation + let runtime = || { + if !$e { + // abort instead of panicking to reduce impact on code size + ::core::intrinsics::abort(); + } + }; + const fn comptime() {} + + ::core::intrinsics::const_eval_select((), comptime, runtime); + } + }; +} +pub(crate) use assert_unsafe_precondition; + /// Checks whether `ptr` is properly aligned with respect to /// `align_of::<T>()`. pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool { @@ -1977,7 +2011,6 @@ pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool { /// Checks whether the regions of memory starting at `src` and `dst` of size /// `count * size_of::<T>()` do *not* overlap. -#[cfg(debug_assertions)] pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool { let src_usize = src.addr(); let dst_usize = dst.addr(); @@ -2079,28 +2112,16 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize); } - #[cfg(debug_assertions)] - fn runtime_check<T>(src: *const T, dst: *mut T, count: usize) { - if !is_aligned_and_not_null(src) - || !is_aligned_and_not_null(dst) - || !is_nonoverlapping(src, dst, count) - { - // Not panicking to keep codegen impact smaller. - abort(); - } - } - #[cfg(debug_assertions)] - const fn compiletime_check<T>(_src: *const T, _dst: *mut T, _count: usize) {} - #[cfg(debug_assertions)] - // SAFETY: As per our safety precondition, we may assume that the `abort` above is never reached. - // Therefore, compiletime_check and runtime_check are observably equivalent. - unsafe { - const_eval_select((src, dst, count), compiletime_check, runtime_check); - } - // SAFETY: the safety contract for `copy_nonoverlapping` must be // upheld by the caller. - unsafe { copy_nonoverlapping(src, dst, count) } + unsafe { + assert_unsafe_precondition!( + is_aligned_and_not_null(src) + && is_aligned_and_not_null(dst) + && is_nonoverlapping(src, dst, count) + ); + copy_nonoverlapping(src, dst, count) + } } /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source @@ -2173,24 +2194,11 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) { fn copy<T>(src: *const T, dst: *mut T, count: usize); } - #[cfg(debug_assertions)] - fn runtime_check<T>(src: *const T, dst: *mut T) { - if !is_aligned_and_not_null(src) || !is_aligned_and_not_null(dst) { - // Not panicking to keep codegen impact smaller. - abort(); - } - } - #[cfg(debug_assertions)] - const fn compiletime_check<T>(_src: *const T, _dst: *mut T) {} - #[cfg(debug_assertions)] - // SAFETY: As per our safety precondition, we may assume that the `abort` above is never reached. - // Therefore, compiletime_check and runtime_check are observably equivalent. + // SAFETY: the safety contract for `copy` must be upheld by the caller. unsafe { - const_eval_select((src, dst), compiletime_check, runtime_check); + assert_unsafe_precondition!(is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)); + copy(src, dst, count) } - - // SAFETY: the safety contract for `copy` must be upheld by the caller. - unsafe { copy(src, dst, count) } } /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to @@ -2274,24 +2282,11 @@ pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) { fn write_bytes<T>(dst: *mut T, val: u8, count: usize); } - #[cfg(debug_assertions)] - fn runtime_check<T>(ptr: *mut T) { - debug_assert!( - is_aligned_and_not_null(ptr), - "attempt to write to unaligned or null pointer" - ); - } - #[cfg(debug_assertions)] - const fn compiletime_check<T>(_ptr: *mut T) {} - #[cfg(debug_assertions)] - // SAFETY: runtime debug-assertions are a best-effort basis; it's fine to - // not do them during compile time + // SAFETY: the safety contract for `write_bytes` must be upheld by the caller. unsafe { - const_eval_select((dst,), compiletime_check, runtime_check); + assert_unsafe_precondition!(is_aligned_and_not_null(dst)); + write_bytes(dst, val, count) } - - // SAFETY: the safety contract for `write_bytes` must be upheld by the caller. - unsafe { write_bytes(dst, val, count) } } /// Selects which function to call depending on the context. diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 445a7ba6e2d..7dfcc36ce93 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -97,7 +97,6 @@ // Library features: #![feature(const_align_offset)] #![feature(const_align_of_val)] -#![feature(const_alloc_layout)] #![feature(const_arguments_as_str)] #![feature(const_array_into_iter_constructors)] #![feature(const_bigint_helper_methods)] diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 9db5a9a2889..58d682fc4c8 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -622,7 +622,7 @@ impl<T> MaybeUninit<T> { /// // `x` had not been initialized yet, so this last line caused undefined behavior. ⚠️ /// ``` #[stable(feature = "maybe_uninit", since = "1.36.0")] - #[rustc_const_stable(feature = "const_maybe_uninit_assume_init", since = "1.59.0")] + #[rustc_const_stable(feature = "const_maybe_uninit_assume_init_by_value", since = "1.59.0")] #[inline(always)] #[rustc_diagnostic_item = "assume_init"] #[track_caller] @@ -788,7 +788,7 @@ impl<T> MaybeUninit<T> { /// } /// ``` #[stable(feature = "maybe_uninit_ref", since = "1.55.0")] - #[rustc_const_stable(feature = "const_maybe_uninit_assume_init", since = "1.59.0")] + #[rustc_const_stable(feature = "const_maybe_uninit_assume_init_ref", since = "1.59.0")] #[inline(always)] pub const unsafe fn assume_init_ref(&self) -> &T { // SAFETY: the caller must guarantee that `self` is initialized. diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 8a99bed6a96..005f8749e01 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -299,7 +299,7 @@ pub fn forget_unsized<T: ?Sized>(t: T) { #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_promotable] -#[rustc_const_stable(feature = "const_size_of", since = "1.24.0")] +#[rustc_const_stable(feature = "const_mem_size_of", since = "1.24.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "mem_size_of")] pub const fn size_of<T>() -> usize { intrinsics::size_of::<T>() @@ -581,7 +581,7 @@ pub const unsafe fn align_of_val_raw<T: ?Sized>(val: *const T) -> usize { #[inline] #[must_use] #[stable(feature = "needs_drop", since = "1.21.0")] -#[rustc_const_stable(feature = "const_needs_drop", since = "1.36.0")] +#[rustc_const_stable(feature = "const_mem_needs_drop", since = "1.36.0")] #[rustc_diagnostic_item = "needs_drop"] pub const fn needs_drop<T>() -> bool { intrinsics::needs_drop::<T>() diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 3665573ab0f..ec460286d03 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -270,7 +270,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(0, 0", stringify!($SelfT), ".reverse_bits());")] /// ``` #[stable(feature = "reverse_bits", since = "1.37.0")] - #[rustc_const_stable(feature = "const_int_methods", since = "1.37.0")] + #[rustc_const_stable(feature = "reverse_bits", since = "1.37.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] @@ -603,7 +603,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_div(0), None);")] /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.52.0")] + #[rustc_const_stable(feature = "const_checked_int_div", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -656,7 +656,7 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_rem(-1), None);")] /// ``` #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.52.0")] + #[rustc_const_stable(feature = "const_checked_int_div", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index f4f1d274d10..8cbece0417b 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -281,7 +281,7 @@ impl u8 { /// ``` #[must_use] #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] - #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.43.0")] + #[rustc_const_stable(feature = "const_u8_is_ascii", since = "1.43.0")] #[inline] pub const fn is_ascii(&self) -> bool { *self & 128 == 0 diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index c3652931478..a98b5d787f1 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -52,9 +52,13 @@ macro_rules! nonzero_integers { #[$const_new_unchecked_stability] #[must_use] #[inline] + #[rustc_allow_const_fn_unstable(const_fn_fn_ptr_basics)] // required by assert_unsafe_precondition pub const unsafe fn new_unchecked(n: $Int) -> Self { // SAFETY: this is guaranteed to be safe by the caller. - unsafe { Self(n) } + unsafe { + core::intrinsics::assert_unsafe_precondition!(n != 0); + Self(n) + } } /// Creates a non-zero if the given value is not zero. @@ -74,7 +78,7 @@ macro_rules! nonzero_integers { /// Returns the value as a primitive type. #[$stability] #[inline] - #[rustc_const_stable(feature = "nonzero", since = "1.34.0")] + #[rustc_const_stable(feature = "const_nonzero_get", since = "1.34.0")] pub const fn get(self) -> $Int { self.0 } diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 4751faeb936..514ac69f7e0 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -273,7 +273,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(0, 0", stringify!($SelfT), ".reverse_bits());")] /// ``` #[stable(feature = "reverse_bits", since = "1.37.0")] - #[rustc_const_stable(feature = "const_math", since = "1.37.0")] + #[rustc_const_stable(feature = "reverse_bits", since = "1.37.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] @@ -591,7 +591,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_div(0), None);")] /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.52.0")] + #[rustc_const_stable(feature = "const_checked_int_div", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -642,7 +642,7 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem(0), None);")] /// ``` #[stable(feature = "wrapping", since = "1.7.0")] - #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.52.0")] + #[rustc_const_stable(feature = "const_checked_int_div", since = "1.52.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/ops/deref.rs b/library/core/src/ops/deref.rs index fb4ec83bc28..d68932402a4 100644 --- a/library/core/src/ops/deref.rs +++ b/library/core/src/ops/deref.rs @@ -164,7 +164,7 @@ impl<T: ?Sized> const Deref for &mut T { /// /// let mut x = DerefMutExample { value: 'a' }; /// *x = 'b'; -/// assert_eq!('b', *x); +/// assert_eq!('b', x.value); /// ``` #[lang = "deref_mut"] #[doc(alias = "*")] diff --git a/library/core/src/option.rs b/library/core/src/option.rs index acab8de8c70..b5ca9e35dce 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -549,7 +549,7 @@ impl<T> Option<T> { #[must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead"] #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_option", since = "1.48.0")] + #[rustc_const_stable(feature = "const_option_basics", since = "1.48.0")] pub const fn is_some(&self) -> bool { matches!(*self, Some(_)) } @@ -592,7 +592,7 @@ impl<T> Option<T> { `.and_then(|_| panic!(\"`Option` had a value when expected `None`\"))` instead"] #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_option", since = "1.48.0")] + #[rustc_const_stable(feature = "const_option_basics", since = "1.48.0")] pub const fn is_none(&self) -> bool { !self.is_some() } @@ -621,7 +621,7 @@ impl<T> Option<T> { /// println!("still can print text: {text:?}"); /// ``` #[inline] - #[rustc_const_stable(feature = "const_option", since = "1.48.0")] + #[rustc_const_stable(feature = "const_option_basics", since = "1.48.0")] #[stable(feature = "rust1", since = "1.0.0")] pub const fn as_ref(&self) -> Option<&T> { match *self { diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 68d80022b4c..42e55ce1046 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -332,7 +332,10 @@ use crate::cmp::Ordering; use crate::fmt; use crate::hash; -use crate::intrinsics::{self, abort, is_aligned_and_not_null}; +use crate::intrinsics::{ + self, assert_unsafe_precondition, is_aligned_and_not_null, is_nonoverlapping, +}; + use crate::mem::{self, MaybeUninit}; #[stable(feature = "rust1", since = "1.0.0")] @@ -510,7 +513,7 @@ pub const fn null_mut<T>() -> *mut T { /// see the [module documentation][crate::ptr] for details. #[inline(always)] #[must_use] -#[rustc_const_stable(feature = "strict_provenance", since = "1.61.0")] +#[rustc_const_stable(feature = "stable_things_using_strict_provenance", since = "1.61.0")] #[unstable(feature = "strict_provenance", issue = "95228")] pub const fn invalid<T>(addr: usize) -> *const T { // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic. @@ -537,7 +540,7 @@ pub const fn invalid<T>(addr: usize) -> *const T { /// see the [module documentation][crate::ptr] for details. #[inline(always)] #[must_use] -#[rustc_const_stable(feature = "strict_provenance", since = "1.61.0")] +#[rustc_const_stable(feature = "stable_things_using_strict_provenance", since = "1.61.0")] #[unstable(feature = "strict_provenance", issue = "95228")] pub const fn invalid_mut<T>(addr: usize) -> *mut T { // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic. @@ -749,6 +752,16 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) { }; } + // SAFETY: the caller must guarantee that `x` and `y` are + // valid for writes and properly aligned. + unsafe { + assert_unsafe_precondition!( + is_aligned_and_not_null(x) + && is_aligned_and_not_null(y) + && is_nonoverlapping(x, y, count) + ); + } + // NOTE(scottmcm) MIRI is disabled here as reading in smaller units is a // pessimization for it. Also, if the type contains any unaligned pointers, // copying those over multiple reads is difficult to support. @@ -839,6 +852,7 @@ pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T { // and cannot overlap `src` since `dst` must point to a distinct // allocated object. unsafe { + assert_unsafe_precondition!(is_aligned_and_not_null(dst)); mem::swap(&mut *dst, &mut src); // cannot overlap } src @@ -1318,12 +1332,11 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) { #[inline] #[stable(feature = "volatile", since = "1.9.0")] pub unsafe fn read_volatile<T>(src: *const T) -> T { - if cfg!(debug_assertions) && !is_aligned_and_not_null(src) { - // Not panicking to keep codegen impact smaller. - abort(); - } // SAFETY: the caller must uphold the safety contract for `volatile_load`. - unsafe { intrinsics::volatile_load(src) } + unsafe { + assert_unsafe_precondition!(is_aligned_and_not_null(src)); + intrinsics::volatile_load(src) + } } /// Performs a volatile write of a memory location with the given value without @@ -1389,12 +1402,9 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T { #[inline] #[stable(feature = "volatile", since = "1.9.0")] pub unsafe fn write_volatile<T>(dst: *mut T, src: T) { - if cfg!(debug_assertions) && !is_aligned_and_not_null(dst) { - // Not panicking to keep codegen impact smaller. - abort(); - } // SAFETY: the caller must uphold the safety contract for `volatile_store`. unsafe { + assert_unsafe_precondition!(is_aligned_and_not_null(dst)); intrinsics::volatile_store(dst, src); } } diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index c1b19895f00..7516d4bba4c 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -4,6 +4,7 @@ use crate::fmt; use crate::hash; use crate::marker::Unsize; use crate::mem::{self, MaybeUninit}; +use crate::num::NonZeroUsize; use crate::ops::{CoerceUnsized, DispatchFromDyn}; use crate::ptr::Unique; use crate::slice::{self, SliceIndex}; @@ -253,6 +254,53 @@ impl<T: ?Sized> NonNull<T> { (self.cast(), super::metadata(self.as_ptr())) } + /// Gets the "address" portion of the pointer. + /// + /// This API and its claimed semantics are part of the Strict Provenance experiment, + /// see the [module documentation][crate::ptr] for details. + #[must_use] + #[inline] + #[unstable(feature = "strict_provenance", issue = "95228")] + pub fn addr(self) -> NonZeroUsize + where + T: Sized, + { + // SAFETY: The pointer is guaranteed by the type to be non-null, + // meaning that the address will be non-zero. + unsafe { NonZeroUsize::new_unchecked(self.pointer.addr()) } + } + + /// Creates a new pointer with the given address. + /// + /// This API and its claimed semantics are part of the Strict Provenance experiment, + /// see the [module documentation][crate::ptr] for details. + #[must_use] + #[inline] + #[unstable(feature = "strict_provenance", issue = "95228")] + pub fn with_addr(self, addr: NonZeroUsize) -> Self + where + T: Sized, + { + // SAFETY: The result of `ptr::from::with_addr` is non-null because `addr` is guaranteed to be non-zero. + unsafe { NonNull::new_unchecked(self.pointer.with_addr(addr.get()) as *mut _) } + } + + /// Creates a new pointer by mapping `self`'s address to a new one. + /// + /// This is a convenience for [`with_addr`][Self::with_addr], see that method for details. + /// + /// This API and its claimed semantics are part of the Strict Provenance experiment, + /// see the [module documentation][crate::ptr] for details. + #[must_use] + #[inline] + #[unstable(feature = "strict_provenance", issue = "95228")] + pub fn map_addr(self, f: impl FnOnce(NonZeroUsize) -> NonZeroUsize) -> Self + where + T: Sized, + { + self.with_addr(f(self.addr())) + } + /// Acquires the underlying `*mut` pointer. /// /// # Examples diff --git a/library/core/src/result.rs b/library/core/src/result.rs index afd0c857229..641749be366 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -536,7 +536,7 @@ impl<T, E> Result<T, E> { /// assert_eq!(x.is_ok(), false); /// ``` #[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"] - #[rustc_const_stable(feature = "const_result", since = "1.48.0")] + #[rustc_const_stable(feature = "const_result_basics", since = "1.48.0")] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub const fn is_ok(&self) -> bool { @@ -580,7 +580,7 @@ impl<T, E> Result<T, E> { /// assert_eq!(x.is_err(), true); /// ``` #[must_use = "if you intended to assert that this is err, consider `.unwrap_err()` instead"] - #[rustc_const_stable(feature = "const_result", since = "1.48.0")] + #[rustc_const_stable(feature = "const_result_basics", since = "1.48.0")] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub const fn is_err(&self) -> bool { @@ -698,7 +698,7 @@ impl<T, E> Result<T, E> { /// assert_eq!(x.as_ref(), Err(&"Error")); /// ``` #[inline] - #[rustc_const_stable(feature = "const_result", since = "1.48.0")] + #[rustc_const_stable(feature = "const_result_basics", since = "1.48.0")] #[stable(feature = "rust1", since = "1.0.0")] pub const fn as_ref(&self) -> Result<&T, &E> { match *self { diff --git a/library/core/src/slice/cmp.rs b/library/core/src/slice/cmp.rs index 27c6b6f5bc0..5e1b218e507 100644 --- a/library/core/src/slice/cmp.rs +++ b/library/core/src/slice/cmp.rs @@ -1,6 +1,7 @@ //! Comparison traits for `[T]`. use crate::cmp::{self, Ordering}; +use crate::ffi; use crate::mem; use super::from_raw_parts; @@ -13,8 +14,7 @@ extern "C" { /// /// Returns 0 for equal, < 0 for less than and > 0 for greater /// than. - // FIXME(#32610): Return type should be c_int - fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32; + fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> ffi::c_int; } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index a23de54ef20..880d0f80cc8 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -1,5 +1,6 @@ //! Indexing implementations for `[T]`. +use crate::intrinsics::assert_unsafe_precondition; use crate::intrinsics::const_eval_select; use crate::ops; use crate::ptr; @@ -219,13 +220,19 @@ unsafe impl<T> const SliceIndex<[T]> for usize { // cannot be longer than `isize::MAX`. They also guarantee that // `self` is in bounds of `slice` so `self` cannot overflow an `isize`, // so the call to `add` is safe. - unsafe { slice.as_ptr().add(self) } + unsafe { + assert_unsafe_precondition!(self < slice.len()); + slice.as_ptr().add(self) + } } #[inline] unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut T { // SAFETY: see comments for `get_unchecked` above. - unsafe { slice.as_mut_ptr().add(self) } + unsafe { + assert_unsafe_precondition!(self < slice.len()); + slice.as_mut_ptr().add(self) + } } #[inline] @@ -272,13 +279,18 @@ unsafe impl<T> const SliceIndex<[T]> for ops::Range<usize> { // cannot be longer than `isize::MAX`. They also guarantee that // `self` is in bounds of `slice` so `self` cannot overflow an `isize`, // so the call to `add` is safe. - unsafe { ptr::slice_from_raw_parts(slice.as_ptr().add(self.start), self.end - self.start) } + + unsafe { + assert_unsafe_precondition!(self.end >= self.start && self.end <= slice.len()); + ptr::slice_from_raw_parts(slice.as_ptr().add(self.start), self.end - self.start) + } } #[inline] unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T] { // SAFETY: see comments for `get_unchecked` above. unsafe { + assert_unsafe_precondition!(self.end >= self.start && self.end <= slice.len()); ptr::slice_from_raw_parts_mut(slice.as_mut_ptr().add(self.start), self.end - self.start) } } diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 77bf5f9dc34..17f6373ecbf 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -7,6 +7,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::cmp::Ordering::{self, Greater, Less}; +use crate::intrinsics::{assert_unsafe_precondition, exact_div}; use crate::marker::Copy; use crate::mem; use crate::num::NonZeroUsize; @@ -656,15 +657,10 @@ impl<T> [T] { #[unstable(feature = "slice_swap_unchecked", issue = "88539")] #[rustc_const_unstable(feature = "const_swap", issue = "83163")] pub const unsafe fn swap_unchecked(&mut self, a: usize, b: usize) { - #[cfg(debug_assertions)] - { - let _ = &self[a]; - let _ = &self[b]; - } - let ptr = self.as_mut_ptr(); // SAFETY: caller has to guarantee that `a < self.len()` and `b < self.len()` unsafe { + assert_unsafe_precondition!(a < self.len() && b < self.len()); ptr::swap(ptr.add(a), ptr.add(b)); } } @@ -970,11 +966,11 @@ impl<T> [T] { #[inline] #[must_use] pub unsafe fn as_chunks_unchecked<const N: usize>(&self) -> &[[T; N]] { - debug_assert_ne!(N, 0); - debug_assert_eq!(self.len() % N, 0); - let new_len = - // SAFETY: Our precondition is exactly what's needed to call this - unsafe { crate::intrinsics::exact_div(self.len(), N) }; + // SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length + let new_len = unsafe { + assert_unsafe_precondition!(N != 0 && self.len() % N == 0); + exact_div(self.len(), N) + }; // SAFETY: We cast a slice of `new_len * N` elements into // a slice of `new_len` many `N` elements chunks. unsafe { from_raw_parts(self.as_ptr().cast(), new_len) } @@ -1109,11 +1105,11 @@ impl<T> [T] { #[inline] #[must_use] pub unsafe fn as_chunks_unchecked_mut<const N: usize>(&mut self) -> &mut [[T; N]] { - debug_assert_ne!(N, 0); - debug_assert_eq!(self.len() % N, 0); - let new_len = - // SAFETY: Our precondition is exactly what's needed to call this - unsafe { crate::intrinsics::exact_div(self.len(), N) }; + // SAFETY: Caller must guarantee that `N` is nonzero and exactly divides the slice length + let new_len = unsafe { + assert_unsafe_precondition!(N != 0 && self.len() % N == 0); + exact_div(self.len(), N) + }; // SAFETY: We cast a slice of `new_len * N` elements into // a slice of `new_len` many `N` elements chunks. unsafe { from_raw_parts_mut(self.as_mut_ptr().cast(), new_len) } @@ -1675,7 +1671,10 @@ impl<T> [T] { // // `[ptr; mid]` and `[mid; len]` are not overlapping, so returning a mutable reference // is fine. - unsafe { (from_raw_parts_mut(ptr, mid), from_raw_parts_mut(ptr.add(mid), len - mid)) } + unsafe { + assert_unsafe_precondition!(mid <= len); + (from_raw_parts_mut(ptr, mid), from_raw_parts_mut(ptr.add(mid), len - mid)) + } } /// Divides one slice into an array and a remainder slice at an index. diff --git a/library/core/src/slice/raw.rs b/library/core/src/slice/raw.rs index 6744400c304..1b88573035d 100644 --- a/library/core/src/slice/raw.rs +++ b/library/core/src/slice/raw.rs @@ -1,6 +1,7 @@ //! Free functions to create `&[T]` and `&mut [T]`. use crate::array; +use crate::intrinsics::{assert_unsafe_precondition, is_aligned_and_not_null}; use crate::ops::Range; use crate::ptr; @@ -87,10 +88,14 @@ use crate::ptr; #[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")] #[must_use] pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] { - debug_check_data_len(data, len); - // SAFETY: the caller must uphold the safety contract for `from_raw_parts`. - unsafe { &*ptr::slice_from_raw_parts(data, len) } + unsafe { + assert_unsafe_precondition!( + is_aligned_and_not_null(data) + && crate::mem::size_of::<T>().saturating_mul(len) <= isize::MAX as usize + ); + &*ptr::slice_from_raw_parts(data, len) + } } /// Performs the same functionality as [`from_raw_parts`], except that a @@ -127,46 +132,16 @@ pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] #[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")] #[must_use] pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] { - debug_check_data_len(data as _, len); - // SAFETY: the caller must uphold the safety contract for `from_raw_parts_mut`. - unsafe { &mut *ptr::slice_from_raw_parts_mut(data, len) } -} - -// In debug builds checks that `data` pointer is aligned and non-null and that slice with given `len` would cover less than half the address space -#[cfg(debug_assertions)] -#[unstable(feature = "const_slice_from_raw_parts", issue = "67456")] -#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")] -const fn debug_check_data_len<T>(data: *const T, len: usize) { - fn rt_check<T>(data: *const T) { - use crate::intrinsics::is_aligned_and_not_null; - - assert!(is_aligned_and_not_null(data), "attempt to create unaligned or null slice"); - } - - const fn noop<T>(_: *const T) {} - - // SAFETY: - // - // `rt_check` is just a debug assert to hint users that they are causing UB, - // it is not required for safety (the safety must be guatanteed by - // the `from_raw_parts[_mut]` caller). - // - // As per our safety precondition, we may assume that assertion above never fails. - // Therefore, noop and rt_check are observably equivalent. unsafe { - crate::intrinsics::const_eval_select((data,), noop, rt_check); + assert_unsafe_precondition!( + is_aligned_and_not_null(data) + && crate::mem::size_of::<T>().saturating_mul(len) <= isize::MAX as usize + ); + &mut *ptr::slice_from_raw_parts_mut(data, len) } - - assert!( - crate::mem::size_of::<T>().saturating_mul(len) <= isize::MAX as usize, - "attempt to create slice covering at least half the address space" - ); } -#[cfg(not(debug_assertions))] -const fn debug_check_data_len<T>(_data: *const T, _len: usize) {} - /// Converts a reference to T into a slice of length 1 (without copying). #[stable(feature = "from_ref", since = "1.28.0")] #[rustc_const_unstable(feature = "const_slice_from_ref", issue = "90206")] diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index c11a35ab947..6285d1c1cbb 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -2498,7 +2498,7 @@ macro_rules! atomic_int_ptr_sized { stable(feature = "atomic_access", since = "1.15.0"), stable(feature = "atomic_from", since = "1.23.0"), stable(feature = "atomic_nand", since = "1.27.0"), - rustc_const_stable(feature = "const_integer_atomics", since = "1.24.0"), + rustc_const_stable(feature = "const_ptr_sized_atomics", since = "1.24.0"), stable(feature = "rust1", since = "1.0.0"), "isize", "", @@ -2518,7 +2518,7 @@ macro_rules! atomic_int_ptr_sized { stable(feature = "atomic_access", since = "1.15.0"), stable(feature = "atomic_from", since = "1.23.0"), stable(feature = "atomic_nand", since = "1.27.0"), - rustc_const_stable(feature = "const_integer_atomics", since = "1.24.0"), + rustc_const_stable(feature = "const_ptr_sized_atomics", since = "1.24.0"), stable(feature = "rust1", since = "1.0.0"), "usize", "", diff --git a/library/core/src/time.rs b/library/core/src/time.rs index bd72d82b71c..6c97305b1a8 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -333,7 +333,7 @@ impl Duration { /// /// [`subsec_nanos`]: Duration::subsec_nanos #[stable(feature = "duration", since = "1.3.0")] - #[rustc_const_stable(feature = "duration", since = "1.32.0")] + #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] #[must_use] #[inline] pub const fn as_secs(&self) -> u64 { @@ -356,7 +356,7 @@ impl Duration { /// assert_eq!(duration.subsec_millis(), 432); /// ``` #[stable(feature = "duration_extras", since = "1.27.0")] - #[rustc_const_stable(feature = "duration_extras", since = "1.32.0")] + #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] #[must_use] #[inline] pub const fn subsec_millis(&self) -> u32 { @@ -379,7 +379,7 @@ impl Duration { /// assert_eq!(duration.subsec_micros(), 234_567); /// ``` #[stable(feature = "duration_extras", since = "1.27.0")] - #[rustc_const_stable(feature = "duration_extras", since = "1.32.0")] + #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] #[must_use] #[inline] pub const fn subsec_micros(&self) -> u32 { @@ -402,7 +402,7 @@ impl Duration { /// assert_eq!(duration.subsec_nanos(), 10_000_000); /// ``` #[stable(feature = "duration", since = "1.3.0")] - #[rustc_const_stable(feature = "duration", since = "1.32.0")] + #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")] #[must_use] #[inline] pub const fn subsec_nanos(&self) -> u32 { diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 5f90a76ab74..3af277a556b 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -13,7 +13,6 @@ #![feature(const_convert)] #![feature(const_heap)] #![feature(const_maybe_uninit_as_mut_ptr)] -#![feature(const_maybe_uninit_assume_init)] #![feature(const_maybe_uninit_assume_init_read)] #![feature(const_nonnull_new)] #![feature(const_num_from_num)] @@ -87,6 +86,7 @@ #![feature(int_roundings)] #![feature(slice_group_by)] #![feature(split_array)] +#![feature(strict_provenance)] #![feature(trusted_random_access)] #![feature(unsize)] #![feature(unzip_option)] diff --git a/library/core/tests/num/int_log.rs b/library/core/tests/num/int_log.rs index 3cd0073ddd8..dc3092e1486 100644 --- a/library/core/tests/num/int_log.rs +++ b/library/core/tests/num/int_log.rs @@ -22,12 +22,15 @@ fn checked_log() { assert_eq!(0i8.checked_log(4), None); assert_eq!(0i16.checked_log(4), None); + #[cfg(not(miri))] // Miri is too slow for i in i16::MIN..=0 { assert_eq!(i.checked_log(4), None); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=i16::MAX { assert_eq!(i.checked_log(13), Some((i as f32).log(13.0) as u32)); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=u16::MAX { assert_eq!(i.checked_log(13), Some((i as f32).log(13.0) as u32)); } @@ -48,6 +51,7 @@ fn checked_log2() { for i in 1..=u8::MAX { assert_eq!(i.checked_log2(), Some((i as f32).log2() as u32)); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=u16::MAX { // Guard against Android's imprecise f32::log2 implementation. if i != 8192 && i != 32768 { @@ -60,9 +64,11 @@ fn checked_log2() { for i in 1..=i8::MAX { assert_eq!(i.checked_log2(), Some((i as f32).log2() as u32)); } + #[cfg(not(miri))] // Miri is too slow for i in i16::MIN..=0 { assert_eq!(i.checked_log2(), None); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=i16::MAX { // Guard against Android's imprecise f32::log2 implementation. if i != 8192 { @@ -87,15 +93,19 @@ fn checked_log10() { assert_eq!(0i8.checked_log10(), None); assert_eq!(0i16.checked_log10(), None); + #[cfg(not(miri))] // Miri is too slow for i in i16::MIN..=0 { assert_eq!(i.checked_log10(), None); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=i16::MAX { assert_eq!(i.checked_log10(), Some((i as f32).log10() as u32)); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=u16::MAX { assert_eq!(i.checked_log10(), Some((i as f32).log10() as u32)); } + #[cfg(not(miri))] // Miri is too slow for i in 1..=100_000u32 { assert_eq!(i.checked_log10(), Some((i as f32).log10() as u32)); } diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 750e7295fb5..03fe56022b0 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -1,4 +1,5 @@ use core::cell::RefCell; +use core::num::NonZeroUsize; use core::ptr; use core::ptr::*; use std::fmt::{Debug, Display}; @@ -490,11 +491,11 @@ fn ptr_metadata() { let vtable_5: DynMetadata<dyn Display> = metadata(&Pair(true, 7_u32) as &Pair<bool, dyn Display>); unsafe { - let address_1: usize = std::mem::transmute(vtable_1); - let address_2: usize = std::mem::transmute(vtable_2); - let address_3: usize = std::mem::transmute(vtable_3); - let address_4: usize = std::mem::transmute(vtable_4); - let address_5: usize = std::mem::transmute(vtable_5); + let address_1: *const () = std::mem::transmute(vtable_1); + let address_2: *const () = std::mem::transmute(vtable_2); + let address_3: *const () = std::mem::transmute(vtable_3); + let address_4: *const () = std::mem::transmute(vtable_4); + let address_5: *const () = std::mem::transmute(vtable_5); // Different trait => different vtable pointer assert_ne!(address_1, address_2); // Different erased type => different vtable pointer @@ -691,3 +692,80 @@ fn thin_box() { } } } + +#[test] +fn nonnull_tagged_pointer_with_provenance() { + let raw_pointer = Box::into_raw(Box::new(10)); + + let mut p = TaggedPointer::new(raw_pointer).unwrap(); + assert_eq!(p.tag(), 0); + + p.set_tag(1); + assert_eq!(p.tag(), 1); + assert_eq!(unsafe { *p.pointer().as_ptr() }, 10); + + p.set_tag(3); + assert_eq!(p.tag(), 3); + assert_eq!(unsafe { *p.pointer().as_ptr() }, 10); + + unsafe { Box::from_raw(p.pointer().as_ptr()) }; + + /// A non-null pointer type which carries several bits of metadata and maintains provenance. + #[repr(transparent)] + pub struct TaggedPointer<T>(NonNull<T>); + + impl<T> Clone for TaggedPointer<T> { + fn clone(&self) -> Self { + Self(self.0) + } + } + + impl<T> Copy for TaggedPointer<T> {} + + impl<T> TaggedPointer<T> { + /// The ABI-required minimum alignment of the `P` type. + pub const ALIGNMENT: usize = core::mem::align_of::<T>(); + /// A mask for data-carrying bits of the address. + pub const DATA_MASK: usize = !Self::ADDRESS_MASK; + /// Number of available bits of storage in the address. + pub const NUM_BITS: u32 = Self::ALIGNMENT.trailing_zeros(); + /// A mask for the non-data-carrying bits of the address. + pub const ADDRESS_MASK: usize = usize::MAX << Self::NUM_BITS; + + /// Create a new tagged pointer from a possibly null pointer. + pub fn new(pointer: *mut T) -> Option<TaggedPointer<T>> { + Some(TaggedPointer(NonNull::new(pointer)?)) + } + + /// Consume this tagged pointer and produce a raw mutable pointer to the + /// memory location. + pub fn pointer(self) -> NonNull<T> { + // SAFETY: The `addr` guaranteed to have bits set in the Self::ADDRESS_MASK, so the result will be non-null. + self.0.map_addr(|addr| unsafe { + NonZeroUsize::new_unchecked(addr.get() & Self::ADDRESS_MASK) + }) + } + + /// Consume this tagged pointer and produce the data it carries. + pub fn tag(&self) -> usize { + self.0.addr().get() & Self::DATA_MASK + } + + /// Update the data this tagged pointer carries to a new value. + pub fn set_tag(&mut self, data: usize) { + assert_eq!( + data & Self::ADDRESS_MASK, + 0, + "cannot set more data beyond the lowest NUM_BITS" + ); + let data = data & Self::DATA_MASK; + + // SAFETY: This value will always be non-zero because the upper bits (from + // ADDRESS_MASK) will always be non-zero. This a property of the type and its + // construction. + self.0 = self.0.map_addr(|addr| unsafe { + NonZeroUsize::new_unchecked((addr.get() & Self::ADDRESS_MASK) | data) + }) + } + } +} diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 133ced5f26c..e1c18004383 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -218,111 +218,121 @@ feature(slice_index_methods, coerce_unsized, sgx_platform) )] #![deny(rustc::existing_doc_keyword)] -// std is implemented with unstable features, many of which are internal -// compiler details that will never be stable -// NB: the following list is sorted to minimize merge conflicts. +// +// Language features: #![feature(alloc_error_handler)] -#![feature(alloc_layout_extra)] -#![feature(allocator_api)] #![feature(allocator_internals)] #![feature(allow_internal_unsafe)] #![feature(allow_internal_unstable)] -#![feature(array_error_internals)] -#![feature(assert_matches)] -#![feature(associated_type_bounds)] -#![feature(async_iterator)] -#![feature(atomic_mut_ptr)] -#![feature(bench_black_box)] #![feature(box_syntax)] #![feature(c_unwind)] -#![feature(c_variadic)] -#![feature(cfg_accessible)] -#![feature(cfg_eval)] #![feature(cfg_target_thread_local)] -#![feature(char_error_internals)] -#![feature(char_internals)] -#![feature(concat_bytes)] #![feature(concat_idents)] #![cfg_attr(bootstrap, feature(const_fn_fn_ptr_basics))] #![cfg_attr(bootstrap, feature(const_fn_trait_bound))] -#![feature(const_format_args)] -#![feature(const_io_structs)] -#![feature(const_ip)] -#![feature(const_ipv4)] -#![feature(const_ipv6)] #![feature(const_mut_refs)] -#![feature(const_option)] -#![feature(const_socketaddr)] #![feature(const_trait_impl)] -#![feature(c_size_t)] -#![feature(core_ffi_c)] -#![feature(core_intrinsics)] -#![feature(core_panic)] -#![feature(custom_test_frameworks)] #![feature(decl_macro)] +#![cfg_attr(not(bootstrap), feature(deprecated_suggestion))] #![feature(doc_cfg)] #![feature(doc_cfg_hide)] -#![feature(rustdoc_internals)] -#![cfg_attr(not(bootstrap), feature(deprecated_suggestion))] #![feature(doc_masked)] #![feature(doc_notable_trait)] #![feature(dropck_eyepatch)] -#![feature(duration_checked_float)] -#![feature(duration_constants)] -#![feature(edition_panic)] -#![feature(exact_size_is_empty)] #![feature(exhaustive_patterns)] -#![feature(extend_one)] -#![feature(float_minimum_maximum)] -#![feature(format_args_nl)] -#![feature(strict_provenance)] -#![feature(get_mut_unchecked)] -#![feature(hashmap_internals)] -#![feature(int_error_internals)] #![feature(intra_doc_pointers)] #![feature(lang_items)] #![feature(linkage)] -#![feature(log_syntax)] -#![feature(map_try_insert)] -#![feature(maybe_uninit_slice)] -#![feature(maybe_uninit_write_slice)] #![feature(min_specialization)] -#![feature(mixed_integer_ops)] #![feature(must_not_suspend)] #![feature(needs_panic_runtime)] #![feature(negative_impls)] #![feature(never_type)] -#![feature(new_uninit)] #![feature(nll)] +#![feature(platform_intrinsics)] +#![feature(prelude_import)] +#![feature(rustc_attrs)] +#![feature(rustdoc_internals)] +#![feature(staged_api)] +#![feature(thread_local)] +#![feature(try_blocks)] +// +// Library features (core): +#![feature(array_error_internals)] +#![feature(atomic_mut_ptr)] +#![feature(char_error_internals)] +#![feature(char_internals)] +#![feature(core_intrinsics)] +#![feature(duration_checked_float)] +#![feature(duration_constants)] +#![feature(exact_size_is_empty)] +#![feature(extend_one)] +#![feature(float_minimum_maximum)] +#![feature(hashmap_internals)] +#![feature(int_error_internals)] +#![feature(maybe_uninit_slice)] +#![feature(maybe_uninit_write_slice)] +#![feature(mixed_integer_ops)] #![feature(nonnull_slice_from_raw_parts)] -#![feature(once_cell)] +#![feature(panic_can_unwind)] #![feature(panic_info_message)] #![feature(panic_internals)] -#![feature(panic_can_unwind)] -#![feature(panic_unwind)] -#![feature(platform_intrinsics)] #![feature(portable_simd)] -#![feature(prelude_import)] #![feature(ptr_as_uninit)] #![feature(raw_os_nonzero)] -#![feature(rustc_attrs)] -#![feature(saturating_int_impl)] #![feature(slice_internals)] #![feature(slice_ptr_get)] -#![feature(staged_api)] #![feature(std_internals)] -#![feature(stdsimd)] #![feature(str_internals)] -#![feature(test)] -#![feature(thread_local)] -#![feature(thread_local_internals)] -#![feature(toowned_clone_into)] +#![feature(strict_provenance)] #![feature(total_cmp)] -#![feature(trace_macros)] -#![feature(try_blocks)] +// +// Library features (alloc): +#![feature(alloc_layout_extra)] +#![feature(allocator_api)] +#![feature(get_mut_unchecked)] +#![feature(map_try_insert)] +#![feature(new_uninit)] +#![feature(toowned_clone_into)] #![feature(try_reserve_kind)] #![feature(vec_into_raw_parts)] -// NB: the above list is sorted to minimize merge conflicts. +// +// Library features (unwind): +#![feature(panic_unwind)] +// +// Only for re-exporting: +#![feature(assert_matches)] +#![feature(async_iterator)] +#![feature(c_size_t)] +#![feature(c_variadic)] +#![feature(cfg_accessible)] +#![feature(cfg_eval)] +#![feature(concat_bytes)] +#![feature(const_format_args)] +#![feature(core_ffi_c)] +#![feature(core_panic)] +#![feature(custom_test_frameworks)] +#![feature(edition_panic)] +#![feature(format_args_nl)] +#![feature(log_syntax)] +#![feature(once_cell)] +#![feature(saturating_int_impl)] +#![feature(stdsimd)] +#![feature(test)] +#![feature(trace_macros)] +// +// Only used in tests/benchmarks: +#![feature(bench_black_box)] +// +// Only for const-ness: +#![feature(const_io_structs)] +#![feature(const_ip)] +#![feature(const_ipv4)] +#![feature(const_ipv6)] +#![feature(const_option)] +#![feature(const_socketaddr)] +#![feature(thread_local_internals)] +// #![default_lib_allocator] // Explicitly import the prelude. The compiler uses this same unstable attribute diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index 70a7d7a8cab..036f2919976 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -235,7 +235,7 @@ impl IpAddr { /// assert_eq!(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)).is_unspecified(), true); /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)).is_unspecified(), true); /// ``` - #[rustc_const_stable(feature = "const_ip", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(feature = "ip_shared", since = "1.12.0")] #[must_use] #[inline] @@ -259,7 +259,7 @@ impl IpAddr { /// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).is_loopback(), true); /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1)).is_loopback(), true); /// ``` - #[rustc_const_stable(feature = "const_ip", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(feature = "ip_shared", since = "1.12.0")] #[must_use] #[inline] @@ -309,7 +309,7 @@ impl IpAddr { /// assert_eq!(IpAddr::V4(Ipv4Addr::new(224, 254, 0, 0)).is_multicast(), true); /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0)).is_multicast(), true); /// ``` - #[rustc_const_stable(feature = "const_ip", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(feature = "ip_shared", since = "1.12.0")] #[must_use] #[inline] @@ -387,7 +387,7 @@ impl IpAddr { /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv4(), true); /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv4(), false); /// ``` - #[rustc_const_stable(feature = "const_ip", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(feature = "ipaddr_checker", since = "1.16.0")] #[must_use] #[inline] @@ -408,7 +408,7 @@ impl IpAddr { /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv6(), false); /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv6(), true); /// ``` - #[rustc_const_stable(feature = "const_ip", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(feature = "ipaddr_checker", since = "1.16.0")] #[must_use] #[inline] @@ -454,7 +454,7 @@ impl Ipv4Addr { /// /// let addr = Ipv4Addr::new(127, 0, 0, 1); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.32.0")] + #[rustc_const_stable(feature = "const_ip_32", since = "1.32.0")] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] #[inline] @@ -516,7 +516,7 @@ impl Ipv4Addr { /// let addr = Ipv4Addr::new(127, 0, 0, 1); /// assert_eq!(addr.octets(), [127, 0, 0, 1]); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] #[inline] @@ -540,7 +540,7 @@ impl Ipv4Addr { /// assert_eq!(Ipv4Addr::new(0, 0, 0, 0).is_unspecified(), true); /// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_unspecified(), false); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.32.0")] + #[rustc_const_stable(feature = "const_ip_32", since = "1.32.0")] #[stable(feature = "ip_shared", since = "1.12.0")] #[must_use] #[inline] @@ -562,7 +562,7 @@ impl Ipv4Addr { /// assert_eq!(Ipv4Addr::new(127, 0, 0, 1).is_loopback(), true); /// assert_eq!(Ipv4Addr::new(45, 22, 13, 197).is_loopback(), false); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(since = "1.7.0", feature = "ip_17")] #[must_use] #[inline] @@ -593,7 +593,7 @@ impl Ipv4Addr { /// assert_eq!(Ipv4Addr::new(192, 168, 0, 2).is_private(), true); /// assert_eq!(Ipv4Addr::new(192, 169, 0, 2).is_private(), false); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(since = "1.7.0", feature = "ip_17")] #[must_use] #[inline] @@ -621,7 +621,7 @@ impl Ipv4Addr { /// assert_eq!(Ipv4Addr::new(169, 254, 10, 65).is_link_local(), true); /// assert_eq!(Ipv4Addr::new(16, 89, 10, 65).is_link_local(), false); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(since = "1.7.0", feature = "ip_17")] #[must_use] #[inline] @@ -823,7 +823,7 @@ impl Ipv4Addr { /// assert_eq!(Ipv4Addr::new(236, 168, 10, 65).is_multicast(), true); /// assert_eq!(Ipv4Addr::new(172, 16, 10, 65).is_multicast(), false); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(since = "1.7.0", feature = "ip_17")] #[must_use] #[inline] @@ -845,7 +845,7 @@ impl Ipv4Addr { /// assert_eq!(Ipv4Addr::new(255, 255, 255, 255).is_broadcast(), true); /// assert_eq!(Ipv4Addr::new(236, 168, 10, 65).is_broadcast(), false); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(since = "1.7.0", feature = "ip_17")] #[must_use] #[inline] @@ -873,7 +873,7 @@ impl Ipv4Addr { /// assert_eq!(Ipv4Addr::new(203, 0, 113, 6).is_documentation(), true); /// assert_eq!(Ipv4Addr::new(193, 34, 17, 19).is_documentation(), false); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(since = "1.7.0", feature = "ip_17")] #[must_use] #[inline] @@ -901,7 +901,7 @@ impl Ipv4Addr { /// Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc000, 0x2ff) /// ); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] @@ -928,7 +928,7 @@ impl Ipv4Addr { /// assert_eq!(Ipv4Addr::new(192, 0, 2, 255).to_ipv6_mapped(), /// Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x2ff)); /// ``` - #[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] @@ -1216,7 +1216,7 @@ impl Ipv6Addr { /// /// let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff); /// ``` - #[rustc_const_stable(feature = "const_ipv6", since = "1.32.0")] + #[rustc_const_stable(feature = "const_ip_32", since = "1.32.0")] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] #[inline] @@ -1278,7 +1278,7 @@ impl Ipv6Addr { /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).segments(), /// [0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff]); /// ``` - #[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] #[inline] @@ -1315,7 +1315,7 @@ impl Ipv6Addr { /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unspecified(), false); /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0).is_unspecified(), true); /// ``` - #[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(since = "1.7.0", feature = "ip_17")] #[must_use] #[inline] @@ -1339,7 +1339,7 @@ impl Ipv6Addr { /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_loopback(), false); /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1).is_loopback(), true); /// ``` - #[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(since = "1.7.0", feature = "ip_17")] #[must_use] #[inline] @@ -1624,7 +1624,7 @@ impl Ipv6Addr { /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).is_multicast(), true); /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_multicast(), false); /// ``` - #[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(since = "1.7.0", feature = "ip_17")] #[must_use] #[inline] @@ -1693,7 +1693,7 @@ impl Ipv6Addr { /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4(), /// Some(Ipv4Addr::new(0, 0, 0, 1))); /// ``` - #[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")] + #[rustc_const_stable(feature = "const_ip_50", since = "1.50.0")] #[stable(feature = "rust1", since = "1.0.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] @@ -1740,7 +1740,7 @@ impl Ipv6Addr { /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).octets(), /// [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); /// ``` - #[rustc_const_stable(feature = "const_ipv6", since = "1.32.0")] + #[rustc_const_stable(feature = "const_ip_32", since = "1.32.0")] #[stable(feature = "ipv6_to_octets", since = "1.12.0")] #[must_use] #[inline] diff --git a/library/std/src/sys/sgx/abi/usercalls/alloc.rs b/library/std/src/sys/sgx/abi/usercalls/alloc.rs index 9fdb1b45844..3792a3820a5 100644 --- a/library/std/src/sys/sgx/abi/usercalls/alloc.rs +++ b/library/std/src/sys/sgx/abi/usercalls/alloc.rs @@ -571,7 +571,8 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UserRef<U>> for UserRef<T> {} impl<T, I> Index<I> for UserRef<[T]> where [T]: UserSafe, - I: SliceIndex<[T], Output: UserSafe>, + I: SliceIndex<[T]>, + I::Output: UserSafe, { type Output = UserRef<I::Output>; @@ -591,7 +592,8 @@ where impl<T, I> IndexMut<I> for UserRef<[T]> where [T]: UserSafe, - I: SliceIndex<[T], Output: UserSafe>, + I: SliceIndex<[T]>, + I::Output: UserSafe, { #[inline] fn index_mut(&mut self, index: I) -> &mut UserRef<I::Output> { diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs index ca29261b1c9..a41cb02a607 100644 --- a/library/std/src/thread/local.rs +++ b/library/std/src/thread/local.rs @@ -193,7 +193,7 @@ macro_rules! __thread_local_inner { #[cfg(all(target_family = "wasm", not(target_feature = "atomics")))] { static mut VAL: $t = INIT_EXPR; - Some(&VAL) + $crate::option::Option::Some(&VAL) } // If the platform has support for `#[thread_local]`, use it. @@ -209,7 +209,7 @@ macro_rules! __thread_local_inner { // just get going. if !$crate::mem::needs_drop::<$t>() { unsafe { - return Some(&VAL) + return $crate::option::Option::Some(&VAL) } } @@ -217,13 +217,13 @@ macro_rules! __thread_local_inner { // 1 == dtor registered, dtor not run // 2 == dtor registered and is running or has run #[thread_local] - static mut STATE: u8 = 0; + static mut STATE: $crate::primitive::u8 = 0; - unsafe extern "C" fn destroy(ptr: *mut u8) { + unsafe extern "C" fn destroy(ptr: *mut $crate::primitive::u8) { let ptr = ptr as *mut $t; unsafe { - debug_assert_eq!(STATE, 1); + $crate::debug_assert_eq!(STATE, 1); STATE = 2; $crate::ptr::drop_in_place(ptr); } @@ -235,18 +235,18 @@ macro_rules! __thread_local_inner { // so now. 0 => { $crate::thread::__FastLocalKeyInner::<$t>::register_dtor( - $crate::ptr::addr_of_mut!(VAL) as *mut u8, + $crate::ptr::addr_of_mut!(VAL) as *mut $crate::primitive::u8, destroy, ); STATE = 1; - Some(&VAL) + $crate::option::Option::Some(&VAL) } // 1 == the destructor is registered and the value // is valid, so return the pointer. - 1 => Some(&VAL), + 1 => $crate::option::Option::Some(&VAL), // otherwise the destructor has already run, so we // can't give access. - _ => None, + _ => $crate::option::Option::None, } } } @@ -269,7 +269,7 @@ macro_rules! __thread_local_inner { if let $crate::option::Option::Some(value) = init.take() { return value; } else if $crate::cfg!(debug_assertions) { - unreachable!("missing initial value"); + $crate::unreachable!("missing initial value"); } } __init() @@ -344,7 +344,7 @@ macro_rules! __thread_local_inner { if let $crate::option::Option::Some(value) = init.take() { return value; } else if $crate::cfg!(debug_assertions) { - unreachable!("missing default value"); + $crate::unreachable!("missing default value"); } } __init() diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 3e60ed2f7c4..7698c2de24d 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1,5 +1,6 @@ use std::cell::RefCell; use std::default::Default; +use std::fmt; use std::hash::Hash; use std::iter; use std::lazy::SyncOnceCell as OnceCell; @@ -355,7 +356,7 @@ crate enum ExternalLocation { /// Anything with a source location and set of attributes and, optionally, a /// name. That is, anything that can be documented. This doesn't correspond /// directly to the AST's concept of an item; it's a strict superset. -#[derive(Clone, Debug)] +#[derive(Clone)] crate struct Item { /// The name of this item. /// Optional because not every item has a name, e.g. impls. @@ -370,6 +371,27 @@ crate struct Item { crate cfg: Option<Arc<Cfg>>, } +/// NOTE: this does NOT unconditionally print every item, to avoid thousands of lines of logs. +/// If you want to see the debug output for attributes and the `kind` as well, use `{:#?}` instead of `{:?}`. +impl fmt::Debug for Item { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let alternate = f.alternate(); + // hand-picked fields that don't bloat the logs too much + let mut fmt = f.debug_struct("Item"); + fmt.field("name", &self.name) + .field("visibility", &self.visibility) + .field("def_id", &self.def_id); + // allow printing the full item if someone really wants to + if alternate { + fmt.field("attrs", &self.attrs).field("kind", &self.kind).field("cfg", &self.cfg); + } else { + fmt.field("kind", &self.type_()); + fmt.field("docs", &self.doc_value()); + } + fmt.finish() + } +} + // `Item` is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] rustc_data_structures::static_assert_size!(Item, 56); @@ -471,14 +493,17 @@ impl Item { ) -> Item { trace!("name={:?}, def_id={:?}", name, def_id); - Item { - def_id: def_id.into(), - kind: box kind, - name, - attrs, - visibility: cx.tcx.visibility(def_id).clean(cx), - cfg, - } + // Primitives and Keywords are written in the source code as private modules. + // The modules need to be private so that nobody actually uses them, but the + // keywords and primitives that they are documenting are public. + let visibility = if matches!(&kind, ItemKind::KeywordItem(..) | ItemKind::PrimitiveItem(..)) + { + Visibility::Public + } else { + cx.tcx.visibility(def_id).clean(cx) + }; + + Item { def_id: def_id.into(), kind: box kind, name, attrs, visibility, cfg } } /// Finds all `doc` attributes as NameValues and returns their corresponding values, joined diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 41efda980a2..c4201e22212 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -10,7 +10,10 @@ use rustc_interface::interface; use rustc_middle::hir::map::Map; use rustc_middle::hir::nested_filter; use rustc_middle::ty::TyCtxt; +use rustc_parse::maybe_new_parser_from_source_str; +use rustc_parse::parser::attr::InnerAttrPolicy; use rustc_session::config::{self, CrateType, ErrorOutputType}; +use rustc_session::parse::ParseSess; use rustc_session::{lint, DiagnosticOutput, Session}; use rustc_span::edition::Edition; use rustc_span::source_map::SourceMap; @@ -493,7 +496,7 @@ crate fn make_test( edition: Edition, test_id: Option<&str>, ) -> (String, usize, bool) { - let (crate_attrs, everything_else, crates) = partition_source(s); + let (crate_attrs, everything_else, crates) = partition_source(s, edition); let everything_else = everything_else.trim(); let mut line_offset = 0; let mut prog = String::new(); @@ -525,9 +528,7 @@ crate fn make_test( rustc_span::create_session_if_not_set_then(edition, |_| { use rustc_errors::emitter::{Emitter, EmitterWriter}; use rustc_errors::Handler; - use rustc_parse::maybe_new_parser_from_source_str; use rustc_parse::parser::ForceCollect; - use rustc_session::parse::ParseSess; use rustc_span::source_map::FilePathMapping; let filename = FileName::anon_source_code(s); @@ -697,8 +698,39 @@ crate fn make_test( (prog, line_offset, supports_color) } -// FIXME(aburka): use a real parser to deal with multiline attributes -fn partition_source(s: &str) -> (String, String, String) { +fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool { + if source.is_empty() { + // Empty content so nothing to check in here... + return true; + } + rustc_span::create_session_if_not_set_then(edition, |_| { + let filename = FileName::anon_source_code(source); + let sess = ParseSess::with_silent_emitter(None); + let mut parser = match maybe_new_parser_from_source_str(&sess, filename, source.to_owned()) + { + Ok(p) => p, + Err(_) => { + debug!("Cannot build a parser to check mod attr so skipping..."); + return true; + } + }; + // If a parsing error happened, it's very likely that the attribute is incomplete. + if !parser.parse_attribute(InnerAttrPolicy::Permitted).is_ok() { + return false; + } + // We now check if there is an unclosed delimiter for the attribute. To do so, we look at + // the `unclosed_delims` and see if the opening square bracket was closed. + parser + .unclosed_delims() + .get(0) + .map(|unclosed| { + unclosed.unclosed_span.map(|s| s.lo()).unwrap_or(BytePos(0)) != BytePos(2) + }) + .unwrap_or(true) + }) +} + +fn partition_source(s: &str, edition: Edition) -> (String, String, String) { #[derive(Copy, Clone, PartialEq)] enum PartitionState { Attrs, @@ -710,6 +742,8 @@ fn partition_source(s: &str) -> (String, String, String) { let mut crates = String::new(); let mut after = String::new(); + let mut mod_attr_pending = String::new(); + for line in s.lines() { let trimline = line.trim(); @@ -717,8 +751,14 @@ fn partition_source(s: &str) -> (String, String, String) { // shunted into "everything else" match state { PartitionState::Attrs => { - state = if trimline.starts_with("#![") - || trimline.chars().all(|c| c.is_whitespace()) + state = if trimline.starts_with("#![") { + if !check_if_attr_is_complete(line, edition) { + mod_attr_pending = line.to_owned(); + } else { + mod_attr_pending.clear(); + } + PartitionState::Attrs + } else if trimline.chars().all(|c| c.is_whitespace()) || (trimline.starts_with("//") && !trimline.starts_with("///")) { PartitionState::Attrs @@ -727,7 +767,21 @@ fn partition_source(s: &str) -> (String, String, String) { { PartitionState::Crates } else { - PartitionState::Other + // First we check if the previous attribute was "complete"... + if !mod_attr_pending.is_empty() { + // If not, then we append the new line into the pending attribute to check + // if this time it's complete... + mod_attr_pending.push_str(line); + if !trimline.is_empty() && check_if_attr_is_complete(line, edition) { + // If it's complete, then we can clear the pending content. + mod_attr_pending.clear(); + } + // In any case, this is considered as `PartitionState::Attrs` so it's + // prepended before rustdoc's inserts. + PartitionState::Attrs + } else { + PartitionState::Other + } }; } PartitionState::Crates => { diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 93b33b0d609..0cfe12abcd1 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1987,6 +1987,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { let used_links_bor = &mut used_links; let mut assoc_consts = v .iter() + .filter(|i| i.inner_impl().trait_.is_none()) .flat_map(|i| get_associated_constants(i.inner_impl(), used_links_bor)) .collect::<Vec<_>>(); if !assoc_consts.is_empty() { diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 1223b6c8002..3ad376b8a2c 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -615,7 +615,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra w.write_str(";\n"); if pos < required.len() - 1 { - w.write_str("<div class=\"item-spacer\"></div>"); + w.write_str("<span class=\"item-spacer\"></span>"); } } if !required.is_empty() && !provided.is_empty() { @@ -641,7 +641,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra } } if pos < provided.len() - 1 { - w.write_str("<div class=\"item-spacer\"></div>"); + w.write_str("<span class=\"item-spacer\"></span>"); } } if toggle { diff --git a/src/test/run-make-fulldeps/separate-link-fail/Makefile b/src/test/run-make-fulldeps/separate-link-fail/Makefile new file mode 100644 index 00000000000..c759f42a235 --- /dev/null +++ b/src/test/run-make-fulldeps/separate-link-fail/Makefile @@ -0,0 +1,7 @@ +-include ../tools.mk + +all: + echo 'fn main(){}' > $(TMPDIR)/main.rs + # Make sure that this fails + ! $(RUSTC) -Z link-only $(TMPDIR)/main.rs 2> $(TMPDIR)/stderr.txt + $(CGREP) "The input does not look like a .rlink file" < $(TMPDIR)/stderr.txt diff --git a/src/test/rustdoc-ui/doc-comment-multi-line-cfg-attr.rs b/src/test/rustdoc-ui/doc-comment-multi-line-cfg-attr.rs new file mode 100644 index 00000000000..b2a8133c90e --- /dev/null +++ b/src/test/rustdoc-ui/doc-comment-multi-line-cfg-attr.rs @@ -0,0 +1,12 @@ +// compile-flags:--test +// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" +// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME" +// check-pass + +/// ``` +/// # #![cfg_attr(not(dox), deny(missing_abi, +/// # non_ascii_idents))] +/// +/// pub struct Bar; +/// ``` +pub struct Bar; diff --git a/src/test/rustdoc-ui/doc-comment-multi-line-cfg-attr.stdout b/src/test/rustdoc-ui/doc-comment-multi-line-cfg-attr.stdout new file mode 100644 index 00000000000..bf3521e4f91 --- /dev/null +++ b/src/test/rustdoc-ui/doc-comment-multi-line-cfg-attr.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/doc-comment-multi-line-cfg-attr.rs - Bar (line 6) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/src/test/rustdoc/associated-consts.rs b/src/test/rustdoc/associated-consts.rs index da50fb86cd5..9319a073bb7 100644 --- a/src/test/rustdoc/associated-consts.rs +++ b/src/test/rustdoc/associated-consts.rs @@ -9,8 +9,8 @@ pub trait Trait { pub struct Bar; // @has 'foo/struct.Bar.html' -// @has - '//h3[@class="sidebar-title"]' 'Associated Constants' -// @has - '//div[@class="sidebar-elems"]//a' 'FOO' +// @!has - '//h3[@class="sidebar-title"]' 'Associated Constants' +// @!has - '//div[@class="sidebar-elems"]//a' 'FOO' impl Trait for Bar { const FOO: u32 = 1; @@ -22,10 +22,30 @@ pub enum Foo { } // @has 'foo/enum.Foo.html' -// @has - '//h3[@class="sidebar-title"]' 'Associated Constants' -// @has - '//div[@class="sidebar-elems"]//a' 'FOO' +// @!has - '//h3[@class="sidebar-title"]' 'Associated Constants' +// @!has - '//div[@class="sidebar-elems"]//a' 'FOO' impl Trait for Foo { const FOO: u32 = 1; fn foo() {} } + +pub struct Baz; + +// @has 'foo/struct.Baz.html' +// @has - '//h3[@class="sidebar-title"]' 'Associated Constants' +// @has - '//div[@class="sidebar-elems"]//a' 'FOO' +impl Baz { + pub const FOO: u32 = 42; +} + +pub enum Quux { + B, +} + +// @has 'foo/enum.Quux.html' +// @has - '//h3[@class="sidebar-title"]' 'Associated Constants' +// @has - '//div[@class="sidebar-elems"]//a' 'FOO' +impl Quux { + pub const FOO: u32 = 42; +} diff --git a/src/test/rustdoc/const-display.rs b/src/test/rustdoc/const-display.rs index e3f5d074783..8455dd9ef95 100644 --- a/src/test/rustdoc/const-display.rs +++ b/src/test/rustdoc/const-display.rs @@ -64,7 +64,7 @@ impl Foo { // @has 'foo/struct.Foo.html' '//*[@id="method.stable_impl"]/h4[@class="code-header"]' 'pub const fn stable_impl() -> u32' // @has - '//span[@class="since"]' '1.0.0 (const: 1.2.0)' #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "rust1", since = "1.2.0")] + #[rustc_const_stable(feature = "const2", since = "1.2.0")] pub const fn stable_impl() -> u32 { 42 } } @@ -75,12 +75,12 @@ impl Bar { // Do not show non-const stabilities that are the same as the enclosing item. // @matches 'foo/struct.Bar.html' '//span[@class="since"]' '^const: 1.2.0$' #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "rust1", since = "1.2.0")] + #[rustc_const_stable(feature = "const2", since = "1.2.0")] pub const fn stable_impl() -> u32 { 42 } // Show const-stability even for unstable functions. // @matches 'foo/struct.Bar.html' '//span[@class="since"]' '^const: 1.3.0$' #[unstable(feature = "foo2", issue = "none")] - #[rustc_const_stable(feature = "rust1", since = "1.3.0")] + #[rustc_const_stable(feature = "const3", since = "1.3.0")] pub const fn const_stable_unstable() -> u32 { 42 } } diff --git a/src/test/rustdoc/keyword.rs b/src/test/rustdoc/keyword.rs index 29ceda4f7c1..1cebe4c6797 100644 --- a/src/test/rustdoc/keyword.rs +++ b/src/test/rustdoc/keyword.rs @@ -12,6 +12,7 @@ // @has foo/index.html '//a/@href' '../foo/index.html' // @!has foo/foo/index.html // @!has-dir foo/foo +// @!has foo/index.html '//span' '🔒' #[doc(keyword = "match")] /// this is a test! mod foo{} diff --git a/src/test/rustdoc/primitive.rs b/src/test/rustdoc/primitive.rs new file mode 100644 index 00000000000..605ca4d170b --- /dev/null +++ b/src/test/rustdoc/primitive.rs @@ -0,0 +1,21 @@ +#![crate_name = "foo"] + +#![feature(rustdoc_internals)] + +// @has foo/index.html '//h2[@id="primitives"]' 'Primitive Types' +// @has foo/index.html '//a[@href="primitive.i32.html"]' 'i32' +// @has foo/index.html '//div[@class="sidebar-elems"]//li/a' 'Primitive Types' +// @has foo/index.html '//div[@class="sidebar-elems"]//li/a/@href' '#primitives' +// @has foo/primitive.i32.html '//a[@class="primitive"]' 'i32' +// @has foo/primitive.i32.html '//span[@class="in-band"]' 'Primitive Type i32' +// @has foo/primitive.i32.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!' +// @has foo/index.html '//a/@href' '../foo/index.html' +// @!has foo/index.html '//span' '🔒' +#[doc(primitive = "i32")] +/// this is a test! +mod i32{} + +// @has foo/primitive.bool.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'hello' +#[doc(primitive = "bool")] +/// hello +mod bool {} diff --git a/src/test/ui/asm/naked-functions.stderr b/src/test/ui/asm/naked-functions.stderr index 7bbe49c3b19..8a610b25f00 100644 --- a/src/test/ui/asm/naked-functions.stderr +++ b/src/test/ui/asm/naked-functions.stderr @@ -115,6 +115,11 @@ LL | | LL | | sym G, LL | | ); | |_____^ + | +help: consider specifying that the asm block is responsible for returning from the function + | +LL | sym G, options(noreturn), + | +++++++++++++++++++ error[E0787]: naked functions must contain a single asm block --> $DIR/naked-functions.rs:53:1 @@ -149,18 +154,33 @@ error[E0787]: asm in naked functions must use `noreturn` option | LL | asm!(""); | ^^^^^^^^ + | +help: consider specifying that the asm block is responsible for returning from the function + | +LL | asm!("", options(noreturn)); + | +++++++++++++++++++ error[E0787]: asm in naked functions must use `noreturn` option --> $DIR/naked-functions.rs:85:5 | LL | asm!(""); | ^^^^^^^^ + | +help: consider specifying that the asm block is responsible for returning from the function + | +LL | asm!("", options(noreturn)); + | +++++++++++++++++++ error[E0787]: asm in naked functions must use `noreturn` option --> $DIR/naked-functions.rs:87:5 | LL | asm!(""); | ^^^^^^^^ + | +help: consider specifying that the asm block is responsible for returning from the function + | +LL | asm!("", options(noreturn)); + | +++++++++++++++++++ error[E0787]: naked functions must contain a single asm block --> $DIR/naked-functions.rs:81:1 @@ -216,6 +236,11 @@ error[E0787]: asm in naked functions must use `noreturn` option | LL | asm!("", options(readonly, nostack), options(pure)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: consider specifying that the asm block is responsible for returning from the function + | +LL | asm!("", options(noreturn), options(readonly, nostack), options(pure)); + | +++++++++++++++++++ error[E0787]: asm options unsupported in naked functions: `may_unwind` --> $DIR/naked-functions.rs:118:5 diff --git a/src/test/ui/consts/assert-type-intrinsics.rs b/src/test/ui/consts/assert-type-intrinsics.rs index 31ff6aed03b..38e5c454edf 100644 --- a/src/test/ui/consts/assert-type-intrinsics.rs +++ b/src/test/ui/consts/assert-type-intrinsics.rs @@ -1,7 +1,7 @@ // error-pattern: any use of this value will cause an error #![feature(never_type)] -#![feature(const_maybe_uninit_assume_init, const_assert_type2)] +#![feature(const_assert_type2)] #![feature(core_intrinsics)] use std::intrinsics; diff --git a/src/test/ui/consts/const-eval/simd/insert_extract.rs b/src/test/ui/consts/const-eval/simd/insert_extract.rs index a1d6c5e51b4..3472c05d12f 100644 --- a/src/test/ui/consts/const-eval/simd/insert_extract.rs +++ b/src/test/ui/consts/const-eval/simd/insert_extract.rs @@ -2,7 +2,7 @@ #![feature(repr_simd)] #![feature(platform_intrinsics)] #![feature(staged_api)] -#![stable(feature = "foo", since = "1.33.7")] +#![stable(feature = "foo", since = "1.3.37")] #![allow(non_camel_case_types)] #[repr(simd)] struct i8x1(i8); diff --git a/src/test/ui/consts/const-eval/size-of-t.rs b/src/test/ui/consts/const-eval/size-of-t.rs new file mode 100644 index 00000000000..efbdeec7008 --- /dev/null +++ b/src/test/ui/consts/const-eval/size-of-t.rs @@ -0,0 +1,13 @@ +// https://github.com/rust-lang/rust/issues/69228 +// Used to give bogus suggestion about T not being Sized. + +use std::mem::size_of; + +fn foo<T>() { + let _arr: [u8; size_of::<T>()]; + //~^ ERROR generic parameters may not be used in const operations + //~| NOTE cannot perform const operation + //~| NOTE type parameters may not be used in const expressions +} + +fn main() {} diff --git a/src/test/ui/consts/const-eval/size-of-t.stderr b/src/test/ui/consts/const-eval/size-of-t.stderr new file mode 100644 index 00000000000..abe6410465e --- /dev/null +++ b/src/test/ui/consts/const-eval/size-of-t.stderr @@ -0,0 +1,11 @@ +error: generic parameters may not be used in const operations + --> $DIR/size-of-t.rs:7:30 + | +LL | let _arr: [u8; size_of::<T>()]; + | ^ cannot perform const operation using `T` + | + = note: type parameters may not be used in const expressions + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: aborting due to previous error + diff --git a/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr b/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr index f8c9dca566b..46901bd3b9b 100644 --- a/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr +++ b/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr @@ -104,6 +104,17 @@ LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; error[E0080]: it is undefined behavior to use this value --> $DIR/ub-wide-ptr.rs:71:1 | +LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid reference metadata: slice is bigger than largest supported object + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 8, align: 4) { + ╾─allocN─╼ ff ff ff 7f │ ╾──╼.... + } + +error[E0080]: it is undefined behavior to use this value + --> $DIR/ub-wide-ptr.rs:74:1 + | LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer | @@ -113,7 +124,7 @@ LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:74:1 + --> $DIR/ub-wide-ptr.rs:77:1 | LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling box (going beyond the bounds of its allocation) @@ -124,7 +135,7 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:77:1 + --> $DIR/ub-wide-ptr.rs:80:1 | LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer @@ -135,7 +146,7 @@ LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3) } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:81:1 + --> $DIR/ub-wide-ptr.rs:84:1 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>[0]: encountered 0x03, but expected a boolean @@ -146,29 +157,29 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:87:1 + --> $DIR/ub-wide-ptr.rs:90:1 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>.0: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { - ╾─allocN─╼ │ ╾──╼ + ╾allocN─╼ │ ╾──╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:90:1 + --> $DIR/ub-wide-ptr.rs:93:1 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>.1[0]: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { - ╾─allocN─╼ │ ╾──╼ + ╾allocN─╼ │ ╾──╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:97:1 + --> $DIR/ub-wide-ptr.rs:100:1 | LL | / const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe { LL | | @@ -183,7 +194,7 @@ LL | | }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:105:1 + --> $DIR/ub-wide-ptr.rs:108:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered too small vtable @@ -194,7 +205,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:108:1 + --> $DIR/ub-wide-ptr.rs:111:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered too small vtable @@ -205,7 +216,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:111:1 + --> $DIR/ub-wide-ptr.rs:114:1 | LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered dangling vtable pointer in wide pointer @@ -216,7 +227,7 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:113:1 + --> $DIR/ub-wide-ptr.rs:116:1 | LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered unaligned vtable pointer in wide pointer @@ -227,7 +238,7 @@ LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92 } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:115:1 + --> $DIR/ub-wide-ptr.rs:118:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function) @@ -238,7 +249,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92 } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:117:1 + --> $DIR/ub-wide-ptr.rs:120:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function) @@ -249,7 +260,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:119:1 + --> $DIR/ub-wide-ptr.rs:122:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered invalid drop function pointer in vtable (not pointing to a function) @@ -260,7 +271,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:123:1 + --> $DIR/ub-wide-ptr.rs:126:1 | LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean @@ -271,7 +282,7 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:127:1 + --> $DIR/ub-wide-ptr.rs:130:1 | LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling vtable pointer in wide pointer @@ -282,7 +293,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:129:1 + --> $DIR/ub-wide-ptr.rs:132:1 | LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered too small vtable @@ -293,17 +304,17 @@ LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transm } error[E0080]: could not evaluate static initializer - --> $DIR/ub-wide-ptr.rs:135:5 + --> $DIR/ub-wide-ptr.rs:138:5 | LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: null pointer is not a valid pointer error[E0080]: could not evaluate static initializer - --> $DIR/ub-wide-ptr.rs:139:5 + --> $DIR/ub-wide-ptr.rs:142:5 | LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: allocN has size N, so pointer to 12 bytes starting at offset N is out-of-bounds -error: aborting due to 28 previous errors +error: aborting due to 29 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr b/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr index ded007ce281..b76f8892867 100644 --- a/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr +++ b/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr @@ -104,6 +104,17 @@ LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; error[E0080]: it is undefined behavior to use this value --> $DIR/ub-wide-ptr.rs:71:1 | +LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid reference metadata: slice is bigger than largest supported object + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 16, align: 8) { + ╾───────allocN───────╼ ff ff ff ff ff ff ff 7f │ ╾──────╼........ + } + +error[E0080]: it is undefined behavior to use this value + --> $DIR/ub-wide-ptr.rs:74:1 + | LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer | @@ -113,7 +124,7 @@ LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:74:1 + --> $DIR/ub-wide-ptr.rs:77:1 | LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling box (going beyond the bounds of its allocation) @@ -124,7 +135,7 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:77:1 + --> $DIR/ub-wide-ptr.rs:80:1 | LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer @@ -135,7 +146,7 @@ LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3) } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:81:1 + --> $DIR/ub-wide-ptr.rs:84:1 | LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>[0]: encountered 0x03, but expected a boolean @@ -146,29 +157,29 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }]; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:87:1 + --> $DIR/ub-wide-ptr.rs:90:1 | LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>.0: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { - ╾───────allocN───────╼ │ ╾──────╼ + ╾──────allocN───────╼ │ ╾──────╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:90:1 + --> $DIR/ub-wide-ptr.rs:93:1 | LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>.1[0]: encountered 0x03, but expected a boolean | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 8, align: 8) { - ╾───────allocN───────╼ │ ╾──────╼ + ╾──────allocN───────╼ │ ╾──────╼ } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:97:1 + --> $DIR/ub-wide-ptr.rs:100:1 | LL | / const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe { LL | | @@ -183,7 +194,7 @@ LL | | }; } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:105:1 + --> $DIR/ub-wide-ptr.rs:108:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered too small vtable @@ -194,7 +205,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:108:1 + --> $DIR/ub-wide-ptr.rs:111:1 | LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered too small vtable @@ -205,7 +216,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W(( } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:111:1 + --> $DIR/ub-wide-ptr.rs:114:1 | LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered dangling vtable pointer in wide pointer @@ -216,7 +227,7 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:113:1 + --> $DIR/ub-wide-ptr.rs:116:1 | LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered unaligned vtable pointer in wide pointer @@ -227,7 +238,7 @@ LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92 } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:115:1 + --> $DIR/ub-wide-ptr.rs:118:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function) @@ -238,7 +249,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92 } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:117:1 + --> $DIR/ub-wide-ptr.rs:120:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function) @@ -249,7 +260,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:119:1 + --> $DIR/ub-wide-ptr.rs:122:1 | LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered invalid drop function pointer in vtable (not pointing to a function) @@ -260,7 +271,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:123:1 + --> $DIR/ub-wide-ptr.rs:126:1 | LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean @@ -271,7 +282,7 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:127:1 + --> $DIR/ub-wide-ptr.rs:130:1 | LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling vtable pointer in wide pointer @@ -282,7 +293,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute } error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-wide-ptr.rs:129:1 + --> $DIR/ub-wide-ptr.rs:132:1 | LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered too small vtable @@ -293,17 +304,17 @@ LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transm } error[E0080]: could not evaluate static initializer - --> $DIR/ub-wide-ptr.rs:135:5 + --> $DIR/ub-wide-ptr.rs:138:5 | LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: null pointer is not a valid pointer error[E0080]: could not evaluate static initializer - --> $DIR/ub-wide-ptr.rs:139:5 + --> $DIR/ub-wide-ptr.rs:142:5 | LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: allocN has size N, so pointer to 24 bytes starting at offset N is out-of-bounds -error: aborting due to 28 previous errors +error: aborting due to 29 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/ub-wide-ptr.rs b/src/test/ui/consts/const-eval/ub-wide-ptr.rs index 0fb9f7960ce..ea48a095df9 100644 --- a/src/test/ui/consts/const-eval/ub-wide-ptr.rs +++ b/src/test/ui/consts/const-eval/ub-wide-ptr.rs @@ -67,6 +67,9 @@ const SLICE_LENGTH_UNINIT: &[u8] = unsafe { // bad slice: length too big const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) }; //~^ ERROR it is undefined behavior to use this value +// bad slice: length computation overflows +const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) }; +//~^ ERROR it is undefined behavior to use this value // bad slice: length not an int const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) }; //~^ ERROR it is undefined behavior to use this value diff --git a/src/test/ui/consts/const-size_of_val-align_of_val.rs b/src/test/ui/consts/const-size_of_val-align_of_val.rs index 5c0d7d94d64..5a78313c483 100644 --- a/src/test/ui/consts/const-size_of_val-align_of_val.rs +++ b/src/test/ui/consts/const-size_of_val-align_of_val.rs @@ -2,8 +2,9 @@ #![feature(const_size_of_val, const_align_of_val)] #![feature(const_size_of_val_raw, const_align_of_val_raw, layout_for_ptr)] +#![feature(const_slice_from_raw_parts)] -use std::mem; +use std::{mem, ptr}; struct Foo(u32); @@ -34,6 +35,8 @@ const ALIGN_OF_UGH: usize = mem::align_of_val(&UGH); const SIZE_OF_SLICE: usize = mem::size_of_val("foobar".as_bytes()); const SIZE_OF_DANGLING: usize = unsafe { mem::size_of_val_raw(0x100 as *const i32) }; +const SIZE_OF_BIG: usize = + unsafe { mem::size_of_val_raw(ptr::slice_from_raw_parts(0 as *const u8, isize::MAX as usize)) }; const ALIGN_OF_DANGLING: usize = unsafe { mem::align_of_val_raw(0x100 as *const i16) }; fn main() { @@ -46,6 +49,7 @@ fn main() { assert_eq!(ALIGN_OF_UGH, mem::align_of::<Ugh>()); assert_eq!(SIZE_OF_DANGLING, mem::size_of::<i32>()); + assert_eq!(SIZE_OF_BIG, isize::MAX as usize); assert_eq!(ALIGN_OF_DANGLING, mem::align_of::<i16>()); assert_eq!(SIZE_OF_SLICE, "foobar".len()); diff --git a/src/test/ui/did_you_mean/brackets-to-braces-single-element.rs b/src/test/ui/did_you_mean/brackets-to-braces-single-element.rs new file mode 100644 index 00000000000..4d0109767fc --- /dev/null +++ b/src/test/ui/did_you_mean/brackets-to-braces-single-element.rs @@ -0,0 +1,10 @@ +const A: [&str; 1] = { "hello" }; +//~^ ERROR mismatched types + +const B: &[u32] = &{ 1 }; +//~^ ERROR mismatched types + +const C: &&[u32; 1] = &&{ 1 }; +//~^ ERROR mismatched types + +fn main() {} diff --git a/src/test/ui/did_you_mean/brackets-to-braces-single-element.stderr b/src/test/ui/did_you_mean/brackets-to-braces-single-element.stderr new file mode 100644 index 00000000000..6ded03e45b5 --- /dev/null +++ b/src/test/ui/did_you_mean/brackets-to-braces-single-element.stderr @@ -0,0 +1,38 @@ +error[E0308]: mismatched types + --> $DIR/brackets-to-braces-single-element.rs:1:24 + | +LL | const A: [&str; 1] = { "hello" }; + | ^^^^^^^ expected array `[&'static str; 1]`, found `&str` + | +help: to create an array, use square brackets instead of curly braces + | +LL | const A: [&str; 1] = [ "hello" ]; + | ~ ~ + +error[E0308]: mismatched types + --> $DIR/brackets-to-braces-single-element.rs:4:19 + | +LL | const B: &[u32] = &{ 1 }; + | ^^^^^^ expected slice `[u32]`, found integer + | + = note: expected reference `&'static [u32]` + found reference `&{integer}` +help: to create an array, use square brackets instead of curly braces + | +LL | const B: &[u32] = &[ 1 ]; + | ~ ~ + +error[E0308]: mismatched types + --> $DIR/brackets-to-braces-single-element.rs:7:27 + | +LL | const C: &&[u32; 1] = &&{ 1 }; + | ^ expected array `[u32; 1]`, found integer + | +help: to create an array, use square brackets instead of curly braces + | +LL | const C: &&[u32; 1] = &&[ 1 ]; + | ~ ~ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/did_you_mean/issue-87830-try-brackets-for-arrays.rs b/src/test/ui/did_you_mean/issue-87830-try-brackets-for-arrays.rs index 53dad85900a..070ffaa1eff 100644 --- a/src/test/ui/did_you_mean/issue-87830-try-brackets-for-arrays.rs +++ b/src/test/ui/did_you_mean/issue-87830-try-brackets-for-arrays.rs @@ -1,15 +1,16 @@ fn main() {} -const FOO: [u8; 3] = { //~ ERROR this code is interpreted as a block expression +const FOO: [u8; 3] = { + //~^ ERROR this is a block expression, not an array 1, 2, 3 }; const BAR: [&str; 3] = {"one", "two", "three"}; -//~^ ERROR this code is interpreted as a block expression +//~^ ERROR this is a block expression, not an array fn foo() { {1, 2, 3}; - //~^ ERROR this code is interpreted as a block expression + //~^ ERROR this is a block expression, not an array } fn bar() { diff --git a/src/test/ui/did_you_mean/issue-87830-try-brackets-for-arrays.stderr b/src/test/ui/did_you_mean/issue-87830-try-brackets-for-arrays.stderr index 9ab491f5c23..d5ad1a72b82 100644 --- a/src/test/ui/did_you_mean/issue-87830-try-brackets-for-arrays.stderr +++ b/src/test/ui/did_you_mean/issue-87830-try-brackets-for-arrays.stderr @@ -1,46 +1,45 @@ -error: this code is interpreted as a block expression, not an array +error: this is a block expression, not an array --> $DIR/issue-87830-try-brackets-for-arrays.rs:3:22 | LL | const FOO: [u8; 3] = { | ______________________^ +LL | | LL | | 1, 2, 3 LL | | }; | |_^ | - = note: to define an array, one would use square brackets instead of curly braces -help: try using [] instead of {} +help: to make an array, use square brackets instead of curly braces | LL ~ const FOO: [u8; 3] = [ +LL | LL | 1, 2, 3 LL ~ ]; | -error: this code is interpreted as a block expression, not an array - --> $DIR/issue-87830-try-brackets-for-arrays.rs:7:24 +error: this is a block expression, not an array + --> $DIR/issue-87830-try-brackets-for-arrays.rs:8:24 | LL | const BAR: [&str; 3] = {"one", "two", "three"}; | ^^^^^^^^^^^^^^^^^^^^^^^ | - = note: to define an array, one would use square brackets instead of curly braces -help: try using [] instead of {} +help: to make an array, use square brackets instead of curly braces | LL | const BAR: [&str; 3] = ["one", "two", "three"]; | ~ ~ -error: this code is interpreted as a block expression, not an array - --> $DIR/issue-87830-try-brackets-for-arrays.rs:11:5 +error: this is a block expression, not an array + --> $DIR/issue-87830-try-brackets-for-arrays.rs:12:5 | LL | {1, 2, 3}; | ^^^^^^^^^ | - = note: to define an array, one would use square brackets instead of curly braces -help: try using [] instead of {} +help: to make an array, use square brackets instead of curly braces | LL | [1, 2, 3]; | ~ ~ error: expected one of `.`, `;`, `?`, `}`, or an operator, found `,` - --> $DIR/issue-87830-try-brackets-for-arrays.rs:16:6 + --> $DIR/issue-87830-try-brackets-for-arrays.rs:17:6 | LL | 1, 2, 3 | ^ expected one of `.`, `;`, `?`, `}`, or an operator diff --git a/src/test/ui/generic-associated-types/gat-in-trait-path.stderr b/src/test/ui/generic-associated-types/gat-in-trait-path.base.stderr index a55642490f9..c2054f64e2d 100644 --- a/src/test/ui/generic-associated-types/gat-in-trait-path.stderr +++ b/src/test/ui/generic-associated-types/gat-in-trait-path.base.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/gat-in-trait-path.rs:21:17 + --> $DIR/gat-in-trait-path.rs:27:17 | LL | fn f(_arg : Box<dyn for<'a> Foo<A<'a> = &'a ()>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $DIR/gat-in-trait-path.rs:5:10 + --> $DIR/gat-in-trait-path.rs:11:10 | LL | trait Foo { | --- this trait cannot be made into an object... diff --git a/src/test/ui/generic-associated-types/gat-in-trait-path.rs b/src/test/ui/generic-associated-types/gat-in-trait-path.rs index 7bbcf950ae1..c82450ccff1 100644 --- a/src/test/ui/generic-associated-types/gat-in-trait-path.rs +++ b/src/test/ui/generic-associated-types/gat-in-trait-path.rs @@ -1,5 +1,11 @@ +// revisions: base extended +//[base] check-fail +//[extended] check-pass + #![feature(generic_associated_types)] #![feature(associated_type_defaults)] +#![cfg_attr(extended, feature(generic_associated_types_extended))] +#![cfg_attr(extended, allow(incomplete_features))] trait Foo { type A<'a> where Self: 'a; @@ -19,7 +25,7 @@ impl<T> Foo for Fooer<T> { } fn f(_arg : Box<dyn for<'a> Foo<A<'a> = &'a ()>>) {} -//~^ the trait `Foo` cannot be made into an object +//[base]~^ the trait `Foo` cannot be made into an object fn main() { diff --git a/src/test/ui/generic-associated-types/issue-67510-pass.stderr b/src/test/ui/generic-associated-types/issue-67510-pass.base.stderr index 7dd1bdf891e..74a616aaabe 100644 --- a/src/test/ui/generic-associated-types/issue-67510-pass.stderr +++ b/src/test/ui/generic-associated-types/issue-67510-pass.base.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `X` cannot be made into an object - --> $DIR/issue-67510-pass.rs:7:23 + --> $DIR/issue-67510-pass.rs:13:23 | LL | fn _func1<'a>(_x: Box<dyn X<Y<'a>=&'a ()>>) {} | ^^^^^^^^^^^^^^^^^^^ `X` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $DIR/issue-67510-pass.rs:4:10 + --> $DIR/issue-67510-pass.rs:10:10 | LL | trait X { | - this trait cannot be made into an object... diff --git a/src/test/ui/generic-associated-types/issue-67510-pass.rs b/src/test/ui/generic-associated-types/issue-67510-pass.rs index 99f0e84fa6d..c5b02ff9a64 100644 --- a/src/test/ui/generic-associated-types/issue-67510-pass.rs +++ b/src/test/ui/generic-associated-types/issue-67510-pass.rs @@ -1,10 +1,16 @@ +// revisions: base extended +//[base] check-fail +//[extended] check-pass + #![feature(generic_associated_types)] +#![cfg_attr(extended, feature(generic_associated_types_extended))] +#![cfg_attr(extended, allow(incomplete_features))] trait X { type Y<'a>; } fn _func1<'a>(_x: Box<dyn X<Y<'a>=&'a ()>>) {} -//~^ ERROR the trait `X` cannot be made into an object +//[base]~^ ERROR the trait `X` cannot be made into an object fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-76535.stderr b/src/test/ui/generic-associated-types/issue-76535.base.stderr index 64eeec1b2fc..5decd58bbcd 100644 --- a/src/test/ui/generic-associated-types/issue-76535.stderr +++ b/src/test/ui/generic-associated-types/issue-76535.base.stderr @@ -1,11 +1,11 @@ error[E0107]: missing generics for associated type `SuperTrait::SubType` - --> $DIR/issue-76535.rs:36:33 + --> $DIR/issue-76535.rs:40:33 | LL | let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0)); | ^^^^^^^ expected 1 lifetime argument | note: associated type defined here, with 1 lifetime parameter: `'a` - --> $DIR/issue-76535.rs:6:10 + --> $DIR/issue-76535.rs:10:10 | LL | type SubType<'a>: SubTrait where Self: 'a; | ^^^^^^^ -- @@ -15,13 +15,13 @@ LL | let sub: Box<dyn SuperTrait<SubType<'a> = SubStruct>> = Box::new(SuperS | ~~~~~~~~~~~ error[E0038]: the trait `SuperTrait` cannot be made into an object - --> $DIR/issue-76535.rs:36:14 + --> $DIR/issue-76535.rs:40:14 | LL | let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $DIR/issue-76535.rs:6:10 + --> $DIR/issue-76535.rs:10:10 | LL | pub trait SuperTrait { | ---------- this trait cannot be made into an object... @@ -30,13 +30,13 @@ LL | type SubType<'a>: SubTrait where Self: 'a; = help: consider moving `SubType` to another trait error[E0038]: the trait `SuperTrait` cannot be made into an object - --> $DIR/issue-76535.rs:36:57 + --> $DIR/issue-76535.rs:40:57 | LL | let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $DIR/issue-76535.rs:6:10 + --> $DIR/issue-76535.rs:10:10 | LL | pub trait SuperTrait { | ---------- this trait cannot be made into an object... diff --git a/src/test/ui/generic-associated-types/issue-76535.extended.stderr b/src/test/ui/generic-associated-types/issue-76535.extended.stderr new file mode 100644 index 00000000000..067d0489b48 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-76535.extended.stderr @@ -0,0 +1,19 @@ +error[E0107]: missing generics for associated type `SuperTrait::SubType` + --> $DIR/issue-76535.rs:40:33 + | +LL | let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0)); + | ^^^^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-76535.rs:10:10 + | +LL | type SubType<'a>: SubTrait where Self: 'a; + | ^^^^^^^ -- +help: add missing lifetime argument + | +LL | let sub: Box<dyn SuperTrait<SubType<'a> = SubStruct>> = Box::new(SuperStruct::new(0)); + | ~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/generic-associated-types/issue-76535.rs b/src/test/ui/generic-associated-types/issue-76535.rs index 20c6924afa6..46f217ba06b 100644 --- a/src/test/ui/generic-associated-types/issue-76535.rs +++ b/src/test/ui/generic-associated-types/issue-76535.rs @@ -1,4 +1,8 @@ +// revisions: base extended + #![feature(generic_associated_types)] +#![cfg_attr(extended, feature(generic_associated_types_extended))] +#![cfg_attr(extended, allow(incomplete_features))] pub trait SubTrait {} @@ -35,6 +39,6 @@ impl SuperTrait for SuperStruct { fn main() { let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0)); //~^ ERROR missing generics for associated type - //~^^ ERROR the trait - //~| ERROR the trait + //[base]~^^ ERROR the trait + //[base]~| ERROR the trait } diff --git a/src/test/ui/generic-associated-types/issue-78671.stderr b/src/test/ui/generic-associated-types/issue-78671.base.stderr index 17dd0ff4a0c..6bcd004b1a9 100644 --- a/src/test/ui/generic-associated-types/issue-78671.stderr +++ b/src/test/ui/generic-associated-types/issue-78671.base.stderr @@ -1,11 +1,11 @@ error[E0107]: missing generics for associated type `CollectionFamily::Member` - --> $DIR/issue-78671.rs:7:47 + --> $DIR/issue-78671.rs:11:47 | LL | Box::new(Family) as &dyn CollectionFamily<Member=usize> | ^^^^^^ expected 1 generic argument | note: associated type defined here, with 1 generic parameter: `T` - --> $DIR/issue-78671.rs:4:10 + --> $DIR/issue-78671.rs:8:10 | LL | type Member<T>; | ^^^^^^ - @@ -15,13 +15,13 @@ LL | Box::new(Family) as &dyn CollectionFamily<Member<T>=usize> | ~~~~~~~~~ error[E0038]: the trait `CollectionFamily` cannot be made into an object - --> $DIR/issue-78671.rs:7:25 + --> $DIR/issue-78671.rs:11:25 | LL | Box::new(Family) as &dyn CollectionFamily<Member=usize> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `CollectionFamily` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $DIR/issue-78671.rs:4:10 + --> $DIR/issue-78671.rs:8:10 | LL | trait CollectionFamily { | ---------------- this trait cannot be made into an object... diff --git a/src/test/ui/generic-associated-types/issue-78671.extended.stderr b/src/test/ui/generic-associated-types/issue-78671.extended.stderr new file mode 100644 index 00000000000..f1b48933516 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-78671.extended.stderr @@ -0,0 +1,19 @@ +error[E0107]: missing generics for associated type `CollectionFamily::Member` + --> $DIR/issue-78671.rs:11:47 + | +LL | Box::new(Family) as &dyn CollectionFamily<Member=usize> + | ^^^^^^ expected 1 generic argument + | +note: associated type defined here, with 1 generic parameter: `T` + --> $DIR/issue-78671.rs:8:10 + | +LL | type Member<T>; + | ^^^^^^ - +help: add missing generic argument + | +LL | Box::new(Family) as &dyn CollectionFamily<Member<T>=usize> + | ~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/generic-associated-types/issue-78671.rs b/src/test/ui/generic-associated-types/issue-78671.rs index 7ccf376e5cb..c09dac28bda 100644 --- a/src/test/ui/generic-associated-types/issue-78671.rs +++ b/src/test/ui/generic-associated-types/issue-78671.rs @@ -1,4 +1,8 @@ +// revisions: base extended + #![feature(generic_associated_types)] +#![cfg_attr(extended, feature(generic_associated_types_extended))] +#![cfg_attr(extended, allow(incomplete_features))] trait CollectionFamily { type Member<T>; @@ -6,7 +10,7 @@ trait CollectionFamily { fn floatify() { Box::new(Family) as &dyn CollectionFamily<Member=usize> //~^ ERROR: missing generics for associated type - //~| ERROR: the trait `CollectionFamily` cannot be made into an object + //[base]~^^ ERROR: the trait `CollectionFamily` cannot be made into an object } struct Family; diff --git a/src/test/ui/generic-associated-types/issue-79422.stderr b/src/test/ui/generic-associated-types/issue-79422.base.stderr index 8b6f9b866e5..404c975d64a 100644 --- a/src/test/ui/generic-associated-types/issue-79422.stderr +++ b/src/test/ui/generic-associated-types/issue-79422.base.stderr @@ -1,11 +1,11 @@ error[E0107]: missing generics for associated type `MapLike::VRefCont` - --> $DIR/issue-79422.rs:42:36 + --> $DIR/issue-79422.rs:48:36 | LL | as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>; | ^^^^^^^^ expected 1 lifetime argument | note: associated type defined here, with 1 lifetime parameter: `'a` - --> $DIR/issue-79422.rs:20:10 + --> $DIR/issue-79422.rs:24:10 | LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a; | ^^^^^^^^ -- @@ -15,13 +15,13 @@ LL | as Box<dyn MapLike<u8, u8, VRefCont<'a> = dyn RefCont<'_, u8>>>; | ~~~~~~~~~~~~ error[E0038]: the trait `MapLike` cannot be made into an object - --> $DIR/issue-79422.rs:42:12 + --> $DIR/issue-79422.rs:48:12 | LL | as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `MapLike` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $DIR/issue-79422.rs:20:10 + --> $DIR/issue-79422.rs:24:10 | LL | trait MapLike<K, V> { | ------- this trait cannot be made into an object... @@ -30,13 +30,13 @@ LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a; = help: consider moving `VRefCont` to another trait error[E0038]: the trait `MapLike` cannot be made into an object - --> $DIR/issue-79422.rs:41:13 + --> $DIR/issue-79422.rs:45:13 | LL | let m = Box::new(std::collections::BTreeMap::<u8, u8>::new()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `MapLike` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $DIR/issue-79422.rs:20:10 + --> $DIR/issue-79422.rs:24:10 | LL | trait MapLike<K, V> { | ------- this trait cannot be made into an object... diff --git a/src/test/ui/generic-associated-types/issue-79422.extended.stderr b/src/test/ui/generic-associated-types/issue-79422.extended.stderr new file mode 100644 index 00000000000..9478fc89792 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-79422.extended.stderr @@ -0,0 +1,35 @@ +error[E0107]: missing generics for associated type `MapLike::VRefCont` + --> $DIR/issue-79422.rs:48:36 + | +LL | as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>; + | ^^^^^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-79422.rs:24:10 + | +LL | type VRefCont<'a>: RefCont<'a, V> where Self: 'a; + | ^^^^^^^^ -- +help: add missing lifetime argument + | +LL | as Box<dyn MapLike<u8, u8, VRefCont<'a> = dyn RefCont<'_, u8>>>; + | ~~~~~~~~~~~~ + +error[E0271]: type mismatch resolving `<BTreeMap<u8, u8> as MapLike<u8, u8>>::VRefCont<'_> == (dyn RefCont<'_, u8> + 'static)` + --> $DIR/issue-79422.rs:45:13 + | +LL | let m = Box::new(std::collections::BTreeMap::<u8, u8>::new()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<BTreeMap<u8, u8> as MapLike<u8, u8>>::VRefCont<'_> == (dyn RefCont<'_, u8> + 'static)` + | +note: expected this to be `(dyn RefCont<'_, u8> + 'static)` + --> $DIR/issue-79422.rs:29:25 + | +LL | type VRefCont<'a> = &'a V where Self: 'a; + | ^^^^^ + = note: expected trait object `(dyn RefCont<'_, u8> + 'static)` + found reference `&u8` + = note: required for the cast to the object type `dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0107, E0271. +For more information about an error, try `rustc --explain E0107`. diff --git a/src/test/ui/generic-associated-types/issue-79422.rs b/src/test/ui/generic-associated-types/issue-79422.rs index b9a3c583f7c..7749975e687 100644 --- a/src/test/ui/generic-associated-types/issue-79422.rs +++ b/src/test/ui/generic-associated-types/issue-79422.rs @@ -1,4 +1,8 @@ +// revisions: base extended + #![feature(generic_associated_types)] +#![cfg_attr(extended, feature(generic_associated_types_extended))] +#![cfg_attr(extended, allow(incomplete_features))] trait RefCont<'a, T> { fn t(&'a self) -> &'a T; @@ -39,8 +43,9 @@ impl<K, V: Default> MapLike<K, V> for Source { fn main() { let m = Box::new(std::collections::BTreeMap::<u8, u8>::new()) + //[base]~^ ERROR the trait + //[extended]~^^ type mismatch as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>; //~^ ERROR missing generics for associated type - //~^^ ERROR the trait - //~^^^^ ERROR the trait + //[base]~^^ ERROR the trait } diff --git a/src/test/ui/generic-associated-types/trait-objects.stderr b/src/test/ui/generic-associated-types/trait-objects.base.stderr index 5ab37910207..1df76a21bf9 100644 --- a/src/test/ui/generic-associated-types/trait-objects.stderr +++ b/src/test/ui/generic-associated-types/trait-objects.base.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `StreamingIterator` cannot be made into an object - --> $DIR/trait-objects.rs:10:21 + --> $DIR/trait-objects.rs:14:21 | LL | fn min_size(x: &mut dyn for<'a> StreamingIterator<Item<'a> = &'a i32>) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `StreamingIterator` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> - --> $DIR/trait-objects.rs:4:10 + --> $DIR/trait-objects.rs:8:10 | LL | trait StreamingIterator { | ----------------- this trait cannot be made into an object... diff --git a/src/test/ui/generic-associated-types/trait-objects.extended.nll.stderr b/src/test/ui/generic-associated-types/trait-objects.extended.nll.stderr new file mode 100644 index 00000000000..52d48d57859 --- /dev/null +++ b/src/test/ui/generic-associated-types/trait-objects.extended.nll.stderr @@ -0,0 +1,17 @@ +error[E0521]: borrowed data escapes outside of function + --> $DIR/trait-objects.rs:16:5 + | +LL | fn min_size(x: &mut dyn for<'a> StreamingIterator<Item<'a> = &'a i32>) -> usize { + | - - let's call the lifetime of this reference `'1` + | | + | `x` is a reference that is only valid in the function body +LL | +LL | x.size_hint().0 + | ^^^^^^^^^^^^^ + | | + | `x` escapes the function body here + | argument requires that `'1` must outlive `'static` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/generic-associated-types/trait-objects.extended.stderr b/src/test/ui/generic-associated-types/trait-objects.extended.stderr new file mode 100644 index 00000000000..7cc3dad9921 --- /dev/null +++ b/src/test/ui/generic-associated-types/trait-objects.extended.stderr @@ -0,0 +1,12 @@ +error[E0621]: explicit lifetime required in the type of `x` + --> $DIR/trait-objects.rs:16:7 + | +LL | fn min_size(x: &mut dyn for<'a> StreamingIterator<Item<'a> = &'a i32>) -> usize { + | ------------------------------------------------------ help: add explicit lifetime `'a` to the type of `x`: `&'a mut (dyn StreamingIterator<for<'a> Item = &'a i32> + 'a)` +LL | +LL | x.size_hint().0 + | ^^^^^^^^^ lifetime `'a` required + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0621`. diff --git a/src/test/ui/generic-associated-types/trait-objects.rs b/src/test/ui/generic-associated-types/trait-objects.rs index 559e6758a32..644e56ce21f 100644 --- a/src/test/ui/generic-associated-types/trait-objects.rs +++ b/src/test/ui/generic-associated-types/trait-objects.rs @@ -1,4 +1,8 @@ +// revisions: base extended + #![feature(generic_associated_types)] +#![cfg_attr(extended, feature(generic_associated_types_extended))] +#![cfg_attr(extended, allow(incomplete_features))] trait StreamingIterator { type Item<'a> where Self: 'a; @@ -8,8 +12,9 @@ trait StreamingIterator { } fn min_size(x: &mut dyn for<'a> StreamingIterator<Item<'a> = &'a i32>) -> usize { - //~^ the trait `StreamingIterator` cannot be made into an object + //[base]~^ the trait `StreamingIterator` cannot be made into an object x.size_hint().0 + //[extended]~^ explicit lifetime required } fn main() {} diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.stderr b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.stderr index b1107346421..066bf431a83 100644 --- a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.stderr +++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-62529-3.stderr @@ -4,6 +4,8 @@ error[E0277]: expected a `Fn<(<_ as ATC<'a>>::Type,)>` closure, found `F` LL | call(f, ()); | ^^^^ expected an `Fn<(<_ as ATC<'a>>::Type,)>` closure, found `F` | + = note: expected a closure with arguments `((),)` + found a closure with arguments `(<_ as ATC<'a>>::Type,)` note: required by a bound in `call` --> $DIR/issue-62529-3.rs:9:36 | diff --git a/src/test/ui/issues/issue-59494.stderr b/src/test/ui/issues/issue-59494.stderr index a9284535e4d..8b542bb69de 100644 --- a/src/test/ui/issues/issue-59494.stderr +++ b/src/test/ui/issues/issue-59494.stderr @@ -7,6 +7,8 @@ LL | let t8 = t8n(t7, t7p(f, g)); | required by a bound introduced by this call | = help: the trait `Fn<(_,)>` is not implemented for `impl Fn(((_, _), _))` + = note: expected a closure with arguments `(((_, _), _),)` + found a closure with arguments `(_,)` note: required by a bound in `t8n` --> $DIR/issue-59494.rs:5:45 | diff --git a/src/test/ui/lint/uninitialized-zeroed.rs b/src/test/ui/lint/uninitialized-zeroed.rs index 122933c3c4e..5cd323c01db 100644 --- a/src/test/ui/lint/uninitialized-zeroed.rs +++ b/src/test/ui/lint/uninitialized-zeroed.rs @@ -81,6 +81,9 @@ fn main() { let _val: *const dyn Send = mem::zeroed(); //~ ERROR: does not permit zero-initialization let _val: *const dyn Send = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: [fn(); 2] = mem::zeroed(); //~ ERROR: does not permit zero-initialization + let _val: [fn(); 2] = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + // Things that can be zero, but not uninit. let _val: bool = mem::zeroed(); let _val: bool = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized @@ -94,6 +97,9 @@ fn main() { let _val: Fruit = mem::zeroed(); let _val: Fruit = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + let _val: [bool; 2] = mem::zeroed(); + let _val: [bool; 2] = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized + // Transmute-from-0 let _val: &'static i32 = mem::transmute(0usize); //~ ERROR: does not permit zero-initialization let _val: &'static [i32] = mem::transmute((0usize, 0usize)); //~ ERROR: does not permit zero-initialization @@ -110,6 +116,8 @@ fn main() { let _val: MaybeUninit<&'static i32> = mem::zeroed(); let _val: i32 = mem::zeroed(); let _val: bool = MaybeUninit::zeroed().assume_init(); + let _val: [bool; 0] = MaybeUninit::uninit().assume_init(); + let _val: [!; 0] = MaybeUninit::zeroed().assume_init(); // Some things that happen to work due to rustc implementation details, // but are not guaranteed to keep working. let _val: i32 = mem::uninitialized(); diff --git a/src/test/ui/lint/uninitialized-zeroed.stderr b/src/test/ui/lint/uninitialized-zeroed.stderr index 0af185ef61b..b6a66f0a95a 100644 --- a/src/test/ui/lint/uninitialized-zeroed.stderr +++ b/src/test/ui/lint/uninitialized-zeroed.stderr @@ -329,8 +329,30 @@ LL | let _val: *const dyn Send = mem::uninitialized(); | = note: the vtable of a wide raw pointer must be non-null +error: the type `[fn(); 2]` does not permit zero-initialization + --> $DIR/uninitialized-zeroed.rs:84:31 + | +LL | let _val: [fn(); 2] = mem::zeroed(); + | ^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done + | + = note: function pointers must be non-null + +error: the type `[fn(); 2]` does not permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:85:31 + | +LL | let _val: [fn(); 2] = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done + | + = note: function pointers must be non-null + error: the type `bool` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:86:26 + --> $DIR/uninitialized-zeroed.rs:89:26 | LL | let _val: bool = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -341,7 +363,7 @@ LL | let _val: bool = mem::uninitialized(); = note: booleans must be either `true` or `false` error: the type `Wrap<char>` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:89:32 + --> $DIR/uninitialized-zeroed.rs:92:32 | LL | let _val: Wrap<char> = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -356,7 +378,7 @@ LL | struct Wrap<T> { wrapped: T } | ^^^^^^^^^^ error: the type `NonBig` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:92:28 + --> $DIR/uninitialized-zeroed.rs:95:28 | LL | let _val: NonBig = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -367,7 +389,7 @@ LL | let _val: NonBig = mem::uninitialized(); = note: `NonBig` must be initialized inside its custom valid range error: the type `Fruit` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:95:27 + --> $DIR/uninitialized-zeroed.rs:98:27 | LL | let _val: Fruit = mem::uninitialized(); | ^^^^^^^^^^^^^^^^^^^^ @@ -384,8 +406,19 @@ LL | | Banana, LL | | } | |_^ +error: the type `[bool; 2]` does not permit being left uninitialized + --> $DIR/uninitialized-zeroed.rs:101:31 + | +LL | let _val: [bool; 2] = mem::uninitialized(); + | ^^^^^^^^^^^^^^^^^^^^ + | | + | this code causes undefined behavior when executed + | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done + | + = note: booleans must be either `true` or `false` + error: the type `&i32` does not permit zero-initialization - --> $DIR/uninitialized-zeroed.rs:98:34 + --> $DIR/uninitialized-zeroed.rs:104:34 | LL | let _val: &'static i32 = mem::transmute(0usize); | ^^^^^^^^^^^^^^^^^^^^^^ @@ -396,7 +429,7 @@ LL | let _val: &'static i32 = mem::transmute(0usize); = note: references must be non-null error: the type `&[i32]` does not permit zero-initialization - --> $DIR/uninitialized-zeroed.rs:99:36 + --> $DIR/uninitialized-zeroed.rs:105:36 | LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -407,7 +440,7 @@ LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize)); = note: references must be non-null error: the type `NonZeroU32` does not permit zero-initialization - --> $DIR/uninitialized-zeroed.rs:100:32 + --> $DIR/uninitialized-zeroed.rs:106:32 | LL | let _val: NonZeroU32 = mem::transmute(0); | ^^^^^^^^^^^^^^^^^ @@ -418,7 +451,7 @@ LL | let _val: NonZeroU32 = mem::transmute(0); = note: `std::num::NonZeroU32` must be non-null error: the type `NonNull<i32>` does not permit zero-initialization - --> $DIR/uninitialized-zeroed.rs:103:34 + --> $DIR/uninitialized-zeroed.rs:109:34 | LL | let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -429,7 +462,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init(); = note: `std::ptr::NonNull<i32>` must be non-null error: the type `NonNull<i32>` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:104:34 + --> $DIR/uninitialized-zeroed.rs:110:34 | LL | let _val: NonNull<i32> = MaybeUninit::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -440,7 +473,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::uninit().assume_init(); = note: `std::ptr::NonNull<i32>` must be non-null error: the type `bool` does not permit being left uninitialized - --> $DIR/uninitialized-zeroed.rs:105:26 + --> $DIR/uninitialized-zeroed.rs:111:26 | LL | let _val: bool = MaybeUninit::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -450,5 +483,5 @@ LL | let _val: bool = MaybeUninit::uninit().assume_init(); | = note: booleans must be either `true` or `false` -error: aborting due to 36 previous errors +error: aborting due to 39 previous errors diff --git a/src/test/ui/macros/issue-95533.rs b/src/test/ui/macros/issue-95533.rs new file mode 100644 index 00000000000..905c14dc5fd --- /dev/null +++ b/src/test/ui/macros/issue-95533.rs @@ -0,0 +1,8 @@ +// check-pass + +#![no_implicit_prelude] +// the macro should not rely on the prelude being imported +::std::thread_local! { static P: () = (); } +::std::thread_local! { static Q: () = const { () }; } + +fn main () {} diff --git a/src/test/ui/parser/increment-autofix.fixed b/src/test/ui/parser/increment-autofix.fixed new file mode 100644 index 00000000000..7a426badfc2 --- /dev/null +++ b/src/test/ui/parser/increment-autofix.fixed @@ -0,0 +1,31 @@ +// run-rustfix + +pub fn pre_regular() { + let mut i = 0; + i += 1; //~ ERROR Rust has no prefix increment operator + println!("{}", i); +} + +pub fn pre_while() { + let mut i = 0; + while { i += 1; i } < 5 { + //~^ ERROR Rust has no prefix increment operator + println!("{}", i); + } +} + +pub fn pre_regular_tmp() { + let mut tmp = 0; + tmp += 1; //~ ERROR Rust has no prefix increment operator + println!("{}", tmp); +} + +pub fn pre_while_tmp() { + let mut tmp = 0; + while { tmp += 1; tmp } < 5 { + //~^ ERROR Rust has no prefix increment operator + println!("{}", tmp); + } +} + +fn main() {} diff --git a/src/test/ui/parser/increment-autofix.rs b/src/test/ui/parser/increment-autofix.rs new file mode 100644 index 00000000000..d38603697a7 --- /dev/null +++ b/src/test/ui/parser/increment-autofix.rs @@ -0,0 +1,31 @@ +// run-rustfix + +pub fn pre_regular() { + let mut i = 0; + ++i; //~ ERROR Rust has no prefix increment operator + println!("{}", i); +} + +pub fn pre_while() { + let mut i = 0; + while ++i < 5 { + //~^ ERROR Rust has no prefix increment operator + println!("{}", i); + } +} + +pub fn pre_regular_tmp() { + let mut tmp = 0; + ++tmp; //~ ERROR Rust has no prefix increment operator + println!("{}", tmp); +} + +pub fn pre_while_tmp() { + let mut tmp = 0; + while ++tmp < 5 { + //~^ ERROR Rust has no prefix increment operator + println!("{}", tmp); + } +} + +fn main() {} diff --git a/src/test/ui/parser/increment-autofix.stderr b/src/test/ui/parser/increment-autofix.stderr new file mode 100644 index 00000000000..593592ba4ab --- /dev/null +++ b/src/test/ui/parser/increment-autofix.stderr @@ -0,0 +1,52 @@ +error: Rust has no prefix increment operator + --> $DIR/increment-autofix.rs:5:5 + | +LL | ++i; + | ^^ not a valid prefix operator + | +help: use `+= 1` instead + | +LL - ++i; +LL + i += 1; + | + +error: Rust has no prefix increment operator + --> $DIR/increment-autofix.rs:11:11 + | +LL | while ++i < 5 { + | ----- ^^ not a valid prefix operator + | | + | while parsing the condition of this `while` expression + | +help: use `+= 1` instead + | +LL | while { i += 1; i } < 5 { + | ~ +++++++++ + +error: Rust has no prefix increment operator + --> $DIR/increment-autofix.rs:19:5 + | +LL | ++tmp; + | ^^ not a valid prefix operator + | +help: use `+= 1` instead + | +LL - ++tmp; +LL + tmp += 1; + | + +error: Rust has no prefix increment operator + --> $DIR/increment-autofix.rs:25:11 + | +LL | while ++tmp < 5 { + | ----- ^^ not a valid prefix operator + | | + | while parsing the condition of this `while` expression + | +help: use `+= 1` instead + | +LL | while { tmp += 1; tmp } < 5 { + | ~ +++++++++++ + +error: aborting due to 4 previous errors + diff --git a/src/test/ui/parser/increment-notfixed.rs b/src/test/ui/parser/increment-notfixed.rs new file mode 100644 index 00000000000..15f159e53d2 --- /dev/null +++ b/src/test/ui/parser/increment-notfixed.rs @@ -0,0 +1,61 @@ +struct Foo { + bar: Bar, +} + +struct Bar { + qux: i32, +} + +pub fn post_regular() { + let mut i = 0; + i++; //~ ERROR Rust has no postfix increment operator + println!("{}", i); +} + +pub fn post_while() { + let mut i = 0; + while i++ < 5 { + //~^ ERROR Rust has no postfix increment operator + println!("{}", i); + } +} + +pub fn post_regular_tmp() { + let mut tmp = 0; + tmp++; //~ ERROR Rust has no postfix increment operator + println!("{}", tmp); +} + +pub fn post_while_tmp() { + let mut tmp = 0; + while tmp++ < 5 { + //~^ ERROR Rust has no postfix increment operator + println!("{}", tmp); + } +} + +pub fn post_field() { + let foo = Foo { bar: Bar { qux: 0 } }; + foo.bar.qux++; + //~^ ERROR Rust has no postfix increment operator + println!("{}", foo.bar.qux); +} + +pub fn post_field_tmp() { + struct S { + tmp: i32 + } + let s = S { tmp: 0 }; + s.tmp++; + //~^ ERROR Rust has no postfix increment operator + println!("{}", s.tmp); +} + +pub fn pre_field() { + let foo = Foo { bar: Bar { qux: 0 } }; + ++foo.bar.qux; + //~^ ERROR Rust has no prefix increment operator + println!("{}", foo.bar.qux); +} + +fn main() {} diff --git a/src/test/ui/parser/increment-notfixed.stderr b/src/test/ui/parser/increment-notfixed.stderr new file mode 100644 index 00000000000..f23595da32a --- /dev/null +++ b/src/test/ui/parser/increment-notfixed.stderr @@ -0,0 +1,102 @@ +error: Rust has no postfix increment operator + --> $DIR/increment-notfixed.rs:11:6 + | +LL | i++; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | { let tmp = i; i += 1; tmp }; + | +++++++++++ ~~~~~~~~~~~~~~~ +LL - i++; +LL + i += 1; + | + +error: Rust has no postfix increment operator + --> $DIR/increment-notfixed.rs:17:12 + | +LL | while i++ < 5 { + | ----- ^^ not a valid postfix operator + | | + | while parsing the condition of this `while` expression + | +help: use `+= 1` instead + | +LL | while { let tmp = i; i += 1; tmp } < 5 { + | +++++++++++ ~~~~~~~~~~~~~~~ +LL - while i++ < 5 { +LL + while i += 1 < 5 { + | + +error: Rust has no postfix increment operator + --> $DIR/increment-notfixed.rs:25:8 + | +LL | tmp++; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | { let tmp_ = tmp; tmp += 1; tmp_ }; + | ++++++++++++ ~~~~~~~~~~~~~~~~~~ +LL - tmp++; +LL + tmp += 1; + | + +error: Rust has no postfix increment operator + --> $DIR/increment-notfixed.rs:31:14 + | +LL | while tmp++ < 5 { + | ----- ^^ not a valid postfix operator + | | + | while parsing the condition of this `while` expression + | +help: use `+= 1` instead + | +LL | while { let tmp_ = tmp; tmp += 1; tmp_ } < 5 { + | ++++++++++++ ~~~~~~~~~~~~~~~~~~ +LL - while tmp++ < 5 { +LL + while tmp += 1 < 5 { + | + +error: Rust has no postfix increment operator + --> $DIR/increment-notfixed.rs:39:16 + | +LL | foo.bar.qux++; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | { let tmp = foo.bar.qux; foo.bar.qux += 1; tmp }; + | +++++++++++ ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL - foo.bar.qux++; +LL + foo.bar.qux += 1; + | + +error: Rust has no postfix increment operator + --> $DIR/increment-notfixed.rs:49:10 + | +LL | s.tmp++; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | { let tmp = s.tmp; s.tmp += 1; tmp }; + | +++++++++++ ~~~~~~~~~~~~~~~~~~~ +LL - s.tmp++; +LL + s.tmp += 1; + | + +error: Rust has no prefix increment operator + --> $DIR/increment-notfixed.rs:56:5 + | +LL | ++foo.bar.qux; + | ^^ not a valid prefix operator + | +help: use `+= 1` instead + | +LL - ++foo.bar.qux; +LL + foo.bar.qux += 1; + | + +error: aborting due to 7 previous errors + diff --git a/src/test/ui/proc-macro/nested-macro-rules.stdout b/src/test/ui/proc-macro/nested-macro-rules.stdout index fa35e81148b..31113904041 100644 --- a/src/test/ui/proc-macro/nested-macro-rules.stdout +++ b/src/test/ui/proc-macro/nested-macro-rules.stdout @@ -1,14 +1,8 @@ PRINT-BANG INPUT (DISPLAY): FirstStruct PRINT-BANG INPUT (DEBUG): TokenStream [ - Group { - delimiter: None, - stream: TokenStream [ - Ident { - ident: "FirstStruct", - span: $DIR/auxiliary/nested-macro-rules.rs:16:14: 16:25 (#7), - }, - ], - span: $DIR/auxiliary/nested-macro-rules.rs:9:30: 9:35 (#6), + Ident { + ident: "FirstStruct", + span: $DIR/auxiliary/nested-macro-rules.rs:16:14: 16:25 (#7), }, ] PRINT-ATTR INPUT (DISPLAY): struct FirstAttrStruct {} @@ -17,15 +11,9 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ ident: "struct", span: $DIR/auxiliary/nested-macro-rules.rs:10:32: 10:38 (#6), }, - Group { - delimiter: None, - stream: TokenStream [ - Ident { - ident: "FirstAttrStruct", - span: $DIR/auxiliary/nested-macro-rules.rs:16:27: 16:42 (#7), - }, - ], - span: $DIR/auxiliary/nested-macro-rules.rs:10:39: 10:56 (#6), + Ident { + ident: "FirstAttrStruct", + span: $DIR/auxiliary/nested-macro-rules.rs:16:27: 16:42 (#7), }, Group { delimiter: Brace, diff --git a/src/test/ui/thread-local/name-collision.rs b/src/test/ui/thread-local/name-collision.rs new file mode 100644 index 00000000000..dcff9183ad9 --- /dev/null +++ b/src/test/ui/thread-local/name-collision.rs @@ -0,0 +1,15 @@ +// check-pass + +#[allow(non_camel_case_types)] +struct u8; + +std::thread_local! { + pub static A: i32 = f(); + pub static B: i32 = const { 0 }; +} + +fn f() -> i32 { + 0 +} + +fn main() {} diff --git a/src/test/ui/trait-bounds/mismatch-fn-trait.rs b/src/test/ui/trait-bounds/mismatch-fn-trait.rs new file mode 100644 index 00000000000..0ed64043a9a --- /dev/null +++ b/src/test/ui/trait-bounds/mismatch-fn-trait.rs @@ -0,0 +1,28 @@ +fn take(_f: impl FnMut(i32)) {} + +fn test1(f: impl FnMut(u32)) { + take(f) + //~^ ERROR [E0277] +} + +fn test2(f: impl FnMut(i32, i32)) { + take(f) + //~^ ERROR [E0277] +} + +fn test3(f: impl FnMut()) { + take(f) + //~^ ERROR [E0277] +} + +fn test4(f: impl FnOnce(i32)) { + take(f) + //~^ ERROR [E0277] +} + +fn test5(f: impl FnOnce(u32)) { + take(f) + //~^ ERROR [E0277] +} + +fn main() {} diff --git a/src/test/ui/trait-bounds/mismatch-fn-trait.stderr b/src/test/ui/trait-bounds/mismatch-fn-trait.stderr new file mode 100644 index 00000000000..961e6d88fbe --- /dev/null +++ b/src/test/ui/trait-bounds/mismatch-fn-trait.stderr @@ -0,0 +1,81 @@ +error[E0277]: expected a `FnMut<(i32,)>` closure, found `impl FnMut(u32)` + --> $DIR/mismatch-fn-trait.rs:4:10 + | +LL | take(f) + | ---- ^ expected an `FnMut<(i32,)>` closure, found `impl FnMut(u32)` + | | + | required by a bound introduced by this call + | + = note: expected a closure with arguments `(u32,)` + found a closure with arguments `(i32,)` +note: required by a bound in `take` + --> $DIR/mismatch-fn-trait.rs:1:18 + | +LL | fn take(_f: impl FnMut(i32)) {} + | ^^^^^^^^^^ required by this bound in `take` + +error[E0277]: expected a `FnMut<(i32,)>` closure, found `impl FnMut(i32, i32)` + --> $DIR/mismatch-fn-trait.rs:9:10 + | +LL | take(f) + | ---- ^ expected an `FnMut<(i32,)>` closure, found `impl FnMut(i32, i32)` + | | + | required by a bound introduced by this call + | + = note: expected a closure taking 2 arguments, but one taking 1 argument was given +note: required by a bound in `take` + --> $DIR/mismatch-fn-trait.rs:1:18 + | +LL | fn take(_f: impl FnMut(i32)) {} + | ^^^^^^^^^^ required by this bound in `take` + +error[E0277]: expected a `FnMut<(i32,)>` closure, found `impl FnMut()` + --> $DIR/mismatch-fn-trait.rs:14:10 + | +LL | take(f) + | ---- ^ expected an `FnMut<(i32,)>` closure, found `impl FnMut()` + | | + | required by a bound introduced by this call + | + = note: expected a closure taking 0 arguments, but one taking 1 argument was given +note: required by a bound in `take` + --> $DIR/mismatch-fn-trait.rs:1:18 + | +LL | fn take(_f: impl FnMut(i32)) {} + | ^^^^^^^^^^ required by this bound in `take` + +error[E0277]: expected a `FnMut<(i32,)>` closure, found `impl FnOnce(i32)` + --> $DIR/mismatch-fn-trait.rs:19:10 + | +LL | take(f) + | ---- ^ expected an `FnMut<(i32,)>` closure, found `impl FnOnce(i32)` + | | + | required by a bound introduced by this call + | + = note: `impl FnOnce(i32)` implements `FnOnce`, but it must implement `FnMut`, which is more general +note: required by a bound in `take` + --> $DIR/mismatch-fn-trait.rs:1:18 + | +LL | fn take(_f: impl FnMut(i32)) {} + | ^^^^^^^^^^ required by this bound in `take` + +error[E0277]: expected a `FnMut<(i32,)>` closure, found `impl FnOnce(u32)` + --> $DIR/mismatch-fn-trait.rs:24:10 + | +LL | take(f) + | ---- ^ expected an `FnMut<(i32,)>` closure, found `impl FnOnce(u32)` + | | + | required by a bound introduced by this call + | + = note: `impl FnOnce(u32)` implements `FnOnce`, but it must implement `FnMut`, which is more general + = note: expected a closure with arguments `(u32,)` + found a closure with arguments `(i32,)` +note: required by a bound in `take` + --> $DIR/mismatch-fn-trait.rs:1:18 + | +LL | fn take(_f: impl FnMut(i32)) {} + | ^^^^^^^^^^ required by this bound in `take` + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unboxed-closures/unboxed-closures-fnmut-as-fn.stderr b/src/test/ui/unboxed-closures/unboxed-closures-fnmut-as-fn.stderr index f379d73eecf..0ea1c1dcd5b 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-fnmut-as-fn.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closures-fnmut-as-fn.stderr @@ -7,6 +7,7 @@ LL | let x = call_it(&S, 22); | required by a bound introduced by this call | = help: the trait `Fn<(isize,)>` is not implemented for `S` + = note: `S` implements `FnMut`, but it must implement `Fn`, which is more general note: required by a bound in `call_it` --> $DIR/unboxed-closures-fnmut-as-fn.rs:22:14 | diff --git a/src/tools/miri b/src/tools/miri -Subproject c1bbf078f368b1a16951730148fe15127df249e +Subproject 732461b4cd2c4bfd8b229ad43fbc32c193b4049 |
