Skip to content

Commit b0ec96c

Browse files
committed
Use inner/outer generator naming instead of first/last
I personally find this clearer.
1 parent 76b1198 commit b0ec96c

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ crate trait InferCtxtExt<'tcx> {
126126
scope_span: &Option<Span>,
127127
expr: Option<hir::HirId>,
128128
snippet: String,
129-
first_generator: DefId,
130-
last_generator: Option<DefId>,
129+
inner_generator: DefId,
130+
outer_generator: Option<DefId>,
131131
trait_ref: ty::TraitRef<'_>,
132132
target_ty: Ty<'tcx>,
133133
tables: &ty::TypeckTables<'_>,
@@ -1003,16 +1003,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
10031003
// - `BindingObligation` with `impl_send (Send requirement)
10041004
//
10051005
// The first obligation in the chain is the most useful and has the generator that captured
1006-
// the type. The last generator has information about where the bound was introduced. At
1007-
// least one generator should be present for this diagnostic to be modified.
1006+
// the type. The last generator (`outer_generator` below) has information about where the
1007+
// bound was introduced. At least one generator should be present for this diagnostic to be
1008+
// modified.
10081009
let (mut trait_ref, mut target_ty) = match obligation.predicate {
10091010
ty::Predicate::Trait(p, _) => {
10101011
(Some(p.skip_binder().trait_ref), Some(p.skip_binder().self_ty()))
10111012
}
10121013
_ => (None, None),
10131014
};
10141015
let mut generator = None;
1015-
let mut last_generator = None;
1016+
let mut outer_generator = None;
10161017
let mut next_code = Some(&obligation.cause.code);
10171018
while let Some(code) = next_code {
10181019
debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
@@ -1029,7 +1030,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
10291030
match ty.kind {
10301031
ty::Generator(did, ..) => {
10311032
generator = generator.or(Some(did));
1032-
last_generator = Some(did);
1033+
outer_generator = Some(did);
10331034
}
10341035
ty::GeneratorWitness(..) => {}
10351036
_ if generator.is_none() => {
@@ -1133,7 +1134,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11331134
*expr,
11341135
snippet,
11351136
generator_did,
1136-
last_generator,
1137+
outer_generator,
11371138
trait_ref,
11381139
target_ty,
11391140
tables,
@@ -1155,8 +1156,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11551156
scope_span: &Option<Span>,
11561157
expr: Option<hir::HirId>,
11571158
snippet: String,
1158-
first_generator: DefId,
1159-
last_generator: Option<DefId>,
1159+
inner_generator: DefId,
1160+
outer_generator: Option<DefId>,
11601161
trait_ref: ty::TraitRef<'_>,
11611162
target_ty: Ty<'tcx>,
11621163
tables: &ty::TypeckTables<'_>,
@@ -1167,14 +1168,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11671168

11681169
let is_async_fn = self
11691170
.tcx
1170-
.parent(first_generator)
1171+
.parent(inner_generator)
11711172
.map(|parent_did| self.tcx.asyncness(parent_did))
11721173
.map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
11731174
.unwrap_or(false);
11741175
let is_async_move = self
11751176
.tcx
11761177
.hir()
1177-
.as_local_hir_id(first_generator)
1178+
.as_local_hir_id(inner_generator)
11781179
.and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id))
11791180
.map(|body_id| self.tcx.hir().body(body_id))
11801181
.and_then(|body| body.generator_kind())
@@ -1203,7 +1204,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12031204
let original_span = err.span.primary_span().unwrap();
12041205
let mut span = MultiSpan::from_span(original_span);
12051206

1206-
let message = if let Some(name) = last_generator
1207+
let message = if let Some(name) = outer_generator
12071208
.and_then(|generator_did| self.tcx.parent(generator_did))
12081209
.and_then(|parent_did| hir.as_local_hir_id(parent_did))
12091210
.and_then(|parent_hir_id| hir.opt_name(parent_hir_id))

0 commit comments

Comments
 (0)