From 4333fb0627ca18f863314942adc9f81d452f8251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 14 Jan 2024 13:48:23 +0100 Subject: [PATCH 01/11] Clarify prioritization alert --- triagebot.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/triagebot.toml b/triagebot.toml index 1e1db2d16632e..08ca2ae10a250 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -383,7 +383,7 @@ message_on_add = """\ - Priority? - Regression? - Notify people/groups? -- Needs `I-nominated`? +- Needs `I-{team}-nominated`? """ message_on_remove = "Issue #{number}'s prioritization request has been removed." message_on_close = "Issue #{number} has been closed while requested for prioritization." From cf836bcc3c1a3c630f40ceb68e2378bafb33b12b Mon Sep 17 00:00:00 2001 From: Slanterns Date: Fri, 12 Apr 2024 02:27:58 +0800 Subject: [PATCH 02/11] Stabilize `Seek::seek_relative` --- library/std/src/io/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 980b3e7aa48d0..c0a82f5b60553 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -2055,7 +2055,6 @@ pub trait Seek { /// # Example /// /// ```no_run - /// #![feature(seek_seek_relative)] /// use std::{ /// io::{self, Seek}, /// fs::File, @@ -2070,7 +2069,7 @@ pub trait Seek { /// ``` /// /// [`BufReader`]: crate::io::BufReader - #[unstable(feature = "seek_seek_relative", issue = "117374")] + #[stable(feature = "seek_seek_relative", since = "CURRENT_RUSTC_VERSION")] fn seek_relative(&mut self, offset: i64) -> Result<()> { self.seek(SeekFrom::Current(offset))?; Ok(()) From b98b8d76b1228999dd97058ea4e4a4719fe2f287 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Mon, 13 May 2024 09:18:23 +0200 Subject: [PATCH 03/11] Don't call `env::set_var` in `rustc_driver::install_ice_hook` Modifying an environment variable would make the function unsafe to call. --- compiler/rustc_driver_impl/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index b2d38a00f0b5f..ba6b9ef078467 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -11,6 +11,7 @@ #![allow(internal_features)] #![feature(decl_macro)] #![feature(let_chains)] +#![feature(panic_backtrace_config)] #![feature(panic_update_hook)] #![feature(result_flattening)] @@ -1317,8 +1318,8 @@ pub fn install_ice_hook( // by the user. Compiler developers and other rustc users can // opt in to less-verbose backtraces by manually setting "RUST_BACKTRACE" // (e.g. `RUST_BACKTRACE=1`) - if std::env::var_os("RUST_BACKTRACE").is_none() { - std::env::set_var("RUST_BACKTRACE", "full"); + if env::var_os("RUST_BACKTRACE").is_none() { + panic::set_backtrace_style(panic::BacktraceStyle::Full); } let using_internal_features = Arc::new(std::sync::atomic::AtomicBool::default()); From eea00ca354855e546a1f3626c215571a5afa9e6c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 May 2024 15:04:10 +0200 Subject: [PATCH 04/11] Add `target` method to `Rustdoc` type --- src/tools/run-make-support/src/rustdoc.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/rustdoc.rs index 75ca1fc29747f..fa8521ed9194b 100644 --- a/src/tools/run-make-support/src/rustdoc.rs +++ b/src/tools/run-make-support/src/rustdoc.rs @@ -123,6 +123,12 @@ impl Rustdoc { self } + /// Specify the target triple, or a path to a custom target json spec file. + pub fn target(&mut self, target: &str) -> &mut Self { + self.cmd.arg(format!("--target={target}")); + self + } + /// Specify the crate type. pub fn crate_type(&mut self, crate_type: &str) -> &mut Self { self.cmd.arg("--crate-type"); From 4057a7b1e3fd1a1371b5dda1fa4323c6d3426b39 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 May 2024 15:12:42 +0200 Subject: [PATCH 05/11] Add `library_search_path` to `Rustdoc` --- src/tools/run-make-support/src/rustdoc.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/rustdoc.rs index fa8521ed9194b..c4f4e9f9bd23b 100644 --- a/src/tools/run-make-support/src/rustdoc.rs +++ b/src/tools/run-make-support/src/rustdoc.rs @@ -143,6 +143,14 @@ impl Rustdoc { self } + /// Add a directory to the library search path. It corresponds to the `-L` + /// rustdoc option. + pub fn library_search_path>(&mut self, path: P) -> &mut Self { + self.cmd.arg("-L"); + self.cmd.arg(path.as_ref()); + self + } + #[track_caller] pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output { let caller_location = std::panic::Location::caller(); From b515de83af4fd73255de0a1ebb48db5849f8e01f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 13 May 2024 15:04:36 +0200 Subject: [PATCH 06/11] Migrate `run-make/rustdoc-target-spec-json-path` to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - .../rustdoc-target-spec-json-path/Makefile | 9 --------- .../rustdoc-target-spec-json-path/rmake.rs | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 10 deletions(-) delete mode 100644 tests/run-make/rustdoc-target-spec-json-path/Makefile create mode 100644 tests/run-make/rustdoc-target-spec-json-path/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index d742368292035..5f385280ac5ac 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -251,7 +251,6 @@ run-make/rustdoc-scrape-examples-multiple/Makefile run-make/rustdoc-scrape-examples-remap/Makefile run-make/rustdoc-scrape-examples-test/Makefile run-make/rustdoc-scrape-examples-whitespace/Makefile -run-make/rustdoc-target-spec-json-path/Makefile run-make/rustdoc-themes/Makefile run-make/rustdoc-verify-output-files/Makefile run-make/rustdoc-with-out-dir-option/Makefile diff --git a/tests/run-make/rustdoc-target-spec-json-path/Makefile b/tests/run-make/rustdoc-target-spec-json-path/Makefile deleted file mode 100644 index 6d0bc4186f229..0000000000000 --- a/tests/run-make/rustdoc-target-spec-json-path/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -include ../tools.mk - -# Test that rustdoc will properly canonicalize the target spec json path just like rustc - -OUTPUT_DIR := "$(TMPDIR)/rustdoc-target-spec-json-path" - -all: - $(RUSTC) --crate-type lib dummy_core.rs --target target.json - $(RUSTDOC) -o $(OUTPUT_DIR) -L $(TMPDIR) my_crate.rs --target target.json diff --git a/tests/run-make/rustdoc-target-spec-json-path/rmake.rs b/tests/run-make/rustdoc-target-spec-json-path/rmake.rs new file mode 100644 index 0000000000000..66530a4f08ee9 --- /dev/null +++ b/tests/run-make/rustdoc-target-spec-json-path/rmake.rs @@ -0,0 +1,14 @@ +// Test that rustdoc will properly canonicalize the target spec json path just like rustc. + +use run_make_support::{rustc, rustdoc, tmp_dir}; + +fn main() { + let out_dir = tmp_dir().join("rustdoc-target-spec-json-path"); + rustc().crate_type("lib").input("dummy_core.rs").target("target.json").run(); + rustdoc() + .input("my_crate.rs") + .output(out_dir) + .library_search_path(tmp_dir()) + .target("target.json") + .run(); +} From 3742a4bd902f5d6efd2b401a6dab5e4087070d5d Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Tue, 2 Jan 2024 04:59:24 -0800 Subject: [PATCH 07/11] style-guide: Format single associated type `where` clauses on the same line In particular, lifetime-generic associated types often have a `where Self: 'a` bound, which we can format on the same line. --- src/doc/style-guide/src/editions.md | 1 + src/doc/style-guide/src/items.md | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/doc/style-guide/src/editions.md b/src/doc/style-guide/src/editions.md index b9a89c20cee40..9d593f8081025 100644 --- a/src/doc/style-guide/src/editions.md +++ b/src/doc/style-guide/src/editions.md @@ -43,6 +43,7 @@ include: - Miscellaneous `rustfmt` bugfixes. - Use version-sort (sort `x8`, `x16`, `x32`, `x64`, `x128` in that order). - Change "ASCIIbetical" sort to Unicode-aware "non-lowercase before lowercase". +- Format single associated type `where` clauses on the same line if they fit. ## Rust 2015/2018/2021 style edition diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md index 0066a4bacb956..06bac12987191 100644 --- a/src/doc/style-guide/src/items.md +++ b/src/doc/style-guide/src/items.md @@ -421,9 +421,20 @@ Format associated types like type aliases. Where an associated type has a bound, put a space after the colon but not before: ```rust -pub type Foo: Bar; +type Foo: Bar; ``` +If an associated type has no `=`, and has a `where` clause with only one entry, +format the entire type declaration including the `where` clause on the same +line if it fits: + +```rust +type Item<'a> where Self: 'a; +``` + +If the associated type has a `=`, or if the `where` clause contains multiple +entries, format it across multiple lines as with a type alias. + ## extern items When writing extern items (such as `extern "C" fn`), always specify the ABI. From 2f20bb4a976e7dbd11c5329b48a2d402ff81fca9 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 10 Jan 2024 19:11:17 -0800 Subject: [PATCH 08/11] style-guide: Give a second example for associated type formatting Show an example that has bounds. --- src/doc/style-guide/src/items.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md index 06bac12987191..718180191895a 100644 --- a/src/doc/style-guide/src/items.md +++ b/src/doc/style-guide/src/items.md @@ -430,6 +430,7 @@ line if it fits: ```rust type Item<'a> where Self: 'a; +type Item<'a>: PartialEq + Send where Self: 'a; ``` If the associated type has a `=`, or if the `where` clause contains multiple From 2af29af710aa4613e4ff670e5902d7ea6725988f Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 10 Jan 2024 19:13:15 -0800 Subject: [PATCH 09/11] style-guide: Not all where clauses can be written as inline bounds --- src/doc/style-guide/src/items.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md index 718180191895a..095e5512ea923 100644 --- a/src/doc/style-guide/src/items.md +++ b/src/doc/style-guide/src/items.md @@ -347,7 +347,7 @@ where ``` If a `where` clause is very short, prefer using an inline bound on the type -parameter. +parameter if possible. If a component of a `where` clause does not fit and contains `+`, break it before each `+` and block-indent the continuation lines. Put each bound on its From 9ff777bf50cb26107496c1bfdd178c56c5a57cca Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 10 Jan 2024 19:21:27 -0800 Subject: [PATCH 10/11] style-guide: Also format where clauses on one line for short function decls --- src/doc/style-guide/src/items.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md index 095e5512ea923..9b8cdaed88bee 100644 --- a/src/doc/style-guide/src/items.md +++ b/src/doc/style-guide/src/items.md @@ -295,8 +295,18 @@ Prefer to use single-letter names for generic parameters. These rules apply for `where` clauses on any item. -If immediately following a closing bracket of any kind, write the keyword -`where` on the same line, with a space before it. +If a where clause is short, and appears on a short one-line function +declaration with no body or a short associated type with no `=`, format it on +the same line as the declaration: + +```rust +fn new(&self) -> Self where Self: Sized; + +type Item<'a>: SomeTrait where Self: 'a; +``` + +Otherwise, if immediately following a closing bracket of any kind, write the +keyword `where` on the same line, with a space before it. Otherwise, put `where` on a new line at the same indentation level. Put each component of a `where` clause on its own line, block-indented. Use a trailing @@ -424,9 +434,9 @@ bound, put a space after the colon but not before: type Foo: Bar; ``` -If an associated type has no `=`, and has a `where` clause with only one entry, -format the entire type declaration including the `where` clause on the same -line if it fits: +If an associated type is short, has no `=`, and has a `where` clause with only +one entry, format the entire type declaration including the `where` clause on +the same line if it fits: ```rust type Item<'a> where Self: 'a; From 163b1a66152faffb5543f5a7ed5d80251f4d466c Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 24 Jan 2024 12:48:11 -0800 Subject: [PATCH 11/11] Reword formatting for where clauses Suggested-by: Caleb Cartwright --- src/doc/style-guide/src/items.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md index 9b8cdaed88bee..c0628691b7734 100644 --- a/src/doc/style-guide/src/items.md +++ b/src/doc/style-guide/src/items.md @@ -296,7 +296,7 @@ Prefer to use single-letter names for generic parameters. These rules apply for `where` clauses on any item. If a where clause is short, and appears on a short one-line function -declaration with no body or a short associated type with no `=`, format it on +declaration with no body or on a short type with no `=`, format it on the same line as the declaration: ```rust