Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use note for pointing at bound introducing requirement #87668

Merged
merged 1 commit into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
ObligationCauseCode::BindingObligation(item_def_id, span) => {
let item_name = tcx.def_path_str(item_def_id);
let msg = format!("required by this bound in `{}`", item_name);
let mut multispan = MultiSpan::from(span);
if let Some(ident) = tcx.opt_item_name(item_def_id) {
let sm = tcx.sess.source_map();
let same_line =
Expand All @@ -1971,16 +1971,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
_ => true,
};
if !ident.span.overlaps(span) && !same_line {
err.span_label(ident.span, "required by a bound in this");
multispan
.push_span_label(ident.span, "required by a bound in this".to_string());
}
}
let descr = format!("required by a bound in `{}`", item_name);
if span != DUMMY_SP {
err.span_label(span, &msg);
let msg = format!("required by this bound in `{}`", item_name);
multispan.push_span_label(span, msg);
err.span_note(multispan, &descr);
} else {
err.span_note(
tcx.def_span(item_def_id),
&format!("required by a bound in `{}`", item_name),
);
err.span_note(tcx.def_span(item_def_id), &descr);
}
}
ObligationCauseCode::ObjectCastObligation(object_ty) => {
Expand Down
77 changes: 55 additions & 22 deletions src/test/ui/anonymous-higher-ranked-lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ LL | f1(|_: (), _: ()| {});
| ^^ -------------- found signature of `fn((), ()) -> _`
| |
| expected signature of `for<'r, 's> fn(&'r (), &'s ()) -> _`
...
|
note: required by a bound in `f1`
--> $DIR/anonymous-higher-ranked-lifetime.rs:16:25
|
LL | fn f1<F>(_: F) where F: Fn(&(), &()) {}
| ------------ required by this bound in `f1`
| ^^^^^^^^^^^^ required by this bound in `f1`

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

error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:4:5
Expand All @@ -27,9 +33,12 @@ LL | f3(|_: (), _: ()| {});
| ^^ -------------- found signature of `fn((), ()) -> _`
| |
| expected signature of `for<'r> fn(&(), &'r ()) -> _`
...
|
note: required by a bound in `f3`
--> $DIR/anonymous-higher-ranked-lifetime.rs:18:29
|
LL | fn f3<'a, F>(_: F) where F: Fn(&'a (), &()) {}
| --------------- required by this bound in `f3`
| ^^^^^^^^^^^^^^^ required by this bound in `f3`

error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:5:5
Expand All @@ -38,9 +47,12 @@ LL | f4(|_: (), _: ()| {});
| ^^ -------------- found signature of `fn((), ()) -> _`
| |
| expected signature of `for<'s, 'r> fn(&'s (), &'r ()) -> _`
...
|
note: required by a bound in `f4`
--> $DIR/anonymous-higher-ranked-lifetime.rs:19:25
|
LL | fn f4<F>(_: F) where F: for<'r> Fn(&(), &'r ()) {}
| ----------------------- required by this bound in `f4`
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f4`

error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:6:5
Expand All @@ -49,9 +61,12 @@ LL | f5(|_: (), _: ()| {});
| ^^ -------------- found signature of `fn((), ()) -> _`
| |
| expected signature of `for<'r> fn(&'r (), &'r ()) -> _`
...
|
note: required by a bound in `f5`
--> $DIR/anonymous-higher-ranked-lifetime.rs:20:25
|
LL | fn f5<F>(_: F) where F: for<'r> Fn(&'r (), &'r ()) {}
| -------------------------- required by this bound in `f5`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f5`

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

error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:8:5
Expand All @@ -71,9 +89,12 @@ LL | g2(|_: (), _: ()| {});
| ^^ -------------- found signature of `fn((), ()) -> _`
| |
| expected signature of `for<'r> fn(&'r (), for<'s> fn(&'s ())) -> _`
...
|
note: required by a bound in `g2`
--> $DIR/anonymous-higher-ranked-lifetime.rs:24:25
|
LL | fn g2<F>(_: F) where F: Fn(&(), fn(&())) {}
| ---------------- required by this bound in `g2`
| ^^^^^^^^^^^^^^^^ required by this bound in `g2`

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

error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:10:5
Expand All @@ -93,9 +117,12 @@ LL | g4(|_: (), _: ()| {});
| ^^ -------------- found signature of `fn((), ()) -> _`
| |
| expected signature of `for<'s> fn(&'s (), for<'r> fn(&'r ())) -> _`
...
|
note: required by a bound in `g4`
--> $DIR/anonymous-higher-ranked-lifetime.rs:26:25
|
LL | fn g4<F>(_: F) where F: Fn(&(), for<'r> fn(&'r ())) {}
| --------------------------- required by this bound in `g4`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g4`

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

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

