about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLuqman Aden <me@luqman.ca>2013-06-11 15:08:40 -0400
committerLuqman Aden <laden@csclub.uwaterloo.ca>2013-06-12 02:46:38 -0400
commit47772bcb737b229586cc9a9d96a9abda005b907c (patch)
tree05139b69980e8242bfcf79ec37f665b227f83c98 /src
parentc6f3103006f3e91daf4ffbd026ff64d77f858675 (diff)
downloadrust-47772bcb737b229586cc9a9d96a9abda005b907c.tar.gz
rust-47772bcb737b229586cc9a9d96a9abda005b907c.zip
Add tests for duplicate methods on traits/impls.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/resolve.rs8
-rw-r--r--src/test/compile-fail/impl-duplicate-methods.rs17
-rw-r--r--src/test/compile-fail/trait-duplicate-methods.rs16
3 files changed, 37 insertions, 4 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index e4be8dac712..af8cd758fc5 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -1238,10 +1238,10 @@ impl Resolver {
                             let old_sp = methods_seen.find_or_insert(ident, span);
                             if *old_sp != span {
                                 self.session.span_err(span,
-                                                      fmt!("duplicate definition of method %s",
+                                                      fmt!("duplicate definition of method `%s`",
                                                            *self.session.str_of(ident)));
                                 self.session.span_note(*old_sp,
-                                                       fmt!("first definition of method %s here",
+                                                       fmt!("first definition of method `%s` here",
                                                             *self.session.str_of(ident)));
                             }
                         }
@@ -1375,10 +1375,10 @@ impl Resolver {
                             let old_sp = method_names.find_or_insert(ident, ty_m.span);
                             if *old_sp != ty_m.span {
                                 self.session.span_err(ty_m.span,
-                                                      fmt!("duplicate definition of method %s",
+                                                      fmt!("duplicate definition of method `%s`",
                                                            *self.session.str_of(ident)));
                                 self.session.span_note(*old_sp,
-                                                       fmt!("first definition of method %s here",
+                                                       fmt!("first definition of method `%s` here",
                                                             *self.session.str_of(ident)));
                             }
                         }
diff --git a/src/test/compile-fail/impl-duplicate-methods.rs b/src/test/compile-fail/impl-duplicate-methods.rs
new file mode 100644
index 00000000000..ec766e5ce9b
--- /dev/null
+++ b/src/test/compile-fail/impl-duplicate-methods.rs
@@ -0,0 +1,17 @@
+// Copyright 2013 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 Foo;
+impl Foo {
+    fn orange(&self){}
+    fn orange(&self){}   //~ ERROR error: duplicate definition of method `orange`
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/trait-duplicate-methods.rs b/src/test/compile-fail/trait-duplicate-methods.rs
new file mode 100644
index 00000000000..e2ba5267eba
--- /dev/null
+++ b/src/test/compile-fail/trait-duplicate-methods.rs
@@ -0,0 +1,16 @@
+// Copyright 2013 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.
+
+trait Foo {
+    fn orange(&self);
+    fn orange(&self);   //~ ERROR error: duplicate definition of method `orange`
+}
+
+fn main() {}