Skip to content

Instantly share code, notes, and snippets.

@killerswan
Last active August 29, 2015 14:04
Show Gist options
  • Save killerswan/87b9482eca5d09c82619 to your computer and use it in GitHub Desktop.
Save killerswan/87b9482eca5d09c82619 to your computer and use it in GitHub Desktop.
Why is this extra let binding necessary? See line 13 below. If you remove it, there's an error. (And the source code: https://github.com/killerswan/ovid/blob/b197f03f4b670e25c420751ec3358ead2d42059a/CSVProvider.rs#L139)
ovid $ git ll -1 --oneline
* b197f03 (HEAD, master) cleanup
ovid $
ovid $ git diff
diff --git a/CSVProvider.rs b/CSVProvider.rs
index 2b24cd2..2181c0b 100644
--- a/CSVProvider.rs
+++ b/CSVProvider.rs
@@ -205,8 +205,7 @@ fn provide_csv_given_labels(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Bo
println!("Parsing given labels...");
- let labels1 = format!("{}", labels);
- let labels_iter = parse_csv_row(labels1.as_slice(), None);
+ let labels_iter = parse_csv_row(format!("{}", labels).as_slice(), None);
println!("Defining items in the CSV provider...");
ovid $
ovid $ ./build.sh
CSVProvider.rs:208:36: 208:58 error: borrowed value does not live long enough
CSVProvider.rs:208 let labels_iter = parse_csv_row(format!("{}", labels).as_slice(), None);
^~~~~~~~~~~~~~~~~~~~~~
CSVProvider.rs:162:94: 252:2 note: reference must be valid for the block at 162:93...
CSVProvider.rs:162 fn provide_csv_given_labels(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacResult> {
CSVProvider.rs:163 let mut entries = match parse_entries(cx, tts) {
CSVProvider.rs:164 Some(entries) => entries,
CSVProvider.rs:165 None => return DummyResult::expr(sp),
CSVProvider.rs:166 };
CSVProvider.rs:167
...
CSVProvider.rs:208:8: 208:75 note: ...but borrowed value is only valid for the statement at 208:7; consider using a `let` binding to increase its lifetime
CSVProvider.rs:208 let labels_iter = parse_csv_row(format!("{}", labels).as_slice(), None);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment