Skip to content

Commit cdd8804

Browse files
committed
---
yaml --- r: 35551 b: refs/heads/master c: 8a9ccf8 h: refs/heads/master i: 35549: 45936aa 35547: 9851308 35543: ee19fe0 35535: 39720a9 35519: 319d97c v: v3
1 parent f1a35be commit cdd8804

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
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: d719eac8aa0816212194449ea962a3a818aac9dc
2+
refs/heads/master: 8a9ccf81b056baf493f22d31f31c642d5ca47fb7
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024

trunk/src/librustc/middle/lint.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ enum lint {
6565
non_camel_case_types,
6666
structural_records,
6767
type_limits,
68+
default_methods,
6869

6970
managed_heap_memory,
7071
owned_heap_memory,
@@ -200,7 +201,12 @@ fn get_lint_dict() -> lint_dict {
200201
(~"type_limits",
201202
@{lint: type_limits,
202203
desc: ~"comparisons made useless by limits of the types involved",
203-
default: warn})
204+
default: warn}),
205+
206+
(~"default_methods",
207+
@{lint: default_methods,
208+
desc: ~"allow default methods",
209+
default: forbid}),
204210

205211
/* FIXME(#3266)--make liveness warnings lintable
206212
(~"unused_variable",
@@ -414,6 +420,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
414420
check_item_structural_records(cx, i);
415421
check_item_deprecated_modes(cx, i);
416422
check_item_type_limits(cx, i);
423+
check_item_default_methods(cx, i);
417424
}
418425

419426
// Take a visitor, and modify it so that it will not proceed past subitems.
@@ -563,6 +570,27 @@ fn check_item_type_limits(cx: ty::ctxt, it: @ast::item) {
563570
visit::visit_item(it, (), visit);
564571
}
565572

573+
fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) {
574+
match item.node {
575+
ast::item_trait(_, _, methods) => {
576+
for methods.each |method| {
577+
match *method {
578+
ast::required(*) => {}
579+
ast::provided(*) => {
580+
cx.sess.span_lint(
581+
default_methods,
582+
item.id,
583+
item.id,
584+
item.span,
585+
~"default methods are experimental");
586+
}
587+
}
588+
}
589+
}
590+
_ => {}
591+
}
592+
}
593+
566594
fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) {
567595
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
568596
visit_expr: fn@(e: @ast::expr) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[forbid(default_methods)];
2+
3+
trait Foo {
4+
fn bar() { io::println("hi"); } //~ ERROR default methods are experimental
5+
}
6+
7+
fn main() {}
8+

0 commit comments

Comments
 (0)