Skip to content

Compiler panic on type inference for impl Generator yielding a reference #52304

Closed

Description

@bergus

I'm getting

error: internal compiler error: librustc/infer/error_reporting/mod.rs:184: ReEmpty
thread 'main' panicked at 'Box', librustc_errors/lib.rs:554:9

when trying to compile

#![feature(generators, generator_trait)]
use std::ops::Generator;
fn example() -> impl Generator {
    || { yield &1 }
}

on rustc 1.29.0-nightly (e5f6498 2018-07-10) - Playground demo.

This seems to happen when I yield a reference type and don't specify the exact type in impl Generator<Yield=&Whatever>.

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Jul 12, 2018
  2. Zoxc commented on Aug 1, 2018

    @Zoxc
    Contributor

    We don't generate an error message for the ReEmpty region here and panic instead. Here is the message that should be printed with a placeholder:

    error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
     --> test-region.rs:3:17
      |
    3 | fn example() -> impl Generator {
      |                 ^^^^^^^^^^^^^^
      |
      = note: hidden type `[generator@test-region.rs:4:5: 4:20 for<'r> {i32, &'r i32, ()}]` captures BUG[ReEmpty]
    

    Should ReEmpty be allowed for impl Trait? cc @rust-lang/compiler

  3. added
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    on Aug 1, 2018
  4. arielb1 commented on Aug 4, 2018

    @arielb1
    Contributor

    Why are we capturing ReEmpty here?

  5. Zoxc commented on Aug 6, 2018

    @Zoxc
    Contributor

    There isn't any ReEmpty in the type. There's some scary code which replaces regions with ReEmpty which is closure related. I'm not sure what is going on there, but perhaps generators should be treated the same? cc @nikomatsakis

  6. eddyb commented on Aug 18, 2018

    @eddyb
    Contributor

    @Zoxc Oh, all of that code is for exporting impl Trait concrete types from inference results, which needs to "connect up" lifetimes inside the inferred concrete type with lifetime parameters.

  7. arielb1 commented on Aug 19, 2018

    @arielb1
    Contributor

    I think the problem is that the yield_ty of the generator ends up being &'ReEmpty u32, because nothing is constraining it to be anything else. I wonder why this isn't occurring with closures.

  8. arielb1 commented on Aug 19, 2018

    @arielb1
    Contributor

    This doesn't occur with closures because regionck forces the return type of the closure to outlive the closure's call scope, which prevents ReEmpty from being inferred.

  9. arielb1 commented on Aug 19, 2018

    @arielb1
    Contributor

    I think that the correct way to fix it would be to require all "implicit" projections in impl Trait types to be well-formed. that goes in the wrong direction.

  10. arielb1 commented on Aug 19, 2018

    @arielb1
    Contributor

    The requirement we want is that that "implicit" impl Generator for [generator type] makes sense.

    That requires that the projections in that impl are alive as long as [generator type] is alive (we don't consider that as a "well-formed" requirement, but the "projection outlives" rules assume that). That does not hold if regions in the projections can be inferred to ReEmpty - we need to be checking that.

  11. arielb1 commented on Aug 19, 2018

    @arielb1
    Contributor

    I think that in closures, CallSite (from the fix to #29793) is serving that rule with lexical lifetimes - not sure what is checking that with NLL.

  12. 2 remaining items

  13. arielb1 commented on Aug 19, 2018

    @arielb1
    Contributor

    Note: the version above is fixed by NLL. need to check whether fix is tight.

  14. added
    F-coroutines`#![feature(coroutines)]`
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Jul 28, 2019
  15. rossmacarthur commented on Dec 25, 2019

    @rossmacarthur
    Contributor

    @arielb1 any ideas on how to check whether the "fix is tight"? Otherwise perhaps this issue can be closed?

  16. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 9, 2020
  17. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 9, 2020
  18. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Feb 5, 2022
  19. added a commit that references this issue on Jul 21, 2022
  20. added a commit that references this issue on Jul 21, 2022
  21. added a commit that references this issue on Jul 21, 2022
  22. added a commit that references this issue on Jul 21, 2022
  23. added a commit that references this issue on Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coroutinesArea: CoroutinesA-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-coroutines`#![feature(coroutines)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions