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

Show the location of a type usage for trait bound failures #66444

Open
oli-cosmian opened this issue Nov 15, 2019 · 2 comments

Comments

@oli-cosmian
Copy link

@oli-cosmian oli-cosmian commented Nov 15, 2019

cc @estebank

The following diagnostic doesn't tell the user anything about where the type that causes the failure is coming from. I understand that we can't report a correct source site, but we could create a heuristic:

Instead of having a note: without an associated span, we could check where (if at all) the type is used in the function and report those spans as potential sources of the error. Though I'm not sure what would be needed to fiddle this information through to the diagnostic reporting site.

fn foo(i: i32) -> impl std::future::Future<Output = ()> + Send {
    async move {
        boo(format!("{}", i).as_str()).await;
    }
}

async fn boo(_: &str) {
    
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0277]: `*mut (dyn std::ops::Fn() + 'static)` cannot be shared between threads safely
 --> src/lib.rs:1:19
  |
1 | fn foo(i: i32) -> impl std::future::Future<Output = ()> + Send {
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut (dyn std::ops::Fn() + 'static)` cannot be shared between threads safely
  |
  = help: within `core::fmt::Void`, the trait `std::marker::Sync` is not implemented for `*mut (dyn std::ops::Fn() + 'static)`
  = note: required because it appears within the type `std::marker::PhantomData<*mut (dyn std::ops::Fn() + 'static)>`
  = note: required because it appears within the type `core::fmt::Void`
  = note: required because of the requirements on the impl of `std::marker::Send` for `&core::fmt::Void`
  = note: required because it appears within the type `std::fmt::ArgumentV1<'_>`
  = note: required because it appears within the type `[std::fmt::ArgumentV1<'_>; 1]`
  = note: required because it appears within the type `for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5, 't6, 't7, 't8, 't9, 't10, 't11, 't12, 't13, 't14, 't15, 't16, 't17, 't18> {for<'_> fn(&str) -> impl std::future::Future {boo}, for<'t19> fn(std::fmt::Arguments<'t19>) -> std::string::String {std::fmt::format}, fn(&'r [&'r str], &'r [std::fmt::ArgumentV1<'r>]) -> std::fmt::Arguments<'r> {std::fmt::Arguments::<'r>::new_v1}, &'s str, &'t0 str, [&'t1 str; 1], &'t2 [&'t3 str], &'t4 [&'t5 str; 1], i32, &'t6 i32, (&'t7 i32,), [std::fmt::ArgumentV1<'t8>; 1], &'t9 [std::fmt::ArgumentV1<'t10>], &'t11 [std::fmt::ArgumentV1<'t12>; 1], std::fmt::Arguments<'t13>, &'t14 std::string::String, std::string::String, &'t15 str, &'t16 str, impl std::future::Future, impl std::future::Future, ()}`
  = note: required because it appears within the type `[static generator@src/lib.rs:2:16: 4:6 i:i32 for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5, 't6, 't7, 't8, 't9, 't10, 't11, 't12, 't13, 't14, 't15, 't16, 't17, 't18> {for<'_> fn(&str) -> impl std::future::Future {boo}, for<'t19> fn(std::fmt::Arguments<'t19>) -> std::string::String {std::fmt::format}, fn(&'r [&'r str], &'r [std::fmt::ArgumentV1<'r>]) -> std::fmt::Arguments<'r> {std::fmt::Arguments::<'r>::new_v1}, &'s str, &'t0 str, [&'t1 str; 1], &'t2 [&'t3 str], &'t4 [&'t5 str; 1], i32, &'t6 i32, (&'t7 i32,), [std::fmt::ArgumentV1<'t8>; 1], &'t9 [std::fmt::ArgumentV1<'t10>], &'t11 [std::fmt::ArgumentV1<'t12>; 1], std::fmt::Arguments<'t13>, &'t14 std::string::String, std::string::String, &'t15 str, &'t16 str, impl std::future::Future, impl std::future::Future, ()}]`
  = note: required because it appears within the type `std::future::GenFuture<[static generator@src/lib.rs:2:16: 4:6 i:i32 for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5, 't6, 't7, 't8, 't9, 't10, 't11, 't12, 't13, 't14, 't15, 't16, 't17, 't18> {for<'_> fn(&str) -> impl std::future::Future {boo}, for<'t19> fn(std::fmt::Arguments<'t19>) -> std::string::String {std::fmt::format}, fn(&'r [&'r str], &'r [std::fmt::ArgumentV1<'r>]) -> std::fmt::Arguments<'r> {std::fmt::Arguments::<'r>::new_v1}, &'s str, &'t0 str, [&'t1 str; 1], &'t2 [&'t3 str], &'t4 [&'t5 str; 1], i32, &'t6 i32, (&'t7 i32,), [std::fmt::ArgumentV1<'t8>; 1], &'t9 [std::fmt::ArgumentV1<'t10>], &'t11 [std::fmt::ArgumentV1<'t12>; 1], std::fmt::Arguments<'t13>, &'t14 std::string::String, std::string::String, &'t15 str, &'t16 str, impl std::future::Future, impl std::future::Future, ()}]>`
  = note: required because it appears within the type `impl std::future::Future`
  = note: the return type of a function must have a statically known size

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

@nikomatsakis nikomatsakis commented Nov 19, 2019

This is possibly addressed by @davidtwco's PR #65345

@davidtwco

This comment has been minimized.

Copy link
Member

@davidtwco davidtwco commented Nov 19, 2019

Assigning to myself, should get handled by #65345 but currently isn't (presumably due to this comment).

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.