Rollup merge of #101556 - compiler-errors:tweak-generator-print, r=jackh726
Tweak future opaque ty pretty printing 1. The `Return` type of a generator doesn't need to be a lang item just for diagnostic printing of types 2. We shouldn't suppress the `Output = Ty` of a opaque future if the type is a int or float var.
This commit is contained in:
commit
bdfbc3597b
5 changed files with 7 additions and 7 deletions
|
@ -238,7 +238,6 @@ language_item_table! {
|
||||||
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
|
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||||
GeneratorState, sym::generator_state, gen_state, Target::Enum, GenericRequirement::None;
|
GeneratorState, sym::generator_state, gen_state, Target::Enum, GenericRequirement::None;
|
||||||
Generator, sym::generator, gen_trait, Target::Trait, GenericRequirement::Minimum(1);
|
Generator, sym::generator, gen_trait, Target::Trait, GenericRequirement::Minimum(1);
|
||||||
GeneratorReturn, sym::generator_return, generator_return, Target::AssocTy, GenericRequirement::None;
|
|
||||||
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
|
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
|
||||||
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
|
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
|
||||||
|
|
||||||
|
|
|
@ -916,12 +916,14 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
// Skip printing `<[generator@] as Generator<_>>::Return` from async blocks,
|
// Skip printing `<[generator@] as Generator<_>>::Return` from async blocks,
|
||||||
// unless we can find out what generator return type it comes from.
|
// unless we can find out what generator return type it comes from.
|
||||||
let term = if let Some(ty) = term.skip_binder().ty()
|
let term = if let Some(ty) = term.skip_binder().ty()
|
||||||
&& let ty::Projection(ty::ProjectionTy { item_def_id, substs }) = ty.kind()
|
&& let ty::Projection(proj) = ty.kind()
|
||||||
&& Some(*item_def_id) == tcx.lang_items().generator_return()
|
&& let assoc = tcx.associated_item(proj.item_def_id)
|
||||||
|
&& assoc.trait_container(tcx) == tcx.lang_items().gen_trait()
|
||||||
|
&& assoc.name == rustc_span::sym::Return
|
||||||
{
|
{
|
||||||
if let ty::Generator(_, substs, _) = substs.type_at(0).kind() {
|
if let ty::Generator(_, substs, _) = substs.type_at(0).kind() {
|
||||||
let return_ty = substs.as_generator().return_ty();
|
let return_ty = substs.as_generator().return_ty();
|
||||||
if !return_ty.is_ty_infer() {
|
if !return_ty.is_ty_var() {
|
||||||
return_ty.into()
|
return_ty.into()
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -763,7 +763,6 @@ symbols! {
|
||||||
gen_future,
|
gen_future,
|
||||||
gen_kill,
|
gen_kill,
|
||||||
generator,
|
generator,
|
||||||
generator_return,
|
|
||||||
generator_state,
|
generator_state,
|
||||||
generators,
|
generators,
|
||||||
generic_arg_infer,
|
generic_arg_infer,
|
||||||
|
|
|
@ -83,7 +83,7 @@ pub trait Generator<R = ()> {
|
||||||
/// `return` statement or implicitly as the last expression of a generator
|
/// `return` statement or implicitly as the last expression of a generator
|
||||||
/// literal. For example futures would use this as `Result<T, E>` as it
|
/// literal. For example futures would use this as `Result<T, E>` as it
|
||||||
/// represents a completed future.
|
/// represents a completed future.
|
||||||
#[lang = "generator_return"]
|
#[cfg_attr(bootstrap, lang = "generator_return")]
|
||||||
type Return;
|
type Return;
|
||||||
|
|
||||||
/// Resumes the execution of this generator.
|
/// Resumes the execution of this generator.
|
||||||
|
|
|
@ -91,7 +91,7 @@ LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
|
||||||
| ------------------------------- the found opaque type
|
| ------------------------------- the found opaque type
|
||||||
|
|
|
|
||||||
= note: expected struct `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>`
|
= note: expected struct `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>`
|
||||||
found opaque type `impl Future`
|
found opaque type `impl Future<Output = {integer}>`
|
||||||
help: you need to pin and box this expression
|
help: you need to pin and box this expression
|
||||||
|
|
|
|
||||||
LL ~ Box::pin(async {
|
LL ~ Box::pin(async {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue