Skip to content

Commit b129b32

Browse files
committed
Use inner/outer generator naming instead of first/last
I personally find this clearer.
1 parent 8e18e26 commit b129b32

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
@@ -127,8 +127,8 @@ pub trait InferCtxtExt<'tcx> {
127127
scope_span: &Option<Span>,
128128
expr: Option<hir::HirId>,
129129
snippet: String,
130-
first_generator: DefId,
131-
last_generator: Option<DefId>,
130+
inner_generator: DefId,
131+
outer_generator: Option<DefId>,
132132
trait_ref: ty::TraitRef<'_>,
133133
target_ty: Ty<'tcx>,
134134
tables: &ty::TypeckTables<'_>,
@@ -1118,16 +1118,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11181118
// - `BindingObligation` with `impl_send (Send requirement)
11191119
//
11201120
// The first obligation in the chain is the most useful and has the generator that captured
1121-
// the type. The last generator has information about where the bound was introduced. At
1122-
// least one generator should be present for this diagnostic to be modified.
1121+
// the type. The last generator (`outer_generator` below) has information about where the
1122+
// bound was introduced. At least one generator should be present for this diagnostic to be
1123+
// modified.
11231124
let (mut trait_ref, mut target_ty) = match obligation.predicate {
11241125
ty::Predicate::Trait(p, _) => {
11251126
(Some(p.skip_binder().trait_ref), Some(p.skip_binder().self_ty()))
11261127
}
11271128
_ => (None, None),
11281129
};
11291130
let mut generator = None;
1130-
let mut last_generator = None;
1131+
let mut outer_generator = None;
11311132
let mut next_code = Some(&obligation.cause.code);
11321133
while let Some(code) = next_code {
11331134
debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
@@ -1144,7 +1145,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
11441145
match ty.kind {
11451146
ty::Generator(did, ..) => {
11461147
generator = generator.or(Some(did));
1147-
last_generator = Some(did);
1148+
outer_generator = Some(did);
11481149
}
11491150
ty::GeneratorWitness(..) => {}
11501151
_ if generator.is_none() => {
@@ -1248,7 +1249,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12481249
*expr,
12491250
snippet,
12501251
generator_did,
1251-
last_generator,
1252+
outer_generator,
12521253
trait_ref,
12531254
target_ty,
12541255
tables,
@@ -1270,8 +1271,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12701271
scope_span: &Option<Span>,
12711272
expr: Option<hir::HirId>,
12721273
snippet: String,
1273-
first_generator: DefId,
1274-
last_generator: Option<DefId>,
1274+
inner_generator: DefId,
1275+
outer_generator: Option<DefId>,
12751276
trait_ref: ty::TraitRef<'_>,
12761277
target_ty: Ty<'tcx>,
12771278
tables: &ty::TypeckTables<'_>,
@@ -1282,14 +1283,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12821283

12831284
let is_async_fn = self
12841285
.tcx
1285-
.parent(first_generator)
1286+
.parent(inner_generator)
12861287
.map(|parent_did| self.tcx.asyncness(parent_did))
12871288
.map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
12881289
.unwrap_or(false);
12891290
let is_async_move = self
12901291
.tcx
12911292
.hir()
1292-
.as_local_hir_id(first_generator)
1293+
.as_local_hir_id(inner_generator)
12931294
.and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id))
12941295
.map(|body_id| self.tcx.hir().body(body_id))
12951296
.and_then(|body| body.generator_kind())
@@ -1318,7 +1319,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
13181319
let original_span = err.span.primary_span().unwrap();
13191320
let mut span = MultiSpan::from_span(original_span);
13201321

1321-
let message = if let Some(name) = last_generator
1322+
let message = if let Some(name) = outer_generator
13221323
.and_then(|generator_did| self.tcx.parent(generator_did))
13231324
.and_then(|parent_did| hir.as_local_hir_id(parent_did))
13241325
.and_then(|parent_hir_id| hir.opt_name(parent_hir_id))

0 commit comments

Comments
 (0)