Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 39f220c

Browse files
committedAug 16, 2021
Use note to point at bound introducing requirement
1 parent 92f3753 commit 39f220c

File tree

333 files changed

+3164
-1922
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

333 files changed

+3164
-1922
lines changed
 

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
19621962
}
19631963
ObligationCauseCode::BindingObligation(item_def_id, span) => {
19641964
let item_name = tcx.def_path_str(item_def_id);
1965-
let msg = format!("required by this bound in `{}`", item_name);
1965+
let mut multispan = MultiSpan::from(span);
19661966
if let Some(ident) = tcx.opt_item_name(item_def_id) {
19671967
let sm = tcx.sess.source_map();
19681968
let same_line =
@@ -1971,16 +1971,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
19711971
_ => true,
19721972
};
19731973
if !ident.span.overlaps(span) && !same_line {
1974-
err.span_label(ident.span, "required by a bound in this");
1974+
multispan
1975+
.push_span_label(ident.span, "required by a bound in this".to_string());
19751976
}
19761977
}
1978+
let descr = format!("required by a bound in `{}`", item_name);
19771979
if span != DUMMY_SP {
1978-
err.span_label(span, &msg);
1980+
let msg = format!("required by this bound in `{}`", item_name);
1981+
multispan.push_span_label(span, msg);
1982+
err.span_note(multispan, &descr);
19791983
} else {
1980-
err.span_note(
1981-
tcx.def_span(item_def_id),
1982-
&format!("required by a bound in `{}`", item_name),
1983-
);
1984+
err.span_note(tcx.def_span(item_def_id), &descr);
19841985
}
19851986
}
19861987
ObligationCauseCode::ObjectCastObligation(object_ty) => {

‎src/test/ui/anonymous-higher-ranked-lifetime.stderr

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ LL | f1(|_: (), _: ()| {});
55
| ^^ -------------- found signature of `fn((), ()) -> _`
66
| |
77
| expected signature of `for<'r, 's> fn(&'r (), &'s ()) -> _`
8-
...
8+
|
9+
note: required by a bound in `f1`
10+
--> $DIR/anonymous-higher-ranked-lifetime.rs:16:25
11+
|
912
LL | fn f1<F>(_: F) where F: Fn(&(), &()) {}
10-
| ------------ required by this bound in `f1`
13+
| ^^^^^^^^^^^^ required by this bound in `f1`
1114

1215
error[E0631]: type mismatch in closure arguments
1316
--> $DIR/anonymous-higher-ranked-lifetime.rs:3:5
@@ -16,9 +19,12 @@ LL | f2(|_: (), _: ()| {});
1619
| ^^ -------------- found signature of `fn((), ()) -> _`
1720
| |
1821
| expected signature of `for<'a, 'r> fn(&'a (), &'r ()) -> _`
19-
...
22+
|
23+
note: required by a bound in `f2`
24+
--> $DIR/anonymous-higher-ranked-lifetime.rs:17:25
25+
|
2026
LL | fn f2<F>(_: F) where F: for<'a> Fn(&'a (), &()) {}
21-
| ----------------------- required by this bound in `f2`
27+
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f2`
2228

2329
error[E0631]: type mismatch in closure arguments
2430
--> $DIR/anonymous-higher-ranked-lifetime.rs:4:5
@@ -27,9 +33,12 @@ LL | f3(|_: (), _: ()| {});
2733
| ^^ -------------- found signature of `fn((), ()) -> _`
2834
| |
2935
| expected signature of `for<'r> fn(&(), &'r ()) -> _`
30-
...
36+
|
37+
note: required by a bound in `f3`
38+
--> $DIR/anonymous-higher-ranked-lifetime.rs:18:29
39+
|
3140
LL | fn f3<'a, F>(_: F) where F: Fn(&'a (), &()) {}
32-
| --------------- required by this bound in `f3`
41+
| ^^^^^^^^^^^^^^^ required by this bound in `f3`
3342

3443
error[E0631]: type mismatch in closure arguments
3544
--> $DIR/anonymous-higher-ranked-lifetime.rs:5:5
@@ -38,9 +47,12 @@ LL | f4(|_: (), _: ()| {});
3847
| ^^ -------------- found signature of `fn((), ()) -> _`
3948
| |
4049
| expected signature of `for<'s, 'r> fn(&'s (), &'r ()) -> _`
41-
...
50+
|
51+
note: required by a bound in `f4`
52+
--> $DIR/anonymous-higher-ranked-lifetime.rs:19:25
53+
|
4254
LL | fn f4<F>(_: F) where F: for<'r> Fn(&(), &'r ()) {}
43-
| ----------------------- required by this bound in `f4`
55+
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f4`
4456

