From 5710fca279d989676bae903299cce134552747f5 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 12 Jul 2023 12:23:40 +0200 Subject: [PATCH 1/9] update ancient note --- library/std/src/collections/hash/set.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index ec59634df363a..04d77424ac7b1 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -65,8 +65,8 @@ use super::map::{map_try_reserve_error, RandomState}; /// ``` /// /// The easiest way to use `HashSet` with a custom type is to derive -/// [`Eq`] and [`Hash`]. We must also derive [`PartialEq`], this will in the -/// future be implied by [`Eq`]. +/// [`Eq`] and [`Hash`]. We must also derive [`PartialEq`], +/// which is implied by [`Eq`]. /// /// ``` /// use std::collections::HashSet; From 5842a3fe082498077a256d578c366b8075f327d8 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 3 Jul 2023 07:21:54 +0200 Subject: [PATCH 2/9] add support of available_parallelism for target hermit On RustyHermit, the function `get_processor_count` returns the number of activated processors. --- library/std/src/sys/hermit/thread.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/std/src/sys/hermit/thread.rs b/library/std/src/sys/hermit/thread.rs index 2507f70695173..332151e40d026 100644 --- a/library/std/src/sys/hermit/thread.rs +++ b/library/std/src/sys/hermit/thread.rs @@ -1,6 +1,5 @@ #![allow(dead_code)] -use super::unsupported; use crate::ffi::CStr; use crate::io; use crate::mem; @@ -99,7 +98,7 @@ impl Thread { } pub fn available_parallelism() -> io::Result { - unsupported() + unsafe { Ok(NonZeroUsize::new_unchecked(abi::get_processor_count())) } } pub mod guard { From 50c7344eafb8dd88aff996063cc0ec270e2e09e3 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 3 Jul 2023 07:35:02 +0200 Subject: [PATCH 3/9] define hermit_abi as public depedenceny It's exported publicly, so it should not be linted. --- library/std/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index eb4815d0cdf6e..6897ed24beb0e 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -45,7 +45,7 @@ dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] } fortanix-sgx-abi = { version = "0.5.0", features = ['rustc-dep-of-std'], public = true } [target.'cfg(target_os = "hermit")'.dependencies] -hermit-abi = { version = "0.3.0", features = ['rustc-dep-of-std'] } +hermit-abi = { version = "0.3.1", features = ['rustc-dep-of-std'], public = true } [target.wasm32-wasi.dependencies] wasi = { version = "0.11.0", features = ['rustc-dep-of-std'], default-features = false } From e1777f9690e50b693ec50f5fa1c9e10e428174b4 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 3 Jul 2023 07:35:46 +0200 Subject: [PATCH 4/9] fix usage of Timespec om the target hermit --- library/std/src/sys/hermit/time.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/hermit/time.rs b/library/std/src/sys/hermit/time.rs index 5440d85df4adf..7d91460aba3ee 100644 --- a/library/std/src/sys/hermit/time.rs +++ b/library/std/src/sys/hermit/time.rs @@ -40,7 +40,7 @@ impl Timespec { } fn checked_add_duration(&self, other: &Duration) -> Option { - let mut secs = self.tv_sec.checked_add_unsigned(other.as_secs())?; + let mut secs = self.t.tv_sec.checked_add_unsigned(other.as_secs())?; // Nano calculations can't overflow because nanos are <1B which fit // in a u32. @@ -53,7 +53,7 @@ impl Timespec { } fn checked_sub_duration(&self, other: &Duration) -> Option { - let mut secs = self.tv_sec.checked_sub_unsigned(other.as_secs())?; + let mut secs = self.t.tv_sec.checked_sub_unsigned(other.as_secs())?; // Similar to above, nanos can't overflow. let mut nsec = self.t.tv_nsec as i32 - other.subsec_nanos() as i32; From 8666adeb61c6d81903e5a82d7b27a6ad250e38e4 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 4 Jul 2023 15:58:02 +0200 Subject: [PATCH 5/9] use latest version of hermit-abi 0.3.0 and 0.3.1 have an issue and will be yanked. Consequently, std should switch to 0.3.2. --- Cargo.lock | 12 ++++++------ library/std/Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fcd58d8a86634..9f1561b503d8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1529,9 +1529,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" dependencies = [ "compiler_builtins", "rustc-std-workspace-alloc", @@ -1864,7 +1864,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", "windows-sys 0.48.0", ] @@ -1881,7 +1881,7 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "rustix 0.38.2", "windows-sys 0.48.0", ] @@ -2396,7 +2396,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", ] @@ -4819,7 +4819,7 @@ dependencies = [ "dlmalloc", "fortanix-sgx-abi", "hashbrown 0.14.0", - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", "miniz_oxide", "object", diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 6897ed24beb0e..c129a753912f7 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -45,7 +45,7 @@ dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] } fortanix-sgx-abi = { version = "0.5.0", features = ['rustc-dep-of-std'], public = true } [target.'cfg(target_os = "hermit")'.dependencies] -hermit-abi = { version = "0.3.1", features = ['rustc-dep-of-std'], public = true } +hermit-abi = { version = "0.3.2", features = ['rustc-dep-of-std'], public = true } [target.wasm32-wasi.dependencies] wasi = { version = "0.11.0", features = ['rustc-dep-of-std'], default-features = false } From df3f45dbc5dc216de00b6cbee6267da3fca2a9a4 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 12 Jul 2023 20:10:52 +0200 Subject: [PATCH 6/9] avoid ambiguous word See https://github.com/rust-lang/rust/pull/113618#pullrequestreview-1526295432 --- library/std/src/collections/hash/set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 04d77424ac7b1..959403e164476 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -66,7 +66,7 @@ use super::map::{map_try_reserve_error, RandomState}; /// /// The easiest way to use `HashSet` with a custom type is to derive /// [`Eq`] and [`Hash`]. We must also derive [`PartialEq`], -/// which is implied by [`Eq`]. +/// which is required if [`Eq`] is derived. /// /// ``` /// use std::collections::HashSet; From 0b5c683b06bba30cce4eb8528132a15bb1aa8edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Sat, 17 Jun 2023 15:06:48 +0800 Subject: [PATCH 7/9] Add machine-applicable suggestion for `unused_qualifications` lint --- compiler/rustc_lint/src/context.rs | 8 +++++ compiler/rustc_lint_defs/src/lib.rs | 6 ++++ compiler/rustc_resolve/src/late.rs | 6 +++- tests/ui/lint/lint-qualification.stderr | 4 +++ .../unused-qualifications-suggestion.fixed | 23 +++++++++++++++ .../unused-qualifications-suggestion.rs | 23 +++++++++++++++ .../unused-qualifications-suggestion.stderr | 29 +++++++++++++++++++ 7 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 tests/ui/resolve/unused-qualifications-suggestion.fixed create mode 100644 tests/ui/resolve/unused-qualifications-suggestion.rs create mode 100644 tests/ui/resolve/unused-qualifications-suggestion.stderr diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 3761754f3aea4..4770ed6639312 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -956,6 +956,14 @@ pub trait LintContext: Sized { db.span_note(glob_reexport_span, format!("the name `{}` in the {} namespace is supposed to be publicly re-exported here", name, namespace)); db.span_note(private_item_span, "but the private item here shadows it".to_owned()); } + BuiltinLintDiagnostics::UnusedQualifications { path_span, unqualified_path } => { + db.span_suggestion_verbose( + path_span, + "replace it with the unqualified path", + unqualified_path, + Applicability::MachineApplicable + ); + } } // Rewrap `db`, and pass control to the user. decorate(db) diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 5a5031b791964..f6ffd46b1fe08 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -550,6 +550,12 @@ pub enum BuiltinLintDiagnostics { /// The local binding that shadows the glob reexport. private_item_span: Span, }, + UnusedQualifications { + /// The span of the unnecessarily-qualified path. + path_span: Span, + /// The replacement unqualified path. + unqualified_path: Ident, + }, } /// Lints that are buffered up early on in the `Session` before the diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index f6c7aecf8b0bb..d3647663824a5 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3917,11 +3917,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { }; if res == unqualified_result { let lint = lint::builtin::UNUSED_QUALIFICATIONS; - self.r.lint_buffer.buffer_lint( + self.r.lint_buffer.buffer_lint_with_diagnostic( lint, finalize.node_id, finalize.path_span, "unnecessary qualification", + lint::BuiltinLintDiagnostics::UnusedQualifications { + path_span: finalize.path_span, + unqualified_path: path.last().unwrap().ident + } ) } } diff --git a/tests/ui/lint/lint-qualification.stderr b/tests/ui/lint/lint-qualification.stderr index 149a782d97c2e..d09cb78c4f013 100644 --- a/tests/ui/lint/lint-qualification.stderr +++ b/tests/ui/lint/lint-qualification.stderr @@ -9,6 +9,10 @@ note: the lint level is defined here | LL | #![deny(unused_qualifications)] | ^^^^^^^^^^^^^^^^^^^^^ +help: replace it with the unqualified path + | +LL | bar(); + | ~~~ error: aborting due to previous error diff --git a/tests/ui/resolve/unused-qualifications-suggestion.fixed b/tests/ui/resolve/unused-qualifications-suggestion.fixed new file mode 100644 index 0000000000000..0d4b9007c7b5e --- /dev/null +++ b/tests/ui/resolve/unused-qualifications-suggestion.fixed @@ -0,0 +1,23 @@ +// run-rustfix + +#![deny(unused_qualifications)] + +mod foo { + pub fn bar() {} +} + +mod baz { + pub mod qux { + pub fn quux() {} + } +} + +fn main() { + use foo::bar; + bar(); + //~^ ERROR unnecessary qualification + + use baz::qux::quux; + quux(); + //~^ ERROR unnecessary qualification +} diff --git a/tests/ui/resolve/unused-qualifications-suggestion.rs b/tests/ui/resolve/unused-qualifications-suggestion.rs new file mode 100644 index 0000000000000..f6722e96537c9 --- /dev/null +++ b/tests/ui/resolve/unused-qualifications-suggestion.rs @@ -0,0 +1,23 @@ +// run-rustfix + +#![deny(unused_qualifications)] + +mod foo { + pub fn bar() {} +} + +mod baz { + pub mod qux { + pub fn quux() {} + } +} + +fn main() { + use foo::bar; + foo::bar(); + //~^ ERROR unnecessary qualification + + use baz::qux::quux; + baz::qux::quux(); + //~^ ERROR unnecessary qualification +} diff --git a/tests/ui/resolve/unused-qualifications-suggestion.stderr b/tests/ui/resolve/unused-qualifications-suggestion.stderr new file mode 100644 index 0000000000000..c8e91e07295b6 --- /dev/null +++ b/tests/ui/resolve/unused-qualifications-suggestion.stderr @@ -0,0 +1,29 @@ +error: unnecessary qualification + --> $DIR/unused-qualifications-suggestion.rs:17:5 + | +LL | foo::bar(); + | ^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/unused-qualifications-suggestion.rs:3:9 + | +LL | #![deny(unused_qualifications)] + | ^^^^^^^^^^^^^^^^^^^^^ +help: replace it with the unqualified path + | +LL | bar(); + | ~~~ + +error: unnecessary qualification + --> $DIR/unused-qualifications-suggestion.rs:21:5 + | +LL | baz::qux::quux(); + | ^^^^^^^^^^^^^^ + | +help: replace it with the unqualified path + | +LL | quux(); + | ~~~~ + +error: aborting due to 2 previous errors + From 9d071b3b0d0f940c030cf8aa7ab40bae411757ef Mon Sep 17 00:00:00 2001 From: jyn Date: Thu, 13 Jul 2023 01:21:46 -0500 Subject: [PATCH 8/9] Make `nodejs` control the default for RustdocJs tests instead of a hard-off switch If someone says `x test rustdoc-js-std` explicitly on the command line, it's because they want to run the tests. Give an error instead of doing nothing and reporting success. --- src/bootstrap/test.rs | 82 ++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index d7303427c3b1f..3b8b837682d06 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -867,7 +867,8 @@ impl Step for RustdocJSStd { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.suite_path("tests/rustdoc-js-std") + let default = run.builder.config.nodejs.is_some(); + run.suite_path("tests/rustdoc-js-std").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -875,38 +876,34 @@ impl Step for RustdocJSStd { } fn run(self, builder: &Builder<'_>) { - if let Some(ref nodejs) = builder.config.nodejs { - let mut command = Command::new(nodejs); - command - .arg(builder.src.join("src/tools/rustdoc-js/tester.js")) - .arg("--crate-name") - .arg("std") - .arg("--resource-suffix") - .arg(&builder.version) - .arg("--doc-folder") - .arg(builder.doc_out(self.target)) - .arg("--test-folder") - .arg(builder.src.join("tests/rustdoc-js-std")); - for path in &builder.paths { - if let Some(p) = - util::is_valid_test_suite_arg(path, "tests/rustdoc-js-std", builder) - { - if !p.ends_with(".js") { - eprintln!("A non-js file was given: `{}`", path.display()); - panic!("Cannot run rustdoc-js-std tests"); - } - command.arg("--test-file").arg(path); + let nodejs = + builder.config.nodejs.as_ref().expect("need nodejs to run rustdoc-js-std tests"); + let mut command = Command::new(nodejs); + command + .arg(builder.src.join("src/tools/rustdoc-js/tester.js")) + .arg("--crate-name") + .arg("std") + .arg("--resource-suffix") + .arg(&builder.version) + .arg("--doc-folder") + .arg(builder.doc_out(self.target)) + .arg("--test-folder") + .arg(builder.src.join("tests/rustdoc-js-std")); + for path in &builder.paths { + if let Some(p) = util::is_valid_test_suite_arg(path, "tests/rustdoc-js-std", builder) { + if !p.ends_with(".js") { + eprintln!("A non-js file was given: `{}`", path.display()); + panic!("Cannot run rustdoc-js-std tests"); } + command.arg("--test-file").arg(path); } - builder.ensure(crate::doc::Std::new( - builder.top_stage, - self.target, - DocumentationFormat::HTML, - )); - builder.run(&mut command); - } else { - builder.info("No nodejs found, skipping \"tests/rustdoc-js-std\" tests"); } + builder.ensure(crate::doc::Std::new( + builder.top_stage, + self.target, + DocumentationFormat::HTML, + )); + builder.run(&mut command); } } @@ -922,7 +919,8 @@ impl Step for RustdocJSNotStd { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.suite_path("tests/rustdoc-js") + let default = run.builder.config.nodejs.is_some(); + run.suite_path("tests/rustdoc-js").default_condition(default) } fn make_run(run: RunConfig<'_>) { @@ -931,18 +929,14 @@ impl Step for RustdocJSNotStd { } fn run(self, builder: &Builder<'_>) { - if builder.config.nodejs.is_some() { - builder.ensure(Compiletest { - compiler: self.compiler, - target: self.target, - mode: "js-doc-test", - suite: "rustdoc-js", - path: "tests/rustdoc-js", - compare_mode: None, - }); - } else { - builder.info("No nodejs found, skipping \"tests/rustdoc-js\" tests"); - } + builder.ensure(Compiletest { + compiler: self.compiler, + target: self.target, + mode: "js-doc-test", + suite: "rustdoc-js", + path: "tests/rustdoc-js", + compare_mode: None, + }); } } @@ -1568,6 +1562,8 @@ note: if you're sure you want to do this, please open an issue as to why. In the if let Some(ref nodejs) = builder.config.nodejs { cmd.arg("--nodejs").arg(nodejs); + } else if mode == "js-doc-test" { + panic!("need nodejs to run js-doc-test suite"); } if let Some(ref npm) = builder.config.npm { cmd.arg("--npm").arg(npm); From 3ce5f6eb44b31a93089db0d46d031b0bd689ba7d Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Thu, 13 Jul 2023 12:00:46 -0700 Subject: [PATCH 9/9] Correct `the` -> `there` typo in items.md --- 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 1e0e60248bfbd..de31e8a8799b3 100644 --- a/src/doc/style-guide/src/items.md +++ b/src/doc/style-guide/src/items.md @@ -282,7 +282,7 @@ impl SomeType { ... If the generics clause must be formatted across multiple lines, each parameter should have its own block-indented line, there should be newlines after the -opening bracket and before the closing bracket, and the should be a trailing +opening bracket and before the closing bracket, and there should be a trailing comma. ```rust