diff --git a/Cargo.lock b/Cargo.lock index 0af7e9a51e285..66ae09a5c4618 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1812,9 +1812,9 @@ dependencies = [ [[package]] name = "icu_list" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeeaf517689324395bed4767f7c65504f5455942ed4c14ee54c2087ca00b816e" +checksum = "5a5c625125085fac4bf9ad111888a90c6ab9dc7bcaec392ca79cab417f46e3fb" dependencies = [ "icu_provider", "regex-automata", @@ -1824,39 +1824,38 @@ dependencies = [ ] [[package]] -name = "icu_locale" -version = "2.2.0" +name = "icu_locale_core" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5a396343c7208121dc86e35623d3dfe19814a7613cfd14964994cdc9c9a2e26" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" dependencies = [ - "icu_collections", - "icu_locale_core", - "icu_locale_data", - "icu_provider", - "potential_utf", + "displaydoc", + "litemap", + "serde", "tinystr", + "writeable", "zerovec", ] [[package]] -name = "icu_locale_core" -version = "2.2.0" +name = "icu_locale_fallback" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +checksum = "251af8e57c9400e3eb58242fe5b8b1152b2a64fdf4cf632f923c38ccee6f2fa9" dependencies = [ - "displaydoc", - "litemap", - "serde", + "icu_locale_core", + "icu_locale_fallback_data", + "icu_provider", + "potential_utf", "tinystr", - "writeable", "zerovec", ] [[package]] -name = "icu_locale_data" -version = "2.2.0" +name = "icu_locale_fallback_data" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5fdcc9ac77c6d74ff5cf6e65ef3181d6af32003b16fce3a77fb451d2f695993" +checksum = "decf2a22ec8fa68f1a0c1129a3f8583f8f8bc24e8b9ccbe98ead99f62a4dc3a8" [[package]] name = "icu_normalizer" @@ -1900,9 +1899,9 @@ checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" [[package]] name = "icu_provider" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +checksum = "92a7ed671a6aad807a8651a2e1782a6598fda9ce5185dd8158549e95a91c6428" dependencies = [ "displaydoc", "icu_locale_core", @@ -3727,7 +3726,7 @@ name = "rustc_baked_icu_data" version = "0.0.0" dependencies = [ "icu_list", - "icu_locale", + "icu_locale_fallback", "icu_provider", "zerovec", ] @@ -4003,7 +4002,7 @@ version = "0.0.0" dependencies = [ "fluent-bundle", "icu_list", - "icu_locale", + "icu_locale_core", "intl-memoizer", "rustc_baked_icu_data", "rustc_data_structures", @@ -5783,9 +5782,9 @@ dependencies = [ [[package]] name = "tinystr" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" dependencies = [ "displaydoc", "serde_core", @@ -6901,9 +6900,9 @@ dependencies = [ [[package]] name = "writeable" -version = "0.6.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" [[package]] name = "x" @@ -6930,9 +6929,9 @@ dependencies = [ [[package]] name = "yoke" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" dependencies = [ "stable_deref_trait", "yoke-derive", @@ -6994,9 +6993,9 @@ dependencies = [ [[package]] name = "zerotrie" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" dependencies = [ "displaydoc", "yoke", @@ -7006,9 +7005,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.6" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +checksum = "94b5c6b5976d66c1d703c4fd17d3f5e43c8cedaacf604961b171adc7130896d8" dependencies = [ "serde", "yoke", @@ -7018,13 +7017,13 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.11.3" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +checksum = "9f212a141d820099d57ffafb9569be9617a6f27d3dc881fbee8fb56642f917a9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 3.0.3", ] [[package]] diff --git a/compiler/rustc_attr_parsing/src/stability.rs b/compiler/rustc_attr_parsing/src/stability.rs index 9ae8287812542..53851d9deaecf 100644 --- a/compiler/rustc_attr_parsing/src/stability.rs +++ b/compiler/rustc_attr_parsing/src/stability.rs @@ -7,13 +7,15 @@ use crate::{AttributeParser, ShouldEmit}; #[macro_export] macro_rules! unstable { - ($feat: ident $(, $notes:expr)*) => { + ($feat: ident $(, $notes:expr)*) => {{ + // Check that the feature exists + _ = rustc_feature::Features::$feat; + AttributeStability::Unstable { gate_name: rustc_span::sym::$feat, - gate_check: rustc_feature::Features::$feat, notes: &[$($notes),*], } - }; + }}; } impl<'sess> AttributeParser<'sess> { @@ -27,12 +29,11 @@ impl<'sess> AttributeParser<'sess> { return; } - let AttributeStability::Unstable { gate_check, gate_name, notes } = expected_stability - else { + let AttributeStability::Unstable { gate_name, notes } = expected_stability else { return; }; - if gate_check(self.features()) || attr_span.allows_unstable(gate_name) { + if self.features().enabled(gate_name) || attr_span.allows_unstable(gate_name) { return; } diff --git a/compiler/rustc_baked_icu_data/Cargo.toml b/compiler/rustc_baked_icu_data/Cargo.toml index c3887e4580d71..072084e8ff061 100644 --- a/compiler/rustc_baked_icu_data/Cargo.toml +++ b/compiler/rustc_baked_icu_data/Cargo.toml @@ -5,8 +5,8 @@ edition = "2024" [dependencies] # tidy-alphabetical-start -icu_list = { version = "2.2", default-features = false } -icu_locale = { version = "2.2", default-features = false, features = ["compiled_data"] } -icu_provider = { version = "2.2", features = ["baked", "sync"] } +icu_list = { version = "2.3", default-features = false } +icu_locale_fallback = { version = "2.3", default-features = false, features = ["compiled_data"] } +icu_provider = { version = "2.3", features = ["baked", "sync"] } zerovec = "0.11.0" # tidy-alphabetical-end diff --git a/compiler/rustc_baked_icu_data/src/data/list_and_v1.rs.data b/compiler/rustc_baked_icu_data/src/data/list_and_v1.rs.data index e89e10d20de7b..6a0d2bf61e49e 100644 --- a/compiler/rustc_baked_icu_data/src/data/list_and_v1.rs.data +++ b/compiler/rustc_baked_icu_data/src/data/list_and_v1.rs.data @@ -11,7 +11,7 @@ /// /// This macro requires the following crates: /// * `icu_list` -/// * `icu_locale/compiled_data` +/// * `icu_locale_fallback/compiled_data` /// * `icu_provider` /// * `icu_provider/baked` /// * `zerovec` @@ -19,9 +19,9 @@ #[macro_export] macro_rules! __impl_list_and_v1 { ($ provider : ty) => { - #[clippy::msrv = "1.86"] + #[clippy::msrv = "1.88"] const _: () = <$provider>::MUST_USE_MAKE_PROVIDER_MACRO; - #[clippy::msrv = "1.86"] + #[clippy::msrv = "1.88"] impl $provider { const DATA_LIST_AND_V1: icu_provider::baked::zerotrie::Data = { const TRIE: icu_provider::baked::zerotrie::ZeroTrieSimpleAscii<&'static [u8]> = icu_provider::baked::zerotrie::ZeroTrieSimpleAscii { store: b"\xC8efijprtz\x18#.9DOZ\xC2ns\n\x1E\xC3NSW\x01\x02\x80\x85\x8A\x1E\xC3NSW\x01\x02\x81\x81\x81r\x1E\xC3NSW\x01\x02\x80\x86\x86t\x1E\xC3NSW\x01\x02\x82\x82\x82a\x1E\xC3NSW\x01\x02\x83\x83\x83t\x1E\xC3NSW\x01\x02\x80\x82\x82u\x1E\xC3NSW\x01\x02\x80\x87\x87r\x1E\xC3NSW\x01\x02\x80\x88\x88h\xC2\x1E-\t\xC3NSW\x01\x02\x83\x89\x89Han\xC2st\n\x1E\xC3NSW\x01\x02\x83\x89\x89\x1E\xC3NSW\x01\x02\x84\x89\x89" }; @@ -29,14 +29,14 @@ macro_rules! __impl_list_and_v1 { unsafe { icu_provider::baked::zerotrie::Data::from_trie_and_values_unchecked(TRIE, VALUES) } }; } - #[clippy::msrv = "1.86"] + #[clippy::msrv = "1.88"] impl icu_provider::DataProvider for $provider { fn load(&self, req: icu_provider::DataRequest) -> Result, icu_provider::DataError> { let mut metadata = icu_provider::DataResponseMetadata::default(); let payload = if let Some(payload) = icu_provider::baked::DataStore::get(&Self::DATA_LIST_AND_V1, req.id, req.metadata.attributes_prefix_match) { payload } else { - const FALLBACKER: icu_locale::fallback::LocaleFallbackerWithConfig<'static> = icu_locale::fallback::LocaleFallbacker::new().for_config(::INFO.fallback_config); + const FALLBACKER: icu_locale_fallback::LocaleFallbackerWithConfig<'static> = icu_locale_fallback::LocaleFallbacker::new().for_config(::INFO.fallback_config); let mut fallback_iterator = FALLBACKER.fallback_for(req.id.locale.clone()); loop { if let Some(payload) = icu_provider::baked::DataStore::get(&Self::DATA_LIST_AND_V1, icu_provider::DataIdentifierBorrowed::for_marker_attributes_and_locale(req.id.marker_attributes, fallback_iterator.get()), req.metadata.attributes_prefix_match) { @@ -55,7 +55,7 @@ macro_rules! __impl_list_and_v1 { }; ($ provider : ty , ITER) => { __impl_list_and_v1!($provider); - #[clippy::msrv = "1.86"] + #[clippy::msrv = "1.88"] impl icu_provider::IterableDataProvider for $provider { fn iter_ids(&self) -> Result>, icu_provider::DataError> { Ok(icu_provider::baked::DataStore::iter(&Self::DATA_LIST_AND_V1).collect()) diff --git a/compiler/rustc_baked_icu_data/src/data/mod.rs b/compiler/rustc_baked_icu_data/src/data/mod.rs index fd43456b9e619..61d39d153db68 100644 --- a/compiler/rustc_baked_icu_data/src/data/mod.rs +++ b/compiler/rustc_baked_icu_data/src/data/mod.rs @@ -15,7 +15,7 @@ include!("list_and_v1.rs.data"); #[macro_export] macro_rules! __make_provider { ($ name : ty) => { - #[clippy::msrv = "1.86"] + #[clippy::msrv = "1.88"] impl $name { #[allow(dead_code)] pub(crate) const MUST_USE_MAKE_PROVIDER_MACRO: () = (); @@ -27,7 +27,7 @@ macro_rules! __make_provider { pub use __make_provider as make_provider; /// This macro requires the following crates: /// * `icu_list` -/// * `icu_locale/compiled_data` +/// * `icu_locale_fallback/compiled_data` /// * `icu_provider` /// * `icu_provider/baked` /// * `zerovec` diff --git a/compiler/rustc_baked_icu_data/src/lib.rs b/compiler/rustc_baked_icu_data/src/lib.rs index 75fe473ef999a..1116990e7f033 100644 --- a/compiler/rustc_baked_icu_data/src/lib.rs +++ b/compiler/rustc_baked_icu_data/src/lib.rs @@ -37,14 +37,17 @@ pub const fn baked_data_provider() -> BakedDataProvider { } pub mod supported_locales { - pub const EN: icu_locale::Locale = icu_locale::locale!("en"); - pub const ES: icu_locale::Locale = icu_locale::locale!("es"); - pub const FR: icu_locale::Locale = icu_locale::locale!("fr"); - pub const IT: icu_locale::Locale = icu_locale::locale!("it"); - pub const JA: icu_locale::Locale = icu_locale::locale!("ja"); - pub const PT: icu_locale::Locale = icu_locale::locale!("pt"); - pub const RU: icu_locale::Locale = icu_locale::locale!("ru"); - pub const TR: icu_locale::Locale = icu_locale::locale!("tr"); - pub const ZH_HANS: icu_locale::Locale = icu_locale::locale!("zh-Hans"); - pub const ZH_HANT: icu_locale::Locale = icu_locale::locale!("zh-Hant"); + use icu_locale_core::{Locale, locale}; + use icu_provider::prelude::*; + + pub const EN: Locale = locale!("en"); + pub const ES: Locale = locale!("es"); + pub const FR: Locale = locale!("fr"); + pub const IT: Locale = locale!("it"); + pub const JA: Locale = locale!("ja"); + pub const PT: Locale = locale!("pt"); + pub const RU: Locale = locale!("ru"); + pub const TR: Locale = locale!("tr"); + pub const ZH_HANS: Locale = locale!("zh-Hans"); + pub const ZH_HANT: Locale = locale!("zh-Hant"); } diff --git a/compiler/rustc_builtin_macros/src/offload.rs b/compiler/rustc_builtin_macros/src/offload.rs index b75131db68207..4111843b0c9d8 100644 --- a/compiler/rustc_builtin_macros/src/offload.rs +++ b/compiler/rustc_builtin_macros/src/offload.rs @@ -122,7 +122,7 @@ pub(crate) fn expand_kernel( span, ecx.path_global( span, - [sym::std, sym::unimplemented].map(|s| Ident::new(s, span)).to_vec(), + [sym::core, sym::unimplemented].map(|s| Ident::new(s, span)).to_vec(), ), Delimiter::Parenthesis, TokenStream::default(), diff --git a/compiler/rustc_codegen_cranelift/src/cast.rs b/compiler/rustc_codegen_cranelift/src/cast.rs index f124739d1e154..abf4326f91888 100644 --- a/compiler/rustc_codegen_cranelift/src/cast.rs +++ b/compiler/rustc_codegen_cranelift/src/cast.rs @@ -148,10 +148,6 @@ pub(crate) fn clif_int_or_float_cast( fx.bcx.ins().fcvt_to_uint_sat(to_ty, from) }; - if let Some(false) = fx.tcx.sess.opts.unstable_opts.saturating_float_casts { - return val; - } - let is_not_nan = fx.bcx.ins().fcmp(FloatCC::Equal, from, from); let zero = type_zero_value(&mut fx.bcx, to_ty); fx.bcx.ins().select(is_not_nan, val, zero) diff --git a/compiler/rustc_codegen_cranelift/src/codegen_f16_f128.rs b/compiler/rustc_codegen_cranelift/src/codegen_f16_f128.rs index 3dbd59c2fca4d..09762f1a451b6 100644 --- a/compiler/rustc_codegen_cranelift/src/codegen_f16_f128.rs +++ b/compiler/rustc_codegen_cranelift/src/codegen_f16_f128.rs @@ -265,10 +265,6 @@ pub(crate) fn codegen_cast( fx.bcx.ins().ireduce(to_ty, val) }; - if let Some(false) = fx.tcx.sess.opts.unstable_opts.saturating_float_casts { - return val; - } - let is_not_nan = fcmp(fx, FloatCC::Equal, from, from); let zero = type_zero_value(&mut fx.bcx, to_ty); fx.bcx.ins().select(is_not_nan, val, zero) diff --git a/compiler/rustc_codegen_ssa/src/traits/builder.rs b/compiler/rustc_codegen_ssa/src/traits/builder.rs index 56dc13b832032..cb0209a0ae369 100644 --- a/compiler/rustc_codegen_ssa/src/traits/builder.rs +++ b/compiler/rustc_codegen_ssa/src/traits/builder.rs @@ -404,10 +404,6 @@ pub trait BuilderMethods<'a, 'tcx>: ); assert_eq!(self.cx().type_kind(int_ty), TypeKind::Integer); - if let Some(false) = self.cx().sess().opts.unstable_opts.saturating_float_casts { - return if signed { self.fptosi(x, dest_ty) } else { self.fptoui(x, dest_ty) }; - } - if signed { self.fptosi_sat(x, dest_ty) } else { self.fptoui_sat(x, dest_ty) } } diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index b2a2d3dbd60dd..e4a307a2224d8 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -616,7 +616,7 @@ fn list_metadata(sess: &Session, metadata_loader: &dyn MetadataLoader) { } } -fn print_crate_info( +pub fn print_crate_info( codegen_backend: &dyn CodegenBackend, sess: &Session, parse_attrs: bool, diff --git a/compiler/rustc_error_messages/Cargo.toml b/compiler/rustc_error_messages/Cargo.toml index 50f0b265527fe..02851a2255a87 100644 --- a/compiler/rustc_error_messages/Cargo.toml +++ b/compiler/rustc_error_messages/Cargo.toml @@ -6,8 +6,8 @@ edition = "2024" [dependencies] # tidy-alphabetical-start fluent-bundle = "0.16" -icu_list = { version = "2.2", default-features = false, features = ["alloc"] } -icu_locale = { version = "2.2", default-features = false } +icu_list = { version = "2.3", default-features = false, features = ["alloc"] } +icu_locale_core = { version = "2.3", default-features = false } intl-memoizer = "0.5.1" rustc_baked_icu_data = { path = "../rustc_baked_icu_data" } rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 7f7e6f2efb65d..7c4e9fb649217 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -213,8 +213,8 @@ impl From> for MultiSpan { } } -fn icu_locale_from_unic_langid(lang: LanguageIdentifier) -> Option { - icu_locale::Locale::try_from_str(&lang.to_string()).ok() +fn icu_locale_from_unic_langid(lang: LanguageIdentifier) -> Option { + icu_locale_core::Locale::try_from_str(&lang.to_string()).ok() } pub fn fluent_value_from_str_list_sep_by_and(l: Vec>) -> FluentValue<'_> { diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index cb900339faaa4..f79a8e9ffc79c 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -65,9 +65,6 @@ pub enum AttributeStability { Unstable { /// The feature gate, for example `rustc_attrs` for rustc_* attributes. gate_name: Symbol, - /// Check function to be called during the `PostExpansionVisitor` pass, which will be one - /// of the `Features::*` functions - gate_check: GateFn, /// Notes to be displayed when an attempt is made to use the attribute without its feature /// gate. notes: &'static [&'static str], diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 490888f87b38e..51e26d4ba5044 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -128,6 +128,18 @@ impl Linker { // any more, we can finalize it (which involves renaming it) rustc_incremental::finalize_session_directory(sess, incr_comp_session, self.crate_hash); + // The `HostMetadata` offload pass only writes the kernel manifest. + // Codegen was already skipped so there are no files to link. + if sess + .opts + .unstable_opts + .offload + .iter() + .any(|o| matches!(o, config::Offload::HostMetadata(_))) + { + return; + } + if !sess .opts .output_types diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index d3c479f2a22f5..41ce4fb759dac 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -890,7 +890,6 @@ fn test_unstable_options_tracking_hash() { tracked!(sanitizer_kcfi_arity, Some(true)); tracked!(sanitizer_memory_track_origins, 2); tracked!(sanitizer_recover, SanitizerSet::ADDRESS); - tracked!(saturating_float_casts, Some(true)); tracked!(share_generics, Some(true)); tracked!(simulate_remapped_rust_src_base, Some(PathBuf::from("/rustc/abc"))); tracked!(small_data_threshold, Some(16)); diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 1af2094c93d0d..307d858bf2428 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -117,7 +117,7 @@ pub(crate) fn check_abi_required_features(sess: &Session) { } pub static STACK_SIZE: OnceLock = OnceLock::new(); -pub const DEFAULT_STACK_SIZE: usize = 16 * 1024 * 1024; +pub const DEFAULT_STACK_SIZE: usize = 17 * 1024 * 1024; fn init_stack_size(early_dcx: &EarlyDiagCtxt) -> usize { // Obey the environment setting or default diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 68bbc1520a06d..d30cc29e66298 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -35,8 +35,11 @@ use tracing::debug; pub use crate::config::cfg::{Cfg, CheckCfg, ExpectedValues}; use crate::config::native_libs::parse_native_libs; -pub use crate::config::print_request::{PrintKind, PrintRequest}; +pub use crate::config::print_request::{ + PrintCategory, PrintKind, PrintRequest, collect_print_requests, +}; use crate::diagnostics::FileWriteFail; +use crate::macros::AllVariants; pub use crate::options::*; use crate::search_paths::SearchPath; use crate::utils::CanonicalizedPath; @@ -1414,12 +1417,11 @@ impl Sysroot { } } +/// Get the host triple out of the build environment. This ensures that our +/// idea of the host triple is the same as for the set of libraries we've +/// actually built. We can't just take LLVM's host triple because they +/// normalize all ix86 architectures to i386. pub fn host_tuple() -> &'static str { - // Get the host triple out of the build environment. This ensures that our - // idea of the host triple is the same as for the set of libraries we've - // actually built. We can't just take LLVM's host triple because they - // normalize all ix86 architectures to i386. - // // Instead of grabbing the host triple (for the current host), we grab (at // compile time) the target triple that this rustc is built with and // calling that (at runtime) the host triple. @@ -2879,7 +2881,13 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M )); } - let prints = print_request::collect_print_requests(early_dcx, &mut cg, &unstable_opts, matches); + let prints = print_request::collect_print_requests( + early_dcx, + &mut cg, + &unstable_opts, + matches, + PrintCategory::ALL_VARIANTS, + ); // -Zretpoline-external-thunk also requires -Zretpoline if unstable_opts.retpoline_external_thunk { diff --git a/compiler/rustc_session/src/config/print_request.rs b/compiler/rustc_session/src/config/print_request.rs index 8201e1bfdd9a7..b41ceb1699eaa 100644 --- a/compiler/rustc_session/src/config/print_request.rs +++ b/compiler/rustc_session/src/config/print_request.rs @@ -22,36 +22,98 @@ pub struct PrintRequest { #[derive(AllVariants)] pub enum PrintKind { // tidy-alphabetical-start + /// All target JSON specifications. AllTargetSpecsJson, + + /// Does the backend supports the [`PrintRequest::arg`] `asm!()` mnemonic? (perma-unstable) BackendHasMnemonic, + + /// Does the backend supports Zstd compression? (perma-unstable) BackendHasZstd, + + /// List of all calling conventions supported by rustc. CallingConventions, + + /// List of cfg values. Cfg, + + /// List of check-cfg values. CheckCfg, + + /// List of available code models for the current backend. CodeModels, + + /// Name of the crate being compiled. CrateName, + + /// Lint levels of the crate's root module. CrateRootLintLevels, + + /// The current selected deployment target. (Apple only) DeploymentTarget, + + /// The names of the files created by the `--emit=link` option. (e.g. `libfoo.a`) FileNames, + + /// Target-tuple of the host compiler. HostTuple, + + /// Linker invocations. LinkArgs, + + /// When compiling a `staticlib` crate, print the linker flags used. NativeStaticLibs, + + /// List of available relocation models for the current backend. RelocationModels, + + /// List of available split debuginfos for the current target. SplitDebuginfo, + + /// List of available stack protector strategies for the current backend. StackProtectorStrategies, + + /// List of available crate types for the current target. SupportedCrateTypes, + + /// Path to the sysroot. Sysroot, + + /// List of available CPU values for the current target. TargetCPUs, + + /// List of available target features for the current target. TargetFeatures, + + /// Path to the target libdir. TargetLibdir, + + /// List of supported targets. TargetList, + + /// Current target JSON specification. TargetSpecJson, + + /// Target JSON specification schema. TargetSpecJsonSchema, + + /// List of available TLS models for the current backend. TlsModels, + + /// Target-tuple for WebAssembly's proc-macro crates. WasmProcMacroTuple, // tidy-alphabetical-end } +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(AllVariants)] +pub enum PrintCategory { + Target, + Codegen, + Linker, + Crate, +} + impl PrintKind { fn name(self) -> &'static str { use PrintKind::*; @@ -88,6 +150,28 @@ impl PrintKind { } } + fn category(self) -> PrintCategory { + use PrintKind::*; + match self { + TargetList | TargetSpecJsonSchema | AllTargetSpecsJson | TargetSpecJson + | TargetCPUs | TargetFeatures | DeploymentTarget | HostTuple | SupportedCrateTypes + | Sysroot | TargetLibdir | Cfg | CheckCfg | WasmProcMacroTuple => PrintCategory::Target, + + BackendHasMnemonic + | BackendHasZstd + | CallingConventions + | CodeModels + | SplitDebuginfo + | StackProtectorStrategies + | TlsModels + | RelocationModels => PrintCategory::Codegen, + + LinkArgs | NativeStaticLibs => PrintCategory::Linker, + + CrateName | CrateRootLintLevels | FileNames => PrintCategory::Crate, + } + } + fn is_stable(self) -> bool { use PrintKind::*; match self { @@ -144,11 +228,12 @@ pub(crate) static PRINT_HELP: LazyLock = LazyLock::new(|| { ) }); -pub(crate) fn collect_print_requests( +pub fn collect_print_requests( early_dcx: &EarlyDiagCtxt, cg: &mut CodegenOptions, unstable_opts: &UnstableOptions, matches: &getopts::Matches, + allowed: &[PrintCategory], ) -> Vec { let mut prints = Vec::::new(); if cg.target_cpu.as_deref() == Some("help") { @@ -190,12 +275,14 @@ pub(crate) fn collect_print_requests( for example: `--print=backend-has-mnemonic:RET`", ); } - } else if let Some(print_kind) = PrintKind::from_str(req) { + } else if let Some(print_kind) = PrintKind::from_str(req) + && allowed.contains(&print_kind.category()) + { check_print_request_stability(early_dcx, unstable_opts, print_kind); (print_kind, None) } else { let is_nightly = nightly_options::match_is_nightly_build(matches); - emit_unknown_print_request_help(early_dcx, req, is_nightly) + emit_unknown_print_request_help(early_dcx, req, is_nightly, allowed) }; let out = out.unwrap_or(OutFileName::Stdout); @@ -226,11 +313,17 @@ fn check_print_request_stability( } } -fn emit_unknown_print_request_help(early_dcx: &EarlyDiagCtxt, req: &str, is_nightly: bool) -> ! { +fn emit_unknown_print_request_help( + early_dcx: &EarlyDiagCtxt, + req: &str, + is_nightly: bool, + allowed: &[PrintCategory], +) -> ! { let prints = PrintKind::ALL_VARIANTS .iter() // If we're not on nightly, we don't want to print unstable options .filter(|kind| is_nightly || kind.is_stable()) + .filter(|kind| allowed.contains(&kind.category())) .map(|kind| format!("`{kind}`")) .collect::>() .join(", "); @@ -239,9 +332,12 @@ fn emit_unknown_print_request_help(early_dcx: &EarlyDiagCtxt, req: &str, is_nigh diag.help(format!("valid print requests are: {prints}")); if req == "lints" { - diag.help(format!("use `-Whelp` to print a list of lints")); + diag.help("use `-Whelp` to print a list of lints"); + } + + if allowed == PrintCategory::ALL_VARIANTS { + diag.help("for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information"); } - diag.help(format!("for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information")); diag.emit() } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index a075a088d206c..eb4d48615fa54 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2829,9 +2829,6 @@ written to standard error output)"), "enable origins tracking in MemorySanitizer"), sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED], "enable recovery for selected sanitizers"), - saturating_float_casts: Option = (None, parse_opt_bool, [TRACKED], - "make float->int casts UB-free: numbers outside the integer type's range are clipped to \ - the max/min integer respectively, and NaN is mapped to 0 (default: yes)"), self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled, parse_switch_with_opt_path, [UNTRACKED], "run the self profiler and output the raw event data"), diff --git a/library/alloc/src/boxed/thin.rs b/library/alloc/src/boxed/thin.rs index 98904aa500669..ef0d5a3d18aae 100644 --- a/library/alloc/src/boxed/thin.rs +++ b/library/alloc/src/boxed/thin.rs @@ -165,10 +165,10 @@ impl DerefMut for ThinBox { #[unstable(feature = "thin_box", issue = "92791")] impl Drop for ThinBox { fn drop(&mut self) { + let value = self.deref_mut(); + let value = value as *mut T; // ignore-tidy-undocumented-unsafe unsafe { - let value = self.deref_mut(); - let value = value as *mut T; self.with_header().drop::(value); } } @@ -240,34 +240,38 @@ impl WithHeader { alloc::handle_alloc_error(Layout::new::<()>()); }; - // ignore-tidy-undocumented-unsafe - unsafe { - // Note: It's UB to pass a layout with a zero size to `alloc::alloc`, so - // we use `layout.dangling()` for this case, which should have a valid - // alignment for both `T` and `H`. - let ptr = if layout.size() == 0 { - // Some paranoia checking, mostly so that the ThinBox tests are - // more able to catch issues. - debug_assert!(value_offset == 0 && T::IS_ZST && H::IS_ZST); - layout.dangling_ptr() - } else { - let ptr = alloc::alloc(layout); - if ptr.is_null() { - alloc::handle_alloc_error(layout); - } - // Safety: - // - The size is at least `aligned_header_size`. + // Note: It's UB to pass a layout with a zero size to `alloc::alloc`, so + // we use `layout.dangling()` for this case, which should have a valid + // alignment for both `T` and `H`. + let ptr = if layout.size() == 0 { + // Some paranoia checking, mostly so that the ThinBox tests are + // more able to catch issues. + debug_assert!(value_offset == 0 && T::IS_ZST && H::IS_ZST); + layout.dangling_ptr() + } else { + // ignore-tidy-undocumented-unsafe + let ptr = unsafe { alloc::alloc(layout) }; + if ptr.is_null() { + alloc::handle_alloc_error(layout); + } + // SAFETY: + // - The size is at least `aligned_header_size`. + unsafe { let ptr = ptr.add(value_offset) as *mut _; NonNull::new_unchecked(ptr) - }; + } + }; - let result = WithHeader(ptr, PhantomData); + let result = WithHeader(ptr, PhantomData); + + // ignore-tidy-undocumented-unsafe + unsafe { ptr::write(result.header(), header); ptr::write(result.value().cast(), value); - - result } + + result } /// Non-panicking version of `new`. @@ -278,35 +282,39 @@ impl WithHeader { return Err(core::alloc::AllocError); }; - // ignore-tidy-undocumented-unsafe - unsafe { - // Note: It's UB to pass a layout with a zero size to `alloc::alloc`, so - // we use `layout.dangling()` for this case, which should have a valid - // alignment for both `T` and `H`. - let ptr = if layout.size() == 0 { - // Some paranoia checking, mostly so that the ThinBox tests are - // more able to catch issues. - debug_assert!(value_offset == 0 && T::IS_ZST && H::IS_ZST); - layout.dangling_ptr() - } else { - let ptr = alloc::alloc(layout); - if ptr.is_null() { - return Err(core::alloc::AllocError); - } - - // Safety: - // - The size is at least `aligned_header_size`. + // Note: It's UB to pass a layout with a zero size to `alloc::alloc`, so + // we use `layout.dangling()` for this case, which should have a valid + // alignment for both `T` and `H`. + let ptr = if layout.size() == 0 { + // Some paranoia checking, mostly so that the ThinBox tests are + // more able to catch issues. + debug_assert!(value_offset == 0 && T::IS_ZST && H::IS_ZST); + layout.dangling_ptr() + } else { + // ignore-tidy-undocumented-unsafe + let ptr = unsafe { alloc::alloc(layout) }; + if ptr.is_null() { + return Err(core::alloc::AllocError); + } + + // SAFETY: + // - The size is at least `aligned_header_size`. + unsafe { let ptr = ptr.add(value_offset) as *mut _; NonNull::new_unchecked(ptr) - }; + } + }; + + let result = WithHeader(ptr, PhantomData); - let result = WithHeader(ptr, PhantomData); + // ignore-tidy-undocumented-unsafe + unsafe { ptr::write(result.header(), header); ptr::write(result.value().cast(), value); - - Ok(result) } + + Ok(result) } // `Dyn` is `?Sized` type like `[u32]`, and `T` is ZST type like `[u32; 0]`. diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index a6c6377c8b2e1..8d993f6758a52 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -333,10 +333,10 @@ impl FromIterator for ByteString { #[unstable(feature = "bstr", issue = "134915")] impl FromStr for ByteString { - type Err = core::convert::Infallible; + type Err = !; #[inline] - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(ByteString(s.as_bytes().to_vec())) } } diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 0fc83871c815f..f0e48dde5e951 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -1574,9 +1574,9 @@ impl<'a, T> Hole<'a, T> { unsafe fn move_to(&mut self, index: usize) { debug_assert!(index != self.pos); debug_assert!(index < self.data.len()); + let ptr = self.data.as_mut_ptr(); // ignore-tidy-undocumented-unsafe unsafe { - let ptr = self.data.as_mut_ptr(); let index_ptr: *const _ = ptr.add(index); let hole_ptr = ptr.add(self.pos); ptr::copy_nonoverlapping(index_ptr, hole_ptr, 1); @@ -1589,9 +1589,9 @@ impl Drop for Hole<'_, T> { #[inline] fn drop(&mut self) { // fill the hole again + let pos = self.pos; // ignore-tidy-undocumented-unsafe unsafe { - let pos = self.pos; ptr::copy_nonoverlapping(&*self.elt, self.data.get_unchecked_mut(pos), 1); } } diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 2f60fd1f74d35..55ef4d59864e7 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -280,10 +280,10 @@ impl Clone for BTreeMap { // We can't destructure subtree directly // because BTreeMap implements Drop - // ignore-tidy-undocumented-unsafe - let (subroot, sublength) = unsafe { + let (subroot, sublength) = { let subtree = ManuallyDrop::new(subtree); - let root = ptr::read(&subtree.root); + // ignore-tidy-undocumented-unsafe + let root = unsafe { ptr::read(&subtree.root) }; let length = subtree.length; (root, length) }; diff --git a/library/alloc/src/collections/btree/node.rs b/library/alloc/src/collections/btree/node.rs index c97f7ac00474a..3859d857d0518 100644 --- a/library/alloc/src/collections/btree/node.rs +++ b/library/alloc/src/collections/btree/node.rs @@ -1875,11 +1875,11 @@ pub(super) mod marker { /// # Safety /// The slice has more than `idx` elements. unsafe fn slice_insert(slice: &mut [MaybeUninit], idx: usize, val: T) { + let len = slice.len(); + debug_assert!(len > idx); + let slice_ptr = slice.as_mut_ptr(); // ignore-tidy-undocumented-unsafe unsafe { - let len = slice.len(); - debug_assert!(len > idx); - let slice_ptr = slice.as_mut_ptr(); if len > idx + 1 { ptr::copy(slice_ptr.add(idx), slice_ptr.add(idx + 1), len - idx - 1); } @@ -1893,11 +1893,11 @@ unsafe fn slice_insert(slice: &mut [MaybeUninit], idx: usize, val: T) { /// # Safety /// The slice has more than `idx` elements. unsafe fn slice_remove(slice: &mut [MaybeUninit], idx: usize) -> T { + let len = slice.len(); + debug_assert!(idx < len); + let slice_ptr = slice.as_mut_ptr(); // ignore-tidy-undocumented-unsafe unsafe { - let len = slice.len(); - debug_assert!(idx < len); - let slice_ptr = slice.as_mut_ptr(); let ret = (*slice_ptr.add(idx)).assume_init_read(); ptr::copy(slice_ptr.add(idx + 1), slice_ptr.add(idx), len - idx - 1); ret @@ -1909,9 +1909,9 @@ unsafe fn slice_remove(slice: &mut [MaybeUninit], idx: usize) -> T { /// # Safety /// The slice has at least `distance` elements. unsafe fn slice_shl(slice: &mut [MaybeUninit], distance: usize) { + let slice_ptr = slice.as_mut_ptr(); // ignore-tidy-undocumented-unsafe unsafe { - let slice_ptr = slice.as_mut_ptr(); ptr::copy(slice_ptr.add(distance), slice_ptr, slice.len() - distance); } } @@ -1921,9 +1921,9 @@ unsafe fn slice_shl(slice: &mut [MaybeUninit], distance: usize) { /// # Safety /// The slice has at least `distance` elements. unsafe fn slice_shr(slice: &mut [MaybeUninit], distance: usize) { + let slice_ptr = slice.as_mut_ptr(); // ignore-tidy-undocumented-unsafe unsafe { - let slice_ptr = slice.as_mut_ptr(); ptr::copy(slice_ptr, slice_ptr.add(distance), slice.len() - distance); } } diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 953cffc1c396d..2c1245524a0cf 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -1679,20 +1679,20 @@ impl<'a, T> CursorMut<'a, T> { /// inserted at the start of the `LinkedList`. #[unstable(feature = "linked_list_cursors", issue = "58533")] pub fn splice_after(&mut self, list: LinkedList) { + let Some((splice_head, splice_tail, splice_len)) = list.detach_all_nodes() else { + return; + }; // ignore-tidy-undocumented-unsafe unsafe { - let Some((splice_head, splice_tail, splice_len)) = list.detach_all_nodes() else { - return; - }; let node_next = match self.current { None => self.list.head, Some(node) => node.as_ref().next, }; self.list.splice_nodes(self.current, node_next, splice_head, splice_tail, splice_len); - if self.current.is_none() { - // The "ghost" non-element's index has changed. - self.index = self.list.len; - } + } + if self.current.is_none() { + // The "ghost" non-element's index has changed. + self.index = self.list.len; } } @@ -1702,19 +1702,19 @@ impl<'a, T> CursorMut<'a, T> { /// inserted at the end of the `LinkedList`. #[unstable(feature = "linked_list_cursors", issue = "58533")] pub fn splice_before(&mut self, list: LinkedList) { + let (splice_head, splice_tail, splice_len) = match list.detach_all_nodes() { + Some(parts) => parts, + _ => return, + }; // ignore-tidy-undocumented-unsafe unsafe { - let (splice_head, splice_tail, splice_len) = match list.detach_all_nodes() { - Some(parts) => parts, - _ => return, - }; let node_prev = match self.current { None => self.list.tail, Some(node) => node.as_ref().prev, }; self.list.splice_nodes(node_prev, self.current, splice_head, splice_tail, splice_len); - self.index += splice_len; } + self.index += splice_len; } } @@ -1725,19 +1725,19 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> { /// inserted at the front of the `LinkedList`. #[unstable(feature = "linked_list_cursors", issue = "58533")] pub fn insert_after(&mut self, item: T) { + let spliced_node = + Box::into_non_null_with_allocator(Box::new_in(Node::new(item), &self.list.alloc)).0; // ignore-tidy-undocumented-unsafe unsafe { - let spliced_node = - Box::into_non_null_with_allocator(Box::new_in(Node::new(item), &self.list.alloc)).0; let node_next = match self.current { None => self.list.head, Some(node) => node.as_ref().next, }; self.list.splice_nodes(self.current, node_next, spliced_node, spliced_node, 1); - if self.current.is_none() { - // The "ghost" non-element's index has changed. - self.index = self.list.len; - } + } + if self.current.is_none() { + // The "ghost" non-element's index has changed. + self.index = self.list.len; } } @@ -1747,17 +1747,17 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> { /// inserted at the end of the `LinkedList`. #[unstable(feature = "linked_list_cursors", issue = "58533")] pub fn insert_before(&mut self, item: T) { + let spliced_node = + Box::into_non_null_with_allocator(Box::new_in(Node::new(item), &self.list.alloc)).0; // ignore-tidy-undocumented-unsafe unsafe { - let spliced_node = - Box::into_non_null_with_allocator(Box::new_in(Node::new(item), &self.list.alloc)).0; let node_prev = match self.current { None => self.list.tail, Some(node) => node.as_ref().prev, }; self.list.splice_nodes(node_prev, self.current, spliced_node, spliced_node, 1); - self.index += 1; } + self.index += 1; } /// Removes the current element from the `LinkedList`. @@ -1799,14 +1799,14 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> { unlinked_node.as_mut().prev = None; unlinked_node.as_mut().next = None; - Some(LinkedList { - head: Some(unlinked_node), - tail: Some(unlinked_node), - len: 1, - alloc: self.list.alloc.clone(), - marker: PhantomData, - }) } + Some(LinkedList { + head: Some(unlinked_node), + tail: Some(unlinked_node), + len: 1, + alloc: self.list.alloc.clone(), + marker: PhantomData, + }) } /// Splits the list into two after the current element. This will return a diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 08abf0e5c5a68..6494eaacfeeb4 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -1455,6 +1455,12 @@ impl VecDeque { #[doc(alias = "retain_front")] #[stable(feature = "deque_extras", since = "1.16.0")] pub fn truncate(&mut self, len: usize) { + if len >= self.len { + return; + } + + let (front, back) = self.as_mut_slices(); + // SAFETY: // * Any slice passed to `drop_in_place` is valid; the second case has // `len <= front.len()` and returning on `len > self.len()` ensures @@ -1462,11 +1468,6 @@ impl VecDeque { // * The head of the VecDeque is moved before calling `drop_in_place`, // so no value is dropped twice if `drop_in_place` panics unsafe { - if len >= self.len { - return; - } - - let (front, back) = self.as_mut_slices(); if len > front.len() { let begin = len - front.len(); let drop_back = back.get_unchecked_mut(begin..) as *mut _; @@ -1508,14 +1509,15 @@ impl VecDeque { #[doc(alias = "truncate_front")] #[stable(feature = "vec_deque_truncate_front", since = "1.99.0")] pub fn retain_back(&mut self, len: usize) { + if len >= self.len { + // No action is taken + return; + } + + let (front, back) = self.as_mut_slices(); + // ignore-tidy-undocumented-unsafe unsafe { - if len >= self.len { - // No action is taken - return; - } - - let (front, back) = self.as_mut_slices(); if len > back.len() { // The 'back' slice remains unchanged. // front.len() + back.len() == self.len, so 'end' is non-negative @@ -2773,9 +2775,9 @@ impl VecDeque { } self.reserve(other.len); + let (left, right) = other.as_slices(); // ignore-tidy-undocumented-unsafe unsafe { - let (left, right) = other.as_slices(); self.copy_slice(self.to_wrapped_index(self.len), left); // no overflow, because self.capacity() >= old_cap + left.len() >= self.len + left.len() self.copy_slice(self.to_wrapped_index(self.len + left.len()), right); diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index fe39a0145d3a9..358f19d720ed6 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -86,8 +86,8 @@ impl SpecExtend> for Ve // ignore-tidy-undocumented-unsafe unsafe { self.copy_slice(self.to_wrapped_index(self.len), slice); - self.len += slice.len(); } + self.len += slice.len(); iterator.forget_remaining_elements_and_dealloc(); } } @@ -113,8 +113,8 @@ where // ignore-tidy-undocumented-unsafe unsafe { self.copy_slice(self.to_wrapped_index(self.len), slice); - self.len += slice.len(); } + self.len += slice.len(); } } diff --git a/library/alloc/src/collections/vec_deque/splice.rs b/library/alloc/src/collections/vec_deque/splice.rs index 4edd26c1e1e22..93e5a0b4addf0 100644 --- a/library/alloc/src/collections/vec_deque/splice.rs +++ b/library/alloc/src/collections/vec_deque/splice.rs @@ -64,10 +64,10 @@ impl Drop for Splice<'_, I, A> { // At this point draining is done and the only remaining tasks are splicing // and moving things into the final place. + let tail_len = self.drain.tail_len; // #elements behind the drain + // ignore-tidy-undocumented-unsafe unsafe { - let tail_len = self.drain.tail_len; // #elements behind the drain - if tail_len == 0 { self.drain.deque.as_mut().extend(self.replace_with.by_ref()); return; diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 1e859b38c9dd7..cb52becb45b55 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -2393,9 +2393,9 @@ impl Rc { #[cfg(not(no_global_oom_handling))] fn from_box_in(src: Box) -> Rc { + let value_size = size_of_val(&*src); // ignore-tidy-undocumented-unsafe unsafe { - let value_size = size_of_val(&*src); let ptr = Self::allocate_for_ptr_in(&*src, Box::allocator(&src)); // Copy value as bytes diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 541b3413f71ba..7708b523ced86 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -474,12 +474,10 @@ impl [T] { #[rustc_const_unstable(feature = "const_heap", issue = "79597")] #[inline] pub const fn into_vec(self: Box) -> Vec { + let len = self.len(); + let (b, alloc) = Box::into_raw_with_allocator(self); // ignore-tidy-undocumented-unsafe - unsafe { - let len = self.len(); - let (b, alloc) = Box::into_raw_with_allocator(self); - Vec::from_raw_parts_in(b as *mut T, len, len, alloc) - } + unsafe { Vec::from_raw_parts_in(b as *mut T, len, len, alloc) } } /// Creates a vector by copying a slice `n` times. diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 72c8fc08fb8ff..cd1c149c3c4fc 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -181,10 +181,10 @@ where result.extend_from_slice(first); + let pos = result.len(); + debug_assert!(reserved_len >= pos); // ignore-tidy-undocumented-unsafe unsafe { - let pos = result.len(); - debug_assert!(reserved_len >= pos); let target = result.spare_capacity_mut().get_unchecked_mut(..reserved_len - pos); // Convert the separator and slices to slices of MaybeUninit diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 170b94ba0c4b8..bf702875f3cad 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -2895,20 +2895,18 @@ impl ops::DerefMut for String { } } -/// A type alias for [`Infallible`]. +/// A type alias for [`!`]. /// /// This alias exists for backwards compatibility, and may be eventually deprecated. -/// -/// [`Infallible`]: core::convert::Infallible "convert::Infallible" #[stable(feature = "str_parse_error", since = "1.5.0")] -pub type ParseError = core::convert::Infallible; +pub type ParseError = !; #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for String { - type Err = core::convert::Infallible; + type Err = !; #[inline] - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(String::from(s)) } } diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index ae15f6d69986b..05fb6fc77d368 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -860,9 +860,9 @@ impl Arc { // Now we can properly initialize the inner value and turn our weak // reference into a strong reference. + let inner = init_ptr.as_ptr(); // ignore-tidy-undocumented-unsafe unsafe { - let inner = init_ptr.as_ptr(); ptr::write(&raw mut (*inner).data, data); // The above write to the data field must be visible to any threads which diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 2fc958968fdd6..451b61fda7501 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -340,12 +340,12 @@ fn write_in_place_with_drop( src_end: *const T, ) -> impl FnMut(InPlaceDrop, T) -> Result, !> { move |mut sink, item| { + // the InPlaceIterable contract cannot be verified precisely here since + // try_fold has an exclusive reference to the source pointer + // all we can do is check if it's still in range + debug_assert!(sink.dst as *const _ <= src_end, "InPlaceIterable contract violation"); // ignore-tidy-undocumented-unsafe unsafe { - // the InPlaceIterable contract cannot be verified precisely here since - // try_fold has an exclusive reference to the source pointer - // all we can do is check if it's still in range - debug_assert!(sink.dst as *const _ <= src_end, "InPlaceIterable contract violation"); ptr::write(sink.dst, item); // Since this executes user code which can panic we have to bump the pointer // after each step. diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 120483356d81c..49be5f72c1aac 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1733,10 +1733,10 @@ impl Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] pub fn into_boxed_slice(mut self) -> Box<[T], A> { + self.shrink_to_fit(); + let me = ManuallyDrop::new(self); // ignore-tidy-undocumented-unsafe unsafe { - self.shrink_to_fit(); - let me = ManuallyDrop::new(self); let buf = ptr::read(&me.buf); let len = me.len(); buf.into_box(len).assume_init() @@ -2449,10 +2449,10 @@ impl Vec { if index >= len { return None; } + // infallible + let ret; // ignore-tidy-undocumented-unsafe unsafe { - // infallible - let ret; { // the place we are taking from. let ptr = self.as_mut_ptr().add(index); @@ -2464,8 +2464,8 @@ impl Vec { ptr::copy(ptr.add(1), ptr, len - index - 1); } self.set_len(len - 1); - Some(ret) } + Some(ret) } /// Retains only the elements specified by the predicate. @@ -2906,9 +2906,9 @@ impl Vec { if self.len == 0 { None } else { + self.len -= 1; // ignore-tidy-undocumented-unsafe unsafe { - self.len -= 1; core::hint::assert_unchecked(self.len < self.capacity()); Some(ptr::read(self.as_ptr().add(self.len()))) } @@ -4067,9 +4067,9 @@ impl IntoIterator for Vec { /// ``` #[inline] fn into_iter(self) -> Self::IntoIter { + let me = ManuallyDrop::new(self); // ignore-tidy-undocumented-unsafe unsafe { - let me = ManuallyDrop::new(self); let alloc = ManuallyDrop::new(ptr::read(me.allocator())); let buf = me.buf.non_null(); let begin = buf.as_ptr(); @@ -4175,10 +4175,10 @@ impl Vec { (low, high) ); self.reserve(additional); + let ptr = self.as_mut_ptr(); + let mut local_len = SetLenOnDrop::new(&mut self.len); // ignore-tidy-undocumented-unsafe unsafe { - let ptr = self.as_mut_ptr(); - let mut local_len = SetLenOnDrop::new(&mut self.len); iterator.for_each(move |element| { ptr::write(ptr.add(local_len.current_len()), element); // Since the loop executes user code which can panic we have to update diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index 3da17e4aebd57..97850c7426045 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -46,9 +46,9 @@ impl SpecFromIter> for Vec { // But it is a conservative choice. let has_advanced = iterator.buf != iterator.ptr; if !has_advanced || iterator.len() >= iterator.cap / 2 { + let it = ManuallyDrop::new(iterator); // ignore-tidy-undocumented-unsafe unsafe { - let it = ManuallyDrop::new(iterator); if has_advanced { ptr::copy(it.ptr.as_ptr(), it.buf.as_ptr(), it.len()); } diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index d42e174283a7b..1129e8b6ceb2b 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -172,7 +172,7 @@ impl IntoIter { /// assert_eq!(empty.len(), 0); /// assert_eq!(empty.as_slice(), &[]); /// - /// let empty = IntoIter::::empty(); + /// let empty = IntoIter::::empty(); /// assert_eq!(empty.len(), 0); /// ``` /// diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 30af6450d19a9..fcd635a03c652 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -7,7 +7,6 @@ use crate::borrow::{Borrow, BorrowMut}; use crate::clone::TrivialClone; use crate::cmp::Ordering; -use crate::convert::Infallible; use crate::error::Error; use crate::hash::{self, Hash}; use crate::intrinsics::transmute_unchecked; @@ -195,8 +194,8 @@ impl Error for TryFromSliceError {} #[stable(feature = "try_from_slice_error", since = "1.36.0")] #[rustc_const_unstable(feature = "const_convert", issue = "143773")] -const impl From for TryFromSliceError { - fn from(x: Infallible) -> TryFromSliceError { +const impl From for TryFromSliceError { + fn from(x: !) -> TryFromSliceError { match x {} } } diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 7e675815edb2e..a57f3d58e3998 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -815,10 +815,10 @@ const impl TryFrom for T where U: [const] Into, { - type Error = Infallible; + type Error = !; #[inline] - fn try_from(value: U) -> Result { + fn try_from(value: U) -> Result { Ok(U::into(value)) } } diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index a98ef99b9d7bb..a53c11e2d876d 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -3922,28 +3922,6 @@ macro_rules! uint_impl { self.count_ones() == 1 } - // Returns one less than next power of two. - // (For 8u8 next power of two is 8u8 and for 6u8 it is 8u8) - // - // 8u8.one_less_than_next_power_of_two() == 7 - // 6u8.one_less_than_next_power_of_two() == 7 - // - // This method cannot overflow, as in the `next_power_of_two` - // overflow cases it instead ends up returning the maximum value - // of the type, and can return 0 for 0. - #[inline] - const fn one_less_than_next_power_of_two(self) -> Self { - if self <= 1 { return 0; } - - let p = self - 1; - // SAFETY: Because `p > 0`, it cannot consist entirely of leading zeros. - // That means the shift is always in-bounds, and some processors - // (such as intel pre-haswell) have more efficient ctlz - // intrinsics when the argument is non-zero. - let z = unsafe { intrinsics::ctlz_nonzero(p) }; - <$SelfT>::MAX >> z - } - /// Returns the smallest power of two greater than or equal to `self`. /// /// When return value overflows (i.e., `self > (1 << (N-1))` for type @@ -3964,7 +3942,15 @@ macro_rules! uint_impl { #[inline] #[rustc_inherit_overflow_checks] pub const fn next_power_of_two(self) -> Self { - self.one_less_than_next_power_of_two() + 1 + if let Some(npot) = self.checked_next_power_of_two() { + npot + } else { + #[expect(arithmetic_overflow)] + { + // Zero but in a way that panics in debug + Self::MAX + 1 + } + } } /// Returns the smallest power of two greater than or equal to `self`. If @@ -3984,7 +3970,13 @@ macro_rules! uint_impl { #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn checked_next_power_of_two(self) -> Option { - self.one_less_than_next_power_of_two().checked_add(1) + let m1 = self.saturating_sub(1); + if m1.cast_signed() >= 0 { + let exp = m1.bit_width(); + Some(1 << exp) + } else { + None + } } /// Returns the smallest power of two greater than or equal to `n`. If @@ -4003,10 +3995,11 @@ macro_rules! uint_impl { #[inline] #[unstable(feature = "wrapping_next_power_of_two", issue = "32463", reason = "needs decision on wrapping behavior")] + #[rustc_const_unstable(feature = "wrapping_next_power_of_two", issue = "32463")] #[must_use = "this returns the result of the operation, \ without modifying the original"] pub const fn wrapping_next_power_of_two(self) -> Self { - self.one_less_than_next_power_of_two().wrapping_add(1) + self.checked_next_power_of_two().unwrap_or(0) } /// Returns the memory representation of this integer as a byte array in diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index 227c9c43bea66..56c9d0cf0cba7 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -1,5 +1,5 @@ use crate::marker::Destruct; -use crate::{convert, ops}; +use crate::ops; /// Used to tell an operation whether it should exit early or go on as usual. /// @@ -104,7 +104,7 @@ pub enum ControlFlow { #[rustc_const_unstable(feature = "const_try", issue = "74935")] const impl ops::Try for ControlFlow { type Output = C; - type Residual = ControlFlow; + type Residual = ControlFlow; #[inline] fn from_output(output: Self::Output) -> Self { @@ -124,9 +124,9 @@ const impl ops::Try for ControlFlow { #[rustc_const_unstable(feature = "const_try", issue = "74935")] // Note: manually specifying the residual type instead of using the default to work around // https://github.com/rust-lang/rust/issues/99940 -const impl ops::FromResidual> for ControlFlow { +const impl ops::FromResidual> for ControlFlow { #[inline] - fn from_residual(residual: ControlFlow) -> Self { + fn from_residual(residual: ControlFlow) -> Self { match residual { ControlFlow::Break(b) => ControlFlow::Break(b), } @@ -135,7 +135,7 @@ const impl ops::FromResidual> for Cont #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try_residual", issue = "91285")] -const impl ops::Residual for ControlFlow { +const impl ops::Residual for ControlFlow { type TryType = ControlFlow; } diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index 19830365faa32..d81279cb56be3 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -56,6 +56,10 @@ impl fmt::Debug for RangeFull { /// The range `start..end` contains all values with `start <= x < end`. /// It is empty if `start >= end`. /// +/// Note that this type is not suited to represent all possible ranges. For example, `Range` +/// cannot represent the range that covers all of `u8`. Use [`(Bound, Bound)`][Bound] if you +/// need a type that can store an arbitrary range. +/// /// # Examples /// /// The `start..end` syntax is a `Range`: diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index 614b104d9c2a2..d0dd6c8d5c8b7 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -148,12 +148,12 @@ pub const trait Try: [const] FromResidual { /// this type is typically a newtype of some sort to "color" the type /// so that it's distinguishable from the residuals of other types. /// - /// This is why `Result::Residual` is not `E`, but `Result`. + /// This is why `Result::Residual` is not `E`, but `Result`. /// That way it's distinct from `ControlFlow::Residual`, for example, /// and thus `?` on `ControlFlow` cannot be used in a method returning `Result`. /// /// If you're making a generic type `Foo` that implements `Try`, - /// then typically you can use `Foo` as its `Residual` + /// then typically you can use `Foo` as its `Residual` /// type: that type will have a "hole" in the correct place, and will maintain the /// "foo-ness" of the residual so other types need to opt-in to interconversion. #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] @@ -356,9 +356,9 @@ where /// and [`Try::Residual`] components, this allows putting them back together. /// /// For example, -/// `Result: Try>`, +/// `Result: Try>`, /// and in the other direction, -/// ` as Residual>::TryType = Result`. +/// ` as Residual>::TryType = Result`. #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try_residual", issue = "91285")] pub const trait Residual: Sized { diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 8ec0414cf6874..2fe7c8c305afe 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -585,7 +585,7 @@ use crate::num::NonZero; use crate::ops::{self, ControlFlow, Deref, DerefMut, Residual, Try}; use crate::panicking::{panic, panic_display}; use crate::pin::Pin; -use crate::{cmp, convert, hint, mem, slice}; +use crate::{cmp, hint, mem, slice}; /// The `Option` type. See [the module level documentation](self) for more. #[doc(search_unbox)] @@ -2864,7 +2864,7 @@ impl> FromIterator> for Option { #[rustc_const_unstable(feature = "const_try", issue = "74935")] const impl ops::Try for Option { type Output = T; - type Residual = Option; + type Residual = Option; #[inline] fn from_output(output: Self::Output) -> Self { @@ -2884,9 +2884,9 @@ const impl ops::Try for Option { #[rustc_const_unstable(feature = "const_try", issue = "74935")] // Note: manually specifying the residual type instead of using the default to work around // https://github.com/rust-lang/rust/issues/99940 -const impl ops::FromResidual> for Option { +const impl ops::FromResidual> for Option { #[inline] - fn from_residual(residual: Option) -> Self { + fn from_residual(residual: Option) -> Self { match residual { None => None, } @@ -2905,7 +2905,7 @@ const impl ops::FromResidual> for Option { #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] -const impl ops::Residual for Option { +const impl ops::Residual for Option { type TryType = Option; } diff --git a/library/core/src/range.rs b/library/core/src/range.rs index 81f4b2ce78c9c..ea4ac96179981 100644 --- a/library/core/src/range.rs +++ b/library/core/src/range.rs @@ -48,6 +48,10 @@ pub use crate::ops::{RangeFull, RangeTo}; /// The `Range` contains all values with `start <= x < end`. /// It is empty if `start >= end`. /// +/// Note that this type is not suited to represent all possible ranges. For example, `Range` +/// cannot represent the range that covers all of `u8`. Use [`(Bound, Bound)`][Bound] if you +/// need a type that can store an arbitrary range. +/// /// # Examples /// /// ``` diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 6e76c3525b4cc..472d568c5cf66 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -544,7 +544,7 @@ use crate::iter::{self, FusedIterator, TrustedLen}; use crate::marker::Destruct; use crate::ops::{self, ControlFlow, Deref, DerefMut}; -use crate::{convert, fmt, hint}; +use crate::{fmt, hint}; /// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]). /// @@ -2164,7 +2164,7 @@ impl> FromIterator> for Result { #[rustc_const_unstable(feature = "const_try", issue = "74935")] const impl ops::Try for Result { type Output = T; - type Residual = Result; + type Residual = Result; #[inline] fn from_output(output: Self::Output) -> Self { @@ -2182,12 +2182,10 @@ const impl ops::Try for Result { #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] -const impl> ops::FromResidual> - for Result -{ +const impl> ops::FromResidual> for Result { #[inline] #[track_caller] - fn from_residual(residual: Result) -> Self { + fn from_residual(residual: Result) -> Self { match residual { Err(e) => Err(From::from(e)), } @@ -2205,6 +2203,6 @@ const impl> ops::FromResidual> for Result< #[unstable(feature = "try_trait_v2_residual", issue = "91285")] #[rustc_const_unstable(feature = "const_try", issue = "74935")] -const impl ops::Residual for Result { +const impl ops::Residual for Result { type TryType = Result; } diff --git a/library/core/src/slice/cmp.rs b/library/core/src/slice/cmp.rs index acb74c9916dfd..cd3fc889ecdd5 100644 --- a/library/core/src/slice/cmp.rs +++ b/library/core/src/slice/cmp.rs @@ -176,7 +176,7 @@ const trait SliceChain: Sized { fn chaining_ge(left: &[Self], right: &[Self]) -> ControlFlow; } -type AlwaysBreak = ControlFlow; +type AlwaysBreak = ControlFlow; #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] const impl SlicePartialOrd for A { diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index 87f8830a6b176..bad3cbe83ed65 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -1,6 +1,5 @@ #![stable(feature = "futures_api", since = "1.36.0")] -use crate::convert; use crate::ops::{self, ControlFlow}; /// Indicates whether a value is available or if the current task has been @@ -233,7 +232,7 @@ const impl From for Poll { #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl ops::Try for Poll> { type Output = Poll; - type Residual = Result; + type Residual = Result; #[inline] fn from_output(c: Self::Output) -> Self { @@ -251,9 +250,9 @@ impl ops::Try for Poll> { } #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] -impl> ops::FromResidual> for Poll> { +impl> ops::FromResidual> for Poll> { #[inline] - fn from_residual(x: Result) -> Self { + fn from_residual(x: Result) -> Self { match x { Err(e) => Poll::Ready(Err(From::from(e))), } @@ -263,7 +262,7 @@ impl> ops::FromResidual> for Pol #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] impl ops::Try for Poll>> { type Output = Poll>; - type Residual = Result; + type Residual = Result; #[inline] fn from_output(c: Self::Output) -> Self { @@ -282,11 +281,9 @@ impl ops::Try for Poll>> { } #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] -impl> ops::FromResidual> - for Poll>> -{ +impl> ops::FromResidual> for Poll>> { #[inline] - fn from_residual(x: Result) -> Self { + fn from_residual(x: Result) -> Self { match x { Err(e) => Poll::Ready(Some(Err(From::from(e)))), } diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 7ad313e1ed3ca..6be8f775b441d 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1804,10 +1804,10 @@ impl AsInner for OsStr { #[stable(feature = "osstring_from_str", since = "1.45.0")] impl FromStr for OsString { - type Err = core::convert::Infallible; + type Err = !; #[inline] - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(OsString::from(s)) } } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index f2fc148551d2e..141bc72fb2e42 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2025,10 +2025,10 @@ impl From for PathBuf { #[stable(feature = "path_from_str", since = "1.32.0")] impl FromStr for PathBuf { - type Err = core::convert::Infallible; + type Err = !; #[inline] - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(PathBuf::from(s)) } } diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 941632f0d283a..c2c58a345fa22 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -10,8 +10,9 @@ use rustc_errors::DiagCtxtHandle; use rustc_lint::Level; use rustc_session::config::{ self, CodegenOptions, ErrorOutputType, Externs, Input, JsonUnusedExterns, - OptionsTargetModifiers, OutFileName, Sysroot, UnstableOptions, get_cmd_lint_options, - nightly_options, parse_crate_types_from_list, parse_externs, parse_target_triple, + OptionsTargetModifiers, OutFileName, PrintCategory, PrintRequest, Sysroot, UnstableOptions, + collect_print_requests, get_cmd_lint_options, nightly_options, parse_crate_types_from_list, + parse_externs, parse_target_triple, }; use rustc_session::search_paths::SearchPath; use rustc_session::{EarlyDiagCtxt, getopts}; @@ -105,6 +106,8 @@ pub(crate) struct Options { pub(crate) describe_lints: bool, /// What level to cap lints at. pub(crate) lint_cap: Option, + /// Print requests to hand to the compiler. + pub(crate) prints: Vec, // Options specific to running doctests /// Whether we should run doctests instead of generating docs. @@ -198,6 +201,7 @@ impl fmt::Debug for Options { .field("lint_opts", &self.lint_opts) .field("describe_lints", &self.describe_lints) .field("lint_cap", &self.lint_cap) + .field("prints", &self.prints) .field("should_test", &self.should_test) .field("test_args", &self.test_args) .field("test_run_directory", &self.test_run_directory) @@ -336,7 +340,6 @@ impl FromStr for EmitType { fn from_str(s: &str) -> Result { match s { - // modern choices "html-static-files" => Ok(Self::HtmlStaticFiles), "html-non-static-files" => Ok(Self::HtmlNonStaticFiles), "dep-info" => Ok(Self::DepInfo(None)), @@ -409,7 +412,7 @@ impl Options { let diagnostic_width = matches.opt_get("diagnostic-width").unwrap_or_default(); let mut collected_options = Default::default(); - let codegen_options = CodegenOptions::build(early_dcx, matches, &mut collected_options); + let mut codegen_options = CodegenOptions::build(early_dcx, matches, &mut collected_options); let unstable_opts = UnstableOptions::build(early_dcx, matches, &mut collected_options); let remap_path_prefix = match parse_remap_path_prefix(matches) { @@ -571,6 +574,14 @@ impl Options { Err(err) => dcx.fatal(err), }; + let prints = collect_print_requests( + early_dcx, + &mut codegen_options, + &unstable_opts, + matches, + &[PrintCategory::Target, PrintCategory::Crate], + ); + let mut parts_out_dir = match matches.opt_str("write-doc-meta-dir").map(PathToParts::from_flag).transpose() { Ok(parts_out_dir) => parts_out_dir, @@ -906,6 +917,7 @@ impl Options { lint_opts, describe_lints, lint_cap, + prints, should_test, test_args, show_coverage, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index ad6718e75466e..db5e281f376ad 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -224,6 +224,7 @@ pub(crate) fn create_config( lint_opts, describe_lints, lint_cap, + prints, scrape_examples_options, remap_path_prefix, remap_path_scope, @@ -284,6 +285,7 @@ pub(crate) fn create_config( diagnostic_width, edition, describe_lints, + prints, crate_name, test, remap_path_prefix, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index d8064cec13b96..80affbd132bfe 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -176,6 +176,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions unstable_opts: options.unstable_opts.clone(), error_format: options.error_format.clone(), target_modifiers: options.target_modifiers.clone(), + describe_lints: options.describe_lints, ..config::Options::default() }; @@ -215,8 +216,17 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions let extract_doctests = options.output_format == OutputFormat::Doctest; let save_temps = options.codegen_options.save_temps; + let registered_lints = config.register_lints.is_some(); let result = interface::run_compiler(config, |compiler| { - let krate = rustc_interface::passes::parse(&compiler.sess); + let sess = &compiler.sess; + + // -W help + if sess.opts.describe_lints { + rustc_driver::describe_lints(sess, registered_lints); + return Ok(None); + } + + let krate = rustc_interface::passes::parse(sess); let (collector, _incr_comp_session) = rustc_interface::create_and_enter_global_ctxt(compiler, krate, |tcx| { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index c4f7d2c361952..fd50a7b306783 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -542,6 +542,14 @@ fn opts() -> Vec { "Comma separated list of types of output for rustdoc to emit", "[html-static-files,html-non-static-files,dep-info]", ), + opt( + Unstable, + Multi, + "", + "print", + "Rustdoc information to print on stdout (or to a file)", + "[=]", + ), opt(Unstable, FlagMulti, "", "no-run", "Compile doctests without running them", ""), opt( Unstable, @@ -841,6 +849,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { let input = match input { config::InputMode::HasFile(input) => input, config::InputMode::NoInputMergeFinalize => { + if !options.prints.is_empty() { + dcx.fatal("`--print` is not supported for the `--write-doc-meta-dir` option"); + } + let config = core::create_config( Input::Str { name: rustc_span::FileName::Custom(String::new()), @@ -858,32 +870,53 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { ); } }; + let md_input = config::markdown_input(&input); - let output_format = options.output_format; + if options.should_test || options.output_format == config::OutputFormat::Doctest { + if !options.prints.is_empty() { + dcx.fatal(format!( + "`--print` is not yet supported for the `{}` option", + if options.should_test { "--test" } else { "--output-format=doctest" } + )); + } + + return match md_input { + Some(_) => wrap_return(dcx, doctest::test_markdown(&input, options, dcx)), + None => doctest::run(dcx, input, options), + }; + } - match ( - options.should_test || output_format == config::OutputFormat::Doctest, - config::markdown_input(&input), - ) { - (true, Some(_)) => return wrap_return(dcx, doctest::test_markdown(&input, options, dcx)), - (true, None) => return doctest::run(dcx, input, options), - (false, Some(md_input)) => { + if let Some(md_input) = md_input { + if !options.prints.is_empty() { + dcx.fatal("`--print` is not yet supported for standalone Markdown files"); + } + + return { let md_input = md_input.to_owned(); let edition = options.edition; let config = core::create_config(input, options, &render_options); + let registered_lints = config.register_lints.is_some(); // `markdown::render` can invoke `doctest::make_test`, which // requires session globals and a thread pool, so we use // `run_compiler`. - return wrap_return( + wrap_return( dcx, interface::run_compiler(config, |compiler| { + let sess = &compiler.sess; + + // -W help + if sess.opts.describe_lints { + rustc_driver::describe_lints(sess, registered_lints); + return Ok(()); + } + // construct a phony "crate" without actually running the parser // allows us to use other compiler infrastructure like dep-info - let file = - compiler.sess.source_map().load_file(&md_input).map_err(|e| { - format!("{md_input}: {e}", md_input = md_input.display()) - })?; + let file = sess + .source_map() + .load_file(&md_input) + .map_err(|e| format!("{md_input}: {e}", md_input = md_input.display()))?; let inner_span = Span::new( file.start_pos, BytePos(file.start_pos.0 + file.normalized_source_len.0), @@ -916,9 +949,8 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { }); res }), - ); - } - (false, None) => {} + ) + }; } // need to move these items separately because we lose them by the time the closure is called, @@ -940,7 +972,6 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { let output_format = options.output_format; let config = core::create_config(input, options, &render_options); - let registered_lints = config.register_lints.is_some(); interface::run_compiler(config, |compiler| { @@ -952,11 +983,19 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { let _ = sess.source_map().load_binary_file(external_path); } + // -W help if sess.opts.describe_lints { rustc_driver::describe_lints(sess, registered_lints); return; } + // --print + if rustc_driver::print_crate_info(&*compiler.codegen_backend, sess, true) + == rustc_driver::Compilation::Stop + { + return; + } + let krate = rustc_interface::passes::parse(sess); rustc_interface::create_and_enter_global_ctxt(compiler, krate, |tcx| { if sess.dcx().has_errors().is_some() { diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 4550c13982cbd..65a7890a5ecc2 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -351,11 +351,10 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "gimli", "gsgdt", "hashbrown", - "icu_collections", "icu_list", - "icu_locale", "icu_locale_core", - "icu_locale_data", + "icu_locale_fallback", + "icu_locale_fallback_data", "icu_provider", "ident_case", "indexmap", @@ -482,7 +481,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "unicode-script", "unicode-security", "unicode-width", - "utf8_iter", "utf8parse", "valuable", "version_check", diff --git a/tests/codegen-llvm/lib-optimizations/next_power_of_two.rs b/tests/codegen-llvm/lib-optimizations/next_power_of_two.rs new file mode 100644 index 0000000000000..309bd2f4661d4 --- /dev/null +++ b/tests/codegen-llvm/lib-optimizations/next_power_of_two.rs @@ -0,0 +1,82 @@ +//@ compile-flags: -C opt-level=3 -Z merge-functions=disabled +//@ only-64bit (avoid worrying about `usize` width) +//@ revisions: aarch64 x86_64 +//@ [aarch64] only-aarch64 +//@ [x86_64] only-x86_64 +//@ [x86_64] compile-flags: -C target-cpu=x86-64-v3 +// (The codegen comes out differently in -v1 so use -v3 to make it the same as aarch64.) + +#![crate_type = "lib"] + +// The idea behind the current implementation is that by returning `1 << …` +// LLVM can see that it's obviously a power of two, which wasn't the case +// in the implementation that did `(-1 >> …) + 1`. + +#[unsafe(no_mangle)] +pub fn full_npot(x: u64) -> u64 { + // CHECK-LABEL: @full_npot + // CHECK: [[M1:%.+]] = tail call i64 @llvm.usub.sat.i64(i64 %x, i64 1) + // CHECK: [[LZ:%.+]] = tail call {{.+}} i64 @llvm.ctlz.i64(i64 [[M1]], i1 false) + // CHECK: [[BW:%.+]] = sub nuw nsw i64 64, [[LZ]] + // CHECK: [[POT:%.+]] = shl nuw i64 1, [[BW]] + // CHECK: [[IS_WRAPPING:%.+]] = icmp slt i64 [[M1]], 0 + // CHECK: [[RET:%.+]] = select i1 [[IS_WRAPPING]], i64 0, i64 [[POT]] + // CHECK: ret i64 [[RET]] + x.next_power_of_two() +} + +// With a restricted input, both edge cases optimize away +#[unsafe(no_mangle)] +pub unsafe fn restricted_npot(x: u16) -> u16 { + std::hint::assert_unchecked(1 <= x); + // largest value that can get `shl nsw` too. + std::hint::assert_unchecked(x <= 0x4000); + + // CHECK-LABEL: @restricted_npot( + // CHECK: [[M1:%.+]] = add nsw i16 %x, -1 + // CHECK: [[LZ:%.+]] = tail call {{.+}} i16 @llvm.ctlz.i16(i16 [[M1]], i1 false) + // CHECK: [[BW:%.+]] = sub nuw nsw i16 16, [[LZ]] + // CHECK: [[P2:%.+]] = shl nuw nsw i16 1, [[BW]] + // CHECK: ret i16 [[P2]] + (x as u16).next_power_of_two() +} + +// Slices (of non-ZSTs) are short enough that the power-of-two always fits +#[unsafe(no_mangle)] +pub fn slice_length_npot(slice: &[u8]) -> usize { + // CHECK-LABEL: @slice_length_npot( + // CHECK: [[POT:%.+]] = shl nuw i64 1, + // CHECK: ret i64 [[POT]] + slice.len().next_power_of_two() +} + +#[unsafe(no_mangle)] +pub fn checked_npot_is_pot(x: u32) -> bool { + // CHECK-LABEL: @checked_npot_is_pot + // CHECK: ret i1 true + x.checked_next_power_of_two().is_none_or(u32::is_power_of_two) +} + +#[unsafe(no_mangle)] +pub fn wrapping_npot_is_pot_or_zero(x: u32) -> bool { + // CHECK-LABEL: @wrapping_npot_is_pot_or_zero + // CHECK: ret i1 true + x.next_power_of_two().count_ones() <= 1 +} + +// Because it knows it's a power of two, it can rewrite modulo to masking +#[no_mangle] +pub fn modulo_npot(value: u64, dividend: u64) { + // CHECK-LABEL: @modulo_npot + // CHECK: [[HIGHBITS:%.+]] = shl nsw i64 -1, + // CHECK: [[LOWBITS:%.+]] = xor i64 [[HIGHBITS]], -1 + // CHECK: [[REMAINDER:%.+]] = and i64 %dividend, [[LOWBITS]] + // CHECK: @do_something(i64 noundef [[REMAINDER]]) + if let Some(pot) = value.checked_next_power_of_two() { + do_something(dividend % pot) + } +} + +unsafe extern "Rust" { + safe fn do_something(_: u64); +} diff --git a/tests/run-make/offload-generic-manifest/generic.rs b/tests/run-make/offload/generic-manifest/generic.rs similarity index 100% rename from tests/run-make/offload-generic-manifest/generic.rs rename to tests/run-make/offload/generic-manifest/generic.rs diff --git a/tests/run-make/offload-generic-manifest/rmake.rs b/tests/run-make/offload/generic-manifest/rmake.rs similarity index 100% rename from tests/run-make/offload-generic-manifest/rmake.rs rename to tests/run-make/offload/generic-manifest/rmake.rs diff --git a/tests/run-make/offload/host-std-device-nostd/example.rs b/tests/run-make/offload/host-std-device-nostd/example.rs new file mode 100644 index 0000000000000..03b76ae8be06f --- /dev/null +++ b/tests/run-make/offload/host-std-device-nostd/example.rs @@ -0,0 +1,22 @@ +#![feature(gpu_offload, rustc_attrs)] +#![allow(internal_features)] +#![cfg_attr(device, no_std)] +#![cfg_attr(device, no_main)] + +#[cfg(device)] +#[panic_handler] +fn panic(_: &core::panic::PanicInfo) -> ! { + loop {} +} + +#[rustc_offload_kernel] +fn kernel() {} + +#[cfg(not(device))] +fn main() { + core::offload::offload! { + kernel = kernel, + args = (), + } + println!("Hello from Host with std"); +} diff --git a/tests/run-make/offload/host-std-device-nostd/rmake.rs b/tests/run-make/offload/host-std-device-nostd/rmake.rs new file mode 100644 index 0000000000000..35f408e8b1cd0 --- /dev/null +++ b/tests/run-make/offload/host-std-device-nostd/rmake.rs @@ -0,0 +1,40 @@ +//@ needs-offload + +// Tests offload with no-std in device and std in host + +use run_make_support::{cwd, rfs, rustc}; + +fn main() { + rustc() + .input("example.rs") + .arg("-Zunstable-options") + .arg("-Zoffload=HostMetadata=example.manifest") + .arg("-Csymbol-mangling-version=v0") + .arg("-Clto=fat") + .emit("metadata") + .run(); + + rustc() + .input("example.rs") + .cfg("device") + .arg("-Zunstable-options") + .arg("-Zoffload=Device=example.manifest") + .arg("-Csymbol-mangling-version=v0") + .arg("-Clto=fat") + .arg("-Cpanic=abort") + .emit("obj") + .run(); + + rfs::write(cwd().join("device.bin"), [0u8; 8]); + + rustc() + .input("example.rs") + .arg("-Zunstable-options") + .arg(format!("-Zoffload=Host={}", cwd().join("device.bin").display())) + .arg("-Csymbol-mangling-version=v0") + .arg("-Clto=fat") + .emit("obj") + .run(); + + assert!(cwd().join("host.o").exists()); +} diff --git a/tests/run-make/rustdoc/default-output/output-default.stdout b/tests/run-make/rustdoc/default-output/output-default.stdout index 78dfbf03c1b10..3093a01ec79f7 100644 --- a/tests/run-make/rustdoc/default-output/output-default.stdout +++ b/tests/run-make/rustdoc/default-output/output-default.stdout @@ -155,6 +155,8 @@ Options: --emit [html-static-files,html-non-static-files,dep-info] Comma separated list of types of output for rustdoc to emit + --print [=] + Rustdoc information to print on stdout (or to a file) --no-run Compile doctests without running them --merge-doctests yes|no|auto Force all doctests to be compiled as a single binary, diff --git a/tests/run-make/rustdoc/doctest/markdown/bad.md b/tests/run-make/rustdoc/doctest/markdown/bad.md new file mode 100644 index 0000000000000..3d43232cd61f1 --- /dev/null +++ b/tests/run-make/rustdoc/doctest/markdown/bad.md @@ -0,0 +1,9 @@ +# Cool Title + +``` +assert!(true); +``` + +``` +assert_eq!("foo", "bar"); +``` diff --git a/tests/run-make/rustdoc/doctest/markdown/extadd.rs b/tests/run-make/rustdoc/doctest/markdown/extadd.rs new file mode 100644 index 0000000000000..77a01ad3ca498 --- /dev/null +++ b/tests/run-make/rustdoc/doctest/markdown/extadd.rs @@ -0,0 +1,3 @@ +pub fn add(x: i32, y: i32) -> i32 { + x + y +} diff --git a/tests/run-make/rustdoc/doctest/markdown/extern.md b/tests/run-make/rustdoc/doctest/markdown/extern.md new file mode 100644 index 0000000000000..27a2a0e28588a --- /dev/null +++ b/tests/run-make/rustdoc/doctest/markdown/extern.md @@ -0,0 +1,7 @@ +# With extern crate + +``` +# extern crate aux; + +assert_eq!(aux::add(3, 4), 7); +``` diff --git a/tests/run-make/rustdoc/doctest/markdown/good.md b/tests/run-make/rustdoc/doctest/markdown/good.md new file mode 100644 index 0000000000000..db7e85d3fc51f --- /dev/null +++ b/tests/run-make/rustdoc/doctest/markdown/good.md @@ -0,0 +1,23 @@ +# Title + +Some text + +``` +assert_eq!(0, 0); +``` + +```text +Some more text +``` + +```ignore (example) +assert_eq!(0, 1; +``` + +```no_run +assert_eq!(0, 1); +``` + +```rust,compile_fail +Something +``` diff --git a/tests/run-make/rustdoc/doctest/markdown/rmake.rs b/tests/run-make/rustdoc/doctest/markdown/rmake.rs new file mode 100644 index 0000000000000..39e6b7e75885c --- /dev/null +++ b/tests/run-make/rustdoc/doctest/markdown/rmake.rs @@ -0,0 +1,34 @@ +// Doctests need std and executables that can run on the host +//@ needs-target-std +//@ ignore-wasm +//@ ignore-sgx +//@ ignore-pauthtest +//@ ignore-remote (e.g. armhf-gnu) + +use run_make_support::{rust_lib_name, rustc, rustdoc}; + +fn main() { + rustdoc().arg("--test").input("good.md").run().assert_exit_code(0).assert_stdout_contains( + "test result: ok. 3 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out;", + ); + + rustdoc() + .arg("--test") + .input("bad.md") + .run_fail() + .assert_exit_code(101) + .assert_stdout_contains( + "test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out;", + ); + + rustc().input("extadd.rs").crate_type("rlib").run(); + rustdoc() + .arg("--test") + .extern_("aux", rust_lib_name("extadd")) + .input("extern.md") + .run() + .assert_exit_code(0) + .assert_stdout_contains( + "test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out;", + ); +} diff --git a/tests/run-make/rustdoc/print-crate-root-lint-levels/lib.rs b/tests/run-make/rustdoc/print-crate-root-lint-levels/lib.rs new file mode 100644 index 0000000000000..a4ec391dda950 --- /dev/null +++ b/tests/run-make/rustdoc/print-crate-root-lint-levels/lib.rs @@ -0,0 +1,6 @@ +#![allow(rustdoc::private_doc_tests)] +#![forbid(rustdoc::private_intra_doc_links)] +#![expect(unused_mut)] + +#[deny(unknown_lints)] +mod my_mod {} diff --git a/tests/run-make/rustdoc/print-crate-root-lint-levels/rmake.rs b/tests/run-make/rustdoc/print-crate-root-lint-levels/rmake.rs new file mode 100644 index 0000000000000..4f7d3e129b41c --- /dev/null +++ b/tests/run-make/rustdoc/print-crate-root-lint-levels/rmake.rs @@ -0,0 +1,124 @@ +//! This checks the output of `--print=crate-root-lint-levels` + +use std::collections::HashSet; +use std::iter::FromIterator; + +use run_make_support::rustdoc; + +struct CrateRootLintLevels { + args: &'static [&'static str], + contains: Contains, +} + +struct Contains { + contains: &'static [&'static str], + doesnt_contain: &'static [&'static str], +} + +fn main() { + // rustdoc don't run rustc lints, and ignores rustc lint check attributes + check(CrateRootLintLevels { + args: &[], + contains: Contains { + contains: &[ + "rustdoc::private_doc_tests=allow", + "unused_mut=allow", + "warnings=warn", + "stable_features=warn", + "unknown_lints=warn", + "rustdoc::broken_intra_doc_links=warn", + "rustdoc::private_intra_doc_links=forbid", + "rustdoc::missing_crate_level_docs=allow", + ], + doesnt_contain: &["rustdoc::private_doc_tests=warn", "unused_mut=expect"], + }, + }); + check(CrateRootLintLevels { + args: &["-Wrustdoc::private_doc_tests"], + contains: Contains { + contains: &["rustdoc::private_doc_tests=allow", "warnings=warn"], + doesnt_contain: &["rustdoc::private_doc_tests=warn"], + }, + }); + check(CrateRootLintLevels { + args: &["-Dwarnings"], + contains: Contains { + contains: &[ + "rustdoc::private_doc_tests=allow", + "warnings=deny", + "stable_features=deny", + "unknown_lints=deny", + ], + doesnt_contain: &["warnings=warn"], + }, + }); + check(CrateRootLintLevels { + args: &["-Dstable_features"], + contains: Contains { + contains: &[ + "warnings=warn", + "stable_features=deny", + "rustdoc::private_doc_tests=allow", + ], + doesnt_contain: &["warnings=deny"], + }, + }); + check(CrateRootLintLevels { + args: &["-Dwarnings", "--force-warn=stable_features"], + contains: Contains { + contains: &["warnings=deny", "stable_features=force-warn", "unknown_lints=deny"], + doesnt_contain: &["warnings=warn"], + }, + }); + check(CrateRootLintLevels { + args: &["-Dwarnings", "--cap-lints=warn"], + contains: Contains { + contains: &[ + "rustdoc::private_doc_tests=allow", + "warnings=warn", + "stable_features=warn", + "unknown_lints=warn", + ], + doesnt_contain: &["warnings=deny"], + }, + }); +} + +#[track_caller] +fn check(CrateRootLintLevels { args, contains }: CrateRootLintLevels) { + let output = rustdoc() + .input("lib.rs") + .arg("-Zunstable-options") + .arg("--print=crate-root-lint-levels") + .args(args) + .run(); + + let stdout = output.stdout_utf8(); + + let mut found = HashSet::::new(); + + for l in stdout.lines() { + assert!(l == l.trim()); + if let Some((left, right)) = l.split_once('=') { + assert!(!left.contains("\"")); + assert!(!right.contains("\"")); + } else { + assert!(l.contains('=')); + } + assert!(found.insert(l.to_string()), "{}", &l); + } + + let Contains { contains, doesnt_contain } = contains; + + { + let should_found = HashSet::::from_iter(contains.iter().map(|s| s.to_string())); + let diff: Vec<_> = should_found.difference(&found).collect(); + assert!(diff.is_empty(), "should found: {:?}, didn't found {:?}", &should_found, &diff); + } + { + let should_not_find = + HashSet::::from_iter(doesnt_contain.iter().map(|s| s.to_string())); + let diff: Vec<_> = should_not_find.intersection(&found).collect(); + assert!(diff.is_empty(), "should not find {:?}, did found {:?}", &should_not_find, &diff); + } +} diff --git a/tests/run-make/rustdoc/print-request-help/invalid-print-request-help.err b/tests/run-make/rustdoc/print-request-help/invalid-print-request-help.err new file mode 100644 index 0000000000000..02d14190030bb --- /dev/null +++ b/tests/run-make/rustdoc/print-request-help/invalid-print-request-help.err @@ -0,0 +1,4 @@ +error: unknown print request: `xxx` + | + = help: valid print requests are: `all-target-specs-json`, `cfg`, `check-cfg`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `wasm-proc-macro-tuple` + diff --git a/tests/run-make/rustdoc/print-request-help/rmake.rs b/tests/run-make/rustdoc/print-request-help/rmake.rs new file mode 100644 index 0000000000000..bfa494ca2ccb6 --- /dev/null +++ b/tests/run-make/rustdoc/print-request-help/rmake.rs @@ -0,0 +1,10 @@ +use run_make_support::{diff, rustdoc}; + +fn main() { + let invalid_print_request_help = + rustdoc().arg("-Zunstable-options").arg("--print=xxx").run_fail().stderr_utf8(); + diff() + .expected_file("invalid-print-request-help.err") + .actual_text("invalid_print_request_help", &invalid_print_request_help) + .run(); +} diff --git a/tests/rustdoc-js/never-search.js b/tests/rustdoc-js/never-search.js index 9cc62a5ed04a5..7f626be7b64f6 100644 --- a/tests/rustdoc-js/never-search.js +++ b/tests/rustdoc-js/never-search.js @@ -12,6 +12,7 @@ const EXPECTED = [ 'query': '-> !', 'others': [ { 'path': 'never_search', 'name': 'loops' }, + { 'path': 'never_search::never', 'name': 'try_from' }, ], }, { @@ -19,6 +20,7 @@ const EXPECTED = [ 'others': [ { 'path': 'never_search', 'name': 'loops' }, { 'path': 'never_search', 'name': 'returns' }, + { 'path': 'never_search::never', 'name': 'try_from' }, ], }, { diff --git a/tests/rustdoc-html/async/async-move-doctest.rs b/tests/rustdoc-ui/doctest/async-move-doctest.rs similarity index 77% rename from tests/rustdoc-html/async/async-move-doctest.rs rename to tests/rustdoc-ui/doctest/async-move-doctest.rs index e18ec353533df..f491a9a04f851 100644 --- a/tests/rustdoc-html/async/async-move-doctest.rs +++ b/tests/rustdoc-ui/doctest/async-move-doctest.rs @@ -1,5 +1,7 @@ //@ compile-flags:--test +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" //@ edition:2018 +//@ check-pass // Prior to setting the default edition for the doctest pre-parser, // this doctest would fail due to a fatal parsing error. diff --git a/tests/rustdoc-ui/doctest/async-move-doctest.stdout b/tests/rustdoc-ui/doctest/async-move-doctest.stdout new file mode 100644 index 0000000000000..4790438d4602f --- /dev/null +++ b/tests/rustdoc-ui/doctest/async-move-doctest.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/async-move-doctest.rs - (line 10) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/comment-in-doctest.rs b/tests/rustdoc-ui/doctest/comment-in-doctest.rs similarity index 89% rename from tests/rustdoc-html/comment-in-doctest.rs rename to tests/rustdoc-ui/doctest/comment-in-doctest.rs index e580aa2bb72c6..2caec5db9c920 100644 --- a/tests/rustdoc-html/comment-in-doctest.rs +++ b/tests/rustdoc-ui/doctest/comment-in-doctest.rs @@ -1,4 +1,6 @@ //@ compile-flags:--test +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ check-pass // comments, both doc comments and regular ones, used to trick rustdoc's doctest parser into // thinking that everything after it was part of the regular program. combined with the librustc_ast diff --git a/tests/rustdoc-ui/doctest/comment-in-doctest.stdout b/tests/rustdoc-ui/doctest/comment-in-doctest.stdout new file mode 100644 index 0000000000000..5cb97c53f37fd --- /dev/null +++ b/tests/rustdoc-ui/doctest/comment-in-doctest.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/comment-in-doctest.rs - (line 12) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/demo-allocator-54478.rs b/tests/rustdoc-ui/doctest/demo-allocator-54478.rs similarity index 93% rename from tests/rustdoc-html/demo-allocator-54478.rs rename to tests/rustdoc-ui/doctest/demo-allocator-54478.rs index 80acfc0ff58a1..073d83e11120e 100644 --- a/tests/rustdoc-html/demo-allocator-54478.rs +++ b/tests/rustdoc-ui/doctest/demo-allocator-54478.rs @@ -1,4 +1,9 @@ // https://github.com/rust-lang/rust/issues/54478 + +//@ compile-flags:--test +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ check-pass + #![crate_name="foo"] // Issue #54478: regression test showing that we can demonstrate @@ -15,8 +20,6 @@ // decided to change `rustdoc` to behave more like the compiler's // default setting, by leaving off `-C prefer-dynamic`. -//@ compile-flags:--test - //! This is a doc comment //! //! ```rust diff --git a/tests/rustdoc-ui/doctest/demo-allocator-54478.stdout b/tests/rustdoc-ui/doctest/demo-allocator-54478.stdout new file mode 100644 index 0000000000000..f32d9a5b7d932 --- /dev/null +++ b/tests/rustdoc-ui/doctest/demo-allocator-54478.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/demo-allocator-54478.rs - (line 25) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/doc-cfg/doc-cfg-target-feature.rs b/tests/rustdoc-ui/doctest/doc-cfg-target-feature.rs similarity index 67% rename from tests/rustdoc-html/doc-cfg/doc-cfg-target-feature.rs rename to tests/rustdoc-ui/doctest/doc-cfg-target-feature.rs index b66e86e36af8b..a55b31d61e3d0 100644 --- a/tests/rustdoc-html/doc-cfg/doc-cfg-target-feature.rs +++ b/tests/rustdoc-ui/doctest/doc-cfg-target-feature.rs @@ -1,6 +1,8 @@ //@ only-x86_64 +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ normalize-stdout: "rust_out::main::.+" -> "rust_out::main::$$PATH" //@ compile-flags:--test -//@ should-fail +//@ failure-status: 101 // #49723: rustdoc didn't add target features when extracting or running doctests diff --git a/tests/rustdoc-ui/doctest/doc-cfg-target-feature.stdout b/tests/rustdoc-ui/doctest/doc-cfg-target-feature.stdout new file mode 100644 index 0000000000000..6526e9898dd2f --- /dev/null +++ b/tests/rustdoc-ui/doctest/doc-cfg-target-feature.stdout @@ -0,0 +1,39 @@ + +running 1 test +test $DIR/doc-cfg-target-feature.rs - foo (line 15) ... FAILED + +failures: + +---- $DIR/doc-cfg-target-feature.rs - foo (line 15) stdout ---- +warning: the feature `cfg_target_feature` has been stable since 1.27.0 and no longer requires an attribute to enable + --> $DIR/doc-cfg-target-feature.rs:15:12 + | +LL | #![feature(cfg_target_feature)] + | ^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(stable_features)]` on by default + +warning: 1 warning emitted + +Test executable failed (exit status: 101). + +stderr: + +thread 'main' ($TID) panicked at $DIR/doc-cfg-target-feature.rs:7:1: +assertion failed: false +stack backtrace: + 0: __rustc::rust_begin_unwind + 1: core::panicking::panic_fmt + 2: core::panicking::panic + 3: rust_out::main::$PATH + 4: rust_out::main + 5: >::call_once +note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. + + + +failures: + $DIR/doc-cfg-target-feature.rs - foo (line 15) + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/doc-test-attr-18199.rs b/tests/rustdoc-ui/doctest/doc-test-attr-18199.rs similarity index 74% rename from tests/rustdoc-html/doc-test-attr-18199.rs rename to tests/rustdoc-ui/doctest/doc-test-attr-18199.rs index 64016e32eeeb1..8350f244fccac 100644 --- a/tests/rustdoc-html/doc-test-attr-18199.rs +++ b/tests/rustdoc-ui/doctest/doc-test-attr-18199.rs @@ -1,6 +1,9 @@ -//@ compile-flags:--test // https://github.com/rust-lang/rust/issues/18199 +//@ compile-flags:--test +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ check-pass + #![doc(test(attr(feature(staged_api))))] /// ``` diff --git a/tests/rustdoc-ui/doctest/doc-test-attr-18199.stdout b/tests/rustdoc-ui/doctest/doc-test-attr-18199.stdout new file mode 100644 index 0000000000000..a182a3b911af6 --- /dev/null +++ b/tests/rustdoc-ui/doctest/doc-test-attr-18199.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/doc-test-attr-18199.rs - foo (line 9) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/edition-doctest.rs b/tests/rustdoc-ui/doctest/edition-doctest.rs similarity index 87% rename from tests/rustdoc-html/edition-doctest.rs rename to tests/rustdoc-ui/doctest/edition-doctest.rs index f43c074f806bd..066475dae7bf0 100644 --- a/tests/rustdoc-html/edition-doctest.rs +++ b/tests/rustdoc-ui/doctest/edition-doctest.rs @@ -1,4 +1,6 @@ -//@ compile-flags:--test +//@ compile-flags:--test --test-args=--test-threads=1 +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ check-pass /// ```rust,edition2018 /// #![feature(try_blocks)] diff --git a/tests/rustdoc-ui/doctest/edition-doctest.stdout b/tests/rustdoc-ui/doctest/edition-doctest.stdout new file mode 100644 index 0000000000000..40d0df0575a76 --- /dev/null +++ b/tests/rustdoc-ui/doctest/edition-doctest.stdout @@ -0,0 +1,7 @@ + +running 2 tests +test $DIR/edition-doctest.rs - foo (line 24) - compile fail ... ok +test $DIR/edition-doctest.rs - foo (line 5) ... ok + +test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/edition-flag.rs b/tests/rustdoc-ui/doctest/edition-flag.rs similarity index 63% rename from tests/rustdoc-html/edition-flag.rs rename to tests/rustdoc-ui/doctest/edition-flag.rs index c57c8d50b2357..51235634dbf4a 100644 --- a/tests/rustdoc-html/edition-flag.rs +++ b/tests/rustdoc-ui/doctest/edition-flag.rs @@ -1,5 +1,7 @@ //@ compile-flags:--test //@ edition:2018 +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ check-pass /// ```rust /// fn main() { diff --git a/tests/rustdoc-ui/doctest/edition-flag.stdout b/tests/rustdoc-ui/doctest/edition-flag.stdout new file mode 100644 index 0000000000000..4833a6dcf9adf --- /dev/null +++ b/tests/rustdoc-ui/doctest/edition-flag.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/edition-flag.rs - main (line 6) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/force-target-feature.rs b/tests/rustdoc-ui/doctest/force-target-feature.rs similarity index 52% rename from tests/rustdoc-html/force-target-feature.rs rename to tests/rustdoc-ui/doctest/force-target-feature.rs index fa71bbeea2747..f39e7cf3a9094 100644 --- a/tests/rustdoc-html/force-target-feature.rs +++ b/tests/rustdoc-ui/doctest/force-target-feature.rs @@ -1,6 +1,10 @@ //@ only-x86_64 //@ compile-flags:--test -C target-feature=+avx -//@ should-fail +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ normalize-stdout: "rust_out::main::.+" -> "rust_out::main::$$PATH" +//@ failure-status: 101 + +#![feature(doc_cfg)] /// (written on a spider's web) Some Struct /// diff --git a/tests/rustdoc-ui/doctest/force-target-feature.stdout b/tests/rustdoc-ui/doctest/force-target-feature.stdout new file mode 100644 index 0000000000000..fb898dd14b2c9 --- /dev/null +++ b/tests/rustdoc-ui/doctest/force-target-feature.stdout @@ -0,0 +1,27 @@ + +running 1 test +test $DIR/force-target-feature.rs - SomeStruct (line 11) ... FAILED + +failures: + +---- $DIR/force-target-feature.rs - SomeStruct (line 11) stdout ---- +Test executable failed (exit status: 101). + +stderr: + +thread 'main' ($TID) panicked at $DIR/force-target-feature.rs:3:1: +oh no +stack backtrace: + 0: std::panicking::begin_panic::<&str> + 1: rust_out::main::$PATH + 2: rust_out::main + 3: >::call_once +note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. + + + +failures: + $DIR/force-target-feature.rs - SomeStruct (line 11) + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/ice-type-error-19181.rs b/tests/rustdoc-ui/doctest/ice-type-error-19181.rs similarity index 65% rename from tests/rustdoc-html/ice-type-error-19181.rs rename to tests/rustdoc-ui/doctest/ice-type-error-19181.rs index 02c6404762222..accb9e2cab1f4 100644 --- a/tests/rustdoc-html/ice-type-error-19181.rs +++ b/tests/rustdoc-ui/doctest/ice-type-error-19181.rs @@ -1,4 +1,7 @@ //@ compile-flags:--test +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ check-pass + // https://github.com/rust-lang/rust/issues/19181 // rustdoc should not panic when target crate has compilation errors diff --git a/tests/rustdoc-ui/doctest/ice-type-error-19181.stdout b/tests/rustdoc-ui/doctest/ice-type-error-19181.stdout new file mode 100644 index 0000000000000..7326c0a25a069 --- /dev/null +++ b/tests/rustdoc-ui/doctest/ice-type-error-19181.stdout @@ -0,0 +1,5 @@ + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/no-run-still-checks-lints.rs b/tests/rustdoc-ui/doctest/no-run-still-checks-lints.rs similarity index 55% rename from tests/rustdoc-html/no-run-still-checks-lints.rs rename to tests/rustdoc-ui/doctest/no-run-still-checks-lints.rs index 73e311b72d5e5..cae6331f4723d 100644 --- a/tests/rustdoc-html/no-run-still-checks-lints.rs +++ b/tests/rustdoc-ui/doctest/no-run-still-checks-lints.rs @@ -1,5 +1,6 @@ //@ compile-flags:--test -//@ should-fail +//@ failure-status: 101 +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" #![doc(test(attr(deny(warnings))))] diff --git a/tests/rustdoc-ui/doctest/no-run-still-checks-lints.stdout b/tests/rustdoc-ui/doctest/no-run-still-checks-lints.stdout new file mode 100644 index 0000000000000..86d1b4d3094b6 --- /dev/null +++ b/tests/rustdoc-ui/doctest/no-run-still-checks-lints.stdout @@ -0,0 +1,29 @@ + +running 1 test +test $DIR/no-run-still-checks-lints.rs - foo (line 7) - compile ... FAILED + +failures: + +---- $DIR/no-run-still-checks-lints.rs - foo (line 7) stdout ---- +error: unused variable: `a` + --> $DIR/no-run-still-checks-lints.rs:8:5 + | +LL | let a = 3; + | ^ help: if this is intentional, prefix it with an underscore: `_a` + | +note: the lint level is defined here + --> $DIR/no-run-still-checks-lints.rs:6:9 + | +LL | #![deny(warnings)] + | ^^^^^^^^ + = note: `#[deny(unused_variables)]` implied by `#[deny(warnings)]` + +error: aborting due to 1 previous error + +Couldn't compile the test. + +failures: + $DIR/no-run-still-checks-lints.rs - foo (line 7) + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/process-termination.rs b/tests/rustdoc-ui/doctest/process-termination.rs similarity index 80% rename from tests/rustdoc-html/process-termination.rs rename to tests/rustdoc-ui/doctest/process-termination.rs index 73a86e57424a2..02ac594b3f0d4 100644 --- a/tests/rustdoc-html/process-termination.rs +++ b/tests/rustdoc-ui/doctest/process-termination.rs @@ -1,4 +1,6 @@ -//@ compile-flags:--test +//@ compile-flags:--test --test-args=--test-threads=1 +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ check-pass /// A check of using various process termination strategies /// diff --git a/tests/rustdoc-ui/doctest/process-termination.stdout b/tests/rustdoc-ui/doctest/process-termination.stdout new file mode 100644 index 0000000000000..3e15b9a5df80a --- /dev/null +++ b/tests/rustdoc-ui/doctest/process-termination.stdout @@ -0,0 +1,8 @@ + +running 3 tests +test $DIR/process-termination.rs - check_process_termination (line 16) ... ok +test $DIR/process-termination.rs - check_process_termination (line 22) ... ok +test $DIR/process-termination.rs - check_process_termination (line 9) ... ok + +test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/sanitizer-option.rs b/tests/rustdoc-ui/doctest/sanitizer-option.rs similarity index 86% rename from tests/rustdoc-html/sanitizer-option.rs rename to tests/rustdoc-ui/doctest/sanitizer-option.rs index 7b0038138f09f..5f29f1b8bac7e 100644 --- a/tests/rustdoc-html/sanitizer-option.rs +++ b/tests/rustdoc-ui/doctest/sanitizer-option.rs @@ -1,7 +1,9 @@ //@ needs-sanitizer-support //@ needs-sanitizer-address //@ compile-flags: --test -Z sanitizer=address -C unsafe-allow-abi-mismatch=sanitizer -// +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ check-pass + // #43031: Verify that rustdoc passes `-Z` options to rustc. Use an extern // function that is provided by the sanitizer runtime, if flag is not passed // correctly, then linking will fail. diff --git a/tests/rustdoc-html/test_option_check/test.rs b/tests/rustdoc-ui/doctest/test-option-check-2.rs similarity index 54% rename from tests/rustdoc-html/test_option_check/test.rs rename to tests/rustdoc-ui/doctest/test-option-check-2.rs index af7a5827690f0..2e74da1eca794 100644 --- a/tests/rustdoc-html/test_option_check/test.rs +++ b/tests/rustdoc-ui/doctest/test-option-check-2.rs @@ -1,6 +1,9 @@ -//@ compile-flags: --test +//@ compile-flags: --test --test-args=--test-threads=1 //@ check-test-line-numbers-match +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ check-pass +#[path = "test-option-check.rs"] pub mod bar; /// This is a Foo; diff --git a/tests/rustdoc-ui/doctest/test-option-check-2.stdout b/tests/rustdoc-ui/doctest/test-option-check-2.stdout new file mode 100644 index 0000000000000..ab2db4938dfab --- /dev/null +++ b/tests/rustdoc-ui/doctest/test-option-check-2.stdout @@ -0,0 +1,8 @@ + +running 3 tests +test $DIR/test-option-check-2.rs - Bar (line 18) ... ok +test $DIR/test-option-check-2.rs - Foo (line 11) ... ok +test $DIR/test-option-check.rs - bar::foooo (line 8) ... ok + +test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-html/test_option_check/bar.rs b/tests/rustdoc-ui/doctest/test-option-check.rs similarity index 65% rename from tests/rustdoc-html/test_option_check/bar.rs rename to tests/rustdoc-ui/doctest/test-option-check.rs index 7c2309a79d4b9..e5d3350e3f981 100644 --- a/tests/rustdoc-html/test_option_check/bar.rs +++ b/tests/rustdoc-ui/doctest/test-option-check.rs @@ -1,5 +1,7 @@ //@ compile-flags: --test //@ check-test-line-numbers-match +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ check-pass /// This looks like another awesome test! /// diff --git a/tests/rustdoc-ui/doctest/test-option-check.stdout b/tests/rustdoc-ui/doctest/test-option-check.stdout new file mode 100644 index 0000000000000..38f949612a47a --- /dev/null +++ b/tests/rustdoc-ui/doctest/test-option-check.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/test-option-check.rs - foooo (line 8) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + diff --git a/tests/rustdoc-ui/lints/renamed-lint-still-applies.rs b/tests/rustdoc-ui/lints/renamed-lint-still-applies.rs deleted file mode 100644 index a4d3a4b497117..0000000000000 --- a/tests/rustdoc-ui/lints/renamed-lint-still-applies.rs +++ /dev/null @@ -1,10 +0,0 @@ -// compile-args: --crate-type lib -#![deny(broken_intra_doc_links)] -//~^ WARNING renamed to `rustdoc::broken_intra_doc_links` -//! [x] -//~^ ERROR unresolved link - -#![deny(rustdoc::non_autolinks)] -//~^ WARNING renamed to `rustdoc::bare_urls` -//! http://example.com -//~^ ERROR not a hyperlink diff --git a/tests/rustdoc-ui/lints/renamed-lint-still-applies.stderr b/tests/rustdoc-ui/lints/renamed-lint-still-applies.stderr index 88807dfb495d0..f4428ff6e5983 100644 --- a/tests/rustdoc-ui/lints/renamed-lint-still-applies.stderr +++ b/tests/rustdoc-ui/lints/renamed-lint-still-applies.stderr @@ -1,5 +1,5 @@ warning: lint `broken_intra_doc_links` has been renamed to `rustdoc::broken_intra_doc_links` - --> $DIR/renamed-lint-still-applies.rs:2:9 + --> $DIR/renamed-lint-still-applies.rs:3:9 | LL | #![deny(broken_intra_doc_links)] | ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::broken_intra_doc_links` @@ -7,33 +7,33 @@ LL | #![deny(broken_intra_doc_links)] = note: `#[warn(renamed_and_removed_lints)]` on by default warning: lint `rustdoc::non_autolinks` has been renamed to `rustdoc::bare_urls` - --> $DIR/renamed-lint-still-applies.rs:7:9 + --> $DIR/renamed-lint-still-applies.rs:8:9 | LL | #![deny(rustdoc::non_autolinks)] | ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::bare_urls` error: unresolved link to `x` - --> $DIR/renamed-lint-still-applies.rs:4:6 + --> $DIR/renamed-lint-still-applies.rs:5:6 | LL | //! [x] | ^ no item named `x` in scope | = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` note: the lint level is defined here - --> $DIR/renamed-lint-still-applies.rs:2:9 + --> $DIR/renamed-lint-still-applies.rs:3:9 | LL | #![deny(broken_intra_doc_links)] | ^^^^^^^^^^^^^^^^^^^^^^ error: this URL is not a hyperlink - --> $DIR/renamed-lint-still-applies.rs:9:5 + --> $DIR/renamed-lint-still-applies.rs:10:5 | LL | //! http://example.com | ^^^^^^^^^^^^^^^^^^ | = note: bare URLs are not automatically turned into clickable links note: the lint level is defined here - --> $DIR/renamed-lint-still-applies.rs:7:9 + --> $DIR/renamed-lint-still-applies.rs:8:9 | LL | #![deny(rustdoc::non_autolinks)] | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/forbid-error-capped.rs b/tests/ui/lint/forbid-error-capped.rs index e458ddf90746e..bfa72beac5828 100644 --- a/tests/ui/lint/forbid-error-capped.rs +++ b/tests/ui/lint/forbid-error-capped.rs @@ -1,5 +1,4 @@ //@ check-pass -// compile-args: --cap-lints=warn -Fwarnings // This checks that the forbid attribute checking is ignored when the forbidden // lint is capped. diff --git a/tests/ui/lint/forbid-error-capped.stderr b/tests/ui/lint/forbid-error-capped.stderr index 479e7b9412d57..3de8c2fe0ce61 100644 --- a/tests/ui/lint/forbid-error-capped.stderr +++ b/tests/ui/lint/forbid-error-capped.stderr @@ -1,5 +1,5 @@ warning: allow(unused) incompatible with previous forbid - --> $DIR/forbid-error-capped.rs:8:10 + --> $DIR/forbid-error-capped.rs:7:10 | LL | #![forbid(warnings)] | -------- `forbid` level set here @@ -14,7 +14,7 @@ warning: 1 warning emitted Future incompatibility report: Future breakage diagnostic: warning: allow(unused) incompatible with previous forbid - --> $DIR/forbid-error-capped.rs:8:10 + --> $DIR/forbid-error-capped.rs:7:10 | LL | #![forbid(warnings)] | -------- `forbid` level set here diff --git a/tests/ui/mir/issue-71793-inline-args-storage.rs b/tests/ui/mir/issue-71793-inline-args-storage.rs index 0ed4d4723731e..38ce28a035346 100644 --- a/tests/ui/mir/issue-71793-inline-args-storage.rs +++ b/tests/ui/mir/issue-71793-inline-args-storage.rs @@ -1,10 +1,10 @@ // Verifies that inliner emits StorageLive & StorageDead when introducing // temporaries for arguments, so that they don't become part of the coroutine. // Regression test for #71793. -// + //@ check-pass //@ edition:2018 -// compile-args: -Zmir-opt-level=3 +//@ compile-flags: -Zmir-opt-level=3 #![crate_type = "lib"] diff --git a/tests/ui/offload/duplicate_kernel.rs b/tests/ui/offload/duplicate_kernel.rs index da667a0c0666a..7dd8d7ee11225 100644 --- a/tests/ui/offload/duplicate_kernel.rs +++ b/tests/ui/offload/duplicate_kernel.rs @@ -5,7 +5,7 @@ // An offload kernel whose mangled symbol collides with another item in the // same crate must be rejected, just like any other symbol collision. -#![feature(core_intrinsics, rustc_attrs)] +#![feature(rustc_attrs, gpu_offload)] #![allow(internal_features)] #[allow(non_snake_case)] @@ -18,5 +18,5 @@ fn kernel(_x: f32) {} fn main() { _RNvC19collision_kernels_a6kernel(0.0); - core::intrinsics::offload::<_, _, ()>(kernel, [1, 1, 1], [1, 1, 1], 0, -1, (0.0f32,)); + core::offload::offload! { kernel = kernel, args = (0.0f32,) } } diff --git a/tests/ui/offload/non_tuple_args.rs b/tests/ui/offload/non_tuple_args.rs index 14de21b2374a2..2c63b6d6abe81 100644 --- a/tests/ui/offload/non_tuple_args.rs +++ b/tests/ui/offload/non_tuple_args.rs @@ -1,10 +1,10 @@ //@ compile-flags: -Zunstable-options -Zoffload=Device -Clto=fat -#![feature(core_intrinsics)] +#![feature(gpu_offload)] fn main() { // args_ty is not a tuple - core::intrinsics::offload::<_, _, ()>(kernel_0, [1, 1, 1], [1, 1, 1], 0, -1, 42); + core::offload::offload! { kernel = kernel_0, args = 42 } //~^ ERROR `{integer}` is not a tuple } diff --git a/tests/ui/offload/non_tuple_args.stderr b/tests/ui/offload/non_tuple_args.stderr index 90b0f16bec53e..26687d4b4bbb7 100644 --- a/tests/ui/offload/non_tuple_args.stderr +++ b/tests/ui/offload/non_tuple_args.stderr @@ -1,11 +1,12 @@ error[E0277]: `{integer}` is not a tuple - --> $DIR/non_tuple_args.rs:7:36 + --> $DIR/non_tuple_args.rs:7:5 | -LL | core::intrinsics::offload::<_, _, ()>(kernel_0, [1, 1, 1], [1, 1, 1], 0, -1, 42); - | ^ the nightly-only, unstable trait `std::marker::Tuple` is not implemented for `{integer}` +LL | core::offload::offload! { kernel = kernel_0, args = 42 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `std::marker::Tuple` is not implemented for `{integer}` | note: required by a bound in `offload` --> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL + = note: this error originates in the macro `$crate::offload` which comes from the expansion of the macro `core::offload::offload` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error