Skip to content

Instantly share code, notes, and snippets.

@maxsnew
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxsnew/9d3d30b469e7e39909d0 to your computer and use it in GitHub Desktop.
Save maxsnew/9d3d30b469e7e39909d0 to your computer and use it in GitHub Desktop.
Non-deterministic Lifetime Error
extern crate graphviz;
use graphviz as dot;
use std::str;
type Nd = uint;
type Ed = (uint, uint);
struct Graph<'a> {
nodes: Vec<&'a str>,
edges: Vec<Ed>,
}
impl<'a> dot::Labeller<'a, Nd, Ed> for Graph<'a> {
fn graph_id(&self) -> dot::Id<'a> {
dot::Id::new("example3")
}
fn node_id(&self, n: &Nd) -> dot::Id {
dot::Id::new(format!("N{:u}", *n))
}
fn node_label<'a>(&'a self, i: &Nd) -> dot::LabelText<'a> {
dot::LabelStr(str::Slice(self.nodes[*i].as_slice()))
}
}
extern crate graphviz;
use graphviz as dot;
use std::str;
type Nd = uint;
type Ed = (uint, uint);
struct Graph<'a> {
nodes: Vec<&'a str>,
edges: Vec<Ed>,
}
impl<'a> dot::Labeller<'a, Nd, Ed> for Graph<'a> {
fn graph_id(&self) -> dot::Id<'a> {
dot::Id::new("example3")
}
fn node_id(&self, n: &Nd) -> dot::Id {
dot::Id::new(format!("N{:u}", *n))
}
fn node_label<'a>(&self, i: &Nd) -> dot::LabelText<'a> {
dot::LabelStr(str::Slice(self.nodes[*i].as_slice()))
}
}
Sometimes I get this bad error message:
lifetime-error.rs:21:34: 21:48 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
lifetime-error.rs:21 dot::LabelStr(str::Slice(self.nodes[*i].as_slice()))
^~~~~~~~~~~~~~
lifetime-error.rs:20:5: 22:6 note: consider using an explicit lifetime parameter as shown: fn node_label<'a>(&self, i: &Nd) -> dot::LabelText<'a>
lifetime-error.rs:20 fn node_label<'a>(&self, i: &Nd) -> dot::LabelText<'a> {
lifetime-error.rs:21 dot::LabelStr(str::Slice(self.nodes[*i].as_slice()))
lifetime-error.rs:22 }
error: aborting due to previous error
Other times I get this good error message:
lifetime-error.rs:21:34: 21:48 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
lifetime-error.rs:21 dot::LabelStr(str::Slice(self.nodes[*i].as_slice()))
^~~~~~~~~~~~~~
lifetime-error.rs:20:5: 22:6 note: consider using an explicit lifetime parameter as shown: fn node_label<'a>(&'a self, i: &Nd) -> dot::LabelText<'a>
lifetime-error.rs:20 fn node_label<'a>(&self, i: &Nd) -> dot::LabelText<'a> {
lifetime-error.rs:21 dot::LabelStr(str::Slice(self.nodes[*i].as_slice()))
lifetime-error.rs:22 }
error: aborting due to previous error
@tbu-
Copy link

tbu- commented Oct 2, 2014

I honestly do not see the difference between the good and the bad error message, and my local diff tool can't see it either. Are you maybe looking at different places?

@maxsnew
Copy link
Author

maxsnew commented Oct 3, 2014

@tbu-, sorry about that. Fixed now

@maxsnew
Copy link
Author

maxsnew commented Oct 3, 2014

The difference is lines 5 and 15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment