about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <t.gross35@gmail.com>2024-07-16 02:02:25 -0500
committerGitHub <noreply@github.com>2024-07-16 02:02:25 -0500
commit1abed9fa068ea76cc048e1fc629fd59e69fb54b4 (patch)
tree15378f16c39e6c0b275a0247bb7dbc3d07cbae03
parent7f8e0e6ef3cec356be0d78deec314f91d9c9459b (diff)
parent841b30f63ea1592f40a906ed1400c1999b89b4ee (diff)
downloadrust-1abed9fa068ea76cc048e1fc629fd59e69fb54b4.tar.gz
rust-1abed9fa068ea76cc048e1fc629fd59e69fb54b4.zip
Rollup merge of #127780 - compiler-errors:zip-args, r=jieyouxu
Make sure trait def ids match before zipping args in `note_function_argument_obligation`

Fixes #126416
Fixes #127745

Didn't add both tests b/c I felt like it was unnecessary.
-rw-r--r--compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs1
-rw-r--r--tests/crashes/126416.rs20
-rw-r--r--tests/ui/methods/filter-relevant-fn-bounds.rs23
-rw-r--r--tests/ui/methods/filter-relevant-fn-bounds.stderr74
4 files changed, 98 insertions, 20 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
index 2cf808f962f..f8843b892db 100644
--- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
@@ -3810,6 +3810,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
             {
                 if let Some(where_pred) = where_pred.as_trait_clause()
                     && let Some(failed_pred) = failed_pred.as_trait_clause()
+                    && where_pred.def_id() == failed_pred.def_id()
                 {
                     self.enter_forall(where_pred, |where_pred| {
                         let failed_pred = self.instantiate_binder_with_fresh_vars(
diff --git a/tests/crashes/126416.rs b/tests/crashes/126416.rs
deleted file mode 100644
index 9b6c5169d44..00000000000
--- a/tests/crashes/126416.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-//@ known-bug: rust-lang/rust#126416
-
-trait Output<'a, T: 'a> {
-    type Type;
-}
-
-struct Wrapper;
-
-impl Wrapper {
-    fn do_something_wrapper<O, F>(&mut self, _: F)
-    where
-        F: for<'a> FnOnce(<F as Output<i32>>::Type),
-    {
-    }
-}
-
-fn main() {
-    let mut wrapper = Wrapper;
-    wrapper.do_something_wrapper(|value| ());
-}
diff --git a/tests/ui/methods/filter-relevant-fn-bounds.rs b/tests/ui/methods/filter-relevant-fn-bounds.rs
new file mode 100644
index 00000000000..76ececf7baa
--- /dev/null
+++ b/tests/ui/methods/filter-relevant-fn-bounds.rs
@@ -0,0 +1,23 @@
+trait Output<'a> {
+    type Type;
+}
+
+struct Wrapper;
+
+impl Wrapper {
+    fn do_something_wrapper<O, F>(self, _: F)
+    //~^ ERROR the trait bound `for<'a> F: Output<'a>` is not satisfied
+    //~| ERROR the trait bound `for<'a> F: Output<'a>` is not satisfied
+    where
+        F: for<'a> FnOnce(<F as Output<'a>>::Type),
+        //~^ ERROR the trait bound `F: Output<'_>` is not satisfied
+        //~| ERROR the trait bound `F: Output<'_>` is not satisfied
+    {
+    }
+}
+
+fn main() {
+    let mut wrapper = Wrapper;
+    wrapper.do_something_wrapper(|value| ());
+    //~^ ERROR expected a `FnOnce
+}
diff --git a/tests/ui/methods/filter-relevant-fn-bounds.stderr b/tests/ui/methods/filter-relevant-fn-bounds.stderr
new file mode 100644
index 00000000000..b737c0ab11f
--- /dev/null
+++ b/tests/ui/methods/filter-relevant-fn-bounds.stderr
@@ -0,0 +1,74 @@
+error[E0277]: the trait bound `for<'a> F: Output<'a>` is not satisfied
+  --> $DIR/filter-relevant-fn-bounds.rs:8:5
+   |
+LL | /     fn do_something_wrapper<O, F>(self, _: F)
+LL | |
+LL | |
+LL | |     where
+LL | |         F: for<'a> FnOnce(<F as Output<'a>>::Type),
+   | |___________________________________________________^ the trait `for<'a> Output<'a>` is not implemented for `F`
+   |
+help: consider further restricting this bound
+   |
+LL |         F: for<'a> FnOnce(<F as Output<'a>>::Type) + for<'a> Output<'a>,
+   |                                                    ++++++++++++++++++++
+
+error[E0277]: the trait bound `for<'a> F: Output<'a>` is not satisfied
+  --> $DIR/filter-relevant-fn-bounds.rs:8:8
+   |
+LL |     fn do_something_wrapper<O, F>(self, _: F)
+   |        ^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Output<'a>` is not implemented for `F`
+   |
+help: consider further restricting this bound
+   |
+LL |         F: for<'a> FnOnce(<F as Output<'a>>::Type) + for<'a> Output<'a>,
+   |                                                    ++++++++++++++++++++
+
+error[E0277]: the trait bound `F: Output<'_>` is not satisfied
+  --> $DIR/filter-relevant-fn-bounds.rs:12:12
+   |
+LL |         F: for<'a> FnOnce(<F as Output<'a>>::Type),
+   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Output<'_>` is not implemented for `F`
+   |
+help: consider further restricting this bound
+   |
+LL |         F: for<'a> FnOnce(<F as Output<'a>>::Type) + Output<'_>,
+   |                                                    ++++++++++++
+
+error[E0277]: the trait bound `F: Output<'_>` is not satisfied
+  --> $DIR/filter-relevant-fn-bounds.rs:12:20
+   |
+LL |         F: for<'a> FnOnce(<F as Output<'a>>::Type),
+   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Output<'_>` is not implemented for `F`
+   |
+help: consider further restricting this bound
+   |
+LL |         F: for<'a> FnOnce(<F as Output<'a>>::Type) + Output<'_>,
+   |                                                    ++++++++++++
+
+error[E0277]: expected a `FnOnce(<{closure@$DIR/filter-relevant-fn-bounds.rs:21:34: 21:41} as Output<'a>>::Type)` closure, found `{closure@$DIR/filter-relevant-fn-bounds.rs:21:34: 21:41}`
+  --> $DIR/filter-relevant-fn-bounds.rs:21:34
+   |
+LL |     wrapper.do_something_wrapper(|value| ());
+   |             -------------------- ^^^^^^^^^^ expected an `FnOnce(<{closure@$DIR/filter-relevant-fn-bounds.rs:21:34: 21:41} as Output<'a>>::Type)` closure, found `{closure@$DIR/filter-relevant-fn-bounds.rs:21:34: 21:41}`
+   |             |
+   |             required by a bound introduced by this call
+   |
+   = help: the trait `for<'a> Output<'a>` is not implemented for closure `{closure@$DIR/filter-relevant-fn-bounds.rs:21:34: 21:41}`
+help: this trait has no implementations, consider adding one
+  --> $DIR/filter-relevant-fn-bounds.rs:1:1
+   |
+LL | trait Output<'a> {
+   | ^^^^^^^^^^^^^^^^
+note: required by a bound in `Wrapper::do_something_wrapper`
+  --> $DIR/filter-relevant-fn-bounds.rs:12:12
+   |
+LL |     fn do_something_wrapper<O, F>(self, _: F)
+   |        -------------------- required by a bound in this associated function
+...
+LL |         F: for<'a> FnOnce(<F as Output<'a>>::Type),
+   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Wrapper::do_something_wrapper`
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0277`.