Skip to content

fixing no-implicit-copies warning for json, switching to str/vec slices, and other cleanup #2574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 37 additions & 39 deletions src/cargo/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import syntax::diagnostic;

import result::{ok, err};
import io::writer_util;
import result;
import std::{map, json, tempfile, term, sort, getopts};
import map::hashmap;
import str;
import vec;
import json::to_str;
import getopts::{optflag, optopt, opt_present};

type package = {
Expand Down Expand Up @@ -399,28 +397,28 @@ fn parse_source(name: str, j: json::json) -> source {
}

alt j {
json::dict(_j) {
let mut url = alt _j.find("url") {
json::dict(j) {
let mut url = alt j.find("url") {
some(json::string(u)) {
u
*u
}
_ { fail "needed 'url' field in source"; }
};
let method = alt _j.find("method") {
let method = alt j.find("method") {
some(json::string(u)) {
u
*u
}
_ { assume_source_method(url) }
};
let key = alt _j.find("key") {
let key = alt j.find("key") {
some(json::string(u)) {
some(u)
some(*u)
}
_ { none }
};
let keyfp = alt _j.find("keyfp") {
let keyfp = alt j.find("keyfp") {
some(json::string(u)) {
some(u)
some(*u)
}
_ { none }
};
Expand Down Expand Up @@ -450,20 +448,20 @@ fn try_parse_sources(filename: str, sources: map::hashmap<str, source>) {
}
}
ok(_) { fail "malformed sources.json"; }
err(e) { fail #fmt("%s:%u:%u: %s", filename, e.line, e.col, e.msg); }
err(e) { fail #fmt("%s:%s", filename, e.to_str()); }
}
}

fn load_one_source_package(src: source, p: map::hashmap<str, json::json>) {
let name = alt p.find("name") {
some(json::string(_n)) {
if !valid_pkg_name(_n) {
warn("malformed source json: " + src.name + ", '" + _n + "'"+
some(json::string(n)) {
if !valid_pkg_name(*n) {
warn("malformed source json: " + src.name + ", '" + *n + "'"+
" is an invalid name (alphanumeric, underscores and" +
" dashes only)");
ret;
}
_n
*n
}
_ {
warn("malformed source json: " + src.name + " (missing name)");
Expand All @@ -472,13 +470,13 @@ fn load_one_source_package(src: source, p: map::hashmap<str, json::json>) {
};

let uuid = alt p.find("uuid") {
some(json::string(_n)) {
if !is_uuid(_n) {
warn("malformed source json: " + src.name + ", '" + _n + "'"+
some(json::string(n)) {
if !is_uuid(*n) {
warn("malformed source json: " + src.name + ", '" + *n + "'"+
" is an invalid uuid");
ret;
}
_n
*n
}
_ {
warn("malformed source json: " + src.name + " (missing uuid)");
Expand All @@ -487,32 +485,32 @@ fn load_one_source_package(src: source, p: map::hashmap<str, json::json>) {
};

let url = alt p.find("url") {
some(json::string(_n)) { _n }
some(json::string(n)) { *n }
_ {
warn("malformed source json: " + src.name + " (missing url)");
ret;
}
};

let method = alt p.find("method") {
some(json::string(_n)) { _n }
some(json::string(n)) { *n }
_ {
warn("malformed source json: " + src.name + " (missing method)");
ret;
}
};

let ref = alt p.find("ref") {
some(json::string(_n)) { some(_n) }
some(json::string(n)) { some(*n) }
_ { none }
};

let mut tags = [];
alt p.find("tags") {
some(json::list(js)) {
for js.each {|j|
for (*js).each {|j|
alt j {
json::string(_j) { vec::grow(tags, 1u, _j); }
json::string(j) { vec::grow(tags, 1u, *j); }
_ { }
}
}
Expand All @@ -521,7 +519,7 @@ fn load_one_source_package(src: source, p: map::hashmap<str, json::json>) {
}

let description = alt p.find("description") {
some(json::string(_n)) { _n }
some(json::string(n)) { *n }
_ {
warn("malformed source json: " + src.name
+ " (missing description)");
Expand Down Expand Up @@ -570,7 +568,7 @@ fn load_source_info(c: cargo, src: source) {
"(source info is not a dict)");
}
err(e) {
warn(#fmt("%s:%u:%u: %s", src.name, e.line, e.col, e.msg));
warn(#fmt("%s:%s", src.name, e.to_str()));
}
};
}
Expand All @@ -582,10 +580,10 @@ fn load_source_packages(c: cargo, src: source) {
let pkgstr = io::read_whole_file_str(pkgfile);
alt json::from_str(result::get(pkgstr)) {
ok(json::list(js)) {
for js.each {|_j|
alt _j {
json::dict(_p) {
load_one_source_package(src, _p);
for (*js).each {|j|
alt j {
json::dict(p) {
load_one_source_package(src, p);
}
_ {
warn("malformed source json: " + src.name +
Expand All @@ -599,7 +597,7 @@ fn load_source_packages(c: cargo, src: source) {
"(packages is not a list)");
}
err(e) {
warn(#fmt("%s:%u:%u: %s", src.name, e.line, e.col, e.msg));
warn(#fmt("%s:%s", src.name, e.to_str()));
}
};
}
Expand Down Expand Up @@ -766,8 +764,8 @@ fn install_one_crate(c: cargo, path: str, cf: str) {

fn rustc_sysroot() -> str {
alt os::self_exe_path() {
some(_path) {
let path = [_path, "..", "bin", "rustc"];
some(path) {
let path = [path, "..", "bin", "rustc"];
check vec::is_not_empty(path);
let rustc = path::normalize(path::connect_many(path));
#debug(" rustc: %s", rustc);
Expand Down Expand Up @@ -1578,18 +1576,18 @@ fn dump_sources(c: cargo) {
let chash = map::str_hash();
let child = json::dict(chash);

chash.insert("url", json::string(v.url));
chash.insert("method", json::string(v.method));
chash.insert("url", json::string(@v.url));
chash.insert("method", json::string(@v.method));

alt copy v.key {
some(key) {
chash.insert("key", json::string(key));
chash.insert("key", json::string(@key));
}
_ {}
}
alt copy v.keyfp {
some(keyfp) {
chash.insert("keyfp", json::string(keyfp));
chash.insert("keyfp", json::string(@keyfp));
}
_ {}
}
Expand Down
30 changes: 15 additions & 15 deletions src/libcore/int-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ export ord, eq, num;
const min_value: T = -1 as T << (inst::bits - 1 as T);
const max_value: T = min_value - 1 as T;

pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }

pure fn add(x: T, y: T) -> T { x + y }
pure fn sub(x: T, y: T) -> T { x - y }
pure fn mul(x: T, y: T) -> T { x * y }
pure fn div(x: T, y: T) -> T { x / y }
pure fn rem(x: T, y: T) -> T { x % y }

pure fn lt(x: T, y: T) -> bool { x < y }
pure fn le(x: T, y: T) -> bool { x <= y }
pure fn eq(x: T, y: T) -> bool { x == y }
pure fn ne(x: T, y: T) -> bool { x != y }
pure fn ge(x: T, y: T) -> bool { x >= y }
pure fn gt(x: T, y: T) -> bool { x > y }
pure fn min(&&x: T, &&y: T) -> T { if x < y { x } else { y } }
pure fn max(&&x: T, &&y: T) -> T { if x > y { x } else { y } }

pure fn add(&&x: T, &&y: T) -> T { x + y }
pure fn sub(&&x: T, &&y: T) -> T { x - y }
pure fn mul(&&x: T, &&y: T) -> T { x * y }
pure fn div(&&x: T, &&y: T) -> T { x / y }
pure fn rem(&&x: T, &&y: T) -> T { x % y }

pure fn lt(&&x: T, &&y: T) -> bool { x < y }
pure fn le(&&x: T, &&y: T) -> bool { x <= y }
pure fn eq(&&x: T, &&y: T) -> bool { x == y }
pure fn ne(&&x: T, &&y: T) -> bool { x != y }
pure fn ge(&&x: T, &&y: T) -> bool { x >= y }
pure fn gt(&&x: T, &&y: T) -> bool { x > y }

pure fn is_positive(x: T) -> bool { x > 0 as T }
pure fn is_negative(x: T) -> bool { x < 0 as T }
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/int-template/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const bits: T = 32 as T;
const bits: T = 64 as T;

#[doc = "Produce a uint suitable for use in a hash table"]
pure fn hash(x: int) -> uint { ret x as uint; }
pure fn hash(&&x: int) -> uint { ret x as uint; }

#[doc = "Returns `base` raised to the power of `exponent`"]
fn pow(base: int, exponent: uint) -> int {
Expand Down
Loading