Skip to content

Commit

Permalink
Small tweaks to required bound span
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Apr 8, 2020
1 parent bd7ea54 commit d605a9d
Show file tree
Hide file tree
Showing 167 changed files with 330 additions and 325 deletions.
6 changes: 4 additions & 2 deletions src/librustc_trait_selection/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
(self.tcx.sess.source_map().span_to_snippet(span), &obligation.cause.code)
{
let generics = self.tcx.generics_of(*def_id);
if generics.params.iter().filter(|p| p.name.as_str() != "Self").next().is_some() && !snippet.ends_with('>') {
if generics.params.iter().filter(|p| p.name.as_str() != "Self").next().is_some()
&& !snippet.ends_with('>')
{
// FIXME: To avoid spurious suggestions in functions where type arguments
// where already supplied, we check the snippet to make sure it doesn't
// end with a turbofish. Ideally we would have access to a `PathSegment`
Expand All @@ -1405,7 +1407,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
// | `Tt::const_val::<[i8; 123]>::<T>`
// ...
// LL | const fn const_val<T: Sized>() -> usize {
// | --------- - required by this bound in `Tt::const_val`
// | - required by this bound in `Tt::const_val`
// |
// = note: cannot satisfy `_: Tt`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
/// --> $DIR/issue-64130-2-send.rs:21:5
/// |
/// LL | fn is_send<T: Send>(t: T) { }
/// | ------- ---- required by this bound in `is_send`
/// | ---- required by this bound in `is_send`
/// ...
/// LL | is_send(bar());
/// | ^^^^^^^ future returned by `bar` is not send
Expand Down Expand Up @@ -1356,7 +1356,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let item_name = tcx.def_path_str(item_def_id);
let msg = format!("required by this bound in `{}`", item_name);
if let Some(ident) = tcx.opt_item_name(item_def_id) {
if !ident.span.overlaps(span) {
let sm = self.tcx.sess.source_map();
let same_line =
match (sm.lookup_line(ident.span.hi()), sm.lookup_line(span.lo())) {
(Ok(l), Ok(r)) => l.line == r.line,
_ => true,
};
if !ident.span.overlaps(span) && !same_line {
err.span_label(ident.span, "");
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/test/ui/anonymous-higher-ranked-lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | f1(|_: (), _: ()| {});
| expected signature of `for<'r, 's> fn(&'r (), &'s ()) -> _`
...
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 @@ -18,7 +18,7 @@ LL | f2(|_: (), _: ()| {});
| expected signature of `for<'a, 'r> fn(&'a (), &'r ()) -> _`
...
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 @@ -29,7 +29,7 @@ LL | f3(|_: (), _: ()| {});
| expected signature of `for<'r> fn(&(), &'r ()) -> _`
...
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 @@ -40,7 +40,7 @@ LL | f4(|_: (), _: ()| {});
| expected signature of `for<'s, 'r> fn(&'s (), &'r ()) -> _`
...
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 @@ -51,7 +51,7 @@ LL | f5(|_: (), _: ()| {});
| expected signature of `for<'r> fn(&'r (), &'r ()) -> _`
...
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 @@ -62,7 +62,7 @@ LL | g1(|_: (), _: ()| {});
| expected signature of `for<'r> fn(&'r (), std::boxed::Box<(dyn for<'s> std::ops::Fn(&'s ()) + 'static)>) -> _`
...
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 @@ -73,7 +73,7 @@ LL | g2(|_: (), _: ()| {});
| expected signature of `for<'r> fn(&'r (), for<'s> fn(&'s ())) -> _`
...
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 @@ -84,7 +84,7 @@ LL | g3(|_: (), _: ()| {});
| expected signature of `for<'s> fn(&'s (), std::boxed::Box<(dyn for<'r> std::ops::Fn(&'r ()) + 'static)>) -> _`
...
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 @@ -95,7 +95,7 @@ LL | g4(|_: (), _: ()| {});
| expected signature of `for<'s> fn(&'s (), for<'r> fn(&'r ())) -> _`
...
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 @@ -106,7 +106,7 @@ LL | h1(|_: (), _: (), _: (), _: ()| {});
| expected signature of `for<'r, 's> fn(&'r (), std::boxed::Box<(dyn for<'t0> std::ops::Fn(&'t0 ()) + 'static)>, &'s (), for<'t0, 't1> fn(&'t0 (), &'t1 ())) -> _`
...
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 @@ -117,7 +117,7 @@ LL | h2(|_: (), _: (), _: (), _: ()| {});
| expected signature of `for<'r, 't0> fn(&'r (), std::boxed::Box<(dyn for<'s> std::ops::Fn(&'s ()) + 'static)>, &'t0 (), for<'s, 't1> fn(&'s (), &'t1 ())) -> _`
...
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 @@ -2,7 +2,7 @@ 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`
| ---------- required by this bound in `blue_car`
...
LL | fn b() { blue_car(ModelT); }
| ^^^^^^^^ expected struct `Blue`, found struct `Black`
Expand All @@ -11,7 +11,7 @@ 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`
| ----------- required by this bound in `black_car`
...
LL | fn c() { black_car(ModelU); }
| ^^^^^^^^^ expected struct `Black`, found struct `Blue`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/associated-types/associated-types-eq-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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`
| ----- required by this bound in `foo1`
...
LL | foo1(a);
| ^^^^ expected struct `Bar`, found `usize`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<Adapter<I> as Iterator>::Item == std::op
--> $DIR/associated-types-issue-20346.rs:34:5
|
LL | fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
| -------------- ------ required by this bound in `is_iterator_of`
| ------ required by this bound in `is_iterator_of`
...
LL | fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
| - this type parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | want_y(t);
| ^^^^^^ expected `i32`, found associated type
...
LL | fn want_y<T:Foo<Y=i32>>(t: &T) { }
| ------ ----- required by this bound in `want_y`
| ----- required by this bound in `want_y`
|
= note: expected type `i32`
found associated type `<T as Foo>::Y`
Expand All @@ -19,7 +19,7 @@ LL | want_x(t);
| ^^^^^^ expected `u32`, found associated type
...
LL | fn want_x<T:Foo<X=u32>>(t: &T) { }
| ------ ----- required by this bound in `want_x`
| ----- required by this bound in `want_x`
|
= note: expected type `u32`
found associated type `<T as Foo>::X`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0284]: type annotations needed
--> $DIR/associated-types-overridden-binding.rs:4:12
|
LL | trait Foo: Iterator<Item = i32> {}
| --- ---------- required by this bound in `Foo`
| ---------- required by this bound in `Foo`
LL | trait Bar: Foo<Item = u32> {}
| ^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self`
|
Expand All @@ -12,7 +12,7 @@ error[E0284]: type annotations needed
--> $DIR/associated-types-overridden-binding.rs:7:21
|
LL | trait I32Iterator = Iterator<Item = i32>;
| ----------- ---------- required by this bound in `I32Iterator`
| ---------- required by this bound in `I32Iterator`
LL | trait U32Iterator = I32Iterator<Item = u32>;
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self`
|
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/associated-types/associated-types-path-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:29:5
|
LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
| -- --- required by this bound in `f1`
| --- required by this bound in `f1`
...
LL | f1(2u32, 4u32);
| ^^ the trait `Foo` is not implemented for `u32`
Expand All @@ -28,7 +28,7 @@ error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:35:5
|
LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
| -- --- required by this bound in `f1`
| --- required by this bound in `f1`
...
LL | f1(2u32, 4i32);
| ^^ the trait `Foo` is not implemented for `u32`
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/async-await/async-fn-nonsend.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: future cannot be sent between threads safely
--> $DIR/async-fn-nonsend.rs:49:5
|
LL | fn assert_send(_: impl Send) {}
| ----------- ---- required by this bound in `assert_send`
| ---- required by this bound in `assert_send`
...
LL | assert_send(local_dropped_before_await());
| ^^^^^^^^^^^ future returned by `local_dropped_before_await` is not `Send`
Expand All @@ -23,7 +23,7 @@ error: future cannot be sent between threads safely
--> $DIR/async-fn-nonsend.rs:51:5
|
LL | fn assert_send(_: impl Send) {}
| ----------- ---- required by this bound in `assert_send`
| ---- required by this bound in `assert_send`
...
LL | assert_send(non_send_temporary_in_match());
| ^^^^^^^^^^^ future returned by `non_send_temporary_in_match` is not `Send`
Expand All @@ -44,7 +44,7 @@ error: future cannot be sent between threads safely
--> $DIR/async-fn-nonsend.rs:53:5
|
LL | fn assert_send(_: impl Send) {}
| ----------- ---- required by this bound in `assert_send`
| ---- required by this bound in `assert_send`
...
LL | assert_send(non_sync_with_method_call());
| ^^^^^^^^^^^ future returned by `non_sync_with_method_call` is not `Send`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/async-await/issue-64130-1-sync.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: future cannot be shared between threads safely
--> $DIR/issue-64130-1-sync.rs:21:5
|
LL | fn is_sync<T: Sync>(t: T) { }
| ------- ---- required by this bound in `is_sync`
| ---- required by this bound in `is_sync`
...
LL | is_sync(bar());
| ^^^^^^^ future returned by `bar` is not `Sync`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/async-await/issue-64130-2-send.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: future cannot be sent between threads safely
--> $DIR/issue-64130-2-send.rs:21:5
|
LL | fn is_send<T: Send>(t: T) { }
| ------- ---- required by this bound in `is_send`
| ---- required by this bound in `is_send`
...
LL | is_send(bar());
| ^^^^^^^ future returned by `bar` is not `Send`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/async-await/issue-64130-3-other.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: the trait bound `Foo: Qux` is not satisfied in `impl std::future::
--> $DIR/issue-64130-3-other.rs:24:5
|
LL | fn is_qux<T: Qux>(t: T) { }
| ------ --- required by this bound in `is_qux`
| --- required by this bound in `is_qux`
LL |
LL | async fn bar() {
| - within this `impl std::future::Future`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: future cannot be sent between threads safely
--> $DIR/issue-64130-non-send-future-diags.rs:21:5
|
LL | fn is_send<T: Send>(t: T) { }
| ------- ---- required by this bound in `is_send`
| ---- required by this bound in `is_send`
...
LL | is_send(foo());
| ^^^^^^^ future returned by `foo` is not `Send`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/async-await/issue-67252-unnamed-future.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: future cannot be sent between threads safely
--> $DIR/issue-67252-unnamed-future.rs:18:5
|
LL | fn spawn<T: Send>(_: T) {}
| ----- ---- required by this bound in `spawn`
| ---- required by this bound in `spawn`
...
LL | spawn(async {
| ^^^^^ future is not `Send`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: future cannot be sent between threads safely
--> $DIR/issue-65436-raw-ptr-not-send.rs:12:5
|
LL | fn assert_send<T: Send>(_: T) {}
| ----------- ---- required by this bound in `assert_send`
| ---- required by this bound in `assert_send`
...
LL | assert_send(async {
| ^^^^^^^^^^^ future returned by `main` is not `Send`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: `F` cannot be sent between threads safely
--> $DIR/closure-bounds-cant-promote-superkind-in-struct.rs:5:22
|
LL | struct X<F> where F: FnOnce() + 'static + Send {
| - ---- required by this bound in `X`
| ---- required by this bound in `X`
...
LL | fn foo<F>(blk: F) -> X<F> where F: FnOnce() + 'static {
| ^^^^ `F` cannot be sent between threads safely
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/closures/closure-bounds-subtype.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: `F` cannot be shared between threads safely
--> $DIR/closure-bounds-subtype.rs:13:22
|
LL | fn take_const_owned<F>(_: F) where F: FnOnce() + Sync + Send {
| ---------------- ---- required by this bound in `take_const_owned`
| ---- required by this bound in `take_const_owned`
...
LL | take_const_owned(f);
| ^ `F` cannot be shared between threads safely
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: the trait bound `&dyn Trait: Trait` is not satisfied
--> $DIR/coherence-unsafe-trait-object-impl.rs:15:13
|
LL | fn takes_t<S: Trait>(s: S) {
| ------- ----- required by this bound in `takes_t`
| ----- required by this bound in `takes_t`
...
LL | takes_t(t);
| ^ the trait `Trait` is not implemented for `&dyn Trait`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/consts/too_generic_eval_ice.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ error[E0277]: the size for values of type `A` cannot be known at compilation tim
--> $DIR/too_generic_eval_ice.rs:7:13
|
LL | pub struct Foo<A, B>(A, B);
| --- - required by this bound in `Foo`
| - required by this bound in `Foo`
LL |
LL | impl<A, B> Foo<A, B> {
| - this type parameter needs to be `std::marker::Sized`
Expand All @@ -30,7 +30,7 @@ error[E0277]: the size for values of type `B` cannot be known at compilation tim
--> $DIR/too_generic_eval_ice.rs:7:13
|
LL | pub struct Foo<A, B>(A, B);
| --- - required by this bound in `Foo`
| - required by this bound in `Foo`
LL |
LL | impl<A, B> Foo<A, B> {
| - this type parameter needs to be `std::marker::Sized`
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/derives/deriving-copyclone.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: the trait bound `C: std::marker::Copy` is not satisfied
--> $DIR/deriving-copyclone.rs:31:13
|
LL | fn is_copy<T: Copy>(_: T) {}
| ------- ---- required by this bound in `is_copy`
| ---- required by this bound in `is_copy`
...
LL | is_copy(B { a: 1, b: C });
| ^^^^^^^^^^^^^^^^
Expand All @@ -16,7 +16,7 @@ error[E0277]: the trait bound `C: std::clone::Clone` is not satisfied
--> $DIR/deriving-copyclone.rs:32:14
|
LL | fn is_clone<T: Clone>(_: T) {}
| -------- ----- required by this bound in `is_clone`
| ----- required by this bound in `is_clone`
...
LL | is_clone(B { a: 1, b: C });
| ^^^^^^^^^^^^^^^^
Expand All @@ -30,7 +30,7 @@ error[E0277]: the trait bound `D: std::marker::Copy` is not satisfied
--> $DIR/deriving-copyclone.rs:35:13
|
LL | fn is_copy<T: Copy>(_: T) {}
| ------- ---- required by this bound in `is_copy`
| ---- required by this bound in `is_copy`
...
LL | is_copy(B { a: 1, b: D });
| ^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/recursion_limit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0275]: overflow evaluating the requirement `J: std::marker::Send`
--> $DIR/recursion_limit.rs:34:5
|
LL | fn is_send<T:Send>() { }
| ------- ---- required by this bound in `is_send`
| ---- required by this bound in `is_send`
...
LL | is_send::<A>();
| ^^^^^^^^^^^^
Expand Down
Loading

0 comments on commit d605a9d

Please sign in to comment.