@@ -509,12 +509,40 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
509
509
tcx,
510
510
fldop : |ty| {
511
511
if let ty:: TyAnon ( def_id, substs) = ty. sty {
512
- // Check that this is `impl Trait` type is declared by
513
- // `parent_def_id`. During the first phase of type-check, this
514
- // is true, but during NLL type-check, we sometimes encounter
515
- // `impl Trait` types in e.g. inferred closure signatures that
516
- // are not 'local' to the current function and hence which
517
- // ought not to be instantiated.
512
+ // Check that this is `impl Trait` type is
513
+ // declared by `parent_def_id` -- i.e., one whose
514
+ // value we are inferring. At present, this is
515
+ // always true during the first phase of
516
+ // type-check, but not always true later on during
517
+ // NLL. Once we support named abstract types more fully,
518
+ // this same scenario will be able to arise during all phases.
519
+ //
520
+ // Here is an example using `abstract type` that indicates
521
+ // the distinction we are checking for:
522
+ //
523
+ // ```rust
524
+ // mod a {
525
+ // pub abstract type Foo: Iterator;
526
+ // pub fn make_foo() -> Foo { .. }
527
+ // }
528
+ //
529
+ // mod b {
530
+ // fn foo() -> a::Foo { a::make_foo() }
531
+ // }
532
+ // ```
533
+ //
534
+ // Here, the return type of `foo` references a
535
+ // `TyAnon` indeed, but not one whose value is
536
+ // presently being inferred. You can get into a
537
+ // similar situation with closure return types
538
+ // today:
539
+ //
540
+ // ```rust
541
+ // fn foo() -> impl Iterator { .. }
542
+ // fn bar() {
543
+ // let x = || foo(); // returns the Anon assoc with `foo`
544
+ // }
545
+ // ```
518
546
if let Some ( anon_node_id) = tcx. hir . as_local_node_id ( def_id) {
519
547
let anon_parent_node_id = tcx. hir . get_parent ( anon_node_id) ;
520
548
let anon_parent_def_id = tcx. hir . local_def_id ( anon_parent_node_id) ;
0 commit comments