Use inner/outer generator naming instead of first/last
I personally find this clearer.
This commit is contained in:
parent
8e18e26f12
commit
b129b32afa
@ -127,8 +127,8 @@ pub trait InferCtxtExt<'tcx> {
|
||||
scope_span: &Option<Span>,
|
||||
expr: Option<hir::HirId>,
|
||||
snippet: String,
|
||||
first_generator: DefId,
|
||||
last_generator: Option<DefId>,
|
||||
inner_generator: DefId,
|
||||
outer_generator: Option<DefId>,
|
||||
trait_ref: ty::TraitRef<'_>,
|
||||
target_ty: Ty<'tcx>,
|
||||
tables: &ty::TypeckTables<'_>,
|
||||
@ -1118,8 +1118,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
// - `BindingObligation` with `impl_send (Send requirement)
|
||||
//
|
||||
// The first obligation in the chain is the most useful and has the generator that captured
|
||||
// the type. The last generator has information about where the bound was introduced. At
|
||||
// least one generator should be present for this diagnostic to be modified.
|
||||
// the type. The last generator (`outer_generator` below) has information about where the
|
||||
// bound was introduced. At least one generator should be present for this diagnostic to be
|
||||
// modified.
|
||||
let (mut trait_ref, mut target_ty) = match obligation.predicate {
|
||||
ty::Predicate::Trait(p, _) => {
|
||||
(Some(p.skip_binder().trait_ref), Some(p.skip_binder().self_ty()))
|
||||
@ -1127,7 +1128,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
_ => (None, None),
|
||||
};
|
||||
let mut generator = None;
|
||||
let mut last_generator = None;
|
||||
let mut outer_generator = None;
|
||||
let mut next_code = Some(&obligation.cause.code);
|
||||
while let Some(code) = next_code {
|
||||
debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
|
||||
@ -1144,7 +1145,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
match ty.kind {
|
||||
ty::Generator(did, ..) => {
|
||||
generator = generator.or(Some(did));
|
||||
last_generator = Some(did);
|
||||
outer_generator = Some(did);
|
||||
}
|
||||
ty::GeneratorWitness(..) => {}
|
||||
_ if generator.is_none() => {
|
||||
@ -1248,7 +1249,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
*expr,
|
||||
snippet,
|
||||
generator_did,
|
||||
last_generator,
|
||||
outer_generator,
|
||||
trait_ref,
|
||||
target_ty,
|
||||
tables,
|
||||
@ -1270,8 +1271,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
scope_span: &Option<Span>,
|
||||
expr: Option<hir::HirId>,
|
||||
snippet: String,
|
||||
first_generator: DefId,
|
||||
last_generator: Option<DefId>,
|
||||
inner_generator: DefId,
|
||||
outer_generator: Option<DefId>,
|
||||
trait_ref: ty::TraitRef<'_>,
|
||||
target_ty: Ty<'tcx>,
|
||||
tables: &ty::TypeckTables<'_>,
|
||||
@ -1282,14 +1283,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
|
||||
let is_async_fn = self
|
||||
.tcx
|
||||
.parent(first_generator)
|
||||
.parent(inner_generator)
|
||||
.map(|parent_did| self.tcx.asyncness(parent_did))
|
||||
.map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
|
||||
.unwrap_or(false);
|
||||
let is_async_move = self
|
||||
.tcx
|
||||
.hir()
|
||||
.as_local_hir_id(first_generator)
|
||||
.as_local_hir_id(inner_generator)
|
||||
.and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id))
|
||||
.map(|body_id| self.tcx.hir().body(body_id))
|
||||
.and_then(|body| body.generator_kind())
|
||||
@ -1318,7 +1319,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
let original_span = err.span.primary_span().unwrap();
|
||||
let mut span = MultiSpan::from_span(original_span);
|
||||
|
||||
let message = if let Some(name) = last_generator
|
||||
let message = if let Some(name) = outer_generator
|
||||
.and_then(|generator_did| self.tcx.parent(generator_did))
|
||||
.and_then(|parent_did| hir.as_local_hir_id(parent_did))
|
||||
.and_then(|parent_hir_id| hir.opt_name(parent_hir_id))
|
||||
|
Loading…
x
Reference in New Issue
Block a user