diff --git a/src/librustc/middle/traits/util.rs b/src/librustc/middle/traits/util.rs index 45ce692bb076..6cbac7d01e7b 100644 --- a/src/librustc/middle/traits/util.rs +++ b/src/librustc/middle/traits/util.rs @@ -11,12 +11,12 @@ use middle::subst::{Substs, VecPerParamSpace}; use middle::infer::InferCtxt; use middle::ty::{self, Ty, AsPredicate, ToPolyTraitRef}; -use std::collections::HashSet; use std::fmt; use std::rc::Rc; use syntax::ast; use syntax::codemap::Span; use util::common::ErrorReported; +use util::nodemap::FnvHashSet; use util::ppaux::Repr; use super::{Obligation, ObligationCause, PredicateObligation, @@ -36,7 +36,7 @@ use super::{Obligation, ObligationCause, PredicateObligation, pub struct Elaborator<'cx, 'tcx:'cx> { tcx: &'cx ty::ctxt<'tcx>, stack: Vec>, - visited: HashSet>, + visited: FnvHashSet>, } struct StackEntry<'tcx> { @@ -65,14 +65,11 @@ pub fn elaborate_trait_refs<'cx, 'tcx>( pub fn elaborate_predicates<'cx, 'tcx>( tcx: &'cx ty::ctxt<'tcx>, - predicates: Vec>) + mut predicates: Vec>) -> Elaborator<'cx, 'tcx> { - let visited: HashSet> = - predicates.iter() - .map(|b| (*b).clone()) - .collect(); - + let mut visited = FnvHashSet(); + predicates.retain(|pred| visited.insert(pred.clone())); let entry = StackEntry { position: 0, predicates: predicates }; Elaborator { tcx: tcx, stack: vec![entry], visited: visited } } diff --git a/src/test/run-pass/associated-types-duplicate-binding-in-env.rs b/src/test/run-pass/associated-types-duplicate-binding-in-env.rs new file mode 100644 index 000000000000..62ac21879520 --- /dev/null +++ b/src/test/run-pass/associated-types-duplicate-binding-in-env.rs @@ -0,0 +1,27 @@ +// Copyright 2015 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. + +// Check that we do not report ambiguities when the same predicate +// appears in the environment twice. Issue #21965. + +trait Foo { + type B; + + fn get() -> Self::B; +} + +fn foo() -> () + where T : Foo, T : Foo +{ + ::get() +} + +fn main() { +}