Merge remote-tracking branch 'origin/master' into flakes

This commit is contained in:
Eelco Dolstra 2020-02-14 22:42:35 +01:00
commit 6208d24c38
7 changed files with 13 additions and 16 deletions

View file

@ -1,14 +1,3 @@
#[macro_use]
extern crate lazy_static;
#[cfg(test)]
#[macro_use]
extern crate assert_matches;
#[cfg(test)]
#[macro_use]
extern crate proptest;
#[cfg(not(test))] #[cfg(not(test))]
mod c; mod c;
mod error; mod error;

View file

@ -138,6 +138,7 @@ impl fmt::Display for StorePathName {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use assert_matches::assert_matches;
#[test] #[test]
fn test_parse() { fn test_parse() {

View file

@ -1,4 +1,5 @@
use crate::error::Error; use crate::error::Error;
use lazy_static::lazy_static;
pub fn encoded_len(input_len: usize) -> usize { pub fn encoded_len(input_len: usize) -> usize {
if input_len == 0 { if input_len == 0 {
@ -87,7 +88,9 @@ pub fn decode(input: &str) -> Result<Vec<u8>, crate::Error> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use assert_matches::assert_matches;
use hex; use hex;
use proptest::proptest;
#[test] #[test]
fn test_encode() { fn test_encode() {

View file

@ -64,12 +64,12 @@ public:
return end(); return end();
} }
std::optional<Attr *> get(const Symbol & name) Attr * get(const Symbol & name)
{ {
Attr key(name, 0); Attr key(name, 0);
iterator i = std::lower_bound(begin(), end(), key); iterator i = std::lower_bound(begin(), end(), key);
if (i != end() && i->name == name) return &*i; if (i != end() && i->name == name) return &*i;
return {}; return nullptr;
} }
Attr & need(const Symbol & name, const Pos & pos = noPos) Attr & need(const Symbol & name, const Pos & pos = noPos)
@ -77,7 +77,7 @@ public:
auto a = get(name); auto a = get(name);
if (!a) if (!a)
throw Error("attribute '%s' missing, at %s", name, pos); throw Error("attribute '%s' missing, at %s", name, pos);
return **a; return *a;
} }
iterator begin() { return &attrs[0]; } iterator begin() { return &attrs[0]; }

View file

@ -18,6 +18,8 @@ extern "C" {
struct StorePath : rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop> struct StorePath : rust::Value<3 * sizeof(void *) + 24, ffi_StorePath_drop>
{ {
StorePath() = delete;
static StorePath make(std::string_view path, std::string_view storeDir); static StorePath make(std::string_view path, std::string_view storeDir);
static StorePath make(unsigned char hash[20], std::string_view name); static StorePath make(unsigned char hash[20], std::string_view name);

View file

@ -113,6 +113,8 @@ extern "C" {
struct String : Vec<char, ffi_String_drop> struct String : Vec<char, ffi_String_drop>
{ {
String() = delete;
String(std::string_view s) String(std::string_view s)
{ {
ffi_String_new(StringSlice(s), this); ffi_String_new(StringSlice(s), this);

View file

@ -103,7 +103,7 @@ struct CmdWhyDepends : SourceExprCommand
std::map<StorePath, Node> graph; std::map<StorePath, Node> graph;
for (auto & path : closure) for (auto & path : closure)
graph.emplace(path.clone(), Node{path.clone(), cloneStorePathSet(store->queryPathInfo(path)->references)}); graph.emplace(path.clone(), Node { .path = path.clone(), .refs = cloneStorePathSet(store->queryPathInfo(path)->references) });
// Transpose the graph. // Transpose the graph.
for (auto & node : graph) for (auto & node : graph)
@ -112,7 +112,7 @@ struct CmdWhyDepends : SourceExprCommand
/* Run Dijkstra's shortest path algorithm to get the distance /* Run Dijkstra's shortest path algorithm to get the distance
of every path in the closure to 'dependency'. */ of every path in the closure to 'dependency'. */
graph[dependencyPath.clone()].dist = 0; graph.emplace(dependencyPath.clone(), Node { .path = dependencyPath.clone(), .dist = 0 });
std::priority_queue<Node *> queue; std::priority_queue<Node *> queue;