Auto merge of #138845 - compiler-errors:stall-generators, r= · rust-lang/rust@5443aaa (original) (raw)

`@@ -8,6 +8,7 @@ use rustc_data_structures::unord::ExtendUnord;

`

8

8

`use rustc_errors::ErrorGuaranteed;

`

9

9

`use rustc_hir::intravisit::{self, InferKind, Visitor};

`

10

10

`use rustc_hir::{self as hir, AmbigArg, HirId};

`

``

11

`+

use rustc_infer::traits::solve::Goal;

`

11

12

`use rustc_middle::span_bug;

`

12

13

`use rustc_middle::traits::ObligationCause;

`

13

14

`use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};

`

`@@ -731,7 +732,32 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {

`

731

732

`T: TypeFoldable<TyCtxt<'tcx>>,

`

732

733

`{

`

733

734

`let value = self.fcx.resolve_vars_if_possible(value);

`

734

``

`-

let value = value.fold_with(&mut Resolver::new(self.fcx, span, self.body, true));

`

``

735

+

``

736

`+

let mut goals = vec![];

`

``

737

`+

let value =

`

``

738

`+

value.fold_with(&mut Resolver::new(self.fcx, span, self.body, true, &mut goals));

`

``

739

+

``

740

`+

// Ensure that we resolve goals we get from normalizing coroutine interiors,

`

``

741

`+

// but we shouldn't expect those goals to need normalizing (or else we'd get

`

``

742

`+

// into a somewhat awkward fixpoint situation, and we don't need it anyways).

`

``

743

`+

let mut unexpected_goals = vec![];

`

``

744

`+

self.typeck_results.coroutine_stalled_predicates.extend(

`

``

745

`+

goals

`

``

746

`+

.into_iter()

`

``

747

`+

.map(|pred| {

`

``

748

`+

self.fcx.resolve_vars_if_possible(pred).fold_with(&mut Resolver::new(

`

``

749

`+

self.fcx,

`

``

750

`+

span,

`

``

751

`+

self.body,

`

``

752

`+

false,

`

``

753

`+

&mut unexpected_goals,

`

``

754

`+

))

`

``

755

`+

})

`

``

756

`+

// FIXME: throwing away the param-env :(

`

``

757

`+

.map(|goal| (goal.predicate, self.fcx.misc(span.to_span(self.fcx.tcx)))),

`

``

758

`+

);

`

``

759

`+

assert_eq!(unexpected_goals, vec![]);

`

``

760

+

735

761

`assert!(!value.has_infer());

`

736

762

``

737

763

`` // We may have introduced e.g. ty::Error, if inference failed, make sure

``

`@@ -749,7 +775,12 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {

`

749

775

`T: TypeFoldable<TyCtxt<'tcx>>,

`

750

776

`{

`

751

777

`let value = self.fcx.resolve_vars_if_possible(value);

`

752

``

`-

let value = value.fold_with(&mut Resolver::new(self.fcx, span, self.body, false));

`

``

778

+

``

779

`+

let mut goals = vec![];

`

``

780

`+

let value =

`

``

781

`+

value.fold_with(&mut Resolver::new(self.fcx, span, self.body, false, &mut goals));

`

``

782

`+

assert_eq!(goals, vec![]);

`

``

783

+

753

784

`assert!(!value.has_infer());

`

754

785

``

755

786

`` // We may have introduced e.g. ty::Error, if inference failed, make sure

``

`@@ -786,6 +817,7 @@ struct Resolver<'cx, 'tcx> {

`

786

817

`/// Whether we should normalize using the new solver, disabled

`

787

818

`/// both when using the old solver and when resolving predicates.

`

788

819

`should_normalize: bool,

`

``

820

`+

nested_goals: &'cx mut Vec<Goal<'tcx, ty::Predicate<'tcx>>>,

`

789

821

`}

`

790

822

``

791

823

`impl<'cx, 'tcx> Resolver<'cx, 'tcx> {

`

`@@ -794,8 +826,9 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {

`

794

826

`span: &'cx dyn Locatable,

`

795

827

`body: &'tcx hir::Body<'tcx>,

`

796

828

`should_normalize: bool,

`

``

829

`+

nested_goals: &'cx mut Vec<Goal<'tcx, ty::Predicate<'tcx>>>,

`

797

830

`) -> Resolver<'cx, 'tcx> {

`

798

``

`-

Resolver { fcx, span, body, should_normalize }

`

``

831

`+

Resolver { fcx, span, body, nested_goals, should_normalize }

`

799

832

`}

`

800

833

``

801

834

`fn report_error(&self, p: impl Into<ty::GenericArg<'tcx>>) -> ErrorGuaranteed {

`

`@@ -832,12 +865,18 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {

`

832

865

`let cause = ObligationCause::misc(self.span.to_span(tcx), body_id);

`

833

866

`let at = self.fcx.at(&cause, self.fcx.param_env);

`

834

867

`let universes = vec![None; outer_exclusive_binder(value).as_usize()];

`

835

``

`-

solve::deeply_normalize_with_skipped_universes(at, value, universes).unwrap_or_else(

`

836

``

`-

|errors| {

`

``

868

`+

match solve::deeply_normalize_with_skipped_universes_and_ambiguous_goals(

`

``

869

`+

at, value, universes,

`

``

870

`+

) {

`

``

871

`+

Ok((value, goals)) => {

`

``

872

`+

self.nested_goals.extend(goals);

`

``

873

`+

value

`

``

874

`+

}

`

``

875

`+

Err(errors) => {

`

837

876

`let guar = self.fcx.err_ctxt().report_fulfillment_errors(errors);

`

838

877

`new_err(tcx, guar)

`

839

``

`-

},

`

840

``

`-

)

`

``

878

`+

}

`

``

879

`+

}

`

841

880

`} else {

`

842

881

` value

`

843

882

`};

`