Repository navigation
Compiler panic on type inference for impl Generator yielding a reference #52304
Copy link
Copy link
Closed
Labels
A-coroutinesArea: CoroutinesArea: CoroutinesA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-coroutines`#![feature(coroutines)]``#![feature(coroutines)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: 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.Relevant 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.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Description
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>.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-coroutinesArea: CoroutinesArea: CoroutinesA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-coroutines`#![feature(coroutines)]``#![feature(coroutines)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: 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.Relevant 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.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Activity
Zoxc commentedon Aug 1, 2018
We don't generate an error message for the
ReEmptyregion here and panic instead. Here is the message that should be printed with a placeholder:Should
ReEmptybe allowed for impl Trait? cc @rust-lang/compilerarielb1 commentedon Aug 4, 2018
Why are we capturing
ReEmptyhere?Zoxc commentedon Aug 6, 2018
There isn't any
ReEmptyin the type. There's some scary code which replaces regions withReEmptywhich is closure related. I'm not sure what is going on there, but perhaps generators should be treated the same? cc @nikomatsakiseddyb commentedon Aug 18, 2018
@Zoxc Oh, all of that code is for exporting
impl Traitconcrete types from inference results, which needs to "connect up" lifetimes inside the inferred concrete type with lifetime parameters.arielb1 commentedon Aug 19, 2018
I think the problem is that the
yield_tyof 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.arielb1 commentedon Aug 19, 2018
This doesn't occur with closures because regionck forces the return type of the closure to outlive the closure's call scope, which prevents
ReEmptyfrom being inferred.arielb1 commentedon Aug 19, 2018
I think that the correct way to fix it would be to
require all "implicit" projections inthat goes in the wrong direction.impl Traittypes to be well-formed.arielb1 commentedon Aug 19, 2018
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 toReEmpty- we need to be checking that.arielb1 commentedon Aug 19, 2018
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.2 remaining items
arielb1 commentedon Aug 19, 2018
Note: the version above is fixed by NLL. need to check whether fix is tight.
rossmacarthur commentedon Dec 25, 2019
@arielb1 any ideas on how to check whether the "fix is tight"? Otherwise perhaps this issue can be closed?
Add regression test for rust-lang#52304
Rollup merge of rust-lang#99549 - JohnTitor:issue-52304, r=compiler-e…
Rollup merge of rust-lang#99549 - JohnTitor:issue-52304, r=compiler-e…
Rollup merge of rust-lang#99549 - JohnTitor:issue-52304, r=compiler-e…
Rollup merge of rust-lang#99549 - JohnTitor:issue-52304, r=compiler-e…
Auto merge of rust-lang#99567 - matthiaskrgr:rollup-08hh3r4, r=matthi…