From 8b89a1280c929f7aaf11386f8f1a9ecdbef2f539 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Mon, 2 May 2022 08:19:57 +0900 Subject: [PATCH 1/7] Fix incorrect syntax suggestion with `pub async fn` --- .../src/traits/error_reporting/suggestions.rs | 28 +++++--- src/test/ui/suggestions/issue-96555.rs | 19 ++++++ src/test/ui/suggestions/issue-96555.stderr | 66 +++++++++++++++++++ 3 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 src/test/ui/suggestions/issue-96555.rs create mode 100644 src/test/ui/suggestions/issue-96555.stderr diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 446b14a17ae92..09a2560fd465f 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1079,18 +1079,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { self.in_progress_typeck_results.map(|t| t.borrow()) && let ty = typeck_results.expr_ty_adjusted(base) && let ty::FnDef(def_id, _substs) = ty.kind() - && let Some(hir::Node::Item(hir::Item { span, ident, .. })) = + && let Some(hir::Node::Item(hir::Item { ident, span, vis_span, .. })) = hir.get_if_local(*def_id) { - err.span_suggestion_verbose( - span.shrink_to_lo(), - &format!( - "alternatively, consider making `fn {}` asynchronous", - ident - ), - "async ".to_string(), - Applicability::MaybeIncorrect, + let msg = format!( + "alternatively, consider making `fn {}` asynchronous", + ident ); + if vis_span.is_empty() { + err.span_suggestion_verbose( + span.shrink_to_lo(), + &msg, + "async ".to_string(), + Applicability::MaybeIncorrect, + ); + } else { + err.span_suggestion_verbose( + vis_span.shrink_to_hi(), + &msg, + " async".to_string(), + Applicability::MaybeIncorrect, + ); + } } } } diff --git a/src/test/ui/suggestions/issue-96555.rs b/src/test/ui/suggestions/issue-96555.rs new file mode 100644 index 0000000000000..9f0a047c6e9a8 --- /dev/null +++ b/src/test/ui/suggestions/issue-96555.rs @@ -0,0 +1,19 @@ +// edition:2018 + +async fn f() { + m::f1().await; //~ ERROR `()` is not a future + m::f2().await; //~ ERROR `()` is not a future + m::f3().await; //~ ERROR `()` is not a future +} + +mod m { + pub fn f1() {} + + pub(crate) fn f2() {} + + pub + fn + f3() {} +} + +fn main() {} diff --git a/src/test/ui/suggestions/issue-96555.stderr b/src/test/ui/suggestions/issue-96555.stderr new file mode 100644 index 0000000000000..6d3b8844d954f --- /dev/null +++ b/src/test/ui/suggestions/issue-96555.stderr @@ -0,0 +1,66 @@ +error[E0277]: `()` is not a future + --> $DIR/issue-96555.rs:4:12 + | +LL | m::f1().await; + | -------^^^^^^ `()` is not a future + | | + | this call returns `()` + | + = help: the trait `Future` is not implemented for `()` + = note: () must be a future or must implement `IntoFuture` to be awaited + = note: required because of the requirements on the impl of `IntoFuture` for `()` +help: remove the `.await` + | +LL - m::f1().await; +LL + m::f1(); + | +help: alternatively, consider making `fn f1` asynchronous + | +LL | pub async fn f1() {} + | +++++ + +error[E0277]: `()` is not a future + --> $DIR/issue-96555.rs:5:12 + | +LL | m::f2().await; + | -------^^^^^^ `()` is not a future + | | + | this call returns `()` + | + = help: the trait `Future` is not implemented for `()` + = note: () must be a future or must implement `IntoFuture` to be awaited + = note: required because of the requirements on the impl of `IntoFuture` for `()` +help: remove the `.await` + | +LL - m::f2().await; +LL + m::f2(); + | +help: alternatively, consider making `fn f2` asynchronous + | +LL | pub(crate) async fn f2() {} + | +++++ + +error[E0277]: `()` is not a future + --> $DIR/issue-96555.rs:6:12 + | +LL | m::f3().await; + | -------^^^^^^ `()` is not a future + | | + | this call returns `()` + | + = help: the trait `Future` is not implemented for `()` + = note: () must be a future or must implement `IntoFuture` to be awaited + = note: required because of the requirements on the impl of `IntoFuture` for `()` +help: remove the `.await` + | +LL - m::f3().await; +LL + m::f3(); + | +help: alternatively, consider making `fn f3` asynchronous + | +LL | pub async + | +++++ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. From 83f785bff9569ae14d4437e3cf795e1ed88b8195 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 7 May 2022 17:44:30 -0700 Subject: [PATCH 2/7] Further elaborate the lack of guarantees from `Hasher` --- library/core/src/hash/mod.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/library/core/src/hash/mod.rs b/library/core/src/hash/mod.rs index 9d64c786d67b5..3d168f62a09f5 100644 --- a/library/core/src/hash/mod.rs +++ b/library/core/src/hash/mod.rs @@ -268,10 +268,29 @@ pub use macros::Hash; /// instance (with [`write`] and [`write_u8`] etc.). Most of the time, `Hasher` /// instances are used in conjunction with the [`Hash`] trait. /// -/// This trait makes no assumptions about how the various `write_*` methods are +/// This trait provides no guarantees about how the various `write_*` methods are /// defined and implementations of [`Hash`] should not assume that they work one /// way or another. You cannot assume, for example, that a [`write_u32`] call is -/// equivalent to four calls of [`write_u8`]. +/// equivalent to four calls of [`write_u8`]. Nor can you assume that adjacent +/// `write` calls are merged, so it's possible, for example, that +/// ``` +/// # fn foo(hasher: &mut impl std::hash::Hasher) { +/// hasher.write(&[1, 2]); +/// hasher.write(&[3, 4, 5, 6]); +/// # } +/// ``` +/// and +/// ``` +/// # fn foo(hasher: &mut impl std::hash::Hasher) { +/// hasher.write(&[1, 2, 3, 4]); +/// hasher.write(&[5, 6]); +/// # } +/// ``` +/// end up producing different hashes. +/// +/// Thus to produce the same hash value, [`Hash`] implementations must ensure +/// for equivalent items that exactly the same sequence of calls is made -- the +/// same methods with the same parameters in the same order. /// /// # Examples /// From c64cf2735605a27b8276649d660f93b5ce232b0c Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 8 May 2022 10:54:38 +0900 Subject: [PATCH 3/7] Fix the `x.py clippy` command --- src/bootstrap/builder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index bc5af79e0c65f..7d838c0a61d22 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -534,7 +534,7 @@ impl<'a> Builder<'a> { native::Lld, native::CrtBeginEnd ), - Kind::Check => describe!( + Kind::Check | Kind::Clippy | Kind::Fix => describe!( check::Std, check::Rustc, check::Rustdoc, @@ -664,7 +664,7 @@ impl<'a> Builder<'a> { ), Kind::Run => describe!(run::ExpandYamlAnchors, run::BuildManifest, run::BumpStage0), // These commands either don't use paths, or they're special-cased in Build::build() - Kind::Clean | Kind::Clippy | Kind::Fix | Kind::Format | Kind::Setup => vec![], + Kind::Clean | Kind::Format | Kind::Setup => vec![], } } From a911452787269051dc17fdd84aa94276a877a3a9 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 8 May 2022 11:27:43 +0900 Subject: [PATCH 4/7] Add regression test for #96654 --- src/test/ui/const-generics/issues/issue-96654.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/test/ui/const-generics/issues/issue-96654.rs diff --git a/src/test/ui/const-generics/issues/issue-96654.rs b/src/test/ui/const-generics/issues/issue-96654.rs new file mode 100644 index 0000000000000..8cf786dbe40bf --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-96654.rs @@ -0,0 +1,15 @@ +// check-pass + +struct A {} + +struct B {} + +impl B { + const M: u32 = M; +} + +struct C { + a: A<{ B::<1>::M }>, +} + +fn main() {} From 2c9074b78ae48a8a4d45c03305fd190cee4c50d9 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 8 May 2022 11:28:18 +0900 Subject: [PATCH 5/7] Correct the issue number of a test --- .../const-generics/issues/{issue-775377.rs => issue-77357.rs} | 0 .../issues/{issue-775377.stderr => issue-77357.stderr} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/test/ui/const-generics/issues/{issue-775377.rs => issue-77357.rs} (100%) rename src/test/ui/const-generics/issues/{issue-775377.stderr => issue-77357.stderr} (92%) diff --git a/src/test/ui/const-generics/issues/issue-775377.rs b/src/test/ui/const-generics/issues/issue-77357.rs similarity index 100% rename from src/test/ui/const-generics/issues/issue-775377.rs rename to src/test/ui/const-generics/issues/issue-77357.rs diff --git a/src/test/ui/const-generics/issues/issue-775377.stderr b/src/test/ui/const-generics/issues/issue-77357.stderr similarity index 92% rename from src/test/ui/const-generics/issues/issue-775377.stderr rename to src/test/ui/const-generics/issues/issue-77357.stderr index 83946df4203d8..804c0ae5175a8 100644 --- a/src/test/ui/const-generics/issues/issue-775377.stderr +++ b/src/test/ui/const-generics/issues/issue-77357.stderr @@ -1,5 +1,5 @@ error: overly complex generic constant - --> $DIR/issue-775377.rs:6:46 + --> $DIR/issue-77357.rs:6:46 | LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { | ^^^^^^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constant From b7e51163755f2f57de5c906f361b0686f6bfb1a5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 8 May 2022 14:07:25 +0200 Subject: [PATCH 6/7] Enforce linebreak style in js source code --- src/librustdoc/html/static/.eslintrc.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/html/static/.eslintrc.js b/src/librustdoc/html/static/.eslintrc.js index 5fcffe715b12f..f6f0545f3bb4a 100644 --- a/src/librustdoc/html/static/.eslintrc.js +++ b/src/librustdoc/html/static/.eslintrc.js @@ -21,6 +21,10 @@ module.exports = { "error", "double" ], + "linebreak-style": [ + "error", + "unix" + ], "no-var": ["error"], "prefer-const": ["error"], "prefer-arrow-callback": ["error"], From 1e93165b052814f87b0bbdb84c6db769297d8621 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 8 May 2022 14:08:33 +0200 Subject: [PATCH 7/7] Enforce no trailing spaces with eslint --- src/librustdoc/html/static/.eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustdoc/html/static/.eslintrc.js b/src/librustdoc/html/static/.eslintrc.js index f6f0545f3bb4a..52577b228aa13 100644 --- a/src/librustdoc/html/static/.eslintrc.js +++ b/src/librustdoc/html/static/.eslintrc.js @@ -25,6 +25,7 @@ module.exports = { "error", "unix" ], + "no-trailing-spaces": "error", "no-var": ["error"], "prefer-const": ["error"], "prefer-arrow-callback": ["error"],