Skip to content

Commit 2f3a2cb

Browse files
committed
---
yaml --- r: 31689 b: refs/heads/dist-snap c: 7d374bd h: refs/heads/master i: 31687: 00aaffc v: v3
1 parent 15d38bf commit 2f3a2cb

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
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: dbef6e593dfb1b164c6750ee99ca2b80c249c4f5
10+
refs/heads/dist-snap: 7d374bde4354eddd37bd548d8d8c33a2bc07d2c0
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/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);

branches/dist-snap/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)