error: aborting due to 11 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ error[E0277]: `<<Self as Case1>::C as Iterator>::Item` cannot be sent between th
LL | type C: Clone + Iterator<Item: Send + Iterator<Item: for<'a> Lam<&'a u8, App: Debug>> + Sync>;
| ^^^^ `<<Self as Case1>::C as Iterator>::Item` cannot be sent between threads safely
|
::: $SRC_DIR/core/src/marker.rs:LL:COL
= help: the trait `Send` is not implemented for `<<Self as Case1>::C as Iterator>::Item`
note: required by a bound in `Send`
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
LL | pub unsafe auto trait Send {
| -------------------------- required by this bound in `Send`
|
= help: the trait `Send` is not implemented for `<<Self as Case1>::C as Iterator>::Item`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Send`
help: consider further restricting the associated type
|
LL | trait Case1 where <<Self as Case1>::C as Iterator>::Item: Send {
Expand All @@ -21,12 +21,12 @@ error[E0277]: `<<Self as Case1>::C as Iterator>::Item` is not an iterator
LL | type C: Clone + Iterator<Item: Send + Iterator<Item: for<'a> Lam<&'a u8, App: Debug>> + Sync>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `<<Self as Case1>::C as Iterator>::Item` is not an iterator
|
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
= help: the trait `Iterator` is not implemented for `<<Self as Case1>::C as Iterator>::Item`
note: required by a bound in `Iterator`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
LL | pub trait Iterator {
| ------------------ required by this bound in `Iterator`
|
= help: the trait `Iterator` is not implemented for `<<Self as Case1>::C as Iterator>::Item`
| ^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator`
help: consider further restricting the associated type
|
LL | trait Case1 where <<Self as Case1>::C as Iterator>::Item: Iterator {
Expand All @@ -38,12 +38,12 @@ error[E0277]: `<<Self as Case1>::C as Iterator>::Item` cannot be shared between
LL | type C: Clone + Iterator<Item: Send + Iterator<Item: for<'a> Lam<&'a u8, App: Debug>> + Sync>;
| ^^^^ `<<Self as Case1>::C as Iterator>::Item` cannot be shared between threads safely
|
::: $SRC_DIR/core/src/marker.rs:LL:COL
= help: the trait `Sync` is not implemented for `<<Self as Case1>::C as Iterator>::Item`
note: required by a bound in `Sync`
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
LL | pub unsafe auto trait Sync {
| -------------------------- required by this bound in `Sync`
|
= help: the trait `Sync` is not implemented for `<<Self as Case1>::C as Iterator>::Item`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Sync`
help: consider further restricting the associated type
|
LL | trait Case1 where <<Self as Case1>::C as Iterator>::Item: Sync {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ error[E0277]: `<<Self as Case1>::A as Iterator>::Item` doesn't implement `Debug`
LL | type A: Iterator<Item: Debug>;
| ^^^^^ `<<Self as Case1>::A as Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
::: $SRC_DIR/core/src/fmt/mod.rs:LL:COL
= help: the trait `Debug` is not implemented for `<<Self as Case1>::A as Iterator>::Item`
note: required by a bound in `Debug`
--> $SRC_DIR/core/src/fmt/mod.rs:LL:COL
|
LL | pub trait Debug {
| --------------- required by this bound in `Debug`
|
= help: the trait `Debug` is not implemented for `<<Self as Case1>::A as Iterator>::Item`
| ^^^^^^^^^^^^^^^ required by this bound in `Debug`
help: consider further restricting the associated type
|
LL | trait Case1 where <<Self as Case1>::A as Iterator>::Item: Debug {
Expand All @@ -21,11 +21,11 @@ error[E0277]: the trait bound `<<Self as Foo>::Out as Baz>::Assoc: Default` is n
LL | pub trait Foo { type Out: Baz<Assoc: Default>; }
| ^^^^^^^ the trait `Default` is not implemented for `<<Self as Foo>::Out as Baz>::Assoc`
|
::: $SRC_DIR/core/src/default.rs:LL:COL
note: required by a bound in `Default`
--> $SRC_DIR/core/src/default.rs:LL:COL
|
LL | pub trait Default: Sized {
| ------------------------ required by this bound in `Default`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Default`
help: consider further restricting the associated type
|
LL | pub trait Foo where <<Self as Foo>::Out as Baz>::Assoc: Default { type Out: Baz<Assoc: Default>; }
Expand Down
22 changes: 14 additions & 8 deletions src/test/ui/associated-type-bounds/issue-83017.stderr
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
error[E0277]: the trait bound `for<'a, 'b> <Z as TraitA<'a>>::AsA: TraitB<'a, 'b>` is not satisfied
--> $DIR/issue-83017.rs:36:5
|
LL | foo::<Z>();
| ^^^^^^^^ the trait `for<'a, 'b> TraitB<'a, 'b>` is not implemented for `<Z as TraitA<'a>>::AsA`
|
note: required by a bound in `foo`
--> $DIR/issue-83017.rs:31:32
|
LL | fn foo<T>()
| --- required by a bound in this
LL | where
LL | for<'a> T: TraitA<'a, AsA: for<'b> TraitB<'a, 'b, AsB: for<'c> TraitC<'a, 'b, 'c>>>,
| ------------------------------------------------------- required by this bound in `foo`
...
LL | foo::<Z>();
| ^^^^^^^^ the trait `for<'a, 'b> TraitB<'a, 'b>` is not implemented for `<Z as TraitA<'a>>::AsA`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error[E0277]: the trait bound `for<'a, 'b, 'c> <<Z as TraitA<'a>>::AsA as TraitB<'a, 'b>>::AsB: TraitC<'a, 'b, 'c>` is not satisfied
--> $DIR/issue-83017.rs:36:5
|
LL | foo::<Z>();
| ^^^^^^^^ the trait `for<'a, 'b, 'c> TraitC<'a, 'b, 'c>` is not implemented for `<<Z as TraitA<'a>>::AsA as TraitB<'a, 'b>>::AsB`
|
note: required by a bound in `foo`
--> $DIR/issue-83017.rs:31:60
|
LL | fn foo<T>()
| --- required by a bound in this
LL | where
LL | for<'a> T: TraitA<'a, AsA: for<'b> TraitB<'a, 'b, AsB: for<'c> TraitC<'a, 'b, 'c>>>,
| -------------------------- required by this bound in `foo`
...
LL | foo::<Z>();
| ^^^^^^^^ the trait `for<'a, 'b, 'c> TraitC<'a, 'b, 'c>` is not implemented for `<<Z as TraitA<'a>>::AsA as TraitB<'a, 'b>>::AsB`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
error[E0271]: type mismatch resolving `<ModelT as Vehicle>::Color == Blue`
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:31:10
|
LL | fn blue_car<C:Car<Color=Blue>>(c: C) {
| ---------- required by this bound in `blue_car`
...
LL | fn b() { blue_car(ModelT); }
| ^^^^^^^^ expected struct `Blue`, found struct `Black`
|
note: required by a bound in `blue_car`
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:27:19
|
LL | fn blue_car<C:Car<Color=Blue>>(c: C) {
| ^^^^^^^^^^ required by this bound in `blue_car`

error[E0271]: type mismatch resolving `<ModelU as Vehicle>::Color == Black`
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:10
|
LL | fn black_car<C:Car<Color=Black>>(c: C) {
| ----------- required by this bound in `black_car`
...
LL | fn c() { black_car(ModelU); }
| ^^^^^^^^^ expected struct `Black`, found struct `Blue`
|
note: required by a bound in `black_car`
--> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:24:20
|
LL | fn black_car<C:Car<Color=Black>>(c: C) {
| ^^^^^^^^^^^ required by this bound in `black_car`

error: aborting due to 2 previous errors

Expand Down
9 changes: 6 additions & 3 deletions src/test/ui/associated-types/associated-types-eq-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ LL | fn foo2<I: Foo<A = Bar>>(x: I) {
error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
--> $DIR/associated-types-eq-3.rs:38:5
|
LL | fn foo1<I: Foo<A=Bar>>(x: I) {
| ----- required by this bound in `foo1`
...
LL | foo1(a);
| ^^^^ expected struct `Bar`, found `usize`
|
note: required by a bound in `foo1`
--> $DIR/associated-types-eq-3.rs:18:16
|
LL | fn foo1<I: Foo<A=Bar>>(x: I) {
| ^^^^^ required by this bound in `foo1`

error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
--> $DIR/associated-types-eq-3.rs:41:9
Expand Down
Loading