Skip to content

Commit d9a5419

Browse files
committed
Add label to item source of bound obligation
1 parent ce936e9 commit d9a5419

32 files changed

+61
-61
lines changed

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1532,14 +1532,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
15321532
let item_name = tcx.def_path_str(item_def_id);
15331533
let msg = format!("required by this bound in `{}`", item_name);
15341534
if let Some(ident) = tcx.opt_item_name(item_def_id) {
1535-
let sm = self.tcx.sess.source_map();
1535+
let sm = tcx.sess.source_map();
15361536
let same_line =
15371537
match (sm.lookup_line(ident.span.hi()), sm.lookup_line(span.lo())) {
15381538
(Ok(l), Ok(r)) => l.line == r.line,
15391539
_ => true,
15401540
};
15411541
if !ident.span.overlaps(span) && !same_line {
1542-
err.span_label(ident.span, "");
1542+
err.span_label(ident.span, "required by a bound in this");
15431543
}
15441544
}
15451545
if span != DUMMY_SP {

src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: `<L1 as Lam<&'a u8>>::App` doesn't implement `std::fmt::Debug`
22
--> $DIR/bad-bounds-on-assoc-in-trait.rs:31:6
33
|
44
LL | trait Case1 {
5-
| -----
5+
| ----- required by a bound in this
66
...
77
LL | Debug
88
| ----- required by this bound in `Case1`
@@ -26,7 +26,7 @@ error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be sent be
2626
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20
2727
|
2828
LL | trait Case1 {
29-
| -----
29+
| ----- required by a bound in this
3030
LL | type C: Clone + Iterator<Item:
3131
LL | Send + Iterator<Item:
3232
| ---- required by this bound in `Case1`
@@ -42,7 +42,7 @@ error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be shared
4242
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20
4343
|
4444
LL | trait Case1 {
45-
| -----
45+
| ----- required by a bound in this
4646
...
4747
LL | > + Sync>;
4848
| ---- required by this bound in `Case1`
@@ -58,7 +58,7 @@ error[E0277]: `<_ as Lam<&'a u8>>::App` doesn't implement `std::fmt::Debug`
5858
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:20
5959
|
6060
LL | trait Case1 {
61-
| -----
61+
| ----- required by a bound in this
6262
...
6363
LL | Debug
6464
| ----- required by this bound in `Case1`

src/test/ui/associated-types/associated-types-eq-hr.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `for<'x> <UintStruct as TheTrait<&'x isize
22
--> $DIR/associated-types-eq-hr.rs:82:5
33
|
44
LL | fn foo<T>()
5-
| ---
5+
| --- required by a bound in this
66
LL | where T : for<'x> TheTrait<&'x isize, A = &'x isize>
77
| ------------- required by this bound in `foo`
88
...
@@ -16,7 +16,7 @@ error[E0271]: type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>
1616
--> $DIR/associated-types-eq-hr.rs:86:5
1717
|
1818
LL | fn bar<T>()
19-
| ---
19+
| --- required by a bound in this
2020
LL | where T : for<'x> TheTrait<&'x isize, A = &'x usize>
2121
| ------------- required by this bound in `bar`
2222
...
@@ -30,7 +30,7 @@ error[E0277]: the trait bound `for<'x, 'y> Tuple: TheTrait<(&'x isize, &'y isize
3030
--> $DIR/associated-types-eq-hr.rs:91:17
3131
|
3232
LL | fn tuple_one<T>()
33-
| ---------
33+
| --------- required by a bound in this
3434
LL | where T : for<'x,'y> TheTrait<(&'x isize, &'y isize), A = &'x isize>
3535
| ---------------------------------------------------------- required by this bound in `tuple_one`
3636
...
@@ -44,7 +44,7 @@ error[E0271]: type mismatch resolving `for<'x, 'y> <Tuple as TheTrait<(&'x isize
4444
--> $DIR/associated-types-eq-hr.rs:91:5
4545
|
4646
LL | fn tuple_one<T>()
47-
| ---------
47+
| --------- required by a bound in this
4848
LL | where T : for<'x,'y> TheTrait<(&'x isize, &'y isize), A = &'x isize>
4949
| ------------- required by this bound in `tuple_one`
5050
...
@@ -55,7 +55,7 @@ error[E0277]: the trait bound `for<'x, 'y> Tuple: TheTrait<(&'x isize, &'y isize
5555
--> $DIR/associated-types-eq-hr.rs:97:17
5656
|
5757
LL | fn tuple_two<T>()
58-
| ---------
58+
| --------- required by a bound in this
5959
LL | where T : for<'x,'y> TheTrait<(&'x isize, &'y isize), A = &'y isize>
6060
| ---------------------------------------------------------- required by this bound in `tuple_two`
6161
...
@@ -69,7 +69,7 @@ error[E0271]: type mismatch resolving `for<'x, 'y> <Tuple as TheTrait<(&'x isize
6969
--> $DIR/associated-types-eq-hr.rs:97:5
7070
|
7171
LL | fn tuple_two<T>()
72-
| ---------
72+
| --------- required by a bound in this
7373
LL | where T : for<'x,'y> TheTrait<(&'x isize, &'y isize), A = &'y isize>
7474
| ------------- required by this bound in `tuple_two`
7575
...
@@ -80,7 +80,7 @@ error[E0277]: the trait bound `for<'x, 'y> Tuple: TheTrait<(&'x isize, &'y isize
8080
--> $DIR/associated-types-eq-hr.rs:107:18
8181
|
8282
LL | fn tuple_four<T>()
83-
| ----------
83+
| ---------- required by a bound in this
8484
LL | where T : for<'x,'y> TheTrait<(&'x isize, &'y isize)>
8585
| ------------------------------------------- required by this bound in `tuple_four`
8686
...

src/test/ui/associated-types/defaults-unsound-62211-1.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ error[E0277]: `T` doesn't implement `std::fmt::Display`
4343
--> $DIR/defaults-unsound-62211-1.rs:41:9
4444
|
4545
LL | trait UncheckedCopy: Sized {
46-
| -------------
46+
| ------------- required by a bound in this
4747
...
4848
LL | + Display = Self;
4949
| ------- required by this bound in `UncheckedCopy`
@@ -62,7 +62,7 @@ error[E0277]: the trait bound `T: std::ops::Deref` is not satisfied
6262
--> $DIR/defaults-unsound-62211-1.rs:41:9
6363
|
6464
LL | trait UncheckedCopy: Sized {
65-
| -------------
65+
| ------------- required by a bound in this
6666
...
6767
LL | + Deref<Target = str>
6868
| ------------------- required by this bound in `UncheckedCopy`
@@ -79,7 +79,7 @@ error[E0277]: cannot add-assign `&'static str` to `T`
7979
--> $DIR/defaults-unsound-62211-1.rs:41:9
8080
|
8181
LL | trait UncheckedCopy: Sized {
82-
| -------------
82+
| ------------- required by a bound in this
8383
...
8484
LL | + AddAssign<&'static str>
8585
| ----------------------- required by this bound in `UncheckedCopy`
@@ -97,7 +97,7 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
9797
--> $DIR/defaults-unsound-62211-1.rs:41:9
9898
|
9999
LL | trait UncheckedCopy: Sized {
100-
| -------------
100+
| ------------- required by a bound in this
101101
...
102102
LL | type Output: Copy
103103
| ---- required by this bound in `UncheckedCopy`

src/test/ui/associated-types/defaults-unsound-62211-2.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ error[E0277]: `T` doesn't implement `std::fmt::Display`
4343
--> $DIR/defaults-unsound-62211-2.rs:41:9
4444
|
4545
LL | trait UncheckedCopy: Sized {
46-
| -------------
46+
| ------------- required by a bound in this
4747
...
4848
LL | + Display = Self;
4949
| ------- required by this bound in `UncheckedCopy`
@@ -62,7 +62,7 @@ error[E0277]: the trait bound `T: std::ops::Deref` is not satisfied
6262
--> $DIR/defaults-unsound-62211-2.rs:41:9
6363
|
6464
LL | trait UncheckedCopy: Sized {
65-
| -------------
65+
| ------------- required by a bound in this
6666
...
6767
LL | + Deref<Target = str>
6868
| ------------------- required by this bound in `UncheckedCopy`
@@ -79,7 +79,7 @@ error[E0277]: cannot add-assign `&'static str` to `T`
7979
--> $DIR/defaults-unsound-62211-2.rs:41:9
8080
|
8181
LL | trait UncheckedCopy: Sized {
82-
| -------------
82+
| ------------- required by a bound in this
8383
...
8484
LL | + AddAssign<&'static str>
8585
| ----------------------- required by this bound in `UncheckedCopy`
@@ -97,7 +97,7 @@ error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
9797
--> $DIR/defaults-unsound-62211-2.rs:41:9
9898
|
9999
LL | trait UncheckedCopy: Sized {
100-
| -------------
100+
| ------------- required by a bound in this
101101
...
102102
LL | type Output: Copy
103103
| ---- required by this bound in `UncheckedCopy`

src/test/ui/associated-types/higher-ranked-projection.bad.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `for<'a> <&'a _ as Mirror>::Image == _`
22
--> $DIR/higher-ranked-projection.rs:25:5
33
|
44
LL | fn foo<U, T>(_t: T)
5-
| ---
5+
| --- required by a bound in this
66
LL | where for<'a> &'a T: Mirror<Image=U>
77
| ------- required by this bound in `foo`
88
...

src/test/ui/associated-types/issue-43924.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0277]: the trait bound `(dyn std::string::ToString + 'static): std::defau
1010
--> $DIR/issue-43924.rs:10:6
1111
|
1212
LL | trait Foo<T: Default + ToString> {
13-
| ---
13+
| --- required by a bound in this
1414
LL | type Out: Default + ToString + ?Sized = dyn ToString;
1515
| ------- required by this bound in `Foo`
1616
...
@@ -21,7 +21,7 @@ error[E0277]: the trait bound `(dyn std::string::ToString + 'static): std::defau
2121
--> $DIR/issue-43924.rs:11:6
2222
|
2323
LL | trait Foo<T: Default + ToString> {
24-
| ---
24+
| --- required by a bound in this
2525
LL | type Out: Default + ToString + ?Sized = dyn ToString;
2626
| ------- required by this bound in `Foo`
2727
...

src/test/ui/associated-types/issue-65774-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0277]: the trait bound `T: MyDisplay` is not satisfied
1010
--> $DIR/issue-65774-1.rs:16:6
1111
|
1212
LL | trait MPU {
13-
| ---
13+
| --- required by a bound in this
1414
LL | type MpuConfig: MyDisplay = T;
1515
| --------- required by this bound in `MPU`
1616
...

src/test/ui/associated-types/issue-65774-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0277]: the trait bound `T: MyDisplay` is not satisfied
1010
--> $DIR/issue-65774-2.rs:16:6
1111
|
1212
LL | trait MPU {
13-
| ---
13+
| --- required by a bound in this
1414
LL | type MpuConfig: MyDisplay = T;
1515
| --------- required by this bound in `MPU`
1616
...

src/test/ui/associated-types/point-at-type-on-obligation-failure-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `bool: Bar` is not satisfied
22
--> $DIR/point-at-type-on-obligation-failure-2.rs:8:18
33
|
44
LL | trait Foo {
5-
| ---
5+
| --- required by a bound in this
66
LL | type Assoc: Bar;
77
| --- required by this bound in `Foo`
88
...

src/test/ui/closure-expected-type/expect-fn-supply-fn.nll.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0631]: type mismatch in closure arguments
22
--> $DIR/expect-fn-supply-fn.rs:30:5
33
|
44
LL | fn with_closure_expecting_fn_with_free_region<F>(_: F)
5-
| ------------------------------------------
5+
| ------------------------------------------ required by a bound in this
66
LL | where F: for<'a> FnOnce(fn(&'a u32), &i32)
77
| ------------------------- required by this bound in `with_closure_expecting_fn_with_free_region`
88
...
@@ -15,7 +15,7 @@ error[E0631]: type mismatch in closure arguments
1515
--> $DIR/expect-fn-supply-fn.rs:37:5
1616
|
1717
LL | fn with_closure_expecting_fn_with_bound_region<F>(_: F)
18-
| -------------------------------------------
18+
| ------------------------------------------- required by a bound in this
1919
LL | where F: FnOnce(fn(&u32), &i32)
2020
| ---------------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
2121
...
@@ -28,7 +28,7 @@ error[E0631]: type mismatch in closure arguments
2828
--> $DIR/expect-fn-supply-fn.rs:46:5
2929
|
3030
LL | fn with_closure_expecting_fn_with_bound_region<F>(_: F)
31-
| -------------------------------------------
31+
| ------------------------------------------- required by a bound in this
3232
LL | where F: FnOnce(fn(&u32), &i32)
3333
| ---------------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
3434
...

src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ error[E0631]: type mismatch in closure arguments
4040
--> $DIR/expect-fn-supply-fn.rs:30:5
4141
|
4242
LL | fn with_closure_expecting_fn_with_free_region<F>(_: F)
43-
| ------------------------------------------
43+
| ------------------------------------------ required by a bound in this
4444
LL | where F: for<'a> FnOnce(fn(&'a u32), &i32)
4545
| ------------------------- required by this bound in `with_closure_expecting_fn_with_free_region`
4646
...
@@ -53,7 +53,7 @@ error[E0631]: type mismatch in closure arguments
5353
--> $DIR/expect-fn-supply-fn.rs:37:5
5454
|
5555
LL | fn with_closure_expecting_fn_with_bound_region<F>(_: F)
56-
| -------------------------------------------
56+
| ------------------------------------------- required by a bound in this
5757
LL | where F: FnOnce(fn(&u32), &i32)
5858
| ---------------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
5959
...
@@ -66,7 +66,7 @@ error[E0631]: type mismatch in closure arguments
6666
--> $DIR/expect-fn-supply-fn.rs:46:5
6767
|
6868
LL | fn with_closure_expecting_fn_with_bound_region<F>(_: F)
69-
| -------------------------------------------
69+
| ------------------------------------------- required by a bound in this
7070
LL | where F: FnOnce(fn(&u32), &i32)
7171
| ---------------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
7272
...

src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0631]: type mismatch in closure arguments
22
--> $DIR/expect-infer-var-appearing-twice.rs:14:5
33
|
44
LL | fn with_closure<F, A>(_: F)
5-
| ------------
5+
| ------------ required by a bound in this
66
LL | where F: FnOnce(A, A)
77
| ------------ required by this bound in `with_closure`
88
...

src/test/ui/generator/generator-yielding-or-returning-itself.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<[generator@$DIR/generator-yielding-or-re
22
--> $DIR/generator-yielding-or-returning-itself.rs:15:5
33
|
44
LL | pub fn want_cyclic_generator_return<T>(_: T)
5-
| ----------------------------
5+
| ---------------------------- required by a bound in this
66
LL | where T: Generator<Yield = (), Return = T>
77
| ---------- required by this bound in `want_cyclic_generator_return`
88
...
@@ -18,7 +18,7 @@ error[E0271]: type mismatch resolving `<[generator@$DIR/generator-yielding-or-re
1818
--> $DIR/generator-yielding-or-returning-itself.rs:28:5
1919
|
2020
LL | pub fn want_cyclic_generator_yield<T>(_: T)
21-
| ---------------------------
21+
| --------------------------- required by a bound in this
2222
LL | where T: Generator<Yield = T, Return = ()>
2323
| --------- required by this bound in `want_cyclic_generator_yield`
2424
...

src/test/ui/generic-associated-types/issue-62326-parameter-out-of-range.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0280]: the requirement `for<'a> <Self as Iterator>::Item<'a>: 'a` is not
22
--> $DIR/issue-62326-parameter-out-of-range.rs:7:20
33
|
44
LL | trait Iterator {
5-
| --------
5+
| -------- required by a bound in this
66
LL | type Item<'a>: 'a;
77
| ^^ required by this bound in `Iterator`
88

src/test/ui/generic-associated-types/iterable.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ error[E0271]: type mismatch resolving `for<'a> <<std::vec::Vec<T> as Iterable>::
2424
--> $DIR/iterable.rs:19:30
2525
|
2626
LL | trait Iterable {
27-
| --------
27+
| -------- required by a bound in this
2828
LL | type Item<'a> where Self: 'a;
2929
LL | type Iter<'a>: Iterator<Item = Self::Item<'a>> where Self: 'a;
3030
| --------------------- required by this bound in `Iterable`
@@ -41,7 +41,7 @@ error[E0271]: type mismatch resolving `for<'a> <<[T] as Iterable>::Iter<'a> as s
4141
--> $DIR/iterable.rs:31:30
4242
|
4343
LL | trait Iterable {
44-
| --------
44+
| -------- required by a bound in this
4545
LL | type Item<'a> where Self: 'a;
4646
LL | type Iter<'a>: Iterator<Item = Self::Item<'a>> where Self: 'a;
4747
| --------------------- required by this bound in `Iterable`

src/test/ui/hrtb/hrtb-conflate-regions.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `for<'a, 'b> SomeStruct: Foo<(&'a isize, &'b isize
22
--> $DIR/hrtb-conflate-regions.rs:27:22
33
|
44
LL | fn want_foo2<T>()
5-
| ---------
5+
| --------- required by a bound in this
66
LL | where T : for<'a,'b> Foo<(&'a isize, &'b isize)>
77
| -------------------------------------- required by this bound in `want_foo2`
88
...

src/test/ui/hrtb/hrtb-exists-forall-trait-contravariant.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `(): Trait<for<'b> fn(&'b u32)>` is not satisfied
22
--> $DIR/hrtb-exists-forall-trait-contravariant.rs:34:11
33
|
44
LL | fn foo<T>()
5-
| ---
5+
| --- required by a bound in this
66
LL | where
77
LL | T: Trait<for<'b> fn(&'b u32)>,
88
| -------------------------- required by this bound in `foo`

src/test/ui/hrtb/hrtb-exists-forall-trait-covariant.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `(): Trait<for<'b> fn(fn(&'b u32))>` is not satisf
22
--> $DIR/hrtb-exists-forall-trait-covariant.rs:36:11
33
|
44
LL | fn foo<T>()
5-
| ---
5+
| --- required by a bound in this
66
LL | where
77
LL | T: Trait<for<'b> fn(fn(&'b u32))>,
88
| ------------------------------ required by this bound in `foo`

src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `(): Trait<for<'b> fn(std::cell::Cell<&'b u32>)>`
22
--> $DIR/hrtb-exists-forall-trait-invariant.rs:28:11
33
|
44
LL | fn foo<T>()
5-
| ---
5+
| --- required by a bound in this
66
LL | where
77
LL | T: Trait<for<'b> fn(Cell<&'b u32>)>,
88
| -------------------------------- required by this bound in `foo`

src/test/ui/hrtb/hrtb-higher-ranker-supertraits-transitive.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `for<'ccx> B: Bar<'ccx>` is not satisfied
22
--> $DIR/hrtb-higher-ranker-supertraits-transitive.rs:47:26
33
|
44
LL | fn want_bar_for_any_ccx<B>(b: &B)
5-
| --------------------
5+
| -------------------- required by a bound in this
66
LL | where B : for<'ccx> Bar<'ccx>
77
| ------------------- required by this bound in `want_bar_for_any_ccx`
88
...

0 commit comments

Comments
 (0)