Skip to content

Commit dfdd3db

Browse files
committed
---
yaml --- r: 151290 b: refs/heads/try2 c: 002f791 h: refs/heads/master v: v3
1 parent 2a4cc59 commit dfdd3db

38 files changed

+562
-166
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: 7e53af35b1d521a4d0f24d964074112266a897b8
8+
refs/heads/try2: 002f791189c43c5ef79da083490e533d015570b1
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/LICENSE-MIT

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Copyright (c) 2006-2009 Graydon Hoare
2-
Copyright (c) 2009-2014 Mozilla Foundation
1+
Copyright (c) 2014 The Rust Project Developers
32

43
Permission is hereby granted, free of charge, to any
54
person obtaining a copy of this software and associated

branches/try2/src/doc/guide-pointers.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ enum List<T> {
186186
Nil,
187187
Cons(T, ~List<T>),
188188
}
189-
189+
190190
fn main() {
191191
let list: List<int> = Cons(1, ~Cons(2, ~Cons(3, ~Nil)));
192192
println!("{:?}", list);
@@ -251,7 +251,7 @@ struct.
251251

252252
> **Note**: the `@` form of managed pointers is deprecated and behind a
253253
> feature gate (it requires a `#![feature(managed_pointers)]` attribute on
254-
> the crate root; remember the semicolon!). There are replacements, currently
254+
> the crate root). There are replacements, currently
255255
> there is `std::rc::Rc` and `std::gc::Gc` for shared ownership via reference
256256
> counting and garbage collection respectively.
257257
@@ -266,7 +266,7 @@ struct Point {
266266
x: int,
267267
y: int,
268268
}
269-
269+
270270
fn main() {
271271
let a = ~Point { x: 10, y: 20 };
272272
let b = a;
@@ -297,7 +297,7 @@ struct Point {
297297
x: int,
298298
y: int,
299299
}
300-
300+
301301
fn main() {
302302
let a = @Point { x: 10, y: 20 };
303303
let b = a;
@@ -361,7 +361,7 @@ So how is this hard? Well, because we're ignoring ownership, the compiler needs
361361
to take great care to make sure that everything is safe. Despite their complete
362362
safety, a reference's representation at runtime is the same as that of
363363
an ordinary pointer in a C program. They introduce zero overhead. The compiler
364-
does all safety checks at compile time.
364+
does all safety checks at compile time.
365365

366366
This theory is called 'region pointers,' and involve a concept called
367367
'lifetimes'. Here's the simple explanation: would you expect this code to
@@ -477,7 +477,7 @@ fn main() {
477477
You may think that this gives us terrible performance: return a value and then
478478
immediately box it up?!?! Isn't that the worst of both worlds? Rust is smarter
479479
than that. There is no copy in this code. `main` allocates enough room for the
480-
`@int`, passes a pointer to that memory into `foo` as `x`, and then `foo` writes
480+
`@int`, passes a pointer to that memory into `foo` as `x`, and then `foo` writes
481481
the value straight into that pointer. This writes the return value directly into
482482
the allocated box.
483483

branches/try2/src/doc/guide-tasks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ fn print_message() { println!("I am running in a different task!"); }
101101
spawn(print_message);
102102
103103
// Print something more profound in a different task using a lambda expression
104+
// This uses the proc() keyword to assign to spawn a function with no name
105+
// That function will call println!(...) as requested
104106
spawn(proc() println!("I am also running in a different task!") );
105107
~~~~
106108

branches/try2/src/doc/tutorial.md

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,38 +1720,103 @@ environment (sometimes referred to as "capturing" variables in their
17201720
environment). For example, you couldn't write the following:
17211721
17221722
~~~~ {.ignore}
1723-
let foo = 10;
1723+
let x = 3;
17241724
1725-
fn bar() -> int {
1726-
return foo; // `bar` cannot refer to `foo`
1727-
}
1725+
// `fun` cannot refer to `x`
1726+
fn fun() -> () { println!("{}", x); }
17281727
~~~~
17291728
1730-
Rust also supports _closures_, functions that can access variables in
1731-
the enclosing scope.
1729+
A _closure_ does support accessing the enclosing scope; below we will create
1730+
2 _closures_ (nameless functions). Compare how `||` replaces `()` and how
1731+
they try to access `x`:
17321732
1733-
~~~~
1734-
fn call_closure_with_ten(b: |int|) { b(10); }
1733+
~~~~ {.ignore}
1734+
let x = 3;
17351735
1736-
let captured_var = 20;
1737-
let closure = |arg| println!("captured_var={}, arg={}", captured_var, arg);
1736+
// `fun` is an invalid definition
1737+
fn fun () -> () { println!("{}", x) } // cannot capture from enclosing scope
1738+
let closure = || -> () { println!("{}", x) }; // can capture from enclosing scope
17381739
1739-
call_closure_with_ten(closure);
1740+
// `fun_arg` is an invalid definition
1741+
fn fun_arg (arg: int) -> () { println!("{}", arg + x) } // cannot capture
1742+
let closure_arg = |arg: int| -> () { println!("{}", arg + x) }; // can capture
1743+
// ^
1744+
// Requires a type because the implementation needs to know which `+` to use.
1745+
// In the future, the implementation may not need the help.
1746+
1747+
fun(); // Still won't work
1748+
closure(); // Prints: 3
1749+
1750+
fun_arg(7); // Still won't work
1751+
closure_arg(7); // Prints: 10
17401752
~~~~
17411753
17421754
Closures begin with the argument list between vertical bars and are followed by
17431755
a single expression. Remember that a block, `{ <expr1>; <expr2>; ... }`, is
17441756
considered a single expression: it evaluates to the result of the last
17451757
expression it contains if that expression is not followed by a semicolon,
1746-
otherwise the block evaluates to `()`.
1758+
otherwise the block evaluates to `()`, the unit value.
1759+
1760+
In general, return types and all argument types must be specified
1761+
explicitly for function definitions. (As previously mentioned in the
1762+
[Functions section](#functions), omitting the return type from a
1763+
function declaration is synonymous with an explicit declaration of
1764+
return type unit, `()`.)
1765+
1766+
~~~~ {.ignore}
1767+
fn fun (x: int) { println!("{}", x) } // this is same as saying `-> ()`
1768+
fn square(x: int) -> uint { (x * x) as uint } // other return types are explicit
1769+
1770+
// Error: mismatched types: expected `()` but found `uint`
1771+
fn badfun(x: int) { (x * x) as uint }
1772+
~~~~
1773+
1774+
On the other hand, the compiler can usually infer both the argument
1775+
and return types for a closure expression; therefore they are often
1776+
omitted, since both a human reader and the compiler can deduce the
1777+
types from the immediate context. This is in contrast to function
1778+
declarations, which require types to be specified and are not subject
1779+
to type inference. Compare:
17471780
1748-
The types of the arguments are generally omitted, as is the return type,
1749-
because the compiler can almost always infer them. In the rare case where the
1750-
compiler needs assistance, though, the arguments and return types may be
1751-
annotated.
1781+
~~~~ {.ignore}
1782+
// `fun` as a function declaration cannot infer the type of `x`, so it must be provided
1783+
fn fun (x: int) { println!("{}", x) }
1784+
let closure = |x | { println!("{}", x) }; // infers `x: int`, return type `()`
1785+
1786+
// For closures, omitting a return type is *not* synonymous with `-> ()`
1787+
let add_3 = |y | { 3i + y }; // infers `y: int`, return type `int`.
1788+
1789+
fun(10); // Prints 10
1790+
closure(20); // Prints 20
1791+
closure(add_3(30)); // Prints 33
17521792
1793+
fun("String"); // Error: mismatched types
1794+
1795+
// Error: mismatched types
1796+
// inference already assigned `closure` the type `|int| -> ()`
1797+
closure("String");
17531798
~~~~
1754-
let square = |x: int| -> uint { (x * x) as uint };
1799+
1800+
In cases where the compiler needs assistance, the arguments and return
1801+
types may be annotated on closures, using the same notation as shown
1802+
earlier. In the example below, since different types provide an
1803+
implementation for the operator `*`, the argument type for the `x`
1804+
parameter must be explicitly provided.
1805+
1806+
~~~~{.ignore}
1807+
// Error: the type of `x` must be known to be used with `x * x`
1808+
let square = |x | -> uint { (x * x) as uint };
1809+
~~~~
1810+
1811+
In the corrected version, the argument type is explicitly annotated,
1812+
while the return type can still be inferred.
1813+
1814+
~~~~
1815+
let square_explicit = |x: int| -> uint { (x * x) as uint };
1816+
let square_infer = |x: int| { (x * x) as uint };
1817+
1818+
println!("{}", square_explicit(20)); // 400
1819+
println!("{}", square_infer(-20)); // 400
17551820
~~~~
17561821
17571822
There are several forms of closure, each with its own role. The most

branches/try2/src/librustc/front/feature_gate.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
5959

6060
("quad_precision_float", Active),
6161

62+
// A temporary feature gate used to enable parser extensions needed
63+
// to bootstrap fix for #5723.
64+
("issue_5723_bootstrap", Active),
65+
6266
// These are used to test this portion of the compiler, they don't actually
6367
// mean anything
6468
("test_accepted_feature", Accepted),
@@ -80,14 +84,16 @@ enum Status {
8084
/// A set of features to be used by later passes.
8185
pub struct Features {
8286
pub default_type_params: Cell<bool>,
83-
pub quad_precision_float: Cell<bool>
87+
pub quad_precision_float: Cell<bool>,
88+
pub issue_5723_bootstrap: Cell<bool>,
8489
}
8590

8691
impl Features {
8792
pub fn new() -> Features {
8893
Features {
8994
default_type_params: Cell::new(false),
90-
quad_precision_float: Cell::new(false)
95+
quad_precision_float: Cell::new(false),
96+
issue_5723_bootstrap: Cell::new(false),
9197
}
9298
}
9399
}
@@ -367,4 +373,5 @@ pub fn check_crate(sess: &Session, krate: &ast::Crate) {
367373

368374
sess.features.default_type_params.set(cx.has_feature("default_type_params"));
369375
sess.features.quad_precision_float.set(cx.has_feature("quad_precision_float"));
376+
sess.features.issue_5723_bootstrap.set(cx.has_feature("issue_5723_bootstrap"));
370377
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,12 @@ impl<'a> ReachableContext<'a> {
270270

271271
// Statics with insignificant addresses are not reachable
272272
// because they're inlined specially into all other crates.
273-
ast::ItemStatic(..) => {
273+
ast::ItemStatic(_, _, init) => {
274274
if attr::contains_name(item.attrs.as_slice(),
275275
"address_insignificant") {
276276
self.reachable_symbols.remove(&search_item);
277277
}
278+
visit::walk_expr(self, init, ());
278279
}
279280

280281
// These are normal, nothing reachable about these

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use metadata::decoder::{DefLike, DlDef, DlField, DlImpl};
1616
use middle::lang_items::LanguageItems;
1717
use middle::lint::{UnnecessaryQualification, UnusedImports};
1818
use middle::pat_util::pat_bindings;
19-
use util::nodemap::{NodeMap, DefIdSet, FnvHashSet};
19+
use util::nodemap::{NodeMap, DefIdSet, FnvHashMap};
2020

2121
use syntax::ast::*;
2222
use syntax::ast;
@@ -821,7 +821,7 @@ fn Resolver<'a>(session: &'a Session,
821821

822822
graph_root: graph_root,
823823

824-
method_set: RefCell::new(FnvHashSet::new()),
824+
method_map: RefCell::new(FnvHashMap::new()),
825825
structs: HashSet::new(),
826826

827827
unresolved_imports: 0,
@@ -860,7 +860,7 @@ struct Resolver<'a> {
860860

861861
graph_root: NameBindings,
862862

863-
method_set: RefCell<FnvHashSet<(Name, DefId)>>,
863+
method_map: RefCell<FnvHashMap<(Name, DefId), ast::ExplicitSelf_>>,
864864
structs: HashSet<DefId>,
865865

866866
// The number of imports that are currently unresolved.
@@ -1371,10 +1371,8 @@ impl<'a> Resolver<'a> {
13711371
ty_m.span);
13721372
method_name_bindings.define_value(def, ty_m.span, true);
13731373

1374-
// Add it to the trait info if not static.
1375-
if ty_m.explicit_self.node != SelfStatic {
1376-
self.method_set.borrow_mut().insert((ident.name, def_id));
1377-
}
1374+
self.method_map.borrow_mut().insert((ident.name, def_id),
1375+
ty_m.explicit_self.node);
13781376
}
13791377

13801378
name_bindings.define_type(DefTrait(def_id), sp, is_public);
@@ -1660,10 +1658,8 @@ impl<'a> Resolver<'a> {
16601658
trait method '{}'",
16611659
token::get_ident(method_name));
16621660

1663-
// Add it to the trait info if not static.
1664-
if explicit_self != SelfStatic {
1665-
self.method_set.borrow_mut().insert((method_name.name, def_id));
1666-
}
1661+
self.method_map.borrow_mut().insert((method_name.name, def_id), explicit_self);
1662+
16671663
if is_exported {
16681664
self.external_exports.insert(method_def_id);
16691665
}
@@ -3828,7 +3824,8 @@ impl<'a> Resolver<'a> {
38283824
TraitTyParamBound(ref tref) => {
38293825
self.resolve_trait_reference(id, tref, TraitBoundingTypeParameter)
38303826
}
3831-
RegionTyParamBound => {}
3827+
StaticRegionTyParamBound => {}
3828+
OtherRegionTyParamBound(_) => {}
38323829
}
38333830
}
38343831

@@ -4718,10 +4715,16 @@ impl<'a> Resolver<'a> {
47184715
match containing_module.kind.get() {
47194716
TraitModuleKind | ImplModuleKind => {
47204717
match containing_module.def_id.get() {
4721-
Some(def_id) if self.method_set.borrow().contains(&(ident.name, def_id)) => {
4722-
debug!("containing module was a trait or impl \
4718+
Some(def_id) => {
4719+
match self.method_map.borrow().find(&(ident.name, def_id)) {
4720+
Some(x) if *x == SelfStatic => (),
4721+
None => (),
4722+
_ => {
4723+
debug!("containing module was a trait or impl \
47234724
and name was a method -> not resolved");
4724-
return None;
4725+
return None;
4726+
}
4727+
}
47254728
},
47264729
_ => (),
47274730
}
@@ -5110,9 +5113,9 @@ impl<'a> Resolver<'a> {
51105113
// Look for the current trait.
51115114
match self.current_trait_refs {
51125115
Some(ref trait_def_ids) => {
5113-
let method_set = self.method_set.borrow();
5116+
let method_map = self.method_map.borrow();
51145117
for &trait_def_id in trait_def_ids.iter() {
5115-
if method_set.contains(&(name, trait_def_id)) {
5118+
if method_map.contains_key(&(name, trait_def_id)) {
51165119
add_trait_info(&mut found_traits, trait_def_id, name);
51175120
}
51185121
}
@@ -5126,7 +5129,7 @@ impl<'a> Resolver<'a> {
51265129
self.populate_module_if_necessary(&search_module);
51275130

51285131
{
5129-
let method_set = self.method_set.borrow();
5132+
let method_map = self.method_map.borrow();
51305133
for (_, child_names) in search_module.children.borrow().iter() {
51315134
let def = match child_names.def_for_namespace(TypeNS) {
51325135
Some(def) => def,
@@ -5136,7 +5139,7 @@ impl<'a> Resolver<'a> {
51365139
DefTrait(trait_def_id) => trait_def_id,
51375140
_ => continue,
51385141
};
5139-
if method_set.contains(&(name, trait_def_id)) {
5142+
if method_map.contains_key(&(name, trait_def_id)) {
51405143
add_trait_info(&mut found_traits, trait_def_id, name);
51415144
}
51425145
}
@@ -5152,7 +5155,7 @@ impl<'a> Resolver<'a> {
51525155
Some(DefTrait(trait_def_id)) => trait_def_id,
51535156
Some(..) | None => continue,
51545157
};
5155-
if self.method_set.borrow().contains(&(name, did)) {
5158+
if self.method_map.borrow().contains_key(&(name, did)) {
51565159
add_trait_info(&mut found_traits, did, name);
51575160
self.used_imports.insert((import.type_id, TypeNS));
51585161
}

0 commit comments

Comments
 (0)