After removing `GenFuture`, I special-cased async generators to pretty-print as `impl Future<Output = X>` mainly to avoid too much diagnostics changes originally.
This now reverses that change so that async fn/blocks are pretty-printed as `[$movability `async` $something@$source-position]` in various diagnostics, and updates the tests that this touches.
ccx: &ConstCx<'_, 'tcx>,
span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
- let msg = format!("{}s are not allowed in {}s", self.0, ccx.const_kind());
+ let msg = format!("{}s are not allowed in {}s", self.0.descr(), ccx.const_kind());
if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 {
ccx.tcx.sess.create_feature_err(
UnallowedOpInConstContext { span, msg },
impl fmt::Display for AsyncGeneratorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
- AsyncGeneratorKind::Block => "`async` block",
- AsyncGeneratorKind::Closure => "`async` closure body",
- AsyncGeneratorKind::Fn => "`async fn` body",
+ AsyncGeneratorKind::Block => "async block",
+ AsyncGeneratorKind::Closure => "async closure body",
+ AsyncGeneratorKind::Fn => "async fn body",
})
}
}
} else {
let note = format!(
"the type is part of the {} because of this {}",
- self.kind, yield_data.source
+ self.kind.descr(),
+ yield_data.source
);
self.fcx
}
ty::Str => p!("str"),
ty::Generator(did, substs, movability) => {
- // FIXME(swatinem): async constructs used to be pretty printed
- // as `impl Future` previously due to the `from_generator` wrapping.
- // lets special case this here for now to avoid churn in diagnostics.
- let generator_kind = self.tcx().generator_kind(did);
- if matches!(generator_kind, Some(hir::GeneratorKind::Async(..))) {
- let return_ty = substs.as_generator().return_ty();
- p!(write("impl Future<Output = {}>", return_ty));
-
- return Ok(self);
- }
-
p!(write("["));
- match movability {
- hir::Movability::Movable => {}
- hir::Movability::Static => p!("static "),
+ let generator_kind = self.tcx().generator_kind(did).unwrap();
+ let should_print_movability =
+ self.should_print_verbose() || generator_kind == hir::GeneratorKind::Gen;
+
+ if should_print_movability {
+ match movability {
+ hir::Movability::Movable => {}
+ hir::Movability::Static => p!("static "),
+ }
}
if !self.should_print_verbose() {
- p!("generator");
+ p!(write("{}", generator_kind));
// FIXME(eddyb) should use `def_span`.
if let Some(did) = did.as_local() {
let span = self.tcx().def_span(did);
let sp = self.tcx.def_span(def_id);
// Special-case this to say "async block" instead of `[static generator]`.
- let kind = tcx.generator_kind(def_id).unwrap();
+ let kind = tcx.generator_kind(def_id).unwrap().descr();
err.span_note(
sp,
&format!("required because it's used within this {}", kind),
return 0u8;
};
let _: &dyn Future<Output = ()> = █
- //~^ ERROR expected `impl Future<Output = u8>` to be a future that resolves to `()`, but it resolves to `u8`
+ //~^ ERROR to be a future that resolves to `()`, but it resolves to `u8`
}
async fn return_targets_async_block_not_async_fn() -> u8 {
return 0u8;
};
let _: &dyn Future<Output = ()> = █
- //~^ ERROR expected `impl Future<Output = u8>` to be a future that resolves to `()`, but it resolves to `u8`
+ //~^ ERROR to be a future that resolves to `()`, but it resolves to `u8`
}
fn no_break_in_async_block() {
LL | | }
| |_^ expected `u8`, found `()`
-error[E0271]: expected `impl Future<Output = u8>` to be a future that resolves to `()`, but it resolves to `u8`
+error[E0271]: expected `[async block@$DIR/async-block-control-flow-static-semantics.rs:23:17: 25:6]` to be a future that resolves to `()`, but it resolves to `u8`
--> $DIR/async-block-control-flow-static-semantics.rs:26:39
|
LL | let _: &dyn Future<Output = ()> = █
| ^^^^^^ expected `()`, found `u8`
|
- = note: required for the cast from `impl Future<Output = u8>` to the object type `dyn Future<Output = ()>`
+ = note: required for the cast from `[async block@$DIR/async-block-control-flow-static-semantics.rs:23:17: 25:6]` to the object type `dyn Future<Output = ()>`
error[E0308]: mismatched types
--> $DIR/async-block-control-flow-static-semantics.rs:12:43
| |
| implicitly returns `()` as its body has no tail or `return` expression
-error[E0271]: expected `impl Future<Output = u8>` to be a future that resolves to `()`, but it resolves to `u8`
+error[E0271]: expected `[async block@$DIR/async-block-control-flow-static-semantics.rs:14:17: 16:6]` to be a future that resolves to `()`, but it resolves to `u8`
--> $DIR/async-block-control-flow-static-semantics.rs:17:39
|
LL | let _: &dyn Future<Output = ()> = █
| ^^^^^^ expected `()`, found `u8`
|
- = note: required for the cast from `impl Future<Output = u8>` to the object type `dyn Future<Output = ()>`
+ = note: required for the cast from `[async block@$DIR/async-block-control-flow-static-semantics.rs:14:17: 16:6]` to the object type `dyn Future<Output = ()>`
error[E0308]: mismatched types
--> $DIR/async-block-control-flow-static-semantics.rs:49:44
| | arguments to this function are incorrect
| the expected `async` block
|
- = note: expected `async` block `impl Future<Output = ()>` (`async` block)
- found `async` block `impl Future<Output = ()>` (`async` block)
+ = note: expected `async` block `[async block@$DIR/generator-desc.rs:10:9: 10:17]`
+ found `async` block `[async block@$DIR/generator-desc.rs:10:19: 10:27]`
note: function defined here
--> $SRC_DIR/core/src/future/mod.rs:LL:COL
|
| | the expected `async` closure body
| arguments to this function are incorrect
|
- = note: expected `async` closure body `impl Future<Output = ()>` (`async` closure body)
- found `async` closure body `impl Future<Output = ()>` (`async` closure body)
+ = note: expected `async` closure body `[async closure body@$DIR/generator-desc.rs:14:19: 14:21]`
+ found `async` closure body `[async closure body@$DIR/generator-desc.rs:14:36: 14:38]`
note: function defined here
--> $DIR/generator-desc.rs:8:4
|
LL | | });
| |_____^ future created by async block is not `Send`
|
- = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*mut ()`
+ = help: within `[async block@$DIR/issue-67252-unnamed-future.rs:18:11: 21:6]`, the trait `Send` is not implemented for `*mut ()`
note: future is not `Send` as this value is used across an await
--> $DIR/issue-67252-unnamed-future.rs:20:16
|
|
LL | let x = x;
| ^ has type `&T` which is not `Send`, because `T` is not `Sync`
- = note: required for the cast from `impl Future<Output = ()>` to the object type `dyn Future<Output = ()> + Send`
+ = note: required for the cast from `[async block@$DIR/issue-86507.rs:18:17: 20:18]` to the object type `dyn Future<Output = ()> + Send`
help: consider further restricting this bound
|
LL | fn bar<'me, 'async_trait, T: Send + std::marker::Sync>(x: &'me T)
LL | | })
| |_____^ future created by async block is not `Send`
|
- = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8`
+ = help: within `[async block@$DIR/issue-65436-raw-ptr-not-send.rs:16:17: 19:6]`, the trait `Send` is not implemented for `*const u8`
note: future is not `Send` as this value is used across an await
--> $DIR/issue-65436-raw-ptr-not-send.rs:18:35
|
-error[E0277]: `impl Future<Output = u32>` is not a future
+error[E0277]: `[async fn body@$DIR/async.rs:7:29: 9:2]` is not a future
--> $DIR/async.rs:7:29
|
LL | async fn foo(x: u32) -> u32 {
LL | | }
| | ^
| | |
- | |_`impl Future<Output = u32>` is not a future
+ | |_`[async fn body@$DIR/async.rs:7:29: 9:2]` is not a future
| required by a bound introduced by this call
|
- = help: the trait `Future` is not implemented for `impl Future<Output = u32>`
- = note: impl Future<Output = u32> must be a future or must implement `IntoFuture` to be awaited
+ = help: the trait `Future` is not implemented for `[async fn body@$DIR/async.rs:7:29: 9:2]`
+ = note: [async fn body@$DIR/async.rs:7:29: 9:2] must be a future or must implement `IntoFuture` to be awaited
note: required by a bound in `identity_future`
--> $SRC_DIR/core/src/future/mod.rs:LL:COL
|
LL | pub const fn identity_future<O, Fut: Future<Output = O>>(f: Fut) -> Fut {
| ^^^^^^^^^^^^^^^^^^ required by this bound in `identity_future`
-error[E0277]: the size for values of type `<impl Future<Output = u32> as Future>::Output` cannot be known at compilation time
+error[E0277]: the size for values of type `<[async fn body@$DIR/async.rs:7:29: 9:2] as Future>::Output` cannot be known at compilation time
--> $DIR/async.rs:7:29
|
LL | async fn foo(x: u32) -> u32 {
LL | | }
| |_^ doesn't have a size known at compile-time
|
- = help: the trait `Sized` is not implemented for `<impl Future<Output = u32> as Future>::Output`
+ = help: the trait `Sized` is not implemented for `<[async fn body@$DIR/async.rs:7:29: 9:2] as Future>::Output`
note: required by a bound in `identity_future`
--> $SRC_DIR/core/src/future/mod.rs:LL:COL
|
LL | pub const fn identity_future<O, Fut: Future<Output = O>>(f: Fut) -> Fut {
| ^ required by this bound in `identity_future`
-error[E0277]: `impl Future<Output = u32>` is not a future
+error[E0277]: `[async fn body@$DIR/async.rs:7:29: 9:2]` is not a future
--> $DIR/async.rs:7:25
|
LL | async fn foo(x: u32) -> u32 {
- | ^^^ `impl Future<Output = u32>` is not a future
+ | ^^^ `[async fn body@$DIR/async.rs:7:29: 9:2]` is not a future
|
- = help: the trait `Future` is not implemented for `impl Future<Output = u32>`
- = note: impl Future<Output = u32> must be a future or must implement `IntoFuture` to be awaited
+ = help: the trait `Future` is not implemented for `[async fn body@$DIR/async.rs:7:29: 9:2]`
+ = note: [async fn body@$DIR/async.rs:7:29: 9:2] must be a future or must implement `IntoFuture` to be awaited
-error[E0280]: the requirement `<impl Future<Output = u32> as Future>::Output == u32` is not satisfied
+error[E0280]: the requirement `<[async fn body@$DIR/async.rs:7:29: 9:2] as Future>::Output == u32` is not satisfied
--> $DIR/async.rs:7:25
|
LL | async fn foo(x: u32) -> u32 {
drop(non_clone);
};
check_copy(&inner_non_clone);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied
+ //~^ ERROR : Copy` is not satisfied
check_clone(&inner_non_clone);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied
+ //~^ ERROR : Clone` is not satisfied
let non_clone = NonClone;
let outer_non_clone = async move {
drop(non_clone);
};
check_copy(&outer_non_clone);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied
+ //~^ ERROR : Copy` is not satisfied
check_clone(&outer_non_clone);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied
+ //~^ ERROR : Clone` is not satisfied
let maybe_copy_clone = async move {};
check_copy(&maybe_copy_clone);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied
+ //~^ ERROR : Copy` is not satisfied
check_clone(&maybe_copy_clone);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied
+ //~^ ERROR : Clone` is not satisfied
let inner_non_clone_fn = the_inner_non_clone_fn();
check_copy(&inner_non_clone_fn);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied
+ //~^ ERROR : Copy` is not satisfied
check_clone(&inner_non_clone_fn);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied
+ //~^ ERROR : Clone` is not satisfied
let outer_non_clone_fn = the_outer_non_clone_fn(NonClone);
check_copy(&outer_non_clone_fn);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied
+ //~^ ERROR : Copy` is not satisfied
check_clone(&outer_non_clone_fn);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied
+ //~^ ERROR : Clone` is not satisfied
let maybe_copy_clone_fn = the_maybe_copy_clone_fn();
check_copy(&maybe_copy_clone_fn);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied
+ //~^ ERROR : Copy` is not satisfied
check_clone(&maybe_copy_clone_fn);
- //~^ ERROR the trait bound `impl Future<Output = ()>: Clone` is not satisfied
+ //~^ ERROR : Clone` is not satisfied
}
async fn the_inner_non_clone_fn() {
drop(non_clone);
}
-async fn the_maybe_copy_clone_fn() {
-}
+async fn the_maybe_copy_clone_fn() {}
fn check_copy<T: Copy>(_x: &T) {}
fn check_clone<T: Clone>(_x: &T) {}
-error[E0277]: the trait bound `impl Future<Output = ()>: Copy` is not satisfied
+error[E0277]: the trait bound `[async block@$DIR/clone-impl-async.rs:12:27: 16:6]: Copy` is not satisfied
--> $DIR/clone-impl-async.rs:17:16
|
LL | check_copy(&inner_non_clone);
- | ---------- ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = ()>`
+ | ---------- ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `[async block@$DIR/clone-impl-async.rs:12:27: 16:6]`
| |
| required by a bound introduced by this call
|
note: required by a bound in `check_copy`
- --> $DIR/clone-impl-async.rs:70:18
+ --> $DIR/clone-impl-async.rs:69:18
|
LL | fn check_copy<T: Copy>(_x: &T) {}
| ^^^^ required by this bound in `check_copy`
-error[E0277]: the trait bound `impl Future<Output = ()>: Clone` is not satisfied
+error[E0277]: the trait bound `[async block@$DIR/clone-impl-async.rs:12:27: 16:6]: Clone` is not satisfied
--> $DIR/clone-impl-async.rs:19:17
|
LL | check_clone(&inner_non_clone);
- | ----------- ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `impl Future<Output = ()>`
+ | ----------- ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `[async block@$DIR/clone-impl-async.rs:12:27: 16:6]`
| |
| required by a bound introduced by this call
|
note: required by a bound in `check_clone`
- --> $DIR/clone-impl-async.rs:71:19
+ --> $DIR/clone-impl-async.rs:70:19
|
LL | fn check_clone<T: Clone>(_x: &T) {}
| ^^^^^ required by this bound in `check_clone`
-error[E0277]: the trait bound `impl Future<Output = ()>: Copy` is not satisfied
+error[E0277]: the trait bound `[async block@$DIR/clone-impl-async.rs:23:27: 25:6]: Copy` is not satisfied
--> $DIR/clone-impl-async.rs:26:16
|
LL | check_copy(&outer_non_clone);
- | ---------- ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = ()>`
+ | ---------- ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `[async block@$DIR/clone-impl-async.rs:23:27: 25:6]`
| |
| required by a bound introduced by this call
|
note: required by a bound in `check_copy`
- --> $DIR/clone-impl-async.rs:70:18
+ --> $DIR/clone-impl-async.rs:69:18
|
LL | fn check_copy<T: Copy>(_x: &T) {}
| ^^^^ required by this bound in `check_copy`
-error[E0277]: the trait bound `impl Future<Output = ()>: Clone` is not satisfied
+error[E0277]: the trait bound `[async block@$DIR/clone-impl-async.rs:23:27: 25:6]: Clone` is not satisfied
--> $DIR/clone-impl-async.rs:28:17
|
LL | check_clone(&outer_non_clone);
- | ----------- ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `impl Future<Output = ()>`
+ | ----------- ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `[async block@$DIR/clone-impl-async.rs:23:27: 25:6]`
| |
| required by a bound introduced by this call
|
note: required by a bound in `check_clone`
- --> $DIR/clone-impl-async.rs:71:19
+ --> $DIR/clone-impl-async.rs:70:19
|
LL | fn check_clone<T: Clone>(_x: &T) {}
| ^^^^^ required by this bound in `check_clone`
-error[E0277]: the trait bound `impl Future<Output = ()>: Copy` is not satisfied
+error[E0277]: the trait bound `[async block@$DIR/clone-impl-async.rs:31:28: 31:41]: Copy` is not satisfied
--> $DIR/clone-impl-async.rs:32:16
|
LL | check_copy(&maybe_copy_clone);
- | ---------- ^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = ()>`
+ | ---------- ^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `[async block@$DIR/clone-impl-async.rs:31:28: 31:41]`
| |
| required by a bound introduced by this call
|
note: required by a bound in `check_copy`
- --> $DIR/clone-impl-async.rs:70:18
+ --> $DIR/clone-impl-async.rs:69:18
|
LL | fn check_copy<T: Copy>(_x: &T) {}
| ^^^^ required by this bound in `check_copy`
-error[E0277]: the trait bound `impl Future<Output = ()>: Clone` is not satisfied
+error[E0277]: the trait bound `[async block@$DIR/clone-impl-async.rs:31:28: 31:41]: Clone` is not satisfied
--> $DIR/clone-impl-async.rs:34:17
|
LL | check_clone(&maybe_copy_clone);
- | ----------- ^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `impl Future<Output = ()>`
+ | ----------- ^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `[async block@$DIR/clone-impl-async.rs:31:28: 31:41]`
| |
| required by a bound introduced by this call
|
note: required by a bound in `check_clone`
- --> $DIR/clone-impl-async.rs:71:19
+ --> $DIR/clone-impl-async.rs:70:19
|
LL | fn check_clone<T: Clone>(_x: &T) {}
| ^^^^^ required by this bound in `check_clone`
| required by a bound introduced by this call
|
note: required by a bound in `check_copy`
- --> $DIR/clone-impl-async.rs:70:18
+ --> $DIR/clone-impl-async.rs:69:18
|
LL | fn check_copy<T: Copy>(_x: &T) {}
| ^^^^ required by this bound in `check_copy`
| required by a bound introduced by this call
|
note: required by a bound in `check_clone`
- --> $DIR/clone-impl-async.rs:71:19
+ --> $DIR/clone-impl-async.rs:70:19
|
LL | fn check_clone<T: Clone>(_x: &T) {}
| ^^^^^ required by this bound in `check_clone`
| required by a bound introduced by this call
|
note: required by a bound in `check_copy`
- --> $DIR/clone-impl-async.rs:70:18
+ --> $DIR/clone-impl-async.rs:69:18
|
LL | fn check_copy<T: Copy>(_x: &T) {}
| ^^^^ required by this bound in `check_copy`
| required by a bound introduced by this call
|
note: required by a bound in `check_clone`
- --> $DIR/clone-impl-async.rs:71:19
+ --> $DIR/clone-impl-async.rs:70:19
|
LL | fn check_clone<T: Clone>(_x: &T) {}
| ^^^^^ required by this bound in `check_clone`
| required by a bound introduced by this call
|
note: required by a bound in `check_copy`
- --> $DIR/clone-impl-async.rs:70:18
+ --> $DIR/clone-impl-async.rs:69:18
|
LL | fn check_copy<T: Copy>(_x: &T) {}
| ^^^^ required by this bound in `check_copy`
| required by a bound introduced by this call
|
note: required by a bound in `check_clone`
- --> $DIR/clone-impl-async.rs:71:19
+ --> $DIR/clone-impl-async.rs:70:19
|
LL | fn check_clone<T: Clone>(_x: &T) {}
| ^^^^^ required by this bound in `check_clone`
impl<S> Bar for S {
type E = impl std::marker::Copy;
fn foo<T>() -> Self::E {
- //~^ ERROR the trait bound `impl Future<Output = ()>: Copy` is not satisfied [E0277]
+ //~^ ERROR : Copy` is not satisfied [E0277]
async {}
}
}
-error[E0277]: the trait bound `impl Future<Output = ()>: Copy` is not satisfied
+error[E0277]: the trait bound `[async block@$DIR/issue-55872-3.rs:16:9: 16:17]: Copy` is not satisfied
--> $DIR/issue-55872-3.rs:14:20
|
LL | fn foo<T>() -> Self::E {
- | ^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = ()>`
+ | ^^^^^^^ the trait `Copy` is not implemented for `[async block@$DIR/issue-55872-3.rs:16:9: 16:17]`
error: aborting due to previous error
struct Bug {
V1: [(); {
fn concrete_use() -> F {
- //~^ ERROR expected `impl Future<Output = ()>` to be a future that resolves to `u8`, but it resolves to `()`
+ //~^ ERROR to be a future that resolves to `u8`, but it resolves to `()`
async {}
}
let f: F = async { 1 };
LL | }],
| - value is dropped here
-error[E0271]: expected `impl Future<Output = ()>` to be a future that resolves to `u8`, but it resolves to `()`
+error[E0271]: expected `[async block@$DIR/issue-78722.rs:11:13: 11:21]` to be a future that resolves to `u8`, but it resolves to `()`
--> $DIR/issue-78722.rs:9:30
|
LL | fn concrete_use() -> F {
LL | const { || {} } => {},
| ^^^^^^^^^^^^^^^
-error: `impl Future<Output = ()>` cannot be used in patterns
+error: `[async block@$DIR/non-structural-match-types.rs:12:17: 12:25]` cannot be used in patterns
--> $DIR/non-structural-match-types.rs:12:9
|
LL | const { async {} } => {},
| arguments to this function are incorrect
|
= note: expected struct `Pin<Box<dyn Future<Output = i32> + Send>>`
- found `async` block `impl Future<Output = {integer}>`
+ found `async` block `[async block@$DIR/expected-boxed-future-isnt-pinned.rs:28:5: 30:6]`
note: function defined here
--> $SRC_DIR/core/src/future/mod.rs:LL:COL
|