Skip to content

Commit 4a30e79

Browse files
committed
---
yaml --- r: 146684 b: refs/heads/try2 c: 4dded43 h: refs/heads/master v: v3
1 parent a15b172 commit 4a30e79

35 files changed

+518
-245
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 8e59c5d34a19e7ce58fec377f3033296476c5e92
8+
refs/heads/try2: 4dded4345fc148edea0e4b8354728c728784883f
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ common_escape : '\x5c'
254254
hex_digit : 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
255255
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
256256
| dec_digit ;
257+
oct_digit : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' ;
257258
dec_digit : '0' | nonzero_dec ;
258259
nonzero_dec: '1' | '2' | '3' | '4'
259260
| '5' | '6' | '7' | '8' | '9' ;
@@ -318,8 +319,9 @@ r##"foo #"# bar"##; // foo #"# bar
318319
~~~~ {.ebnf .gram}
319320
320321
num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ?
321-
| '0' [ [ dec_digit | '_' ] + num_suffix ?
322+
| '0' [ [ dec_digit | '_' ] * num_suffix ?
322323
| 'b' [ '1' | '0' | '_' ] + int_suffix ?
324+
| 'o' [ oct_digit | '_' ] + int_suffix ?
323325
| 'x' [ hex_digit | '_' ] + int_suffix ? ] ;
324326
325327
num_suffix : int_suffix | float_suffix ;
@@ -1548,6 +1550,7 @@ keyword for struct fields and enum variants). When an item is declared as `pub`,
15481550
it can be thought of as being accessible to the outside world. For example:
15491551

15501552
~~~~
1553+
# fn main() {}
15511554
// Declare a private struct
15521555
struct Foo;
15531556

