diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index fc6b4c91b4e89..f65c168f38295 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -48,6 +48,8 @@ use util::ppaux::Repr; use std::rc::Rc; use std::vec_ng::Vec; use std::vec_ng; +use collections::HashSet; + use syntax::abi::AbiSet; use syntax::ast::{RegionTyParamBound, TraitTyParamBound}; use syntax::ast; @@ -478,7 +480,12 @@ fn convert_methods(ccx: &CrateCtxt, rcvr_visibility: ast::Visibility) { let tcx = ccx.tcx; + let mut seen_methods = HashSet::new(); for m in ms.iter() { + if !seen_methods.insert(m.ident.repr(ccx.tcx)) { + tcx.sess.span_err(m.span, "duplicate method in trait impl"); + } + let num_rcvr_ty_params = rcvr_ty_generics.type_param_defs().len(); let m_ty_generics = ty_generics_for_fn_or_method(ccx, &m.generics, num_rcvr_ty_params); diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 6ce555ba9f74a..33868641e5ff0 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1312,7 +1312,7 @@ impl ::Decoder for Decoder { value => self.expected("number", &value) } } - fn read_f32(&mut self) -> f32 { self.read_f64() as f32 } + fn read_f32(&mut self) -> f32 { self.read_f64() as f32 } fn read_char(&mut self) -> char { diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 3704e6e37eb55..ccd08e8a716c0 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -2664,9 +2664,6 @@ impl<'a> StrSlice<'a> for &'a str { return multibyte_char_range_at(*self, i); } - #[inline] - fn char_at(&self, i: uint) -> char { self.char_range_at(i).ch } - #[inline] fn char_range_at_reverse(&self, start: uint) -> CharRange { let mut prev = start; diff --git a/src/test/compile-fail/issue-8153.rs b/src/test/compile-fail/issue-8153.rs new file mode 100644 index 0000000000000..2af531135eca3 --- /dev/null +++ b/src/test/compile-fail/issue-8153.rs @@ -0,0 +1,26 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that duplicate methods in impls are not allowed + +struct Foo; + +trait Bar { + fn bar(&self) -> int; +} + +impl Bar for Foo { + fn bar(&self) -> int {1} + fn bar(&self) -> int {2} //~ ERROR duplicate method +} + +fn main() { + println!("{}", Foo.bar()); +}