Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disallow duplicate methods in trait impls #13002

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/libserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions src/libstd/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions src/test/compile-fail/issue-8153.rs
Original file line number Diff line number Diff line change
@@ -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 <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.

// 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());
}