Skip to content

Commit 90ed91d

Browse files
committed
---
yaml --- r: 23027 b: refs/heads/master c: 7d374bd h: refs/heads/master i: 23025: 86c7be0 23023: 5fabe1a v: v3
1 parent 458659c commit 90ed91d

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: dbef6e593dfb1b164c6750ee99ca2b80c249c4f5
2+
refs/heads/master: 7d374bde4354eddd37bd548d8d8c33a2bc07d2c0
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/rustc/middle/lint.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import std::map::{map,hashmap,int_hash,hash_from_strs};
88
import std::smallintmap::{map,smallintmap};
99
import io::writer_util;
1010
import util::ppaux::{ty_to_str};
11-
import syntax::print::pprust::{expr_to_str, mode_to_str};
11+
import middle::pat_util::{pat_bindings};
12+
import syntax::ast_util::{path_to_ident};
13+
import syntax::print::pprust::{expr_to_str, mode_to_str, pat_to_str};
1214
export lint, ctypes, unused_imports, while_true, path_statement, old_vecs;
1315
export unrecognized_lint, non_implicitly_copyable_typarams;
1416
export vecs_implicitly_copyable, implicit_copies;
@@ -49,6 +51,7 @@ enum lint {
4951
non_implicitly_copyable_typarams,
5052
vecs_implicitly_copyable,
5153
deprecated_mode,
54+
deprecated_pattern,
5255
non_camel_case_types
5356
}
5457

@@ -140,6 +143,11 @@ fn get_lint_dict() -> lint_dict {
140143
desc: ~"warn about deprecated uses of modes",
141144
default: allow}),
142145

146+
(~"deprecated_pattern",
147+
@{lint: deprecated_pattern,
148+
desc: ~"warn about deprecated uses of pattern bindings",
149+
default: allow}),
150+
143151
(~"non_camel_case_types",
144152
@{lint: non_camel_case_types,
145153
desc: ~"types, variants and traits must have camel case names",
@@ -474,6 +482,27 @@ fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
474482
}
475483
}
476484

485+
fn check_pat(tcx: ty::ctxt, pat: @ast::pat) {
486+
debug!{"lint check_pat pat=%s", pat_to_str(pat)};
487+
488+
do pat_bindings(tcx.def_map, pat) |binding_mode, id, span, path| {
489+
match binding_mode {
490+
ast::bind_by_ref(_) | ast::bind_by_value => {}
491+
ast::bind_by_implicit_ref => {
492+
let pat_ty = ty::node_id_to_type(tcx, id);
493+
let kind = ty::type_kind(tcx, pat_ty);
494+
if !ty::kind_is_safe_for_default_mode(kind) {
495+
tcx.sess.span_lint(
496+
deprecated_pattern, id, id,
497+
span,
498+
fmt!{"binding `%s` should use ref or copy mode",
499+
*path_to_ident(path)});
500+
}
501+
}
502+
}
503+
}
504+
}
505+
477506
fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl,
478507
_body: ast::blk, span: span, id: ast::node_id) {
479508
debug!{"lint check_fn fk=%? id=%?", fk, id};
@@ -527,11 +556,12 @@ fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl,
527556
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
528557

529558
let v = visit::mk_simple_visitor(@{
530-
visit_item:
531-
|it| check_item(it, tcx),
532-
visit_fn:
533-
|fk, decl, body, span, id| check_fn(tcx, fk, decl, body,
534-
span, id),
559+
visit_item: |it|
560+
check_item(it, tcx),
561+
visit_fn: |fk, decl, body, span, id|
562+
check_fn(tcx, fk, decl, body, span, id),
563+
visit_pat: |pat|
564+
check_pat(tcx, pat),
535565
with *visit::default_simple_visitor()
536566
});
537567
visit::visit_crate(*crate, (), v);

trunk/src/rustc/rustc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#[no_core];
1313

1414
#[allow(vecs_implicitly_copyable)];
15+
// #[warn(deprecated_pattern)];
1516

1617
use core(vers = "0.3");
1718
use std(vers = "0.3");

0 commit comments

Comments
 (0)