Skip to content

Commit bdfbc35

Browse files
authored
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.
2 parents 434591c + 97668a5 commit bdfbc35

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

compiler/rustc_hir/src/lang_items.rs

-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ language_item_table! {
238238
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
239239
GeneratorState, sym::generator_state, gen_state, Target::Enum, GenericRequirement::None;
240240
Generator, sym::generator, gen_trait, Target::Trait, GenericRequirement::Minimum(1);
241-
GeneratorReturn, sym::generator_return, generator_return, Target::AssocTy, GenericRequirement::None;
242241
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
243242
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
244243

compiler/rustc_middle/src/ty/print/pretty.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,14 @@ pub trait PrettyPrinter<'tcx>:
916916
// Skip printing `<[generator@] as Generator<_>>::Return` from async blocks,
917917
// unless we can find out what generator return type it comes from.
918918
let term = if let Some(ty) = term.skip_binder().ty()
919-
&& let ty::Projection(ty::ProjectionTy { item_def_id, substs }) = ty.kind()
920-
&& Some(*item_def_id) == tcx.lang_items().generator_return()
919+
&& let ty::Projection(proj) = ty.kind()
920+
&& let assoc = tcx.associated_item(proj.item_def_id)
921+
&& assoc.trait_container(tcx) == tcx.lang_items().gen_trait()
922+
&& assoc.name == rustc_span::sym::Return
921923
{
922924
if let ty::Generator(_, substs, _) = substs.type_at(0).kind() {
923925
let return_ty = substs.as_generator().return_ty();
924-
if !return_ty.is_ty_infer() {
926+
if !return_ty.is_ty_var() {
925927
return_ty.into()
926928
} else {
927929
continue;

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@ symbols! {
763763
gen_future,
764764
gen_kill,
765765
generator,
766-
generator_return,
767766
generator_state,
768767
generators,
769768
generic_arg_infer,

library/core/src/ops/generator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub trait Generator<R = ()> {
8383
/// `return` statement or implicitly as the last expression of a generator
8484
/// literal. For example futures would use this as `Result<T, E>` as it
8585
/// represents a completed future.
86-
#[lang = "generator_return"]
86+
#[cfg_attr(bootstrap, lang = "generator_return")]
8787
type Return;
8888

8989
/// Resumes the execution of this generator.

src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
9191
| ------------------------------- the found opaque type
9292
|
9393
= note: expected struct `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>`
94-
found opaque type `impl Future`
94+
found opaque type `impl Future<Output = {integer}>`
9595
help: you need to pin and box this expression
9696
|
9797
LL ~ Box::pin(async {

0 commit comments

Comments
 (0)