4557
error[E0631]: type mismatch in closure arguments
4658
--> $DIR/anonymous-higher-ranked-lifetime.rs:6:5
@@ -49,9 +61,12 @@ LL | f5(|_: (), _: ()| {});
4961
| ^^ -------------- found signature of `fn((), ()) -> _`
5062
| |
5163
| expected signature of `for<'r> fn(&'r (), &'r ()) -> _`
52-
...
64+
|
65+
note: required by a bound in `f5`
66+
--> $DIR/anonymous-higher-ranked-lifetime.rs:20:25
67+
|
5368
LL | fn f5<F>(_: F) where F: for<'r> Fn(&'r (), &'r ()) {}
54-
| -------------------------- required by this bound in `f5`
69+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f5`
5570

5671
error[E0631]: type mismatch in closure arguments
5772
--> $DIR/anonymous-higher-ranked-lifetime.rs:7:5
@@ -60,9 +75,12 @@ LL | g1(|_: (), _: ()| {});
6075
| ^^ -------------- found signature of `fn((), ()) -> _`
6176
| |
6277
| expected signature of `for<'r> fn(&'r (), Box<(dyn for<'s> Fn(&'s ()) + 'static)>) -> _`
63-
...
78+
|
79+
note: required by a bound in `g1`
80+
--> $DIR/anonymous-higher-ranked-lifetime.rs:23:25
81+
|
6482
LL | fn g1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>) {}
65-
| ------------------------- required by this bound in `g1`
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g1`
6684

6785
error[E0631]: type mismatch in closure arguments
6886
--> $DIR/anonymous-higher-ranked-lifetime.rs:8:5
@@ -71,9 +89,12 @@ LL | g2(|_: (), _: ()| {});
7189
| ^^ -------------- found signature of `fn((), ()) -> _`
7290
| |
7391
| expected signature of `for<'r> fn(&'r (), for<'s> fn(&'s ())) -> _`
74-
...
92+
|
93+
note: required by a bound in `g2`
94+
--> $DIR/anonymous-higher-ranked-lifetime.rs:24:25
95+
|
7596
LL | fn g2<F>(_: F) where F: Fn(&(), fn(&())) {}
76-
| ---------------- required by this bound in `g2`
97+
| ^^^^^^^^^^^^^^^^ required by this bound in `g2`
7798

7899
error[E0631]: type mismatch in closure arguments
79100
--> $DIR/anonymous-higher-ranked-lifetime.rs:9:5
@@ -82,9 +103,12 @@ LL | g3(|_: (), _: ()| {});
82103
| ^^ -------------- found signature of `fn((), ()) -> _`
83104
| |
84105
| expected signature of `for<'s> fn(&'s (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>) -> _`
85-
...
106+
|
107+
note: required by a bound in `g3`
108+
--> $DIR/anonymous-higher-ranked-lifetime.rs:25:25
109+
|
86110
LL | fn g3<F>(_: F) where F: for<'s> Fn(&'s (), Box<dyn Fn(&())>) {}
87-
| ------------------------------------ required by this bound in `g3`
111+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g3`
88112

89113
error[E0631]: type mismatch in closure arguments
90114
--> $DIR/anonymous-higher-ranked-lifetime.rs:10:5
@@ -93,9 +117,12 @@ LL | g4(|_: (), _: ()| {});
93117
| ^^ -------------- found signature of `fn((), ()) -> _`
94118
| |
95119
| expected signature of `for<'s> fn(&'s (), for<'r> fn(&'r ())) -> _`
96-
...
120+
|
121+
note: required by a bound in `g4`
122+
--> $DIR/anonymous-higher-ranked-lifetime.rs:26:25
123+
|
97124
LL | fn g4<F>(_: F) where F: Fn(&(), for<'r> fn(&'r ())) {}
98-
| --------------------------- required by this bound in `g4`
125+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g4`
99126

100127
error[E0631]: type mismatch in closure arguments
101128
--> $DIR/anonymous-higher-ranked-lifetime.rs:11:5
@@ -104,9 +131,12 @@ LL | h1(|_: (), _: (), _: (), _: ()| {});
104131
| ^^ ---------------------------- found signature of `fn((), (), (), ()) -> _`
105132
| |
106133
| expected signature of `for<'r, 's> fn(&'r (), Box<(dyn for<'t0> Fn(&'t0 ()) + 'static)>, &'s (), for<'t0, 't1> fn(&'t0 (), &'t1 ())) -> _`
107-
...
134+
|
135+
note: required by a bound in `h1`
136+
--> $DIR/anonymous-higher-ranked-lifetime.rs:29:25
137+
|
108138
LL | fn h1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>, &(), fn(&(), &())) {}
109-
| -------------------------------------------- required by this bound in `h1`
139+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h1`
110140

111141
error[E0631]: type mismatch in closure arguments
112142
--> $DIR/anonymous-higher-ranked-lifetime.rs:12:5
@@ -115,9 +145,12 @@ LL | h2(|_: (), _: (), _: (), _: ()| {});
115145
| ^^ ---------------------------- found signature of `fn((), (), (), ()) -> _`
116146
| |
117147
| expected signature of `for<'r, 't0> fn(&'r (), Box<(dyn for<'s> Fn(&'s ()) + 'static)>, &'t0 (), for<'s, 't1> fn(&'s (), &'t1 ())) -> _`
118-
...
148+
|
149+
note: required by a bound in `h2`
150+
--> $DIR/anonymous-higher-ranked-lifetime.rs:30:25
151+
|
119152
LL | fn h2<F>(_: F) where F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(), &())) {}
120-
| --------------------------------------------------------- required by this bound in `h2`
153+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h2`
121154

122155
error: aborting due to 11 previous errors
123156

0 commit comments

Comments
 (0)