Skip to content

Commit 793d1c3

Browse files
authored
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.
2 parents 24539e2 + 841b30f commit 793d1c3

File tree

4 files changed

+98
-20
lines changed

4 files changed

+98
-20
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3810,6 +3810,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
38103810
{
38113811
if let Some(where_pred) = where_pred.as_trait_clause()
38123812
&& let Some(failed_pred) = failed_pred.as_trait_clause()
3813+
&& where_pred.def_id() == failed_pred.def_id()
38133814
{
38143815
self.enter_forall(where_pred, |where_pred| {
38153816
let failed_pred = self.instantiate_binder_with_fresh_vars(

tests/crashes/126416.rs

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
trait Output<'a> {
2+
type Type;
3+
}
4+
5+
struct Wrapper;
6+
7+
impl Wrapper {
8+
fn do_something_wrapper<O, F>(self, _: F)
9+
//~^ ERROR the trait bound `for<'a> F: Output<'a>` is not satisfied
10+
//~| ERROR the trait bound `for<'a> F: Output<'a>` is not satisfied
11+
where
12+
F: for<'a> FnOnce(<F as Output<'a>>::Type),
13+
//~^ ERROR the trait bound `F: Output<'_>` is not satisfied
14+
//~| ERROR the trait bound `F: Output<'_>` is not satisfied
15+
{
16+
}
17+
}
18+
19+
fn main() {
20+
let mut wrapper = Wrapper;
21+
wrapper.do_something_wrapper(|value| ());
22+
//~^ ERROR expected a `FnOnce
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
error[E0277]: the trait bound `for<'a> F: Output<'a>` is not satisfied
2+
--> $DIR/filter-relevant-fn-bounds.rs:8:5
3+
|
4+
LL | / fn do_something_wrapper<O, F>(self, _: F)
5+
LL | |
6+
LL | |
7+
LL | | where
8+
LL | | F: for<'a> FnOnce(<F as Output<'a>>::Type),
9+
| |___________________________________________________^ the trait `for<'a> Output<'a>` is not implemented for `F`
10+
|
11+
help: consider further restricting this bound
12+
|
13+
LL | F: for<'a> FnOnce(<F as Output<'a>>::Type) + for<'a> Output<'a>,
14+
| ++++++++++++++++++++
15+
16+
error[E0277]: the trait bound `for<'a> F: Output<'a>` is not satisfied
17+
--> $DIR/filter-relevant-fn-bounds.rs:8:8
18+
|
19+
LL | fn do_something_wrapper<O, F>(self, _: F)
20+
| ^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Output<'a>` is not implemented for `F`
21+
|
22+
help: consider further restricting this bound
23+
|
24+
LL | F: for<'a> FnOnce(<F as Output<'a>>::Type) + for<'a> Output<'a>,
25+
| ++++++++++++++++++++
26+
27+
error[E0277]: the trait bound `F: Output<'_>` is not satisfied
28+
--> $DIR/filter-relevant-fn-bounds.rs:12:12
29+
|
30+
LL | F: for<'a> FnOnce(<F as Output<'a>>::Type),
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Output<'_>` is not implemented for `F`
32+
|
33+
help: consider further restricting this bound
34+
|
35+
LL | F: for<'a> FnOnce(<F as Output<'a>>::Type) + Output<'_>,
36+
| ++++++++++++
37+
38+
error[E0277]: the trait bound `F: Output<'_>` is not satisfied
39+
--> $DIR/filter-relevant-fn-bounds.rs:12:20
40+
|
41+
LL | F: for<'a> FnOnce(<F as Output<'a>>::Type),
42+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Output<'_>` is not implemented for `F`
43+
|
44+
help: consider further restricting this bound
45+
|
46+
LL | F: for<'a> FnOnce(<F as Output<'a>>::Type) + Output<'_>,
47+
| ++++++++++++
48+
49+
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}`
50+
--> $DIR/filter-relevant-fn-bounds.rs:21:34
51+
|
52+
LL | wrapper.do_something_wrapper(|value| ());
53+
| -------------------- ^^^^^^^^^^ 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}`
54+
| |
55+
| required by a bound introduced by this call
56+
|
57+
= help: the trait `for<'a> Output<'a>` is not implemented for closure `{closure@$DIR/filter-relevant-fn-bounds.rs:21:34: 21:41}`
58+
help: this trait has no implementations, consider adding one
59+
--> $DIR/filter-relevant-fn-bounds.rs:1:1
60+
|
61+
LL | trait Output<'a> {
62+
| ^^^^^^^^^^^^^^^^
63+
note: required by a bound in `Wrapper::do_something_wrapper`
64+
--> $DIR/filter-relevant-fn-bounds.rs:12:12
65+
|
66+
LL | fn do_something_wrapper<O, F>(self, _: F)
67+
| -------------------- required by a bound in this associated function
68+
...
69+
LL | F: for<'a> FnOnce(<F as Output<'a>>::Type),
70+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Wrapper::do_something_wrapper`
71+
72+
error: aborting due to 5 previous errors
73+
74+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)