branches/try2/doc/tutorial-container.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Reaching the end of the iterator is signalled by returning `None` instead of
8787
`Some(item)`:
8888
8989
~~~
90+
# fn main() {}
9091
/// A stream of N zeroes
9192
struct ZeroStream {
9293
priv remaining: uint
@@ -301,6 +302,7 @@ the iterator can provide better information.
301302
The `ZeroStream` from earlier can provide an exact lower and upper bound:
302303

303304
~~~
305+
# fn main() {}
304306
/// A stream of N zeroes
305307
struct ZeroStream {
306308
priv remaining: uint

branches/try2/doc/tutorial-macros.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Now consider code like the following:
216216

217217
~~~~
218218
# enum t1 { good_1(t2, uint), bad_1 };
219-
# pub struct t2 { body: t3 }
219+
# struct t2 { body: t3 }
220220
# enum t3 { good_2(uint), bad_2};
221221
# fn f(x: t1) -> uint {
222222
match x {
@@ -262,7 +262,7 @@ macro_rules! biased_match (
262262
)
263263
264264
# enum t1 { good_1(t2, uint), bad_1 };
265-
# pub struct t2 { body: t3 }
265+
# struct t2 { body: t3 }
266266
# enum t3 { good_2(uint), bad_2};
267267
# fn f(x: t1) -> uint {
268268
biased_match!((x) ~ (good_1(g1, val)) else { return 0 };
@@ -364,7 +364,7 @@ macro_rules! biased_match (
364364
365365
366366
# enum t1 { good_1(t2, uint), bad_1 };
367-
# pub struct t2 { body: t3 }
367+
# struct t2 { body: t3 }
368368
# enum t3 { good_2(uint), bad_2};
369369
# fn f(x: t1) -> uint {
370370
biased_match!(

branches/try2/doc/tutorial.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,7 @@ pub fn foo() { bar(); }
25682568
~~~
25692569
// c.rs
25702570
pub fn bar() { println("Baz!"); }
2571+
# fn main() {}
25712572
~~~
25722573

25732574
There also exist two short forms for importing multiple names at once:
@@ -2743,7 +2744,7 @@ Therefore, if you plan to compile your crate as a library, you should annotate i
27432744
#[link(name = "farm", vers = "2.5")];
27442745
27452746
// ...
2746-
# pub fn farm() {}
2747+
# fn farm() {}
27472748
~~~~
27482749

27492750
You can also in turn require in a `extern mod` statement that certain link metadata items match some criteria.
@@ -2769,7 +2770,7 @@ or setting the crate type (library or executable) explicitly:
27692770
27702771
// Turn on a warning
27712772
#[warn(non_camel_case_types)]
2772-
# pub fn farm() {}
2773+
# fn farm() {}
27732774
~~~~
27742775

27752776
If you're compiling your crate with `rustpkg`,
@@ -2790,7 +2791,9 @@ We define two crates, and use one of them as a library in the other.
27902791
~~~~
27912792
// world.rs
27922793
#[link(name = "world", vers = "0.42")];
2794+
# extern mod extra;
27932795
pub fn explore() -> &'static str { "world" }
2796+
# fn main() {}
27942797
~~~~
27952798

27962799
~~~~ {.xfail-test}

branches/try2/src/libextra/num/bigint.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ impl ToStrRadix for BigUint {
660660
let divider = FromPrimitive::from_uint(base).unwrap();
661661
let mut result = ~[];
662662
let mut m = n;
663-
while m > divider {
663+
while m >= divider {
664664
let (d, m0) = m.div_mod_floor(&divider);
665665
result.push(m0.to_uint().unwrap() as BigDigit);
666666
m = d;
@@ -2520,6 +2520,11 @@ mod bigint_tests {
25202520
check("-10", Some(-10));
25212521
check("Z", None);
25222522
check("_", None);
2523+
2524+
// issue 10522, this hit an edge case that caused it to
2525+
// attempt to allocate a vector of size (-1u) == huge.
2526+
let x: BigInt = from_str("1" + "0".repeat(36)).unwrap();
2527+
let _y = x.to_str();
25232528
}
25242529

25252530
#[test]

branches/try2/src/libextra/sort.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ mod tests {
846846

847847
fn check_sort(v1: &[int], v2: &[int]) {
848848
let len = v1.len();
849-
pub fn le(a: &int, b: &int) -> bool { *a <= *b }
849+
fn le(a: &int, b: &int) -> bool { *a <= *b }
850850
let f = le;
851851
let v3 = merge_sort::<int>(v1, f);
852852
let mut i = 0u;
@@ -876,7 +876,7 @@ mod tests {
876876

877877
#[test]
878878
fn test_merge_sort_mutable() {
879-
pub fn le(a: &int, b: &int) -> bool { *a <= *b }
879+
fn le(a: &int, b: &int) -> bool { *a <= *b }
880880
let v1 = ~[3, 2, 1];
881881
let v2 = merge_sort(v1, le);
882882
assert_eq!(v2, ~[1, 2, 3]);

branches/try2/src/libextra/url.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ fn query_from_str(rawquery: &str) -> Query {
364364
return query;
365365
}
366366

367+
/**
368+
* Converts an instance of a URI `Query` type to a string.
369+
*
370+
* # Example
371+
*
372+
* ```rust
373+
* let query = ~[(~"title", ~"The Village"), (~"north", ~"52.91"), (~"west", ~"4.10")];
374+
* println(query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
375+
* ```
376+
*/
367377
pub fn query_to_str(query: &Query) -> ~str {
368378
let mut strvec = ~[];
369379
for kv in query.iter() {

branches/try2/src/librustc/middle/check_const.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
117117
ExprUnary(_, UnDeref, _) => { }
118118
ExprUnary(_, UnBox(_), _) | ExprUnary(_, UnUniq, _) => {
119119
sess.span_err(e.span,
120-
"disallowed operator in constant expression");
120+
"cannot do allocations in constant expressions");
121121
return;
122122
}
123123
ExprLit(@codemap::Spanned {node: lit_str(*), _}) => { }
@@ -191,7 +191,13 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
191191
e.span,
192192
"borrowed pointers in constants may only refer to \
193193
immutable values");
194-
}
194+
},
195+
ExprVstore(_, ExprVstoreUniq) |
196+
ExprVstore(_, ExprVstoreBox) |
197+
ExprVstore(_, ExprVstoreMutBox) => {
198+
sess.span_err(e.span, "cannot allocate vectors in constant expressions")
199+
},
200+
195201
_ => {
196202
sess.span_err(e.span,
197203
"constant contains unimplemented expression type");

branches/try2/src/librustc/middle/lint.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -883,20 +883,23 @@ fn check_unused_unsafe(cx: &Context, e: &ast::Expr) {
883883

884884
fn check_unused_mut_pat(cx: &Context, p: @ast::Pat) {
885885
match p.node {
886-
ast::PatIdent(ast::BindByValue(ast::MutMutable), _, _) => {
887-
let mut used = false;
888-
let mut bindings = 0;
889-
do pat_util::pat_bindings(cx.tcx.def_map, p) |_, id, _, _| {
890-
used = used || cx.tcx.used_mut_nodes.contains(&id);
891-
bindings += 1;
892-
}
893-
if !used {
894-
let msg = if bindings == 1 {
895-
"variable does not need to be mutable"
896-
} else {
897-
"variables do not need to be mutable"
898-
};
899-
cx.span_lint(unused_mut, p.span, msg);
886+
ast::PatIdent(ast::BindByValue(ast::MutMutable),
887+
ref path, _) if pat_util::pat_is_binding(cx.tcx.def_map, p)=> {
888+
// `let mut _a = 1;` doesn't need a warning.
889+
let initial_underscore = match path.segments {
890+
[ast::PathSegment { identifier: id, _ }] => {
891+
cx.tcx.sess.str_of(id).starts_with("_")
892+
}
893+
_ => {
894+
cx.tcx.sess.span_bug(p.span,
895+
"mutable binding that doesn't \
896+
consist of exactly one segment");
897+
}
898+
};
899+
900+
if !initial_underscore && !cx.tcx.used_mut_nodes.contains(&p.id) {
901+
cx.span_lint(unused_mut, p.span,
902+
"variable does not need to be mutable");
900903
}
901904
}
902905
_ => ()

branches/try2/src/librustc/middle/privacy.rs

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//! which are available for use externally when compiled as a library.
1414
1515
use std::hashmap::{HashSet, HashMap};
16+
use std::util;
1617

1718
use middle::resolve;
1819
use middle::ty;
@@ -275,6 +276,7 @@ impl<'self> Visitor<()> for EmbargoVisitor<'self> {
275276
struct PrivacyVisitor<'self> {
276277
tcx: ty::ctxt,
277278
curitem: ast::NodeId,
279+
in_fn: bool,
278280

279281
// See comments on the same field in `EmbargoVisitor`.
280282
path_all_public_items: &'self ExportedItems,
@@ -688,6 +690,63 @@ impl<'self> PrivacyVisitor<'self> {
688690
}
689691
}
690692
}
693+
694+
/// When inside of something like a function or a method, visibility has no
695+
/// control over anything so this forbids any mention of any visibility
696+
fn check_all_inherited(&self, item: @ast::item) {
697+
let tcx = self.tcx;
698+
let check_inherited = |sp: Span, vis: ast::visibility| {
699+
if vis != ast::inherited {
700+
tcx.sess.span_err(sp, "visibility has no effect inside functions");
701+
}
702+
};
703+
let check_struct = |def: &@ast::struct_def| {
704+
for f in def.fields.iter() {
705+
match f.node.kind {
706+
ast::named_field(_, p) => check_inherited(f.span, p),
707+
ast::unnamed_field => {}
708+
}
709+
}
710+
};
711+
check_inherited(item.span, item.vis);
712+
match item.node {
713+
ast::item_impl(_, _, _, ref methods) => {
714+
for m in methods.iter() {
715+
check_inherited(m.span, m.vis);
716+
}
717+
}
718+
ast::item_foreign_mod(ref fm) => {
719+
for i in fm.items.iter() {
720+
check_inherited(i.span, i.vis);
721+
}
722+
}
723+
ast::item_enum(ref def, _) => {
724+
for v in def.variants.iter() {
725+
check_inherited(v.span, v.node.vis);
726+
727+
match v.node.kind {
728+
ast::struct_variant_kind(ref s) => check_struct(s),
729+
ast::tuple_variant_kind(*) => {}
730+
}
731+
}
732+
}
733+
734+
ast::item_struct(ref def, _) => check_struct(def),
735+
736+
ast::item_trait(_, _, ref methods) => {
737+
for m in methods.iter() {
738+
match *m {
739+
ast::required(*) => {}
740+
ast::provided(ref m) => check_inherited(m.span, m.vis),
741+
}
742+
}
743+
}
744+
745+
ast::item_static(*) |
746+
ast::item_fn(*) | ast::item_mod(*) | ast::item_ty(*) |
747+
ast::item_mac(*) => {}
748+
}
749+
}
691750
}
692751

693752
impl<'self> Visitor<()> for PrivacyVisitor<'self> {
@@ -699,12 +758,28 @@ impl<'self> Visitor<()> for PrivacyVisitor<'self> {
699758
}
700759

701760
// Disallow unnecessary visibility qualifiers
702-
self.check_sane_privacy(item);
761+
if self.in_fn {
762+
self.check_all_inherited(item);
763+
} else {
764+
self.check_sane_privacy(item);
765+
}
703766

704-
let orig_curitem = self.curitem;
705-
self.curitem = item.id;
767+
let orig_curitem = util::replace(&mut self.curitem, item.id);
768+
let orig_in_fn = util::replace(&mut self.in_fn, match item.node {
769+
ast::item_mod(*) => false, // modules turn privacy back on
770+
_ => self.in_fn, // otherwise we inherit
771+
});
706772
visit::walk_item(self, item, ());
707773
self.curitem = orig_curitem;
774+
self.in_fn = orig_in_fn;
775+
}
776+
777+
fn visit_fn(&mut self, fk: &visit::fn_kind, fd: &ast::fn_decl,
778+
b: &ast::Block, s: Span, n: ast::NodeId, _: ()) {
779+
// This catches both functions and methods
780+
let orig_in_fn = util::replace(&mut self.in_fn, true);
781+
visit::walk_fn(self, fk, fd, b, s, n, ());
782+
self.in_fn = orig_in_fn;
708783
}
709784

710785
fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
@@ -907,6 +982,7 @@ pub fn check_crate(tcx: ty::ctxt,
907982
{
908983
let mut visitor = PrivacyVisitor {
909984
curitem: ast::DUMMY_NODE_ID,
985+
in_fn: false,
910986
tcx: tcx,
911987
path_all_public_items: &path_all_public_items,
912988
parents: &parents,

branches/try2/src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ pub fn subst_tps(tcx: ctxt, tps: &[t], self_ty_opt: Option<t>, typ: t) -> t {
14091409
let mut subst = TpsSubst { tcx: tcx, self_ty_opt: self_ty_opt, tps: tps };
14101410
return subst.fold_ty(typ);
14111411

1412-
pub struct TpsSubst<'self> {
1412+
struct TpsSubst<'self> {
14131413
tcx: ctxt,
14141414
self_ty_opt: Option<t>,
14151415
tps: &'self [t],

branches/try2/src/librustc/middle/typeck/check/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,13 @@ pub fn compare_impl_method(tcx: ty::ctxt,
863863
if impl_m.fty.sig.inputs.len() != trait_m.fty.sig.inputs.len() {
864864
tcx.sess.span_err(
865865
impl_m_span,
866-
format!("method `{}` has {} parameter(s) \
867-
but the trait has {} parameter(s)",
868-
tcx.sess.str_of(trait_m.ident),
869-
impl_m.fty.sig.inputs.len(),
870-
trait_m.fty.sig.inputs.len()));
866+
format!("method `{}` has {} parameter{} \
867+
but the declaration in trait `{}` has {}",
868+
tcx.sess.str_of(trait_m.ident),
869+
impl_m.fty.sig.inputs.len(),
870+
if impl_m.fty.sig.inputs.len() == 1 { "" } else { "s" },
871+
ty::item_path_str(tcx, trait_m.def_id),
872+
trait_m.fty.sig.inputs.len()));
871873
return;
872874
}
873875

0 commit comments

Comments
 (0)