Skip to content

Cache failure when environment contains predicates with free lifetimes #22019

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

Closed
nikomatsakis opened this issue Feb 6, 2015 · 0 comments · Fixed by #22028
Closed

Cache failure when environment contains predicates with free lifetimes #22019

nikomatsakis opened this issue Feb 6, 2015 · 0 comments · Fixed by #22028
Labels
A-trait-system Area: Trait system

Comments

@nikomatsakis
Copy link
Contributor

The following example fails to compile in a nonsense way:

#![allow(missing_copy_implementations)]
#![allow(unused_variables)]

use std::borrow::ToOwned;

pub struct CFGNode;

pub type Node<'a> = &'a CFGNode;

pub trait GraphWalk<'c, N> {
    /// Returns all the nodes in this graph.
    fn nodes(&'c self) where [N]:ToOwned<Vec<N>>;
}

impl<'g> GraphWalk<'g, Node<'g>> for u32
{
    fn nodes(&'g self) where [Node<'g>]:ToOwned<Vec<Node<'g>>>
    { loop { } }
}

impl<'h> GraphWalk<'h, Node<'h>> for u64
{
    fn nodes(&'h self) where [Node<'h>]:ToOwned<Vec<Node<'h>>>
    { loop { } }
}

fn main()  { }

Running this code yields the following errors:



<anon>:23:5: 24:17 error: mismatched types:
 expected `core::borrow::ToOwned<collections::vec::Vec<&'h CFGNode>>`,
    found `core::borrow::ToOwned<collections::vec::Vec<&'g CFGNode>>`
(lifetime mismatch) [E0308]
<anon>:23     fn nodes(&'h self) where [Node<'h>]:ToOwned<Vec<Node<'h>>>
<anon>:24     { loop { } }
<anon>:24:5: 24:17 note: the lifetime 'h as defined on the block at 24:4...
<anon>:24     { loop { } }
              ^~~~~~~~~~~~
<anon>:18:5: 18:17 note: ...does not necessarily outlive the lifetime 'g as defined on the block at 18:4
<anon>:18     { loop { } }
              ^~~~~~~~~~~~
<anon>:23:5: 24:17 error: mismatched types:
 expected `core::borrow::ToOwned<collections::vec::Vec<&'h CFGNode>>`,
    found `core::borrow::ToOwned<collections::vec::Vec<&'g CFGNode>>`
(lifetime mismatch) [E0308]
<anon>:23     fn nodes(&'h self) where [Node<'h>]:ToOwned<Vec<Node<'h>>>
<anon>:24     { loop { } }
<anon>:18:5: 18:17 note: the lifetime 'g as defined on the block at 18:4...
<anon>:18     { loop { } }
              ^~~~~~~~~~~~
<anon>:24:5: 24:17 note: ...does not necessarily outlive the lifetime 'h as defined on the block at 24:4
<anon>:24     { loop { } }
              ^~~~~~~~~~~~
error: aborting due to 2 previous errors
playpen: application terminated with error code 101
Program ended.

These are nonsense because you can see the compiler is comparing two lifetimes ('g and 'h) that are never simultaneously in scope. This arises due to errors in caching.

@nikomatsakis nikomatsakis added the A-trait-system Area: Trait system label Feb 6, 2015
nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Feb 7, 2015
are any where-clauses at all. This seems to be the simplest possible
rule and will (hopefully!) put an end to these annoying "cache leak"
bugs. Fixes rust-lang#22019.
bors added a commit that referenced this issue Feb 10, 2015
Simplify cache selection by just using the local cache whenever there
are any where-clauses at all. This seems to be the simplest possible
rule and will (hopefully!) put an end to these annoying "cache leak"
bugs. Fixes #22019.

r? @aturon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant