Skip to content

Commit c184779

Browse files
committed
---
yaml --- r: 73636 b: refs/heads/dist-snap c: 2bf053c h: refs/heads/master v: v3
1 parent 7212674 commit c184779

File tree

14 files changed

+366
-982
lines changed

14 files changed

+366
-982
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: c23843c4471dcacb203d4439ef7c19bb2c3238b0
10+
refs/heads/dist-snap: 2bf053c0a349a5968820780314c942ef4555b47e
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/lint.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub enum lint {
9696
unnecessary_allocation,
9797

9898
missing_doc,
99+
unreachable_code,
99100
}
100101

101102
pub fn level_to_str(lv: level) -> &'static str {
@@ -273,6 +274,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
273274
desc: "detects missing documentation for public members",
274275
default: allow
275276
}),
277+
278+
("unreachable_code",
279+
LintSpec {
280+
lint: unreachable_code,
281+
desc: "detects unreachable code",
282+
default: warn
283+
}),
276284
];
277285

278286
/*

branches/dist-snap/src/librustc/middle/typeck/check/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ use core::prelude::*;
8181
use middle::const_eval;
8282
use middle::pat_util::pat_id_map;
8383
use middle::pat_util;
84+
use middle::lint::unreachable_code;
8485
use middle::ty::{FnSig, VariantInfo_};
8586
use middle::ty::{ty_param_bounds_and_ty, ty_param_substs_and_ty};
8687
use middle::ty::{substs, param_ty};
@@ -2937,7 +2938,8 @@ pub fn check_block_with_expected(fcx: @mut FnCtxt,
29372938
let mut any_err = false;
29382939
for blk.node.stmts.each |s| {
29392940
check_stmt(fcx, *s);
2940-
let s_ty = fcx.node_ty(ast_util::stmt_id(*s));
2941+
let s_id = ast_util::stmt_id(*s);
2942+
let s_ty = fcx.node_ty(s_id);
29412943
if last_was_bot && !warned && match s.node {
29422944
ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_),
29432945
_}, _) |
@@ -2946,7 +2948,8 @@ pub fn check_block_with_expected(fcx: @mut FnCtxt,
29462948
}
29472949
_ => false
29482950
} {
2949-
fcx.ccx.tcx.sess.span_warn(s.span, "unreachable statement");
2951+
fcx.ccx.tcx.sess.add_lint(unreachable_code, s_id, s.span,
2952+
~"unreachable statement");
29502953
warned = true;
29512954
}
29522955
if ty::type_is_bot(s_ty) {

branches/dist-snap/src/libstd/hashmap.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ pub fn linear_map_with_capacity<K:Eq + Hash,V>(
7272
fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
7373
k0: u64, k1: u64,
7474
initial_capacity: uint) -> HashMap<K, V> {
75+
let cap = uint::max(INITIAL_CAPACITY, initial_capacity);
7576
HashMap {
7677
k0: k0, k1: k1,
77-
resize_at: resize_at(initial_capacity),
78+
resize_at: resize_at(cap),
7879
size: 0,
79-
buckets: vec::from_fn(initial_capacity, |_| None)
80+
buckets: vec::from_fn(cap, |_| None)
8081
}
8182
}
8283

@@ -480,7 +481,8 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
480481
}
481482

482483
fn consume(&mut self, f: &fn(K, V)) {
483-
let buckets = replace(&mut self.buckets, ~[]);
484+
let buckets = replace(&mut self.buckets,
485+
vec::from_fn(INITIAL_CAPACITY, |_| None));
484486
self.size = 0;
485487

486488
do vec::consume(buckets) |_, bucket| {
@@ -664,6 +666,12 @@ mod test_map {
664666
use super::*;
665667
use uint;
666668

669+
#[test]
670+
fn test_create_capacity_zero() {
671+
let mut m = HashMap::with_capacity(0);
672+
assert!(m.insert(1, 1));
673+
}
674+
667675
#[test]
668676
fn test_insert() {
669677
let mut m = HashMap::new();
@@ -771,6 +779,14 @@ mod test_map {
771779
assert_eq!(m2.get(&2), &3);
772780
}
773781

782+
#[test]
783+
fn test_consume_still_usable() {
784+
let mut m = HashMap::new();
785+
assert!(m.insert(1, 2));
786+
do m.consume |_, _| {}
787+
assert!(m.insert(1, 2));
788+
}
789+
774790
#[test]
775791
fn test_iterate() {
776792
let mut m = linear_map_with_capacity(4);

0 commit comments

Comments
 (0)