Skip to content

Lint off the old "drop" notation #5291

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 11 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
12 changes: 6 additions & 6 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,10 +889,10 @@ declared, in an angle-bracket-enclosed, comma-separated list following
the function name.

~~~~ {.xfail-test}
fn iter<T>(seq: &[T], f: fn(T)) {
fn iter<T>(seq: &[T], f: &fn(T)) {
for seq.each |elt| { f(elt); }
}
fn map<T, U>(seq: &[T], f: fn(T) -> U) -> ~[U] {
fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {
let mut acc = ~[];
for seq.each |elt| { acc.push(f(elt)); }
acc
Expand Down Expand Up @@ -1198,7 +1198,7 @@ These appear after the trait name, using the same syntax used in [generic functi
trait Seq<T> {
fn len() -> uint;
fn elt_at(n: uint) -> T;
fn iter(fn(T));
fn iter(&fn(T));
}
~~~~

Expand Down Expand Up @@ -2074,7 +2074,7 @@ and moving values from the environment into the lambda expression's captured env
An example of a lambda expression:

~~~~
fn ten_times(f: fn(int)) {
fn ten_times(f: &fn(int)) {
let mut i = 0;
while i < 10 {
f(i);
Expand Down Expand Up @@ -2177,7 +2177,7 @@ If the `expr` is a [field expression](#field-expressions), it is parsed as thoug
In this example, both calls to `f` are equivalent:

~~~~
# fn f(f: fn(int)) { }
# fn f(f: &fn(int)) { }
# fn g(i: int) { }

f(|j| g(j));
Expand Down Expand Up @@ -2755,7 +2755,7 @@ and the cast expression in `main`.
Within the body of an item that has type parameter declarations, the names of its type parameters are types:

~~~~~~~
fn map<A: Copy, B: Copy>(f: fn(A) -> B, xs: &[A]) -> ~[B] {
fn map<A: Copy, B: Copy>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
if xs.len() == 0 { return ~[]; }
let first: B = f(xs[0]);
let rest: ~[B] = map(f, xs.slice(1, xs.len()));
Expand Down
98 changes: 45 additions & 53 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,45 +681,6 @@ the value of `North` is 0, `East` is 1, `South` is 2, and `West` is 3.
When an enum is C-like, you can apply the `as` cast operator to
convert it to its discriminator value as an `int`.

<a name="single_variant_enum"></a>

There is a special case for enums with a single variant, which are
sometimes called "newtype-style enums" (after Haskell's "newtype"
feature). These are used to define new types in such a way that the
new name is not just a synonym for an existing type, but its own
distinct type: `type` creates a structural synonym, while this form of
`enum` creates a nominal synonym. If you say:

~~~~
enum GizmoId = int;
~~~~

That is a shorthand for this:

~~~~
enum GizmoId { GizmoId(int) }
~~~~

You can extract the contents of such an enum type with the
dereference (`*`) unary operator:

~~~~
# enum GizmoId = int;
let my_gizmo_id: GizmoId = GizmoId(10);
let id_int: int = *my_gizmo_id;
~~~~

Types like this can be useful to differentiate between data that have
the same type but must be used in different ways.

~~~~
enum Inches = int;
enum Centimeters = int;
~~~~

The above definitions allow for a simple way for programs to avoid
confusing numbers that correspond to different units.

For enum types with multiple variants, destructuring is the only way to
get at their contents. All variant constructors can be used as
patterns, as in this definition of `area`:
Expand Down Expand Up @@ -789,10 +750,10 @@ match mytup {

## Tuple structs

Rust also has _nominal tuples_, which behave like both structs and tuples,
except that nominal tuple types have names
(so `Foo(1, 2)` has a different type from `Bar(1, 2)`),
and nominal tuple types' _fields_ do not have names.
Rust also has _tuple structs_, which behave like both structs and tuples,
except that, unlike tuples, tuple structs have names (so `Foo(1, 2)` has a
different type from `Bar(1, 2)`), and tuple structs' _fields_ do not have
names.

For example:
~~~~
Expand All @@ -803,6 +764,37 @@ match mytup {
}
~~~~

<a name="newtype"></a>

There is a special case for tuple structs with a single field, which are
sometimes called "newtypes" (after Haskell's "newtype" feature). These are
used to define new types in such a way that the new name is not just a
synonym for an existing type but is rather its own distinct type.

~~~~
struct GizmoId(int);
~~~~

For convenience, you can extract the contents of such a struct with the
dereference (`*`) unary operator:

~~~~
# struct GizmoId(int);
let my_gizmo_id: GizmoId = GizmoId(10);
let id_int: int = *my_gizmo_id;
~~~~

Types like this can be useful to differentiate between data that have
the same type but must be used in different ways.

~~~~
struct Inches(int);
struct Centimeters(int);
~~~~

The above definitions allow for a simple way for programs to avoid
confusing numbers that correspond to different units.

# Functions

We've already seen several function definitions. Like all other static
Expand Down Expand Up @@ -1369,7 +1361,7 @@ the enclosing scope.

~~~~
# use println = core::io::println;
fn call_closure_with_ten(b: fn(int)) { b(10); }
fn call_closure_with_ten(b: &fn(int)) { b(10); }

let captured_var = 20;
let closure = |arg| println(fmt!("captured_var=%d, arg=%d", captured_var, arg));
Expand Down Expand Up @@ -1455,7 +1447,7 @@ should almost always declare the type of that argument as `fn()`. That way,
callers may pass any kind of closure.

~~~~
fn call_twice(f: fn()) { f(); f(); }
fn call_twice(f: &fn()) { f(); f(); }
let closure = || { "I'm a closure, and it doesn't matter what type I am"; };
fn function() { "I'm a normal function"; }
call_twice(closure);
Expand All @@ -1475,7 +1467,7 @@ Consider this function that iterates over a vector of
integers, passing in a pointer to each integer in the vector:

~~~~
fn each(v: &[int], op: fn(v: &int)) {
fn each(v: &[int], op: &fn(v: &int)) {
let mut n = 0;
while n < v.len() {
op(&v[n]);
Expand All @@ -1496,7 +1488,7 @@ argument, we can write it in a way that has a pleasant, block-like
structure.

~~~~
# fn each(v: &[int], op: fn(v: &int)) { }
# fn each(v: &[int], op: &fn(v: &int)) { }
# fn do_some_work(i: &int) { }
each([1, 2, 3], |n| {
do_some_work(n);
Expand All @@ -1507,7 +1499,7 @@ This is such a useful pattern that Rust has a special form of function
call that can be written more like a built-in control structure:

~~~~
# fn each(v: &[int], op: fn(v: &int)) { }
# fn each(v: &[int], op: &fn(v: &int)) { }
# fn do_some_work(i: &int) { }
do each([1, 2, 3]) |n| {
do_some_work(n);
Expand Down Expand Up @@ -1554,7 +1546,7 @@ Consider again our `each` function, this time improved to
break early when the iteratee returns `false`:

~~~~
fn each(v: &[int], op: fn(v: &int) -> bool) {
fn each(v: &[int], op: &fn(v: &int) -> bool) {
let mut n = 0;
while n < v.len() {
if !op(&v[n]) {
Expand Down Expand Up @@ -1778,7 +1770,7 @@ vector consisting of the result of applying `function` to each element
of `vector`:

~~~~
fn map<T, U>(vector: &[T], function: fn(v: &T) -> U) -> ~[U] {
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
let mut accumulator = ~[];
for vec::each(vector) |element| {
accumulator.push(function(element));
Expand Down Expand Up @@ -1977,12 +1969,12 @@ types might look like the following:
~~~~
trait Seq<T> {
fn len(&self) -> uint;
fn iter(&self, b: fn(v: &T));
fn iter(&self, b: &fn(v: &T));
}

impl<T> Seq<T> for ~[T] {
fn len(&self) -> uint { vec::len(*self) }
fn iter(&self, b: fn(v: &T)) {
fn iter(&self, b: &fn(v: &T)) {
for vec::each(*self) |elt| { b(elt); }
}
}
Expand Down Expand Up @@ -2294,7 +2286,7 @@ struct level. Note that fields and methods are _public_ by default.
pub mod farm {
# pub type Chicken = int;
# type Cow = int;
# enum Human = int;
# struct Human(int);
# impl Human { fn rest(&self) { } }
# pub fn make_me_a_farm() -> Farm { Farm { chickens: ~[], cows: ~[], farmer: Human(0) } }
pub struct Farm {
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub fn is_test_ignored(config: config, testfile: &Path) -> bool {
}
}

fn iter_header(testfile: &Path, it: fn(~str) -> bool) -> bool {
fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
let rdr = io::file_reader(testfile).get();
while !rdr.eof() {
let ln = rdr.read_line();
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ fn compose_and_run(config: config, testfile: &Path,
}

fn make_compile_args(config: config, props: TestProps, extras: ~[~str],
xform: fn(config, (&Path)) -> Path,
xform: &fn(config, (&Path)) -> Path,
testfile: &Path) -> ProcArgs {
let prog = config.rustc_path;
let mut args = ~[testfile.to_str(),
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub pure fn capacity<T>(v: @[const T]) -> uint {
*/
#[inline(always)]
pub pure fn build_sized<A>(size: uint,
builder: &fn(push: pure fn(v: A))) -> @[A] {
builder: &fn(push: &pure fn(v: A))) -> @[A] {
let mut vec: @[const A] = @[];
unsafe { raw::reserve(&mut vec, size); }
builder(|+x| unsafe { raw::push(&mut vec, x) });
Expand All @@ -79,7 +79,7 @@ pub pure fn build_sized<A>(size: uint,
* onto the vector being constructed.
*/
#[inline(always)]
pub pure fn build<A>(builder: &fn(push: pure fn(v: A))) -> @[A] {
pub pure fn build<A>(builder: &fn(push: &pure fn(v: A))) -> @[A] {
build_sized(4, builder)
}

Expand All @@ -97,7 +97,7 @@ pub pure fn build<A>(builder: &fn(push: pure fn(v: A))) -> @[A] {
*/
#[inline(always)]
pub pure fn build_sized_opt<A>(size: Option<uint>,
builder: &fn(push: pure fn(v: A))) -> @[A] {
builder: &fn(push: &pure fn(v: A))) -> @[A] {
build_sized(size.get_or_default(4), builder)
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub pure fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
* Iterates over all truth values by passing them to `blk` in an unspecified
* order
*/
pub fn all_values(blk: fn(v: bool)) {
pub fn all_values(blk: &fn(v: bool)) {
blk(true);
blk(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub impl<T> Cell<T> {
}

// Calls a closure with a reference to the value.
fn with_ref<R>(&self, op: fn(v: &T) -> R) -> R {
fn with_ref<R>(&self, op: &fn(v: &T) -> R) -> R {
let v = self.take();
let r = op(&v);
self.put_back(v);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct AnnihilateStats {
n_bytes_freed: uint
}

unsafe fn each_live_alloc(f: fn(box: *mut BoxRepr, uniq: bool) -> bool) {
unsafe fn each_live_alloc(f: &fn(box: *mut BoxRepr, uniq: bool) -> bool) {
use managed;

let task: *Task = transmute(rustrt::rust_get_task());
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ pub trait Map<K, V>: Mutable {
pure fn contains_key(&self, key: &K) -> bool;

/// Visit all keys
pure fn each_key(&self, f: fn(&K) -> bool);
pure fn each_key(&self, f: &fn(&K) -> bool);

/// Visit all values
pure fn each_value(&self, f: fn(&V) -> bool);
pure fn each_value(&self, f: &fn(&V) -> bool);

/// Return the value corresponding to the key in the map
pure fn find(&self, key: &K) -> Option<&self/V>;
Expand Down Expand Up @@ -71,14 +71,14 @@ pub trait Set<T>: Mutable {
pure fn is_superset(&self, other: &Self) -> bool;

/// Visit the values representing the difference
pure fn difference(&self, other: &Self, f: fn(&T) -> bool);
pure fn difference(&self, other: &Self, f: &fn(&T) -> bool);

/// Visit the values representing the symmetric difference
pure fn symmetric_difference(&self, other: &Self, f: fn(&T) -> bool);
pure fn symmetric_difference(&self, other: &Self, f: &fn(&T) -> bool);

/// Visit the values representing the intersection
pure fn intersection(&self, other: &Self, f: fn(&T) -> bool);
pure fn intersection(&self, other: &Self, f: &fn(&T) -> bool);

/// Visit the values representing the union
pure fn union(&self, other: &Self, f: fn(&T) -> bool);
pure fn union(&self, other: &Self, f: &fn(&T) -> bool);
}
1 change: 1 addition & 0 deletions src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Implicitly, all crates behave as if they included the following prologue:
#[deny(non_camel_case_types)];
#[allow(deprecated_mutable_fields)];
#[deny(deprecated_self)];
#[allow(deprecated_drop)];

// On Linux, link to the runtime with -lrt.
#[cfg(target_os = "linux")]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ pub impl<T> DList<T> {
}

/// Iterate over nodes.
pure fn each_node(@mut self, f: fn(@mut DListNode<T>) -> bool) {
pure fn each_node(@mut self, f: &fn(@mut DListNode<T>) -> bool) {
let mut link = self.peek_n();
while link.is_some() {
let nobe = link.get();
Expand Down Expand Up @@ -507,7 +507,7 @@ impl<T> BaseIter<T> for @mut DList<T> {
* allow for e.g. breadth-first search with in-place enqueues), but
* removing the current node is forbidden.
*/
pure fn each(&self, f: fn(v: &T) -> bool) {
pure fn each(&self, f: &fn(v: &T) -> bool) {
let mut link = self.peek_n();
while option::is_some(&link) {
let nobe = option::get(link);
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub enum Either<T, U> {
}

#[inline(always)]
pub fn either<T, U, V>(f_left: fn(&T) -> V,
f_right: fn(&U) -> V, value: &Either<T, U>) -> V {
pub fn either<T, U, V>(f_left: &fn(&T) -> V,
f_right: &fn(&U) -> V, value: &Either<T, U>) -> V {
/*!
* Applies a function based on the given either value
*
Expand Down Expand Up @@ -148,7 +148,7 @@ pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {

pub impl<T, U> Either<T, U> {
#[inline(always)]
fn either<V>(&self, f_left: fn(&T) -> V, f_right: fn(&U) -> V) -> V {
fn either<V>(&self, f_left: &fn(&T) -> V, f_right: &fn(&U) -> V) -> V {
either(f_left, f_right, self)
}

Expand Down
Loading