Skip to content

Commit

Permalink
WIP pacify tidy in the OF
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jan 14, 2016
1 parent 199fa5e commit ec26c49
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 57 deletions.
10 changes: 10 additions & 0 deletions src/librustc_data_structures/obligation_forest/node_index.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use core::nonzero::NonZero;
use std::u32;

Expand Down
132 changes: 75 additions & 57 deletions src/librustc_data_structures/obligation_forest/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::{ObligationForest, Outcome, Error};

#[test]
Expand Down Expand Up @@ -86,42 +96,46 @@ fn success_in_grandchildren() {
let mut forest = ObligationForest::new();
forest.push_root("A");

let Outcome { successful: ok, errors: err, .. } = forest.process_obligations::<(),_>(|obligation, _| {
match *obligation {
"A" => Ok(Some(vec!["A.1", "A.2", "A.3"])),
_ => unreachable!(),
}
});
let Outcome { successful: ok, errors: err, .. } =
forest.process_obligations::<(),_>(|obligation, _| {
match *obligation {
"A" => Ok(Some(vec!["A.1", "A.2", "A.3"])),
_ => unreachable!(),
}
});
assert!(ok.is_empty());
assert!(err.is_empty());

let Outcome { successful: ok, errors: err, .. } = forest.process_obligations::<(),_>(|obligation, _| {
match *obligation {
"A.1" => Ok(Some(vec![])),
"A.2" => Ok(Some(vec!["A.2.i", "A.2.ii"])),
"A.3" => Ok(Some(vec![])),
_ => unreachable!(),
}
});
let Outcome { successful: ok, errors: err, .. } =
forest.process_obligations::<(),_>(|obligation, _| {
match *obligation {
"A.1" => Ok(Some(vec![])),
"A.2" => Ok(Some(vec!["A.2.i", "A.2.ii"])),
"A.3" => Ok(Some(vec![])),
_ => unreachable!(),
}
});
assert_eq!(ok, vec!["A.3", "A.1"]);
assert!(err.is_empty());

let Outcome { successful: ok, errors: err, .. } = forest.process_obligations::<(),_>(|obligation, _| {
match *obligation {
"A.2.i" => Ok(Some(vec!["A.2.i.a"])),
"A.2.ii" => Ok(Some(vec![])),
_ => unreachable!(),
}
});
let Outcome { successful: ok, errors: err, .. } =
forest.process_obligations::<(),_>(|obligation, _| {
match *obligation {
"A.2.i" => Ok(Some(vec!["A.2.i.a"])),
"A.2.ii" => Ok(Some(vec![])),
_ => unreachable!(),
}
});
assert_eq!(ok, vec!["A.2.ii"]);
assert!(err.is_empty());

let Outcome { successful: ok, errors: err, .. } = forest.process_obligations::<(),_>(|obligation, _| {
match *obligation {
"A.2.i.a" => Ok(Some(vec![])),
_ => unreachable!(),
}
});
let Outcome { successful: ok, errors: err, .. } =
forest.process_obligations::<(),_>(|obligation, _| {
match *obligation {
"A.2.i.a" => Ok(Some(vec![])),
_ => unreachable!(),
}
});
assert_eq!(ok, vec!["A.2.i.a", "A.2.i", "A.2", "A"]);
assert!(err.is_empty());

Expand All @@ -137,12 +151,13 @@ fn to_errors_no_throw() {
// only yields one of them (and does not panic, in particular).
let mut forest = ObligationForest::new();
forest.push_root("A");
let Outcome { successful: ok, errors: err, .. } = forest.process_obligations::<(),_>(|obligation, _| {
match *obligation {
"A" => Ok(Some(vec!["A.1", "A.2", "A.3"])),
_ => unreachable!(),
}
});
let Outcome { successful: ok, errors: err, .. } =
forest.process_obligations::<(),_>(|obligation, _| {
match *obligation {
"A" => Ok(Some(vec!["A.1", "A.2", "A.3"])),
_ => unreachable!(),
}
});
assert_eq!(ok.len(), 0);
assert_eq!(err.len(), 0);
let errors = forest.to_errors(());
Expand All @@ -155,34 +170,37 @@ fn backtrace() {
// only yields one of them (and does not panic, in particular).
let mut forest: ObligationForest<&'static str> = ObligationForest::new();
forest.push_root("A");
let Outcome { successful: ok, errors: err, .. } = forest.process_obligations::<(),_>(|obligation, mut backtrace| {
assert!(backtrace.next().is_none());
match *obligation {
"A" => Ok(Some(vec!["A.1"])),
_ => unreachable!(),
}
});
let Outcome { successful: ok, errors: err, .. } =
forest.process_obligations::<(),_>(|obligation, mut backtrace| {
assert!(backtrace.next().is_none());
match *obligation {
"A" => Ok(Some(vec!["A.1"])),
_ => unreachable!(),
}
});
assert!(ok.is_empty());
assert!(err.is_empty());
let Outcome { successful: ok, errors: err, .. } = forest.process_obligations::<(),_>(|obligation, mut backtrace| {
assert!(backtrace.next().unwrap() == &"A");
assert!(backtrace.next().is_none());
match *obligation {
"A.1" => Ok(Some(vec!["A.1.i"])),
_ => unreachable!(),
}
});
let Outcome { successful: ok, errors: err, .. } =
forest.process_obligations::<(),_>(|obligation, mut backtrace| {
assert!(backtrace.next().unwrap() == &"A");
assert!(backtrace.next().is_none());
match *obligation {
"A.1" => Ok(Some(vec!["A.1.i"])),
_ => unreachable!(),
}
});
assert!(ok.is_empty());
assert!(err.is_empty());
let Outcome { successful: ok, errors: err, .. } = forest.process_obligations::<(),_>(|obligation, mut backtrace| {
assert!(backtrace.next().unwrap() == &"A.1");
assert!(backtrace.next().unwrap() == &"A");
assert!(backtrace.next().is_none());
match *obligation {
"A.1.i" => Ok(None),
_ => unreachable!(),
}
});
let Outcome { successful: ok, errors: err, .. } =
forest.process_obligations::<(),_>(|obligation, mut backtrace| {
assert!(backtrace.next().unwrap() == &"A.1");
assert!(backtrace.next().unwrap() == &"A");
assert!(backtrace.next().is_none());
match *obligation {
"A.1.i" => Ok(None),
_ => unreachable!(),
}
});
assert_eq!(ok.len(), 0);
assert!(err.is_empty());
}

0 comments on commit ec26c49

Please sign in to comment.