Skip to content

Commit 08c8402

Browse files
committed
librustc: Lint the old drop destructor notation off
1 parent 7353568 commit 08c8402

File tree

9 files changed

+51
-81
lines changed

9 files changed

+51
-81
lines changed

doc/rust.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,10 @@ declared, in an angle-bracket-enclosed, comma-separated list following
889889
the function name.
890890

891891
~~~~ {.xfail-test}
892-
fn iter<T>(seq: &[T], f: fn(T)) {
892+
fn iter<T>(seq: &[T], f: &fn(T)) {
893893
for seq.each |elt| { f(elt); }
894894
}
895-
fn map<T, U>(seq: &[T], f: fn(T) -> U) -> ~[U] {
895+
fn map<T, U>(seq: &[T], f: &fn(T) -> U) -> ~[U] {
896896
let mut acc = ~[];
897897
for seq.each |elt| { acc.push(f(elt)); }
898898
acc
@@ -1198,7 +1198,7 @@ These appear after the trait name, using the same syntax used in [generic functi
11981198
trait Seq<T> {
11991199
fn len() -> uint;
12001200
fn elt_at(n: uint) -> T;
1201-
fn iter(fn(T));
1201+
fn iter(&fn(T));
12021202
}
12031203
~~~~
12041204

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

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

21792179
~~~~
2180-
# fn f(f: fn(int)) { }
2180+
# fn f(f: &fn(int)) { }
21812181
# fn g(i: int) { }
21822182
21832183
f(|j| g(j));
@@ -2755,7 +2755,7 @@ and the cast expression in `main`.
27552755
Within the body of an item that has type parameter declarations, the names of its type parameters are types:
27562756

27572757
~~~~~~~
2758-
fn map<A: Copy, B: Copy>(f: fn(A) -> B, xs: &[A]) -> ~[B] {
2758+
fn map<A: Copy, B: Copy>(f: &fn(A) -> B, xs: &[A]) -> ~[B] {
27592759
if xs.len() == 0 { return ~[]; }
27602760
let first: B = f(xs[0]);
27612761
let rest: ~[B] = map(f, xs.slice(1, xs.len()));

doc/tutorial.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ the enclosing scope.
13611361

13621362
~~~~
13631363
# use println = core::io::println;
1364-
fn call_closure_with_ten(b: fn(int)) { b(10); }
1364+
fn call_closure_with_ten(b: &fn(int)) { b(10); }
13651365
13661366
let captured_var = 20;
13671367
let closure = |arg| println(fmt!("captured_var=%d, arg=%d", captured_var, arg));
@@ -1447,7 +1447,7 @@ should almost always declare the type of that argument as `fn()`. That way,
14471447
callers may pass any kind of closure.
14481448

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

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

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

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

15481548
~~~~
1549-
fn each(v: &[int], op: fn(v: &int) -> bool) {
1549+
fn each(v: &[int], op: &fn(v: &int) -> bool) {
15501550
let mut n = 0;
15511551
while n < v.len() {
15521552
if !op(&v[n]) {
@@ -1770,7 +1770,7 @@ vector consisting of the result of applying `function` to each element
17701770
of `vector`:
17711771

17721772
~~~~
1773-
fn map<T, U>(vector: &[T], function: fn(v: &T) -> U) -> ~[U] {
1773+
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
17741774
let mut accumulator = ~[];
17751775
for vec::each(vector) |element| {
17761776
accumulator.push(function(element));
@@ -1969,12 +1969,12 @@ types might look like the following:
19691969
~~~~
19701970
trait Seq<T> {
19711971
fn len(&self) -> uint;
1972-
fn iter(&self, b: fn(v: &T));
1972+
fn iter(&self, b: &fn(v: &T));
19731973
}
19741974
19751975
impl<T> Seq<T> for ~[T] {
19761976
fn len(&self) -> uint { vec::len(*self) }
1977-
fn iter(&self, b: fn(v: &T)) {
1977+
fn iter(&self, b: &fn(v: &T)) {
19781978
for vec::each(*self) |elt| { b(elt); }
19791979
}
19801980
}

src/libcore/core.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Implicitly, all crates behave as if they included the following prologue:
5252
#[deny(non_camel_case_types)];
5353
#[allow(deprecated_mutable_fields)];
5454
#[deny(deprecated_self)];
55+
#[allow(deprecated_drop)];
5556

5657
// On Linux, link to the runtime with -lrt.
5758
#[cfg(target_os = "linux")]

src/librustc/middle/lint.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub enum lint {
7777
default_methods,
7878
deprecated_self,
7979
deprecated_mutable_fields,
80+
deprecated_drop,
8081

8182
managed_heap_memory,
8283
owned_heap_memory,
@@ -251,6 +252,13 @@ pub fn get_lint_dict() -> LintDict {
251252
default: deny
252253
}),
253254

255+
(@~"deprecated_drop",
256+
@LintSpec {
257+
lint: deprecated_drop,
258+
desc: "deprecated \"drop\" notation for the destructor",
259+
default: deny
260+
}),
261+
254262
/* FIXME(#3266)--make liveness warnings lintable
255263
(@~"unused_variable",
256264
@LintSpec {
@@ -483,6 +491,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
483491
check_item_default_methods(cx, i);
484492
check_item_deprecated_self(cx, i);
485493
check_item_deprecated_mutable_fields(cx, i);
494+
check_item_deprecated_drop(cx, i);
486495
}
487496

488497
// Take a visitor, and modify it so that it will not proceed past subitems.
@@ -720,6 +729,26 @@ fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
720729
}
721730
}
722731

732+
fn check_item_deprecated_drop(cx: ty::ctxt, item: @ast::item) {
733+
match item.node {
734+
ast::item_struct(struct_def, _) => {
735+
match struct_def.dtor {
736+
None => {}
737+
Some(ref dtor) => {
738+
cx.sess.span_lint(deprecated_drop,
739+
item.id,
740+
item.id,
741+
dtor.span,
742+
~"`drop` notation for destructors is \
743+
deprecated; implement the `Drop` \
744+
trait instead");
745+
}
746+
}
747+
}
748+
_ => {}
749+
}
750+
}
751+
723752
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
724753

725754
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,

src/libsyntax/print/pprust.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -612,36 +612,11 @@ pub fn print_item(s: @ps, &&item: @ast::item) {
612612
pub fn print_enum_def(s: @ps, enum_definition: ast::enum_def,
613613
generics: &ast::Generics, ident: ast::ident,
614614
span: codemap::span, visibility: ast::visibility) {
615-
let mut newtype =
616-
vec::len(enum_definition.variants) == 1u &&
617-
ident == enum_definition.variants[0].node.name;
618-
if newtype {
619-
match enum_definition.variants[0].node.kind {
620-
ast::tuple_variant_kind(ref args) if args.len() == 1 => {}
621-
_ => newtype = false
622-
}
623-
}
624-
if newtype {
625-
ibox(s, indent_unit);
626-
word_space(s, visibility_qualified(visibility, ~"enum"));
627-
} else {
628-
head(s, visibility_qualified(visibility, ~"enum"));
629-
}
630-
615+
head(s, visibility_qualified(visibility, ~"enum"));
631616
print_ident(s, ident);
632617
print_generics(s, generics);
633618
space(s.s);
634-
if newtype {
635-
word_space(s, ~"=");
636-
match /*bad*/ copy enum_definition.variants[0].node.kind {
637-
ast::tuple_variant_kind(args) => print_type(s, args[0].ty),
638-
_ => fail!(~"newtype syntax with struct?")
639-
}
640-
word(s.s, ~";");
641-
end(s);
642-
} else {
643-
print_variants(s, enum_definition.variants, span);
644-
}
619+
print_variants(s, enum_definition.variants, span);
645620
}
646621
647622
pub fn print_variants(s: @ps,

src/test/compile-fail/issue-2063.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// xfail-test
2+
13
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
24
// file at the top-level directory of this distribution and at
35
// http://rust-lang.org/COPYRIGHT.

src/test/compile-fail/issue-2718-a.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// xfail-test
2+
13
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
24
// file at the top-level directory of this distribution and at
35
// http://rust-lang.org/COPYRIGHT.

src/test/run-pass/coherence-copy-bound.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/test/run-pass/operator-overloading-explicit-self.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)