Rust: Tiny difference of the diagnostics for generator on some environment

Created on 16 Apr 2020  路  5Comments  路  Source: rust-lang/rust

Follow-up of #71182
Consider this example: https://github.com/rust-lang/rust/issues/67893#issuecomment-612650979

It emits the stderr on my local (x86_64-unknown-linux-gnu):

error[E0277]: `std::sync::MutexGuard<'_, ()>` cannot be sent between threads safely
  --> $DIR/issue-67893.rs:9:5
   |
LL | fn g(_: impl Send) {}
   |              ---- required by this bound in `g`
...
LL |     g(issue_67893::run())
   |     ^ `std::sync::MutexGuard<'_, ()>` cannot be sent between threads safely
   | 
  ::: $DIR/auxiliary/issue_67893.rs:7:20
   |
LL | pub async fn run() {
   |                    - within this `impl std::future::Future`
   |
   = help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `std::sync::MutexGuard<'_, ()>`
   = note: required because it appears within the type `for<'r, 's, 't0, 't1, 't2, 't3> {std::future::ResumeTy, std::sync::Arc<std::sync::Mutex<()>>, &'r std::sync::Mutex<()>, std::result::Result<std::sync::MutexGuard<'s, ()>, std::sync::PoisonError<std::sync::MutexGuard<'t0, ()>>>, &'t1 std::sync::MutexGuard<'t2, ()>, std::sync::MutexGuard<'t3, ()>, (), impl std::future::Future}`
   = note: required because it appears within the type `[static generator@DefId(15:11 ~ issue_67893[8787]::run[0]::{{closure}}[0]) for<'r, 's, 't0, 't1, 't2, 't3> {std::future::ResumeTy, std::sync::Arc<std::sync::Mutex<()>>, &'r std::sync::Mutex<()>, std::result::Result<std::sync::MutexGuard<'s, ()>, std::sync::PoisonError<std::sync::MutexGuard<'t0, ()>>>, &'t1 std::sync::MutexGuard<'t2, ()>, std::sync::MutexGuard<'t3, ()>, (), impl std::future::Future}]`
   = note: required because it appears within the type `std::future::from_generator::GenFuture<[static generator@DefId(15:11 ~ issue_67893[8787]::run[0]::{{closure}}[0]) for<'r, 's, 't0, 't1, 't2, 't3> {std::future::ResumeTy, std::sync::Arc<std::sync::Mutex<()>>, &'r std::sync::Mutex<()>, std::result::Result<std::sync::MutexGuard<'s, ()>, std::sync::PoisonError<std::sync::MutexGuard<'t0, ()>>>, &'t1 std::sync::MutexGuard<'t2, ()>, std::sync::MutexGuard<'t3, ()>, (), impl std::future::Future}]>`
   = note: required because it appears within the type `impl std::future::Future`
   = note: required because it appears within the type `impl std::future::Future`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

But on some other environment on CI, e.g. dist-i586-gnu-i586-i686-musl or Linux test-various, it emits it with a tiny difference:

14     |
15     = help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `std::sync::MutexGuard<'_, ()>`
16     = note: required because it appears within the type `for<'r, 's, 't0, 't1, 't2, 't3> {std::future::ResumeTy, std::sync::Arc<std::sync::Mutex<()>>, &'r std::sync::Mutex<()>, std::result::Result<std::sync::MutexGuard<'s, ()>, std::sync::PoisonError<std::sync::MutexGuard<'t0, ()>>>, &'t1 std::sync::MutexGuard<'t2, ()>, std::sync::MutexGuard<'t3, ()>, (), impl std::future::Future}`
-      = note: required because it appears within the type `[static generator@DefId(15:11 ~ issue_67893[8787]::run[0]::{{closure}}[0]) for<'r, 's, 't0, 't1, 't2, 't3> {std::future::ResumeTy, std::sync::Arc<std::sync::Mutex<()>>, &'r std::sync::Mutex<()>, std::result::Result<std::sync::MutexGuard<'s, ()>, std::sync::PoisonError<std::sync::MutexGuard<'t0, ()>>>, &'t1 std::sync::MutexGuard<'t2, ()>, std::sync::MutexGuard<'t3, ()>, (), impl std::future::Future}]`
-      = note: required because it appears within the type `std::future::from_generator::GenFuture<[static generator@DefId(15:11 ~ issue_67893[8787]::run[0]::{{closure}}[0]) for<'r, 's, 't0, 't1, 't2, 't3> {std::future::ResumeTy, std::sync::Arc<std::sync::Mutex<()>>, &'r std::sync::Mutex<()>, std::result::Result<std::sync::MutexGuard<'s, ()>, std::sync::PoisonError<std::sync::MutexGuard<'t0, ()>>>, &'t1 std::sync::MutexGuard<'t2, ()>, std::sync::MutexGuard<'t3, ()>, (), impl std::future::Future}]>`
+      = note: required because it appears within the type `[static generator@DefId(14:11 ~ issue_67893[8787]::run[0]::{{closure}}[0]) for<'r, 's, 't0, 't1, 't2, 't3> {std::future::ResumeTy, std::sync::Arc<std::sync::Mutex<()>>, &'r std::sync::Mutex<()>, std::result::Result<std::sync::MutexGuard<'s, ()>, std::sync::PoisonError<std::sync::MutexGuard<'t0, ()>>>, &'t1 std::sync::MutexGuard<'t2, ()>, std::sync::MutexGuard<'t3, ()>, (), impl std::future::Future}]`
+      = note: required because it appears within the type `std::future::from_generator::GenFuture<[static generator@DefId(14:11 ~ issue_67893[8787]::run[0]::{{closure}}[0]) for<'r, 's, 't0, 't1, 't2, 't3> {std::future::ResumeTy, std::sync::Arc<std::sync::Mutex<()>>, &'r std::sync::Mutex<()>, std::result::Result<std::sync::MutexGuard<'s, ()>, std::sync::PoisonError<std::sync::MutexGuard<'t0, ()>>>, &'t1 std::sync::MutexGuard<'t2, ()>, std::sync::MutexGuard<'t3, ()>, (), impl std::future::Future}]>`
19     = note: required because it appears within the type `impl std::future::Future`
20     = note: required because it appears within the type `impl std::future::Future`

It's ideal to have the same diagnostics on all the environment.

See also:

A-async-await A-diagnostics A-generators A-pretty A-reproducibility C-enhancement T-compiler

All 5 comments

DefIds shouldn't be leaked in user output.

Yeah, other places look like:

required because it appears within the type `[generator@$DIR/issue-68112.rs:48:20: 51:6 {impl std::ops::Generator, ()}]`

Perhaps we emit DefId accidentally in somewhere.

@JohnTitor that makes me think that we probably have some {:?} instead of {} somewhere.

The relevant code is:
https://github.com/rust-lang/rust/blob/ce93331e2cf21ac4b72a53854b105955919114e7/src/librustc_trait_selection/traits/error_reporting/suggestions.rs#L1633-L1648

I don't find any difference between here and similar places yet. @estebank thoughts?

@JohnTitor the place to look at is:

https://github.com/rust-lang/rust/blob/2deb39dd1fd7525eedbb9067ca52dfa71eed4fab/src/librustc_middle/ty/print/pretty.rs#L622-L654

CC @eddyb

The same applies to closures, but we are likely not displaying them this way anywhere (or we've just gotten lucky).

Was this page helpful?
0 / 5 - 0 ratings