Skip to content

Change in lifetime inference? #46184

Description

@ltratt

On lrtable (at least as of commit softdevteam/lrtable@ce03d95), @snim2 found that the current Rust nightly gives this error:

$ cargo check
   Compiling lrtable v0.1.0 (file:///home/snim2/Desktop/working/softdev/lrtable)
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
  --> src/lib/stategraph.rs:61:21
   |
61 |         self.states.iter().map(|x| &x.1)
   |                     ^^^^
   |
note: first, the lifetime cannot outlive the lifetime 'a as defined on the method body at 60:5...
  --> src/lib/stategraph.rs:60:5
   |
60 | /     pub fn iter_closed_states<'a>(&'a self) -> impl Iterator<Item=&Itemset> + 'a {
61 | |         self.states.iter().map(|x| &x.1)
62 | |     }
   | |_____^
note: ...so that reference does not outlive borrowed content
  --> src/lib/stategraph.rs:61:9
   |
61 |         self.states.iter().map(|x| &x.1)
   |         ^^^^^^^^^^^
   = note: but, the lifetime must be valid for the static lifetime...
note: ...so that types are compatible (expected &itemset::Itemset, found &'static itemset::Itemset)
  --> src/lib/stategraph.rs:60:48
   |
60 |     pub fn iter_closed_states<'a>(&'a self) -> impl Iterator<Item=&Itemset> + 'a {
   |                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: /checkout/src/librustc_typeck/check/writeback.rs:485: writeback: `[Deref(Some(OverloadedDeref { region: ReStatic, mutbl: MutImmutable })) -> [(itemset::Itemset, itemset::Itemset)], Borrow(Ref(ReStatic, MutImmutable)) -> &'static [(itemset::Itemset, itemset::Itemset)]]` missing from the global type context
  --> src/lib/stategraph.rs:61:9
   |
61 |         self.states.iter().map(|x| &x.1)
   |         ^^^^^^^^^^^

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.23.0-nightly (63739ab7b 2017-11-21) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:448:8
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: Could not compile `lrtable`.

To learn more, run the command again with --verbose.

We've hacked around this temporarily by returning a Box instead of the iterator directly, but this code used to compile, and I'm not sure if it's intentional that it doesn't compile any more or not?

Activity

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

    C-bugCategory: This is a bug.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.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions