diff options
| author | Ben Kimock <kimockb@gmail.com> | 2025-01-24 05:28:23 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-24 05:28:23 +0000 |
| commit | f8f5c9d64297f34a260abd882f752153e85102f3 (patch) | |
| tree | 6100914717d811f3627524c0f79d4b4e8814613b /src | |
| parent | e923d85be4a6ea0e4a1668ed01b27dabbbe76d68 (diff) | |
| parent | d22ba488f066532993592e01417f2612c3dbf3b3 (diff) | |
| download | rust-f8f5c9d64297f34a260abd882f752153e85102f3.tar.gz rust-f8f5c9d64297f34a260abd882f752153e85102f3.zip | |
Merge pull request #4147 from rust-lang/rustup-2025-01-24
Automatic Rustup
Diffstat (limited to 'src')
25 files changed, 227 insertions, 303 deletions
diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index cf55fff4078..3cf25373b89 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -1338,7 +1338,7 @@ impl Step for CrtBeginEnd { .file(crtbegin_src) .file(crtend_src); - // Those flags are defined in src/llvm-project/compiler-rt/lib/crt/CMakeLists.txt + // Those flags are defined in src/llvm-project/compiler-rt/lib/builtins/CMakeLists.txt // Currently only consumer of those objects is musl, which use .init_array/.fini_array // instead of .ctors/.dtors cfg.flag("-std=c11") diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 9f3e4d9cc89..0d3ab6ad97d 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -87,7 +87,7 @@ impl Step for CrateBootstrap { &[], ); let crate_name = path.rsplit_once('/').unwrap().1; - run_cargo_test(cargo, &[], &[], crate_name, crate_name, compiler, bootstrap_host, builder); + run_cargo_test(cargo, &[], &[], crate_name, crate_name, bootstrap_host, builder); } } @@ -143,7 +143,6 @@ You can skip linkcheck with --skip src/tools/linkchecker" &[], "linkchecker", "linkchecker self tests", - compiler, bootstrap_host, builder, ); @@ -312,7 +311,7 @@ impl Step for Cargo { ); // NOTE: can't use `run_cargo_test` because we need to overwrite `PATH` - let mut cargo = prepare_cargo_test(cargo, &[], &[], "cargo", compiler, self.host, builder); + let mut cargo = prepare_cargo_test(cargo, &[], &[], "cargo", self.host, builder); // Don't run cross-compile tests, we may not have cross-compiled libstd libs // available. @@ -397,7 +396,7 @@ impl Step for RustAnalyzer { cargo.env("SKIP_SLOW_TESTS", "1"); cargo.add_rustc_lib_path(builder); - run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", compiler, host, builder); + run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", host, builder); } } @@ -445,7 +444,7 @@ impl Step for Rustfmt { cargo.add_rustc_lib_path(builder); - run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", compiler, host, builder); + run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", host, builder); } } @@ -565,7 +564,7 @@ impl Step for Miri { // We can NOT use `run_cargo_test` since Miri's integration tests do not use the usual test // harness and therefore do not understand the flags added by `add_flags_and_try_run_test`. - let mut cargo = prepare_cargo_test(cargo, &[], &[], "miri", host_compiler, host, builder); + let mut cargo = prepare_cargo_test(cargo, &[], &[], "miri", host, builder); // miri tests need to know about the stage sysroot cargo.env("MIRI_SYSROOT", &miri_sysroot); @@ -713,16 +712,7 @@ impl Step for CompiletestTest { &[], ); cargo.allow_features("test"); - run_cargo_test( - cargo, - &[], - &[], - "compiletest", - "compiletest self test", - compiler, - host, - builder, - ); + run_cargo_test(cargo, &[], &[], "compiletest", "compiletest self test", host, builder); } } @@ -769,7 +759,7 @@ impl Step for Clippy { cargo.env("HOST_LIBS", host_libs); cargo.add_rustc_lib_path(builder); - let cargo = prepare_cargo_test(cargo, &[], &[], "clippy", compiler, host, builder); + let cargo = prepare_cargo_test(cargo, &[], &[], "clippy", host, builder); let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host); @@ -1294,7 +1284,6 @@ impl Step for CrateRunMakeSupport { &[], "run-make-support", "run-make-support self test", - compiler, host, builder, ); @@ -1334,16 +1323,7 @@ impl Step for CrateBuildHelper { &[], ); cargo.allow_features("test"); - run_cargo_test( - cargo, - &[], - &[], - "build_helper", - "build_helper self test", - compiler, - host, - builder, - ); + run_cargo_test(cargo, &[], &[], "build_helper", "build_helper self test", host, builder); } } @@ -2540,19 +2520,17 @@ impl Step for CrateLibrustc { /// Given a `cargo test` subcommand, add the appropriate flags and run it. /// /// Returns whether the test succeeded. -#[allow(clippy::too_many_arguments)] // FIXME: reduce the number of args and remove this. fn run_cargo_test<'a>( - cargo: impl Into<BootstrapCommand>, + cargo: builder::Cargo, libtest_args: &[&str], crates: &[String], primary_crate: &str, description: impl Into<Option<&'a str>>, - compiler: Compiler, target: TargetSelection, builder: &Builder<'_>, ) -> bool { - let mut cargo = - prepare_cargo_test(cargo, libtest_args, crates, primary_crate, compiler, target, builder); + let compiler = cargo.compiler(); + let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, primary_crate, target, builder); let _time = helpers::timeit(builder); let _group = description.into().and_then(|what| { builder.msg_sysroot_tool(Kind::Test, compiler.stage, what, compiler.host, target) @@ -2573,15 +2551,15 @@ fn run_cargo_test<'a>( /// Given a `cargo test` subcommand, pass it the appropriate test flags given a `builder`. fn prepare_cargo_test( - cargo: impl Into<BootstrapCommand>, + cargo: builder::Cargo, libtest_args: &[&str], crates: &[String], primary_crate: &str, - compiler: Compiler, target: TargetSelection, builder: &Builder<'_>, ) -> BootstrapCommand { - let mut cargo = cargo.into(); + let compiler = cargo.compiler(); + let mut cargo: BootstrapCommand = cargo.into(); // Propagate `--bless` if it has not already been set/unset // Any tools that want to use this should bless if `RUSTC_BLESS` is set to @@ -2793,7 +2771,6 @@ impl Step for Crate { &self.crates, &self.crates[0], &*crate_description(&self.crates), - compiler, target, builder, ); @@ -2895,7 +2872,6 @@ impl Step for CrateRustdoc { &["rustdoc:0.0.0".to_string()], "rustdoc", "rustdoc", - compiler, target, builder, ); @@ -2956,7 +2932,6 @@ impl Step for CrateRustdocJsonTypes { &["rustdoc-json-types".to_string()], "rustdoc-json-types", "rustdoc-json-types", - compiler, target, builder, ); @@ -3113,23 +3088,25 @@ impl Step for Bootstrap { // Use `python -m unittest` manually if you want to pass arguments. check_bootstrap.delay_failure().run(builder); - let mut cmd = command(&builder.initial_cargo); - cmd.arg("test") - .current_dir(builder.src.join("src/bootstrap")) - .env("RUSTFLAGS", "--cfg test -Cdebuginfo=2") + let mut cargo = tool::prepare_tool_cargo( + builder, + compiler, + Mode::ToolBootstrap, + host, + Kind::Test, + "src/bootstrap", + SourceType::InTree, + &[], + ); + + cargo + .rustflag("-Cdebuginfo=2") .env("CARGO_TARGET_DIR", builder.out.join("bootstrap")) - .env("RUSTC_BOOTSTRAP", "1") - .env("RUSTDOC", builder.rustdoc(compiler)) - .env("RUSTC", &builder.initial_rustc); - if let Some(flags) = option_env!("RUSTFLAGS") { - // Use the same rustc flags for testing as for "normal" compilation, - // so that Cargo doesn’t recompile the entire dependency graph every time: - // https://github.com/rust-lang/rust/issues/49215 - cmd.env("RUSTFLAGS", flags); - } + .env("RUSTC_BOOTSTRAP", "1"); + // bootstrap tests are racy on directory creation so just run them one at a time. // Since there's not many this shouldn't be a problem. - run_cargo_test(cmd, &["--test-threads=1"], &[], "bootstrap", None, compiler, host, builder); + run_cargo_test(cargo, &["--test-threads=1"], &[], "bootstrap", None, host, builder); } fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { @@ -3254,7 +3231,7 @@ impl Step for RustInstaller { bootstrap_host, bootstrap_host, ); - run_cargo_test(cargo, &[], &[], "installer", None, compiler, bootstrap_host, builder); + run_cargo_test(cargo, &[], &[], "installer", None, bootstrap_host, builder); // We currently don't support running the test.sh script outside linux(?) environments. // Eventually this should likely migrate to #[test]s in rust-installer proper rather than a @@ -3639,16 +3616,7 @@ impl Step for TestFloatParse { &[], ); - run_cargo_test( - cargo_test, - &[], - &[], - crate_name, - crate_name, - compiler, - bootstrap_host, - builder, - ); + run_cargo_test(cargo_test, &[], &[], crate_name, crate_name, bootstrap_host, builder); // Run the actual parse tests. let mut cargo_run = tool::prepare_tool_cargo( diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index f9fb19ddb09..6b792108784 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -121,6 +121,10 @@ impl Cargo { cargo } + pub fn compiler(&self) -> Compiler { + self.compiler + } + pub fn into_cmd(self) -> BootstrapCommand { self.into() } diff --git a/src/bootstrap/src/core/config/tests.rs b/src/bootstrap/src/core/config/tests.rs index c5e578ff351..f0a185ee3a7 100644 --- a/src/bootstrap/src/core/config/tests.rs +++ b/src/bootstrap/src/core/config/tests.rs @@ -92,7 +92,7 @@ fn detect_src_and_out() { // `{build-dir}/bootstrap/debug/deps/bootstrap-c7ee91d5661e2804` // `{build-dir}` can be anywhere, not just in the rust project directory. let dep = Path::new(args.first().unwrap()); - let expected_out = dep.ancestors().nth(4).unwrap(); + let expected_out = dep.ancestors().nth(5).unwrap(); assert_eq!(&cfg.out, expected_out); } diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index c5b33a45db7..5e95e3721df 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -48,6 +48,8 @@ runners: <<: *base-job - &job-aarch64-linux + # Free some disk space to avoid running out of space during the build. + free_disk: true os: ubuntu-22.04-arm envs: diff --git a/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs b/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs index 576bbcea965..8983915d78a 100644 --- a/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs +++ b/src/doc/rustc-dev-guide/examples/rustc-driver-example.rs @@ -18,8 +18,8 @@ use std::path::Path; use rustc_ast_pretty::pprust::item_to_string; use rustc_data_structures::sync::Lrc; -use rustc_driver::{Compilation, RunCompiler}; -use rustc_interface::interface::Compiler; +use rustc_driver::{Compilation, run_compiler}; +use rustc_interface::interface::{Compiler, Config}; use rustc_middle::ty::TyCtxt; struct MyFileLoader; @@ -51,6 +51,10 @@ fn main() { struct MyCallbacks; impl rustc_driver::Callbacks for MyCallbacks { + fn config(&mut self, config: &mut Config) { + config.file_loader = Some(Box::new(MyFileLoader)); + } + fn after_crate_root_parsing( &mut self, _compiler: &Compiler, @@ -83,10 +87,5 @@ impl rustc_driver::Callbacks for MyCallbacks { } fn main() { - match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) { - mut compiler => { - compiler.set_file_loader(Some(Box::new(MyFileLoader))); - compiler.run(); - } - } + run_compiler(&["main.rs".to_string()], &mut MyCallbacks); } diff --git a/src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs b/src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs index 90a85d5db21..c894b60444a 100644 --- a/src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs +++ b/src/doc/rustc-dev-guide/examples/rustc-driver-interacting-with-the-ast.rs @@ -18,8 +18,8 @@ use std::path::Path; use rustc_ast_pretty::pprust::item_to_string; use rustc_data_structures::sync::Lrc; -use rustc_driver::{Compilation, RunCompiler}; -use rustc_interface::interface::Compiler; +use rustc_driver::{Compilation, run_compiler}; +use rustc_interface::interface::{Compiler, Config}; use rustc_middle::ty::TyCtxt; struct MyFileLoader; @@ -51,6 +51,10 @@ fn main() { struct MyCallbacks; impl rustc_driver::Callbacks for MyCallbacks { + fn config(&mut self, config: &mut Config) { + config.file_loader = Some(Box::new(MyFileLoader)); + } + fn after_crate_root_parsing( &mut self, _compiler: &Compiler, @@ -90,10 +94,5 @@ impl rustc_driver::Callbacks for MyCallbacks { } fn main() { - match RunCompiler::new(&["main.rs".to_string()], &mut MyCallbacks) { - mut compiler => { - compiler.set_file_loader(Some(Box::new(MyFileLoader))); - compiler.run(); - } - } + run_compiler(&["main.rs".to_string()], &mut MyCallbacks); } diff --git a/src/doc/rustc-dev-guide/src/rustc-driver/intro.md b/src/doc/rustc-dev-guide/src/rustc-driver/intro.md index a6234dc129f..40500e6bc7a 100644 --- a/src/doc/rustc-dev-guide/src/rustc-driver/intro.md +++ b/src/doc/rustc-dev-guide/src/rustc-driver/intro.md @@ -6,7 +6,7 @@ The [`rustc_driver`] is essentially `rustc`'s `main` function. It acts as the glue for running the various phases of the compiler in the correct order, using the interface defined in the [`rustc_interface`] crate. Where possible, using [`rustc_driver`] rather than [`rustc_interface`] is recommended. -The main entry point of [`rustc_driver`] is [`rustc_driver::RunCompiler`][rd_rc]. +The main entry point of [`rustc_driver`] is [`rustc_driver::run_compiler`][rd_rc]. This builder accepts the same command-line args as rustc as well as an implementation of [`Callbacks`][cb] and a couple of other optional options. [`Callbacks`][cb] is a `trait` that allows for custom compiler configuration, as well as allowing custom code to run after different phases of the compilation. @@ -40,7 +40,7 @@ specifically [`rustc_driver_impl::run_compiler`][rdi_rc] [cb]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/trait.Callbacks.html [example]: https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-interface-example.rs [i_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/fn.run_compiler.html -[rd_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/struct.RunCompiler.html +[rd_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/fn.run_compiler.html [rdi_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver_impl/fn.run_compiler.html [stupid-stats]: https://github.com/nrc/stupid-stats [`nightly-rustc`]: https://doc.rust-lang.org/nightly/nightly-rustc/ diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index bfa789b1f39..bdd44b4a993 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -389,6 +389,49 @@ fn write_with_opt_paren<T: fmt::Display>( Ok(()) } +impl Display<'_> { + fn display_sub_cfgs( + &self, + fmt: &mut fmt::Formatter<'_>, + sub_cfgs: &[Cfg], + separator: &str, + ) -> fmt::Result { + let short_longhand = self.1.is_long() && { + let all_crate_features = + sub_cfgs.iter().all(|sub_cfg| matches!(sub_cfg, Cfg::Cfg(sym::feature, Some(_)))); + let all_target_features = sub_cfgs + .iter() + .all(|sub_cfg| matches!(sub_cfg, Cfg::Cfg(sym::target_feature, Some(_)))); + + if all_crate_features { + fmt.write_str("crate features ")?; + true + } else if all_target_features { + fmt.write_str("target features ")?; + true + } else { + false + } + }; + + for (i, sub_cfg) in sub_cfgs.iter().enumerate() { + if i != 0 { + fmt.write_str(separator)?; + } + if let (true, Cfg::Cfg(_, Some(feat))) = (short_longhand, sub_cfg) { + if self.1.is_html() { + write!(fmt, "<code>{feat}</code>")?; + } else { + write!(fmt, "`{feat}`")?; + } + } else { + write_with_opt_paren(fmt, !sub_cfg.is_all(), Display(sub_cfg, self.1))?; + } + } + Ok(()) + } +} + impl fmt::Display for Display<'_> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match *self.0 { @@ -408,79 +451,9 @@ impl fmt::Display for Display<'_> { Cfg::Any(ref sub_cfgs) => { let separator = if sub_cfgs.iter().all(Cfg::is_simple) { " or " } else { ", or " }; - - let short_longhand = self.1.is_long() && { - let all_crate_features = sub_cfgs - .iter() - .all(|sub_cfg| matches!(sub_cfg, Cfg::Cfg(sym::feature, Some(_)))); - let all_target_features = sub_cfgs - .iter() - .all(|sub_cfg| matches!(sub_cfg, Cfg::Cfg(sym::target_feature, Some(_)))); - - if all_crate_features { - fmt.write_str("crate features ")?; - true - } else if all_target_features { - fmt.write_str("target features ")?; - true - } else { - false - } - }; - - for (i, sub_cfg) in sub_cfgs.iter().enumerate() { - if i != 0 { - fmt.write_str(separator)?; - } - if let (true, Cfg::Cfg(_, Some(feat))) = (short_longhand, sub_cfg) { - if self.1.is_html() { - write!(fmt, "<code>{feat}</code>")?; - } else { - write!(fmt, "`{feat}`")?; - } - } else { - write_with_opt_paren(fmt, !sub_cfg.is_all(), Display(sub_cfg, self.1))?; - } - } - Ok(()) - } - - Cfg::All(ref sub_cfgs) => { - let short_longhand = self.1.is_long() && { - let all_crate_features = sub_cfgs - .iter() - .all(|sub_cfg| matches!(sub_cfg, Cfg::Cfg(sym::feature, Some(_)))); - let all_target_features = sub_cfgs - .iter() - .all(|sub_cfg| matches!(sub_cfg, Cfg::Cfg(sym::target_feature, Some(_)))); - - if all_crate_features { - fmt.write_str("crate features ")?; - true - } else if all_target_features { - fmt.write_str("target features ")?; - true - } else { - false - } - }; - - for (i, sub_cfg) in sub_cfgs.iter().enumerate() { - if i != 0 { - fmt.write_str(" and ")?; - } - if let (true, Cfg::Cfg(_, Some(feat))) = (short_longhand, sub_cfg) { - if self.1.is_html() { - write!(fmt, "<code>{feat}</code>")?; - } else { - write!(fmt, "`{feat}`")?; - } - } else { - write_with_opt_paren(fmt, !sub_cfg.is_simple(), Display(sub_cfg, self.1))?; - } - } - Ok(()) + self.display_sub_cfgs(fmt, sub_cfgs, separator) } + Cfg::All(ref sub_cfgs) => self.display_sub_cfgs(fmt, sub_cfgs, " and "), Cfg::True => fmt.write_str("everywhere"), Cfg::False => fmt.write_str("nowhere"), diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 0dda3466a71..ad67c2ba245 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -1,10 +1,10 @@ -use std::sync::atomic::AtomicBool; -use std::sync::{Arc, LazyLock}; +use std::sync::LazyLock; use std::{io, mem}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::sync::Lrc; use rustc_data_structures::unord::UnordSet; +use rustc_driver::USING_INTERNAL_FEATURES; use rustc_errors::TerminalUrl; use rustc_errors::codes::*; use rustc_errors::emitter::{ @@ -221,7 +221,6 @@ pub(crate) fn create_config( .. }: RustdocOptions, RenderOptions { document_private, .. }: &RenderOptions, - using_internal_features: Arc<AtomicBool>, ) -> rustc_interface::Config { // Add the doc cfg into the doc build. cfgs.push("doc".to_string()); @@ -316,7 +315,7 @@ pub(crate) fn create_config( make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), ice_file: None, - using_internal_features, + using_internal_features: &USING_INTERNAL_FEATURES, expanded_args, } } diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 009e9662933..8c3e28ecec3 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -193,7 +193,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), ice_file: None, - using_internal_features: Arc::default(), + using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES, expanded_args: options.expanded_args.clone(), }; diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 92935c72b47..20a8dc72491 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -150,8 +150,9 @@ pub(crate) fn comma_sep<T: Display>( items: impl Iterator<Item = T>, space_after_comma: bool, ) -> impl Display { - display_fn(move |f| { - for (i, item) in items.enumerate() { + let items = Cell::new(Some(items)); + fmt::from_fn(move |f| { + for (i, item) in items.take().unwrap().enumerate() { if i != 0 { write!(f, ",{}", if space_after_comma { " " } else { "" })?; } @@ -165,7 +166,7 @@ pub(crate) fn print_generic_bounds<'a, 'tcx: 'a>( bounds: &'a [clean::GenericBound], cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let mut bounds_dup = FxHashSet::default(); for (i, bound) in bounds.iter().filter(|b| bounds_dup.insert(*b)).enumerate() { @@ -183,7 +184,7 @@ impl clean::GenericParamDef { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| match &self.kind { + fmt::from_fn(move |f| match &self.kind { clean::GenericParamDefKind::Lifetime { outlives } => { write!(f, "{}", self.name)?; @@ -238,7 +239,7 @@ impl clean::Generics { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let mut real_params = self.params.iter().filter(|p| !p.is_synthetic_param()).peekable(); if real_params.peek().is_none() { return Ok(()); @@ -268,12 +269,12 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>( indent: usize, ending: Ending, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let mut where_predicates = gens .where_predicates .iter() .map(|pred| { - display_fn(move |f| { + fmt::from_fn(move |f| { if f.alternate() { f.write_str(" ")?; } else { @@ -376,17 +377,15 @@ impl clean::Lifetime { impl clean::ConstantKind { pub(crate) fn print(&self, tcx: TyCtxt<'_>) -> impl Display + '_ { let expr = self.expr(tcx); - display_fn( - move |f| { - if f.alternate() { f.write_str(&expr) } else { write!(f, "{}", Escape(&expr)) } - }, - ) + fmt::from_fn(move |f| { + if f.alternate() { f.write_str(&expr) } else { write!(f, "{}", Escape(&expr)) } + }) } } impl clean::PolyTrait { fn print<'a, 'tcx: 'a>(&'a self, cx: &'a Context<'tcx>) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { print_higher_ranked_params_with_space(&self.generic_params, cx, "for").fmt(f)?; self.trait_.print(cx).fmt(f) }) @@ -398,7 +397,7 @@ impl clean::GenericBound { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| match self { + fmt::from_fn(move |f| match self { clean::GenericBound::Outlives(lt) => write!(f, "{}", lt.print()), clean::GenericBound::TraitBound(ty, modifiers) => { // `const` and `~const` trait bounds are experimental; don't render them. @@ -430,7 +429,7 @@ impl clean::GenericBound { impl clean::GenericArgs { fn print<'a, 'tcx: 'a>(&'a self, cx: &'a Context<'tcx>) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { match self { clean::GenericArgs::AngleBracketed { args, constraints } => { if !args.is_empty() || !constraints.is_empty() { @@ -950,7 +949,7 @@ fn tybounds<'a, 'tcx: 'a>( lt: &'a Option<clean::Lifetime>, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { for (i, bound) in bounds.iter().enumerate() { if i > 0 { write!(f, " + ")?; @@ -971,7 +970,7 @@ fn print_higher_ranked_params_with_space<'a, 'tcx: 'a>( cx: &'a Context<'tcx>, keyword: &'static str, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { if !params.is_empty() { f.write_str(keyword)?; f.write_str(if f.alternate() { "<" } else { "<" })?; @@ -982,13 +981,13 @@ fn print_higher_ranked_params_with_space<'a, 'tcx: 'a>( }) } -pub(crate) fn anchor<'a, 'cx: 'a>( +pub(crate) fn anchor<'a: 'cx, 'cx>( did: DefId, text: Symbol, - cx: &'cx Context<'_>, -) -> impl Display + 'a { - let parts = href(did, cx); - display_fn(move |f| { + cx: &'cx Context<'a>, +) -> impl Display + Captures<'a> + 'cx { + fmt::from_fn(move |f| { + let parts = href(did, cx); if let Ok((url, short_ty, fqp)) = parts { write!( f, @@ -1150,7 +1149,7 @@ fn fmt_type( } } clean::BorrowedRef { lifetime: ref l, mutability, type_: ref ty } => { - let lt = display_fn(|f| match l { + let lt = fmt::from_fn(|f| match l { Some(l) => write!(f, "{} ", l.print()), _ => Ok(()), }); @@ -1270,7 +1269,7 @@ impl clean::Type { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'b + Captures<'tcx> { - display_fn(move |f| fmt_type(self, f, false, cx)) + fmt::from_fn(move |f| fmt_type(self, f, false, cx)) } } @@ -1279,7 +1278,7 @@ impl clean::Path { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'b + Captures<'tcx> { - display_fn(move |f| resolved_path(f, self.def_id(), self, false, false, cx)) + fmt::from_fn(move |f| resolved_path(f, self.def_id(), self, false, false, cx)) } } @@ -1289,7 +1288,7 @@ impl clean::Impl { use_absolute: bool, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { f.write_str("impl")?; self.generics.print(cx).fmt(f)?; f.write_str(" ")?; @@ -1407,7 +1406,7 @@ impl clean::Arguments { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { for (i, input) in self.values.iter().enumerate() { write!(f, "{}: ", input.name)?; input.type_.print(cx).fmt(f)?; @@ -1447,7 +1446,7 @@ impl clean::FnDecl { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'b + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let ellipsis = if self.c_variadic { ", ..." } else { "" }; if f.alternate() { write!( @@ -1481,10 +1480,10 @@ impl clean::FnDecl { indent: usize, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { // First, generate the text form of the declaration, with no line wrapping, and count the bytes. let mut counter = WriteCounter(0); - write!(&mut counter, "{:#}", display_fn(|f| { self.inner_full_print(None, f, cx) })) + write!(&mut counter, "{:#}", fmt::from_fn(|f| { self.inner_full_print(None, f, cx) })) .unwrap(); // If the text form was over 80 characters wide, we will line-wrap our output. let line_wrapping_indent = @@ -1566,7 +1565,7 @@ impl clean::FnDecl { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| match &self.output { + fmt::from_fn(move |f| match &self.output { clean::Tuple(tys) if tys.is_empty() => Ok(()), ty if f.alternate() => { write!(f, " -> {:#}", ty.print(cx)) @@ -1618,7 +1617,7 @@ pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>( }; let is_doc_hidden = item.is_doc_hidden(); - display_fn(move |f| { + fmt::from_fn(move |f| { if is_doc_hidden { f.write_str("#[doc(hidden)] ")?; } @@ -1692,7 +1691,7 @@ impl clean::Import { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| match self.kind { + fmt::from_fn(move |f| match self.kind { clean::ImportKind::Simple(name) => { if name == self.source.path.last() { write!(f, "use {};", self.source.print(cx)) @@ -1716,7 +1715,7 @@ impl clean::ImportSource { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| match self.did { + fmt::from_fn(move |f| match self.did { Some(did) => resolved_path(f, did, &self.path, true, false, cx), _ => { for seg in &self.path.segments[..self.path.segments.len() - 1] { @@ -1744,7 +1743,7 @@ impl clean::AssocItemConstraint { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { f.write_str(self.assoc.name.as_str())?; self.assoc.args.print(cx).fmt(f)?; match self.kind { @@ -1765,7 +1764,7 @@ impl clean::AssocItemConstraint { } pub(crate) fn print_abi_with_space(abi: ExternAbi) -> impl Display { - display_fn(move |f| { + fmt::from_fn(move |f| { let quot = if f.alternate() { "\"" } else { """ }; match abi { ExternAbi::Rust => Ok(()), @@ -1783,7 +1782,7 @@ impl clean::GenericArg { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| match self { + fmt::from_fn(move |f| match self { clean::GenericArg::Lifetime(lt) => lt.print().fmt(f), clean::GenericArg::Type(ty) => ty.print(cx).fmt(f), clean::GenericArg::Const(ct) => ct.print(cx.tcx()).fmt(f), @@ -1797,24 +1796,9 @@ impl clean::Term { &'a self, cx: &'a Context<'tcx>, ) -> impl Display + 'a + Captures<'tcx> { - display_fn(move |f| match self { + fmt::from_fn(move |f| match self { clean::Term::Type(ty) => ty.print(cx).fmt(f), clean::Term::Constant(ct) => ct.print(cx.tcx()).fmt(f), }) } } - -pub(crate) fn display_fn(f: impl FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl Display { - struct WithFormatter<F>(Cell<Option<F>>); - - impl<F> Display for WithFormatter<F> - where - F: FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result, - { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - (self.0.take()).unwrap()(f) - } - } - - WithFormatter(Cell::new(Some(f))) -} diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 62cf2b63f7f..7b2aee4b4a5 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -233,7 +233,7 @@ pub(super) fn write_code( out: &mut impl Write, src: &str, href_context: Option<HrefContext<'_, '_>>, - decoration_info: Option<DecorationInfo>, + decoration_info: Option<&DecorationInfo>, ) { // This replace allows to fix how the code source with DOS backline characters is displayed. let src = src.replace("\r\n", "\n"); @@ -510,12 +510,12 @@ struct Decorations { } impl Decorations { - fn new(info: DecorationInfo) -> Self { + fn new(info: &DecorationInfo) -> Self { // Extract tuples (start, end, kind) into separate sequences of (start, kind) and (end). let (mut starts, mut ends): (Vec<_>, Vec<_>) = info .0 - .into_iter() - .flat_map(|(kind, ranges)| ranges.into_iter().map(move |(lo, hi)| ((lo, kind), hi))) + .iter() + .flat_map(|(&kind, ranges)| ranges.into_iter().map(move |&(lo, hi)| ((lo, kind), hi))) .unzip(); // Sort the sequences in document order. @@ -542,7 +542,7 @@ struct Classifier<'src> { impl<'src> Classifier<'src> { /// Takes as argument the source code to HTML-ify, the rust edition to use and the source code /// file span which will be used later on by the `span_correspondence_map`. - fn new(src: &str, file_span: Span, decoration_info: Option<DecorationInfo>) -> Classifier<'_> { + fn new(src: &'src str, file_span: Span, decoration_info: Option<&DecorationInfo>) -> Self { let tokens = PeekIter::new(TokenIter { src, cursor: Cursor::new(src) }); let decorations = decoration_info.map(Decorations::new); Classifier { diff --git a/src/librustdoc/html/highlight/tests.rs b/src/librustdoc/html/highlight/tests.rs index fd5275189d6..fccbb98f80f 100644 --- a/src/librustdoc/html/highlight/tests.rs +++ b/src/librustdoc/html/highlight/tests.rs @@ -78,7 +78,7 @@ let a = 4;"; decorations.insert("example2", vec![(22, 32)]); let mut html = Buffer::new(); - write_code(&mut html, src, None, Some(DecorationInfo(decorations))); + write_code(&mut html, src, None, Some(&DecorationInfo(decorations))); expect_file!["fixtures/decorations.html"].assert_eq(&html.into_inner()); }); } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 9a9ce31caaa..a27a9d202eb 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -69,9 +69,9 @@ use crate::formats::cache::Cache; use crate::formats::item_type::ItemType; use crate::html::escape::Escape; use crate::html::format::{ - Buffer, Ending, HrefError, PrintWithSpace, display_fn, href, join_with_double_colon, - print_abi_with_space, print_constness_with_space, print_default_space, print_generic_bounds, - print_where_clause, visibility_print_with_space, + Buffer, Ending, HrefError, PrintWithSpace, href, join_with_double_colon, print_abi_with_space, + print_constness_with_space, print_default_space, print_generic_bounds, print_where_clause, + visibility_print_with_space, }; use crate::html::markdown::{ HeadingOffset, IdMap, Markdown, MarkdownItemInfo, MarkdownSummaryLine, @@ -82,13 +82,14 @@ use crate::scrape_examples::{CallData, CallLocation}; use crate::{DOC_RUST_LANG_ORG_CHANNEL, try_none}; pub(crate) fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ { - crate::html::format::display_fn(move |f| { + fmt::from_fn(move |f| { if !v.ends_with('/') && !v.is_empty() { write!(f, "{v}/") } else { f.write_str(v) } }) } /// Specifies whether rendering directly implemented trait items or ones from a certain Deref /// impl. +#[derive(Copy, Clone)] pub(crate) enum AssocItemRender<'a> { All, DerefFor { trait_: &'a clean::Path, type_: &'a clean::Type, deref_mut_: bool }, @@ -309,9 +310,7 @@ impl ItemEntry { impl ItemEntry { pub(crate) fn print(&self) -> impl fmt::Display + '_ { - crate::html::format::display_fn(move |f| { - write!(f, "<a href=\"{}\">{}</a>", self.url, Escape(&self.name)) - }) + fmt::from_fn(move |f| write!(f, "<a href=\"{}\">{}</a>", self.url, Escape(&self.name))) } } @@ -513,7 +512,7 @@ fn document<'a, 'cx: 'a>( info!("Documenting {name}"); } - display_fn(move |f| { + fmt::from_fn(move |f| { document_item_info(cx, item, parent).render_into(f).unwrap(); if parent.is_none() { write!(f, "{}", document_full_collapsible(item, cx, heading_offset)) @@ -530,7 +529,7 @@ fn render_markdown<'a, 'cx: 'a>( links: Vec<RenderedLink>, heading_offset: HeadingOffset, ) -> impl fmt::Display + 'a + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { write!( f, "<div class=\"docblock\">{}</div>", @@ -557,7 +556,7 @@ fn document_short<'a, 'cx: 'a>( parent: &'a clean::Item, show_def_docs: bool, ) -> impl fmt::Display + 'a + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { document_item_info(cx, item, Some(parent)).render_into(f).unwrap(); if !show_def_docs { return Ok(()); @@ -605,7 +604,7 @@ fn document_full_inner<'a, 'cx: 'a>( is_collapsible: bool, heading_offset: HeadingOffset, ) -> impl fmt::Display + 'a + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { if let Some(s) = item.opt_doc_value() { debug!("Doc block: =====\n{s}\n====="); if is_collapsible { @@ -1159,7 +1158,7 @@ fn render_attributes_in_pre<'a, 'tcx: 'a>( prefix: &'a str, cx: &'a Context<'tcx>, ) -> impl fmt::Display + Captures<'a> + Captures<'tcx> { - crate::html::format::display_fn(move |f| { + fmt::from_fn(move |f| { for a in it.attributes(cx.tcx(), cx.cache(), false) { writeln!(f, "{prefix}{a}")?; } @@ -1256,9 +1255,9 @@ fn render_assoc_items<'a, 'cx: 'a>( it: DefId, what: AssocItemRender<'a>, ) -> impl fmt::Display + 'a + Captures<'cx> { - let mut derefs = DefIdSet::default(); - derefs.insert(it); - display_fn(move |f| { + fmt::from_fn(move |f| { + let mut derefs = DefIdSet::default(); + derefs.insert(it); render_assoc_items_inner(f, cx, containing_item, it, what, &mut derefs); Ok(()) }) @@ -2577,7 +2576,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &Context<'_>, item: &clean file_span, cx, &cx.root_path(), - highlight::DecorationInfo(decoration_info), + &highlight::DecorationInfo(decoration_info), sources::SourceContext::Embedded(sources::ScrapedInfo { needs_expansion, offset: line_min, diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 01e40f823d9..37fea09ace3 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -30,7 +30,7 @@ use crate::formats::Impl; use crate::formats::item_type::ItemType; use crate::html::escape::{Escape, EscapeBodyTextWithWbr}; use crate::html::format::{ - Buffer, Ending, PrintWithSpace, display_fn, join_with_double_colon, print_abi_with_space, + Buffer, Ending, PrintWithSpace, join_with_double_colon, print_abi_with_space, print_constness_with_space, print_where_clause, visibility_print_with_space, }; use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine}; @@ -92,7 +92,7 @@ macro_rules! item_template_methods { () => {}; (document $($rest:tt)*) => { fn document<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let (item, cx) = self.item_and_cx(); let v = document(cx, item, None, HeadingOffset::H2); write!(f, "{v}") @@ -102,7 +102,7 @@ macro_rules! item_template_methods { }; (document_type_layout $($rest:tt)*) => { fn document_type_layout<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let (item, cx) = self.item_and_cx(); let def_id = item.item_id.expect_def_id(); let v = document_type_layout(cx, def_id); @@ -113,7 +113,7 @@ macro_rules! item_template_methods { }; (render_attributes_in_pre $($rest:tt)*) => { fn render_attributes_in_pre<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let (item, cx) = self.item_and_cx(); let v = render_attributes_in_pre(item, "", cx); write!(f, "{v}") @@ -123,7 +123,7 @@ macro_rules! item_template_methods { }; (render_assoc_items $($rest:tt)*) => { fn render_assoc_items<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let (item, cx) = self.item_and_cx(); let def_id = item.item_id.expect_def_id(); let v = render_assoc_items(cx, item, def_id, AssocItemRender::All); @@ -520,13 +520,13 @@ fn extra_info_tags<'a, 'tcx: 'a>( parent: &'a clean::Item, import_def_id: Option<DefId>, ) -> impl fmt::Display + 'a + Captures<'tcx> { - display_fn(move |f| { + fmt::from_fn(move |f| { fn tag_html<'a>( class: &'a str, title: &'a str, contents: &'a str, ) -> impl fmt::Display + 'a { - display_fn(move |f| { + fmt::from_fn(move |f| { write!( f, r#"<wbr><span class="stab {class}" title="{title}">{contents}</span>"#, @@ -1375,7 +1375,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> { fn render_union<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let v = render_union(self.it, Some(&self.s.generics), &self.s.fields, self.cx); write!(f, "{v}") }) @@ -1385,7 +1385,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni &'b self, field: &'a clean::Item, ) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let v = document(self.cx, field, Some(self.it), HeadingOffset::H3); write!(f, "{v}") }) @@ -1399,7 +1399,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni &'b self, ty: &'a clean::Type, ) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { let v = ty.print(self.cx); write!(f, "{v}") }) @@ -1426,7 +1426,7 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>( cx: &'a Context<'cx>, s: &'a [clean::Item], ) -> impl fmt::Display + 'a + Captures<'cx> { - display_fn(|f| { + fmt::from_fn(|f| { if !s.is_empty() && s.iter().all(|field| { matches!(field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) @@ -2151,7 +2151,7 @@ fn render_union<'a, 'cx: 'a>( fields: &'a [clean::Item], cx: &'a Context<'cx>, ) -> impl fmt::Display + 'a + Captures<'cx> { - display_fn(move |mut f| { + fmt::from_fn(move |mut f| { write!(f, "{}union {}", visibility_print_with_space(it, cx), it.name.unwrap(),)?; let where_displayed = g @@ -2331,7 +2331,7 @@ fn document_non_exhaustive_header(item: &clean::Item) -> &str { } fn document_non_exhaustive(item: &clean::Item) -> impl fmt::Display + '_ { - display_fn(|f| { + fmt::from_fn(|f| { if item.is_non_exhaustive() { write!( f, diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index 881df8b0050..23ac568fdf8 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -100,18 +100,17 @@ impl<'a> Link<'a> { } pub(crate) mod filters { - use std::fmt::Display; + use std::fmt::{self, Display}; use rinja::filters::Safe; use crate::html::escape::EscapeBodyTextWithWbr; - use crate::html::render::display_fn; pub(crate) fn wrapped<T>(v: T) -> rinja::Result<Safe<impl Display>> where T: Display, { let string = v.to_string(); - Ok(Safe(display_fn(move |f| EscapeBodyTextWithWbr(&string).fmt(f)))) + Ok(Safe(fmt::from_fn(move |f| EscapeBodyTextWithWbr(&string).fmt(f)))) } } diff --git a/src/librustdoc/html/render/type_layout.rs b/src/librustdoc/html/render/type_layout.rs index 9317844956d..0f01db5f6bc 100644 --- a/src/librustdoc/html/render/type_layout.rs +++ b/src/librustdoc/html/render/type_layout.rs @@ -9,7 +9,6 @@ use rustc_middle::ty::layout::LayoutError; use rustc_middle::ty::{self}; use rustc_span::symbol::Symbol; -use crate::html::format::display_fn; use crate::html::render::Context; #[derive(Template)] @@ -31,7 +30,7 @@ pub(crate) fn document_type_layout<'a, 'cx: 'a>( cx: &'a Context<'cx>, ty_def_id: DefId, ) -> impl fmt::Display + 'a + Captures<'cx> { - display_fn(move |f| { + fmt::from_fn(move |f| { if !cx.shared.show_type_layout { return Ok(()); } diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 9827f97d28d..1ac0c10c612 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -17,7 +17,7 @@ use crate::clean::utils::has_doc_flag; use crate::docfs::PathError; use crate::error::Error; use crate::html::render::Context; -use crate::html::{format, highlight, layout}; +use crate::html::{highlight, layout}; use crate::visit::DocVisitor; pub(crate) fn render(cx: &mut Context<'_>, krate: &clean::Crate) -> Result<(), Error> { @@ -249,7 +249,7 @@ impl SourceCollector<'_, '_> { file_span, self.cx, &root_path, - highlight::DecorationInfo::default(), + &highlight::DecorationInfo::default(), SourceContext::Standalone { file_path }, ) }, @@ -328,13 +328,13 @@ pub(crate) fn print_src( file_span: rustc_span::Span, context: &Context<'_>, root_path: &str, - decoration_info: highlight::DecorationInfo, + decoration_info: &highlight::DecorationInfo, source_context: SourceContext<'_>, ) { - let current_href = context - .href_from_span(clean::Span::new(file_span), false) - .expect("only local crates should have sources emitted"); - let code = format::display_fn(move |fmt| { + let code = fmt::from_fn(move |fmt| { + let current_href = context + .href_from_span(clean::Span::new(file_span), false) + .expect("only local crates should have sources emitted"); highlight::write_code( fmt, s, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index ba620b6cb6b..bb954a31891 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -5,6 +5,7 @@ #![feature(rustc_private)] #![feature(assert_matches)] #![feature(box_patterns)] +#![feature(debug_closure_helpers)] #![feature(file_buffered)] #![feature(if_let_guard)] #![feature(impl_trait_in_assoc_type)] @@ -73,8 +74,6 @@ extern crate tikv_jemalloc_sys as jemalloc_sys; use std::env::{self, VarError}; use std::io::{self, IsTerminal}; use std::process; -use std::sync::Arc; -use std::sync::atomic::AtomicBool; use rustc_errors::DiagCtxtHandle; use rustc_interface::interface; @@ -158,7 +157,7 @@ pub fn main() { let mut early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default()); - let using_internal_features = rustc_driver::install_ice_hook( + rustc_driver::install_ice_hook( "https://github.com/rust-lang/rust/issues/new\ ?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md", |_| (), @@ -179,7 +178,7 @@ pub fn main() { let exit_code = rustc_driver::catch_with_exit_code(|| { let at_args = rustc_driver::args::raw_args(&early_dcx)?; - main_args(&mut early_dcx, &at_args, using_internal_features); + main_args(&mut early_dcx, &at_args); Ok(()) }); process::exit(exit_code); @@ -768,11 +767,7 @@ fn run_merge_finalize(opt: config::RenderOptions) -> Result<(), error::Error> { Ok(()) } -fn main_args( - early_dcx: &mut EarlyDiagCtxt, - at_args: &[String], - using_internal_features: Arc<AtomicBool>, -) { +fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) { // Throw away the first argument, the name of the binary. // In case of at_args being empty, as might be the case by // passing empty argument array to execve under some platforms, @@ -825,8 +820,7 @@ fn main_args( (false, Some(md_input)) => { let md_input = md_input.to_owned(); let edition = options.edition; - let config = - core::create_config(input, options, &render_options, using_internal_features); + let config = core::create_config(input, options, &render_options); // `markdown::render` can invoke `doctest::make_test`, which // requires session globals and a thread pool, so we use @@ -859,7 +853,7 @@ fn main_args( let scrape_examples_options = options.scrape_examples_options.clone(); let bin_crate = options.bin_crate; - let config = core::create_config(input, options, &render_options, using_internal_features); + let config = core::create_config(input, options, &render_options); let registered_lints = config.register_lints.is_some(); diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 5a99977ded5..916f0ab3cc8 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -1099,8 +1099,7 @@ pub struct Trait { pub is_auto: bool, /// Whether the trait is marked as `unsafe`. pub is_unsafe: bool, - // FIXME(dyn_compat_renaming): Update the URL once the Reference is updated and hits stable. - /// Whether the trait is [dyn compatible](https://doc.rust-lang.org/reference/items/traits.html#object-safety)[^1]. + /// Whether the trait is [dyn compatible](https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility)[^1]. /// /// [^1]: Formerly known as "object safe". pub is_dyn_compatible: bool, diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs index 75ef60a5dc8..68edefd3095 100644 --- a/src/tools/clippy/src/driver.rs +++ b/src/tools/clippy/src/driver.rs @@ -186,7 +186,7 @@ pub fn main() { rustc_driver::init_rustc_env_logger(&early_dcx); - let using_internal_features = rustc_driver::install_ice_hook(BUG_REPORT_URL, |dcx| { + rustc_driver::install_ice_hook(BUG_REPORT_URL, |dcx| { // FIXME: this macro calls unwrap internally but is called in a panicking context! It's not // as simple as moving the call from the hook to main, because `install_ice_hook` doesn't // accept a generic closure. @@ -236,7 +236,7 @@ pub fn main() { let mut args: Vec<String> = orig_args.clone(); pass_sysroot_env_if_given(&mut args, sys_root_env); - rustc_driver::RunCompiler::new(&args, &mut DefaultCallbacks).run(); + rustc_driver::run_compiler(&args, &mut DefaultCallbacks); return Ok(()); } @@ -295,13 +295,9 @@ pub fn main() { let clippy_enabled = !cap_lints_allow && relevant_package && !info_query; if clippy_enabled { args.extend(clippy_args); - rustc_driver::RunCompiler::new(&args, &mut ClippyCallbacks { clippy_args_var }) - .set_using_internal_features(using_internal_features) - .run(); + rustc_driver::run_compiler(&args, &mut ClippyCallbacks { clippy_args_var }); } else { - rustc_driver::RunCompiler::new(&args, &mut RustcCallbacks { clippy_args_var }) - .set_using_internal_features(using_internal_features) - .run(); + rustc_driver::run_compiler(&args, &mut RustcCallbacks { clippy_args_var }); } Ok(()) })) diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs index 570b2c374c0..19340b5d07a 100644 --- a/src/tools/linkchecker/main.rs +++ b/src/tools/linkchecker/main.rs @@ -50,6 +50,29 @@ const LINKCHECK_EXCEPTIONS: &[(&str, &[&str])] = &[ ("alloc/slice/trait.Concat.html", &["#method.concat"]), ("alloc/slice/index.html", &["#method.concat", "#method.join"]), ("alloc/vec/struct.Vec.html", &["#method.sort_by_key", "#method.sort_by_cached_key"]), + ("alloc/bstr/struct.ByteStr.html", &[ + "#method.to_ascii_uppercase", + "#method.to_ascii_lowercase", + "core/slice::sort_by_key", + "core\\slice::sort_by_key", + "#method.sort_by_cached_key", + "#method.sort_by_key" + ]), + ("alloc/bstr/struct.ByteString.html", &[ + "#method.to_ascii_uppercase", + "#method.to_ascii_lowercase", + "core/slice::sort_by_key", + "core\\slice::sort_by_key", + "#method.sort_by_cached_key", + "#method.sort_by_key" + ]), + ("core/bstr/struct.ByteStr.html", &[ + "#method.to_ascii_uppercase", + "#method.to_ascii_lowercase", + "core/bstr/slice::sort_by_key", + "core\\bstr\\slice::sort_by_key", + "#method.sort_by_cached_key" + ]), ("core/primitive.str.html", &["#method.to_ascii_uppercase", "#method.to_ascii_lowercase"]), ("core/primitive.slice.html", &["#method.to_ascii_uppercase", "#method.to_ascii_lowercase", "core/slice::sort_by_key", "core\\slice::sort_by_key", diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index 65d54088833..8bbded32c3e 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -3cd8fcbf87bd28a1f31be000ca906fb66f4d451d +1c9837df1dde9b234229709e89b3672bd3cf04a4 diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index 9cd84332204..26a9836a3ae 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -29,8 +29,8 @@ use std::num::NonZero; use std::ops::Range; use std::path::PathBuf; use std::str::FromStr; +use std::sync::Once; use std::sync::atomic::{AtomicI32, Ordering}; -use std::sync::{Arc, Once}; use miri::{ BacktraceStyle, BorrowTrackerMethod, MiriConfig, MiriEntryFnType, ProvenanceMode, RetagFields, @@ -371,13 +371,10 @@ fn init_late_loggers(early_dcx: &EarlyDiagCtxt, tcx: TyCtxt<'_>) { fn run_compiler_and_exit( args: &[String], callbacks: &mut (dyn rustc_driver::Callbacks + Send), - using_internal_features: Arc<std::sync::atomic::AtomicBool>, ) -> ! { // Invoke compiler, and handle return code. let exit_code = rustc_driver::catch_with_exit_code(move || { - rustc_driver::RunCompiler::new(args, callbacks) - .set_using_internal_features(using_internal_features) - .run(); + rustc_driver::run_compiler(args, callbacks); Ok(()) }); std::process::exit(exit_code) @@ -468,8 +465,7 @@ fn main() { // If the environment asks us to actually be rustc, then do that. if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") { // Earliest rustc setup. - let using_internal_features = - rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ()); + rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ()); rustc_driver::init_rustc_env_logger(&early_dcx); let target_crate = if crate_kind == "target" { @@ -493,16 +489,11 @@ fn main() { } // We cannot use `rustc_driver::main` as we want it to use `args` as the CLI arguments. - run_compiler_and_exit( - &args, - &mut MiriBeRustCompilerCalls { target_crate }, - using_internal_features, - ) + run_compiler_and_exit(&args, &mut MiriBeRustCompilerCalls { target_crate }) } // Add an ICE bug report hook. - let using_internal_features = - rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ()); + rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ()); // Init loggers the Miri way. init_early_loggers(&early_dcx); @@ -736,9 +727,5 @@ fn main() { debug!("rustc arguments: {:?}", rustc_args); debug!("crate arguments: {:?}", miri_config.args); - run_compiler_and_exit( - &rustc_args, - &mut MiriCompilerCalls::new(miri_config, many_seeds), - using_internal_features, - ) + run_compiler_and_exit(&rustc_args, &mut MiriCompilerCalls::new(miri_config, many_seeds)) } |
