From 5c8c3a2c492a57c761e23ae19bdb63df487214f8 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Fri, 1 Dec 2023 21:19:39 +0100 Subject: [PATCH 1/4] rustc_hir_typeck: Fix ICE when probing for non-ASCII function alternative --- compiler/rustc_hir_typeck/src/method/probe.rs | 7 ++++--- tests/ui/suggestions/non_ascii_ident.rs | 3 +++ tests/ui/suggestions/non_ascii_ident.stderr | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 7d83f4a12b1fe..7a544c2f26d5a 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1799,9 +1799,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { .iter() .find(|cand| self.matches_by_doc_alias(cand.def_id)) .map(|cand| cand.name) - }) - .unwrap(); - Ok(applicable_close_candidates.into_iter().find(|method| method.name == best_name)) + }); + Ok(best_name.and_then(|best_name| { + applicable_close_candidates.into_iter().find(|method| method.name == best_name) + })) } }) } diff --git a/tests/ui/suggestions/non_ascii_ident.rs b/tests/ui/suggestions/non_ascii_ident.rs index 679ac4bcb6e3f..9c89714751826 100644 --- a/tests/ui/suggestions/non_ascii_ident.rs +++ b/tests/ui/suggestions/non_ascii_ident.rs @@ -1,4 +1,7 @@ fn main() { // There shall be no suggestions here. In particular not `Ok`. let _ = 读文; //~ ERROR cannot find value `读文` in this scope + + let f = 0f32; // Important line to make this an ICE regression test + 读文(f); //~ ERROR cannot find function `读文` in this scope } diff --git a/tests/ui/suggestions/non_ascii_ident.stderr b/tests/ui/suggestions/non_ascii_ident.stderr index 79fca3e1f612c..fdcc64aef3681 100644 --- a/tests/ui/suggestions/non_ascii_ident.stderr +++ b/tests/ui/suggestions/non_ascii_ident.stderr @@ -4,6 +4,12 @@ error[E0425]: cannot find value `读文` in this scope LL | let _ = 读文; | ^^^^ not found in this scope -error: aborting due to 1 previous error +error[E0425]: cannot find function `读文` in this scope + --> $DIR/non_ascii_ident.rs:6:5 + | +LL | 读文(f); + | ^^^^ not found in this scope + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0425`. From c997c6d8224c544632ba86ab849721758330de48 Mon Sep 17 00:00:00 2001 From: "Celina G. Val" Date: Fri, 1 Dec 2023 16:20:35 -0800 Subject: [PATCH 2/4] Add more information to stable Instance - Retrieve `FnSig`. - Implement CrateDef for InstanceDef. - Add VTable index for Virtual instances. --- compiler/rustc_smir/src/rustc_smir/context.rs | 24 ++++++++++- .../rustc_smir/src/rustc_smir/convert/ty.rs | 4 +- compiler/stable_mir/src/compiler_interface.rs | 17 ++++++-- compiler/stable_mir/src/mir/mono.rs | 43 +++++++++++++++---- compiler/stable_mir/src/ty.rs | 38 ++++++++++++++-- tests/ui-fulldeps/stable-mir/check_defs.rs | 28 +++++++++++- 6 files changed, 134 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/context.rs b/compiler/rustc_smir/src/rustc_smir/context.rs index 3449176f72937..0bd640ee1e3b0 100644 --- a/compiler/rustc_smir/src/rustc_smir/context.rs +++ b/compiler/rustc_smir/src/rustc_smir/context.rs @@ -3,6 +3,7 @@ //! This trait is currently the main interface between the Rust compiler, //! and the `stable_mir` crate. +use rustc_middle::ty; use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths}; use rustc_middle::ty::{GenericPredicates, Instance, ParamEnv, ScalarInt, ValTree}; use rustc_span::def_id::LOCAL_CRATE; @@ -12,9 +13,9 @@ use stable_mir::mir::mono::{InstanceDef, StaticDef}; use stable_mir::mir::Body; use stable_mir::ty::{ AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FnDef, GenericArgs, LineInfo, - RigidTy, Span, TyKind, + PolyFnSig, RigidTy, Span, TyKind, }; -use stable_mir::{self, Crate, CrateItem, Error, Filename, ItemKind, Symbol}; +use stable_mir::{self, Crate, CrateItem, DefId, Error, Filename, ItemKind, Symbol}; use std::cell::RefCell; use crate::rustc_internal::{internal, RustcInternal}; @@ -39,6 +40,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> { tables.tcx.instance_mir(rustc_middle::ty::InstanceDef::Item(def_id)).stable(&mut tables) } + fn has_body(&self, def: DefId) -> bool { + let tables = self.0.borrow(); + let def_id = tables[def]; + tables.tcx.is_mir_available(def_id) + } + fn all_trait_decls(&self) -> stable_mir::TraitDecls { let mut tables = self.0.borrow_mut(); tables @@ -195,6 +202,13 @@ impl<'tcx> Context for TablesWrapper<'tcx> { def.internal(&mut *tables).is_box() } + fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig { + let mut tables = self.0.borrow_mut(); + let def_id = def.0.internal(&mut *tables); + let sig = tables.tcx.fn_sig(def_id).instantiate(tables.tcx, args.internal(&mut *tables)); + sig.stable(&mut *tables) + } + fn eval_target_usize(&self, cnst: &Const) -> Result { let mut tables = self.0.borrow_mut(); let mir_const = cnst.internal(&mut *tables); @@ -266,6 +280,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> { tables.tcx.symbol_name(instance).name.to_string() } + fn is_empty_drop_shim(&self, def: InstanceDef) -> bool { + let tables = self.0.borrow_mut(); + let instance = tables.instances[def]; + matches!(instance.def, ty::InstanceDef::DropGlue(_, None)) + } + fn mono_instance(&self, item: stable_mir::CrateItem) -> stable_mir::mir::mono::Instance { let mut tables = self.0.borrow_mut(); let def_id = tables[item.0]; diff --git a/compiler/rustc_smir/src/rustc_smir/convert/ty.rs b/compiler/rustc_smir/src/rustc_smir/convert/ty.rs index 32ee928ddd406..f837f28e11ed2 100644 --- a/compiler/rustc_smir/src/rustc_smir/convert/ty.rs +++ b/compiler/rustc_smir/src/rustc_smir/convert/ty.rs @@ -777,7 +777,9 @@ impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> { let kind = match self.def { ty::InstanceDef::Item(..) => stable_mir::mir::mono::InstanceKind::Item, ty::InstanceDef::Intrinsic(..) => stable_mir::mir::mono::InstanceKind::Intrinsic, - ty::InstanceDef::Virtual(..) => stable_mir::mir::mono::InstanceKind::Virtual, + ty::InstanceDef::Virtual(_def_id, idx) => { + stable_mir::mir::mono::InstanceKind::Virtual { idx } + } ty::InstanceDef::VTableShim(..) | ty::InstanceDef::ReifyShim(..) | ty::InstanceDef::FnPtrAddrShim(..) diff --git a/compiler/stable_mir/src/compiler_interface.rs b/compiler/stable_mir/src/compiler_interface.rs index 827418a643259..daf4465963edd 100644 --- a/compiler/stable_mir/src/compiler_interface.rs +++ b/compiler/stable_mir/src/compiler_interface.rs @@ -10,8 +10,8 @@ use crate::mir::mono::{Instance, InstanceDef, StaticDef}; use crate::mir::Body; use crate::ty::{ AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FnDef, GenericArgs, - GenericPredicates, Generics, ImplDef, ImplTrait, LineInfo, RigidTy, Span, TraitDecl, TraitDef, - Ty, TyKind, + GenericPredicates, Generics, ImplDef, ImplTrait, LineInfo, PolyFnSig, RigidTy, Span, TraitDecl, + TraitDef, Ty, TyKind, }; use crate::{ mir, Crate, CrateItem, CrateItems, DefId, Error, Filename, ImplTraitDecls, ItemKind, Symbol, @@ -24,7 +24,11 @@ pub trait Context { fn entry_fn(&self) -> Option; /// Retrieve all items of the local crate that have a MIR associated with them. fn all_local_items(&self) -> CrateItems; + /// Retrieve the body of a function. + /// This function will panic if the body is not available. fn mir_body(&self, item: DefId) -> mir::Body; + /// Check whether the body of a function is available. + fn has_body(&self, item: DefId) -> bool; fn all_trait_decls(&self) -> TraitDecls; fn trait_decl(&self, trait_def: &TraitDef) -> TraitDecl; fn all_trait_impls(&self) -> ImplTraitDecls; @@ -64,6 +68,9 @@ pub trait Context { /// Returns if the ADT is a box. fn adt_is_box(&self, def: AdtDef) -> bool; + /// Retrieve the function signature for the given generic arguments. + fn fn_sig(&self, def: FnDef, args: &GenericArgs) -> PolyFnSig; + /// Evaluate constant as a target usize. fn eval_target_usize(&self, cnst: &Const) -> Result; @@ -85,8 +92,7 @@ pub trait Context { /// Obtain the representation of a type. fn ty_kind(&self, ty: Ty) -> TyKind; - /// Get the body of an Instance. - /// FIXME: Monomorphize the body. + /// Get the body of an Instance which is already monomorphized. fn instance_body(&self, instance: InstanceDef) -> Option; /// Get the instance type with generic substitutions applied and lifetimes erased. @@ -98,6 +104,9 @@ pub trait Context { /// Get the instance mangled name. fn instance_mangled_name(&self, instance: InstanceDef) -> Symbol; + /// Check if this is an empty DropGlue shim. + fn is_empty_drop_shim(&self, def: InstanceDef) -> bool; + /// Convert a non-generic crate item into an instance. /// This function will panic if the item is generic. fn mono_instance(&self, item: CrateItem) -> Instance; diff --git a/compiler/stable_mir/src/mir/mono.rs b/compiler/stable_mir/src/mir/mono.rs index 9f9af5d630904..10270c82e6323 100644 --- a/compiler/stable_mir/src/mir/mono.rs +++ b/compiler/stable_mir/src/mir/mono.rs @@ -1,6 +1,6 @@ use crate::crate_def::CrateDef; use crate::mir::Body; -use crate::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, IndexedVal, Ty}; +use crate::ty::{Allocation, ClosureDef, ClosureKind, FnDef, FnSig, GenericArgs, IndexedVal, Ty}; use crate::{with, CrateItem, DefId, Error, ItemKind, Opaque, Symbol}; use std::fmt::{Debug, Formatter}; @@ -27,7 +27,8 @@ pub enum InstanceKind { /// A compiler intrinsic function. Intrinsic, /// A virtual function definition stored in a VTable. - Virtual, + /// The `idx` field indicates the position in the VTable for this instance. + Virtual { idx: usize }, /// A compiler generated shim. Shim, } @@ -106,6 +107,24 @@ impl Instance { }) }) } + + /// Get this function signature with all types already instantiated. + pub fn fn_sig(&self) -> FnSig { + self.ty().kind().fn_sig().unwrap().skip_binder() + } + + /// Check whether this instance is an empty shim. + /// + /// Allow users to check if this shim can be ignored when called directly. + /// + /// We have decided not to export different types of Shims to StableMIR users, however, this + /// is a query that can be very helpful for users when processing DropGlue. + /// + /// When generating code for a Drop terminator, users can ignore an empty drop glue. + /// These shims are only needed to generate a valid Drop call done via VTable. + pub fn is_empty_shim(&self) -> bool { + self.kind == InstanceKind::Shim && with(|cx| cx.is_empty_drop_shim(self.def)) + } } impl Debug for Instance { @@ -124,8 +143,6 @@ impl TryFrom for Instance { fn try_from(item: CrateItem) -> Result { with(|context| { - // FIXME(celinval): - // - Return `Err` if instance does not have a body. if !context.requires_monomorphization(item.0) { Ok(context.mono_instance(item)) } else { @@ -141,11 +158,13 @@ impl TryFrom for CrateItem { type Error = crate::Error; fn try_from(value: Instance) -> Result { - if value.kind == InstanceKind::Item { - Ok(CrateItem(with(|context| context.instance_def_id(value.def)))) - } else { - Err(Error::new(format!("Item kind `{:?}` cannot be converted", value.kind))) - } + with(|context| { + if value.kind == InstanceKind::Item && context.has_body(value.def.def_id()) { + Ok(CrateItem(context.instance_def_id(value.def))) + } else { + Err(Error::new(format!("Item kind `{:?}` cannot be converted", value.kind))) + } + }) } } @@ -170,6 +189,12 @@ impl From for CrateItem { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct InstanceDef(usize); +impl CrateDef for InstanceDef { + fn def_id(&self) -> DefId { + with(|context| context.instance_def_id(*self)) + } +} + crate_def! { /// Holds information about a static variable definition. pub StaticDef; diff --git a/compiler/stable_mir/src/ty.rs b/compiler/stable_mir/src/ty.rs index 80558657debe3..6c4fb4a775352 100644 --- a/compiler/stable_mir/src/ty.rs +++ b/compiler/stable_mir/src/ty.rs @@ -168,7 +168,11 @@ impl TyKind { } pub fn is_unit(&self) -> bool { - matches!(self, TyKind::RigidTy(RigidTy::Tuple(data)) if data.len() == 0) + matches!(self, TyKind::RigidTy(RigidTy::Tuple(data)) if data.is_empty()) + } + + pub fn is_bool(&self) -> bool { + matches!(self, TyKind::RigidTy(RigidTy::Bool)) } pub fn is_trait(&self) -> bool { @@ -187,6 +191,14 @@ impl TyKind { matches!(self, TyKind::RigidTy(RigidTy::Adt(def, _)) if def.kind() == AdtKind::Union) } + pub fn is_fn(&self) -> bool { + matches!(self, TyKind::RigidTy(RigidTy::FnDef(..))) + } + + pub fn is_fn_ptr(&self) -> bool { + matches!(self, TyKind::RigidTy(RigidTy::FnPtr(..))) + } + pub fn trait_principal(&self) -> Option> { if let TyKind::RigidTy(RigidTy::Dynamic(predicates, _, _)) = self { if let Some(Binder { value: ExistentialPredicate::Trait(trait_ref), bound_vars }) = @@ -227,6 +239,15 @@ impl TyKind { _ => None, } } + + /// Get the function signature for function like types (Fn, FnPtr, Closure, Coroutine) + pub fn fn_sig(&self) -> Option { + match self { + TyKind::RigidTy(RigidTy::FnDef(def, args)) => Some(with(|cx| cx.fn_sig(*def, args))), + TyKind::RigidTy(RigidTy::FnPtr(sig)) => Some(sig.clone()), + _ => None, + } + } } pub struct TypeAndMut { @@ -307,8 +328,9 @@ crate_def! { } impl FnDef { - pub fn body(&self) -> Body { - with(|ctx| ctx.mir_body(self.0)) + // Get the function body if available. + pub fn body(&self) -> Option { + with(|ctx| ctx.has_body(self.0).then(|| ctx.mir_body(self.0))) } } @@ -488,6 +510,16 @@ pub struct FnSig { pub abi: Abi, } +impl FnSig { + pub fn output(&self) -> Ty { + self.inputs_and_output[self.inputs_and_output.len() - 1] + } + + pub fn inputs(&self) -> &[Ty] { + &self.inputs_and_output[..self.inputs_and_output.len() - 1] + } +} + #[derive(Clone, PartialEq, Eq, Debug)] pub enum Abi { Rust, diff --git a/tests/ui-fulldeps/stable-mir/check_defs.rs b/tests/ui-fulldeps/stable-mir/check_defs.rs index bbb4959628888..d311be5982d2d 100644 --- a/tests/ui-fulldeps/stable-mir/check_defs.rs +++ b/tests/ui-fulldeps/stable-mir/check_defs.rs @@ -18,10 +18,11 @@ extern crate rustc_driver; extern crate rustc_interface; extern crate stable_mir; +use std::assert_matches::assert_matches; use mir::{mono::Instance, TerminatorKind::*}; use rustc_middle::ty::TyCtxt; use rustc_smir::rustc_internal; -use stable_mir::ty::{RigidTy, TyKind}; +use stable_mir::ty::{RigidTy, TyKind, Ty, UintTy}; use stable_mir::*; use std::io::Write; use std::ops::ControlFlow; @@ -39,6 +40,7 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> { assert_eq!(instances.len(), 2); test_fn(instances[0], "from_u32", "std::char::from_u32", "core"); test_fn(instances[1], "Vec::::new", "std::vec::Vec::::new", "alloc"); + test_vec_new(instances[1]); ControlFlow::Continue(()) } @@ -56,6 +58,30 @@ fn test_fn(instance: Instance, expected_trimmed: &str, expected_qualified: &str, assert_eq!(&item.krate().name, krate); } +fn extract_elem_ty(ty: Ty) -> Ty { + match ty.kind() { + TyKind::RigidTy(RigidTy::Adt(_, args)) => { + *args.0[0].expect_ty() + } + _ => unreachable!("Expected Vec ADT, but found: {ty:?}") + } +} + +/// Check signature and type of `Vec::::new` and its generic version. +fn test_vec_new(instance: mir::mono::Instance) { + let sig = instance.fn_sig(); + assert_matches!(sig.inputs(), &[]); + let elem_ty = extract_elem_ty(sig.output()); + assert_matches!(elem_ty.kind(), TyKind::RigidTy(RigidTy::Uint(UintTy::U8))); + + // Get the signature for Vec::::new. + let item = CrateItem::try_from(instance).unwrap(); + let ty = item.ty(); + let gen_sig = ty.kind().fn_sig().unwrap().skip_binder(); + let gen_ty = extract_elem_ty(gen_sig.output()); + assert_matches!(gen_ty.kind(), TyKind::Param(_)); +} + /// Inspect the instance body fn get_instances(body: mir::Body) -> Vec { body.blocks.iter().filter_map(|bb| { From b7e6da80af0d316b966940368abf073c89abdce9 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sat, 2 Dec 2023 12:44:23 +0300 Subject: [PATCH 3/4] replace `once_cell::sync::OnceCell` with std `OnceLock` Signed-off-by: onur-ozkan --- src/bootstrap/src/core/builder.rs | 11 +++++------ src/bootstrap/src/core/config/config.rs | 4 ++-- src/bootstrap/src/core/download.rs | 6 +++--- src/bootstrap/src/lib.rs | 4 ++-- src/bootstrap/src/utils/helpers.rs | 4 ++-- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index aaddf5ca09cb0..65af2aed6de37 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -10,6 +10,7 @@ use std::io::{BufRead, BufReader}; use std::ops::Deref; use std::path::{Path, PathBuf}; use std::process::Command; +use std::sync::OnceLock; use std::time::{Duration, Instant}; use crate::core::build_steps::llvm; @@ -25,12 +26,10 @@ use crate::EXTRA_CHECK_CFGS; use crate::{Build, CLang, DocTests, GitRepo, Mode}; pub use crate::Compiler; -// FIXME: -// - use std::lazy for `Lazy` -// - use std::cell for `OnceCell` -// Once they get stabilized and reach beta. + use clap::ValueEnum; -use once_cell::sync::{Lazy, OnceCell}; +// FIXME: replace with std::lazy after it gets stabilized and reaches beta +use once_cell::sync::Lazy; #[cfg(test)] #[path = "../tests/builder.rs"] @@ -496,7 +495,7 @@ impl<'a> ShouldRun<'a> { /// /// [`path`]: ShouldRun::path pub fn paths(mut self, paths: &[&str]) -> Self { - static SUBMODULES_PATHS: OnceCell> = OnceCell::new(); + static SUBMODULES_PATHS: OnceLock> = OnceLock::new(); let init_submodules_paths = |src: &PathBuf| { let file = File::open(src.join(".gitmodules")).unwrap(); diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 9ef90798590ce..22e8ce8365b1f 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -17,6 +17,7 @@ use std::io::IsTerminal; use std::path::{Path, PathBuf}; use std::process::Command; use std::str::FromStr; +use std::sync::OnceLock; use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX; use crate::core::build_steps::llvm; @@ -25,7 +26,6 @@ use crate::utils::cache::{Interned, INTERNER}; use crate::utils::channel::{self, GitInfo}; use crate::utils::helpers::{exe, output, t}; use build_helper::exit; -use once_cell::sync::OnceCell; use semver::Version; use serde::{Deserialize, Deserializer}; use serde_derive::Deserialize; @@ -1907,7 +1907,7 @@ impl Config { } pub(crate) fn download_rustc_commit(&self) -> Option<&str> { - static DOWNLOAD_RUSTC: OnceCell> = OnceCell::new(); + static DOWNLOAD_RUSTC: OnceLock> = OnceLock::new(); if self.dry_run() && DOWNLOAD_RUSTC.get().is_none() { // avoid trying to actually download the commit return self.download_rustc_commit.as_deref(); diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs index 3327aed9600b2..0a5844a6859f8 100644 --- a/src/bootstrap/src/core/download.rs +++ b/src/bootstrap/src/core/download.rs @@ -5,10 +5,10 @@ use std::{ io::{BufRead, BufReader, BufWriter, ErrorKind, Write}, path::{Path, PathBuf}, process::{Command, Stdio}, + sync::OnceLock, }; use build_helper::ci::CiEnv; -use once_cell::sync::OnceCell; use xz2::bufread::XzDecoder; use crate::core::build_steps::llvm::detect_llvm_sha; @@ -16,7 +16,7 @@ use crate::core::config::RustfmtMetadata; use crate::utils::helpers::{check_run, exe, program_out_of_date}; use crate::{t, Config}; -static SHOULD_FIX_BINS_AND_DYLIBS: OnceCell = OnceCell::new(); +static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock = OnceLock::new(); /// `Config::try_run` wrapper for this module to avoid warnings on `try_run`, since we don't have access to a `builder` yet. fn try_run(config: &Config, cmd: &mut Command) -> Result<(), ()> { @@ -131,7 +131,7 @@ impl Config { println!("attempting to patch {}", fname.display()); // Only build `.nix-deps` once. - static NIX_DEPS_DIR: OnceCell = OnceCell::new(); + static NIX_DEPS_DIR: OnceLock = OnceLock::new(); let mut nix_build_succeeded = true; let nix_deps_dir = NIX_DEPS_DIR.get_or_init(|| { // Run `nix-build` to "build" each dependency (which will likely reuse diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 480dd75791517..60a89e9bf0709 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -25,12 +25,12 @@ use std::io; use std::path::{Path, PathBuf}; use std::process::{Command, Output, Stdio}; use std::str; +use std::sync::OnceLock; use build_helper::ci::{gha, CiEnv}; use build_helper::exit; use build_helper::util::fail; use filetime::FileTime; -use once_cell::sync::OnceCell; use sha2::digest::Digest; use termcolor::{ColorChoice, StandardStream, WriteColor}; use utils::channel::GitInfo; @@ -906,7 +906,7 @@ impl Build { /// Returns the sysroot of the snapshot compiler. fn rustc_snapshot_sysroot(&self) -> &Path { - static SYSROOT_CACHE: OnceCell = once_cell::sync::OnceCell::new(); + static SYSROOT_CACHE: OnceLock = OnceLock::new(); SYSROOT_CACHE.get_or_init(|| { let mut rustc = Command::new(&self.initial_rustc); rustc.args(&["--print", "sysroot"]); diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index 89fa2b805cd16..f878d6347435e 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -11,11 +11,11 @@ use std::io; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use std::str; +use std::sync::OnceLock; use std::time::{Instant, SystemTime, UNIX_EPOCH}; use crate::core::builder::Builder; use crate::core::config::{Config, TargetSelection}; -use crate::OnceCell; pub use crate::utils::dylib::{dylib_path, dylib_path_var}; @@ -444,7 +444,7 @@ pub fn get_clang_cl_resource_dir(clang_cl_path: &str) -> PathBuf { } pub fn lld_flag_no_threads(is_windows: bool) -> &'static str { - static LLD_NO_THREADS: OnceCell<(&'static str, &'static str)> = OnceCell::new(); + static LLD_NO_THREADS: OnceLock<(&'static str, &'static str)> = OnceLock::new(); let (windows, other) = LLD_NO_THREADS.get_or_init(|| { let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version")); let newer = match (out.find(char::is_numeric), out.find('.')) { From 253d61714d3c9421b647c3be67ce203fbfb23323 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 2 Dec 2023 14:25:03 +0100 Subject: [PATCH 4/4] move packed-struct tests into packed/ folder --- src/tools/tidy/src/ui_tests.rs | 2 +- .../packed-struct-generic-transmute.rs | 0 .../packed-struct-generic-transmute.stderr | 0 tests/ui/{packed-struct => packed}/packed-struct-transmute.rs | 0 .../ui/{packed-struct => packed}/packed-struct-transmute.stderr | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename tests/ui/{packed-struct => packed}/packed-struct-generic-transmute.rs (100%) rename tests/ui/{packed-struct => packed}/packed-struct-generic-transmute.stderr (100%) rename tests/ui/{packed-struct => packed}/packed-struct-transmute.rs (100%) rename tests/ui/{packed-struct => packed}/packed-struct-transmute.stderr (100%) diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index dfa386b49de7c..40149f8f1c3b6 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -11,7 +11,7 @@ use std::path::{Path, PathBuf}; const ENTRY_LIMIT: usize = 900; // FIXME: The following limits should be reduced eventually. const ISSUES_ENTRY_LIMIT: usize = 1852; -const ROOT_ENTRY_LIMIT: usize = 867; +const ROOT_ENTRY_LIMIT: usize = 866; const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[ "rs", // test source files diff --git a/tests/ui/packed-struct/packed-struct-generic-transmute.rs b/tests/ui/packed/packed-struct-generic-transmute.rs similarity index 100% rename from tests/ui/packed-struct/packed-struct-generic-transmute.rs rename to tests/ui/packed/packed-struct-generic-transmute.rs diff --git a/tests/ui/packed-struct/packed-struct-generic-transmute.stderr b/tests/ui/packed/packed-struct-generic-transmute.stderr similarity index 100% rename from tests/ui/packed-struct/packed-struct-generic-transmute.stderr rename to tests/ui/packed/packed-struct-generic-transmute.stderr diff --git a/tests/ui/packed-struct/packed-struct-transmute.rs b/tests/ui/packed/packed-struct-transmute.rs similarity index 100% rename from tests/ui/packed-struct/packed-struct-transmute.rs rename to tests/ui/packed/packed-struct-transmute.rs diff --git a/tests/ui/packed-struct/packed-struct-transmute.stderr b/tests/ui/packed/packed-struct-transmute.stderr similarity index 100% rename from tests/ui/packed-struct/packed-struct-transmute.stderr rename to tests/ui/packed/packed-struct-transmute.stderr