Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in lifetime inference? #46184

Closed
ltratt opened this issue Nov 22, 2017 · 6 comments
Closed

Change in lifetime inference? #46184

ltratt opened this issue Nov 22, 2017 · 6 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ltratt
Copy link
Contributor

ltratt commented Nov 22, 2017

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?

@ltratt
Copy link
Contributor Author

ltratt commented Nov 23, 2017

Ah, I wonder if I fingered the wrong suspect. The impl trait stuff that's recently been merged (#45918) seems a more plausible culprit?

@phil-opp
Copy link
Contributor

This affects embed-rs/net as well:

> cargo +nightly-2017-11-21 build
   Compiling net v0.1.0 (file:///home/philipp/Documents/net)
    Finished dev [unoptimized + debuginfo] target(s) in 0.90 secs

> cargo +nightly-2017-11-22 build
   Compiling net v0.1.0 (file:///home/philipp/Documents/net)
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
   --> src/tcp.rs:215:27
    |
215 |         self.packet_queue.values()
    |                           ^^^^^^
    |
note: first, the lifetime cannot outlive the lifetime 'a as defined on the method body at 214:5...
   --> src/tcp.rs:214:5
    |
214 | /     pub fn packets<'a>(&'a mut self) -> impl Iterator<Item = &TcpPacket<Box<[u8]>>> {
215 | |         self.packet_queue.values()
216 | |     }
    | |_____^
note: ...so that reference does not outlive borrowed content
   --> src/tcp.rs:215:9
    |
215 |         self.packet_queue.values()
    |         ^^^^^^^^^^^^^^^^^
    = note: but, the lifetime must be valid for the static lifetime...
note: ...so that return value is valid for the call
   --> src/tcp.rs:214:41
    |
214 |     pub fn packets<'a>(&'a mut self) -> impl Iterator<Item = &TcpPacket<Box<[u8]>>> {
    |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@ltratt
Copy link
Contributor Author

ltratt commented Nov 23, 2017

#46205 may also be relevant?

@pietroalbini pietroalbini added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jan 23, 2018
@nikomatsakis
Copy link
Contributor

Can one of you isolate these examples at all? We did make changes to how impl Trait interacts with lifetimes that could be affecting these errors.

@ltratt
Copy link
Contributor Author

ltratt commented Feb 24, 2018

With a recent nightly, I no longer get an error on that version of lrtable.

[If you want to replicate it, clone https://github.com/softdevteam/lrtable/commit/ce03d95d4a5b722b4335c19fc2cc459777ce4195 then edit this line in Cargo.toml:

cfgrammar = { git = "https://github.com/softdevteam/cfgrammar" }      

to:

cfgrammar = { git = "https://github.com/softdevteam/cfgrammar", rev = "907703afc5243f6ebf8b3aec9df5d849cfacd09d" }      

]

@estebank
Copy link
Contributor

Closing as per @ltratt's prior comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants