diff options
| author | Teddy Wing | 2017-11-09 20:05:44 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2017-11-09 20:05:44 +0100 | 
| commit | 69b930565a118f1f9890492e9f3130e23091b398 (patch) | |
| tree | 1636ce6350bf064ef99d764958b63c1f700b1a5e | |
| parent | fe3401411a324a7777514f66b1e79a3331ed0690 (diff) | |
| download | kipper-69b930565a118f1f9890492e9f3130e23091b398.tar.bz2 | |
Fix move compilation errors in `find_and_track_build_and_update_status`
I had a bunch of compilation errors in this function because I wasn't
borrowing correctly. Fix the errors with borrows by reference, and
copying strings.
Here are the errors for reference:
    error[E0373]: closure may outlive the current function, but it borrows `job`, which is owned by the current function
      --> src/jenkins.rs:89:27
       |
    89 |             thread::spawn(|| {
       |                           ^^ may outlive borrowed value `job`
    ...
    94 |                     job.result.commit_status(),
       |                     --- `job` is borrowed here
       |
    help: to force the closure to take ownership of `job` (and any other referenced variables), use the `move` keyword
       |
    89 |             thread::spawn(move || {
       |                           ^^^^^^^
    error[E0373]: closure may outlive the current function, but it borrows `job_url`, which is owned by the current function
      --> src/jenkins.rs:89:27
       |
    89 |             thread::spawn(|| {
       |                           ^^ may outlive borrowed value `job_url`
    ...
    96 |                     job_url.clone(),
       |                     ------- `job_url` is borrowed here
       |
    help: to force the closure to take ownership of `job_url` (and any other referenced variables), use the `move` keyword
       |
    89 |             thread::spawn(move || {
       |                           ^^^^^^^
    error[E0382]: use of moved value: `commit_ref`
      --> src/jenkins.rs:88:32
       |
    88 |         if job_for_commit(job, commit_ref) {
       |                                ^^^^^^^^^^ value moved here in previous iteration of loop
       |
       = note: move occurs because `commit_ref` has type `pull_request::CommitRef`, which does not implement the `Copy` trait
    error[E0382]: capture of moved value: `commit_ref`
      --> src/jenkins.rs:93:21
       |
    88 |         if job_for_commit(job, commit_ref) {
       |                                ---------- value moved here
    ...
    93 |                     commit_ref,
       |                     ^^^^^^^^^^ value captured here after move
       |
       = note: move occurs because `commit_ref` has type `pull_request::CommitRef`, which does not implement the `Copy` trait
    error[E0382]: capture of moved value: `job`
      --> src/jenkins.rs:89:27
       |
    88 |         if job_for_commit(job, commit_ref) {
       |                           --- value moved here
    89 |             thread::spawn(|| {
       |                           ^^ value captured here after move
       |
       = note: move occurs because `job` has type `jenkins::Job`, which does not implement the `Copy` trait
    error[E0382]: capture of moved value: `job_url`
      --> src/jenkins.rs:89:27
       |
    85 |         let job = request_job(job_url);
       |                               ------- value moved here
    ...
    89 |             thread::spawn(|| {
       |                           ^^ value captured here after move
       |
       = note: move occurs because `job_url` has type `std::string::String`, which does not implement the `Copy` trait
| -rw-r--r-- | src/af83.rs | 2 | ||||
| -rw-r--r-- | src/github.rs | 4 | ||||
| -rw-r--r-- | src/jenkins.rs | 18 | 
3 files changed, 12 insertions, 12 deletions
| diff --git a/src/af83.rs b/src/af83.rs index bc8876c..1547700 100644 --- a/src/af83.rs +++ b/src/af83.rs @@ -1,6 +1,6 @@  use pull_request::CommitRef; -pub fn job_name(commit_ref: CommitRef) -> String { +pub fn job_name(commit_ref: &CommitRef) -> String {      let (sha, _) = commit_ref.sha.split_at(5);      format!("{}-{}", commit_ref.branch, sha) diff --git a/src/github.rs b/src/github.rs index c5cedca..0eb85b0 100644 --- a/src/github.rs +++ b/src/github.rs @@ -33,8 +33,8 @@ impl fmt::Display for CommitStatus {  }  pub fn update_commit_status( -    commit_ref: CommitRef, -    state: CommitStatus, +    commit_ref: &CommitRef, +    state: &CommitStatus,      target_url: String,      description: Option<String>,      context: String, diff --git a/src/jenkins.rs b/src/jenkins.rs index 0992983..2034492 100644 --- a/src/jenkins.rs +++ b/src/jenkins.rs @@ -82,17 +82,17 @@ pub fn find_and_track_build_and_update_status(      let jobs = get_jobs(repo_name);      for job_url in jobs { -        let job = request_job(job_url); +        let job = request_job(job_url.as_ref());          // Does `displayName` match -        if job_for_commit(job, commit_ref) { -            thread::spawn(|| { +        if job_for_commit(&job, &commit_ref) { +            thread::spawn(move || {                  // Start timer                  github::update_commit_status( -                    commit_ref, -                    job.result.commit_status(), -                    job_url, +                    &commit_ref, +                    &job.result.commit_status(), +                    job_url.clone(),                      None,                      "continuous-integration/jenkins".to_string()                  ); @@ -143,7 +143,7 @@ pub fn get_jobs(repo_name: String) -> Vec<String> {          .collect::<Vec<String>>()  } -pub fn request_job(url: String) -> Job { +pub fn request_job(url: &str) -> Job {      let url = Url::parse(url.as_ref()).unwrap();      let client = reqwest::Client::new(); @@ -166,8 +166,8 @@ pub fn request_job(url: String) -> Job {  }  // Does the `commit_ref` correspond to the job? -pub fn job_for_commit(job: Job, commit_ref: CommitRef) -> bool { -    job.display_name == af83::job_name(commit_ref) +pub fn job_for_commit(job: &Job, commit_ref: &CommitRef) -> bool { +    job.display_name == af83::job_name(&commit_ref)  }  pub fn result_from_job(status: Option<String>) -> JobStatus { | 
