Skip to content

Commit d5c508c

Browse files
committed
---
yaml --- r: 30748 b: refs/heads/incoming c: 62649f0 h: refs/heads/master v: v3
1 parent aac8428 commit d5c508c

File tree

8 files changed

+111
-37
lines changed

8 files changed

+111
-37
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: e500659eb5482aea8b4675416449b03d5cfbe898
9+
refs/heads/incoming: 62649f0412630f8bfe284996c82b6a723d2ffea9
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
// NB: transitionary, de-mode-ing.
12-
#[forbid(deprecated_mode)];
12+
#[warn(deprecated_mode)];
1313
#[forbid(deprecated_pattern)];
1414

1515
use cmp::Eq;

branches/incoming/src/libstd/fun_treemap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[forbid(deprecated_mode)];
1+
#[warn(deprecated_mode)];
22
#[forbid(deprecated_pattern)];
33

44
/*!

branches/incoming/src/libstd/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! A standard linked list
2-
#[forbid(deprecated_mode)];
2+
#[warn(deprecated_mode)];
33
#[forbid(deprecated_pattern)];
44

55
use core::cmp::Eq;

branches/incoming/src/libstd/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// simplest interface possible for representing and running tests
66
// while providing a base that other test frameworks may build off of.
77

8-
#[forbid(deprecated_mode)];
8+
#[warn(deprecated_mode)];
99
#[forbid(deprecated_pattern)];
1010

1111
use core::cmp::Eq;

branches/incoming/src/libstd/treemap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* very naive algorithm, but it will probably be updated to be a
66
* red-black tree or something else.
77
*/
8-
#[forbid(deprecated_mode)];
8+
#[warn(deprecated_mode)];
99
#[forbid(deprecated_pattern)];
1010

1111
use core::cmp::{Eq, Ord};

branches/incoming/src/rustc/middle/lint.rs

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
396396
check_item_non_camel_case_types(cx, i);
397397
check_item_heap(cx, i);
398398
check_item_structural_records(cx, i);
399+
check_item_deprecated_modes(cx, i);
399400
}
400401

401402
// Take a visitor, and modify it so that it will not proceed past subitems.
@@ -666,43 +667,107 @@ fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl,
666667
}
667668

668669
let fn_ty = ty::node_id_to_type(tcx, id);
670+
check_fn_deprecated_modes(tcx, fn_ty, decl, span, id);
671+
}
672+
673+
fn check_fn_deprecated_modes(tcx: ty::ctxt, fn_ty: ty::t, decl: ast::fn_decl,
674+
span: span, id: ast::node_id) {
669675
match ty::get(fn_ty).sty {
670-
ty::ty_fn(fn_ty) => {
671-
let mut counter = 0;
672-
do vec::iter2(fn_ty.sig.inputs, decl.inputs) |arg_ty, arg_ast| {
673-
counter += 1;
674-
debug!("arg %d, ty=%s, mode=%s",
675-
counter,
676-
ty_to_str(tcx, arg_ty.ty),
677-
mode_to_str(arg_ast.mode));
678-
match arg_ast.mode {
679-
ast::expl(ast::by_copy) => {
680-
/* always allow by-copy */
681-
}
676+
ty::ty_fn(fn_ty) => {
677+
let mut counter = 0;
678+
do vec::iter2(fn_ty.sig.inputs, decl.inputs) |arg_ty, arg_ast| {
679+
counter += 1;
680+
debug!("arg %d, ty=%s, mode=%s",
681+
counter,
682+
ty_to_str(tcx, arg_ty.ty),
683+
mode_to_str(arg_ast.mode));
684+
match arg_ast.mode {
685+
ast::expl(ast::by_copy) => {
686+
/* always allow by-copy */
687+
}
682688

683-
ast::expl(_) => {
684-
tcx.sess.span_lint(
685-
deprecated_mode, id, id,
686-
span,
687-
fmt!("argument %d uses an explicit mode", counter));
688-
}
689+
ast::expl(_) => {
690+
tcx.sess.span_lint(
691+
deprecated_mode, id, id,
692+
span,
693+
fmt!("argument %d uses an explicit mode", counter));
694+
}
689695

690-
ast::infer(_) => {
691-
let kind = ty::type_kind(tcx, arg_ty.ty);
692-
if !ty::kind_is_safe_for_default_mode(kind) {
693-
tcx.sess.span_lint(
694-
deprecated_mode, id, id,
695-
span,
696-
fmt!("argument %d uses the default mode \
697-
but shouldn't",
698-
counter));
696+
ast::infer(_) => {
697+
let kind = ty::type_kind(tcx, arg_ty.ty);
698+
if !ty::kind_is_safe_for_default_mode(kind) {
699+
tcx.sess.span_lint(
700+
deprecated_mode, id, id,
701+
span,
702+
fmt!("argument %d uses the default mode \
703+
but shouldn't",
704+
counter));
705+
}
706+
}
707+
}
708+
709+
match ty::get(arg_ty.ty).sty {
710+
ty::ty_fn(*) => {
711+
let span = arg_ast.ty.span;
712+
// Recurse to check fn-type argument
713+
match arg_ast.ty.node {
714+
ast::ty_fn(_, _, _, decl) => {
715+
check_fn_deprecated_modes(tcx, arg_ty.ty,
716+
decl, span, id);
717+
}
718+
ast::ty_path(*) => {
719+
// This is probably a typedef, so we can't
720+
// see the actual fn decl
721+
// e.g. fn foo(f: InitOp<T>)
722+
}
723+
ast::ty_rptr(_, mt)
724+
| ast::ty_box(mt)
725+
| ast::ty_uniq(mt) => {
726+
// Functions with preceding sigil are parsed
727+
// as pointers of functions
728+
match mt.ty.node {
729+
ast::ty_fn(_, _, _, decl) => {
730+
check_fn_deprecated_modes(
731+
tcx, arg_ty.ty,
732+
decl, span, id);
733+
}
734+
_ => fail
735+
}
736+
}
737+
_ => {
738+
tcx.sess.span_warn(span, ~"what");
739+
error!("arg %d, ty=%s, mode=%s",
740+
counter,
741+
ty_to_str(tcx, arg_ty.ty),
742+
mode_to_str(arg_ast.mode));
743+
error!("%?",arg_ast.ty.node);
744+
fail
745+
}
746+
};
747+
}
748+
_ => ()
699749
}
700-
}
701750
}
702751
}
703-
}
704-
_ => tcx.sess.impossible_case(span, ~"check_fn: function has \
705-
non-fn type")
752+
753+
_ => tcx.sess.impossible_case(span, ~"check_fn: function has \
754+
non-fn type")
755+
}
756+
}
757+
758+
fn check_item_deprecated_modes(tcx: ty::ctxt, it: @ast::item) {
759+
match it.node {
760+
ast::item_ty(ty, _) => {
761+
match ty.node {
762+
ast::ty_fn(_, _, _, decl) => {
763+
let fn_ty = ty::node_id_to_type(tcx, it.id);
764+
check_fn_deprecated_modes(
765+
tcx, fn_ty, decl, ty.span, it.id)
766+
}
767+
_ => ()
768+
}
769+
}
770+
_ => ()
706771
}
707772
}
708773

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[forbid(deprecated_mode)];
2+
3+
fn foo(_f: fn(&i: int)) { //~ ERROR explicit mode
4+
}
5+
6+
type Bar = fn(&i: int); //~ ERROR explicit mode
7+
8+
fn main() {
9+
}

0 commit comments

Comments
 (0)