librustc: Lint the old drop destructor notation off

This commit is contained in:
Patrick Walton 2013-03-08 16:21:58 -08:00
parent 7353568cd8
commit 08c840205e
9 changed files with 51 additions and 81 deletions

View file

@ -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")]

View file

@ -77,6 +77,7 @@ pub enum lint {
default_methods,
deprecated_self,
deprecated_mutable_fields,
deprecated_drop,
managed_heap_memory,
owned_heap_memory,
@ -251,6 +252,13 @@ pub fn get_lint_dict() -> LintDict {
default: deny
}),
(@~"deprecated_drop",
@LintSpec {
lint: deprecated_drop,
desc: "deprecated \"drop\" notation for the destructor",
default: deny
}),
/* FIXME(#3266)--make liveness warnings lintable
(@~"unused_variable",
@LintSpec {
@ -483,6 +491,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
check_item_default_methods(cx, i);
check_item_deprecated_self(cx, i);
check_item_deprecated_mutable_fields(cx, i);
check_item_deprecated_drop(cx, i);
}
// 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) {
}
}
fn check_item_deprecated_drop(cx: ty::ctxt, item: @ast::item) {
match item.node {
ast::item_struct(struct_def, _) => {
match struct_def.dtor {
None => {}
Some(ref dtor) => {
cx.sess.span_lint(deprecated_drop,
item.id,
item.id,
dtor.span,
~"`drop` notation for destructors is \
deprecated; implement the `Drop` \
trait instead");
}
}
}
_ => {}
}
}
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,

View file

@ -612,36 +612,11 @@ pub fn print_item(s: @ps, &&item: @ast::item) {
pub fn print_enum_def(s: @ps, enum_definition: ast::enum_def,
generics: &ast::Generics, ident: ast::ident,
span: codemap::span, visibility: ast::visibility) {
let mut newtype =
vec::len(enum_definition.variants) == 1u &&
ident == enum_definition.variants[0].node.name;
if newtype {
match enum_definition.variants[0].node.kind {
ast::tuple_variant_kind(ref args) if args.len() == 1 => {}
_ => newtype = false
}
}
if newtype {
ibox(s, indent_unit);
word_space(s, visibility_qualified(visibility, ~"enum"));
} else {
head(s, visibility_qualified(visibility, ~"enum"));
}
head(s, visibility_qualified(visibility, ~"enum"));
print_ident(s, ident);
print_generics(s, generics);
space(s.s);
if newtype {
word_space(s, ~"=");
match /*bad*/ copy enum_definition.variants[0].node.kind {
ast::tuple_variant_kind(args) => print_type(s, args[0].ty),
_ => fail!(~"newtype syntax with struct?")
}
word(s.s, ~";");
end(s);
} else {
print_variants(s, enum_definition.variants, span);
}
print_variants(s, enum_definition.variants, span);
}
pub fn print_variants(s: @ps,

View file

@ -1,3 +1,5 @@
// xfail-test
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.

View file

@ -1,3 +1,5 @@
// xfail-test
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.

View file

@ -1,13 +0,0 @@
trait X {}
impl<A:Copy> X for A {}
struct S {
x: int,
drop {}
}
impl X for S {}
pub fn main(){}

View file

@ -1,26 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct S {
x: int
}
pub impl S {
pure fn add(&self, other: &S) -> S {
S { x: self.x + other.x }
}
}
pub fn main() {
let mut s = S { x: 1 };
s += S { x: 2 };
fail_unless!(s.x == 3);
}