From c7d949d9ead313fd9d1c14edfe709d1b1669b6f1 Mon Sep 17 00:00:00 2001 From: Hanna Kruppe Date: Sat, 29 Aug 2026 13:32:29 +0200 Subject: [PATCH 01/15] Remove -Zsaturating-float-casts flag I added this flag back in 2017 to enable benchmarking of the saturating semantics when it was newly implemented and still experimental. But saturation has been the official semantics for float<->int `as` casts for years now. A flag for turning it off no longer serves any purpose, it's just `-Zplease-miscompile-casts` now. --- compiler/rustc_codegen_cranelift/src/cast.rs | 4 ---- compiler/rustc_codegen_cranelift/src/codegen_f16_f128.rs | 4 ---- compiler/rustc_codegen_ssa/src/traits/builder.rs | 4 ---- compiler/rustc_interface/src/tests.rs | 1 - compiler/rustc_session/src/options.rs | 3 --- 5 files changed, 16 deletions(-) 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_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_session/src/options.rs b/compiler/rustc_session/src/options.rs index 90459090ced87..d1cc7122236b7 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2827,9 +2827,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"), From 938b233e4c0e94db0974b958ecc5a5842fc1df21 Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Sun, 30 Aug 2026 15:05:23 +0200 Subject: [PATCH 02/15] doc: `PrintKind` --- compiler/rustc_session/src/config.rs | 9 ++-- .../rustc_session/src/config/print_request.rs | 53 +++++++++++++++++++ src/librustdoc/config.rs | 1 - 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 95f6348cfbdbb..bba0d8190dab7 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1414,12 +1414,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. diff --git a/compiler/rustc_session/src/config/print_request.rs b/compiler/rustc_session/src/config/print_request.rs index 8201e1bfdd9a7..0cc805d4706cc 100644 --- a/compiler/rustc_session/src/config/print_request.rs +++ b/compiler/rustc_session/src/config/print_request.rs @@ -22,32 +22,85 @@ 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 } diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 941632f0d283a..349fb9c0b2b08 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -336,7 +336,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)), From 2e7e5cb3a90baf22f14d7f1f6b55ce46342028a3 Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Sun, 30 Aug 2026 17:36:51 +0200 Subject: [PATCH 03/15] rustdoc: cleanup `main_args()` markdown handling --- src/librustdoc/lib.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index c4f7d2c361952..55eae627467a4 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -858,16 +858,17 @@ 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 { + 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 { + return { let md_input = md_input.to_owned(); let edition = options.edition; let config = core::create_config(input, options, &render_options); @@ -875,7 +876,7 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { // `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| { // construct a phony "crate" without actually running the parser @@ -916,9 +917,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, From 41258df4130f7c8eaab4d3177d156b1661587456 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 30 Aug 2026 16:19:50 +0200 Subject: [PATCH 04/15] Move more `rustdoc-html` tests using `--test` into the right folder --- .../doctest}/async-move-doctest.rs | 2 + .../doctest/async-move-doctest.stdout | 6 +++ .../doctest}/comment-in-doctest.rs | 2 + .../doctest/comment-in-doctest.stdout | 6 +++ .../doctest}/demo-allocator-54478.rs | 7 +++- .../doctest/demo-allocator-54478.stdout | 6 +++ .../doctest}/doc-cfg-target-feature.rs | 3 +- .../doctest/doc-cfg-target-feature.stdout | 39 +++++++++++++++++++ .../doctest}/doc-test-attr-18199.rs | 5 ++- .../doctest/doc-test-attr-18199.stdout | 6 +++ .../doctest}/edition-doctest.rs | 4 +- .../rustdoc-ui/doctest/edition-doctest.stdout | 7 ++++ .../doctest}/edition-flag.rs | 2 + tests/rustdoc-ui/doctest/edition-flag.stdout | 6 +++ .../doctest}/force-target-feature.rs | 5 ++- .../doctest/force-target-feature.stdout | 27 +++++++++++++ .../doctest}/ice-type-error-19181.rs | 3 ++ .../doctest/ice-type-error-19181.stdout | 5 +++ .../doctest}/no-run-still-checks-lints.rs | 3 +- .../doctest/no-run-still-checks-lints.stdout | 29 ++++++++++++++ .../doctest}/process-termination.rs | 4 +- .../doctest/process-termination.stdout | 8 ++++ .../doctest}/sanitizer-option.rs | 4 +- .../doctest/test-option-check-2.rs} | 5 ++- .../doctest/test-option-check-2.stdout | 8 ++++ .../doctest/test-option-check.rs} | 2 + .../doctest/test-option-check.stdout | 6 +++ .../lints/renamed-lint-still-applies.rs | 10 ----- 28 files changed, 200 insertions(+), 20 deletions(-) rename tests/{rustdoc-html/async => rustdoc-ui/doctest}/async-move-doctest.rs (77%) create mode 100644 tests/rustdoc-ui/doctest/async-move-doctest.stdout rename tests/{rustdoc-html => rustdoc-ui/doctest}/comment-in-doctest.rs (89%) create mode 100644 tests/rustdoc-ui/doctest/comment-in-doctest.stdout rename tests/{rustdoc-html => rustdoc-ui/doctest}/demo-allocator-54478.rs (93%) create mode 100644 tests/rustdoc-ui/doctest/demo-allocator-54478.stdout rename tests/{rustdoc-html/doc-cfg => rustdoc-ui/doctest}/doc-cfg-target-feature.rs (78%) create mode 100644 tests/rustdoc-ui/doctest/doc-cfg-target-feature.stdout rename tests/{rustdoc-html => rustdoc-ui/doctest}/doc-test-attr-18199.rs (74%) create mode 100644 tests/rustdoc-ui/doctest/doc-test-attr-18199.stdout rename tests/{rustdoc-html => rustdoc-ui/doctest}/edition-doctest.rs (87%) create mode 100644 tests/rustdoc-ui/doctest/edition-doctest.stdout rename tests/{rustdoc-html => rustdoc-ui/doctest}/edition-flag.rs (63%) create mode 100644 tests/rustdoc-ui/doctest/edition-flag.stdout rename tests/{rustdoc-html => rustdoc-ui/doctest}/force-target-feature.rs (64%) create mode 100644 tests/rustdoc-ui/doctest/force-target-feature.stdout rename tests/{rustdoc-html => rustdoc-ui/doctest}/ice-type-error-19181.rs (65%) create mode 100644 tests/rustdoc-ui/doctest/ice-type-error-19181.stdout rename tests/{rustdoc-html => rustdoc-ui/doctest}/no-run-still-checks-lints.rs (55%) create mode 100644 tests/rustdoc-ui/doctest/no-run-still-checks-lints.stdout rename tests/{rustdoc-html => rustdoc-ui/doctest}/process-termination.rs (80%) create mode 100644 tests/rustdoc-ui/doctest/process-termination.stdout rename tests/{rustdoc-html => rustdoc-ui/doctest}/sanitizer-option.rs (86%) rename tests/{rustdoc-html/test_option_check/test.rs => rustdoc-ui/doctest/test-option-check-2.rs} (54%) create mode 100644 tests/rustdoc-ui/doctest/test-option-check-2.stdout rename tests/{rustdoc-html/test_option_check/bar.rs => rustdoc-ui/doctest/test-option-check.rs} (65%) create mode 100644 tests/rustdoc-ui/doctest/test-option-check.stdout delete mode 100644 tests/rustdoc-ui/lints/renamed-lint-still-applies.rs 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 78% 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..99a133a6829c5 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,7 @@ //@ only-x86_64 +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" //@ 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..d71b1032e60ec --- /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 14) ... FAILED + +failures: + +---- $DIR/doc-cfg-target-feature.rs - foo (line 14) 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:14: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::_doctest_main__home_imperio_rust_rust_tests_rustdoc_ui_doctest_doc_cfg_target_feature_rs_14_0 + 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 14) + +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 64% rename from tests/rustdoc-html/force-target-feature.rs rename to tests/rustdoc-ui/doctest/force-target-feature.rs index fa71bbeea2747..c3f9798147074 100644 --- a/tests/rustdoc-html/force-target-feature.rs +++ b/tests/rustdoc-ui/doctest/force-target-feature.rs @@ -1,6 +1,9 @@ //@ only-x86_64 //@ compile-flags:--test -C target-feature=+avx -//@ should-fail +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ 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..861a742075623 --- /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 10) ... FAILED + +failures: + +---- $DIR/force-target-feature.rs - SomeStruct (line 10) 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::_doctest_main__home_imperio_rust_rust_tests_rustdoc_ui_doctest_force_target_feature_rs_10_0 + 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 10) + +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 From 614d9ea42ce84b46371e653f882496877ce277b4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 30 Aug 2026 16:24:44 +0200 Subject: [PATCH 05/15] Fix invalid `compile-args` ui tests argument --- .../lints/renamed-lint-still-applies.stderr | 12 ++++++------ tests/ui/lint/forbid-error-capped.rs | 1 - tests/ui/lint/forbid-error-capped.stderr | 4 ++-- tests/ui/mir/issue-71793-inline-args-storage.rs | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) 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"] From 57cc38f1d6620a499e028908bd115ee94515eb70 Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Mon, 13 Jul 2026 15:33:54 +0200 Subject: [PATCH 06/15] rustdoc: add `--print` option --- compiler/rustc_driver_impl/src/lib.rs | 2 +- compiler/rustc_session/src/config.rs | 2 +- .../rustc_session/src/config/print_request.rs | 2 +- src/librustdoc/config.rs | 14 ++++-- src/librustdoc/core.rs | 2 + src/librustdoc/doctest.rs | 12 ++++- src/librustdoc/lib.rs | 49 +++++++++++++++++-- .../default-output/output-default.stdout | 2 + 8 files changed, 73 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 54a1babbaae72..ade737fe1a4a6 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_session/src/config.rs b/compiler/rustc_session/src/config.rs index bba0d8190dab7..ebbf973d334e6 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -35,7 +35,7 @@ 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::{PrintKind, PrintRequest, collect_print_requests}; use crate::diagnostics::FileWriteFail; pub use crate::options::*; use crate::search_paths::SearchPath; diff --git a/compiler/rustc_session/src/config/print_request.rs b/compiler/rustc_session/src/config/print_request.rs index 0cc805d4706cc..dee63856c2ec7 100644 --- a/compiler/rustc_session/src/config/print_request.rs +++ b/compiler/rustc_session/src/config/print_request.rs @@ -197,7 +197,7 @@ 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, diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 349fb9c0b2b08..886275ee29469 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, 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) @@ -408,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) { @@ -570,6 +574,9 @@ impl Options { Err(err) => dcx.fatal(err), }; + let prints = + collect_print_requests(early_dcx, &mut codegen_options, &unstable_opts, matches); + 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, @@ -905,6 +912,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 55eae627467a4..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()), @@ -861,6 +873,13 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { let md_input = config::markdown_input(&input); 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), @@ -868,10 +887,15 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { } 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 @@ -879,12 +903,20 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { 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), @@ -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/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, From 736a14b73f6de4dc7b08bf734c37330d3dd280ff Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Sun, 30 Aug 2026 16:41:57 +0200 Subject: [PATCH 07/15] rustdoc: test `--print` option --- .../print-crate-root-lint-levels/lib.rs | 6 + .../print-crate-root-lint-levels/rmake.rs | 124 ++++++++++++++++++ .../invalid-print-request-help.err | 5 + .../rustdoc/print-request-help/rmake.rs | 10 ++ 4 files changed, 145 insertions(+) create mode 100644 tests/run-make/rustdoc/print-crate-root-lint-levels/lib.rs create mode 100644 tests/run-make/rustdoc/print-crate-root-lint-levels/rmake.rs create mode 100644 tests/run-make/rustdoc/print-request-help/invalid-print-request-help.err create mode 100644 tests/run-make/rustdoc/print-request-help/rmake.rs 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..06842577618c8 --- /dev/null +++ b/tests/run-make/rustdoc/print-request-help/invalid-print-request-help.err @@ -0,0 +1,5 @@ +error: unknown print request: `xxx` + | + = help: valid print requests are: `all-target-specs-json`, `backend-has-mnemonic`, `backend-has-zstd`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `tls-models`, `wasm-proc-macro-tuple` + = help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information + 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(); +} From 0e6616bfc06bf505ff53bb4db51b2e9204809bd4 Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Sun, 30 Aug 2026 17:02:03 +0200 Subject: [PATCH 08/15] rustdoc: filter print kinds --- compiler/rustc_session/src/config.rs | 13 ++++- .../rustc_session/src/config/print_request.rs | 53 +++++++++++++++++-- src/librustdoc/config.rs | 11 ++-- .../invalid-print-request-help.err | 3 +- 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index ebbf973d334e6..9a0620caf1058 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, collect_print_requests}; +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; @@ -2897,7 +2900,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 dee63856c2ec7..b41ceb1699eaa 100644 --- a/compiler/rustc_session/src/config/print_request.rs +++ b/compiler/rustc_session/src/config/print_request.rs @@ -105,6 +105,15 @@ pub enum PrintKind { // 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::*; @@ -141,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 { @@ -202,6 +233,7 @@ pub fn collect_print_requests( 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") { @@ -243,12 +275,14 @@ pub 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); @@ -279,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(", "); @@ -292,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/src/librustdoc/config.rs b/src/librustdoc/config.rs index 886275ee29469..c2c58a345fa22 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -10,7 +10,7 @@ use rustc_errors::DiagCtxtHandle; use rustc_lint::Level; use rustc_session::config::{ self, CodegenOptions, ErrorOutputType, Externs, Input, JsonUnusedExterns, - OptionsTargetModifiers, OutFileName, PrintRequest, Sysroot, UnstableOptions, + 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, }; @@ -574,8 +574,13 @@ impl Options { Err(err) => dcx.fatal(err), }; - let prints = - collect_print_requests(early_dcx, &mut codegen_options, &unstable_opts, matches); + 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() { 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 index 06842577618c8..02d14190030bb 100644 --- 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 @@ -1,5 +1,4 @@ error: unknown print request: `xxx` | - = help: valid print requests are: `all-target-specs-json`, `backend-has-mnemonic`, `backend-has-zstd`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `tls-models`, `wasm-proc-macro-tuple` - = help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information + = 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` From d3a3f135a353104f5e413c1cdced76e06f73d999 Mon Sep 17 00:00:00 2001 From: "Eddy (Eduard) Stefes" Date: Tue, 25 Aug 2026 16:29:06 +0200 Subject: [PATCH 09/15] change DEFAULT_STACK_SIZE to be 17MB tests/ui/match/match-stack-overflow-72933-.rs crashes on s390x due to hitting stack_size limit. changing the size to 17MB the crash. --- compiler/rustc_interface/src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 89907447571ee..93ae0af448cac 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -122,7 +122,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 From ac1ba50024c2d56cc02a1ab8bcc26dffb992b0ca Mon Sep 17 00:00:00 2001 From: Marcelo Dominguez Date: Sat, 29 Aug 2026 12:50:18 +0300 Subject: [PATCH 10/15] Some fixes re linking and no-std --- compiler/rustc_builtin_macros/src/offload.rs | 2 +- compiler/rustc_interface/src/queries.rs | 12 ++++++ .../offload-host-std-device-nostd/example.rs | 22 ++++++++++ .../offload-host-std-device-nostd/rmake.rs | 40 +++++++++++++++++++ tests/ui/offload/duplicate_kernel.rs | 4 +- tests/ui/offload/non_tuple_args.rs | 4 +- tests/ui/offload/non_tuple_args.stderr | 7 ++-- 7 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 tests/run-make/offload-host-std-device-nostd/example.rs create mode 100644 tests/run-make/offload-host-std-device-nostd/rmake.rs diff --git a/compiler/rustc_builtin_macros/src/offload.rs b/compiler/rustc_builtin_macros/src/offload.rs index 006332b8c40c9..c8efdf016c99e 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_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/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/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 From 5698c8d51522a3a3794df756f86576f03416bd41 Mon Sep 17 00:00:00 2001 From: Marcelo Dominguez Date: Tue, 1 Sep 2026 12:59:14 +0300 Subject: [PATCH 11/15] Move run-make tests to offload folder --- .../generic-manifest}/generic.rs | 0 .../generic-manifest}/rmake.rs | 0 .../host-std-device-nostd}/example.rs | 0 .../host-std-device-nostd}/rmake.rs | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename tests/run-make/{offload-generic-manifest => offload/generic-manifest}/generic.rs (100%) rename tests/run-make/{offload-generic-manifest => offload/generic-manifest}/rmake.rs (100%) rename tests/run-make/{offload-host-std-device-nostd => offload/host-std-device-nostd}/example.rs (100%) rename tests/run-make/{offload-host-std-device-nostd => offload/host-std-device-nostd}/rmake.rs (100%) 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 similarity index 100% rename from tests/run-make/offload-host-std-device-nostd/example.rs rename to tests/run-make/offload/host-std-device-nostd/example.rs diff --git a/tests/run-make/offload-host-std-device-nostd/rmake.rs b/tests/run-make/offload/host-std-device-nostd/rmake.rs similarity index 100% rename from tests/run-make/offload-host-std-device-nostd/rmake.rs rename to tests/run-make/offload/host-std-device-nostd/rmake.rs From 80dc5df240ffbd0addc5cf73e9dfd136b4c70e5a Mon Sep 17 00:00:00 2001 From: Robert Bastian <4706271+robertbastian@users.noreply.github.com> Date: Tue, 18 Aug 2026 13:18:15 +0200 Subject: [PATCH 12/15] Update icu_list to 2.3 --- Cargo.lock | 73 +++++++++---------- compiler/rustc_baked_icu_data/Cargo.toml | 6 +- .../src/data/list_and_v1.rs.data | 12 +-- compiler/rustc_baked_icu_data/src/data/mod.rs | 4 +- compiler/rustc_baked_icu_data/src/lib.rs | 23 +++--- compiler/rustc_error_messages/Cargo.toml | 4 +- compiler/rustc_error_messages/src/lib.rs | 4 +- src/tools/tidy/src/deps.rs | 6 +- 8 files changed, 66 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a00c6c397962a..78f3b4bae7139 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1811,9 +1811,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", @@ -1823,39 +1823,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" @@ -1899,9 +1898,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", @@ -3696,7 +3695,7 @@ name = "rustc_baked_icu_data" version = "0.0.0" dependencies = [ "icu_list", - "icu_locale", + "icu_locale_fallback", "icu_provider", "zerovec", ] @@ -3961,7 +3960,7 @@ version = "0.0.0" dependencies = [ "fluent-bundle", "icu_list", - "icu_locale", + "icu_locale_core", "intl-memoizer", "rustc_baked_icu_data", "rustc_data_structures", @@ -5688,9 +5687,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", @@ -6830,9 +6829,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" @@ -6859,9 +6858,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", @@ -6923,9 +6922,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", @@ -6935,9 +6934,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", @@ -6947,13 +6946,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_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_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/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 721dcb851035a..8d9262f9f9221 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", From bf27a5a38b600acb54b5b2935491b78513ba0018 Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Tue, 1 Sep 2026 14:02:19 +0200 Subject: [PATCH 13/15] rustdoc: add tests for Markdown files --- .../run-make/rustdoc/doctest/markdown/bad.md | 9 +++++ .../rustdoc/doctest/markdown/extadd.rs | 3 ++ .../rustdoc/doctest/markdown/extern.md | 7 ++++ .../run-make/rustdoc/doctest/markdown/good.md | 23 +++++++++++++ .../rustdoc/doctest/markdown/rmake.rs | 34 +++++++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 tests/run-make/rustdoc/doctest/markdown/bad.md create mode 100644 tests/run-make/rustdoc/doctest/markdown/extadd.rs create mode 100644 tests/run-make/rustdoc/doctest/markdown/extern.md create mode 100644 tests/run-make/rustdoc/doctest/markdown/good.md create mode 100644 tests/run-make/rustdoc/doctest/markdown/rmake.rs 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;", + ); +} From 5ba810f06513b45387f1ed249a49b3ed75c8f47f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 1 Sep 2026 14:18:42 +0200 Subject: [PATCH 14/15] Normalize more rustdoc-ui doctest output --- tests/rustdoc-ui/doctest/doc-cfg-target-feature.rs | 1 + tests/rustdoc-ui/doctest/doc-cfg-target-feature.stdout | 10 +++++----- tests/rustdoc-ui/doctest/force-target-feature.rs | 1 + tests/rustdoc-ui/doctest/force-target-feature.stdout | 8 ++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/rustdoc-ui/doctest/doc-cfg-target-feature.rs b/tests/rustdoc-ui/doctest/doc-cfg-target-feature.rs index 99a133a6829c5..a55b31d61e3d0 100644 --- a/tests/rustdoc-ui/doctest/doc-cfg-target-feature.rs +++ b/tests/rustdoc-ui/doctest/doc-cfg-target-feature.rs @@ -1,5 +1,6 @@ //@ 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 //@ failure-status: 101 diff --git a/tests/rustdoc-ui/doctest/doc-cfg-target-feature.stdout b/tests/rustdoc-ui/doctest/doc-cfg-target-feature.stdout index d71b1032e60ec..6526e9898dd2f 100644 --- a/tests/rustdoc-ui/doctest/doc-cfg-target-feature.stdout +++ b/tests/rustdoc-ui/doctest/doc-cfg-target-feature.stdout @@ -1,12 +1,12 @@ running 1 test -test $DIR/doc-cfg-target-feature.rs - foo (line 14) ... FAILED +test $DIR/doc-cfg-target-feature.rs - foo (line 15) ... FAILED failures: ----- $DIR/doc-cfg-target-feature.rs - foo (line 14) stdout ---- +---- $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:14:12 + --> $DIR/doc-cfg-target-feature.rs:15:12 | LL | #![feature(cfg_target_feature)] | ^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ stack backtrace: 0: __rustc::rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic - 3: rust_out::main::_doctest_main__home_imperio_rust_rust_tests_rustdoc_ui_doctest_doc_cfg_target_feature_rs_14_0 + 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. @@ -33,7 +33,7 @@ note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose bac failures: - $DIR/doc-cfg-target-feature.rs - foo (line 14) + $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-ui/doctest/force-target-feature.rs b/tests/rustdoc-ui/doctest/force-target-feature.rs index c3f9798147074..f39e7cf3a9094 100644 --- a/tests/rustdoc-ui/doctest/force-target-feature.rs +++ b/tests/rustdoc-ui/doctest/force-target-feature.rs @@ -1,6 +1,7 @@ //@ only-x86_64 //@ compile-flags:--test -C target-feature=+avx //@ 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)] diff --git a/tests/rustdoc-ui/doctest/force-target-feature.stdout b/tests/rustdoc-ui/doctest/force-target-feature.stdout index 861a742075623..fb898dd14b2c9 100644 --- a/tests/rustdoc-ui/doctest/force-target-feature.stdout +++ b/tests/rustdoc-ui/doctest/force-target-feature.stdout @@ -1,10 +1,10 @@ running 1 test -test $DIR/force-target-feature.rs - SomeStruct (line 10) ... FAILED +test $DIR/force-target-feature.rs - SomeStruct (line 11) ... FAILED failures: ----- $DIR/force-target-feature.rs - SomeStruct (line 10) stdout ---- +---- $DIR/force-target-feature.rs - SomeStruct (line 11) stdout ---- Test executable failed (exit status: 101). stderr: @@ -13,7 +13,7 @@ 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::_doctest_main__home_imperio_rust_rust_tests_rustdoc_ui_doctest_force_target_feature_rs_10_0 + 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. @@ -21,7 +21,7 @@ note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose bac failures: - $DIR/force-target-feature.rs - SomeStruct (line 10) + $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 From 7a02fd9f271adfb948158b13a965daee562bd73b Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Mon, 31 Aug 2026 22:02:33 +0200 Subject: [PATCH 15/15] Remove `gate_check` from `AttributeStability::Unstable` --- compiler/rustc_attr_parsing/src/stability.rs | 13 +++++++------ compiler/rustc_feature/src/builtin_attrs.rs | 3 --- 2 files changed, 7 insertions(+), 9 deletions(-) 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_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],