From f8c10ff8b7da40868ceb085e7d85d8adcce2c764 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Thu, 17 Jun 2021 14:48:19 +0200 Subject: [PATCH] Remove invalid suggestion involving Fn trait bound --- .../src/traits/error_reporting/mod.rs | 1 + src/test/ui/traits/issue-85735.rs | 13 +++++++++++++ src/test/ui/traits/issue-85735.stderr | 16 ++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/test/ui/traits/issue-85735.rs create mode 100644 src/test/ui/traits/issue-85735.stderr diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index f46fae1326c8f..3f713ce3c3914 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1604,6 +1604,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { if generics.params.iter().any(|p| p.name != kw::SelfUpper) && !snippet.ends_with('>') && !generics.has_impl_trait() + && !self.tcx.fn_trait_kind_from_lang_item(*def_id).is_some() { // FIXME: To avoid spurious suggestions in functions where type arguments // where already supplied, we check the snippet to make sure it doesn't diff --git a/src/test/ui/traits/issue-85735.rs b/src/test/ui/traits/issue-85735.rs new file mode 100644 index 0000000000000..16e874ee21e62 --- /dev/null +++ b/src/test/ui/traits/issue-85735.rs @@ -0,0 +1,13 @@ +// Regression test for the invalid suggestion in #85735 (the +// underlying issue #21974 still exists here). + +trait Foo {} +impl<'a, 'b, T> Foo for T +where + T: FnMut(&'a ()), + //~^ ERROR: type annotations needed [E0283] + T: FnMut(&'b ()), +{ +} + +fn main() {} diff --git a/src/test/ui/traits/issue-85735.stderr b/src/test/ui/traits/issue-85735.stderr new file mode 100644 index 0000000000000..8c958e3844cbe --- /dev/null +++ b/src/test/ui/traits/issue-85735.stderr @@ -0,0 +1,16 @@ +error[E0283]: type annotations needed + --> $DIR/issue-85735.rs:7:8 + | +LL | T: FnMut(&'a ()), + | ^^^^^^^^^^^^^ cannot infer type for type parameter `T` + | + ::: $SRC_DIR/core/src/ops/function.rs:LL:COL + | +LL | pub trait FnMut: FnOnce { + | ----------------------------------- required by this bound in `FnMut` + | + = note: cannot satisfy `T: FnMut<(&'a (),)>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0283`.