Skip to content

Commit

Permalink
Improve compile-test tests
Browse files Browse the repository at this point in the history
We want to catch when _any_ of those borrows erroneously become legal,
so we need them to be separate tests. Also added tests for the
iterator types.
  • Loading branch information
jonhoo committed Jan 24, 2020
1 parent a8c0ff4 commit f6cdb55
Showing 1 changed file with 80 additions and 14 deletions.
94 changes: 80 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,32 +1364,98 @@ impl<K, V> Table<K, V> {
/// supposed to compile without pulling in `compiletest` as a dependency. See rust-lang/rust#12335.
/// But it _is_ possible to write `compile_test` tests as doctests, sooooo:
///
/// No references outlive the map:
/// # No references outlive the map.
///
/// Note that these have to be _separate_ tests, otherwise you could have, say, `get` break the
/// contract, but `insert` continue to uphold it, and then the test would still fail to compile
/// (and so pass).
///
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let r = map.insert((), (), &guard);
/// drop(map);
/// drop(r);
/// ```
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let r = map.get(&(), &guard);
/// drop(map);
/// drop(r);
/// ```
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let r = map.remove(&(), &guard);
/// drop(map);
/// drop(r);
/// ```
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let r = map.iter(&guard).next();
/// drop(map);
/// drop(r);
/// ```
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let r = map.keys(&guard).next();
/// drop(map);
/// drop(r);
/// ```
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let ref1 = map.insert((), (), &guard);
/// let ref2 = map.get(&(), &guard);
/// let ref3 = map.remove(&(), &guard);
/// let r = map.values(&guard).next();
/// drop(map);
/// drop(ref1);
/// drop(ref2);
/// drop(ref3);
/// drop(r);
/// ```
///
/// No references outlive the guard:
/// # No references outlive the guard.
///
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let ref1 = map.insert((), (), &guard);
/// let ref2 = map.get(&(), &guard);
/// let ref3 = map.remove(&(), &guard);
/// let r = map.insert((), (), &guard);
/// drop(guard);
/// drop(r);
/// ```
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let r = map.get(&(), &guard);
/// drop(guard);
/// drop(r);
/// ```
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let r = map.remove(&(), &guard);
/// drop(guard);
/// drop(r);
/// ```
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let r = map.iter(&guard).next();
/// drop(guard);
/// drop(r);
/// ```
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let r = map.keys(&guard).next();
/// drop(guard);
/// drop(r);
/// ```
/// ```compile_fail
/// let guard = crossbeam::epoch::pin();
/// let map = super::FlurryHashMap::default();
/// let r = map.values(&guard).next();
/// drop(guard);
/// drop(ref1);
/// drop(ref2);
/// drop(ref3);
/// drop(r);
/// ```
#[allow(dead_code)]
struct CompileFailTests;

0 comments on commit f6cdb55

Please sign in to comment.