From d651baef95276deab03c42a732759f14be0dd076 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:51:14 +0200 Subject: [PATCH 1/8] Require LLVM_CONFIG to be set in rustc_llvm/build.rs This environment variable should always be set by bootstrap in `rustc_llvm_env`. The fallback is quite ugly and complicated, so removing it is nice. --- compiler/rustc_llvm/build.rs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 4b0c1229da1..a2709a8aedd 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -112,28 +112,10 @@ fn main() { restore_library_path(); - let target = env::var("TARGET").expect("TARGET was not set"); let llvm_config = - tracked_env_var_os("LLVM_CONFIG").map(|x| Some(PathBuf::from(x))).unwrap_or_else(|| { - if let Some(dir) = tracked_env_var_os("CARGO_TARGET_DIR").map(PathBuf::from) { - let to_test = dir - .parent() - .unwrap() - .parent() - .unwrap() - .join(&target) - .join("llvm/bin/llvm-config"); - if Command::new(&to_test).output().is_ok() { - return Some(to_test); - } - } - None - }); + PathBuf::from(tracked_env_var_os("LLVM_CONFIG").expect("LLVM_CONFIG was not set")); - if let Some(llvm_config) = &llvm_config { - println!("cargo:rerun-if-changed={}", llvm_config.display()); - } - let llvm_config = llvm_config.unwrap_or_else(|| PathBuf::from("llvm-config")); + println!("cargo:rerun-if-changed={}", llvm_config.display()); // Test whether we're cross-compiling LLVM. This is a pretty rare case // currently where we're producing an LLVM for a different platform than From 9d7090726d8c3c1bc267bb866415ca46051881a1 Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Thu, 4 Apr 2024 11:16:09 -0700 Subject: [PATCH 2/8] MSVC targets should use COFF as their archive format --- compiler/rustc_codegen_ssa/src/back/archive.rs | 6 +++++- compiler/rustc_target/src/spec/base/msvc.rs | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs index 22b58c13949..ef55682d541 100644 --- a/compiler/rustc_codegen_ssa/src/back/archive.rs +++ b/compiler/rustc_codegen_ssa/src/back/archive.rs @@ -231,7 +231,11 @@ fn build_inner(self, output: &Path) -> io::Result { "gnu" => ArchiveKind::Gnu, "bsd" => ArchiveKind::Bsd, "darwin" => ArchiveKind::Darwin, - "coff" => ArchiveKind::Coff, + "coff" => { + // FIXME: ar_archive_writer doesn't support COFF archives yet. + // https://github.com/rust-lang/ar_archive_writer/issues/9 + ArchiveKind::Gnu + } "aix_big" => ArchiveKind::AixBig, kind => { self.sess.dcx().emit_fatal(UnknownArchiveKind { kind }); diff --git a/compiler/rustc_target/src/spec/base/msvc.rs b/compiler/rustc_target/src/spec/base/msvc.rs index efe949a4e90..44fc376fea0 100644 --- a/compiler/rustc_target/src/spec/base/msvc.rs +++ b/compiler/rustc_target/src/spec/base/msvc.rs @@ -14,6 +14,7 @@ pub fn opts() -> TargetOptions { pre_link_args, abi_return_struct_as_int: true, emit_debug_gdb_scripts: false, + archive_format: "coff".into(), // Currently this is the only supported method of debuginfo on MSVC // where `*.pdb` files show up next to the final artifact. From 889e5719c642cd6f2592964d244ff6f1d01e65c6 Mon Sep 17 00:00:00 2001 From: bohan Date: Fri, 5 Apr 2024 23:12:43 +0800 Subject: [PATCH 3/8] explaining `DefKind::Field` --- compiler/rustc_hir/src/def.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index e8cecb1930f..2662f5661ba 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -113,6 +113,9 @@ pub enum DefKind { InlineConst, /// Opaque type, aka `impl Trait`. OpaqueTy, + /// A field in a struct, enum or union. e.g. + /// - `bar` in `struct Foo { bar: u8 }` + /// - `Foo::Bar::0` in `enum Foo { Bar(u8) }` Field, /// Lifetime parameter: the `'a` in `struct Foo<'a> { ... }` LifetimeParam, From 5b14497f01137053c3cd38caf7df6bfe0c504f65 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 5 Apr 2024 23:01:40 +0200 Subject: [PATCH 4/8] Move cfg and check-cfg configuration in it's own module and add docs --- compiler/rustc_session/src/config.rs | 348 +-------------------- compiler/rustc_session/src/config/cfg.rs | 373 +++++++++++++++++++++++ 2 files changed, 379 insertions(+), 342 deletions(-) create mode 100644 compiler/rustc_session/src/config/cfg.rs diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index d51fcf693ed..a4919b25fe3 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -10,19 +10,16 @@ use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind}; use crate::{filesearch, lint, HashStableContext}; use crate::{EarlyDiagCtxt, Session}; -use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey}; use rustc_errors::emitter::HumanReadableErrorType; use rustc_errors::{ColorConfig, DiagArgValue, DiagCtxtFlags, IntoDiagArg}; use rustc_feature::UnstableFeatures; use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION}; use rustc_span::source_map::FilePathMapping; -use rustc_span::symbol::{sym, Symbol}; use rustc_span::{FileName, FileNameDisplayPreference, RealFileName, SourceFileHashAlgorithm}; -use rustc_target::abi::Align; use rustc_target::spec::LinkSelfContainedComponents; -use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, SplitDebuginfo}; -use rustc_target::spec::{Target, TargetTriple, TARGETS}; +use rustc_target::spec::{SplitDebuginfo, Target, TargetTriple}; use std::collections::btree_map::{ Iter as BTreeMapIter, Keys as BTreeMapKeysIter, Values as BTreeMapValuesIter, }; @@ -36,8 +33,11 @@ use std::str::{self, FromStr}; use std::sync::LazyLock; +mod cfg; pub mod sigpipe; +pub use cfg::{Cfg, CheckCfg, ExpectedValues}; + /// The different settings that the `-C strip` flag can have. #[derive(Clone, Copy, PartialEq, Hash, Debug)] pub enum Strip { @@ -1201,346 +1201,10 @@ pub(crate) const fn default_lib_output() -> CrateType { CrateType::Rlib } -fn default_configuration(sess: &Session) -> Cfg { - let mut ret = Cfg::default(); - - macro_rules! ins_none { - ($key:expr) => { - ret.insert(($key, None)); - }; - } - macro_rules! ins_str { - ($key:expr, $val_str:expr) => { - ret.insert(($key, Some(Symbol::intern($val_str)))); - }; - } - macro_rules! ins_sym { - ($key:expr, $val_sym:expr) => { - ret.insert(($key, Some($val_sym))); - }; - } - - // Symbols are inserted in alphabetical order as much as possible. - // The exceptions are where control flow forces things out of order. - // - // Run `rustc --print cfg` to see the configuration in practice. - // - // NOTE: These insertions should be kept in sync with - // `CheckCfg::fill_well_known` below. - - if sess.opts.debug_assertions { - ins_none!(sym::debug_assertions); - } - - if sess.overflow_checks() { - ins_none!(sym::overflow_checks); - } - - ins_sym!(sym::panic, sess.panic_strategy().desc_symbol()); - - // JUSTIFICATION: before wrapper fn is available - #[allow(rustc::bad_opt_access)] - if sess.opts.crate_types.contains(&CrateType::ProcMacro) { - ins_none!(sym::proc_macro); - } - - if sess.is_nightly_build() { - ins_sym!(sym::relocation_model, sess.target.relocation_model.desc_symbol()); - } - - for mut s in sess.opts.unstable_opts.sanitizer { - // KASAN is still ASAN under the hood, so it uses the same attribute. - if s == SanitizerSet::KERNELADDRESS { - s = SanitizerSet::ADDRESS; - } - ins_str!(sym::sanitize, &s.to_string()); - } - - if sess.is_sanitizer_cfi_generalize_pointers_enabled() { - ins_none!(sym::sanitizer_cfi_generalize_pointers); - } - if sess.is_sanitizer_cfi_normalize_integers_enabled() { - ins_none!(sym::sanitizer_cfi_normalize_integers); - } - - ins_str!(sym::target_abi, &sess.target.abi); - ins_str!(sym::target_arch, &sess.target.arch); - ins_str!(sym::target_endian, sess.target.endian.as_str()); - ins_str!(sym::target_env, &sess.target.env); - - for family in sess.target.families.as_ref() { - ins_str!(sym::target_family, family); - if family == "windows" { - ins_none!(sym::windows); - } else if family == "unix" { - ins_none!(sym::unix); - } - } - - // `target_has_atomic*` - let layout = sess.target.parse_data_layout().unwrap_or_else(|err| { - sess.dcx().emit_fatal(err); - }); - let mut has_atomic = false; - for (i, align) in [ - (8, layout.i8_align.abi), - (16, layout.i16_align.abi), - (32, layout.i32_align.abi), - (64, layout.i64_align.abi), - (128, layout.i128_align.abi), - ] { - if i >= sess.target.min_atomic_width() && i <= sess.target.max_atomic_width() { - if !has_atomic { - has_atomic = true; - if sess.is_nightly_build() { - if sess.target.atomic_cas { - ins_none!(sym::target_has_atomic); - } - ins_none!(sym::target_has_atomic_load_store); - } - } - let mut insert_atomic = |sym, align: Align| { - if sess.target.atomic_cas { - ins_sym!(sym::target_has_atomic, sym); - } - if align.bits() == i { - ins_sym!(sym::target_has_atomic_equal_alignment, sym); - } - ins_sym!(sym::target_has_atomic_load_store, sym); - }; - insert_atomic(sym::integer(i), align); - if sess.target.pointer_width as u64 == i { - insert_atomic(sym::ptr, layout.pointer_align.abi); - } - } - } - - ins_str!(sym::target_os, &sess.target.os); - ins_sym!(sym::target_pointer_width, sym::integer(sess.target.pointer_width)); - - if sess.opts.unstable_opts.has_thread_local.unwrap_or(sess.target.has_thread_local) { - ins_none!(sym::target_thread_local); - } - - ins_str!(sym::target_vendor, &sess.target.vendor); - - // If the user wants a test runner, then add the test cfg. - if sess.is_test_crate() { - ins_none!(sym::test); - } - - ret -} - -/// The parsed `--cfg` options that define the compilation environment of the -/// crate, used to drive conditional compilation. -/// -/// An `FxIndexSet` is used to ensure deterministic ordering of error messages -/// relating to `--cfg`. -pub type Cfg = FxIndexSet<(Symbol, Option)>; - -/// The parsed `--check-cfg` options. -#[derive(Default)] -pub struct CheckCfg { - /// Is well known names activated - pub exhaustive_names: bool, - /// Is well known values activated - pub exhaustive_values: bool, - /// All the expected values for a config name - pub expecteds: FxHashMap>, - /// Well known names (only used for diagnostics purposes) - pub well_known_names: FxHashSet, -} - -pub enum ExpectedValues { - Some(FxHashSet>), - Any, -} - -impl ExpectedValues { - fn insert(&mut self, value: T) -> bool { - match self { - ExpectedValues::Some(expecteds) => expecteds.insert(Some(value)), - ExpectedValues::Any => false, - } - } -} - -impl Extend for ExpectedValues { - fn extend>(&mut self, iter: I) { - match self { - ExpectedValues::Some(expecteds) => expecteds.extend(iter.into_iter().map(Some)), - ExpectedValues::Any => {} - } - } -} - -impl<'a, T: Eq + Hash + Copy + 'a> Extend<&'a T> for ExpectedValues { - fn extend>(&mut self, iter: I) { - match self { - ExpectedValues::Some(expecteds) => expecteds.extend(iter.into_iter().map(|a| Some(*a))), - ExpectedValues::Any => {} - } - } -} - -impl CheckCfg { - pub fn fill_well_known(&mut self, current_target: &Target) { - if !self.exhaustive_values && !self.exhaustive_names { - return; - } - - let no_values = || { - let mut values = FxHashSet::default(); - values.insert(None); - ExpectedValues::Some(values) - }; - - let empty_values = || { - let values = FxHashSet::default(); - ExpectedValues::Some(values) - }; - - macro_rules! ins { - ($name:expr, $values:expr) => {{ - self.well_known_names.insert($name); - self.expecteds.entry($name).or_insert_with($values) - }}; - } - - // Symbols are inserted in alphabetical order as much as possible. - // The exceptions are where control flow forces things out of order. - // - // NOTE: This should be kept in sync with `default_configuration`. - // Note that symbols inserted conditionally in `default_configuration` - // are inserted unconditionally here. - // - // When adding a new config here you should also update - // `tests/ui/check-cfg/well-known-values.rs`. - // - // Don't forget to update `src/doc/unstable-book/src/compiler-flags/check-cfg.md` - // in the unstable book as well! - - ins!(sym::debug_assertions, no_values); - - // These four are never set by rustc, but we set them anyway: they - // should not trigger a lint because `cargo clippy`, `cargo doc`, - // `cargo test` and `cargo miri run` (respectively) can set them. - ins!(sym::clippy, no_values); - ins!(sym::doc, no_values); - ins!(sym::doctest, no_values); - ins!(sym::miri, no_values); - - ins!(sym::overflow_checks, no_values); - - ins!(sym::panic, empty_values).extend(&PanicStrategy::all()); - - ins!(sym::proc_macro, no_values); - - ins!(sym::relocation_model, empty_values).extend(RelocModel::all()); - - let sanitize_values = SanitizerSet::all() - .into_iter() - .map(|sanitizer| Symbol::intern(sanitizer.as_str().unwrap())); - ins!(sym::sanitize, empty_values).extend(sanitize_values); - - ins!(sym::sanitizer_cfi_generalize_pointers, no_values); - ins!(sym::sanitizer_cfi_normalize_integers, no_values); - - ins!(sym::target_feature, empty_values).extend( - rustc_target::target_features::all_known_features() - .map(|(f, _sb)| f) - .chain(rustc_target::target_features::RUSTC_SPECIFIC_FEATURES.iter().cloned()) - .map(Symbol::intern), - ); - - // sym::target_* - { - const VALUES: [&Symbol; 8] = [ - &sym::target_abi, - &sym::target_arch, - &sym::target_endian, - &sym::target_env, - &sym::target_family, - &sym::target_os, - &sym::target_pointer_width, - &sym::target_vendor, - ]; - - // Initialize (if not already initialized) - for &e in VALUES { - if !self.exhaustive_values { - ins!(e, || ExpectedValues::Any); - } else { - ins!(e, empty_values); - } - } - - if self.exhaustive_values { - // Get all values map at once otherwise it would be costly. - // (8 values * 220 targets ~= 1760 times, at the time of writing this comment). - let [ - values_target_abi, - values_target_arch, - values_target_endian, - values_target_env, - values_target_family, - values_target_os, - values_target_pointer_width, - values_target_vendor, - ] = self - .expecteds - .get_many_mut(VALUES) - .expect("unable to get all the check-cfg values buckets"); - - for target in TARGETS - .iter() - .map(|target| Target::expect_builtin(&TargetTriple::from_triple(target))) - .chain(iter::once(current_target.clone())) - { - values_target_abi.insert(Symbol::intern(&target.options.abi)); - values_target_arch.insert(Symbol::intern(&target.arch)); - values_target_endian.insert(Symbol::intern(target.options.endian.as_str())); - values_target_env.insert(Symbol::intern(&target.options.env)); - values_target_family.extend( - target.options.families.iter().map(|family| Symbol::intern(family)), - ); - values_target_os.insert(Symbol::intern(&target.options.os)); - values_target_pointer_width.insert(sym::integer(target.pointer_width)); - values_target_vendor.insert(Symbol::intern(&target.options.vendor)); - } - } - } - - let atomic_values = &[ - sym::ptr, - sym::integer(8usize), - sym::integer(16usize), - sym::integer(32usize), - sym::integer(64usize), - sym::integer(128usize), - ]; - for sym in [ - sym::target_has_atomic, - sym::target_has_atomic_equal_alignment, - sym::target_has_atomic_load_store, - ] { - ins!(sym, no_values).extend(atomic_values); - } - - ins!(sym::target_thread_local, no_values); - - ins!(sym::test, no_values); - - ins!(sym::unix, no_values); - ins!(sym::windows, no_values); - } -} - pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg { // Combine the configuration requested by the session (command line) with // some default and generated configuration items. - user_cfg.extend(default_configuration(sess)); + user_cfg.extend(cfg::default_configuration(sess)); user_cfg } diff --git a/compiler/rustc_session/src/config/cfg.rs b/compiler/rustc_session/src/config/cfg.rs new file mode 100644 index 00000000000..337019f720b --- /dev/null +++ b/compiler/rustc_session/src/config/cfg.rs @@ -0,0 +1,373 @@ +//! cfg and check-cfg configuration +//! +//! This module contains the definition of [`Cfg`] and [`CheckCfg`] +//! as well as the logic for creating the default configuration for a +//! given [`Session`]. +//! +//! It also contains the filling of the well known configs, which should +//! ALWAYS be in sync with the default_configuration. +//! +//! ## Adding a new cfg +//! +//! Adding a new feature requires two new symbols one for the cfg it-self +//! and the second one for the unstable feature gate, those are defined in +//! `rustc_span::symbol`. +//! +//! As well as the following points, +//! - Add the activation logic in [`default_configuration`] +//! - Add the cfg to [`CheckCfg::fill_well_known`] (and related files), +//! so that the compiler can know the cfg is expected +//! - Add the feature gating in `compiler/rustc_feature/src/builtin_attrs.rs` + +use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; +use rustc_span::symbol::{sym, Symbol}; +use rustc_target::abi::Align; +use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet}; +use rustc_target::spec::{Target, TargetTriple, TARGETS}; + +use crate::config::CrateType; +use crate::Session; + +use std::hash::Hash; +use std::iter; + +/// The parsed `--cfg` options that define the compilation environment of the +/// crate, used to drive conditional compilation. +/// +/// An `FxIndexSet` is used to ensure deterministic ordering of error messages +/// relating to `--cfg`. +pub type Cfg = FxIndexSet<(Symbol, Option)>; + +/// The parsed `--check-cfg` options. +#[derive(Default)] +pub struct CheckCfg { + /// Is well known names activated + pub exhaustive_names: bool, + /// Is well known values activated + pub exhaustive_values: bool, + /// All the expected values for a config name + pub expecteds: FxHashMap>, + /// Well known names (only used for diagnostics purposes) + pub well_known_names: FxHashSet, +} + +pub enum ExpectedValues { + Some(FxHashSet>), + Any, +} + +impl ExpectedValues { + fn insert(&mut self, value: T) -> bool { + match self { + ExpectedValues::Some(expecteds) => expecteds.insert(Some(value)), + ExpectedValues::Any => false, + } + } +} + +impl Extend for ExpectedValues { + fn extend>(&mut self, iter: I) { + match self { + ExpectedValues::Some(expecteds) => expecteds.extend(iter.into_iter().map(Some)), + ExpectedValues::Any => {} + } + } +} + +impl<'a, T: Eq + Hash + Copy + 'a> Extend<&'a T> for ExpectedValues { + fn extend>(&mut self, iter: I) { + match self { + ExpectedValues::Some(expecteds) => expecteds.extend(iter.into_iter().map(|a| Some(*a))), + ExpectedValues::Any => {} + } + } +} + +/// Generate the default configs for a given session +pub(crate) fn default_configuration(sess: &Session) -> Cfg { + let mut ret = Cfg::default(); + + macro_rules! ins_none { + ($key:expr) => { + ret.insert(($key, None)); + }; + } + macro_rules! ins_str { + ($key:expr, $val_str:expr) => { + ret.insert(($key, Some(Symbol::intern($val_str)))); + }; + } + macro_rules! ins_sym { + ($key:expr, $val_sym:expr) => { + ret.insert(($key, Some($val_sym))); + }; + } + + // Symbols are inserted in alphabetical order as much as possible. + // The exceptions are where control flow forces things out of order. + // + // Run `rustc --print cfg` to see the configuration in practice. + // + // NOTE: These insertions should be kept in sync with + // `CheckCfg::fill_well_known` below. + + if sess.opts.debug_assertions { + ins_none!(sym::debug_assertions); + } + + if sess.overflow_checks() { + ins_none!(sym::overflow_checks); + } + + ins_sym!(sym::panic, sess.panic_strategy().desc_symbol()); + + // JUSTIFICATION: before wrapper fn is available + #[allow(rustc::bad_opt_access)] + if sess.opts.crate_types.contains(&CrateType::ProcMacro) { + ins_none!(sym::proc_macro); + } + + if sess.is_nightly_build() { + ins_sym!(sym::relocation_model, sess.target.relocation_model.desc_symbol()); + } + + for mut s in sess.opts.unstable_opts.sanitizer { + // KASAN is still ASAN under the hood, so it uses the same attribute. + if s == SanitizerSet::KERNELADDRESS { + s = SanitizerSet::ADDRESS; + } + ins_str!(sym::sanitize, &s.to_string()); + } + + if sess.is_sanitizer_cfi_generalize_pointers_enabled() { + ins_none!(sym::sanitizer_cfi_generalize_pointers); + } + if sess.is_sanitizer_cfi_normalize_integers_enabled() { + ins_none!(sym::sanitizer_cfi_normalize_integers); + } + + ins_str!(sym::target_abi, &sess.target.abi); + ins_str!(sym::target_arch, &sess.target.arch); + ins_str!(sym::target_endian, sess.target.endian.as_str()); + ins_str!(sym::target_env, &sess.target.env); + + for family in sess.target.families.as_ref() { + ins_str!(sym::target_family, family); + if family == "windows" { + ins_none!(sym::windows); + } else if family == "unix" { + ins_none!(sym::unix); + } + } + + // `target_has_atomic*` + let layout = sess.target.parse_data_layout().unwrap_or_else(|err| { + sess.dcx().emit_fatal(err); + }); + let mut has_atomic = false; + for (i, align) in [ + (8, layout.i8_align.abi), + (16, layout.i16_align.abi), + (32, layout.i32_align.abi), + (64, layout.i64_align.abi), + (128, layout.i128_align.abi), + ] { + if i >= sess.target.min_atomic_width() && i <= sess.target.max_atomic_width() { + if !has_atomic { + has_atomic = true; + if sess.is_nightly_build() { + if sess.target.atomic_cas { + ins_none!(sym::target_has_atomic); + } + ins_none!(sym::target_has_atomic_load_store); + } + } + let mut insert_atomic = |sym, align: Align| { + if sess.target.atomic_cas { + ins_sym!(sym::target_has_atomic, sym); + } + if align.bits() == i { + ins_sym!(sym::target_has_atomic_equal_alignment, sym); + } + ins_sym!(sym::target_has_atomic_load_store, sym); + }; + insert_atomic(sym::integer(i), align); + if sess.target.pointer_width as u64 == i { + insert_atomic(sym::ptr, layout.pointer_align.abi); + } + } + } + + ins_str!(sym::target_os, &sess.target.os); + ins_sym!(sym::target_pointer_width, sym::integer(sess.target.pointer_width)); + + if sess.opts.unstable_opts.has_thread_local.unwrap_or(sess.target.has_thread_local) { + ins_none!(sym::target_thread_local); + } + + ins_str!(sym::target_vendor, &sess.target.vendor); + + // If the user wants a test runner, then add the test cfg. + if sess.is_test_crate() { + ins_none!(sym::test); + } + + ret +} + +impl CheckCfg { + /// Fill the current [`CheckCfg`] with all the well known cfgs + pub fn fill_well_known(&mut self, current_target: &Target) { + if !self.exhaustive_values && !self.exhaustive_names { + return; + } + + // for `#[cfg(foo)]` (ie. cfg value is none) + let no_values = || { + let mut values = FxHashSet::default(); + values.insert(None); + ExpectedValues::Some(values) + }; + + // preparation for inserting some values + let empty_values = || { + let values = FxHashSet::default(); + ExpectedValues::Some(values) + }; + + macro_rules! ins { + ($name:expr, $values:expr) => {{ + self.well_known_names.insert($name); + self.expecteds.entry($name).or_insert_with($values) + }}; + } + + // Symbols are inserted in alphabetical order as much as possible. + // The exceptions are where control flow forces things out of order. + // + // NOTE: This should be kept in sync with `default_configuration`. + // Note that symbols inserted conditionally in `default_configuration` + // are inserted unconditionally here. + // + // When adding a new config here you should also update + // `tests/ui/check-cfg/well-known-values.rs` (in order to test the + // expected values of the new config) and bless the all directory. + // + // Don't forget to update `src/doc/unstable-book/src/compiler-flags/check-cfg.md` + // in the unstable book as well! + + ins!(sym::debug_assertions, no_values); + + // These four are never set by rustc, but we set them anyway: they + // should not trigger a lint because `cargo clippy`, `cargo doc`, + // `cargo test` and `cargo miri run` (respectively) can set them. + ins!(sym::clippy, no_values); + ins!(sym::doc, no_values); + ins!(sym::doctest, no_values); + ins!(sym::miri, no_values); + + ins!(sym::overflow_checks, no_values); + + ins!(sym::panic, empty_values).extend(&PanicStrategy::all()); + + ins!(sym::proc_macro, no_values); + + ins!(sym::relocation_model, empty_values).extend(RelocModel::all()); + + let sanitize_values = SanitizerSet::all() + .into_iter() + .map(|sanitizer| Symbol::intern(sanitizer.as_str().unwrap())); + ins!(sym::sanitize, empty_values).extend(sanitize_values); + + ins!(sym::sanitizer_cfi_generalize_pointers, no_values); + ins!(sym::sanitizer_cfi_normalize_integers, no_values); + + ins!(sym::target_feature, empty_values).extend( + rustc_target::target_features::all_known_features() + .map(|(f, _sb)| f) + .chain(rustc_target::target_features::RUSTC_SPECIFIC_FEATURES.iter().cloned()) + .map(Symbol::intern), + ); + + // sym::target_* + { + const VALUES: [&Symbol; 8] = [ + &sym::target_abi, + &sym::target_arch, + &sym::target_endian, + &sym::target_env, + &sym::target_family, + &sym::target_os, + &sym::target_pointer_width, + &sym::target_vendor, + ]; + + // Initialize (if not already initialized) + for &e in VALUES { + if !self.exhaustive_values { + ins!(e, || ExpectedValues::Any); + } else { + ins!(e, empty_values); + } + } + + if self.exhaustive_values { + // Get all values map at once otherwise it would be costly. + // (8 values * 220 targets ~= 1760 times, at the time of writing this comment). + let [ + values_target_abi, + values_target_arch, + values_target_endian, + values_target_env, + values_target_family, + values_target_os, + values_target_pointer_width, + values_target_vendor, + ] = self + .expecteds + .get_many_mut(VALUES) + .expect("unable to get all the check-cfg values buckets"); + + for target in TARGETS + .iter() + .map(|target| Target::expect_builtin(&TargetTriple::from_triple(target))) + .chain(iter::once(current_target.clone())) + { + values_target_abi.insert(Symbol::intern(&target.options.abi)); + values_target_arch.insert(Symbol::intern(&target.arch)); + values_target_endian.insert(Symbol::intern(target.options.endian.as_str())); + values_target_env.insert(Symbol::intern(&target.options.env)); + values_target_family.extend( + target.options.families.iter().map(|family| Symbol::intern(family)), + ); + values_target_os.insert(Symbol::intern(&target.options.os)); + values_target_pointer_width.insert(sym::integer(target.pointer_width)); + values_target_vendor.insert(Symbol::intern(&target.options.vendor)); + } + } + } + + let atomic_values = &[ + sym::ptr, + sym::integer(8usize), + sym::integer(16usize), + sym::integer(32usize), + sym::integer(64usize), + sym::integer(128usize), + ]; + for sym in [ + sym::target_has_atomic, + sym::target_has_atomic_equal_alignment, + sym::target_has_atomic_load_store, + ] { + ins!(sym, no_values).extend(atomic_values); + } + + ins!(sym::target_thread_local, no_values); + + ins!(sym::test, no_values); + + ins!(sym::unix, no_values); + ins!(sym::windows, no_values); + } +} From c39c0e1e2b72129a1cda8fdea98e1a21b64e32a2 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 5 Apr 2024 23:02:36 +0200 Subject: [PATCH 5/8] Add mention for Urgau about cfg and check-cfg configuration changes --- triagebot.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index 55f0d32398f..abc44cc17dd 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -527,7 +527,12 @@ cc = ["@Nadrieril"] message = "Some changes occurred in exhaustiveness checking" cc = ["@Nadrieril"] +[mentions."compiler/rustc_session/src/config/cfg.rs"] +message = "Some changes occurred in cfg and check-cfg configuration" +cc = ["@Urgau"] + [mentions."compiler/rustc_lint/src/context/diagnostics/check_cfg.rs"] +message = "Some changes occurred in check-cfg diagnostics" cc = ["@Urgau"] [mentions."library/core/src/intrinsics/simd.rs"] From 5083378f166f660ff18af43a9e98b9075e8a91c7 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Sat, 30 Mar 2024 01:22:22 +0000 Subject: [PATCH 6/8] CFI: Don't rewrite ty::Dynamic directly Now that we're using a type folder, the arguments in predicates are processed automatically - we don't need to descend manually. We also want to keep projection clauses around, and this does so. --- .../src/typeid/typeid_itanium_cxx_abi.rs | 24 ++++--------------- ...adata-id-itanium-cxx-abi-function-types.rs | 18 +++++++------- ...metadata-id-itanium-cxx-abi-trait-types.rs | 24 +++++++++---------- 3 files changed, 25 insertions(+), 41 deletions(-) diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index c632712f5a9..87bb44a9fe4 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -283,12 +283,12 @@ fn encode_region<'tcx>(region: Region<'tcx>, dict: &mut FxHashMap, s.push('E'); compress(dict, DictKey::Region(region), &mut s); } - // FIXME(@lcnr): Why is `ReEarlyParam` reachable here. - RegionKind::ReEarlyParam(..) | RegionKind::ReErased => { + RegionKind::ReErased => { s.push_str("u6region"); compress(dict, DictKey::Region(region), &mut s); } - RegionKind::ReLateParam(..) + RegionKind::ReEarlyParam(..) + | RegionKind::ReLateParam(..) | RegionKind::ReStatic | RegionKind::ReError(_) | RegionKind::ReVar(..) @@ -776,6 +776,7 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { | ty::Coroutine(..) | ty::CoroutineClosure(..) | ty::CoroutineWitness(..) + | ty::Dynamic(..) | ty::Float(..) | ty::FnDef(..) | ty::Foreign(..) @@ -924,23 +925,6 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { } } - ty::Dynamic(predicates, _region, kind) => { - let predicates = self.tcx.mk_poly_existential_predicates_from_iter( - predicates.iter().filter_map(|predicate| match predicate.skip_binder() { - ty::ExistentialPredicate::Trait(trait_ref) => { - let trait_ref = ty::TraitRef::identity(self.tcx, trait_ref.def_id); - Some(ty::Binder::dummy(ty::ExistentialPredicate::Trait( - ty::ExistentialTraitRef::erase_self_ty(self.tcx, trait_ref), - ))) - } - ty::ExistentialPredicate::Projection(..) => None, - ty::ExistentialPredicate::AutoTrait(..) => Some(predicate), - }), - ); - - Ty::new_dynamic(self.tcx, predicates, self.tcx.lifetimes.re_erased, *kind) - } - ty::Alias(..) => { self.fold_ty(self.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), t)) } diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs index ab3d339989b..c5dadf70de9 100644 --- a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-function-types.rs @@ -34,12 +34,12 @@ pub fn foo12(_: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32, _: &dyn FnO // CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvPFu3i32S_EE"} // CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvPFu3i32S_ES0_E"} // CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvPFu3i32S_ES0_S0_E"} -// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5paramEu6regionEEE"} -// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5paramEu6regionEES3_E"} -// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5paramEu6regionEES3_S3_E"} -// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5paramEu6regionEEE"} -// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5paramEu6regionEES3_E"} -// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5paramEu6regionEES3_S3_E"} -// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5paramEu6regionEEE"} -// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5paramEu6regionEES3_E"} -// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5paramEu6regionEES3_S3_E"} +// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5tupleIu3i32EEu{{[0-9]+}}NtNtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnce6OutputIS0_ES_u6regionEEE"} +// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5tupleIu3i32EEu{{[0-9]+}}NtNtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnce6OutputIS0_ES_u6regionEES5_E"} +// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function2FnIu5tupleIu3i32EEu{{[0-9]+}}NtNtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnce6OutputIS0_ES_u6regionEES5_S5_E"} +// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5tupleIu3i32EEu{{[0-9]+}}NtNtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnce6OutputIS0_ES_u6regionEEE"} +// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5tupleIu3i32EEu{{[0-9]+}}NtNtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnce6OutputIS0_ES_u6regionEES5_E"} +// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function5FnMutIu5tupleIu3i32EEu{{[0-9]+}}NtNtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnce6OutputIS0_ES_u6regionEES5_S5_E"} +// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5tupleIu3i32EEu{{[0-9]+}}NtNtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnce6OutputIS0_ES_u6regionEEE"} +// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5tupleIu3i32EEu{{[0-9]+}}NtNtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnce6OutputIS0_ES_u6regionEES5_E"} +// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnceIu5tupleIu3i32EEu{{[0-9]+}}NtNtNtNtC{{[[:print:]]+}}_4core3ops8function6FnOnce6OutputIS0_ES_u6regionEES5_S5_E"} diff --git a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs index cc7178e41c7..6d9fe7040f7 100644 --- a/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs +++ b/tests/codegen/sanitizer/cfi/emit-type-metadata-id-itanium-cxx-abi-trait-types.rs @@ -132,7 +132,7 @@ pub fn foo27(_: &dyn Trait5, _: &dyn Trait5, _: &dyn Trait // CHECK: define{{.*}}5foo27{{.*}}!type ![[TYPE27:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} // CHECK: ![[TYPE13]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u6regionEEE"} -// CHECK: ![[TYPE16]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait2Iu5paramEu6regionEEE"} +// CHECK: ![[TYPE16]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait2Iu3i32Eu6regionEEE"} // CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEEE"} // CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEES2_E"} // CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEES2_S2_E"} @@ -148,14 +148,14 @@ pub fn foo27(_: &dyn Trait5, _: &dyn Trait5, _: &dyn Trait // CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker{{(4Send|4Sync)}}u6regionEES4_S4_E"} // CHECK: ![[TYPE14]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u6regionEES2_E"} // CHECK: ![[TYPE15]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait1u6regionEES2_S2_E"} -// CHECK: ![[TYPE17]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait2Iu5paramEu6regionEES3_E"} -// CHECK: ![[TYPE18]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait2Iu5paramEu6regionEES3_S3_E"} -// CHECK: ![[TYPE19]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait3Iu5paramEu6regionEEE"} -// CHECK: ![[TYPE20]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait3Iu5paramEu6regionEES3_E"} -// CHECK: ![[TYPE21]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait3Iu5paramEu6regionEES3_S3_E"} -// CHECK: ![[TYPE22]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait4Iu6regionu5paramEu6regionEEE"} -// CHECK: ![[TYPE23]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait4Iu6regionu5paramEu6regionEES4_E"} -// CHECK: ![[TYPE24]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait4Iu6regionu5paramEu6regionEES4_S4_E"} -// CHECK: ![[TYPE25]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait5Iu5paramLu5usizeEEu6regionEEE"} -// CHECK: ![[TYPE26]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait5Iu5paramLu5usizeEEu6regionEES5_E"} -// CHECK: ![[TYPE27]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait5Iu5paramLu5usizeEEu6regionEES5_S5_E"} +// CHECK: ![[TYPE17]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait2Iu3i32Eu6regionEES3_E"} +// CHECK: ![[TYPE18]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait2Iu3i32Eu6regionEES3_S3_E"} +// CHECK: ![[TYPE19]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait3Iu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type3Eu6regionEEE"} +// CHECK: ![[TYPE20]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait3Iu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type3Eu6regionEES3_E"} +// CHECK: ![[TYPE21]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait3Iu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type3Eu6regionEES3_S3_E"} +// CHECK: ![[TYPE22]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait4Iu6regionu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type4Eu{{[0-9]+}}NtNtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait46OutputIS_S0_Eu3refIu3i32ES_EEE"} +// CHECK: ![[TYPE23]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait4Iu6regionu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type4Eu{{[0-9]+}}NtNtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait46OutputIS_S0_Eu3refIu3i32ES_EES6_E"} +// CHECK: ![[TYPE24]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait4Iu6regionu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type4Eu{{[0-9]+}}NtNtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait46OutputIS_S0_Eu3refIu3i32ES_EES6_S6_E"} +// CHECK: ![[TYPE25]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait5Iu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type5Lu5usize32EEu6regionEEE"} +// CHECK: ![[TYPE26]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait5Iu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type5Lu5usize32EEu6regionEES5_E"} +// CHECK: ![[TYPE27]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}6Trait5Iu{{[0-9]+}}NtC{{[[:print:]]+}}_{{[[:print:]]+}}5Type5Lu5usize32EEu6regionEES5_S5_E"} From aa53bc0b04cb53ca59285b48679adce0f33a4410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 6 Apr 2024 01:15:31 +0000 Subject: [PATCH 7/8] Do not ICE when calling incorrectly defined `transmute` intrinsic Fix #123442 --- compiler/rustc_hir_typeck/src/expr.rs | 11 ++++++-- tests/ui/intrinsics/incorrect-transmute.rs | 8 ++++++ .../ui/intrinsics/incorrect-transmute.stderr | 25 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/ui/intrinsics/incorrect-transmute.rs create mode 100644 tests/ui/intrinsics/incorrect-transmute.stderr diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index d3e6eb124f7..6d9dc098fbe 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -547,13 +547,20 @@ pub(crate) fn check_expr_path( if tcx.fn_sig(did).skip_binder().abi() == RustIntrinsic && tcx.item_name(did) == sym::transmute { - let from = fn_sig.inputs().skip_binder()[0]; + let Some(from) = fn_sig.inputs().skip_binder().get(0) else { + let e = self.dcx().span_delayed_bug( + tcx.def_span(did), + "intrinsic fn `transmute` defined with no parameters", + ); + self.set_tainted_by_errors(e); + return Ty::new_error(tcx, e); + }; let to = fn_sig.output().skip_binder(); // We defer the transmute to the end of typeck, once all inference vars have // been resolved or we errored. This is important as we can only check transmute // on concrete types, but the output type may not be known yet (it would only // be known if explicitly specified via turbofish). - self.deferred_transmute_checks.borrow_mut().push((from, to, expr.hir_id)); + self.deferred_transmute_checks.borrow_mut().push((*from, to, expr.hir_id)); } if !tcx.features().unsized_fn_params { // We want to remove some Sized bounds from std functions, diff --git a/tests/ui/intrinsics/incorrect-transmute.rs b/tests/ui/intrinsics/incorrect-transmute.rs new file mode 100644 index 00000000000..4f1d1491ec9 --- /dev/null +++ b/tests/ui/intrinsics/incorrect-transmute.rs @@ -0,0 +1,8 @@ +fn main() { + transmute(); // does not ICE +} + +extern "rust-intrinsic" fn transmute() {} +//~^ ERROR intrinsic has wrong number of type parameters: found 0, expected 2 +//~| ERROR intrinsics are subject to change +//~| ERROR intrinsic must be in `extern "rust-intrinsic" { ... }` block diff --git a/tests/ui/intrinsics/incorrect-transmute.stderr b/tests/ui/intrinsics/incorrect-transmute.stderr new file mode 100644 index 00000000000..20b95925b76 --- /dev/null +++ b/tests/ui/intrinsics/incorrect-transmute.stderr @@ -0,0 +1,25 @@ +error[E0658]: intrinsics are subject to change + --> $DIR/incorrect-transmute.rs:5:8 + | +LL | extern "rust-intrinsic" fn transmute() {} + | ^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(intrinsics)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0094]: intrinsic has wrong number of type parameters: found 0, expected 2 + --> $DIR/incorrect-transmute.rs:5:37 + | +LL | extern "rust-intrinsic" fn transmute() {} + | ^ expected 2 type parameters + +error: intrinsic must be in `extern "rust-intrinsic" { ... }` block + --> $DIR/incorrect-transmute.rs:5:40 + | +LL | extern "rust-intrinsic" fn transmute() {} + | ^^ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0094, E0658. +For more information about an error, try `rustc --explain E0094`. From 262670a8f105803c28ba50014644ddbc6fa9accf Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 5 Apr 2024 18:54:38 -0700 Subject: [PATCH 8/8] Hide async_gen_internals from standard library documentation --- library/core/src/async_iter/async_iter.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/core/src/async_iter/async_iter.rs b/library/core/src/async_iter/async_iter.rs index 489f95bbf10..a0ffb6d4750 100644 --- a/library/core/src/async_iter/async_iter.rs +++ b/library/core/src/async_iter/async_iter.rs @@ -116,6 +116,7 @@ fn size_hint(&self) -> (usize, Option) { impl Poll> { /// A helper function for internal desugaring -- produces `Ready(Some(t))`, /// which corresponds to the async iterator yielding a value. + #[doc(hidden)] #[unstable(feature = "async_gen_internals", issue = "none")] #[lang = "AsyncGenReady"] pub fn async_gen_ready(t: T) -> Self { @@ -124,6 +125,7 @@ pub fn async_gen_ready(t: T) -> Self { /// A helper constant for internal desugaring -- produces `Pending`, /// which corresponds to the async iterator pending on an `.await`. + #[doc(hidden)] #[unstable(feature = "async_gen_internals", issue = "none")] #[lang = "AsyncGenPending"] // FIXME(gen_blocks): This probably could be deduplicated. @@ -131,6 +133,7 @@ pub fn async_gen_ready(t: T) -> Self { /// A helper constant for internal desugaring -- produces `Ready(None)`, /// which corresponds to the async iterator finishing its iteration. + #[doc(hidden)] #[unstable(feature = "async_gen_internals", issue = "none")] #[lang = "AsyncGenFinished"] pub const FINISHED: Self = Poll::Ready(None);